Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Synchronizing Compute Shader


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 gfxCahd   Members   -  Reputation: 204

Like
0Likes
Like

Posted 22 March 2014 - 09:10 AM

I have a single compute shader that has two distinct steps.
I need the first step to be finished, before starting the second step
(i.e. threads in the second step use data that could be produced by any thread in the previous step).
 
I have separated the two steps into two functions in my compute shader.
Is there a way to synchronize them inside the compute shader?
Or do I need to do it by calling Dispatch twice, and run one of the methods depending on the value in a cbuffer?

[numthreads(128, 1, 1)]

void CSMAIN(uint3 DispatchThreadID : SV_DispatchThreadID, uint GroupID : SV_GroupID)
{
  if (DispatchThreadID.x < N)
  {
    StepOne(DispatchThreadID.x);    
    //synchronization here?
    StepTwo(DispatchThreadID.x);
  }
}

Edited by gfxCahd, 22 March 2014 - 09:11 AM.


Sponsor:

#2 gfxCahd   Members   -  Reputation: 204

Like
0Likes
Like

Posted 22 March 2014 - 09:27 AM

p.s. I guess the following command does not fit my needs, since it only syncs groups, but not all of my threads.

 

AllMemoryBarrierWithGroupSync function

Blocks execution of all threads in a group until all memory accesses have been completed and all threads in the group have reached this call.

http://msdn.microsoft.com/en-us/library/windows/desktop/ff471351%28v=vs.85%29.aspx


Edited by gfxCahd, 22 March 2014 - 09:28 AM.


#3 jamesxli   Members   -  Reputation: 303

Like
0Likes
Like

Posted 22 March 2014 - 10:51 AM

How many groups do you dispatch? If you just dispatch one group, i.e. Disptach(1,1,1), the method GroupMemoryBarrierWithGroupSync() should work. To use this type of synchronization you need to setup a groupshared array and let each thread write once into that array after it has finished a step.



#4 gfxCahd   Members   -  Reputation: 204

Like
0Likes
Like

Posted 22 March 2014 - 11:27 AM

How many groups do you dispatch? If you just dispatch one group, i.e. Disptach(1,1,1), the method GroupMemoryBarrierWithGroupSync() should work. To use this type of synchronization you need to setup a groupshared array and let each thread write once into that array after it has finished a step.

 

 

Actualy I'm using a variable amount of groups (the amount of threads per group is fixed, the amount of groups depends on the size of the input/problem).

 

Could you maybe elaborate on the groupshared array method? Not sure I understand how it should work.


Edited by gfxCahd, 22 March 2014 - 11:27 AM.


#5 MJP   Moderators   -  Reputation: 11590

Like
1Likes
Like

Posted 22 March 2014 - 11:49 AM

The sync functions only work across thread groups. If you need a global sync point, then the easiest way to do it would be to split things into two Dispatch calls.



#6 gfxCahd   Members   -  Reputation: 204

Like
0Likes
Like

Posted 22 March 2014 - 11:51 AM

Ah ok, thanks!

 

Was hoping I could save 0.3 milliseconds or so in overhead, but it was not to be...


Edited by gfxCahd, 22 March 2014 - 11:52 AM.





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