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
This commit is contained in:
gdkchan 2023-12-04 16:30:19 -03:00 committed by GitHub
parent 0531c16326
commit 1df6c07f78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 1241 additions and 233 deletions

View file

@ -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();