summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZephyron <zephyron@citron-emu.org>2025-02-02 12:07:43 +1000
committerMike Lothian <mike@fireburn.co.uk>2025-05-11 14:54:45 +0100
commitfdeaf764fe20725dfc8df86dbb813a544f5c84ce (patch)
tree10b8bc1a152dfd4a345220a52e21e7516b085381
parent2bce10f740c69c7bf843144d3328dc9537d0c2bb (diff)
vulkan: Add 4KB memory alignment for AMD and Qualcomm drivers
Adds special handling for memory allocation size on AMD and Qualcomm (Adreno) drivers by aligning allocations to 4KB boundaries. This fixes potential memory allocation issues on these drivers where unaligned allocations may fail or cause undefined behavior. Affected drivers: - AMD Proprietary (AMDVLK) - AMD Open Source (RADV) - Qualcomm Proprietary (Adreno)
-rw-r--r--src/video_core/vulkan_common/vulkan_memory_allocator.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/video_core/vulkan_common/vulkan_memory_allocator.cpp b/src/video_core/vulkan_common/vulkan_memory_allocator.cpp
index 54331688e..371e13cfc 100644
--- a/src/video_core/vulkan_common/vulkan_memory_allocator.cpp
+++ b/src/video_core/vulkan_common/vulkan_memory_allocator.cpp
@@ -303,7 +303,12 @@ bool MemoryAllocator::TryAllocMemory(VkMemoryPropertyFlags flags, u32 type_mask,
vk::DeviceMemory memory = device.GetLogical().TryAllocateMemory({
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
.pNext = nullptr,
- .allocationSize = size,
+ /* AMD drivers (including Adreno) require 4KB alignment */
+ .allocationSize = (device.GetDriverID() == VK_DRIVER_ID_AMD_PROPRIETARY ||
+ device.GetDriverID() == VK_DRIVER_ID_AMD_OPEN_SOURCE ||
+ device.GetDriverID() == VK_DRIVER_ID_QUALCOMM_PROPRIETARY) ?
+ ((size + 4095) & ~4095) : /* AMD (AMDVLK, RADV, RadeonSI) & Adreno */
+ size, /* Others (NVIDIA, Intel, Mali, etc) */
.memoryTypeIndex = type,
});
if (!memory) {