don't hardcode render pipeline attachments

This commit is contained in:
Samuliak
2024-05-14 20:51:53 +02:00
committed by Isaac Marovitz
parent a11247b72d
commit 64005ba9ee
4 changed files with 22 additions and 11 deletions

View File

@@ -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);