Skip to content

Maximum values of Texture Dimension #1327

@Richard-Yunchao

Description

@Richard-Yunchao

When we create a texture, the max value of its width, height and depth are limited. I investigated the max values on D3D12, Vulkan and Metal and attempt to propose the max values we should set for texture dimensions in WebGPU.

Texture size limits at native side

All native graphics APIs have these max values for different texture types, although the names may differ slightly:

  • maxTextureDimension1D: size.width should not exceed this value for 1D texture.
  • maxTextureDimension2D: size.width and size.height should not exceed this value for 2D texture.
  • maxTextureDimension3D: size.width, size.height, and size.depth should not exceed this value for 3D texture.
  • maxTextureDimensionCube: size.width and size.height should not exceed this value for cube texture
  • maxTextureArrayLayers: size.depth should not exceed this value for 1D array texture, or 2D array texture, or cube array texture.

I investigated the values for these parameters on D3D12, Vulkan, and Metal:

Parameters D3D12 Vulkan Metal
maxTextureDimension1D 16384 4096 8192 / 16384
maxTextureDimension2D 16384 4096 8192 / 16384
maxTextureDimension3D 2048 256 2048
maxTextureDimensionCube 16384 4096 8192 / 16384
maxTextureArrayLayers 2048 256 2048

Notes:

  • If textures' dimensions are smaller than the given max values, it is guaranteed that the texture creation can succeed if it fulfill other requirements. If developers want to create larger textures whose width, height, or depth exceed the specified max value for a given texture type, it doesn't mean that the texture creation will fail. But it requires developers to query the adapter and see whether that large value is supported.
  • D3D12's limits on texture size follows D3D11's if feature level is 11_0 or above, see D3D12_RESOURCE_DESC
  • D3D12 has separate parameters for maxTextureArrayLayers for 1D array texture and 2D array texture, but their values are the same. Vulkan and Metal have only one parameter for both 1D array texture and 2D array texture
  • Metal may have different max values for different OSes, but the smaller one is still greater than Vulkan's.

I suppose we should select the minimum values among these max values in order to be compatible with all native graphics and to support more hardware, which fall into Vulkan's limits.

A problem in WebGPU:

We may not know whether a texture is used for Cube/CubeArray when we create a texture. We know that information when we create texture view. So there comes a problem that how maxTextureDimensionCube take effect? At native side, this problem is resolved by different methods:

  • Vulkan has a flag VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT. If this flag is set, then size.width and size.height can't exceed maxTextureDimensionCube. Otherwise, they should not exceed maxTextureDimension2D.
  • D3D11 has a similar flag named D3D11_RESOURCE_MISC_TEXTURECUBE in D3D11_TEXTURE2D_DESC's MiscFlags. But I didn't find such a flag in D3D12. @RafaelCintron , do you know how maxTextureDimensionCube is used in D3D12?
  • Metal has particular texture types for Cube and CubeArray when we create a texture. So it is not a problem at all on Metal.

In WebGPU, we have neither flag nor Cube/CubeArray texture type. So I can't figure out a method to check dimension limits for maxTextureDimensionCube when we create a texture.

Proposal

I propose that we don't expose maxTextureDimensionCube in WebGPU. Instead, we set maxTextureDimension2D as the smaller one of maxTextureDimension2D and maxTextureDimensionCube. Note that the two values are the same in D3D12/Vulkan/Metal, but they may differ in older APIs like D3D10.

The corresponding pr to add the proposed parameters to GPUAdapterLimits has been uploaded.

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