diff options
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Memory')
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs | 12 | ||||
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs | 12 |
2 files changed, 18 insertions, 6 deletions
diff --git a/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs b/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs index cfc6f7f5..38f448d9 100644 --- a/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs +++ b/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs @@ -46,11 +46,11 @@ namespace Ryujinx.Graphics.Gpu.Memory } /// <summary> - /// Reads a structure from GPU mapped memory. + /// Reads data from GPU mapped memory. /// </summary> - /// <typeparam name="T">Type of the structure</typeparam> - /// <param name="gpuVa">GPU virtual address where the structure is located</param> - /// <returns>The structure at the specified memory location</returns> + /// <typeparam name="T">Type of the data</typeparam> + /// <param name="gpuVa">GPU virtual address where the data is located</param> + /// <returns>The data at the specified memory location</returns> public T Read<T>(ulong gpuVa) where T : unmanaged { ulong processVa = _context.MemoryManager.Translate(gpuVa); @@ -67,7 +67,7 @@ namespace Ryujinx.Graphics.Gpu.Memory { ulong processVa = _context.MemoryManager.Translate(gpuVa); - return BitConverter.ToInt32(_context.PhysicalMemory.GetSpan(processVa, 4)); + return _context.PhysicalMemory.Read<int>(processVa); } /// <summary> @@ -79,7 +79,7 @@ namespace Ryujinx.Graphics.Gpu.Memory { ulong processVa = _context.MemoryManager.Translate(gpuVa); - return BitConverter.ToUInt64(_context.PhysicalMemory.GetSpan(processVa, 8)); + return _context.PhysicalMemory.Read<ulong>(processVa); } /// <summary> diff --git a/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs b/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs index 5d9b5561..4a80aa1a 100644 --- a/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs +++ b/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace Ryujinx.Graphics.Gpu.Memory { @@ -34,6 +35,17 @@ namespace Ryujinx.Graphics.Gpu.Memory } /// <summary> + /// Reads data from the application process. + /// </summary> + /// <typeparam name="T">Type of the structure</typeparam> + /// <param name="gpuVa">Address to read from</param> + /// <returns>The data at the specified memory location</returns> + public T Read<T>(ulong address) where T : unmanaged + { + return MemoryMarshal.Cast<byte, T>(GetSpan(address, Unsafe.SizeOf<T>()))[0]; + } + + /// <summary> /// Writes data to the application process. /// </summary> /// <param name="address">Address to write into</param> |
