From 0e11ee3bce48eedcb39935545e385e40187866dd Mon Sep 17 00:00:00 2001 From: riperiperi Date: Fri, 17 May 2024 20:43:45 +0100 Subject: [PATCH] BufferPreFlush comments --- .../Memory/BufferPreFlush.cs | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/Ryujinx.Graphics.Gpu/Memory/BufferPreFlush.cs b/src/Ryujinx.Graphics.Gpu/Memory/BufferPreFlush.cs index eefc03903f..d58b9ea66d 100644 --- a/src/Ryujinx.Graphics.Gpu/Memory/BufferPreFlush.cs +++ b/src/Ryujinx.Graphics.Gpu/Memory/BufferPreFlush.cs @@ -17,6 +17,9 @@ namespace Ryujinx.Graphics.Gpu.Memory /// private const int DeactivateCopyThreshold = 200; + /// + /// Value that indicates whether a page has been flushed or copied before. + /// private enum PreFlushState { None, @@ -24,6 +27,11 @@ namespace Ryujinx.Graphics.Gpu.Memory HasCopied } + /// + /// Flush state for each page of the buffer. + /// Controls whether data should be copied to the flush buffer, what sync is expected + /// and unflushed copy counting for stopping copies that are no longer needed. + /// private struct PreFlushPage { public PreFlushState State; @@ -59,7 +67,10 @@ namespace Ryujinx.Graphics.Gpu.Memory _flushAction = flushAction; } - public void EnsureFlushBuffer() + /// + /// Ensure that the flush buffer exists. + /// + private void EnsureFlushBuffer() { if (_flushBuffer == BufferHandle.Null) { @@ -67,6 +78,12 @@ namespace Ryujinx.Graphics.Gpu.Memory } } + /// + /// Gets a page range from an address and size byte range. + /// + /// Range address + /// Range size + /// A page index and count private (int index, int count) GetPageRange(ulong address, ulong size) { ulong offset = address - _address; @@ -78,6 +95,12 @@ namespace Ryujinx.Graphics.Gpu.Memory return (basePage, 1 + endPage - basePage); } + /// + /// Gets an offset and size range in the parent buffer from a page index and count. + /// + /// Range start page + /// Range page count + /// Offset and size range private (int offset, int size) GetOffset(int startPage, int count) { int offset = (int)((ulong)startPage * PageSize - _misalignment); @@ -89,6 +112,11 @@ namespace Ryujinx.Graphics.Gpu.Memory return (offset, endOffset - offset); } + /// + /// Copy a range of pages from the parent buffer into the flush buffer. + /// + /// Range start page + /// Range page count private void CopyPageRange(int startPage, int count) { (int offset, int size) = GetOffset(startPage, count); @@ -98,6 +126,12 @@ namespace Ryujinx.Graphics.Gpu.Memory _context.Renderer.Pipeline.CopyBuffer(_buffer.Handle, _flushBuffer, offset, offset, size); } + /// + /// Copy a modified range into the flush buffer if it's marked as flushed. + /// Any pages the range overlaps are copied, and copies aren't repeated in the same sync number. + /// + /// Range address + /// Range size public void CopyModified(ulong address, ulong size) { (int baseIndex, int count) = GetPageRange(address, size); @@ -148,6 +182,15 @@ namespace Ryujinx.Graphics.Gpu.Memory } } + /// + /// Flush the given page range back into guest memory, optionally using data from the flush buffer. + /// The actual flushed range is an intersection of the page range and the address range. + /// + /// Address range start + /// Address range size + /// Page range start + /// Page range count + /// True if the data should come from the flush buffer private void FlushPageRange(ulong address, ulong size, int startPage, int count, bool preFlush) { (int pageOffset, int pageSize) = GetOffset(startPage, count); @@ -165,6 +208,14 @@ namespace Ryujinx.Graphics.Gpu.Memory } } + /// + /// Flush the given address range back into guest memory, optionally using data from the flush buffer. + /// When a copy has been performed on or before the waited sync number, the data can come from the flush buffer. + /// Otherwise, it flushes the parent buffer directly. + /// + /// Range address + /// Range size + /// Sync number that has been waited for public void FlushWithAction(ulong address, ulong size, ulong syncNumber) { // Copy the parts of the range that have pre-flush copies that have been completed. @@ -230,6 +281,9 @@ namespace Ryujinx.Graphics.Gpu.Memory } } + /// + /// Dispose the flush buffer, if present. + /// public void Dispose() { if (_flushBuffer != BufferHandle.Null)