Jump to content
  • Advertisement
Sign in to follow this  
user88

DX11 [DX11] InterlockedMin works wrong?

This topic is 2050 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

hello,

[size=2]code snippet from Compute Shader 5.0:

groupshared int3 sMin;
...
InterlockedMin(sMin.x, asint(viewPosition.x));
...

In code snippet above there is groupshared variable that holds minimum position value across the thread group. I noticed the case that the InterlockedMin works wrong when sMin.x == 0 and viewPosition == some_negaive_sign_value. After the operation sMin.x == 0.

Question: why negative value doesn't take as minimal value? In documentation mentioned that uint and int types are supported by InterlockedMin, so the sine should takes in account in case of int type.

I use nSight to profiler via network to debug shaders. The graphics adapter on target PC is GeForce GTX 460.

Any help would be appreciated.. Edited by user88

Share this post


Link to post
Share on other sites
Advertisement
I found work around simply inverting sign bit. For those who are interested:

groupshared uint3 sMin;
...
uint3 InvertSignBit(uint3 value)
{
return ((~value) & uint3(0x80000000, 0x80000000, 0x80000000)) | (value & uint3(0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF));
}
...
InterlockedMin(sMin.x, InvertSignBit(asint(viewPosition).x);
...
GroupMemoryBarrierWithGroupSync();
uint3 signedSMin = InvertSignBit(sMin);
float3 minViewPosition = asfloat(signedSMin);


Edit:
No.. Unfortunately this is not a solution. Min for values with negative sing is wrong. Edited by user88

Share this post


Link to post
Share on other sites
InterlockedMin takes a uint parameter, hence it only works with unsigned integers. If you pass it an int, it will treat it as an unsigned integer which will cause negative numbers to be treated as greater than positive numbers.

Share this post


Link to post
Share on other sites
Ok, thanks for answer MJP. Strange why Microsoft didn't noticed it in MSDN?..

For those who are interested in work around, i use two functions for signed values (this time the code is working <_<) :

uint IntToUIntInRange(uint value)
{
if ((value & 0x80000000) == 0)
{
return 0x80000000 | value;
}
else
{
return ~value;
}
}
uint UIntToIntInRange(uint value)
{
if ((value & 0x80000000) != 0)
{
return 0x7FFFFFFF & value;
}
else
{
return ~value;
}
}

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!