将着色器资源视图用于深度模板缓冲区资源的哪种格式?

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

深度模板缓冲区资源定义为 DXGI_FORMAT_D24_UNORM_S8_UINT 格式。


我假设要在该资源中创建着色器资源视图 (SRV) 需要将视图格式描述为:

但是,创建此类 SRV 失败并出现以下错误:

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]

调查 API doc 让我得到以下信息:

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.


我不太明白为什么不允许使用无类型格式我应该使用哪种格式

恰恰相反,您使用无类型组件创建资源,并将资源专门化为具有所需最终表示的视图。由于您已经为资源模板提供了一个 uint 表示,因此您只能坚持使用它。