Jump to content
  • Advertisement
Sign in to follow this  
hiya83

Buffer as both StructuredBuffer & RWStructuredBuffer

This topic is 431 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

I am trying to use a buffer as a rwstructuredbuffer in one call and in another reuse that as a structuredbuffer to read the data from. However, that's not working. Can you not do that? There is no error thrown when binding the buffer as both ShaderResource & UnordererdAccess. It also works fine if I replace the StructuredBuffer with a RWStructuredBuffer in the reading call.

and I am also doing the following already:
- use StructuredBuffer<uint> : register(tx) vs RWStructuredBuffer<uint> : register(ux) in the shader
- use CSSetShaderResource for structured vs CSSetUnorderedAccessViews for rwstructured

I am hoping to use this buffer in different shaders (vs, ps, cs, but these are all different draw call/dispatches), and since rwstructuredbuffer is not usable in VS AFAIK, I was hoping I can bind it as both structured and rwstructured. Any thoughts?

Thanks!

Share this post


Link to post
Share on other sites
Advertisement

Ok i hate my life... apparently draw call bindings are different from dispatch bindings?? So the buffer when bound as UAV is written from a draw call pixel shader (i.e. bound using OMSetRenderTargetsAndUnorderedAccessViews to slot u1 since rtv defaults to u0). Then in the following dispatch that uses it as a SRV, I am calling CSSetUnorderedAccessViews with 2 other uav's, thinking that'll overwrite the ones from the previous draw call. Apparently not! I have to call OMSetRenderTargetsAndUnorderedAccessViews again with nulls before the dispatch otherwise it complains of double bind as srv/uav... I guess draw call and dispatch bind slots are separate??

Edited by hiya83

Share this post


Link to post
Share on other sites
You have to unbind from uav to srv because the driver may ( have to ) flush caches and set barriers to make sure your dispatch happen after everything from the draws is done and available to it.

Share this post


Link to post
Share on other sites

Sorry for very late response, but what I meant was this:

I have a resource with both uav & srv views, lets say uav0 & srv0, and I call things in following order:

OMSetRenderTargetsAndUnorderedAccessViews (rtv bound and uav0 bound to u1)
DrawIndexed
CSSetUnorderedAccessViews (some other uavs bound to u0 and u1) <------ this does not override the u1 binding above
CSSetShaderResources (srv0 bound to t0) <------- this fails since it complains resource already bound as uav
Dispatch

Hence it seems uav slots for dispatches and draws are not the same?

And you're right debug layer caught this, but I would have thought the CSSetUnorderedAccessViews call would have overridden u1 slot and essentially unbind the previous, guess not?..

Share this post


Link to post
Share on other sites

That's correct, the set of UAV's bound for the CS stage is distinct from the set that's bound for rendering stages. You need to clear the rendering UAV bindings before you can bind the resource as an SRV.

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!