From 1b4a6832dc5f7117f343b7cb69fe554bd4e58049 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 8 Sep 2024 21:55:51 +1000 Subject: [PATCH] VulkanDevice: Handle rare case of unaligned SPIR-V --- src/util/vulkan_pipeline.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/util/vulkan_pipeline.cpp b/src/util/vulkan_pipeline.cpp index 0029104e5..17bbf32ed 100644 --- a/src/util/vulkan_pipeline.cpp +++ b/src/util/vulkan_pipeline.cpp @@ -5,8 +5,10 @@ #include "vulkan_builders.h" #include "vulkan_device.h" +#include "common/align.h" #include "common/assert.h" #include "common/error.h" +#include "common/heap_array.h" #include "common/log.h" Log_SetChannel(VulkanDevice); @@ -30,6 +32,15 @@ std::unique_ptr VulkanDevice::CreateShaderFromBinary(GPUShaderStage s { VkShaderModule mod; + // In the very rare event that the pointer isn't word-aligned... + DynamicHeapArray data_copy; + if (Common::IsAlignedPow2(reinterpret_cast(data.data()), 4)) [[unlikely]] + { + data_copy.resize((data.size() + (sizeof(u32) - 1)) / sizeof(u32)); + std::memcpy(data_copy.data(), data.data(), data.size()); + data = std::span(reinterpret_cast(data_copy.data()), data.size()); + } + const VkShaderModuleCreateInfo ci = {VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, nullptr, 0, data.size(), reinterpret_cast(data.data())}; VkResult res = vkCreateShaderModule(m_device, &ci, nullptr, &mod);