diff options
| author | TSR Berry <20988865+TSRBerry@users.noreply.github.com> | 2023-04-08 01:22:00 +0200 |
|---|---|---|
| committer | Mary <thog@protonmail.com> | 2023-04-27 23:51:14 +0200 |
| commit | cee712105850ac3385cd0091a923438167433f9f (patch) | |
| tree | 4a5274b21d8b7f938c0d0ce18736d3f2993b11b1 /Ryujinx.Graphics.Vulkan/Queries/CounterQueueEvent.cs | |
| parent | cd124bda587ef09668a971fa1cac1c3f0cfc9f21 (diff) | |
Move solution and projects to src
Diffstat (limited to 'Ryujinx.Graphics.Vulkan/Queries/CounterQueueEvent.cs')
| -rw-r--r-- | Ryujinx.Graphics.Vulkan/Queries/CounterQueueEvent.cs | 170 |
1 files changed, 0 insertions, 170 deletions
diff --git a/Ryujinx.Graphics.Vulkan/Queries/CounterQueueEvent.cs b/Ryujinx.Graphics.Vulkan/Queries/CounterQueueEvent.cs deleted file mode 100644 index d3aedb2f..00000000 --- a/Ryujinx.Graphics.Vulkan/Queries/CounterQueueEvent.cs +++ /dev/null @@ -1,170 +0,0 @@ -using Ryujinx.Graphics.GAL; -using System; -using System.Threading; - -namespace Ryujinx.Graphics.Vulkan.Queries -{ - class CounterQueueEvent : ICounterEvent - { - public event EventHandler<ulong> OnResult; - - public CounterType Type { get; } - public bool ClearCounter { get; private set; } - - public bool Disposed { get; private set; } - public bool Invalid { get; set; } - - public ulong DrawIndex { get; } - - private CounterQueue _queue; - private BufferedQuery _counter; - - private bool _hostAccessReserved = false; - private int _refCount = 1; // Starts with a reference from the counter queue. - - private object _lock = new object(); - private ulong _result = ulong.MaxValue; - private double _divisor = 1f; - - public CounterQueueEvent(CounterQueue queue, CounterType type, ulong drawIndex) - { - _queue = queue; - - _counter = queue.GetQueryObject(); - Type = type; - - DrawIndex = drawIndex; - - _counter.Begin(_queue.ResetSequence); - } - - public Auto<DisposableBuffer> GetBuffer() - { - return _counter.GetBuffer(); - } - - internal void Clear(bool counterReset) - { - if (counterReset) - { - _counter.Reset(); - } - - ClearCounter = true; - } - - internal void Complete(bool withResult, double divisor) - { - _counter.End(withResult); - - _divisor = divisor; - } - - internal bool TryConsume(ref ulong result, bool block, AutoResetEvent wakeSignal = null) - { - lock (_lock) - { - if (Disposed) - { - return true; - } - - if (ClearCounter) - { - result = 0; - } - - long queryResult; - - if (block) - { - queryResult = _counter.AwaitResult(wakeSignal); - } - else - { - if (!_counter.TryGetResult(out queryResult)) - { - return false; - } - } - - result += _divisor == 1 ? (ulong)queryResult : (ulong)Math.Ceiling(queryResult / _divisor); - - _result = result; - - OnResult?.Invoke(this, result); - - Dispose(); // Return the our resources to the pool. - - return true; - } - } - - public void Flush() - { - if (Disposed) - { - return; - } - - // Tell the queue to process all events up to this one. - _queue.FlushTo(this); - } - - public void DecrementRefCount() - { - if (Interlocked.Decrement(ref _refCount) == 0) - { - DisposeInternal(); - } - } - - public bool ReserveForHostAccess() - { - if (_hostAccessReserved) - { - return true; - } - - if (IsValueAvailable()) - { - return false; - } - - if (Interlocked.Increment(ref _refCount) == 1) - { - Interlocked.Decrement(ref _refCount); - - return false; - } - - _hostAccessReserved = true; - - return true; - } - - public void ReleaseHostAccess() - { - _hostAccessReserved = false; - - DecrementRefCount(); - } - - private void DisposeInternal() - { - _queue.ReturnQueryObject(_counter); - } - - private bool IsValueAvailable() - { - return _result != ulong.MaxValue || _counter.TryGetResult(out _); - } - - public void Dispose() - { - Disposed = true; - - DecrementRefCount(); - } - } -} |
