From b8eb6abeccbd4a468214a4d2ad3a9b6e5e06973c Mon Sep 17 00:00:00 2001 From: gdkchan Date: Tue, 5 May 2020 22:02:28 -0300 Subject: 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 --- Ryujinx.Graphics.Gpu/Memory/Buffer.cs | 2 +- Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs | 17 +++++------ Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs | 41 --------------------------- Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs | 4 +-- 4 files changed, 10 insertions(+), 54 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/Memory') 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 /// GPU virtual address where the data is located /// Size of the data in bytes /// Byte array with the data - 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. /// /// GPU virtual address where the data is located - /// Maximum size of the data + /// Size of the data /// The span of the data at the specified memory location - public ReadOnlySpan GetSpan(ulong gpuVa, ulong maxSize) + public ReadOnlySpan 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 /// Type of the structure /// GPU virtual address where the structure is located /// The structure at the specified memory location - public T Read(ulong gpuVa) where T : struct + public T Read(ulong gpuVa) where T : unmanaged { ulong processVa = _context.MemoryManager.Translate(gpuVa); - ulong size = (uint)Marshal.SizeOf(); - - return MemoryMarshal.Cast(_context.PhysicalMemory.GetSpan(processVa, size))[0]; + return MemoryMarshal.Cast(_context.PhysicalMemory.GetSpan(processVa, Unsafe.SizeOf()))[0]; } /// @@ -114,7 +111,7 @@ namespace Ryujinx.Graphics.Gpu.Memory /// /// GPU virtual address to write the data into /// The data to be written - public void Write(ulong gpuVa, Span data) + public void Write(ulong gpuVa, ReadOnlySpan 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 @@ -240,28 +240,6 @@ namespace Ryujinx.Graphics.Gpu.Memory return PteUnmapped; } - /// - /// Gets the number of mapped or reserved pages on a given region. - /// - /// Start GPU virtual address of the region - /// Maximum size of the data - /// Mapped size in bytes of the specified region - internal ulong GetSubSize(ulong gpuVa, ulong maxSize) - { - ulong size = 0; - - while (GetPte(gpuVa + size) != PteUnmapped) - { - size += PageSize; - if (size >= maxSize) - { - return maxSize; - } - } - - return size; - } - /// /// Translates a GPU virtual address to a CPU virtual address. /// @@ -279,25 +257,6 @@ namespace Ryujinx.Graphics.Gpu.Memory return baseAddress + (gpuVa & PageMask); } - /// - /// Checks if a given memory region is currently unmapped. - /// - /// Start GPU virtual address of the region - /// Size in bytes of the region - /// True if the region is unmapped (free), false otherwise - public bool IsRegionFree(ulong gpuVa, ulong size) - { - for (ulong offset = 0; offset < size; offset += PageSize) - { - if (IsPageInUse(gpuVa + offset)) - { - return false; - } - } - - return true; - } - /// /// Checks if a given memory page is mapped or reserved. /// 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 /// Start address of the range /// Size in bytes to be range /// A read only span of the data at the specified memory location - public ReadOnlySpan GetSpan(ulong address, ulong size) + public ReadOnlySpan GetSpan(ulong address, int size) { - return _cpuMemory.GetSpan(address, (int)size); + return _cpuMemory.GetSpan(address, size); } /// -- cgit v1.2.3