Implement SetBlendState

This commit is contained in:
Isaac Marovitz 2024-05-18 21:20:15 -04:00 committed by Isaac Marovitz
parent 1db8decd12
commit f98d9bae24
3 changed files with 32 additions and 2 deletions

View file

@ -47,6 +47,8 @@ namespace Ryujinx.Graphics.Metal
public MTLTexture DepthStencil = default;
public MTLTexture[] RenderTargets = new MTLTexture[MaxColorAttachments];
public MTLVertexDescriptor VertexDescriptor = new();
public Dictionary<int, BlendDescriptor> BlendDescriptors = new();
public ColorF BlendColor = new();
public EncoderState() { }
}

View file

@ -56,12 +56,22 @@ namespace Ryujinx.Graphics.Metal
passAttachment.LoadAction = MTLLoadAction.Load;
var pipelineAttachment = renderPipelineDescriptor.ColorAttachments.Object((ulong)i);
pipelineAttachment.SetBlendingEnabled(true);
pipelineAttachment.PixelFormat = _currentState.RenderTargets[i].PixelFormat;
pipelineAttachment.SourceAlphaBlendFactor = MTLBlendFactor.SourceAlpha;
pipelineAttachment.DestinationAlphaBlendFactor = MTLBlendFactor.OneMinusSourceAlpha;
pipelineAttachment.SourceRGBBlendFactor = MTLBlendFactor.SourceAlpha;
pipelineAttachment.DestinationRGBBlendFactor = MTLBlendFactor.OneMinusSourceAlpha;
if (_currentState.BlendDescriptors.TryGetValue(i, out BlendDescriptor blendDescriptor))
{
pipelineAttachment.SetBlendingEnabled(blendDescriptor.Enable);
pipelineAttachment.AlphaBlendOperation = blendDescriptor.AlphaOp.Convert();
pipelineAttachment.RgbBlendOperation = blendDescriptor.ColorOp.Convert();
pipelineAttachment.SourceAlphaBlendFactor = blendDescriptor.AlphaSrcFactor.Convert();
pipelineAttachment.DestinationAlphaBlendFactor = blendDescriptor.AlphaDstFactor.Convert();
pipelineAttachment.SourceRGBBlendFactor = blendDescriptor.ColorSrcFactor.Convert();
pipelineAttachment.DestinationRGBBlendFactor = blendDescriptor.ColorDstFactor.Convert();
}
}
}
@ -136,6 +146,12 @@ namespace Ryujinx.Graphics.Metal
renderCommandEncoder.SetRenderPipelineState(pipelineState);
renderCommandEncoder.SetBlendColor(
_currentState.BlendColor.Red,
_currentState.BlendColor.Green,
_currentState.BlendColor.Blue,
_currentState.BlendColor.Alpha);
SetDepthStencilState(renderCommandEncoder, _currentState.DepthStencilState);
SetScissors(renderCommandEncoder, _currentState.Scissors);
SetViewports(renderCommandEncoder, _currentState.Viewports);
@ -236,6 +252,18 @@ namespace Ryujinx.Graphics.Metal
}
}
public void UpdateBlendDescriptors(int index, BlendDescriptor blend)
{
_currentState.BlendDescriptors.Add(index, blend);
_currentState.BlendColor = blend.BlendConstant;
// Requires recreating pipeline
if (_pipeline.CurrentEncoderType == EncoderType.Render)
{
_pipeline.EndCurrentPass();
}
}
// Inlineable
public void UpdateStencilState(StencilTestDescriptor stencilTest)
{

View file

@ -311,7 +311,7 @@ namespace Ryujinx.Graphics.Metal
public void SetBlendState(int index, BlendDescriptor blend)
{
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
_encoderStateManager.UpdateBlendDescriptors(index, blend);
}
public void SetDepthBias(PolygonModeMask enables, float factor, float units, float clamp)