summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReinUsesLisp <reinuseslisp@airmail.cc>2020-01-08 23:22:20 +0100
committerReinUsesLisp <reinuseslisp@airmail.cc>2020-01-08 23:22:20 +0100
commit82a64da0777cc48a992b10fee7db472e207f2423 (patch)
tree343bb5904ec0aaec953598ebe967b7322d8af520
parentMerge pull request #3279 from ReinUsesLisp/vk-pipeline-cache (diff)
downloadyuzu-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
-rw-r--r--src/video_core/CMakeLists.txt2
-rw-r--r--src/video_core/renderer_vulkan/vk_shader_util.cpp34
-rw-r--r--src/video_core/renderer_vulkan/vk_shader_util.h17
3 files changed, 53 insertions, 0 deletions
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt
index caf03c2ae..abe736c76 100644
--- a/src/video_core/CMakeLists.txt
+++ b/src/video_core/CMakeLists.txt
@@ -180,6 +180,8 @@ if (ENABLE_VULKAN)
renderer_vulkan/vk_scheduler.h
renderer_vulkan/vk_shader_decompiler.cpp
renderer_vulkan/vk_shader_decompiler.h
+ renderer_vulkan/vk_shader_util.cpp
+ renderer_vulkan/vk_shader_util.h
renderer_vulkan/vk_staging_buffer_pool.cpp
renderer_vulkan/vk_staging_buffer_pool.h
renderer_vulkan/vk_stream_buffer.cpp
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
diff --git a/src/video_core/renderer_vulkan/vk_shader_util.h b/src/video_core/renderer_vulkan/vk_shader_util.h
new file mode 100644
index 000000000..c06d65970
--- /dev/null
+++ b/src/video_core/renderer_vulkan/vk_shader_util.h
@@ -0,0 +1,17 @@
+// Copyright 2018 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <vector>
+#include "common/common_types.h"
+#include "video_core/renderer_vulkan/declarations.h"
+
+namespace Vulkan {
+
+class VKDevice;
+
+UniqueShaderModule BuildShader(const VKDevice& device, std::size_t code_size, const u8* code_data);
+
+} // namespace Vulkan