From 1984c5af7e62ceba01ebe657aa286447d249a0ff Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Wed, 22 May 2024 15:44:00 -0400 Subject: [PATCH] Depth Sampler Fixes --- .../CodeGen/Msl/Declarations.cs | 1 - .../CodeGen/Msl/Instructions/InstGenMemory.cs | 26 +++++++++++----- src/Ryujinx.Graphics.Shader/SamplerType.cs | 31 +++++++++++++------ 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Msl/Declarations.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Msl/Declarations.cs index c2d5e5976..deb5dc394 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Msl/Declarations.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Msl/Declarations.cs @@ -149,7 +149,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl context.AppendLine("float4 position [[position]];"); } - foreach (var ioDefinition in inputs.OrderBy(x => x.Location)) { string type = ioDefinition.IoVariable switch diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Msl/Instructions/InstGenMemory.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Msl/Instructions/InstGenMemory.cs index c1eeca7c8..b771ec12e 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Msl/Instructions/InstGenMemory.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Msl/Instructions/InstGenMemory.cs @@ -175,20 +175,25 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions } else { - texCall += "sample("; + texCall += "sample"; - texCall += $"samp_{samplerName}"; + if (isGather) + { + texCall += "_gather"; + } + + if (isShadow) + { + texCall += "_compare"; + } + + texCall += $"(samp_{samplerName}"; } int coordsCount = texOp.Type.GetDimensions(); int pCount = coordsCount; - if (isShadow && !isGather) - { - pCount++; - } - void Append(string str) { texCall += ", " + str; @@ -224,6 +229,13 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions texCall += ", " + Src(AggregateType.S32); } + if (isShadow) + { + texCall += ", " + Src(AggregateType.S32); + } + + // TODO: Support offsets + texCall += ")" + (colorIsVector ? GetMaskMultiDest(texOp.Index) : ""); return texCall; diff --git a/src/Ryujinx.Graphics.Shader/SamplerType.cs b/src/Ryujinx.Graphics.Shader/SamplerType.cs index f9ae96661..de43d7aa6 100644 --- a/src/Ryujinx.Graphics.Shader/SamplerType.cs +++ b/src/Ryujinx.Graphics.Shader/SamplerType.cs @@ -158,16 +158,29 @@ namespace Ryujinx.Graphics.Shader public static string ToMslTextureType(this SamplerType type) { - string typeName = (type & SamplerType.Mask) switch + string typeName; + + if ((type & SamplerType.Shadow) != 0) { - SamplerType.None => "texture", - SamplerType.Texture1D => "texture1d", - SamplerType.TextureBuffer => "texturebuffer", - SamplerType.Texture2D => "texture2d", - SamplerType.Texture3D => "texture3d", - SamplerType.TextureCube => "texturecube", - _ => throw new ArgumentException($"Invalid sampler type \"{type}\"."), - }; + typeName = (type & SamplerType.Mask) switch + { + SamplerType.Texture2D => "depth2d", + SamplerType.TextureCube => "depthcube", + _ => throw new ArgumentException($"Invalid shadow texture type \"{type}\"."), + }; + } + else + { + typeName = (type & SamplerType.Mask) switch + { + SamplerType.Texture1D => "texture1d", + SamplerType.TextureBuffer => "texturebuffer", + SamplerType.Texture2D => "texture2d", + SamplerType.Texture3D => "texture3d", + SamplerType.TextureCube => "texturecube", + _ => throw new ArgumentException($"Invalid texture type \"{type}\"."), + }; + } if ((type & SamplerType.Multisample) != 0) {