aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Gpu
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2020-07-12 00:07:01 -0300
committerGitHub <noreply@github.com>2020-07-12 05:07:01 +0200
commit4d02a2d2c0451b4de1f6de3bbce54c457cacebe2 (patch)
tree120fe4fb8cfa1ac1c6ef4c97d92be47e955e8c0f /Ryujinx.Graphics.Gpu
parent38b26cf4242999fa7d8c550993ac0940cd03d55f (diff)
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 <me@thog.eu>
Diffstat (limited to 'Ryujinx.Graphics.Gpu')
-rw-r--r--Ryujinx.Graphics.Gpu/Engine/Compute.cs2
-rw-r--r--Ryujinx.Graphics.Gpu/Engine/MethodConditionalRendering.cs10
-rw-r--r--Ryujinx.Graphics.Gpu/Engine/Methods.cs2
-rw-r--r--Ryujinx.Graphics.Gpu/GpuContext.cs2
-rw-r--r--Ryujinx.Graphics.Gpu/Image/TextureManager.cs2
-rw-r--r--Ryujinx.Graphics.Gpu/Memory/MemoryAccessor.cs36
-rw-r--r--Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs60
-rw-r--r--Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs12
8 files changed, 81 insertions, 45 deletions
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<int>(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<ulong>(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<ulong>(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<ulong>(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<ulong>(gpuVa);
+ ulong y = _context.MemoryAccessor.Read<ulong>(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
@@ -59,42 +59,6 @@ namespace Ryujinx.Graphics.Gpu.Memory
}
/// <summary>
- /// Reads a 32-bits signed integer from GPU mapped memory.
- /// </summary>
- /// <param name="gpuVa">GPU virtual address where the value is located</param>
- /// <returns>The value at the specified memory location</returns>
- public int ReadInt32(ulong gpuVa)
- {
- ulong processVa = _context.MemoryManager.Translate(gpuVa);
-
- return _context.PhysicalMemory.Read<int>(processVa);
- }
-
- /// <summary>
- /// Reads a 64-bits unsigned integer from GPU mapped memory.
- /// </summary>
- /// <param name="gpuVa">GPU virtual address where the value is located</param>
- /// <returns>The value at the specified memory location</returns>
- public ulong ReadUInt64(ulong gpuVa)
- {
- ulong processVa = _context.MemoryManager.Translate(gpuVa);
-
- return _context.PhysicalMemory.Read<ulong>(processVa);
- }
-
- /// <summary>
- /// Reads a 8-bits unsigned integer from GPU mapped memory.
- /// </summary>
- /// <param name="gpuVa">GPU virtual address where the value is located</param>
- /// <param name="value">The value to be written</param>
- public void WriteByte(ulong gpuVa, byte value)
- {
- ulong processVa = _context.MemoryManager.Translate(gpuVa);
-
- _context.PhysicalMemory.Write(processVa, MemoryMarshal.CreateSpan(ref value, 1));
- }
-
- /// <summary>
/// Writes a 32-bits signed integer to GPU mapped memory.
/// </summary>
/// <param name="gpuVa">GPU virtual address to write the value into</param>
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,15 +36,70 @@ namespace Ryujinx.Graphics.Gpu.Memory
public event EventHandler<UnmapEventArgs> MemoryUnmapped;
+ private GpuContext _context;
+
/// <summary>
/// Creates a new instance of the GPU memory manager.
/// </summary>
- public MemoryManager()
+ public MemoryManager(GpuContext context)
{
+ _context = context;
_pageTable = new ulong[PtLvl0Size][];
}
/// <summary>
+ /// Reads data from GPU mapped memory.
+ /// </summary>
+ /// <typeparam name="T">Type of the data</typeparam>
+ /// <param name="gpuVa">GPU virtual address where the data is located</param>
+ /// <returns>The data at the specified memory location</returns>
+ public T Read<T>(ulong gpuVa) where T : unmanaged
+ {
+ ulong processVa = Translate(gpuVa);
+
+ return MemoryMarshal.Cast<byte, T>(_context.PhysicalMemory.GetSpan(processVa, Unsafe.SizeOf<T>()))[0];
+ }
+
+ /// <summary>
+ /// Gets a read-only span of data from GPU mapped 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="size">Size of the data</param>
+ /// <returns>The span of the data at the specified memory location</returns>
+ public ReadOnlySpan<byte> GetSpan(ulong gpuVa, int size)
+ {
+ ulong processVa = Translate(gpuVa);
+
+ return _context.PhysicalMemory.GetSpan(processVa, size);
+ }
+
+ /// <summary>
+ /// Gets a writable region from GPU mapped memory.
+ /// </summary>
+ /// <param name="address">Start address of the range</param>
+ /// <param name="size">Size in bytes to be range</param>
+ /// <returns>A writable region with the data at the specified memory location</returns>
+ public WritableRegion GetWritableRegion(ulong gpuVa, int size)
+ {
+ ulong processVa = Translate(gpuVa);
+
+ return _context.PhysicalMemory.GetWritableRegion(processVa, size);
+ }
+
+ /// <summary>
+ /// Writes data to GPU mapped 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, ReadOnlySpan<byte> data)
+ {
+ ulong processVa = Translate(gpuVa);
+
+ _context.PhysicalMemory.Write(processVa, data);
+ }
+
+ /// <summary>
/// Maps a given range of pages to the specified CPU virtual address.
/// </summary>
/// <remarks>
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;
@@ -35,6 +36,17 @@ namespace Ryujinx.Graphics.Gpu.Memory
}
/// <summary>
+ /// Gets a writable region from the application process.
+ /// </summary>
+ /// <param name="address">Start address of the range</param>
+ /// <param name="size">Size in bytes to be range</param>
+ /// <returns>A writable region with the data at the specified memory location</returns>
+ public WritableRegion GetWritableRegion(ulong address, int size)
+ {
+ return _cpuMemory.GetWritableRegion(address, size);
+ }
+
+ /// <summary>
/// Reads data from the application process.
/// </summary>
/// <typeparam name="T">Type of the structure</typeparam>