Which format to use for a shader resource view into depth-stencil buffer resource?
Asked Answered
W

1

5

The depth-stencil buffer resource is defined as DXGI_FORMAT_D24_UNORM_S8_UINT format.


I would have assumed that to create a shader resource view (SRV) into that resource would require the view format to be described either as:

  • DXGI_FORMAT_R24_UNORM_X8_TYPELESS where red channel accesses depth value
  • DXGI_FORMAT_R24G8_TYPELESS where red channel accesses depth and green channel stencil value

However, creating such SRV fails with the following error:

D3D12 ERROR: ID3D12Device::CreateShaderResourceView: For the resource format D24_UNORM_S8_UINT, when making a D3D view, the format name for the view can't be R24_UNORM_X8_TYPELESS. See documentation for the set of valid view format names for this resource format, determining which how the resource (or part of it) will appear to shader. [ STATE_CREATION ERROR #28: CREATESHADERRESOURCEVIEW_INVALIDFORMAT]

Looking into API doc yielded me with the following piece of information:

When viewing a resource, the resource-view description must specify a typed format, that is compatible with the resource format. So that means that you can't create a resource-view description using any format with _TYPELESS in the name. You can however view a typeless resource by specifying a typed format for the view.


I don't really understand why a typeless format is not allowed and which format should I use instead?

Waw answered 13/8, 2016 at 14:11 Comment(0)
S
9

It is the opposite, you create the resource with typeless components and you specialize the resource in a view with the final representation you need. Since you gave the resource stencil a uint representation already, you are stuck with it.

Saundrasaunter answered 13/8, 2016 at 23:24 Comment(1)
Thanks, that makes perfect sense! I ended up defining the resource as R24G8_TYPELESS, DSV as D24_UNORM_S8_UINT and SRV as R24_UNORM_X8_TYPELESS.Waw

© 2022 - 2024 — McMap. All rights reserved.