From 63f1663fa959d8809d1762d99e9364565ba9b3d8 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Mon, 18 Oct 2021 20:24:15 -0300 Subject: Fix shader 8-bit and 16-bit STS/STG (#2741) * Fix 8 and 16-bit STG * Fix 8 and 16-bit STS * Shader cache version bump --- .../HelperFunctions/AtomicMinMaxS32Shared.glsl | 4 ++-- .../HelperFunctions/AtomicMinMaxS32Storage.glsl | 4 ++-- .../Glsl/HelperFunctions/HelperFunctionNames.cs | 5 +++++ .../Glsl/HelperFunctions/StoreSharedSmallInt.glsl | 23 ++++++++++++++++++++++ .../Glsl/HelperFunctions/StoreStorageSmallInt.glsl | 23 ++++++++++++++++++++++ 5 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/StoreSharedSmallInt.glsl create mode 100644 Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/StoreStorageSmallInt.glsl (limited to 'Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions') diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/AtomicMinMaxS32Shared.glsl b/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/AtomicMinMaxS32Shared.glsl index 9f8c641d..82b76bcc 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/AtomicMinMaxS32Shared.glsl +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/AtomicMinMaxS32Shared.glsl @@ -5,7 +5,7 @@ int Helper_AtomicMaxS32(int offset, int value) { oldValue = $SHARED_MEM$[offset]; newValue = uint(max(int(oldValue), value)); - } while (atomicCompSwap($SHARED_MEM$[offset], newValue, oldValue) != oldValue); + } while (atomicCompSwap($SHARED_MEM$[offset], oldValue, newValue) != oldValue); return int(oldValue); } @@ -16,6 +16,6 @@ int Helper_AtomicMinS32(int offset, int value) { oldValue = $SHARED_MEM$[offset]; newValue = uint(min(int(oldValue), value)); - } while (atomicCompSwap($SHARED_MEM$[offset], newValue, oldValue) != oldValue); + } while (atomicCompSwap($SHARED_MEM$[offset], oldValue, newValue) != oldValue); return int(oldValue); } \ No newline at end of file diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/AtomicMinMaxS32Storage.glsl b/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/AtomicMinMaxS32Storage.glsl index fc3af6a7..0862a71b 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/AtomicMinMaxS32Storage.glsl +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/AtomicMinMaxS32Storage.glsl @@ -5,7 +5,7 @@ int Helper_AtomicMaxS32(int index, int offset, int value) { oldValue = $STORAGE_MEM$[index].data[offset]; newValue = uint(max(int(oldValue), value)); - } while (atomicCompSwap($STORAGE_MEM$[index].data[offset], newValue, oldValue) != oldValue); + } while (atomicCompSwap($STORAGE_MEM$[index].data[offset], oldValue, newValue) != oldValue); return int(oldValue); } @@ -16,6 +16,6 @@ int Helper_AtomicMinS32(int index, int offset, int value) { oldValue = $STORAGE_MEM$[index].data[offset]; newValue = uint(min(int(oldValue), value)); - } while (atomicCompSwap($STORAGE_MEM$[index].data[offset], newValue, oldValue) != oldValue); + } while (atomicCompSwap($STORAGE_MEM$[index].data[offset], oldValue, newValue) != oldValue); return int(oldValue); } \ No newline at end of file diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/HelperFunctionNames.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/HelperFunctionNames.cs index 1ff127bb..54f35b15 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/HelperFunctionNames.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/HelperFunctionNames.cs @@ -13,5 +13,10 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl public static string ShuffleUp = "Helper_ShuffleUp"; public static string ShuffleXor = "Helper_ShuffleXor"; public static string SwizzleAdd = "Helper_SwizzleAdd"; + + public static string StoreShared16 = "Helper_StoreShared16"; + public static string StoreShared8 = "Helper_StoreShared8"; + public static string StoreStorage16 = "Helper_StoreStorage16"; + public static string StoreStorage8 = "Helper_StoreStorage8"; } } \ No newline at end of file diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/StoreSharedSmallInt.glsl b/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/StoreSharedSmallInt.glsl new file mode 100644 index 00000000..2f57b5ff --- /dev/null +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/StoreSharedSmallInt.glsl @@ -0,0 +1,23 @@ +void Helper_StoreShared16(int offset, uint value) +{ + int wordOffset = offset >> 2; + int bitOffset = (offset & 3) * 8; + uint oldValue, newValue; + do + { + oldValue = $SHARED_MEM$[wordOffset]; + newValue = bitfieldInsert(oldValue, value, bitOffset, 16); + } while (atomicCompSwap($SHARED_MEM$[wordOffset], oldValue, newValue) != oldValue); +} + +void Helper_StoreShared8(int offset, uint value) +{ + int wordOffset = offset >> 2; + int bitOffset = (offset & 3) * 8; + uint oldValue, newValue; + do + { + oldValue = $SHARED_MEM$[wordOffset]; + newValue = bitfieldInsert(oldValue, value, bitOffset, 8); + } while (atomicCompSwap($SHARED_MEM$[wordOffset], oldValue, newValue) != oldValue); +} \ No newline at end of file diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/StoreStorageSmallInt.glsl b/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/StoreStorageSmallInt.glsl new file mode 100644 index 00000000..f2253a79 --- /dev/null +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/StoreStorageSmallInt.glsl @@ -0,0 +1,23 @@ +void Helper_StoreStorage16(int index, int offset, uint value) +{ + int wordOffset = offset >> 2; + int bitOffset = (offset & 3) * 8; + uint oldValue, newValue; + do + { + oldValue = $STORAGE_MEM$[index].data[wordOffset]; + newValue = bitfieldInsert(oldValue, value, bitOffset, 16); + } while (atomicCompSwap($STORAGE_MEM$[index].data[wordOffset], oldValue, newValue) != oldValue); +} + +void Helper_StoreStorage8(int index, int offset, uint value) +{ + int wordOffset = offset >> 2; + int bitOffset = (offset & 3) * 8; + uint oldValue, newValue; + do + { + oldValue = $STORAGE_MEM$[index].data[wordOffset]; + newValue = bitfieldInsert(oldValue, value, bitOffset, 8); + } while (atomicCompSwap($STORAGE_MEM$[index].data[wordOffset], oldValue, newValue) != oldValue); +} \ No newline at end of file -- cgit v1.2.3