Memory Changes part 2

* Slightly refactors RangeLists from the last Memory Changes MR, which fixes issue 61.

* Convert as many const size array iterators to span iterators as possible. When iterating over a const size array, every iteration created a Span, now only the first iteration does in most places.

* Now using object pooling for a few object types that were rapidly deleted and recreated.

* Converted a few flag checks to binary operations to save memory allocations.
This commit is contained in:
LotP 2025-08-25 17:44:15 -05:00 committed by KeatonTheBot
parent 01cb33f658
commit 171624e7f0
89 changed files with 2121 additions and 1157 deletions

View file

@ -3,6 +3,7 @@ using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Gpu.Engine.Types;
using Ryujinx.Graphics.Gpu.Shader;
using Ryujinx.Graphics.Shader;
using System;
namespace Ryujinx.Graphics.Gpu.Engine.Threed
{
@ -214,10 +215,11 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// Updates the type of the vertex attributes consumed by the shader.
/// </summary>
/// <param name="state">The new state</param>
public void SetAttributeTypes(ref Array32<VertexAttribState> state)
public void SetAttributeTypes(ReadOnlySpan<VertexAttribState> state)
{
bool changed = false;
ref Array32<AttributeType> attributeTypes = ref _graphics.AttributeTypes;
// ref Array32<AttributeType> attributeTypes = ref _graphics.AttributeTypes;
Span<AttributeType> attributeTypesSpan = _graphics.AttributeTypes.AsSpan();
bool mayConvertVtgToCompute = ShaderCache.MayConvertVtgToCompute(ref _context.Capabilities);
bool supportsScaledFormats = _context.Capabilities.SupportsScaledVertexFormats && !mayConvertVtgToCompute;
@ -261,9 +263,9 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
}
}
if (attributeTypes[location] != value)
if (attributeTypesSpan[location] != value)
{
attributeTypes[location] = value;
attributeTypesSpan[location] = value;
changed = true;
}
}
@ -279,10 +281,12 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
/// <param name="rtControl">The render target control register</param>
/// <param name="state">The color attachment state</param>
public void SetFragmentOutputTypes(RtControl rtControl, ref Array8<RtColorState> state)
public void SetFragmentOutputTypes(RtControl rtControl, ReadOnlySpan<RtColorState> state)
{
bool changed = false;
int count = rtControl.UnpackCount();
Span<AttributeType> fragmentOutputTypesSpan = _graphics.FragmentOutputTypes.AsSpan();
for (int index = 0; index < Constants.TotalRenderTargets; index++)
{
@ -296,9 +300,9 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
AttributeType type = format.IsInteger() ? (format.IsSint() ? AttributeType.Sint : AttributeType.Uint) : AttributeType.Float;
if (type != _graphics.FragmentOutputTypes[index])
if (type != fragmentOutputTypesSpan[index])
{
_graphics.FragmentOutputTypes[index] = type;
fragmentOutputTypesSpan[index] = type;
changed = true;
}
}