Jump to content
  • Advertisement
Sign in to follow this  
Quat

RWStructuredBuffer

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

So the RWStructuredBuffer is read/write. Can you read/write at the same time. For example, let's say the buffer was initialized. In the compute shader could you do something like this (pseuoish code):

buffer[x] = 2*buffer[x];

If you can do this, aren't there synchronization problems if you read neighboring elements? You wouldn't know if they were updated yet since they run in different thread groups.

Share this post


Link to post
Share on other sites
Advertisement

So the RWStructuredBuffer is read/write. Can you read/write at the same time. For example, let's say the buffer was initialized. In the compute shader could you do something like this (pseuoish code):

buffer[x] = 2*buffer[x];

If you can do this, aren't there synchronization problems if you read neighboring elements? You wouldn't know if they were updated yet since they run in different thread groups.


Well, you can't actually operate on a structured buffer element like that. You must operate on one of its intrinsic data members. For example like, float a = 2 * buffer[x].FloatA;. Using the fxc compiler to compile the code you wrote would yield "error X3022: scalar, vector, or matrix expected".

Share this post


Link to post
Share on other sites
Hi, that was just pseudocode to explain the read/write process I want to know about.

Share this post


Link to post
Share on other sites

Hi, that was just pseudocode to explain the read/write process I want to know about.


But the pseudo code was meaningless.

Anyway, from what you've written I'll make a guess as to what you actually mean in an effort to help more. I'm going to assume you actually want to operate on a member of the element in the buffer. So we have pseudo code like this, buffer[x].intA = 2 * buffer[x].intA;.

This will generate an error due to a race condition as you guessed in your OP.

What you need to implement is an atomic operation. Unfortunately for multiplication that is not possible in HLSL.

But it is possible for an addition. So the above should be re-written as, InterlockedAdd(buffer[x].intA,buffer[x].intA). That should work fine.

Share this post


Link to post
Share on other sites

If you can do this, aren't there synchronization problems if you read neighboring elements? You wouldn't know if they were updated yet since they run in different thread groups.


Of course there are, which is why doing that is a bad idea :P

You should either use shared memory (possibly adding an "apron" of threads around each group), or add an implicit sync by splitting your technique into multiple Dispatch calls.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!