• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By isu diss
      How do I fill the gap between sky and terrain? Scaling the terrain or procedural terrain rendering?

    • By Jiraya
      For a 2D game, does using a float2 for position increases performance in any way?
      I know that in the end the vertex shader will have to return a float4 anyway, but does using a float2 decreases the amount of data that will have to be sent from the CPU to the GPU?
       
    • By ucfchuck
      I am feeding in 16 bit unsigned integer data to process in a compute shader and i need to get a standard deviation.
      So I read in a series of samples and push them into float arrays
      float vals1[9], vals2[9], vals3[9], vals4[9]; int x = 0,y=0; for ( x = 0; x < 3; x++) { for (y = 0; y < 3; y++) { vals1[3 * x + y] = (float) (asuint(Input1[threadID.xy + int2(x - 1, y - 1)].x)); vals2[3 * x + y] = (float) (asuint(Input2[threadID.xy + int2(x - 1, y - 1)].x)); vals3[3 * x + y] = (float) (asuint(Input3[threadID.xy + int2(x - 1, y - 1)].x)); vals4[3 * x + y] = (float) (asuint(Input4[threadID.xy + int2(x - 1, y - 1)].x)); } } I can send these values out directly and the data is as expected

                             
      Output1[threadID.xy] = (uint) (vals1[4] ); Output2[threadID.xy] = (uint) (vals2[4] ); Output3[threadID.xy] = (uint) (vals3[4] ); Output4[threadID.xy] = (uint) (vals4[4] ); however if i do anything to that data it is destroyed.
      If i add a
      vals1[4] = vals1[4]/2; 
      or a
      vals1[4] = vals[1]-vals[4];
      the data is gone and everything comes back 0.
       
       
      How does one go about converting a uint to a float and performing operations on it and then converting back to a rounded uint?
    • By fs1
      I have been trying to see how the ID3DInclude, and how its methods Open and Close work.
      I would like to add a custom path for the D3DCompile function to search for some of my includes.
      I have not found any working example. Could someone point me on how to implement these functions? I would like D3DCompile to look at a custom C:\Folder path for some of the include files.
      Thanks
    • By stale
      I'm continuing to learn more about terrain rendering, and so far I've managed to load in a heightmap and render it as a tessellated wireframe (following Frank Luna's DX11 book). However, I'm getting some really weird behavior where a large section of the wireframe is being rendered with a yellow color, even though my pixel shader is hard coded to output white. 

      The parts of the mesh that are discolored changes as well, as pictured below (mesh is being clipped by far plane).

      Here is my pixel shader. As mentioned, I simply hard code it to output white:
      float PS(DOUT pin) : SV_Target { return float4(1.0f, 1.0f, 1.0f, 1.0f); } I'm completely lost on what could be causing this, so any help in the right direction would be greatly appreciated. If I can help by providing more information please let me know.
  • Advertisement
  • Advertisement
Sign in to follow this  

DX11 HLSL race condition when writing to shared memory passed to function

Recommended Posts

I have code like this:

groupshared uint tempData[ElementsCount];

[numthreads(ElementsCount/2, 1, 1)]
void CSMain(uint3 gID: SV_GroupID, uint3 gtID: SV_GroupThreadID)
{
    tempData[gtID.x] = 0;
}

And it works fine. Now I change it to this:

void MyFunc(inout uint3 gtID: SV_GroupThreadID, inout uint inputData[ElementsCount])
{
    inputData[gtID.x] = 0;
}

groupshared uint tempData[ElementsCount];

[numthreads(ElementsCount/2, 1, 1)]
void CSMain(uint3 gID: SV_GroupID, uint3 gtID: SV_GroupThreadID)
{
    MyFunc(gtID, tempData);
}

and I get "error X3695: race condition writing to shared memory detected, consider making this write conditional.". Any way to go around this?

Share this post


Link to post
Share on other sites
Advertisement

Based on a quick search I found these:

 

https://www.gamedev.net/topic/594131-dx11-compute-shader-race-condition-error-when-using-optimization-level-2-or-3/

http://xboxforums.create.msdn.com/forums/t/63981.aspx

 

Based on those it sounds like there might be a bug in certain versions of the compiler. I'd suggest trying to use either command line fxc.exe or a more recent version of the d3dcompiler dll to see if it makes any difference.

Share this post


Link to post
Share on other sites

I stumbled upon those threads as well and it's not it.

Also, I'm not really sure how to update my d3dcompiler. I'm using Windows 10 so I presume it gets updated automatically. Although I use Visual Studio 2013 so I cannot really be sure if the most up-to-date dll is used.

I found out that the problem appears even in this code:

static const int ElementsCount = 512;


groupshared uint tempData[2 * ElementsCount];


void MyFunc(inout uint3 gtID: SV_GroupThreadID, inout uint inputData[2 * ElementsCount])
{

}


[numthreads(ElementsCount, 1, 1)]
void CSMain(uint3 gID: SV_GroupID, uint3 gtID: SV_GroupThreadID)
{
    MyFunc(gtID, tempData);
}

Note that I don't even write anything to tempData in MyFunc.
I also found out the problem goes away if I remove the "inout" modifier but then the array just gets copied probably as the code doesn't work as expected.

Edited by maxest

Share this post


Link to post
Share on other sites

Yeah, I have D3dcompiler_47.dll indeed.

I did try. Forgot to mention that in previous post. The same problem persists.

Share this post


Link to post
Share on other sites

There is many version of d3dcompiler_47.dll, a very dumb idea…

If your shader just compile from visual studio as a hlsl source file, the fxc and dll you use is probably bound to the windows sdk that is setup in your project.

 

Not saying that getting the latest one would solve this, but you may still run an outdated compiler :)

Share this post


Link to post
Share on other sites

I've reproduced the behaviour, and simplified the case that goes wrong. Here's my minimal failing case:

groupshared uint tempData[1];

void MyFunc(inout uint inputData[1])
{
}

[numthreads(2, 1, 1)]
void CSMain()
{
    MyFunc(tempData);
}

It looks like just passing the argument to the function is enough to make it fail to compile.

Here's a workaround for the problem - don't pass the array as a function argument:

#define ElementsCount 256

groupshared uint tempData[ElementsCount];

void MyFunc(in uint3 gtID)
{
      tempData[gtID.x] = 0;
}

[numthreads(ElementsCount/2, 1, 1)]
void CSMain(uint3 gID: SV_GroupID, uint3 gtID: SV_GroupThreadID)
{
    MyFunc(gtID);
}

Share this post


Link to post
Share on other sites

Yeah, I'm perfectly aware of that workaround and I do it this way. But because I can't pass a shared memory array to function I can't make the function more general. Instead I need to copy it to a few files I use it in.

Share this post


Link to post
Share on other sites

I found a better workaround. So simple I can't imagine how I could had not come up with it before. I just used macro.

Still, would be nice if this bug was fixed. In the meantime I will be using macros on functions getting shared buffers as input.

Share this post


Link to post
Share on other sites

In the latest Xbox compiler the alleged race condition is just a warning rather than an error like it is in the 15063 Windows SDK. I've added a bug to make sure it's neither.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement