GPU/Vulkan: Fix possible misalignment in VRAM writes

This commit is contained in:
Connor McLaughlin 2021-03-04 01:36:16 +10:00
parent dbb6c708c2
commit 21e53016d7
2 changed files with 8 additions and 2 deletions

View file

@ -97,7 +97,11 @@ public:
} }
ALWAYS_INLINE VkDeviceSize GetTexelBufferAlignment() const ALWAYS_INLINE VkDeviceSize GetTexelBufferAlignment() const
{ {
return m_device_properties.limits.minUniformBufferOffsetAlignment; return m_device_properties.limits.minTexelBufferOffsetAlignment;
}
ALWAYS_INLINE VkDeviceSize GetStorageBufferAlignment() const
{
return m_device_properties.limits.minStorageBufferOffsetAlignment;
} }
ALWAYS_INLINE VkDeviceSize GetBufferImageGranularity() const ALWAYS_INLINE VkDeviceSize GetBufferImageGranularity() const
{ {

View file

@ -1515,7 +1515,9 @@ void GPU_HW_Vulkan::UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void*
} }
const u32 data_size = width * height * sizeof(u16); const u32 data_size = width * height * sizeof(u16);
const u32 alignment = std::max<u32>(sizeof(u16), static_cast<u32>(g_vulkan_context->GetTexelBufferAlignment())); const u32 alignment = std::max<u32>(sizeof(u32), static_cast<u32>(m_use_ssbos_for_vram_writes ?
g_vulkan_context->GetStorageBufferAlignment() :
g_vulkan_context->GetTexelBufferAlignment()));
if (!m_texture_stream_buffer.ReserveMemory(data_size, alignment)) if (!m_texture_stream_buffer.ReserveMemory(data_size, alignment))
{ {
Log_PerfPrintf("Executing command buffer while waiting for %u bytes in stream buffer", data_size); Log_PerfPrintf("Executing command buffer while waiting for %u bytes in stream buffer", data_size);