From 24df896eb8d1520706b086039743ef2dca7ce6df Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 25 Feb 2018 01:09:32 +1000 Subject: [PATCH] VKShader: Fix incorrect loading of binary shaders --- Source/Core/VideoBackends/Vulkan/VKShader.cpp | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/Source/Core/VideoBackends/Vulkan/VKShader.cpp b/Source/Core/VideoBackends/Vulkan/VKShader.cpp index 59128de6b2..ed723235db 100644 --- a/Source/Core/VideoBackends/Vulkan/VKShader.cpp +++ b/Source/Core/VideoBackends/Vulkan/VKShader.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include "Common/Align.h" #include "Common/Assert.h" #include "VideoBackends/Vulkan/ShaderCompiler.h" @@ -103,20 +104,11 @@ std::unique_ptr VKShader::CreateFromSource(ShaderStage stage, const ch std::unique_ptr VKShader::CreateFromBinary(ShaderStage stage, const void* data, size_t length) { - ShaderCompiler::SPIRVCodeVector spv; - const size_t size_in_words = sizeof(length) / sizeof(ShaderCompiler::SPIRVCodeType); - if (size_in_words > 0) - { - spv.resize(length / size_in_words); - std::memcpy(spv.data(), data, size_in_words); - } - - // Non-aligned code sizes, unlikely (unless using VK_NV_glsl). - if ((length % sizeof(ShaderCompiler::SPIRVCodeType)) != 0) - { - spv.resize(size_in_words + 1); - std::memcpy(&spv[size_in_words], data, (length % sizeof(ShaderCompiler::SPIRVCodeType))); - } + const size_t size_in_words = Common::AlignUp(length, sizeof(ShaderCompiler::SPIRVCodeType)) / + sizeof(ShaderCompiler::SPIRVCodeType); + ShaderCompiler::SPIRVCodeVector spv(size_in_words); + if (length > 0) + std::memcpy(spv.data(), data, length); return CreateShaderObject(stage, std::move(spv)); }