diff --git a/src/Ryujinx.Graphics.Gpu/Memory/BufferBackingState.cs b/src/Ryujinx.Graphics.Gpu/Memory/BufferBackingState.cs index 591d937db4..27d1c19e8f 100644 --- a/src/Ryujinx.Graphics.Gpu/Memory/BufferBackingState.cs +++ b/src/Ryujinx.Graphics.Gpu/Memory/BufferBackingState.cs @@ -4,6 +4,10 @@ using System.Collections.Generic; namespace Ryujinx.Graphics.Gpu.Memory { + /// + /// Type of backing memory. + /// In ascending order of priority when merging multiple buffer backing states. + /// internal enum BufferBackingType { HostMemory, @@ -45,6 +49,13 @@ namespace Ryujinx.Graphics.Gpu.Memory private readonly int _size; + /// + /// Initialize the buffer backing state for a given parent buffer. + /// + /// Gpu context + /// Parent buffer + /// Initial buffer stage + /// Buffers to inherit state from public BufferBackingState(GpuContext context, Buffer parent, BufferStage stage, IEnumerable baseBuffers = null) { _size = (int)parent.Size; @@ -99,11 +110,22 @@ namespace Ryujinx.Graphics.Gpu.Memory } } + /// + /// Combine buffer backing types, selecting the one with highest priority. + /// + /// First buffer backing type + /// Second buffer backing type + /// Combined buffer backing type private static BufferBackingType CombineTypes(BufferBackingType left, BufferBackingType right) { return (BufferBackingType)Math.Max((int)left, (int)right); } + /// + /// Combine the state from the given buffer backing state with this one, + /// so that the state isn't lost when migrating buffers. + /// + /// Buffer state to combine into this state private void CombineState(BufferBackingState oldState) { _setCount += oldState._setCount; @@ -118,6 +140,11 @@ namespace Ryujinx.Graphics.Gpu.Memory _desiredType = CombineTypes(_desiredType, oldState._desiredType); } + /// + /// Get the buffer access for the desired backing type, and record that type as now being active. + /// + /// Parent buffer + /// Buffer access public BufferAccess SwitchAccess(Buffer parent) { BufferAccess access = parent.SparseCompatible ? BufferAccess.SparseCompatible : BufferAccess.Default; @@ -145,6 +172,9 @@ namespace Ryujinx.Graphics.Gpu.Memory return access; } + /// + /// Record when data has been uploaded to the buffer. + /// public void RecordSet() { _setCount++; @@ -152,6 +182,9 @@ namespace Ryujinx.Graphics.Gpu.Memory ConsiderUseCounts(); } + /// + /// Record when data has been flushed from the buffer. + /// public void RecordFlush() { if (_lastFlushWrite != _writeCount) @@ -162,11 +195,20 @@ namespace Ryujinx.Graphics.Gpu.Memory } } + /// + /// Determine if the buffer backing should be changed. + /// + /// True if the desired backing type is different from the current type public readonly bool ShouldChangeBacking() { return _desiredType != _activeType; } + /// + /// Determine if the buffer backing should be changed, considering a new use with the given buffer stage. + /// + /// Buffer stage for the use + /// True if the desired backing type is different from the current type public bool ShouldChangeBacking(BufferStage stage) { if (!_canSwap) @@ -202,6 +244,10 @@ namespace Ryujinx.Graphics.Gpu.Memory return _desiredType != _activeType; } + /// + /// Evaluate the current counts to determine what the buffer's desired backing type is. + /// This method depends on heuristics devised by testing a variety of software. + /// private void ConsiderUseCounts() { if (_canSwap)