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 | |
| 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')
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Memory/Buffer.cs | 2 | ||||
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs | 17 | ||||
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs | 41 | ||||
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs | 4 |
4 files changed, 10 insertions, 54 deletions
diff --git a/Ryujinx.Graphics.Gpu/Memory/Buffer.cs b/Ryujinx.Graphics.Gpu/Memory/Buffer.cs index 959e1a10..4dd96878 100644 --- a/Ryujinx.Graphics.Gpu/Memory/Buffer.cs +++ b/Ryujinx.Graphics.Gpu/Memory/Buffer.cs @@ -125,7 +125,7 @@ namespace Ryujinx.Graphics.Gpu.Memory int offset = (int)(mAddress - Address); - HostBuffer.SetData(offset, _context.PhysicalMemory.GetSpan(mAddress, mSize)); + HostBuffer.SetData(offset, _context.PhysicalMemory.GetSpan(mAddress, (int)mSize)); } } 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); diff --git a/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs b/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs index 6f9ee6a4..a9a8fbac 100644 --- a/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs +++ b/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs @@ -241,28 +241,6 @@ namespace Ryujinx.Graphics.Gpu.Memory } /// <summary> - /// Gets the number of mapped or reserved pages on a given region. - /// </summary> - /// <param name="gpuVa">Start GPU virtual address of the region</param> - /// <param name="maxSize">Maximum size of the data</param> - /// <returns>Mapped size in bytes of the specified region</returns> - internal ulong GetSubSize(ulong gpuVa, ulong maxSize) - { - ulong size = 0; - - while (GetPte(gpuVa + size) != PteUnmapped) - { - size += PageSize; - if (size >= maxSize) - { - return maxSize; - } - } - - return size; - } - - /// <summary> /// Translates a GPU virtual address to a CPU virtual address. /// </summary> /// <param name="gpuVa">GPU virtual address to be translated</param> @@ -280,25 +258,6 @@ namespace Ryujinx.Graphics.Gpu.Memory } /// <summary> - /// Checks if a given memory region is currently unmapped. - /// </summary> - /// <param name="gpuVa">Start GPU virtual address of the region</param> - /// <param name="size">Size in bytes of the region</param> - /// <returns>True if the region is unmapped (free), false otherwise</returns> - public bool IsRegionFree(ulong gpuVa, ulong size) - { - for (ulong offset = 0; offset < size; offset += PageSize) - { - if (IsPageInUse(gpuVa + offset)) - { - return false; - } - } - - return true; - } - - /// <summary> /// Checks if a given memory page is mapped or reserved. /// </summary> /// <param name="gpuVa">GPU virtual address of the page</param> diff --git a/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs b/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs index a787305d..5d9b5561 100644 --- a/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs +++ b/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs @@ -28,9 +28,9 @@ namespace Ryujinx.Graphics.Gpu.Memory /// <param name="address">Start address of the range</param> /// <param name="size">Size in bytes to be range</param> /// <returns>A read only span of the data at the specified memory location</returns> - public ReadOnlySpan<byte> GetSpan(ulong address, ulong size) + public ReadOnlySpan<byte> GetSpan(ulong address, int size) { - return _cpuMemory.GetSpan(address, (int)size); + return _cpuMemory.GetSpan(address, size); } /// <summary> |
