From f2e84ff566b824aeb5158fa8432d7b26e2f94a09 Mon Sep 17 00:00:00 2001 From: gdk Date: Sat, 26 Oct 2019 23:41:01 -0300 Subject: [PATCH] Flush buffers on copies --- .../Engine/MethodCopyBuffer.cs | 4 --- Ryujinx.Graphics.Gpu/Memory/Buffer.cs | 11 ++++++ Ryujinx.Graphics.Gpu/Memory/BufferManager.cs | 34 +++++++++---------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/Ryujinx.Graphics.Gpu/Engine/MethodCopyBuffer.cs b/Ryujinx.Graphics.Gpu/Engine/MethodCopyBuffer.cs index 19ffb0e3ce..40560ab13d 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MethodCopyBuffer.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MethodCopyBuffer.cs @@ -69,10 +69,6 @@ namespace Ryujinx.Graphics.Gpu.Engine { // Buffer to buffer copy. _bufferManager.CopyBuffer(cbp.SrcAddress, cbp.DstAddress, (uint)size); - - Span data = _context.MemoryAccessor.Read(cbp.SrcAddress.Pack(), (uint)size); - - _context.MemoryAccessor.Write(cbp.DstAddress.Pack(), data); } } } diff --git a/Ryujinx.Graphics.Gpu/Memory/Buffer.cs b/Ryujinx.Graphics.Gpu/Memory/Buffer.cs index 6f904d0fe0..e37fbc0fc2 100644 --- a/Ryujinx.Graphics.Gpu/Memory/Buffer.cs +++ b/Ryujinx.Graphics.Gpu/Memory/Buffer.cs @@ -9,6 +9,8 @@ namespace Ryujinx.Graphics.Gpu.Memory private IBuffer _buffer; + public IBuffer HostBuffer => _buffer; + public ulong Address { get; } public ulong Size { get; } @@ -86,6 +88,15 @@ namespace Ryujinx.Graphics.Gpu.Memory _buffer.CopyTo(destination._buffer, 0, dstOffset, (int)Size); } + public void Flush(ulong address, ulong size) + { + int offset = (int)(address - Address); + + byte[] data = _buffer.GetData(offset, (int)size); + + _context.PhysicalMemory.Write(address, data); + } + public void Invalidate() { _buffer.SetData(0, _context.PhysicalMemory.Read(Address, Size)); diff --git a/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs b/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs index 6d7fab68b9..c4240061b2 100644 --- a/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs +++ b/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs @@ -484,17 +484,27 @@ namespace Ryujinx.Graphics.Gpu.Memory ulong srcAddress = TranslateAndCreateBuffer(srcVa.Pack(), size); ulong dstAddress = TranslateAndCreateBuffer(dstVa.Pack(), size); - BufferRange srcBuffer = GetBufferRange(srcAddress, size); - BufferRange dstBuffer = GetBufferRange(dstAddress, size); + Buffer srcBuffer = GetBuffer(srcAddress, size); + Buffer dstBuffer = GetBuffer(dstAddress, size); - srcBuffer.Buffer.CopyTo( - dstBuffer.Buffer, - srcBuffer.Offset, - dstBuffer.Offset, + int srcOffset = (int)(srcAddress - srcBuffer.Address); + int dstOffset = (int)(dstAddress - dstBuffer.Address); + + srcBuffer.HostBuffer.CopyTo( + dstBuffer.HostBuffer, + srcOffset, + dstOffset, (int)size); + + dstBuffer.Flush(dstAddress, size); } private BufferRange GetBufferRange(ulong address, ulong size) + { + return GetBuffer(address, size).GetRange(address, size); + } + + private Buffer GetBuffer(ulong address, ulong size) { Buffer buffer; @@ -509,7 +519,7 @@ namespace Ryujinx.Graphics.Gpu.Memory buffer = _buffers.FindFirstOverlap(address, 1); } - return buffer.GetRange(address, size); + return buffer; } private void SynchronizeBufferRange(ulong address, ulong size) @@ -521,15 +531,5 @@ namespace Ryujinx.Graphics.Gpu.Memory buffer.SynchronizeMemory(address, size); } } - - public void InvalidateRange(ulong address, ulong size) - { - Buffer[] overlappingBuffers = _buffers.FindOverlaps(address, size); - - foreach (Buffer buffer in overlappingBuffers) - { - buffer.Invalidate(); - } - } } } \ No newline at end of file