diff options
author | ReinUsesLisp <reinuseslisp@airmail.cc> | 2020-01-08 23:22:20 +0100 |
---|---|---|
committer | ReinUsesLisp <reinuseslisp@airmail.cc> | 2020-01-08 23:22:20 +0100 |
commit | 82a64da0777cc48a992b10fee7db472e207f2423 (patch) | |
tree | 343bb5904ec0aaec953598ebe967b7322d8af520 /src/video_core/renderer_vulkan/vk_shader_util.cpp | |
parent | Merge pull request #3279 from ReinUsesLisp/vk-pipeline-cache (diff) | |
download | yuzu-82a64da0777cc48a992b10fee7db472e207f2423.tar yuzu-82a64da0777cc48a992b10fee7db472e207f2423.tar.gz yuzu-82a64da0777cc48a992b10fee7db472e207f2423.tar.bz2 yuzu-82a64da0777cc48a992b10fee7db472e207f2423.tar.lz yuzu-82a64da0777cc48a992b10fee7db472e207f2423.tar.xz yuzu-82a64da0777cc48a992b10fee7db472e207f2423.tar.zst yuzu-82a64da0777cc48a992b10fee7db472e207f2423.zip |
Diffstat (limited to 'src/video_core/renderer_vulkan/vk_shader_util.cpp')
-rw-r--r-- | src/video_core/renderer_vulkan/vk_shader_util.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/video_core/renderer_vulkan/vk_shader_util.cpp b/src/video_core/renderer_vulkan/vk_shader_util.cpp new file mode 100644 index 000000000..b97c4cb3d --- /dev/null +++ b/src/video_core/renderer_vulkan/vk_shader_util.cpp @@ -0,0 +1,34 @@ +// Copyright 2018 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include <cstring> +#include <memory> +#include <vector> +#include "common/alignment.h" +#include "common/assert.h" +#include "common/common_types.h" +#include "video_core/renderer_vulkan/declarations.h" +#include "video_core/renderer_vulkan/vk_device.h" +#include "video_core/renderer_vulkan/vk_shader_util.h" + +namespace Vulkan { + +UniqueShaderModule BuildShader(const VKDevice& device, std::size_t code_size, const u8* code_data) { + // Avoid undefined behavior by copying to a staging allocation + ASSERT(code_size % sizeof(u32) == 0); + const auto data = std::make_unique<u32[]>(code_size / sizeof(u32)); + std::memcpy(data.get(), code_data, code_size); + + const auto dev = device.GetLogical(); + const auto& dld = device.GetDispatchLoader(); + const vk::ShaderModuleCreateInfo shader_ci({}, code_size, data.get()); + vk::ShaderModule shader_module; + if (dev.createShaderModule(&shader_ci, nullptr, &shader_module, dld) != vk::Result::eSuccess) { + UNREACHABLE_MSG("Shader module failed to build!"); + } + + return UniqueShaderModule(shader_module, vk::ObjectDestroy(dev, nullptr, dld)); +} + +} // namespace Vulkan |