Jump to content

  • Log In with Google      Sign In   
  • Create Account

[DX11] InterlockedMin works wrong?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 user88   Members   -  Reputation: 268

Like
0Likes
Like

Posted 07 December 2012 - 07:03 AM

hello,

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, 07 December 2012 - 07:04 AM.


Sponsor:

#2 user88   Members   -  Reputation: 268

Like
0Likes
Like

Posted 07 December 2012 - 08:14 AM

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, 07 December 2012 - 09:39 AM.


#3 MJP   Moderators   -  Reputation: 11343

Like
1Likes
Like

Posted 07 December 2012 - 04:47 PM

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.

#4 user88   Members   -  Reputation: 268

Like
0Likes
Like

Posted 10 December 2012 - 09:10 AM

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


#5 MJP   Moderators   -  Reputation: 11343

Like
0Likes
Like

Posted 10 December 2012 - 01:18 PM

The MSDN documentation says that it takes a uint.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS