Fix Scissor/Viewport state & Validation Error
This commit is contained in:
parent
17aa3c6d0f
commit
df6821d023
2 changed files with 53 additions and 11 deletions
|
@ -524,12 +524,17 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
public unsafe void SetScissors(ReadOnlySpan<Rectangle<int>> regions)
|
public unsafe void SetScissors(ReadOnlySpan<Rectangle<int>> regions)
|
||||||
{
|
{
|
||||||
// TODO: Test max allowed scissor rects on device
|
int maxScissors = Math.Min(regions.Length, _renderEncoderState.ViewportCount);
|
||||||
var mtlScissorRects = new MTLScissorRect[regions.Length];
|
|
||||||
|
|
||||||
for (int i = 0; i < regions.Length; i++)
|
if (maxScissors == 0) { return; }
|
||||||
|
|
||||||
|
// TODO: Test max allowed scissor rects on device
|
||||||
|
var mtlScissorRects = new MTLScissorRect[maxScissors];
|
||||||
|
|
||||||
|
for (int i = 0; i < maxScissors; i++)
|
||||||
{
|
{
|
||||||
var region = regions[i];
|
var region = regions[i];
|
||||||
|
|
||||||
mtlScissorRects[i] = new MTLScissorRect
|
mtlScissorRects[i] = new MTLScissorRect
|
||||||
{
|
{
|
||||||
height = (ulong)region.Height,
|
height = (ulong)region.Height,
|
||||||
|
@ -539,10 +544,13 @@ namespace Ryujinx.Graphics.Metal
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fixed (MTLScissorRect* pMtlScissorRects = mtlScissorRects)
|
_renderEncoderState.UpdateScissors(mtlScissorRects);
|
||||||
{
|
if (_currentEncoderType == EncoderType.Render) {
|
||||||
var renderCommandEncoder = GetOrCreateRenderEncoder();
|
fixed (MTLScissorRect* pMtlScissorRects = mtlScissorRects)
|
||||||
renderCommandEncoder.SetScissorRects((IntPtr)pMtlScissorRects, (ulong)regions.Length);
|
{
|
||||||
|
var renderCommandEncoder = GetOrCreateRenderEncoder();
|
||||||
|
renderCommandEncoder.SetScissorRects((IntPtr)pMtlScissorRects, (ulong)regions.Length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -730,10 +738,14 @@ namespace Ryujinx.Graphics.Metal
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fixed (MTLViewport* pMtlViewports = mtlViewports)
|
_renderEncoderState.UpdateViewport(mtlViewports);
|
||||||
|
if (_currentEncoderType == EncoderType.Render)
|
||||||
{
|
{
|
||||||
var renderCommandEncoder = GetOrCreateRenderEncoder();
|
fixed (MTLViewport* pMtlViewports = mtlViewports)
|
||||||
renderCommandEncoder.SetViewports((IntPtr)pMtlViewports, (ulong)viewports.Length);
|
{
|
||||||
|
var renderCommandEncoder = GetOrCreateRenderEncoder();
|
||||||
|
renderCommandEncoder.SetViewports((IntPtr)pMtlViewports, (ulong)viewports.Length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,10 @@ namespace Ryujinx.Graphics.Metal
|
||||||
public MTLCullMode CullMode = MTLCullMode.None;
|
public MTLCullMode CullMode = MTLCullMode.None;
|
||||||
public MTLWinding Winding = MTLWinding.Clockwise;
|
public MTLWinding Winding = MTLWinding.Clockwise;
|
||||||
|
|
||||||
|
private MTLViewport[] _viewports = [];
|
||||||
|
private MTLScissorRect[] _scissors = [];
|
||||||
|
public int ViewportCount => _viewports.Length;
|
||||||
|
|
||||||
public RenderEncoderState(MTLFunction vertexFunction, MTLFunction fragmentFunction, MTLDevice device)
|
public RenderEncoderState(MTLFunction vertexFunction, MTLFunction fragmentFunction, MTLDevice device)
|
||||||
{
|
{
|
||||||
_vertexFunction = vertexFunction;
|
_vertexFunction = vertexFunction;
|
||||||
|
@ -32,7 +36,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
_device = device;
|
_device = device;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly void SetEncoderState(MTLRenderCommandEncoder renderCommandEncoder, MTLVertexDescriptor vertexDescriptor)
|
public unsafe readonly void SetEncoderState(MTLRenderCommandEncoder renderCommandEncoder, MTLVertexDescriptor vertexDescriptor)
|
||||||
{
|
{
|
||||||
var renderPipelineDescriptor = new MTLRenderPipelineDescriptor
|
var renderPipelineDescriptor = new MTLRenderPipelineDescriptor
|
||||||
{
|
{
|
||||||
|
@ -72,6 +76,22 @@ namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
renderCommandEncoder.SetDepthStencilState(_depthStencilState.Value);
|
renderCommandEncoder.SetDepthStencilState(_depthStencilState.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_viewports.Length > 0)
|
||||||
|
{
|
||||||
|
fixed (MTLViewport* pMtlViewports = _viewports)
|
||||||
|
{
|
||||||
|
renderCommandEncoder.SetViewports((IntPtr)pMtlViewports, (ulong)_viewports.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_scissors.Length > 0)
|
||||||
|
{
|
||||||
|
fixed (MTLScissorRect* pMtlScissors = _scissors)
|
||||||
|
{
|
||||||
|
renderCommandEncoder.SetScissorRects((IntPtr)pMtlScissors, (ulong)_scissors.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MTLDepthStencilState UpdateStencilState(MTLStencilDescriptor backFace, MTLStencilDescriptor frontFace)
|
public MTLDepthStencilState UpdateStencilState(MTLStencilDescriptor backFace, MTLStencilDescriptor frontFace)
|
||||||
|
@ -107,5 +127,15 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateScissors(MTLScissorRect[] scissors)
|
||||||
|
{
|
||||||
|
_scissors = scissors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateViewport(MTLViewport[] viewports)
|
||||||
|
{
|
||||||
|
_viewports = viewports;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue