I do not know how to use DeviceMemoryBarrier() funcution to to synchronize in a pixel shader. In my situation, if a rasterized fragment has the same object ID (objID) with the current object ID and this object is not shaded, then compute its color.
for (uint count = 0; count < NumOfObj; count++)
{
// DeviceMemoryBarrier();
if (Fragment.ObjID == Objects[count].ObjID && Shaded[count] == 0)
{
// DeviceMemoryBarrier();
uint old_val = 0;
InterlockedAdd(Shaded[count], 1, old_val);
// Shading
break;
}
}
// DeviceMemoryBarrier();
My problem is that an object is shaded twice. I have tried to place DeviceMemoryBarrier() function in many places but it does not work.
Is there any idea? Please help me.