mirror of
https://git.ryujinx.app/projects/Kenji-NX.git
synced 2026-10-10 03:58:52 +02:00
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:
@@ -94,6 +94,8 @@ namespace Ryujinx.HLE.HOS.Services.Hid
|
||||
primaryIndex = PlayerIndex.Unknown;
|
||||
configuredCount = 0;
|
||||
|
||||
Span<NpadState> nPadsSpan = _device.Hid.SharedMemory.Npads.AsSpan();
|
||||
|
||||
for (int i = 0; i < MaxControllers; ++i)
|
||||
{
|
||||
ControllerType npad = _configuredTypes[i];
|
||||
@@ -103,7 +105,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
|
||||
continue;
|
||||
}
|
||||
|
||||
ControllerType currentType = (ControllerType)_device.Hid.SharedMemory.Npads[i].InternalState.StyleSet;
|
||||
ControllerType currentType = (ControllerType)nPadsSpan[i].InternalState.StyleSet;
|
||||
|
||||
if (currentType != ControllerType.None && (npad & acceptedTypes) != 0 && _supportedPlayers[i])
|
||||
{
|
||||
|
||||
@@ -23,12 +23,14 @@ namespace Ryujinx.HLE.HOS.Services.Hid
|
||||
{
|
||||
newState.TouchesCount = points.Length;
|
||||
|
||||
int pointsLength = Math.Min(points.Length, newState.Touches.Length);
|
||||
Span<TouchState> touchesSpan = newState.Touches.AsSpan();
|
||||
|
||||
int pointsLength = Math.Min(points.Length, touchesSpan.Length);
|
||||
|
||||
for (int i = 0; i < pointsLength; ++i)
|
||||
{
|
||||
TouchPoint pi = points[i];
|
||||
newState.Touches[i] = new TouchState
|
||||
touchesSpan[i] = new TouchState
|
||||
{
|
||||
DeltaTime = newState.SamplingNumber,
|
||||
Attribute = pi.Attribute,
|
||||
|
||||
@@ -49,12 +49,14 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common
|
||||
}
|
||||
|
||||
ulong index = ReadCurrentIndex();
|
||||
|
||||
Span<AtomicStorage<T>> storageSpan = _storage.AsSpan();
|
||||
|
||||
while (true)
|
||||
{
|
||||
int inputEntryIndex = (int)((index + MaxEntries + 1 - countAvailaible) % MaxEntries);
|
||||
|
||||
ref AtomicStorage<T> result = ref _storage[inputEntryIndex];
|
||||
ref AtomicStorage<T> result = ref storageSpan[inputEntryIndex];
|
||||
|
||||
ulong samplingNumber0 = result.ReadSamplingNumberAtomic();
|
||||
ulong samplingNumber1 = result.ReadSamplingNumberAtomic();
|
||||
@@ -91,15 +93,17 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common
|
||||
ulong index = ReadCurrentIndex();
|
||||
|
||||
AtomicStorage<T>[] result = new AtomicStorage<T>[countAvailaible];
|
||||
|
||||
Span<AtomicStorage<T>> storageSpan = _storage.AsSpan();
|
||||
|
||||
for (ulong i = 0; i < countAvailaible; i++)
|
||||
{
|
||||
int inputEntryIndex = (int)((index + MaxEntries + 1 - countAvailaible + i) % MaxEntries);
|
||||
int outputEntryIndex = (int)(countAvailaible - i - 1);
|
||||
|
||||
ulong samplingNumber0 = _storage[inputEntryIndex].ReadSamplingNumberAtomic();
|
||||
result[outputEntryIndex] = _storage[inputEntryIndex];
|
||||
ulong samplingNumber1 = _storage[inputEntryIndex].ReadSamplingNumberAtomic();
|
||||
ulong samplingNumber0 = storageSpan[inputEntryIndex].ReadSamplingNumberAtomic();
|
||||
result[outputEntryIndex] = storageSpan[inputEntryIndex];
|
||||
ulong samplingNumber1 = storageSpan[inputEntryIndex].ReadSamplingNumberAtomic();
|
||||
|
||||
if (samplingNumber0 != samplingNumber1 && (i > 0 && (result[outputEntryIndex].SamplingNumber - result[outputEntryIndex].SamplingNumber) != 1))
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Keyboard;
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Mouse;
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Npad;
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.TouchScreen;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory
|
||||
@@ -54,10 +55,12 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory
|
||||
Mouse = RingLifo<MouseState>.Create(),
|
||||
Keyboard = RingLifo<KeyboardState>.Create(),
|
||||
};
|
||||
|
||||
Span<NpadState> npadsSpan = result.Npads.AsSpan();
|
||||
|
||||
for (int i = 0; i < result.Npads.Length; i++)
|
||||
for (int i = 0; i < npadsSpan.Length; i++)
|
||||
{
|
||||
result.Npads[i] = NpadState.Create();
|
||||
npadsSpan[i] = NpadState.Create();
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user