Hi. I try to synchronnize thread groups at some point. The main idea is to make groups execute successively one at a time while others are just looping waiting. It looks something like this:
g_var is a RWBuffer variable, initially set to g_numGroups-1
[allow_uav_condition] do
{
if(groupID == g_var)
{
if(groupID == 0)
g_var = g_numGroups-1;
else
g_var -= 1;
break;
}
}while(true);
[allow_uav_condition] do
{
if(g_var == g_numGroups-1)
break;
}while(true);
So, the first group to break from the first loop would be the group with the highest index, actually it should not stay there at all. Then so do the others. They get caught in the second loop and loop there until the group with index 0 restores the initial value of g_var and they come through altogether. I just want that all the groups contribute to the same variable, so it can be used later by all groups. I ommited this part. I also ommited some details like setting g_var with threads with 0 index in each group, just want to convey the idea. The second loop is not a problem, but apparentely threads get caught in the first one and stay there, and the card stops responding. I just can not see where i make mistake. Could anyone help me pointing out what is wrong and maybe suggest another way to do this. Thanks
I know I can break the code into pieces and synchronize it with another dispatch call. But the code itself is in a for loop, so it would involve changing a shader or a constant buffer several times. I thought maybe it is more efficient to stall them like they would anyway at the end of any code just waiting for other groups to complete.