From a10b2c5ff26886e9ffc6f19e3f0fe9505a503b2f Mon Sep 17 00:00:00 2001 From: gdkchan Date: Wed, 23 Jun 2021 20:51:41 -0300 Subject: Initial support for GPU channels (#2372) * Ground work for separate GPU channels * Rename TextureManager to TextureCache * Decouple texture bindings management from the texture cache * Rename BufferManager to BufferCache * Decouple buffer bindings management from the buffer cache * More comments and proper disposal * PR feedback * Force host state update on channel switch * Typo * PR feedback * Missing using --- Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoDevice.cs | 36 +++++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoDevice.cs') diff --git a/Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoDevice.cs b/Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoDevice.cs index d0fcf142..0e284ac5 100644 --- a/Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoDevice.cs +++ b/Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoDevice.cs @@ -25,6 +25,11 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo /// private struct CommandBuffer { + /// + /// Processor used to process the command buffer. Contains channel state. + /// + public GPFifoProcessor Processor; + /// /// The type of the command buffer. /// @@ -60,11 +65,11 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo private readonly ConcurrentQueue _commandBufferQueue; private CommandBuffer _currentCommandBuffer; + private GPFifoProcessor _prevChannelProcessor; private readonly bool _ibEnable; private readonly GpuContext _context; private readonly AutoResetEvent _event; - private readonly GPFifoProcessor _processor; private bool _interrupt; @@ -78,8 +83,6 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo _ibEnable = true; _context = context; _event = new AutoResetEvent(false); - - _processor = new GPFifoProcessor(context); } /// @@ -94,11 +97,13 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo /// Push a GPFIFO entry in the form of a prefetched command buffer. /// It is intended to be used by nvservices to handle special cases. /// + /// Processor used to process /// The command buffer containing the prefetched commands - public void PushHostCommandBuffer(int[] commandBuffer) + internal void PushHostCommandBuffer(GPFifoProcessor processor, int[] commandBuffer) { _commandBufferQueue.Enqueue(new CommandBuffer { + Processor = processor, Type = CommandBufferType.Prefetch, Words = commandBuffer, EntryAddress = ulong.MaxValue, @@ -109,9 +114,10 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo /// /// Create a CommandBuffer from a GPFIFO entry. /// + /// Processor used to process the command buffer pointed to by /// The GPFIFO entry /// A new CommandBuffer based on the GPFIFO entry - private CommandBuffer CreateCommandBuffer(GPEntry entry) + private static CommandBuffer CreateCommandBuffer(GPFifoProcessor processor, GPEntry entry) { CommandBufferType type = CommandBufferType.Prefetch; @@ -124,6 +130,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo return new CommandBuffer { + Processor = processor, Type = type, Words = null, EntryAddress = startAddress, @@ -134,8 +141,9 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo /// /// Pushes GPFIFO entries. /// + /// Processor used to process the command buffers pointed to by /// GPFIFO entries - public void PushEntries(ReadOnlySpan entries) + internal void PushEntries(GPFifoProcessor processor, ReadOnlySpan entries) { bool beforeBarrier = true; @@ -143,7 +151,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo { ulong entry = entries[index]; - CommandBuffer commandBuffer = CreateCommandBuffer(Unsafe.As(ref entry)); + CommandBuffer commandBuffer = CreateCommandBuffer(processor, Unsafe.As(ref entry)); if (beforeBarrier && commandBuffer.Type == CommandBufferType.Prefetch) { @@ -173,12 +181,24 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo /// public void DispatchCalls() { + // Use this opportunity to also dispose any pending channels that were closed. + _context.DisposePendingChannels(); + + // Process command buffers. while (_ibEnable && !_interrupt && _commandBufferQueue.TryDequeue(out CommandBuffer entry)) { _currentCommandBuffer = entry; _currentCommandBuffer.Fetch(_context); - _processor.Process(_currentCommandBuffer.Words); + // If we are changing the current channel, + // we need to force all the host state to be updated. + if (_prevChannelProcessor != entry.Processor) + { + _prevChannelProcessor = entry.Processor; + entry.Processor.ForceAllDirty(); + } + + entry.Processor.Process(_currentCommandBuffer.Words); } _interrupt = false; -- cgit v1.2.3