aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Gpu
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2024-01-22 17:14:46 -0300
committerGitHub <noreply@github.com>2024-01-22 17:14:46 -0300
commitf241f88558b3fe90d76fc21123bd06b9e4c3d2da (patch)
tree7135051e6a5dc2227d87724777cb63f76453db58 /src/Ryujinx.Graphics.Gpu
parent90455a05e6d7fe4305c997f20f76d2411197a182 (diff)
Add a separate device memory manager (#6153)
* Add a separate device memory manager * Still need this * Device writes are always tracked * Device writes are always tracked (2) * Rename more instances of gmm to mm
Diffstat (limited to 'src/Ryujinx.Graphics.Gpu')
-rw-r--r--src/Ryujinx.Graphics.Gpu/GpuContext.cs17
-rw-r--r--src/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs43
-rw-r--r--src/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs10
-rw-r--r--src/Ryujinx.Graphics.Gpu/Synchronization/SynchronizationManager.cs27
4 files changed, 32 insertions, 65 deletions
diff --git a/src/Ryujinx.Graphics.Gpu/GpuContext.cs b/src/Ryujinx.Graphics.Gpu/GpuContext.cs
index aaf03ff7..aa0084fd 100644
--- a/src/Ryujinx.Graphics.Gpu/GpuContext.cs
+++ b/src/Ryujinx.Graphics.Gpu/GpuContext.cs
@@ -1,4 +1,5 @@
using Ryujinx.Common;
+using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Gpu.Engine.GPFifo;
using Ryujinx.Graphics.Gpu.Memory;
@@ -164,6 +165,22 @@ namespace Ryujinx.Graphics.Gpu
}
/// <summary>
+ /// Creates a new device memory manager.
+ /// </summary>
+ /// <param name="pid">ID of the process that owns the memory manager</param>
+ /// <returns>The memory manager</returns>
+ /// <exception cref="ArgumentException">Thrown when <paramref name="pid"/> is invalid</exception>
+ public DeviceMemoryManager CreateDeviceMemoryManager(ulong pid)
+ {
+ if (!PhysicalMemoryRegistry.TryGetValue(pid, out var physicalMemory))
+ {
+ throw new ArgumentException("The PID is invalid or the process was not registered", nameof(pid));
+ }
+
+ return physicalMemory.CreateDeviceMemoryManager();
+ }
+
+ /// <summary>
/// Registers virtual memory used by a process for GPU memory access, caching and read/write tracking.
/// </summary>
/// <param name="pid">ID of the process that owns <paramref name="cpuMemory"/></param>
diff --git a/src/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs b/src/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs
index 5e19bddc..74d52705 100644
--- a/src/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs
+++ b/src/Ryujinx.Graphics.Gpu/Memory/MemoryManager.cs
@@ -330,49 +330,6 @@ namespace Ryujinx.Graphics.Gpu.Memory
}
/// <summary>
- /// Writes data to GPU mapped memory, stopping at the first unmapped page at the memory region, if any.
- /// </summary>
- /// <param name="va">GPU virtual address to write the data into</param>
- /// <param name="data">The data to be written</param>
- public void WriteMapped(ulong va, ReadOnlySpan<byte> data)
- {
- if (IsContiguous(va, data.Length))
- {
- Physical.Write(Translate(va), data);
- }
- else
- {
- int offset = 0, size;
-
- if ((va & PageMask) != 0)
- {
- ulong pa = Translate(va);
-
- size = Math.Min(data.Length, (int)PageSize - (int)(va & PageMask));
-
- if (pa != PteUnmapped && Physical.IsMapped(pa))
- {
- Physical.Write(pa, data[..size]);
- }
-
- offset += size;
- }
-
- for (; offset < data.Length; offset += size)
- {
- ulong pa = Translate(va + (ulong)offset);
-
- size = Math.Min(data.Length - offset, (int)PageSize);
-
- if (pa != PteUnmapped && Physical.IsMapped(pa))
- {
- Physical.Write(pa, data.Slice(offset, size));
- }
- }
- }
- }
-
- /// <summary>
/// Runs remap actions that are added to an unmap event.
/// These must run after the mapping completes.
/// </summary>
diff --git a/src/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs b/src/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs
index 1ca6071b..69a3054a 100644
--- a/src/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs
+++ b/src/Ryujinx.Graphics.Gpu/Memory/PhysicalMemory.cs
@@ -1,4 +1,5 @@
using Ryujinx.Cpu;
+using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.Gpu.Image;
using Ryujinx.Graphics.Gpu.Shader;
using Ryujinx.Memory;
@@ -83,6 +84,15 @@ namespace Ryujinx.Graphics.Gpu.Memory
}
/// <summary>
+ /// Creates a new device memory manager.
+ /// </summary>
+ /// <returns>The memory manager</returns>
+ public DeviceMemoryManager CreateDeviceMemoryManager()
+ {
+ return new DeviceMemoryManager(_cpuMemory);
+ }
+
+ /// <summary>
/// Gets a host pointer for a given range of application memory.
/// If the memory region is not a single contiguous block, this method returns 0.
/// </summary>
diff --git a/src/Ryujinx.Graphics.Gpu/Synchronization/SynchronizationManager.cs b/src/Ryujinx.Graphics.Gpu/Synchronization/SynchronizationManager.cs
index c2fa4c24..1042a4db 100644
--- a/src/Ryujinx.Graphics.Gpu/Synchronization/SynchronizationManager.cs
+++ b/src/Ryujinx.Graphics.Gpu/Synchronization/SynchronizationManager.cs
@@ -1,4 +1,5 @@
using Ryujinx.Common.Logging;
+using Ryujinx.Graphics.Device;
using System;
using System.Threading;
@@ -7,7 +8,7 @@ namespace Ryujinx.Graphics.Gpu.Synchronization
/// <summary>
/// GPU synchronization manager.
/// </summary>
- public class SynchronizationManager
+ public class SynchronizationManager : ISynchronizationManager
{
/// <summary>
/// The maximum number of syncpoints supported by the GM20B.
@@ -29,12 +30,7 @@ namespace Ryujinx.Graphics.Gpu.Synchronization
}
}
- /// <summary>
- /// Increment the value of a syncpoint with a given id.
- /// </summary>
- /// <param name="id">The id of the syncpoint</param>
- /// <exception cref="System.ArgumentOutOfRangeException">Thrown when id >= MaxHardwareSyncpoints</exception>
- /// <returns>The incremented value of the syncpoint</returns>
+ /// <inheritdoc/>
public uint IncrementSyncpoint(uint id)
{
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(id, (uint)MaxHardwareSyncpoints);
@@ -42,12 +38,7 @@ namespace Ryujinx.Graphics.Gpu.Synchronization
return _syncpoints[id].Increment();
}
- /// <summary>
- /// Get the value of a syncpoint with a given id.
- /// </summary>
- /// <param name="id">The id of the syncpoint</param>
- /// <exception cref="System.ArgumentOutOfRangeException">Thrown when id >= MaxHardwareSyncpoints</exception>
- /// <returns>The value of the syncpoint</returns>
+ /// <inheritdoc/>
public uint GetSyncpointValue(uint id)
{
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(id, (uint)MaxHardwareSyncpoints);
@@ -84,15 +75,7 @@ namespace Ryujinx.Graphics.Gpu.Synchronization
_syncpoints[id].UnregisterCallback(waiterInformation);
}
- /// <summary>
- /// Wait on a syncpoint with a given id at a target threshold.
- /// The callback will be called once the threshold is reached and will automatically be unregistered.
- /// </summary>
- /// <param name="id">The id of the syncpoint</param>
- /// <param name="threshold">The target threshold</param>
- /// <param name="timeout">The timeout</param>
- /// <exception cref="System.ArgumentOutOfRangeException">Thrown when id >= MaxHardwareSyncpoints</exception>
- /// <returns>True if timed out</returns>
+ /// <inheritdoc/>
public bool WaitOnSyncpoint(uint id, uint threshold, TimeSpan timeout)
{
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(id, (uint)MaxHardwareSyncpoints);