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

Investigation: Sampling Depth Textures #659

@Jiawei-Shao

Description

@Jiawei-Shao

Sampling a depth texture is useful for some post-processing effects with depth textures. In this report we will talk about how to support sampling depth textures in WebGPU.

Depth Texture Formats

The following table summarizes the supports of sampling on all depth texture formats.

Note that on D3D12, it is allowed to create a texture in TYPELESS formats, on which we can create a shader resource view (SRV) with the format in the same group of the TYPELESS format. For example, considering texture in R32_TYPELESS format, and we can create both an SRV in R32_FLOAT format and a depth stencil view (DSV) in D32_FLOAT format.

On Metal, the reinterpretation of image data between pixel formats is supported within the groups listed in this Metal document, where none of the depth formats are supported. So we can conclude that it is not allowed to create a Metal texture view in a color format over an existing Metal texture in a depth format.

Vulkan SPEC requires that "each depth/stencil format is only compatible with itself" (Vulkan SPEC Chapter 39.1.6), so it is not allowed to create a Vulkan image view in color formats over an image in depth formats.

Another restriction in Vulkan is that none of the depth formats are required to support VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT, while in D3D12 and Metal there is no such limitation.

Depth Texture Formats Supported in WebGPU Support sampling in D3D12 ("Shader sample (any filter)") Support filtering in Metal (Metal-Feature-Set-Tables, Page 9) Support sampling in Vulkan (Vulkan SPEC Table 58)
depth32float Yes Yes (R32_FLOAT) macOS 10.11+, no iOS Yes
depth24unorm-stencil8 Yes (depth24plus-stencil8) Yes (R24_UNORM_X8_TYPELESS) macOS 10.11+ with depth24Stencil8PixelFormatSupported, no iOS No
depth32float-stencil8 Yes (depth24plus-stencil8) Yes (R32_FLOAT_X8X24_TYPELESS) macOS 10.11+, no iOS No
depth16unorm No Yes (R16_UNORM) macOS 10.12+, iOS 13.0+ Yes

Proposal

According to the table in the last chapter, we can conclude that there is no depth format that can be sampled on all WebGPU back-ends because of the limitations on Metal. As it is still useful to support sampling a depth texture, we suggest introducing the following two extensions:

  • Support depth16unorm as a new texture format, which can be exposed as a depth format that supports sampling on D3D12, Vulkan, macOS 10.12+ and iOS 13.0.
  • Support sampling with depth textures on depth32float, which can be exposed on D3D12, Vulkan and macOS 10.11+.
  • Only allow nearest filter on depth formats because of the limitation on Vulkan.

There are bigger limitations on the support of sampling with depth24unorm-stencil8 and depth32float-stencil8 so currently we don't consider them here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    copyeditingPure editorial stuff (copyediting, *.bs file syntax, etc.)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions