diff --git a/src/Ryujinx.Graphics.Metal/Pipeline.cs b/src/Ryujinx.Graphics.Metal/Pipeline.cs index 94d0bc19e..dd2e3bf99 100644 --- a/src/Ryujinx.Graphics.Metal/Pipeline.cs +++ b/src/Ryujinx.Graphics.Metal/Pipeline.cs @@ -137,7 +137,7 @@ namespace Ryujinx.Graphics.Metal } var renderCommandEncoder = _commandBuffer.RenderCommandEncoder(descriptor); - _renderEncoderState.SetEncoderState(renderCommandEncoder, _vertexDescriptor); + _renderEncoderState.SetEncoderState(renderCommandEncoder, descriptor, _vertexDescriptor); RebindBuffers(renderCommandEncoder); @@ -193,7 +193,7 @@ namespace Ryujinx.Graphics.Metal _helperShaders.BlitShader.VertexFunction, _helperShaders.BlitShader.FragmentFunction, _device); - _renderEncoderState.SetEncoderState(renderCommandEncoder, _vertexDescriptor); + _renderEncoderState.SetEncoderState(renderCommandEncoder, descriptor, _vertexDescriptor); var sampler = _device.NewSamplerState(new MTLSamplerDescriptor { diff --git a/src/Ryujinx.Graphics.Metal/Program.cs b/src/Ryujinx.Graphics.Metal/Program.cs index 764bcf126..255a7316b 100644 --- a/src/Ryujinx.Graphics.Metal/Program.cs +++ b/src/Ryujinx.Graphics.Metal/Program.cs @@ -28,6 +28,8 @@ namespace Ryujinx.Graphics.Metal { Logger.Warning?.Print(LogClass.Gpu, $"Shader linking failed: \n{StringHelper.String(libraryError.LocalizedDescription)}"); _status = ProgramLinkStatus.Failure; + //Console.WriteLine($"SHADER {index}: {shader.Code}"); + //throw new NotImplementedException(); return; } diff --git a/src/Ryujinx.Graphics.Metal/RenderEncoderState.cs b/src/Ryujinx.Graphics.Metal/RenderEncoderState.cs index 4a045c96b..832e0ba36 100644 --- a/src/Ryujinx.Graphics.Metal/RenderEncoderState.cs +++ b/src/Ryujinx.Graphics.Metal/RenderEncoderState.cs @@ -36,7 +36,7 @@ namespace Ryujinx.Graphics.Metal _device = device; } - public unsafe readonly void SetEncoderState(MTLRenderCommandEncoder renderCommandEncoder, MTLVertexDescriptor vertexDescriptor) + public unsafe readonly void SetEncoderState(MTLRenderCommandEncoder renderCommandEncoder, MTLRenderPassDescriptor descriptor, MTLVertexDescriptor vertexDescriptor) { var renderPipelineDescriptor = new MTLRenderPipelineDescriptor { @@ -53,13 +53,21 @@ namespace Ryujinx.Graphics.Metal renderPipelineDescriptor.FragmentFunction = _fragmentFunction.Value; } - var attachment = renderPipelineDescriptor.ColorAttachments.Object(0); - attachment.SetBlendingEnabled(true); - attachment.PixelFormat = MTLPixelFormat.BGRA8Unorm; - attachment.SourceAlphaBlendFactor = MTLBlendFactor.SourceAlpha; - attachment.DestinationAlphaBlendFactor = MTLBlendFactor.OneMinusSourceAlpha; - attachment.SourceRGBBlendFactor = MTLBlendFactor.SourceAlpha; - attachment.DestinationRGBBlendFactor = MTLBlendFactor.OneMinusSourceAlpha; + const int maxColorAttachments = 8; + for (int i = 0; i < maxColorAttachments; i++) + { + var renderAttachment = descriptor.ColorAttachments.Object((ulong)i); + if (renderAttachment.Texture != null) + { + var attachment = renderPipelineDescriptor.ColorAttachments.Object((ulong)i); + attachment.SetBlendingEnabled(true); + attachment.PixelFormat = renderAttachment.Texture.PixelFormat; + attachment.SourceAlphaBlendFactor = MTLBlendFactor.SourceAlpha; + attachment.DestinationAlphaBlendFactor = MTLBlendFactor.OneMinusSourceAlpha; + attachment.SourceRGBBlendFactor = MTLBlendFactor.SourceAlpha; + attachment.DestinationRGBBlendFactor = MTLBlendFactor.OneMinusSourceAlpha; + } + } var error = new NSError(IntPtr.Zero); var pipelineState = _device.NewRenderPipelineState(renderPipelineDescriptor, ref error); diff --git a/src/Ryujinx.Graphics.Metal/Sampler.cs b/src/Ryujinx.Graphics.Metal/Sampler.cs index f4ffecc02..00570b8a9 100644 --- a/src/Ryujinx.Graphics.Metal/Sampler.cs +++ b/src/Ryujinx.Graphics.Metal/Sampler.cs @@ -1,6 +1,7 @@ using Ryujinx.Graphics.GAL; using SharpMetal.Metal; using System.Runtime.Versioning; +using System; namespace Ryujinx.Graphics.Metal { @@ -23,7 +24,7 @@ namespace Ryujinx.Graphics.Metal LodMinClamp = info.MinLod, LodMaxClamp = info.MaxLod, LodAverage = false, - MaxAnisotropy = (uint)info.MaxAnisotropy, + MaxAnisotropy = Math.Max((uint)info.MaxAnisotropy, 1), SAddressMode = info.AddressU.Convert(), TAddressMode = info.AddressV.Convert(), RAddressMode = info.AddressP.Convert()