Fix out-of-bounds shader thread shuffle (#2605)

* Fix out-of-bounds shader thread shuffle

* Shader cache version bump
This commit is contained in:
gdkchan 2021-08-30 14:02:40 -03:00 committed by GitHub
parent 82cefc8dd3
commit 416dc8fde4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 7 deletions

View File

@ -40,7 +40,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
/// <summary>
/// Version of the codegen (to be changed when codegen or guest format change).
/// </summary>
private const ulong ShaderCodeGenVersion = 2546;
private const ulong ShaderCodeGenVersion = 2605;
// Progress reporting helpers
private volatile int _shaderCount;

View File

@ -6,5 +6,6 @@ float Helper_Shuffle(float x, uint index, uint mask, out bool valid)
uint maxThreadId = minThreadId | (clamp & ~segMask);
uint srcThreadId = (index & ~segMask) | minThreadId;
valid = srcThreadId <= maxThreadId;
return valid ? readInvocationARB(x, srcThreadId) : x;
float v = readInvocationARB(x, srcThreadId);
return valid ? v : x;
}

View File

@ -6,5 +6,6 @@ float Helper_ShuffleDown(float x, uint index, uint mask, out bool valid)
uint maxThreadId = minThreadId | (clamp & ~segMask);
uint srcThreadId = gl_SubGroupInvocationARB + index;
valid = srcThreadId <= maxThreadId;
return valid ? readInvocationARB(x, srcThreadId) : x;
float v = readInvocationARB(x, srcThreadId);
return valid ? v : x;
}

View File

@ -1,9 +1,9 @@
float Helper_ShuffleUp(float x, uint index, uint mask, out bool valid)
{
uint clamp = mask & 0x1fu;
uint segMask = (mask >> 8) & 0x1fu;
uint minThreadId = gl_SubGroupInvocationARB & segMask;
uint srcThreadId = gl_SubGroupInvocationARB - index;
valid = srcThreadId >= minThreadId;
return valid ? readInvocationARB(x, srcThreadId) : x;
valid = int(srcThreadId) >= int(minThreadId);
float v = readInvocationARB(x, srcThreadId);
return valid ? v : x;
}

View File

@ -6,5 +6,6 @@ float Helper_ShuffleXor(float x, uint index, uint mask, out bool valid)
uint maxThreadId = minThreadId | (clamp & ~segMask);
uint srcThreadId = gl_SubGroupInvocationARB ^ index;
valid = srcThreadId <= maxThreadId;
return valid ? readInvocationARB(x, srcThreadId) : x;
float v = readInvocationARB(x, srcThreadId);
return valid ? v : x;
}