From 21e53016d75a6726b598fafa7878137a713eb52a Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 4 Mar 2021 01:36:16 +1000 Subject: [PATCH] GPU/Vulkan: Fix possible misalignment in VRAM writes --- src/common/vulkan/context.h | 6 +++++- src/core/gpu_hw_vulkan.cpp | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/common/vulkan/context.h b/src/common/vulkan/context.h index e08363676..7e95c6d43 100644 --- a/src/common/vulkan/context.h +++ b/src/common/vulkan/context.h @@ -97,7 +97,11 @@ public: } 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 { diff --git a/src/core/gpu_hw_vulkan.cpp b/src/core/gpu_hw_vulkan.cpp index 6df0d7229..abefcc9f7 100644 --- a/src/core/gpu_hw_vulkan.cpp +++ b/src/core/gpu_hw_vulkan.cpp @@ -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 alignment = std::max(sizeof(u16), static_cast(g_vulkan_context->GetTexelBufferAlignment())); + const u32 alignment = std::max(sizeof(u32), static_cast(m_use_ssbos_for_vram_writes ? + g_vulkan_context->GetStorageBufferAlignment() : + g_vulkan_context->GetTexelBufferAlignment())); if (!m_texture_stream_buffer.ReserveMemory(data_size, alignment)) { Log_PerfPrintf("Executing command buffer while waiting for %u bytes in stream buffer", data_size);