From 04dce402ac94679c5439038be1c8ce090e7ad4cb Mon Sep 17 00:00:00 2001 From: gdkchan Date: Mon, 12 Jul 2021 16:48:57 -0300 Subject: Implement a fast path for I2M transfers (#2467) --- .../Engine/GPFifo/GPFifoProcessor.cs | 53 ++++++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/Engine/GPFifo') diff --git a/Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoProcessor.cs b/Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoProcessor.cs index dd5e6fe5..ea34d6cd 100644 --- a/Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoProcessor.cs +++ b/Ryujinx.Graphics.Gpu/Engine/GPFifo/GPFifoProcessor.cs @@ -18,6 +18,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo private const int MacrosCount = 0x80; private const int MacroIndexMask = MacrosCount - 1; + private const int LoadInlineDataMethodOffset = 0x6d; private const int UniformBufferUpdateDataMethodOffset = 0x8e4; private readonly GpuChannel _channel; @@ -78,6 +79,11 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo if (_state.MethodCount != 0) { + if (TryFastI2mBufferUpdate(commandBuffer, ref index)) + { + continue; + } + Send(_state.Method, command, _state.SubChannel, _state.MethodCount <= 1); if (!_state.NonIncrementing) @@ -123,6 +129,46 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo _3dClass.FlushUboDirty(); } + /// + /// Tries to perform a fast Inline-to-Memory data update. + /// If successful, all data will be copied at once, and + /// command buffer entries will be consumed. + /// + /// Command buffer where the data is contained + /// Offset at where the data is located, auto-incremented on success + /// True if the fast copy was successful, false otherwise + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private bool TryFastI2mBufferUpdate(ReadOnlySpan commandBuffer, ref int offset) + { + if (_state.Method == LoadInlineDataMethodOffset && _state.NonIncrementing && _state.SubChannel <= 2) + { + int availableCount = commandBuffer.Length - offset; + int consumeCount = Math.Min(_state.MethodCount, availableCount); + + var data = commandBuffer.Slice(offset, consumeCount); + + if (_state.SubChannel == 0) + { + _3dClass.LoadInlineData(data); + } + else if (_state.SubChannel == 1) + { + _computeClass.LoadInlineData(data); + } + else /* if (_state.SubChannel == 2) */ + { + _i2mClass.LoadInlineData(data); + } + + offset += consumeCount - 1; + _state.MethodCount -= consumeCount; + + return true; + } + + return false; + } + /// /// Tries to perform a fast constant buffer data update. /// If successful, all data will be copied at once, and + 1 @@ -132,13 +178,14 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo /// Command buffer where is contained /// Offset at where is located /// True if the fast copy was successful, false otherwise + [MethodImpl(MethodImplOptions.AggressiveInlining)] private bool TryFastUniformBufferUpdate(CompressedMethod meth, ReadOnlySpan commandBuffer, int offset) { int availableCount = commandBuffer.Length - offset; - if (meth.MethodCount < availableCount && - meth.SecOp == SecOp.NonIncMethod && - meth.MethodAddress == UniformBufferUpdateDataMethodOffset) + if (meth.MethodAddress == UniformBufferUpdateDataMethodOffset && + meth.MethodCount < availableCount && + meth.SecOp == SecOp.NonIncMethod) { _3dClass.ConstantBufferUpdate(commandBuffer.Slice(offset + 1, meth.MethodCount)); -- cgit v1.2.3