Hey Guys,
I recently have a bug in related to atomic operation:
void InterlockedAddToUpdateQueue(uint3 u3BlockIdx) { uint uOrig = 1; InterlockedOr( tex_uavBlockStateVol[u3BlockIdx], BLOCKSTATEMASK_UPDATE, uOrig); if ((uOrig & BLOCKSTATEMASK_UPDATE) == 0) { AddToUpdateQueue(u3BlockIdx); } }
So the above is a compute shader function. In my cases, there will be multiple threads from different (or same) threadgroup calling this function try to add u3BlockIdx to UpdateQueue (some thread may call this function with same u3BlockIdx). And I hope to only add unique u3BlockIdx to UpdateQueue, so I made up the above function. The basic idea is that I maintain a flag volume (I just use one bit of a exist block volume so this won't give me lots of memory pressure, and tex_uavBlockStateVol is the UAV of that volume ). Then if one thread try to add its u3BlockIdx, it will flag the corresponding bit in the volume, and since I was doing a interlockedor, I can get the original value on that location, and use that to check whether u3BlockIdx is already added to the UpdateQueue.
The idea is very straight forward. But my UpdateQueue still have so many duplicated u3BlockIdx. So I guess I may do something terribly wrong, and hope you guys could help me figuring that out. And if someone have better idea to achieve what I want, any comments or suggestions will be greatly appreciated.
Thanks