Skip to content

Commit

Permalink
VulkanDevice: Handle rare case of unaligned SPIR-V
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Sep 8, 2024
1 parent 432fd80 commit 6a5f16d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/util/vulkan_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -30,6 +32,15 @@ std::unique_ptr<GPUShader> VulkanDevice::CreateShaderFromBinary(GPUShaderStage s
{
VkShaderModule mod;

// In the very rare event that the pointer isn't word-aligned...
DynamicHeapArray<u32> data_copy;
if (Common::IsAlignedPow2(reinterpret_cast<uintptr_t>(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<const u8>(reinterpret_cast<const u8*>(data_copy.data()), data.size());
}

const VkShaderModuleCreateInfo ci = {VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, nullptr, 0, data.size(),
reinterpret_cast<const u32*>(data.data())};
VkResult res = vkCreateShaderModule(m_device, &ci, nullptr, &mod);
Expand Down

0 comments on commit 6a5f16d

Please sign in to comment.