Stencil Ref Value

This commit is contained in:
Isaac Marovitz 2024-05-27 22:00:48 -04:00
parent 01122ca032
commit 2941f02c87
No known key found for this signature in database
GPG Key ID: 97250B2B09A132E1
2 changed files with 24 additions and 0 deletions

View File

@ -53,6 +53,8 @@ namespace Ryujinx.Graphics.Metal
public MTLStencilDescriptor BackFaceStencil = new();
public MTLStencilDescriptor FrontFaceStencil = new();
public int BackRefValue = 0;
public int FrontRefValue = 0;
public bool StencilTestEnabled = false;
public PrimitiveTopology Topology = PrimitiveTopology.Triangles;

View File

@ -81,6 +81,7 @@ namespace Ryujinx.Graphics.Metal
SetBuffers(renderCommandEncoder, _currentState.StorageBuffers, true);
SetCullMode(renderCommandEncoder);
SetFrontFace(renderCommandEncoder);
SetStencilRefValue(renderCommandEncoder);
// Mark the other state as dirty
_currentState.Dirty.MarkAll();
@ -161,6 +162,7 @@ namespace Ryujinx.Graphics.Metal
SetDepthClamp(renderCommandEncoder);
SetCullMode(renderCommandEncoder);
SetFrontFace(renderCommandEncoder);
SetStencilRefValue(renderCommandEncoder);
SetViewports(renderCommandEncoder);
SetScissors(renderCommandEncoder);
SetVertexBuffers(renderCommandEncoder, _currentState.VertexBuffers);
@ -433,6 +435,8 @@ namespace Ryujinx.Graphics.Metal
_currentState.DepthStencilState = _depthStencilCache.GetOrCreate(descriptor);
UpdateStencilRefValue(stencilTest.FrontFuncRef, stencilTest.BackFuncRef);
// Mark dirty
_currentState.Dirty.DepthStencil = true;
@ -635,6 +639,19 @@ namespace Ryujinx.Graphics.Metal
}
}
private void UpdateStencilRefValue(int frontRef, int backRef)
{
_currentState.FrontRefValue = frontRef;
_currentState.BackRefValue = backRef;
// Inline update
if (_pipeline.CurrentEncoderType == EncoderType.Render && _pipeline.CurrentEncoder != null)
{
var renderCommandEncoder = new MTLRenderCommandEncoder(_pipeline.CurrentEncoder.Value);
SetStencilRefValue(renderCommandEncoder);
}
}
// Inlineable
public readonly void UpdateTextureAndSampler(ShaderStage stage, ulong binding, MTLTexture texture, MTLSamplerState sampler)
{
@ -786,6 +803,11 @@ namespace Ryujinx.Graphics.Metal
renderCommandEncoder.SetFrontFacingWinding(_currentState.Winding);
}
private readonly void SetStencilRefValue(MTLRenderCommandEncoder renderCommandEncoder)
{
renderCommandEncoder.SetStencilReferenceValues((uint)_currentState.FrontRefValue, (uint)_currentState.BackRefValue);
}
private static void SetTextureAndSampler(MTLRenderCommandEncoder renderCommandEncoder, ShaderStage stage, MTLTexture[] textures, MTLSamplerState[] samplers)
{
for (int i = 0; i < textures.Length; i++)