Vulkan: Buffer alignment

This commit is contained in:
sunshineinabox
2026-02-28 15:51:04 -06:00
committed by KeatonTheBot
parent 491fb3ccfb
commit 59c277bc6c
3 changed files with 37 additions and 4 deletions
@@ -54,6 +54,7 @@ namespace Ryujinx.Graphics.Vulkan
public readonly uint VertexBufferAlignment; public readonly uint VertexBufferAlignment;
public readonly uint SubTexelPrecisionBits; public readonly uint SubTexelPrecisionBits;
public readonly ulong MinResourceAlignment; public readonly ulong MinResourceAlignment;
public readonly ulong MinTexelBufferAlignment;
public HardwareCapabilities( public HardwareCapabilities(
bool supportsIndexTypeUint8, bool supportsIndexTypeUint8,
@@ -93,7 +94,8 @@ namespace Ryujinx.Graphics.Vulkan
PortabilitySubsetFlags portabilitySubset, PortabilitySubsetFlags portabilitySubset,
uint vertexBufferAlignment, uint vertexBufferAlignment,
uint subTexelPrecisionBits, uint subTexelPrecisionBits,
ulong minResourceAlignment) ulong minResourceAlignment,
ulong minTexelBufferAlignment)
{ {
SupportsIndexTypeUint8 = supportsIndexTypeUint8; SupportsIndexTypeUint8 = supportsIndexTypeUint8;
SupportsCustomBorderColor = supportsCustomBorderColor; SupportsCustomBorderColor = supportsCustomBorderColor;
@@ -133,6 +135,7 @@ namespace Ryujinx.Graphics.Vulkan
VertexBufferAlignment = vertexBufferAlignment; VertexBufferAlignment = vertexBufferAlignment;
SubTexelPrecisionBits = subTexelPrecisionBits; SubTexelPrecisionBits = subTexelPrecisionBits;
MinResourceAlignment = minResourceAlignment; MinResourceAlignment = minResourceAlignment;
MinTexelBufferAlignment = minTexelBufferAlignment;
} }
} }
} }
+31 -2
View File
@@ -54,6 +54,13 @@ namespace Ryujinx.Graphics.Vulkan
public PinnedSpan<byte> GetData() public PinnedSpan<byte> GetData()
{ {
int minTexelBufferOffsetAlignment = (int)_gd.Capabilities.MinTexelBufferAlignment;
if (_offset % minTexelBufferOffsetAlignment != 0)
{
_offset += (minTexelBufferOffsetAlignment - (_offset % minTexelBufferOffsetAlignment));
}
return _gd.GetBufferData(_bufferHandle, _offset, _size); return _gd.GetBufferData(_bufferHandle, _offset, _size);
} }
@@ -84,6 +91,13 @@ namespace Ryujinx.Graphics.Vulkan
/// <inheritdoc/> /// <inheritdoc/>
public void SetData(MemoryOwner<byte> data) public void SetData(MemoryOwner<byte> data)
{ {
int minTexelBufferOffsetAlignment = (int)_gd.Capabilities.MinTexelBufferAlignment;
if (_offset % minTexelBufferOffsetAlignment != 0)
{
_offset += (minTexelBufferOffsetAlignment - (_offset % minTexelBufferOffsetAlignment));
}
_gd.SetBufferData(_bufferHandle, _offset, data.Span); _gd.SetBufferData(_bufferHandle, _offset, data.Span);
data.Dispose(); data.Dispose();
} }
@@ -102,8 +116,16 @@ namespace Ryujinx.Graphics.Vulkan
public void SetStorage(BufferRange buffer) public void SetStorage(BufferRange buffer)
{ {
int minTexelBufferOffsetAlignment = (int)_gd.Capabilities.MinTexelBufferAlignment;
int bufferOffset = buffer.Offset;
if (bufferOffset % minTexelBufferOffsetAlignment != 0)
{
bufferOffset += (minTexelBufferOffsetAlignment - (bufferOffset % minTexelBufferOffsetAlignment));
}
if (_bufferHandle == buffer.Handle && if (_bufferHandle == buffer.Handle &&
_offset == buffer.Offset && _offset == bufferOffset &&
_size == buffer.Size && _size == buffer.Size &&
_bufferCount == _gd.BufferManager.BufferCount) _bufferCount == _gd.BufferManager.BufferCount)
{ {
@@ -111,7 +133,7 @@ namespace Ryujinx.Graphics.Vulkan
} }
_bufferHandle = buffer.Handle; _bufferHandle = buffer.Handle;
_offset = buffer.Offset; _offset = bufferOffset;
_size = buffer.Size; _size = buffer.Size;
_bufferCount = _gd.BufferManager.BufferCount; _bufferCount = _gd.BufferManager.BufferCount;
@@ -120,6 +142,13 @@ namespace Ryujinx.Graphics.Vulkan
public BufferView GetBufferView(CommandBufferScoped cbs, bool write) public BufferView GetBufferView(CommandBufferScoped cbs, bool write)
{ {
int minTexelBufferOffsetAlignment = (int)_gd.Capabilities.MinTexelBufferAlignment;
if (_offset % minTexelBufferOffsetAlignment != 0)
{
_offset += (minTexelBufferOffsetAlignment - (_offset % minTexelBufferOffsetAlignment));
}
_bufferView ??= _gd.BufferManager.CreateView(_bufferHandle, VkFormat, _offset, _size, ReleaseImpl); _bufferView ??= _gd.BufferManager.CreateView(_bufferHandle, VkFormat, _offset, _size, ReleaseImpl);
return _bufferView?.Get(cbs, _offset, _size, write).Value ?? default; return _bufferView?.Get(cbs, _offset, _size, write).Value ?? default;
@@ -455,7 +455,8 @@ namespace Ryujinx.Graphics.Vulkan
portabilityFlags, portabilityFlags,
vertexBufferAlignment, vertexBufferAlignment,
properties.Limits.SubTexelPrecisionBits, properties.Limits.SubTexelPrecisionBits,
minResourceAlignment); minResourceAlignment,
_physicalDevice.PhysicalDeviceProperties.Limits.MinTexelBufferOffsetAlignment);
IsSharedMemory = MemoryAllocator.IsDeviceMemoryShared(_physicalDevice); IsSharedMemory = MemoryAllocator.IsDeviceMemoryShared(_physicalDevice);