aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.GAL/Multithreading/Model
diff options
context:
space:
mode:
authorTSR Berry <20988865+TSRBerry@users.noreply.github.com>2023-04-08 01:22:00 +0200
committerMary <thog@protonmail.com>2023-04-27 23:51:14 +0200
commitcee712105850ac3385cd0091a923438167433f9f (patch)
tree4a5274b21d8b7f938c0d0ce18736d3f2993b11b1 /Ryujinx.Graphics.GAL/Multithreading/Model
parentcd124bda587ef09668a971fa1cac1c3f0cfc9f21 (diff)
Move solution and projects to src
Diffstat (limited to 'Ryujinx.Graphics.GAL/Multithreading/Model')
-rw-r--r--Ryujinx.Graphics.GAL/Multithreading/Model/CircularSpanPool.cs89
-rw-r--r--Ryujinx.Graphics.GAL/Multithreading/Model/ResultBox.cs7
-rw-r--r--Ryujinx.Graphics.GAL/Multithreading/Model/SpanRef.cs39
-rw-r--r--Ryujinx.Graphics.GAL/Multithreading/Model/TableRef.cs22
4 files changed, 0 insertions, 157 deletions
diff --git a/Ryujinx.Graphics.GAL/Multithreading/Model/CircularSpanPool.cs b/Ryujinx.Graphics.GAL/Multithreading/Model/CircularSpanPool.cs
deleted file mode 100644
index 4ea1a2c7..00000000
--- a/Ryujinx.Graphics.GAL/Multithreading/Model/CircularSpanPool.cs
+++ /dev/null
@@ -1,89 +0,0 @@
-using System;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Threading;
-
-namespace Ryujinx.Graphics.GAL.Multithreading.Model
-{
- /// <summary>
- /// A memory pool for passing through Span<T> resources with one producer and consumer.
- /// Data is copied on creation to part of the pool, then that region is reserved until it is disposed by the consumer.
- /// Similar to the command queue, this pool assumes that data is created and disposed in the same order.
- /// </summary>
- class CircularSpanPool
- {
- private ThreadedRenderer _renderer;
- private byte[] _pool;
- private int _size;
-
- private int _producerPtr;
- private int _producerSkipPosition = -1;
- private int _consumerPtr;
-
- public CircularSpanPool(ThreadedRenderer renderer, int size)
- {
- _renderer = renderer;
- _size = size;
- _pool = new byte[size];
- }
-
- public SpanRef<T> Insert<T>(ReadOnlySpan<T> data) where T : unmanaged
- {
- int size = data.Length * Unsafe.SizeOf<T>();
-
- // Wrapping aware circular queue.
- // If there's no space at the end of the pool for this span, we can't fragment it.
- // So just loop back around to the start. Remember the last skipped position.
-
- bool wraparound = _producerPtr + size >= _size;
- int index = wraparound ? 0 : _producerPtr;
-
- // _consumerPtr is from another thread, and we're taking it without a lock, so treat this as a snapshot in the past.
- // We know that it will always be before or equal to the producer pointer, and it cannot pass it.
- // This is enough to reason about if there is space in the queue for the data, even if we're checking against an outdated value.
-
- int consumer = _consumerPtr;
- bool beforeConsumer = _producerPtr < consumer;
-
- if (size > _size - 1 || (wraparound && beforeConsumer) || ((index < consumer || wraparound) && index + size >= consumer))
- {
- // Just get an array in the following situations:
- // - The data is too large to fit in the pool.
- // - A wraparound would happen but the consumer would be covered by it.
- // - The producer would catch up to the consumer as a result.
-
- return new SpanRef<T>(_renderer, data.ToArray());
- }
-
- data.CopyTo(MemoryMarshal.Cast<byte, T>(new Span<byte>(_pool).Slice(index, size)));
-
- if (wraparound)
- {
- _producerSkipPosition = _producerPtr;
- }
-
- _producerPtr = index + size;
-
- return new SpanRef<T>(data.Length);
- }
-
- public Span<T> Get<T>(int length) where T : unmanaged
- {
- int size = length * Unsafe.SizeOf<T>();
-
- if (_consumerPtr == Interlocked.CompareExchange(ref _producerSkipPosition, -1, _consumerPtr))
- {
- _consumerPtr = 0;
- }
-
- return MemoryMarshal.Cast<byte, T>(new Span<byte>(_pool).Slice(_consumerPtr, size));
- }
-
- public void Dispose<T>(int length) where T : unmanaged
- {
- int size = length * Unsafe.SizeOf<T>();
-
- _consumerPtr = _consumerPtr + size;
- }
- }
-}
diff --git a/Ryujinx.Graphics.GAL/Multithreading/Model/ResultBox.cs b/Ryujinx.Graphics.GAL/Multithreading/Model/ResultBox.cs
deleted file mode 100644
index 7a0be785..00000000
--- a/Ryujinx.Graphics.GAL/Multithreading/Model/ResultBox.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace Ryujinx.Graphics.GAL.Multithreading.Model
-{
- public class ResultBox<T>
- {
- public T Result;
- }
-}
diff --git a/Ryujinx.Graphics.GAL/Multithreading/Model/SpanRef.cs b/Ryujinx.Graphics.GAL/Multithreading/Model/SpanRef.cs
deleted file mode 100644
index 7dbebc76..00000000
--- a/Ryujinx.Graphics.GAL/Multithreading/Model/SpanRef.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using System;
-
-namespace Ryujinx.Graphics.GAL.Multithreading.Model
-{
- struct SpanRef<T> where T : unmanaged
- {
- private int _packedLengthId;
-
- public SpanRef(ThreadedRenderer renderer, T[] data)
- {
- _packedLengthId = -(renderer.AddTableRef(data) + 1);
- }
-
- public SpanRef(int length)
- {
- _packedLengthId = length;
- }
-
- public Span<T> Get(ThreadedRenderer renderer)
- {
- if (_packedLengthId >= 0)
- {
- return renderer.SpanPool.Get<T>(_packedLengthId);
- }
- else
- {
- return new Span<T>((T[])renderer.RemoveTableRef(-(_packedLengthId + 1)));
- }
- }
-
- public void Dispose(ThreadedRenderer renderer)
- {
- if (_packedLengthId > 0)
- {
- renderer.SpanPool.Dispose<T>(_packedLengthId);
- }
- }
- }
-}
diff --git a/Ryujinx.Graphics.GAL/Multithreading/Model/TableRef.cs b/Ryujinx.Graphics.GAL/Multithreading/Model/TableRef.cs
deleted file mode 100644
index 166aa71a..00000000
--- a/Ryujinx.Graphics.GAL/Multithreading/Model/TableRef.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-namespace Ryujinx.Graphics.GAL.Multithreading.Model
-{
- struct TableRef<T>
- {
- private int _index;
-
- public TableRef(ThreadedRenderer renderer, T reference)
- {
- _index = renderer.AddTableRef(reference);
- }
-
- public T Get(ThreadedRenderer renderer)
- {
- return (T)renderer.RemoveTableRef(_index);
- }
-
- public T2 GetAs<T2>(ThreadedRenderer renderer) where T2 : T
- {
- return (T2)renderer.RemoveTableRef(_index);
- }
- }
-}