• Advertisement
Sign in to follow this  

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

This topic is 1004 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Edited by L. Spiro

Share this post


Link to post
Share on other sites

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?

Edited by Jason Z

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement