Jump to content
  • Advertisement
Sign in to follow this  
Volgogradetzzz

Does D3D11_BIND_UNORDERED_ACCESS and D3D11_BIND_SHADER_RESOURCE should be always used together?

This topic is 1032 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
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.

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


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!