Ryujinx/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/ShuffleXor.glsl
gdkchan 416dc8fde4
Fix out-of-bounds shader thread shuffle (#2605)
* Fix out-of-bounds shader thread shuffle

* Shader cache version bump
2021-08-30 14:02:40 -03:00

11 lines
No EOL
434 B
GLSL

float Helper_ShuffleXor(float x, uint index, uint mask, out bool valid)
{
uint clamp = mask & 0x1fu;
uint segMask = (mask >> 8) & 0x1fu;
uint minThreadId = gl_SubGroupInvocationARB & segMask;
uint maxThreadId = minThreadId | (clamp & ~segMask);
uint srcThreadId = gl_SubGroupInvocationARB ^ index;
valid = srcThreadId <= maxThreadId;
float v = readInvocationARB(x, srcThreadId);
return valid ? v : x;
}