From 4d02a2d2c0451b4de1f6de3bbce54c457cacebe2 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sun, 12 Jul 2020 00:07:01 -0300 Subject: New NVDEC and VIC implementation (#1384) * Initial NVDEC and VIC implementation * Update FFmpeg.AutoGen to 4.3.0 * Add nvdec dependencies for Windows * Unify some VP9 structures * Rename VP9 structure fields * Improvements to Video API * XML docs for Common.Memory * Remove now unused or redundant overloads from MemoryAccessor * NVDEC UV surface read/write scalar paths * Add FIXME comments about hacky things/stuff that will need to be fixed in the future * Cleaned up VP9 memory allocation * Remove some debug logs * Rename some VP9 structs * Remove unused struct * No need to compile Ryujinx.Graphics.Host1x with unsafe anymore * Name AsyncWorkQueue threads to make debugging easier * Make Vp9PictureInfo a ref struct * LayoutConverter no longer needs the depth argument (broken by rebase) * Pooling of VP9 buffers, plus fix a memory leak on VP9 * Really wish VS could rename projects properly... * Address feedback * Remove using * Catch OperationCanceledException * Add licensing informations * Add THIRDPARTY.md to release too Co-authored-by: Thog --- Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs | 36 ---------------- Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs | 60 ++++++++++++++++++++++++++- Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs | 12 ++++++ 3 files changed, 71 insertions(+), 37 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/Memory') diff --git a/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs b/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs index 38f448d9..5cc8ec24 100644 --- a/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs +++ b/Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs @@ -58,42 +58,6 @@ namespace Ryujinx.Graphics.Gpu.Memory return MemoryMarshal.Cast(_context.PhysicalMemory.GetSpan(processVa, Unsafe.SizeOf()))[0]; } - /// - /// Reads a 32-bits signed integer from GPU mapped memory. - /// - /// GPU virtual address where the value is located - /// The value at the specified memory location - public int ReadInt32(ulong gpuVa) - { - ulong processVa = _context.MemoryManager.Translate(gpuVa); - - return _context.PhysicalMemory.Read(processVa); - } - - /// - /// Reads a 64-bits unsigned integer from GPU mapped memory. - /// - /// GPU virtual address where the value is located - /// The value at the specified memory location - public ulong ReadUInt64(ulong gpuVa) - { - ulong processVa = _context.MemoryManager.Translate(gpuVa); - - return _context.PhysicalMemory.Read(processVa); - } - - /// - /// Reads a 8-bits unsigned integer from GPU mapped memory. - /// - /// GPU virtual address where the value is located - /// The value to be written - public void WriteByte(ulong gpuVa, byte value) - { - ulong processVa = _context.MemoryManager.Translate(gpuVa); - - _context.PhysicalMemory.Write(processVa, MemoryMarshal.CreateSpan(ref value, 1)); - } - /// /// Writes a 32-bits signed integer to GPU mapped memory. /// diff --git a/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs b/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs index a9a8fbac..2d988f8d 100644 --- a/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs +++ b/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs @@ -1,4 +1,7 @@ +using Ryujinx.Cpu; using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace Ryujinx.Graphics.Gpu.Memory { @@ -33,14 +36,69 @@ namespace Ryujinx.Graphics.Gpu.Memory public event EventHandler MemoryUnmapped; + private GpuContext _context; + /// /// Creates a new instance of the GPU memory manager. /// - public MemoryManager() + public MemoryManager(GpuContext context) { + _context = context; _pageTable = new ulong[PtLvl0Size][]; } + /// + /// Reads data from GPU mapped memory. + /// + /// Type of the data + /// GPU virtual address where the data is located + /// The data at the specified memory location + public T Read(ulong gpuVa) where T : unmanaged + { + ulong processVa = Translate(gpuVa); + + return MemoryMarshal.Cast(_context.PhysicalMemory.GetSpan(processVa, Unsafe.SizeOf()))[0]; + } + + /// + /// Gets a read-only span of data from GPU mapped memory. + /// This reads as much data as possible, up to the specified maximum size. + /// + /// GPU virtual address where the data is located + /// Size of the data + /// The span of the data at the specified memory location + public ReadOnlySpan GetSpan(ulong gpuVa, int size) + { + ulong processVa = Translate(gpuVa); + + return _context.PhysicalMemory.GetSpan(processVa, size); + } + + /// + /// Gets a writable region from GPU mapped memory. + /// + /// Start address of the range + /// Size in bytes to be range + /// A writable region with the data at the specified memory location + public WritableRegion GetWritableRegion(ulong gpuVa, int size) + { + ulong processVa = Translate(gpuVa); + + return _context.PhysicalMemory.GetWritableRegion(processVa, size); + } + + /// + /// Writes data to GPU mapped memory. + /// + /// GPU virtual address to write the data into + /// The data to be written + public void Write(ulong gpuVa, ReadOnlySpan data) + { + ulong processVa = Translate(gpuVa); + + _context.PhysicalMemory.Write(processVa, data); + } + /// /// Maps a given range of pages to the specified CPU virtual address. /// diff --git a/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs b/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs index 4a80aa1a..88beab8f 100644 --- a/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs +++ b/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs @@ -1,3 +1,4 @@ +using Ryujinx.Cpu; using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -34,6 +35,17 @@ namespace Ryujinx.Graphics.Gpu.Memory return _cpuMemory.GetSpan(address, size); } + /// + /// Gets a writable region from the application process. + /// + /// Start address of the range + /// Size in bytes to be range + /// A writable region with the data at the specified memory location + public WritableRegion GetWritableRegion(ulong address, int size) + { + return _cpuMemory.GetWritableRegion(address, size); + } + /// /// Reads data from the application process. /// -- cgit v1.2.3