diff options
| author | gdk <gab.dark.100@gmail.com> | 2019-10-26 23:41:01 -0300 |
|---|---|---|
| committer | Thog <thog@protonmail.com> | 2020-01-09 02:13:00 +0100 |
| commit | f2e84ff566b824aeb5158fa8432d7b26e2f94a09 (patch) | |
| tree | 01e8c99340f5f3bc9715c75fe5bdce9a20d64703 | |
| parent | 8cba252b238ee6cf6599ad2fc57793e6f76c5e2e (diff) | |
Flush buffers on copies
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Engine/MethodCopyBuffer.cs | 4 | ||||
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Memory/Buffer.cs | 11 | ||||
| -rw-r--r-- | 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 19ffb0e3..40560ab1 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<byte> 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 6f904d0f..e37fbc0f 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 6d7fab68..c4240061 100644 --- a/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs +++ b/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs @@ -484,18 +484,28 @@ 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; if (size != 0) @@ -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 |
