mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-25 07:05:40 +00:00
VulkanDevice: Handle rare case of unaligned SPIR-V
This commit is contained in:
parent
2c90680bc2
commit
1b4a6832dc
|
@ -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<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);
|
||||
|
|
Loading…
Reference in a new issue