aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Vulkan/BufferHolder.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2023-12-04 16:30:19 -0300
committerGitHub <noreply@github.com>2023-12-04 20:30:19 +0100
commit1df6c07f78c4c3b8c7fc679d7466f79a10c2d496 (patch)
treeb80d247e199503274054259cb2707f44cc072993 /src/Ryujinx.Graphics.Vulkan/BufferHolder.cs
parent0531c16326c8215bff1c0a98f3ed217f01065446 (diff)
Implement support for multi-range buffers using Vulkan sparse mappings (#5427)
* Pass MultiRange to BufferManager * Implement support for multi-range buffers using Vulkan sparse mappings * Use multi-range for remaining buffers, delete old methods * Assume that more buffers are contiguous * Dispose multi-range buffers after they are removed from the list * Properly init BufferBounds for constant and storage buffers * Do not try reading zero bytes data from an unmapped address on the shader cache + PR feedback * Fix misaligned sparse buffer offsets * Null check can be simplified * PR feedback
Diffstat (limited to 'src/Ryujinx.Graphics.Vulkan/BufferHolder.cs')
-rw-r--r--src/Ryujinx.Graphics.Vulkan/BufferHolder.cs40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/Ryujinx.Graphics.Vulkan/BufferHolder.cs b/src/Ryujinx.Graphics.Vulkan/BufferHolder.cs
index b1887eaa..b54ff3ab 100644
--- a/src/Ryujinx.Graphics.Vulkan/BufferHolder.cs
+++ b/src/Ryujinx.Graphics.Vulkan/BufferHolder.cs
@@ -46,7 +46,7 @@ namespace Ryujinx.Graphics.Vulkan
private bool _lastAccessIsWrite;
- private readonly BufferAllocationType _baseType;
+ private BufferAllocationType _baseType;
private BufferAllocationType _currentType;
private bool _swapQueued;
@@ -109,6 +109,22 @@ namespace Ryujinx.Graphics.Vulkan
_flushLock = new ReaderWriterLockSlim();
}
+ public BufferHolder(VulkanRenderer gd, Device device, VkBuffer buffer, int size, Auto<MemoryAllocation>[] storageAllocations)
+ {
+ _gd = gd;
+ _device = device;
+ _waitable = new MultiFenceHolder(size);
+ _buffer = new Auto<DisposableBuffer>(new DisposableBuffer(gd.Api, device, buffer), _waitable, storageAllocations);
+ _bufferHandle = buffer.Handle;
+ Size = size;
+
+ _baseType = BufferAllocationType.Sparse;
+ _currentType = BufferAllocationType.Sparse;
+ DesiredType = BufferAllocationType.Sparse;
+
+ _flushLock = new ReaderWriterLockSlim();
+ }
+
public bool TryBackingSwap(ref CommandBufferScoped? cbs)
{
if (_swapQueued && DesiredType != _currentType)
@@ -122,7 +138,7 @@ namespace Ryujinx.Graphics.Vulkan
var currentBuffer = _buffer;
IntPtr currentMap = _map;
- (VkBuffer buffer, MemoryAllocation allocation, BufferAllocationType resultType) = _gd.BufferManager.CreateBacking(_gd, Size, DesiredType, false, _currentType);
+ (VkBuffer buffer, MemoryAllocation allocation, BufferAllocationType resultType) = _gd.BufferManager.CreateBacking(_gd, Size, DesiredType, false, false, _currentType);
if (buffer.Handle != 0)
{
@@ -253,6 +269,14 @@ namespace Ryujinx.Graphics.Vulkan
}
}
+ public void Pin()
+ {
+ if (_baseType == BufferAllocationType.Auto)
+ {
+ _baseType = _currentType;
+ }
+ }
+
public unsafe Auto<DisposableBufferView> CreateView(VkFormat format, int offset, int size, Action invalidateView)
{
var bufferViewCreateInfo = new BufferViewCreateInfo
@@ -506,6 +530,16 @@ namespace Ryujinx.Graphics.Vulkan
}
}
+ public Auto<MemoryAllocation> GetAllocation()
+ {
+ return _allocationAuto;
+ }
+
+ public (DeviceMemory, ulong) GetDeviceMemoryAndOffset()
+ {
+ return (_allocation.Memory, _allocation.Offset);
+ }
+
public void SignalWrite(int offset, int size)
{
ConsiderBackingSwap();
@@ -1072,7 +1106,7 @@ namespace Ryujinx.Graphics.Vulkan
}
else
{
- _allocationAuto.Dispose();
+ _allocationAuto?.Dispose();
}
_flushLock.EnterWriteLock();