From df820a72def62319fe97236a2006c64bfb7c065a Mon Sep 17 00:00:00 2001 From: gdkchan Date: Tue, 12 Jan 2021 18:50:54 -0300 Subject: Implement clear buffer (fast path) (#1902) * Implement clear buffer (fast path) * Remove blank line --- Ryujinx.Graphics.Gpu/Engine/MethodCopyBuffer.cs | 20 ++++++++++-- Ryujinx.Graphics.Gpu/Memory/BufferManager.cs | 22 +++++++++++++ .../State/BufferSwizzleComponent.cs | 16 ++++++++++ Ryujinx.Graphics.Gpu/State/CopyBufferSwizzle.cs | 36 ++++++++++++++++++++++ Ryujinx.Graphics.Gpu/State/MethodOffset.cs | 2 ++ 5 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 Ryujinx.Graphics.Gpu/State/BufferSwizzleComponent.cs (limited to 'Ryujinx.Graphics.Gpu') diff --git a/Ryujinx.Graphics.Gpu/Engine/MethodCopyBuffer.cs b/Ryujinx.Graphics.Gpu/Engine/MethodCopyBuffer.cs index 6f03dc5d..15ebb236 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MethodCopyBuffer.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MethodCopyBuffer.cs @@ -200,8 +200,24 @@ namespace Ryujinx.Graphics.Gpu.Engine } else { - // Buffer to buffer copy. - BufferManager.CopyBuffer(cbp.SrcAddress, cbp.DstAddress, (uint)size); + if (remap && + swizzle.UnpackDstX() == BufferSwizzleComponent.ConstA && + swizzle.UnpackDstY() == BufferSwizzleComponent.ConstA && + swizzle.UnpackDstZ() == BufferSwizzleComponent.ConstA && + swizzle.UnpackDstW() == BufferSwizzleComponent.ConstA && + swizzle.UnpackSrcComponentsCount() == 1 && + swizzle.UnpackDstComponentsCount() == 1 && + swizzle.UnpackComponentSize() == 4) + { + // Fast path for clears when remap is enabled. + BufferManager.ClearBuffer(cbp.DstAddress, (uint)size * 4, state.Get(MethodOffset.CopyBufferConstA)); + } + else + { + // TODO: Implement remap functionality. + // Buffer to buffer copy. + BufferManager.CopyBuffer(cbp.SrcAddress, cbp.DstAddress, (uint)size); + } } } } diff --git a/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs b/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs index 1d48b38c..0c643191 100644 --- a/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs +++ b/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs @@ -821,6 +821,28 @@ namespace Ryujinx.Graphics.Gpu.Memory dstBuffer.Flush(dstAddress, size); } + /// + /// Clears a buffer at a given address with the specified value. + /// + /// + /// Both the address and size must be aligned to 4 bytes. + /// + /// GPU virtual address of the region to clear + /// Number of bytes to clear + /// Value to be written into the buffer + public void ClearBuffer(GpuVa gpuVa, ulong size, uint value) + { + ulong address = TranslateAndCreateBuffer(gpuVa.Pack(), size); + + Buffer buffer = GetBuffer(address, size); + + int offset = (int)(address - buffer.Address); + + _context.Renderer.Pipeline.ClearBuffer(buffer.Handle, offset, (int)size, value); + + buffer.Flush(address, size); + } + /// /// Gets a buffer sub-range for a given memory range. /// diff --git a/Ryujinx.Graphics.Gpu/State/BufferSwizzleComponent.cs b/Ryujinx.Graphics.Gpu/State/BufferSwizzleComponent.cs new file mode 100644 index 00000000..5c23cb2d --- /dev/null +++ b/Ryujinx.Graphics.Gpu/State/BufferSwizzleComponent.cs @@ -0,0 +1,16 @@ +namespace Ryujinx.Graphics.Gpu.State +{ + /// + /// Buffer swizzle component. + /// + enum BufferSwizzleComponent + { + SrcX, + SrcY, + SrcZ, + SrcW, + ConstA, + ConstB, + NoWrite + } +} diff --git a/Ryujinx.Graphics.Gpu/State/CopyBufferSwizzle.cs b/Ryujinx.Graphics.Gpu/State/CopyBufferSwizzle.cs index b4a9d9c2..94b650c4 100644 --- a/Ryujinx.Graphics.Gpu/State/CopyBufferSwizzle.cs +++ b/Ryujinx.Graphics.Gpu/State/CopyBufferSwizzle.cs @@ -9,6 +9,42 @@ namespace Ryujinx.Graphics.Gpu.State public uint Swizzle; #pragma warning restore CS0649 + /// + /// Unpacks the source for the buffer destination vector X component. + /// + /// Destination component + public BufferSwizzleComponent UnpackDstX() + { + return (BufferSwizzleComponent)(Swizzle & 7); + } + + /// + /// Unpacks the source for the buffer destination vector Y component. + /// + /// Destination component + public BufferSwizzleComponent UnpackDstY() + { + return (BufferSwizzleComponent)((Swizzle >> 4) & 7); + } + + /// + /// Unpacks the source for the buffer destination vector Z component. + /// + /// Destination component + public BufferSwizzleComponent UnpackDstZ() + { + return (BufferSwizzleComponent)((Swizzle >> 8) & 7); + } + + /// + /// Unpacks the source for the buffer destination vector W component. + /// + /// Destination component + public BufferSwizzleComponent UnpackDstW() + { + return (BufferSwizzleComponent)((Swizzle >> 12) & 7); + } + /// /// Unpacks the size of each vector component of the copy. /// diff --git a/Ryujinx.Graphics.Gpu/State/MethodOffset.cs b/Ryujinx.Graphics.Gpu/State/MethodOffset.cs index 6ec94c1b..4504e6b1 100644 --- a/Ryujinx.Graphics.Gpu/State/MethodOffset.cs +++ b/Ryujinx.Graphics.Gpu/State/MethodOffset.cs @@ -23,6 +23,8 @@ namespace Ryujinx.Graphics.Gpu.State TfBufferState = 0xe0, CopyBufferParams = 0x100, TfState = 0x1c0, + CopyBufferConstA = 0x1c0, + CopyBufferConstB = 0x1c1, CopyBufferSwizzle = 0x1c2, CopyBufferDstTexture = 0x1c3, CopyBufferSrcTexture = 0x1ca, -- cgit v1.2.3