From 75781ba698297ec1d02322b0de3adc11be7b40ca Mon Sep 17 00:00:00 2001 From: Samuliak Date: Thu, 16 May 2024 16:20:52 +0200 Subject: [PATCH] don't hardcode texture type --- .../CodeGen/Msl/MslGenerator.cs | 4 +-- src/Ryujinx.Graphics.Shader/SamplerType.cs | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Msl/MslGenerator.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Msl/MslGenerator.cs index 3b515eb84..5852deca7 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Msl/MslGenerator.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Msl/MslGenerator.cs @@ -135,8 +135,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl foreach (var texture in context.Properties.Textures.Values) { - // TODO: don't use always texture2d - args = args.Append($"texture2d tex_{texture.Name} [[texture({texture.Binding})]]").ToArray(); + var textureTypeName = texture.Type.ToMslTextureType(); + args = args.Append($"{textureTypeName} tex_{texture.Name} [[texture({texture.Binding})]]").ToArray(); args = args.Append($"sampler samp_{texture.Name} [[sampler({texture.Binding})]]").ToArray(); } } diff --git a/src/Ryujinx.Graphics.Shader/SamplerType.cs b/src/Ryujinx.Graphics.Shader/SamplerType.cs index a693495fa..f9ae96661 100644 --- a/src/Ryujinx.Graphics.Shader/SamplerType.cs +++ b/src/Ryujinx.Graphics.Shader/SamplerType.cs @@ -155,5 +155,31 @@ namespace Ryujinx.Graphics.Shader return typeName; } + + public static string ToMslTextureType(this SamplerType type) + { + string typeName = (type & SamplerType.Mask) switch + { + 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}\"."), + }; + + if ((type & SamplerType.Multisample) != 0) + { + typeName += "_ms"; + } + + if ((type & SamplerType.Array) != 0) + { + typeName += "_array"; + } + + return typeName + ""; + } } }