Sign in to follow this  

Does D3D11_BIND_UNORDERED_ACCESS and D3D11_BIND_SHADER_RESOURCE should be always used together?

This topic is 819 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites

"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.

Edited by Hodgman
fixed typos

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

This topic is 819 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this