Fix Clear Viewport

This commit is contained in:
Isaac Marovitz 2024-05-30 13:20:16 +01:00 committed by Isaac Marovitz
parent 362672ae12
commit 3c188718c4
3 changed files with 40 additions and 5 deletions

View file

@ -25,6 +25,8 @@ namespace Ryujinx.Graphics.Metal
public readonly MTLIndexType IndexType => _currentState.IndexType; public readonly MTLIndexType IndexType => _currentState.IndexType;
public readonly ulong IndexBufferOffset => _currentState.IndexBufferOffset; public readonly ulong IndexBufferOffset => _currentState.IndexBufferOffset;
public readonly PrimitiveTopology Topology => _currentState.Topology; public readonly PrimitiveTopology Topology => _currentState.Topology;
public readonly Texture RenderTarget => _currentState.RenderTargets[0];
public readonly Texture DepthStencil => _currentState.DepthStencil;
// RGBA32F is the biggest format // RGBA32F is the biggest format
private const int ZeroBufferSize = 4 * 4; private const int ZeroBufferSize = 4 * 4;

View file

@ -202,19 +202,35 @@ namespace Ryujinx.Graphics.Metal
public unsafe void ClearColor( public unsafe void ClearColor(
int index, int index,
ReadOnlySpan<float> clearColor) ReadOnlySpan<float> clearColor,
uint componentMask,
int dstWidth,
int dstHeight)
{ {
const int ClearColorBufferSize = 16; const int ClearColorBufferSize = 16;
// Save current state // Save current state
_pipeline.SaveState(); _pipeline.SaveState();
Span<Viewport> viewports = stackalloc Viewport[1];
// TODO: Set exact viewport!
viewports[0] = new Viewport(
new Rectangle<float>(0, 0, dstWidth, dstHeight),
ViewportSwizzle.PositiveX,
ViewportSwizzle.PositiveY,
ViewportSwizzle.PositiveZ,
ViewportSwizzle.PositiveW,
0f,
1f);
_pipeline.SetProgram(_programsColorClear[index]); _pipeline.SetProgram(_programsColorClear[index]);
_pipeline.SetBlendState(index, new BlendDescriptor(false, new ColorF(0f, 0f, 0f, 1f), BlendOp.Add, BlendFactor.One, BlendFactor.Zero, BlendOp.Add, BlendFactor.One, BlendFactor.Zero)); _pipeline.SetBlendState(index, new BlendDescriptor(false, new ColorF(0f, 0f, 0f, 1f), BlendOp.Add, BlendFactor.One, BlendFactor.Zero, BlendOp.Add, BlendFactor.One, BlendFactor.Zero));
_pipeline.SetFaceCulling(false, Face.Front); _pipeline.SetFaceCulling(false, Face.Front);
_pipeline.SetDepthTest(new DepthTestDescriptor(false, false, CompareOp.Always)); _pipeline.SetDepthTest(new DepthTestDescriptor(false, false, CompareOp.Always));
// _pipeline.SetRenderTargetColorMasks([componentMask]); _pipeline.SetRenderTargetColorMasks([componentMask]);
_pipeline.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip); _pipeline.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
_pipeline.SetViewports(viewports);
fixed (float* ptr = clearColor) fixed (float* ptr = clearColor)
{ {
@ -231,7 +247,9 @@ namespace Ryujinx.Graphics.Metal
float depthValue, float depthValue,
bool depthMask, bool depthMask,
int stencilValue, int stencilValue,
int stencilMask) int stencilMask,
int dstWidth,
int dstHeight)
{ {
const int ClearDepthBufferSize = 4; const int ClearDepthBufferSize = 4;
@ -240,10 +258,22 @@ namespace Ryujinx.Graphics.Metal
// Save current state // Save current state
_pipeline.SaveState(); _pipeline.SaveState();
Span<Viewport> viewports = stackalloc Viewport[1];
viewports[0] = new Viewport(
new Rectangle<float>(0, 0, dstWidth, dstHeight),
ViewportSwizzle.PositiveX,
ViewportSwizzle.PositiveY,
ViewportSwizzle.PositiveZ,
ViewportSwizzle.PositiveW,
0f,
1f);
_pipeline.SetProgram(_programDepthStencilClear); _pipeline.SetProgram(_programDepthStencilClear);
_pipeline.SetFaceCulling(false, Face.Front); _pipeline.SetFaceCulling(false, Face.Front);
_pipeline.SetDepthTest(new DepthTestDescriptor(false, false, CompareOp.Always)); _pipeline.SetDepthTest(new DepthTestDescriptor(false, false, CompareOp.Always));
_pipeline.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip); _pipeline.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
_pipeline.SetViewports(viewports);
_pipeline.SetDepthTest(new DepthTestDescriptor(true, depthMask, CompareOp.Always)); _pipeline.SetDepthTest(new DepthTestDescriptor(true, depthMask, CompareOp.Always));
// _pipeline.SetStencilTest(CreateStencilTestDescriptor(stencilMask != 0, stencilValue, 0xFF, stencilMask)); // _pipeline.SetStencilTest(CreateStencilTestDescriptor(stencilMask != 0, stencilValue, 0xFF, stencilMask));
_pipeline.GetOrCreateRenderEncoder().SetFragmentBytes(ptr, ClearDepthBufferSize, 0); _pipeline.GetOrCreateRenderEncoder().SetFragmentBytes(ptr, ClearDepthBufferSize, 0);

View file

@ -250,13 +250,16 @@ namespace Ryujinx.Graphics.Metal
public void ClearRenderTargetColor(int index, int layer, int layerCount, uint componentMask, ColorF color) public void ClearRenderTargetColor(int index, int layer, int layerCount, uint componentMask, ColorF color)
{ {
float[] colors = [color.Red, color.Green, color.Blue, color.Alpha]; float[] colors = [color.Red, color.Green, color.Blue, color.Alpha];
var dst = _encoderStateManager.RenderTarget;
_helperShader.ClearColor(index, colors); _helperShader.ClearColor(index, colors, componentMask, dst.Width, dst.Height);
} }
public void ClearRenderTargetDepthStencil(int layer, int layerCount, float depthValue, bool depthMask, int stencilValue, int stencilMask) public void ClearRenderTargetDepthStencil(int layer, int layerCount, float depthValue, bool depthMask, int stencilValue, int stencilMask)
{ {
_helperShader.ClearDepthStencil(depthValue, depthMask, stencilValue, stencilMask); var depthStencil = _encoderStateManager.DepthStencil;
_helperShader.ClearDepthStencil(depthValue, depthMask, stencilValue, stencilMask, depthStencil.Width, depthStencil.Height);
} }
public void CommandBufferBarrier() public void CommandBufferBarrier()