How to synchronize in pixel shader with DeviceMemoryBarrier() function?

Started by
1 comment, last by Jason Z 8 years, 8 months ago

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.

Advertisement

I do not know how to use DeviceMemoryBarrier() funcution to to synchronize in a pixel shader.

Synchronize with what?

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.

This is not a well formed sentence and I have no idea what you are trying to say.

(After much thought) maybe I am being completely thrown off by the extra comma at the end? Restate this sentence clearly.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid


if (Fragment.ObjID == Objects[count].ObjID && Shaded[count] == 0)

Aren't you reading from the Shaded[] array without any protection here? How do you ensure that Shaded is synchronized across all of the threads between when you read it and write it? That is the issue - your method of synching right now is not correct. You should test with the atomic InterlockedAdd, then determine if you should do the operation based on the old_val.

Can you also show your declaration of the Shaded[] array? Is it group shared, or is it device memory?

This topic is closed to new replies.

Advertisement