diff options
author | TSRBerry <20988865+TSRBerry@users.noreply.github.com> | 2023-06-28 20:20:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-28 20:20:10 +0200 |
commit | 7c989f88bdab65dfa7783e824a180220ba829bd0 (patch) | |
tree | 57ca5fa398d1fc2d97f7f1e14fcf74cfb6907fc3 /src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs | |
parent | 16fa98370472f843ebdae5addbb00e26899ebe55 (diff) |
[Ryujinx.Graphics.GAL] Address dotnet-format issues (#5366)1.1.941
* dotnet format style --severity info
Some changes were manually reverted.
* dotnet format analyzers --serverity info
Some changes have been minimally adapted.
* Restore a few unused methods and variables
* Silence dotnet format IDE0052 warnings
* Address dotnet format CA1816 warnings
* Address or silence dotnet format CA1069 warnings
* Address remaining dotnet format analyzer warnings
* Address review comments
* Address most dotnet format whitespace warnings
* Apply dotnet format whitespace formatting
A few of them have been manually reverted and the corresponding warning was silenced
* Revert formatting changes for while and for-loops
* Another rebase, another dotnet format run
* Run dotnet format whitespace after rebase
* Run dotnet format style after rebase
* Run dotnet format analyzers after rebase
* Run dotnet format after rebase and remove unused usings
- analyzers
- style
- whitespace
* Disable 'prefer switch expression' rule
* Add comments to disabled warnings
* Simplify properties and array initialization, Use const when possible, Remove trailing commas
* Start working on disabled warnings
* Address IDE0251 warnings
* Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas"
This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.
* dotnet format whitespace after rebase
* First dotnet format pass
* Address review feedback
* Add trailing commas
* Remove SuppressMessage for IDE0066
* Make explicit Equals implementation implicit
Diffstat (limited to 'src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs')
-rw-r--r-- | src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs b/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs index bc96f222..dc7aab36 100644 --- a/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs +++ b/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs @@ -26,24 +26,24 @@ namespace Ryujinx.Graphics.GAL.Multithreading private const int MaxRefsPerCommand = 2; private const int QueueCount = 10000; - private int _elementSize; - private IRenderer _baseRenderer; + private readonly int _elementSize; + private readonly IRenderer _baseRenderer; private Thread _gpuThread; private Thread _backendThread; private bool _running; - private AutoResetEvent _frameComplete = new AutoResetEvent(true); + private readonly AutoResetEvent _frameComplete = new(true); - private ManualResetEventSlim _galWorkAvailable; - private CircularSpanPool _spanPool; + private readonly ManualResetEventSlim _galWorkAvailable; + private readonly CircularSpanPool _spanPool; - private ManualResetEventSlim _invokeRun; - private AutoResetEvent _interruptRun; + private readonly ManualResetEventSlim _invokeRun; + private readonly AutoResetEvent _interruptRun; private bool _lastSampleCounterClear = true; - private byte[] _commandQueue; - private object[] _refQueue; + private readonly byte[] _commandQueue; + private readonly object[] _refQueue; private int _consumerPtr; private int _commandCount; @@ -79,7 +79,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading renderer.ScreenCaptured += (sender, info) => ScreenCaptured?.Invoke(this, info); renderer.SetInterruptAction(Interrupt); - Pipeline = new ThreadedPipeline(this, renderer.Pipeline); + Pipeline = new ThreadedPipeline(this); Window = new ThreadedWindow(this, renderer); Buffers = new BufferMap(); Sync = new SyncMap(); @@ -105,7 +105,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading _gpuThread = new Thread(gpuLoop) { - Name = "GPU.MainThread" + Name = "GPU.MainThread", }; _gpuThread.Start(); @@ -137,7 +137,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading { int commandPtr = _consumerPtr; - Span<byte> command = new Span<byte>(_commandQueue, commandPtr * _elementSize, _elementSize); + Span<byte> command = new(_commandQueue, commandPtr * _elementSize, _elementSize); // Run the command. @@ -180,10 +180,10 @@ namespace Ryujinx.Graphics.GAL.Multithreading _producerPtr = (_producerPtr + 1) % QueueCount; - Span<byte> memory = new Span<byte>(_commandQueue, taken * _elementSize, _elementSize); + Span<byte> memory = new(_commandQueue, taken * _elementSize, _elementSize); ref T result = ref Unsafe.As<byte, T>(ref MemoryMarshal.GetReference(memory)); - memory[memory.Length - 1] = (byte)((IGALCommand)result).CommandType; + memory[^1] = (byte)((IGALCommand)result).CommandType; return ref result; } @@ -294,7 +294,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading { var program = new ThreadedProgram(this); - SourceProgramRequest request = new SourceProgramRequest(program, shaders, info); + SourceProgramRequest request = new(program, shaders, info); Programs.Add(request); @@ -332,8 +332,10 @@ namespace Ryujinx.Graphics.GAL.Multithreading } else { - var texture = new ThreadedTexture(this, info, scale); - texture.Base = _baseRenderer.CreateTexture(info, scale); + var texture = new ThreadedTexture(this, info, scale) + { + Base = _baseRenderer.CreateTexture(info, scale), + }; return texture; } @@ -349,7 +351,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading { if (IsGpuThread()) { - ResultBox<PinnedSpan<byte>> box = new ResultBox<PinnedSpan<byte>>(); + ResultBox<PinnedSpan<byte>> box = new(); New<BufferGetDataCommand>().Set(buffer, offset, size, Ref(box)); InvokeCommand(); @@ -363,7 +365,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading public Capabilities GetCapabilities() { - ResultBox<Capabilities> box = new ResultBox<Capabilities>(); + ResultBox<Capabilities> box = new(); New<GetCapabilitiesCommand>().Set(Ref(box)); InvokeCommand(); @@ -393,7 +395,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading { var program = new ThreadedProgram(this); - BinaryProgramRequest request = new BinaryProgramRequest(program, programBinary, hasFragmentShader, info); + BinaryProgramRequest request = new(program, programBinary, hasFragmentShader, info); Programs.Add(request); New<CreateProgramCommand>().Set(Ref((IProgramRequest)request)); @@ -410,7 +412,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading public ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler, bool hostReserved) { - ThreadedCounterEvent evt = new ThreadedCounterEvent(this, type, _lastSampleCounterClear); + ThreadedCounterEvent evt = new(this, type, _lastSampleCounterClear); New<ReportCounterCommand>().Set(Ref(evt), type, Ref(resultHandler), hostReserved); QueueCommand(); @@ -466,7 +468,9 @@ namespace Ryujinx.Graphics.GAL.Multithreading { lock (_interruptLock) { - while (Interlocked.CompareExchange(ref _interruptAction, action, null) != null) { } + while (Interlocked.CompareExchange(ref _interruptAction, action, null) != null) + { + } _galWorkAvailable.Set(); @@ -497,6 +501,8 @@ namespace Ryujinx.Graphics.GAL.Multithreading public void Dispose() { + GC.SuppressFinalize(this); + // Dispose must happen from the render thread, after all commands have completed. // Stop the GPU thread. @@ -520,4 +526,4 @@ namespace Ryujinx.Graphics.GAL.Multithreading Sync.Dispose(); } } -}
\ No newline at end of file +} |