From ffb7423260a2fec4b7d07d48007d9672a3b0e0f3 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Tue, 19 Mar 2024 15:07:35 -0400 Subject: [PATCH] Bind Textures & Samplers --- src/Ryujinx.Graphics.Metal/Pipeline.cs | 34 +++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Ryujinx.Graphics.Metal/Pipeline.cs b/src/Ryujinx.Graphics.Metal/Pipeline.cs index 4d182b7ef..a2d427163 100644 --- a/src/Ryujinx.Graphics.Metal/Pipeline.cs +++ b/src/Ryujinx.Graphics.Metal/Pipeline.cs @@ -604,7 +604,39 @@ namespace Ryujinx.Graphics.Metal public void SetTextureAndSampler(ShaderStage stage, int binding, ITexture texture, ISampler sampler) { - Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!"); + if (texture is Texture tex) + { + if (sampler is Sampler samp) + { + MTLRenderCommandEncoder renderCommandEncoder; + MTLComputeCommandEncoder computeCommandEncoder; + + var mtlTexture = tex.MTLTexture; + var mtlSampler = samp.GetSampler(); + var index = (ulong)binding; + + switch (stage) + { + case ShaderStage.Fragment: + renderCommandEncoder = GetOrCreateRenderEncoder(); + renderCommandEncoder.SetFragmentTexture(mtlTexture, index); + renderCommandEncoder.SetFragmentSamplerState(mtlSampler, index); + break; + case ShaderStage.Vertex: + renderCommandEncoder = GetOrCreateRenderEncoder(); + renderCommandEncoder.SetVertexTexture(mtlTexture, index); + renderCommandEncoder.SetVertexSamplerState(mtlSampler, index); + break; + case ShaderStage.Compute: + computeCommandEncoder = GetOrCreateComputeEncoder(); + computeCommandEncoder.SetTexture(mtlTexture, index); + computeCommandEncoder.SetSamplerState(mtlSampler, index); + break; + default: + throw new ArgumentOutOfRangeException(nameof(stage), stage, "Unsupported shader stage!"); + } + } + } } public void SetUniformBuffers(ReadOnlySpan buffers)