Least allocations in the west
This commit is contained in:
parent
5e8606c89a
commit
de5bf3a141
4 changed files with 18 additions and 20 deletions
|
@ -12,6 +12,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
public const int MaxStorageBufferBindings = MaxStorageBuffersPerStage * MaxShaderStages;
|
public const int MaxStorageBufferBindings = MaxStorageBuffersPerStage * MaxShaderStages;
|
||||||
public const int MaxTextureBindings = MaxTexturesPerStage * MaxShaderStages;
|
public const int MaxTextureBindings = MaxTexturesPerStage * MaxShaderStages;
|
||||||
public const int MaxColorAttachments = 8;
|
public const int MaxColorAttachments = 8;
|
||||||
|
public const int MaxViewports = 16;
|
||||||
// TODO: Check this value
|
// TODO: Check this value
|
||||||
public const int MaxVertexAttributes = 31;
|
public const int MaxVertexAttributes = 31;
|
||||||
// TODO: Check this value
|
// TODO: Check this value
|
||||||
|
|
|
@ -109,8 +109,8 @@ namespace Ryujinx.Graphics.Metal
|
||||||
public MTLWinding Winding = MTLWinding.CounterClockwise;
|
public MTLWinding Winding = MTLWinding.CounterClockwise;
|
||||||
public bool CullBoth = false;
|
public bool CullBoth = false;
|
||||||
|
|
||||||
public MTLViewport[] Viewports = [];
|
public MTLViewport[] Viewports = new MTLViewport[Constants.MaxViewports];
|
||||||
public MTLScissorRect[] Scissors = [];
|
public MTLScissorRect[] Scissors = new MTLScissorRect[Constants.MaxViewports];
|
||||||
|
|
||||||
// Changes to attachments take recreation!
|
// Changes to attachments take recreation!
|
||||||
public Texture DepthStencil = default;
|
public Texture DepthStencil = default;
|
||||||
|
@ -122,9 +122,8 @@ namespace Ryujinx.Graphics.Metal
|
||||||
public Array8<ColorBlendStateUid> StoredBlend;
|
public Array8<ColorBlendStateUid> StoredBlend;
|
||||||
public ColorF BlendColor = new();
|
public ColorF BlendColor = new();
|
||||||
|
|
||||||
public VertexBufferDescriptor[] VertexBuffers = [];
|
public readonly VertexBufferDescriptor[] VertexBuffers = new VertexBufferDescriptor[Constants.MaxVertexBuffers];
|
||||||
public VertexAttribDescriptor[] VertexAttribs = [];
|
public readonly VertexAttribDescriptor[] VertexAttribs = new VertexAttribDescriptor[Constants.MaxVertexAttributes];
|
||||||
|
|
||||||
// Dirty flags
|
// Dirty flags
|
||||||
public DirtyFlags Dirty = DirtyFlags.None;
|
public DirtyFlags Dirty = DirtyFlags.None;
|
||||||
|
|
||||||
|
|
|
@ -510,7 +510,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
public void UpdateVertexAttribs(ReadOnlySpan<VertexAttribDescriptor> vertexAttribs)
|
public void UpdateVertexAttribs(ReadOnlySpan<VertexAttribDescriptor> vertexAttribs)
|
||||||
{
|
{
|
||||||
_currentState.VertexAttribs = vertexAttribs.ToArray();
|
vertexAttribs.CopyTo(_currentState.VertexAttribs);
|
||||||
|
|
||||||
// Update the buffers on the pipeline
|
// Update the buffers on the pipeline
|
||||||
UpdatePipelineVertexState(_currentState.VertexBuffers, _currentState.VertexAttribs);
|
UpdatePipelineVertexState(_currentState.VertexBuffers, _currentState.VertexAttribs);
|
||||||
|
@ -625,11 +625,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
// Inlineable
|
// Inlineable
|
||||||
public void UpdateScissors(ReadOnlySpan<Rectangle<int>> regions)
|
public void UpdateScissors(ReadOnlySpan<Rectangle<int>> regions)
|
||||||
{
|
{
|
||||||
int maxScissors = Math.Min(regions.Length, _currentState.Viewports.Length);
|
for (int i = 0; i < regions.Length; i++)
|
||||||
|
|
||||||
_currentState.Scissors = new MTLScissorRect[maxScissors];
|
|
||||||
|
|
||||||
for (int i = 0; i < maxScissors; i++)
|
|
||||||
{
|
{
|
||||||
var region = regions[i];
|
var region = regions[i];
|
||||||
|
|
||||||
|
@ -661,8 +657,6 @@ namespace Ryujinx.Graphics.Metal
|
||||||
return Math.Clamp(value, 0f, 1f);
|
return Math.Clamp(value, 0f, 1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentState.Viewports = new MTLViewport[viewports.Length];
|
|
||||||
|
|
||||||
for (int i = 0; i < viewports.Length; i++)
|
for (int i = 0; i < viewports.Length; i++)
|
||||||
{
|
{
|
||||||
var viewport = viewports[i];
|
var viewport = viewports[i];
|
||||||
|
@ -691,7 +685,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
public void UpdateVertexBuffers(ReadOnlySpan<VertexBufferDescriptor> vertexBuffers)
|
public void UpdateVertexBuffers(ReadOnlySpan<VertexBufferDescriptor> vertexBuffers)
|
||||||
{
|
{
|
||||||
_currentState.VertexBuffers = vertexBuffers.ToArray();
|
vertexBuffers.CopyTo(_currentState.VertexBuffers);
|
||||||
|
|
||||||
// Update the buffers on the pipeline
|
// Update the buffers on the pipeline
|
||||||
UpdatePipelineVertexState(_currentState.VertexBuffers, _currentState.VertexAttribs);
|
UpdatePipelineVertexState(_currentState.VertexBuffers, _currentState.VertexAttribs);
|
||||||
|
@ -1122,7 +1116,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
MTLRenderStages renderStages = 0;
|
MTLRenderStages renderStages = 0;
|
||||||
|
|
||||||
if (segment.Stages.HasFlag(ResourceStages.Vertex))
|
if ((segment.Stages & ResourceStages.Vertex) != 0)
|
||||||
{
|
{
|
||||||
vertResourceIds[vertResourceIdIndex] = mtlTexture.GpuResourceID._impl;
|
vertResourceIds[vertResourceIdIndex] = mtlTexture.GpuResourceID._impl;
|
||||||
vertResourceIdIndex++;
|
vertResourceIdIndex++;
|
||||||
|
@ -1136,7 +1130,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
renderStages |= MTLRenderStages.RenderStageVertex;
|
renderStages |= MTLRenderStages.RenderStageVertex;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (segment.Stages.HasFlag(ResourceStages.Fragment))
|
if ((segment.Stages & ResourceStages.Fragment) != 0)
|
||||||
{
|
{
|
||||||
fragResourceIds[fragResourceIdIndex] = mtlTexture.GpuResourceID._impl;
|
fragResourceIds[fragResourceIdIndex] = mtlTexture.GpuResourceID._impl;
|
||||||
fragResourceIdIndex++;
|
fragResourceIdIndex++;
|
||||||
|
|
|
@ -129,7 +129,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
MathF.Abs(dstRegion.X2 - dstRegion.X1),
|
MathF.Abs(dstRegion.X2 - dstRegion.X1),
|
||||||
MathF.Abs(dstRegion.Y2 - dstRegion.Y1));
|
MathF.Abs(dstRegion.Y2 - dstRegion.Y1));
|
||||||
|
|
||||||
Span<Viewport> viewports = stackalloc Viewport[1];
|
Span<Viewport> viewports = stackalloc Viewport[16];
|
||||||
|
|
||||||
viewports[0] = new Viewport(
|
viewports[0] = new Viewport(
|
||||||
rect,
|
rect,
|
||||||
|
@ -145,8 +145,12 @@ namespace Ryujinx.Graphics.Metal
|
||||||
int dstWidth = dst.Width;
|
int dstWidth = dst.Width;
|
||||||
int dstHeight = dst.Height;
|
int dstHeight = dst.Height;
|
||||||
|
|
||||||
|
Span<Rectangle<int>> scissors = stackalloc Rectangle<int>[16];
|
||||||
|
|
||||||
|
scissors[0] = new Rectangle<int>(0, 0, dstWidth, dstHeight);
|
||||||
|
|
||||||
_pipeline.SetRenderTargets([dst], null);
|
_pipeline.SetRenderTargets([dst], null);
|
||||||
_pipeline.SetScissors(stackalloc Rectangle<int>[] { new Rectangle<int>(0, 0, dstWidth, dstHeight) });
|
_pipeline.SetScissors(scissors);
|
||||||
|
|
||||||
_pipeline.SetClearLoadAction(clear);
|
_pipeline.SetClearLoadAction(clear);
|
||||||
|
|
||||||
|
@ -202,7 +206,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
_renderer.BufferManager.SetData<float>(bufferHandle, 0, region);
|
_renderer.BufferManager.SetData<float>(bufferHandle, 0, region);
|
||||||
_pipeline.SetUniformBuffers([new BufferAssignment(0, new BufferRange(bufferHandle, 0, RegionBufferSize))]);
|
_pipeline.SetUniformBuffers([new BufferAssignment(0, new BufferRange(bufferHandle, 0, RegionBufferSize))]);
|
||||||
|
|
||||||
Span<Viewport> viewports = stackalloc Viewport[1];
|
Span<Viewport> viewports = stackalloc Viewport[16];
|
||||||
|
|
||||||
var rect = new Rectangle<float>(
|
var rect = new Rectangle<float>(
|
||||||
MathF.Min(dstRegion.X1, dstRegion.X2),
|
MathF.Min(dstRegion.X1, dstRegion.X2),
|
||||||
|
@ -302,7 +306,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
buffer.Holder.SetDataUnchecked(buffer.Offset, clearColor);
|
buffer.Holder.SetDataUnchecked(buffer.Offset, clearColor);
|
||||||
_pipeline.SetUniformBuffers([new BufferAssignment(0, buffer.Range)]);
|
_pipeline.SetUniformBuffers([new BufferAssignment(0, buffer.Range)]);
|
||||||
|
|
||||||
Span<Viewport> viewports = stackalloc Viewport[1];
|
Span<Viewport> viewports = stackalloc Viewport[16];
|
||||||
|
|
||||||
// TODO: Set exact viewport!
|
// TODO: Set exact viewport!
|
||||||
viewports[0] = new Viewport(
|
viewports[0] = new Viewport(
|
||||||
|
|
Loading…
Reference in a new issue