_xiaofang/xiaofang/Assets/Obi/Resources/Compute/InterlockedUtils.cginc
杨号敬 bcc74f0465 add
2024-12-18 02:18:45 +08:00

46 lines
913 B
HLSL

#ifndef INTERLOCKEDUTILS_INCLUDE
#define INTERLOCKEDUTILS_INCLUDE
void InterlockedAddFloat(RWStructuredBuffer<uint4> buffer, int index, int axis, float value)
{
uint i_val = asuint(value);
uint tmp0 = 0;
uint tmp1;
[allow_uav_condition]
while (true)
{
InterlockedCompareExchange(buffer[index][axis], tmp0, i_val, tmp1);
if (tmp1 == tmp0)
break;
tmp0 = tmp1;
i_val = asuint(value + asfloat(tmp1));
}
return;
}
void InterlockedAddFloat(RWStructuredBuffer<uint> buffer, int index, float value)
{
uint i_val = asuint(value);
uint tmp0 = 0;
uint tmp1;
[allow_uav_condition]
while (true)
{
InterlockedCompareExchange(buffer[index], tmp0, i_val, tmp1);
if (tmp1 == tmp0)
break;
tmp0 = tmp1;
i_val = asuint(value + asfloat(tmp1));
}
return;
}
#endif