这是indexloc提供的服务,不要输入任何密码
Skip to content

Investigation: Cube dimensionality #68

@Kangz

Description

@Kangz

In WebGL cubemaps and 2D array textures are two different types of textures. However in explicit APIs, the distinction is blurrier as the two are almost the same in term of hardware representation.

D3D12

There is no notion of cube texture in D3D12_RESOURCE_DESC: it has a member called D3D12_RESOURCE_DIMENSION that only lists 1/2/3D textures and buffers.

Cube dimensionality is set when a texture view is created (SRV). D3D12_SHADER_RESOURCE_VIEW_DESC has a ViewDimension member of type D3D12_SRV_DIMENSION that can be D3D12_SRV_DIMENSION_TEXTURECUBE or D3D12_SRV_DIMENSION_TEXTURECUBEARRAY. It seems that D3D12_TEXCUBE_SRV only allows using array slices 0 to 5 as the cubemap, but that D3D12_TEXCUBE_ARRAY_SRV allows using any range for the cubemap array.

Metal

MTLTextureDescriptor has a textureType members of type MTLTextureType that lists typeCube and typeCubeArray.

However the "texture view" mechanism of Metal that works by calling MTLTexture::newTextureViewWithPixelFormat:textureType:levels:slices: allows reinterpreting the texture data freely between typeCube, typeCubeArray and type2DArray.

Vulkan

Vulkan is like D3D12 except that a flag must be set to tag the texture as "cube compatible". VkImageCreateInfo has a VkImageType member that can only be 1/2/3D and a VkImageCreateFlags that can contain VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT bit.

VkImageViewCreateInfo takes a VkImageViewType that can be VK_IMAGE_VIEW_TYPE_CUBE or VK_IMAGE_VIEW_TYPE_CUBE_ARRAY. There are some validation rules that are in a table that's really hard to understand, but it seems cubemaps are created from 2D array textures. Support for cubemap arrays is optional in Vulkan (though widely supported).

Suggestion for WebGPU

Since developers have to create a texture view to sample from a textures, we can only expose cube dimensionality for texture views.

WebGPUTextureDescriptor would have a dimensionality that can only be 1/2/3D and an arraySize member that defaults to 1. WebGPUTextureViewDescriptor would have a dimensionality that can be cube, and with our without arrayness.

Copies don't know about cubemaps and treat them as regular 2D textures (that may be arrayed or not).

enum WebGPUTextureDimensionality {"1d", "2d", "3d"};
dictionary WebGPUTextureDescriptor {
    WebGPUTextureDimensionality dimensionality;
    uint32_t arraySize = 1;
    // ...
};

enum WebGPUTextureViewDimensionatlity{"1d", "1dArray", "2d", "2dArray", "cube", "cubeArray", "3d"};
dictionary WebGPUTextureDescriptor {
    WebGPUTextureViewDimensionality dimensionality;
    uint32_t firstSlice = 0; // Must be 0 for cube, 6xN for cubeArray
    uint32_t numSlices = 1; // Must be 6 for cube, 6xN for cubeArray
    // ...
};

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions