aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Shader/TextureHandle.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2021-10-17 17:28:18 -0300
committerGitHub <noreply@github.com>2021-10-17 17:28:18 -0300
commit25fd4ef10e610ee470b76d6f58b4a3b9cd053844 (patch)
treef6656f02c542f65f8d120dcdb0e62e01562cd40d /Ryujinx.Graphics.Shader/TextureHandle.cs
parentd05573bfd1bfce902ac33a13cfeba72675a506ff (diff)
Extend bindless elimination to work with masked and shifted handles (#2727)
* Extent bindless elimination to work with masked handles * Extend bindless elimination to catch shifted pattern, refactor handle packing/unpacking
Diffstat (limited to 'Ryujinx.Graphics.Shader/TextureHandle.cs')
-rw-r--r--Ryujinx.Graphics.Shader/TextureHandle.cs54
1 files changed, 54 insertions, 0 deletions
diff --git a/Ryujinx.Graphics.Shader/TextureHandle.cs b/Ryujinx.Graphics.Shader/TextureHandle.cs
new file mode 100644
index 00000000..b3712e6b
--- /dev/null
+++ b/Ryujinx.Graphics.Shader/TextureHandle.cs
@@ -0,0 +1,54 @@
+using System.Runtime.CompilerServices;
+
+namespace Ryujinx.Graphics.Shader
+{
+ public enum TextureHandleType
+ {
+ CombinedSampler = 0, // Must be 0.
+ SeparateSamplerHandle = 1,
+ SeparateSamplerId = 2
+ }
+
+ public static class TextureHandle
+ {
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static int PackSlots(int cbufSlot0, int cbufSlot1)
+ {
+ return cbufSlot0 | ((cbufSlot1 + 1) << 16);
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static (int, int) UnpackSlots(int slots, int defaultTextureBufferIndex)
+ {
+ int textureBufferIndex;
+ int samplerBufferIndex;
+
+ if (slots < 0)
+ {
+ textureBufferIndex = defaultTextureBufferIndex;
+ samplerBufferIndex = textureBufferIndex;
+ }
+ else
+ {
+ uint high = (uint)slots >> 16;
+
+ textureBufferIndex = (ushort)slots;
+ samplerBufferIndex = high != 0 ? (int)high - 1 : textureBufferIndex;
+ }
+
+ return (textureBufferIndex, samplerBufferIndex);
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static int PackOffsets(int cbufOffset0, int cbufOffset1, TextureHandleType type)
+ {
+ return cbufOffset0 | (cbufOffset1 << 14) | ((int)type << 28);
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static (int, int, TextureHandleType) UnpackOffsets(int handle)
+ {
+ return (handle & 0x3fff, (handle >> 14) & 0x3fff, (TextureHandleType)((uint)handle >> 28));
+ }
+ }
+}