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 valueDXGI_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?
R24G8_TYPELESS
, DSV asD24_UNORM_S8_UINT
and SRV asR24_UNORM_X8_TYPELESS
. – Waw