aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2022-10-05 17:49:18 -0300
committerGitHub <noreply@github.com>2022-10-05 17:49:18 -0300
commit599d485bffc9080d1c54acce929bbda0c7077499 (patch)
tree3f7a8ae54da3f92973f8a065e5a673b0e99c4382
parent60e16c15b6e9351371711356d205a12435b3c574 (diff)
Change NvMap ID allocation to match nvservices (#3741)1.1.295
* Change NvMap ID allocation to match nvservices * Move NvMapIdDictionary to Types
-rw-r--r--Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/NvMapDeviceFile.cs24
-rw-r--r--Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapIdDictionary.cs61
2 files changed, 65 insertions, 20 deletions
diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/NvMapDeviceFile.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/NvMapDeviceFile.cs
index a8455bdb..a52b36a2 100644
--- a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/NvMapDeviceFile.cs
+++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/NvMapDeviceFile.cs
@@ -3,7 +3,6 @@ using Ryujinx.Common.Logging;
using Ryujinx.Graphics.Gpu.Memory;
using Ryujinx.Memory;
using System;
-using System.Collections.Concurrent;
namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
{
@@ -11,13 +10,10 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
{
private const int FlagNotFreedYet = 1;
- private static ConcurrentDictionary<ulong, IdDictionary> _maps = new ConcurrentDictionary<ulong, IdDictionary>();
+ private static NvMapIdDictionary _maps = new NvMapIdDictionary();
public NvMapDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, owner)
{
- IdDictionary dict = _maps.GetOrAdd(Owner, (key) => new IdDictionary());
-
- dict.Add(0, new NvMapHandle());
}
public override NvInternalResult Ioctl(NvIoctl command, Span<byte> arguments)
@@ -232,19 +228,12 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
private int CreateHandleFromMap(NvMapHandle map)
{
- IdDictionary dict = _maps.GetOrAdd(Owner, (key) => new IdDictionary());
-
- return dict.Add(map);
+ return _maps.Add(map);
}
private static bool DeleteMapWithHandle(ulong pid, int handle)
{
- if (_maps.TryGetValue(pid, out IdDictionary dict))
- {
- return dict.Delete(handle) != null;
- }
-
- return false;
+ return _maps.Delete(handle) != null;
}
public static void IncrementMapRefCount(ulong pid, int handle)
@@ -277,12 +266,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
public static NvMapHandle GetMapFromHandle(ulong pid, int handle)
{
- if (_maps.TryGetValue(pid, out IdDictionary dict))
- {
- return dict.GetData<NvMapHandle>(handle);
- }
-
- return null;
+ return _maps.Get(handle);
}
}
}
diff --git a/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapIdDictionary.cs b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapIdDictionary.cs
new file mode 100644
index 00000000..c4733e94
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvMap/Types/NvMapIdDictionary.cs
@@ -0,0 +1,61 @@
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Threading;
+
+namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
+{
+ class NvMapIdDictionary
+ {
+ private readonly ConcurrentDictionary<int, NvMapHandle> _nvmapHandles;
+ private int _id;
+
+ public ICollection<NvMapHandle> Values => _nvmapHandles.Values;
+
+ public NvMapIdDictionary()
+ {
+ _nvmapHandles = new ConcurrentDictionary<int, NvMapHandle>();
+ }
+
+ public int Add(NvMapHandle handle)
+ {
+ int id = Interlocked.Add(ref _id, 4);
+
+ if (id != 0 && _nvmapHandles.TryAdd(id, handle))
+ {
+ return id;
+ }
+
+ throw new InvalidOperationException("NvMap ID overflow.");
+ }
+
+ public NvMapHandle Get(int id)
+ {
+ if (_nvmapHandles.TryGetValue(id, out NvMapHandle handle))
+ {
+ return handle;
+ }
+
+ return null;
+ }
+
+ public NvMapHandle Delete(int id)
+ {
+ if (_nvmapHandles.TryRemove(id, out NvMapHandle handle))
+ {
+ return handle;
+ }
+
+ return null;
+ }
+
+ public ICollection<NvMapHandle> Clear()
+ {
+ ICollection<NvMapHandle> values = _nvmapHandles.Values;
+
+ _nvmapHandles.Clear();
+
+ return values;
+ }
+ }
+} \ No newline at end of file