I am trying to read the contents of the depth buffer into main memory so that my CPU side code can do Some Stuff™ with it.

I am attempting to do this by creating a staging resource which can be read by the CPU, which I will copy the contents of the depth buffer into before reading it. I keep encountering errors however, because of, I believe, incompatibilities between the resource format and the view formats.

Threads like these lead me to believe it is possible in DX11 to access the depth buffer as a resource, and that I can create a resource with a typeless format and have it interpreted in the view as another, but I cannot get it to work.

What are the valid formats for the resource to be used as the depth buffer? Which of these are also valid for a CPU accessible staging resource?


1 Answer 1


The valid formats for typeless Direct3D11 depth buffer are:

DepthStencilBuffer: DXGI_FORMAT_R16_TYPELESS (instead of typical DXGI_FORMAT_D16_UNORM)
DepthStencilBufferView: DXGI_FORMAT_R16_FLOAT

DepthStencilBuffer: DXGI_FORMAT_R32_TYPELESS (instead of typical DXGI_FORMAT_D32_FLOAT)
DepthStencilBufferView: DXGI_FORMAT_R32_FLOAT

DepthStencilBuffer: DXGI_FORMAT_R24G8_TYPELESS (instead of typical DXGI_FORMAT_D24_UNORM_S8_UINT)

DepthStencilBuffer: DXGI_FORMAT_R32G8X24_TYPELESS (instead of typical DXGI_FORMAT_D32_FLOAT_S8X24_UINT)
DepthStencilBufferView: DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS

Using this format when declaring a depth stencil buffer, you should be able to copy the depth buffer to another R16_FLOAT/R32_FLOAT...etc. texture.

On a side note, it is often not recommended to read back data on the CPU because of the latency that will be introduced. Current techniques - on Windows Direct3D11 - tend to perform typical CPU computation on the GPU with DirectCompute.

  • \$\begingroup\$ Thank you, that is just what I needed. I have created an R24G8_Typeless buffer with a D24_UNorm_S8_UInt DepthStencilView and a R24_UNorm_X8_Typeless staging resource. I was not aware of DirectCompute but it looks like something I definitely want to know, thanks! \$\endgroup\$
    – sebf
    Commented Apr 3, 2012 at 15:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .