← 输入框|github.com|刷新
Skip to content

Maximum values of Texture Dimension #1327

Closed

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.

Activity

  1. jsheard commented on Jan 5, 2021

    @jsheard

    Although Vulkan only requires implementations to support up to 4096px textures, in practice there seems to be near-universal support for at least 8192px even on mobile. It would be a shame to bake a limit into the spec which barely exists in reality.

    https://vulkan.gpuinfo.org/displaydevicelimit.php?name=maxImageDimension2D&platform=windows

    https://vulkan.gpuinfo.org/displaydevicelimit.php?name=maxImageDimension2D&platform=linux

    https://vulkan.gpuinfo.org/displaydevicelimit.php?name=maxImageDimension2D&platform=android

  2. kvark commented on Jan 5, 2021

    @kvark
    Contributor

    Last time we talked about this, we did agree to set the texture size baseline to 8192 (on one of the calls). Also mentioned in #799 (comment)

    We may not know whether a texture is used for Cube/CubeArray when we create a texture.

    Does it matter that much? The limits for maxTextureDimensionCube appear to be the same as for maxTextureDimension2D. I suppose that's what you are saying in "Proposal", so 👍

  3. Richard-Yunchao commented on Jan 5, 2021

    @Richard-Yunchao
    Author

    Although Vulkan only requires implementations to support up to 4096px textures, in practice there seems to be near-universal support for at least 8192px even on mobile. It would be a shame to bake a limit into the spec which barely exists in reality.

    https://vulkan.gpuinfo.org/displaydevicelimit.php?name=maxImageDimension2D&platform=windows

    https://vulkan.gpuinfo.org/displaydevicelimit.php?name=maxImageDimension2D&platform=linux

    https://vulkan.gpuinfo.org/displaydevicelimit.php?name=maxImageDimension2D&platform=android

    That's true. We can set maxTextureDimension2D to 8192 considering that the vast majority of devices in market can support 8192x. Likewise, we can

  4. Richard-Yunchao commented on Jan 5, 2021

    @Richard-Yunchao
    Author

    Last time we talked about this, we did agree to set the texture size baseline to 8192 (on one of the calls). Also mentioned in #799 (comment)

    We may not know whether a texture is used for Cube/CubeArray when we create a texture.

    Does it matter that much? The limits for maxTextureDimensionCube appear to be the same as for maxTextureDimension2D. I suppose that's what you are saying in "Proposal", so

    Thanks for the info about previous discussion, @kvark . For maxTextureDimensionCube, it is true that its value equals to maxTextureDimension2D in most native platforms. And we can not use it in WebGPU now. We can ignore it like you said. Alternatively, we can add a flag for 2D cube texture view upon 2D texture in GPUTextureDescriptor when we create a texture, just like how it works in Vulkan and D3D11.

  5. kainino0x commented on Jan 5, 2021

    @kainino0x
    Contributor

    These limits all sound great. I think we should go straight to making a PR :)
    Sorry didn't see you already have a PR

  6. fintelia commented on Jan 5, 2021

    @fintelia

    It would be kind of a shame to only guarantee maxTextureArrayLayers being at least 256 when D3D12, Metal, and even OpenGL 4.1 (from back in 2010!) all require a value of at least 2048.

    I'm not sure what thresholds of support WebGPU is looking for, but right now every Windows implementation reported and 80% of mobile Vulkan implementations reported support the higher limit.

  7. kainino0x commented on Jan 5, 2021

    @kainino0x
    Contributor

    Scrolling through the vulkaninfo it looks like it's all ARM GPUs and roughly the most prominent/recent is ~Mali-G72 (2017Q4). ~Mali-T880 as well (2016Q1). It would be a bit of an availability hit but I think that's roughly contemporary with other requirements we've baked in already?

  8. Kangz commented on Jan 6, 2021

    @Kangz
    Contributor

    Sounds good, these devices likely have broken drivers anyway. We should revisit with lower limits if needed when we do webgpu-compat. Likewise maxTextureArrayLayers could be 2048 (it is the same situation as maxTexture3D)

  9. Richard-Yunchao commented on Jan 8, 2021

    @Richard-Yunchao
    Author

    Talked with Intel folks, it should be OK to set maxTextureArrayLayers and maxTextureDimension3D to 2048 on Intel devices, because only a small part of old Intel devices on some Linux distributions (and some old Android devices) can't guarantee that. The vast majority of devices can guarantee 2048 or bigger value.

    So the proposed max values are:

    Parameters Value
    maxTextureDimension1D 8192
    maxTextureDimension2D 8192
    maxTextureDimension3D 2048
    maxTextureArrayLayers 2048

    And we can lower limits if needed when we do webgpu-compat, just as Corentin said.

  10. Kangz commented on Jan 11, 2021

    @Kangz
    Contributor

    Closing as the PR has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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