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 inttypes 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.
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;
}
}