Jump to content

  • Log In with Google      Sign In   
  • Create Account


Compute Shader ThreadGroup Order


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Alundra   Members   -  Reputation: 770

Like
0Likes
Like

Posted 26 January 2014 - 08:41 AM

Hi all,

Compute shader works using a split of work by ThreadGroup.

You can use a groupshared to have a cache to reuse data with the next ThreadGroup.

The problem is if you want to store an offset based on each cell who has a count the order is important.

My question is simple : Compute Shader works using a linear dispatch ?

I mean, does it work running thread group left to right and top to bottom ?

Thanks



Sponsor:

#2 Jason Z   Crossbones+   -  Reputation: 4676

Like
1Likes
Like

Posted 26 January 2014 - 08:57 AM

It isn't entirely clear what you are asking for here, so I'll take my best shot.  The way that you define your thread group and dispatch dimensions is usually intended to model your dataset that is being processed.  Generally, if the data set is a 2D texture, then your dispatch and thread groups are sized accordingly to address chunks of the 2D region (and your z coordinates will be 1).  Alternatively, if you are processing a 1D buffer of data, then you would just use the x-coordinate for addressing.

 

The linear index for a complete dispatch is available in the SV_GroupIndex, which includes all thread groups together.  This is good when you are processing a linearly stored data set.  Otherwise you can choose one of the other System Value semantics (SV_GroupID, SV_GroupThreadID, or SV_DispatchThreadID) to get a better addressing for your problem.

 

The group shared memory is intended for sharing intermediate results among the threads in a thread group.  So typically you would use the SV_GroupThreadID system value to address it, since it is local to the thread group.  If you wanted a linear index for your group shared, then you can either choose a 1D thread group shape, or you can flatten your indices manually based on the shape of the thread group.  However, I would highly recommend to just choose your thread group shape according to the data you are processing so that you can skip any additional math in your shader.

 

Does that help clarify the issue?



#3 MJP   Moderators   -  Reputation: 10218

Like
0Likes
Like

Posted 26 January 2014 - 02:43 PM

Like Jason mentioned, group shared memory is only for sharing data within a single thread group. You can't use it to share memory with other thread groups. There's also no ordering guarantees on thread groups (the hardware can and will execute multiple thread groups in parallel) so you can't rely on that in your algorithms.



#4 Alundra   Members   -  Reputation: 770

Like
0Likes
Like

Posted 26 January 2014 - 04:29 PM

Thanks for answer.
The problem is I need to store a list of indices in an array and I need to store a StartOffset.

The data need to be ordored so, and the only way found is to not use sync and has worst case indices buffer size.

That work but that use a lot of wasted memory (width*height*depth*MaxIndex).

No workaround exist to avoid this ? On CPU it's easy since the offset just need to be added by one each time an index is added.



#5 MJP   Moderators   -  Reputation: 10218

Like
0Likes
Like

Posted 26 January 2014 - 06:18 PM

You'll want to use an AppendStructuredBuffer for this. It essentially has a hidden counter, and whenever you call Append it will perform a global atomic on the counter value. Just keep in mind that the resulting order of the elements will be non-deterministic in most cases, since the appends are happening in parallel.



#6 Alundra   Members   -  Reputation: 770

Like
0Likes
Like

Posted 26 January 2014 - 06:58 PM

Ok but still the problem of start offset.

The data needs to be StartOffset and Count (uint2).

Read the length of the buffer as start offset ?

The start offset and the order of indices who is added is important.


Edited by Alundra, 26 January 2014 - 07:03 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS