[DX11] InterlockedMin works wrong?

Started by
3 comments, last by MJP 11 years, 4 months ago
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..
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.
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.
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;
}
}
The MSDN documentation says that it takes a uint.

This topic is closed to new replies.

Advertisement