mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-25 06:40:11 +00:00
VKShader: Fix incorrect loading of binary shaders
This commit is contained in:
parent
1ddc4c5568
commit
24df896eb8
@ -2,6 +2,7 @@
|
|||||||
// Licensed under GPLv2+
|
// Licensed under GPLv2+
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "Common/Align.h"
|
||||||
#include "Common/Assert.h"
|
#include "Common/Assert.h"
|
||||||
|
|
||||||
#include "VideoBackends/Vulkan/ShaderCompiler.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,
|
std::unique_ptr<VKShader> VKShader::CreateFromBinary(ShaderStage stage, const void* data,
|
||||||
size_t length)
|
size_t length)
|
||||||
{
|
{
|
||||||
ShaderCompiler::SPIRVCodeVector spv;
|
const size_t size_in_words = Common::AlignUp(length, sizeof(ShaderCompiler::SPIRVCodeType)) /
|
||||||
const size_t size_in_words = sizeof(length) / sizeof(ShaderCompiler::SPIRVCodeType);
|
sizeof(ShaderCompiler::SPIRVCodeType);
|
||||||
if (size_in_words > 0)
|
ShaderCompiler::SPIRVCodeVector spv(size_in_words);
|
||||||
{
|
if (length > 0)
|
||||||
spv.resize(length / size_in_words);
|
std::memcpy(spv.data(), data, length);
|
||||||
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)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return CreateShaderObject(stage, std::move(spv));
|
return CreateShaderObject(stage, std::move(spv));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user