mirror of
https://git.ryujinx.app/projects/Kenji-NX.git
synced 2026-11-19 09:21:15 +01:00
Add a GetSpan method to the memory manager and use it on GPU (#877)
This commit is contained in:
1 parent
8b90924c1e
commit
b8e3909d80
20 files changed
+93
-48
No files matched your search
@@ -1,6 +1,7 @@
|
||||
using ARMeilleure.State;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
|
||||
@@ -552,6 +553,50 @@ namespace ARMeilleure.Memory
|
||||
return data;
|
||||
}
|
||||
|
||||
public ReadOnlySpan<byte> GetSpan(ulong address, ulong size)
|
||||
{
|
||||
if (IsContiguous(address, size))
|
||||
{
|
||||
return new ReadOnlySpan<byte>((void*)Translate((long)address), (int)size);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ReadBytes((long)address, (long)size);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private bool IsContiguous(ulong address, ulong size)
|
||||
{
|
||||
if (!IsValidPosition((long)address))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ulong endVa = (address + size + PageMask) & ~(ulong)PageMask;
|
||||
|
||||
address &= ~(ulong)PageMask;
|
||||
|
||||
int pages = (int)((endVa - address) / PageSize);
|
||||
|
||||
for (int page = 0; page < pages - 1; page++)
|
||||
{
|
||||
if (!IsValidPosition((long)address + PageSize))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (GetPtEntry((long)address) + PageSize != GetPtEntry((long)address + PageSize))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
address += PageSize;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void WriteSByte(long position, sbyte value)
|
||||
{
|
||||
WriteByte(position, (byte)value);
|
||||
|
||||
Reference in new issue
Block a user