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/Engine/Compute.cs | 2 +- .../Engine/MethodConditionalRendering.cs | 10 ++-- Ryujinx.Graphics.Gpu/Engine/Methods.cs | 2 +- Ryujinx.Graphics.Gpu/GpuContext.cs | 2 +- Ryujinx.Graphics.Gpu/Image/TextureManager.cs | 2 + Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs | 36 ------------- Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs | 60 +++++++++++++++++++++- Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs | 12 +++++ 8 files changed, 81 insertions(+), 45 deletions(-) (limited to 'Ryujinx.Graphics.Gpu') diff --git a/Ryujinx.Graphics.Gpu/Engine/Compute.cs b/Ryujinx.Graphics.Gpu/Engine/Compute.cs index e40984af..60fba006 100644 --- a/Ryujinx.Graphics.Gpu/Engine/Compute.cs +++ b/Ryujinx.Graphics.Gpu/Engine/Compute.cs @@ -67,7 +67,7 @@ namespace Ryujinx.Graphics.Gpu.Engine TextureManager.SetComputeTextureBufferIndex(state.Get(MethodOffset.TextureBufferIndex)); - ShaderProgramInfo info = cs.Shaders[0].Program.Info; + ShaderProgramInfo info = cs.Shaders[0].Program.Info; for (int index = 0; index < info.CBuffers.Count; index++) { diff --git a/Ryujinx.Graphics.Gpu/Engine/MethodConditionalRendering.cs b/Ryujinx.Graphics.Gpu/Engine/MethodConditionalRendering.cs index c8d47b9f..225c732e 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MethodConditionalRendering.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MethodConditionalRendering.cs @@ -63,7 +63,7 @@ namespace Ryujinx.Graphics.Gpu.Engine else { evt.Flush(); - return (_context.MemoryAccessor.ReadUInt64(gpuVa) != 0) ? ConditionalRenderEnabled.True : ConditionalRenderEnabled.False; + return (_context.MemoryAccessor.Read(gpuVa) != 0) ? ConditionalRenderEnabled.True : ConditionalRenderEnabled.False; } } @@ -87,11 +87,11 @@ namespace Ryujinx.Graphics.Gpu.Engine if (evt != null && evt2 == null) { - useHost = _context.Renderer.Pipeline.TryHostConditionalRendering(evt, _context.MemoryAccessor.ReadUInt64(gpuVa + 16), isEqual); + useHost = _context.Renderer.Pipeline.TryHostConditionalRendering(evt, _context.MemoryAccessor.Read(gpuVa + 16), isEqual); } else if (evt == null && evt2 != null) { - useHost = _context.Renderer.Pipeline.TryHostConditionalRendering(evt2, _context.MemoryAccessor.ReadUInt64(gpuVa), isEqual); + useHost = _context.Renderer.Pipeline.TryHostConditionalRendering(evt2, _context.MemoryAccessor.Read(gpuVa), isEqual); } else { @@ -107,8 +107,8 @@ namespace Ryujinx.Graphics.Gpu.Engine evt?.Flush(); evt2?.Flush(); - ulong x = _context.MemoryAccessor.ReadUInt64(gpuVa); - ulong y = _context.MemoryAccessor.ReadUInt64(gpuVa + 16); + ulong x = _context.MemoryAccessor.Read(gpuVa); + ulong y = _context.MemoryAccessor.Read(gpuVa + 16); return (isEqual ? x == y : x != y) ? ConditionalRenderEnabled.True : ConditionalRenderEnabled.False; } diff --git a/Ryujinx.Graphics.Gpu/Engine/Methods.cs b/Ryujinx.Graphics.Gpu/Engine/Methods.cs index 06298cdf..d5b11c2c 100644 --- a/Ryujinx.Graphics.Gpu/Engine/Methods.cs +++ b/Ryujinx.Graphics.Gpu/Engine/Methods.cs @@ -466,7 +466,7 @@ namespace Ryujinx.Graphics.Gpu.Engine bool flipY = yControl.HasFlag(YControl.NegateY); Origin origin = yControl.HasFlag(YControl.TriangleRastFlip) ? Origin.LowerLeft : Origin.UpperLeft; - + _context.Renderer.Pipeline.SetOrigin(origin); // The triangle rast flip flag only affects rasterization, the viewport is not flipped. diff --git a/Ryujinx.Graphics.Gpu/GpuContext.cs b/Ryujinx.Graphics.Gpu/GpuContext.cs index 5e117831..b07694b9 100644 --- a/Ryujinx.Graphics.Gpu/GpuContext.cs +++ b/Ryujinx.Graphics.Gpu/GpuContext.cs @@ -77,7 +77,7 @@ namespace Ryujinx.Graphics.Gpu { Renderer = renderer; - MemoryManager = new MemoryManager(); + MemoryManager = new MemoryManager(this); MemoryAccessor = new MemoryAccessor(this); diff --git a/Ryujinx.Graphics.Gpu/Image/TextureManager.cs b/Ryujinx.Graphics.Gpu/Image/TextureManager.cs index ccd56ae2..69bee541 100644 --- a/Ryujinx.Graphics.Gpu/Image/TextureManager.cs +++ b/Ryujinx.Graphics.Gpu/Image/TextureManager.cs @@ -643,6 +643,8 @@ namespace Ryujinx.Graphics.Gpu.Image overlap.ChangeSize(info.Width, info.Height, info.DepthOrLayers); } + overlap.SynchronizeMemory(); + return overlap; } } 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