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-26 15:30:12 -05:00
committed by KeatonTheBot
parent 01cb33f658
commit 171624e7f0
89 changed files with 2121 additions and 1157 deletions
@@ -17,12 +17,12 @@ namespace Ryujinx.Graphics.Vic.Image
ResourceManager rm,
ref SlotConfig config,
ref SlotSurfaceConfig surfaceConfig,
ref Array8<PlaneOffsets> offsets)
Span<PlaneOffsets> offsets)
{
switch (surfaceConfig.SlotPixelFormat)
{
case PixelFormat.Y8___V8U8_N420:
return ReadNv12(rm, ref config, ref surfaceConfig, ref offsets);
return ReadNv12(rm, ref config, ref surfaceConfig, offsets);
}
Logger.Error?.Print(LogClass.Vic, $"Unsupported pixel format \"{surfaceConfig.SlotPixelFormat}\".");
@@ -37,9 +37,9 @@ namespace Ryujinx.Graphics.Vic.Image
ResourceManager rm,
ref SlotConfig config,
ref SlotSurfaceConfig surfaceConfig,
ref Array8<PlaneOffsets> offsets)
Span<PlaneOffsets> offsets)
{
InputSurface input = ReadSurface(rm, ref config, ref surfaceConfig, ref offsets, 1, 2);
InputSurface input = ReadSurface(rm, ref config, ref surfaceConfig, offsets, 1, 2);
int width = input.Width;
int height = input.Height;
@@ -273,7 +273,7 @@ namespace Ryujinx.Graphics.Vic.Image
ResourceManager rm,
ref SlotConfig config,
ref SlotSurfaceConfig surfaceConfig,
ref Array8<PlaneOffsets> offsets,
Span<PlaneOffsets> offsets,
int bytesPerPixel,
int planes)
{
@@ -301,17 +301,17 @@ namespace Ryujinx.Graphics.Vic.Image
if (planes > 0)
{
surface.SetBuffer0(ReadBuffer(rm, ref config, ref offsets, linear, 0, lw, lh, bytesPerPixel, gobBlocksInY));
surface.SetBuffer0(ReadBuffer(rm, ref config, offsets, linear, 0, lw, lh, bytesPerPixel, gobBlocksInY));
}
if (planes > 1)
{
surface.SetBuffer1(ReadBuffer(rm, ref config, ref offsets, linear, 1, cw, ch, planes == 2 ? 2 : 1, gobBlocksInY));
surface.SetBuffer1(ReadBuffer(rm, ref config, offsets, linear, 1, cw, ch, planes == 2 ? 2 : 1, gobBlocksInY));
}
if (planes > 2)
{
surface.SetBuffer2(ReadBuffer(rm, ref config, ref offsets, linear, 2, cw, ch, 1, gobBlocksInY));
surface.SetBuffer2(ReadBuffer(rm, ref config, offsets, linear, 2, cw, ch, 1, gobBlocksInY));
}
return surface;
@@ -320,7 +320,7 @@ namespace Ryujinx.Graphics.Vic.Image
private static RentedBuffer ReadBuffer(
ResourceManager rm,
scoped ref SlotConfig config,
scoped ref Array8<PlaneOffsets> offsets,
Span<PlaneOffsets> offsets,
bool linear,
int plane,
int width,
+8 -4
View File
@@ -1,3 +1,4 @@
using Ryujinx.Common.Memory;
using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.Vic.Image;
using Ryujinx.Graphics.Vic.Types;
@@ -34,18 +35,21 @@ namespace Ryujinx.Graphics.Vic
config.OutputSurfaceConfig.OutSurfaceWidth + 1,
config.OutputSurfaceConfig.OutSurfaceHeight + 1);
for (int i = 0; i < config.SlotStruct.Length; i++)
Span<SlotStruct> slotStructSpan = config.SlotStruct.AsSpan();
Span<Array8<PlaneOffsets>> setSurfacexSlotxSpan = _state.State.SetSurfacexSlotx.AsSpan();
for (int i = 0; i < slotStructSpan.Length; i++)
{
ref SlotStruct slot = ref config.SlotStruct[i];
ref SlotStruct slot = ref slotStructSpan[i];
if (!slot.SlotConfig.SlotEnable)
{
continue;
}
ref var offsets = ref _state.State.SetSurfacexSlotx[i];
Span<PlaneOffsets> offsets = setSurfacexSlotxSpan[i].AsSpan();
using Surface src = SurfaceReader.Read(_rm, ref slot.SlotConfig, ref slot.SlotSurfaceConfig, ref offsets);
using Surface src = SurfaceReader.Read(_rm, ref slot.SlotConfig, ref slot.SlotSurfaceConfig, offsets);
int x1 = config.OutputConfig.TargetRectLeft;
int y1 = config.OutputConfig.TargetRectTop;