diff options
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Memory/BufferCache.cs')
-rw-r--r-- | Ryujinx.Graphics.Gpu/Memory/BufferCache.cs | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/Ryujinx.Graphics.Gpu/Memory/BufferCache.cs b/Ryujinx.Graphics.Gpu/Memory/BufferCache.cs index 14b177aa..894d009c 100644 --- a/Ryujinx.Graphics.Gpu/Memory/BufferCache.cs +++ b/Ryujinx.Graphics.Gpu/Memory/BufferCache.cs @@ -27,6 +27,7 @@ namespace Ryujinx.Graphics.Gpu.Memory private Buffer[] _bufferOverlaps; private readonly Dictionary<ulong, BufferCacheEntry> _dirtyCache; + private readonly Dictionary<ulong, BufferCacheEntry> _modifiedCache; public event Action NotifyBuffersModified; @@ -45,6 +46,9 @@ namespace Ryujinx.Graphics.Gpu.Memory _bufferOverlaps = new Buffer[OverlapsBufferInitialCapacity]; _dirtyCache = new Dictionary<ulong, BufferCacheEntry>(); + + // There are a lot more entries on the modified cache, so it is separate from the one for ForceDirty. + _modifiedCache = new Dictionary<ulong, BufferCacheEntry>(); } /// <summary> @@ -146,6 +150,30 @@ namespace Ryujinx.Graphics.Gpu.Memory } /// <summary> + /// Checks if the given buffer range has been GPU modifed. + /// </summary> + /// <param name="memoryManager">GPU memory manager where the buffer is mapped</param> + /// <param name="gpuVa">Start GPU virtual address of the buffer</param> + /// <param name="size">Size in bytes of the buffer</param> + /// <returns>True if modified, false otherwise</returns> + public bool CheckModified(MemoryManager memoryManager, ulong gpuVa, ulong size, out ulong outAddr) + { + if (!_modifiedCache.TryGetValue(gpuVa, out BufferCacheEntry result) || + result.EndGpuAddress < gpuVa + size || + result.UnmappedSequence != result.Buffer.UnmappedSequence) + { + ulong address = TranslateAndCreateBuffer(memoryManager, gpuVa, size); + result = new BufferCacheEntry(address, gpuVa, GetBuffer(address, size)); + + _modifiedCache[gpuVa] = result; + } + + outAddr = result.Address; + + return result.Buffer.IsModified(result.Address, size); + } + + /// <summary> /// Creates a new buffer for the specified range, if needed. /// If a buffer where this range can be fully contained already exists, /// then the creation of a new buffer is not necessary. @@ -327,18 +355,6 @@ namespace Ryujinx.Graphics.Gpu.Memory } /// <summary> - /// Gets a buffer sub-range for a given GPU memory range. - /// </summary> - /// <param name="memoryManager">GPU memory manager where the buffer is mapped</param> - /// <param name="gpuVa">Start GPU virtual address of the buffer</param> - /// <param name="size">Size in bytes of the buffer</param> - /// <returns>The buffer sub-range for the given range</returns> - public BufferRange GetGpuBufferRange(MemoryManager memoryManager, ulong gpuVa, ulong size) - { - return GetBufferRange(TranslateAndCreateBuffer(memoryManager, gpuVa, size), size); - } - - /// <summary> /// Gets a buffer sub-range starting at a given memory address. /// </summary> /// <param name="address">Start address of the memory range</param> |