diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2020-05-05 22:02:28 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-06 11:02:28 +1000 |
| commit | b8eb6abeccbd4a468214a4d2ad3a9b6e5e06973c (patch) | |
| tree | cd3d71ebde0f4f32eb674778adae89c0efcb75df /Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs | |
| parent | 7f500e7cae940958289abe1a3461e52684742053 (diff) | |
Refactor shader GPU state and memory access (#1203)
* Refactor shader GPU state and memory access
* Fix NVDEC project build
* Address PR feedback and add missing XML comments
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs')
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs b/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs index fbe2cbc4..cfc6f7f5 100644 --- a/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs +++ b/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace Ryujinx.Graphics.Gpu.Memory @@ -25,7 +26,7 @@ namespace Ryujinx.Graphics.Gpu.Memory /// <param name="gpuVa">GPU virtual address where the data is located</param> /// <param name="size">Size of the data in bytes</param> /// <returns>Byte array with the data</returns> - public byte[] ReadBytes(ulong gpuVa, ulong size) + public byte[] ReadBytes(ulong gpuVa, int size) { return GetSpan(gpuVa, size).ToArray(); } @@ -35,14 +36,12 @@ namespace Ryujinx.Graphics.Gpu.Memory /// This reads as much data as possible, up to the specified maximum size. /// </summary> /// <param name="gpuVa">GPU virtual address where the data is located</param> - /// <param name="maxSize">Maximum size of the data</param> + /// <param name="size">Size of the data</param> /// <returns>The span of the data at the specified memory location</returns> - public ReadOnlySpan<byte> GetSpan(ulong gpuVa, ulong maxSize) + public ReadOnlySpan<byte> GetSpan(ulong gpuVa, int size) { ulong processVa = _context.MemoryManager.Translate(gpuVa); - ulong size = _context.MemoryManager.GetSubSize(gpuVa, maxSize); - return _context.PhysicalMemory.GetSpan(processVa, size); } @@ -52,13 +51,11 @@ namespace Ryujinx.Graphics.Gpu.Memory /// <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> - public T Read<T>(ulong gpuVa) where T : struct + public T Read<T>(ulong gpuVa) where T : unmanaged { ulong processVa = _context.MemoryManager.Translate(gpuVa); - ulong size = (uint)Marshal.SizeOf<T>(); - - return MemoryMarshal.Cast<byte, T>(_context.PhysicalMemory.GetSpan(processVa, size))[0]; + return MemoryMarshal.Cast<byte, T>(_context.PhysicalMemory.GetSpan(processVa, Unsafe.SizeOf<T>()))[0]; } /// <summary> @@ -114,7 +111,7 @@ namespace Ryujinx.Graphics.Gpu.Memory /// </summary> /// <param name="gpuVa">GPU virtual address to write the data into</param> /// <param name="data">The data to be written</param> - public void Write(ulong gpuVa, Span<byte> data) + public void Write(ulong gpuVa, ReadOnlySpan<byte> data) { ulong processVa = _context.MemoryManager.Translate(gpuVa); |
