summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends
diff options
context:
space:
mode:
authorStenzek <stenzek@gmail.com>2018-02-25 01:09:32 +1000
committerStenzek <stenzek@gmail.com>2018-03-10 15:56:27 +1000
commit24df896eb8d1520706b086039743ef2dca7ce6df (patch)
tree55228e995a70d37209c2b2f2ebdabe70ea7ccf89 /Source/Core/VideoBackends
parent1ddc4c55685d38741f95e286fad5b49537ef5399 (diff)
VKShader: Fix incorrect loading of binary shaders
Diffstat (limited to 'Source/Core/VideoBackends')
-rw-r--r--Source/Core/VideoBackends/Vulkan/VKShader.cpp20
1 files 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> VKShader::CreateFromSource(ShaderStage stage, const ch
std::unique_ptr<VKShader> 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));
}