Jump to content

View more

Image of the Day

Adding some finishing touches...
Follow us for more
#screenshotsaturday #indiedev... by #MakeGoodGames https://t.co/Otbwywbm3a
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Buffer as both StructuredBuffer & RWStructuredBuffer

4: Adsense
  • You cannot reply to this topic
3 replies to this topic

#1 hiya83   Members   


Posted 19 May 2017 - 05:13 PM

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?


#2 hiya83   Members   


Posted 19 May 2017 - 05:25 PM

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, 19 May 2017 - 05:26 PM.

#3 galop1n   Members   


Posted 20 May 2017 - 12:19 PM

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.

#4 MJP   Moderators   


Posted 20 May 2017 - 03:16 PM

If you enable the debug layer for your device (which you should *definitely* do for debug builds), you will get error messages when you have a resource simultaneously bound as both an input (SRV) and an output (RTV or UAV).