Does D3D11_BIND_UNORDERED_ACCESS and D3D11_BIND_SHADER_RESOURCE should be always used together?

Started by
3 comments, last by Hodgman 8 years, 7 months ago

Hello.

I'm creating a simple program with one buffer and one only compute shader. Every examples I've seen so far used


csDataBufferDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;

It makes sense - this buffer will be used in a shader so it have to be a shader resource, right? Also I'm reading and writing to any place in it so it have to be unordered. But I tried and for me this also works:


csDataBufferDesc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;

How it's possible? Why do we need this D3D11_BIND_SHADER_RESOURCE at all?

Advertisement

"Shader resource" means it can be bound with *SSetShaderResources on the CPU side, and a t# register on the HLSL side (Buffer, Texture#D, etc).
"Unordered access" means it can be bound with OMSetRenderTargetsAndUnorderedAccessViews and/or CSSetUnorderedAccessViews on the CPU side, and a u# register on the HLSL side (RWBuffer, RWTexture#D, etc).

Setting both flags on a buffer means that you want to be able to use it sometimes as a RWBuffer, and sometimes as a regular (read-only) Buffer.
However, you can't ever use it as both types at once in the same shader:

Note The runtime enforces certain usage patterns when you create multiple view types to the same resource. For example, the runtime does not allow you to have both a UAV mapping for a resource and SRV mapping for the same resource active at the same time.


An example where you'd want to use both flags is where a compute shader generates texture data and writes it into a RWTexture2D, and then later a regular pixel shader wants to sample that data from it as a Texture2D.

Thank you for the explanation. It's much clearer for me now. But I think you're mistaken (a typo?) in a couple of moments:


"Shader resource" means it can be bound with *SSetShaderResources on the CPU side, and a u# register on the HLSL side (RWBuffer, RWTexture#D, etc).

But in order to write somewhere I have to use UAV, so RWBuffer is not a shader resource but UAV, right?

According to documentation (https://msdn.microsoft.com/en-us/library/windows/desktop/dd607359(v=vs.85).aspx) u# register is used for Unordered Access View and t# for Texture and texture buffer and buffers.

Yep UAV are bound to register u*, which makes them non-SRV's.

Ignore please


Thank you for the explanation. It's much clearer for me now. But I think you're mistaken (a typo?)
Yes that was a bad typo! I put the opposite registers and HLSL types... ohmy.png

This topic is closed to new replies.

Advertisement