1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-24 15:46:01 +00:00

SetDepthTest

This commit is contained in:
Isaac Marovitz 2023-07-29 00:46:13 -04:00 committed by Isaac Marovitz
parent 0f52165e86
commit 3d42543f03
2 changed files with 68 additions and 25 deletions

View file

@ -33,7 +33,7 @@ namespace Ryujinx.Graphics.Metal
var renderPipelineDescriptor = new MTLRenderPipelineDescriptor(); var renderPipelineDescriptor = new MTLRenderPipelineDescriptor();
var error = new NSError(IntPtr.Zero); var error = new NSError(IntPtr.Zero);
_renderEncoderState = new(_device.NewRenderPipelineState(renderPipelineDescriptor, ref error)); _renderEncoderState = new(_device.NewRenderPipelineState(renderPipelineDescriptor, ref error), _device);
if (error != IntPtr.Zero) if (error != IntPtr.Zero)
{ {
Logger.Error?.PrintMsg(LogClass.Gpu, $"Failed to create Render Pipeline State: {StringHelper.String(error.LocalizedDescription)}"); Logger.Error?.PrintMsg(LogClass.Gpu, $"Failed to create Render Pipeline State: {StringHelper.String(error.LocalizedDescription)}");
@ -255,7 +255,14 @@ namespace Ryujinx.Graphics.Metal
public void SetDepthTest(DepthTestDescriptor depthTest) public void SetDepthTest(DepthTestDescriptor depthTest)
{ {
throw new NotImplementedException(); var depthStencilState = _renderEncoderState.UpdateDepthState(
depthTest.TestEnable ? MTLCompareFunction.Always : depthTest.Func.Convert(),
depthTest.WriteEnable);
if (_currentEncoder is MTLRenderCommandEncoder renderCommandEncoder)
{
renderCommandEncoder.SetDepthStencilState(depthStencilState);
}
} }
public void SetFaceCulling(bool enable, Face face) public void SetFaceCulling(bool enable, Face face)
@ -387,29 +394,27 @@ namespace Ryujinx.Graphics.Metal
public void SetStencilTest(StencilTestDescriptor stencilTest) public void SetStencilTest(StencilTestDescriptor stencilTest)
{ {
var depthStencilDescriptor = new MTLDepthStencilDescriptor var backFace = new MTLStencilDescriptor
{ {
BackFaceStencil = new MTLStencilDescriptor StencilFailureOperation = stencilTest.BackSFail.Convert(),
{ DepthFailureOperation = stencilTest.BackDpFail.Convert(),
StencilFailureOperation = stencilTest.BackSFail.Convert(), DepthStencilPassOperation = stencilTest.BackDpPass.Convert(),
DepthFailureOperation = stencilTest.BackDpFail.Convert(), StencilCompareFunction = stencilTest.BackFunc.Convert(),
DepthStencilPassOperation = stencilTest.BackDpPass.Convert(), ReadMask = (uint)stencilTest.BackFuncMask,
StencilCompareFunction = stencilTest.BackFunc.Convert(), WriteMask = (uint)stencilTest.BackMask
ReadMask = (uint)stencilTest.BackFuncMask,
WriteMask = (uint)stencilTest.BackMask
},
FrontFaceStencil = new MTLStencilDescriptor
{
StencilFailureOperation = stencilTest.FrontSFail.Convert(),
DepthFailureOperation = stencilTest.FrontDpFail.Convert(),
DepthStencilPassOperation = stencilTest.FrontDpPass.Convert(),
StencilCompareFunction = stencilTest.FrontFunc.Convert(),
ReadMask = (uint)stencilTest.FrontFuncMask,
WriteMask = (uint)stencilTest.FrontMask
}
}; };
var depthStencilState = _device.NewDepthStencilState(depthStencilDescriptor); var frontFace = new MTLStencilDescriptor
{
StencilFailureOperation = stencilTest.FrontSFail.Convert(),
DepthFailureOperation = stencilTest.FrontDpFail.Convert(),
DepthStencilPassOperation = stencilTest.FrontDpPass.Convert(),
StencilCompareFunction = stencilTest.FrontFunc.Convert(),
ReadMask = (uint)stencilTest.FrontFuncMask,
WriteMask = (uint)stencilTest.FrontMask
};
var depthStencilState = _renderEncoderState.UpdateStencilState(backFace, frontFace);
if (_currentEncoder is MTLRenderCommandEncoder renderCommandEncoder) if (_currentEncoder is MTLRenderCommandEncoder renderCommandEncoder)
{ {

View file

@ -7,14 +7,24 @@ namespace Ryujinx.Graphics.Metal
[SupportedOSPlatform("macos")] [SupportedOSPlatform("macos")]
struct RenderEncoderState struct RenderEncoderState
{ {
private MTLDevice _device;
private MTLDepthStencilState _depthStencilState = null;
private MTLCompareFunction _depthCompareFunction = MTLCompareFunction.Always;
private bool _depthWriteEnabled = false;
private MTLStencilDescriptor _backFaceStencil = null;
private MTLStencilDescriptor _frontFaceStencil = null;
public MTLRenderPipelineState RenderPipelineState; public MTLRenderPipelineState RenderPipelineState;
public PrimitiveTopology Topology = PrimitiveTopology.Triangles; public PrimitiveTopology Topology = PrimitiveTopology.Triangles;
public MTLCullMode CullMode = MTLCullMode.None; public MTLCullMode CullMode = MTLCullMode.None;
public MTLWinding Winding = MTLWinding.Clockwise; public MTLWinding Winding = MTLWinding.Clockwise;
public MTLDepthStencilState DepthStencilState = null;
public RenderEncoderState(MTLRenderPipelineState renderPipelineState) public RenderEncoderState(MTLRenderPipelineState renderPipelineState, MTLDevice device)
{ {
_device = device;
RenderPipelineState = renderPipelineState; RenderPipelineState = renderPipelineState;
} }
@ -23,7 +33,35 @@ namespace Ryujinx.Graphics.Metal
renderCommandEncoder.SetRenderPipelineState(RenderPipelineState); renderCommandEncoder.SetRenderPipelineState(RenderPipelineState);
renderCommandEncoder.SetCullMode(CullMode); renderCommandEncoder.SetCullMode(CullMode);
renderCommandEncoder.SetFrontFacingWinding(Winding); renderCommandEncoder.SetFrontFacingWinding(Winding);
renderCommandEncoder.SetDepthStencilState(DepthStencilState); renderCommandEncoder.SetDepthStencilState(_depthStencilState);
}
public MTLDepthStencilState UpdateStencilState(MTLStencilDescriptor backFace, MTLStencilDescriptor frontFace)
{
_backFaceStencil = backFace;
_frontFaceStencil = frontFace;
return _depthStencilState = _device.NewDepthStencilState(new MTLDepthStencilDescriptor
{
DepthCompareFunction = _depthCompareFunction,
DepthWriteEnabled = _depthWriteEnabled,
BackFaceStencil = _backFaceStencil,
FrontFaceStencil = _frontFaceStencil
});
}
public MTLDepthStencilState UpdateDepthState(MTLCompareFunction depthCompareFunction, bool depthWriteEnabled)
{
_depthCompareFunction = depthCompareFunction;
_depthWriteEnabled = depthWriteEnabled;
return _depthStencilState = _device.NewDepthStencilState(new MTLDepthStencilDescriptor
{
DepthCompareFunction = _depthCompareFunction,
DepthWriteEnabled = _depthWriteEnabled,
BackFaceStencil = _backFaceStencil,
FrontFaceStencil = _frontFaceStencil
});
} }
} }
} }