mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-12-28 11:20:56 +01:00
vk_shader_util: Add helper to build SPIR-V shaders
This commit is contained in:
parent
80436c1330
commit
82a64da077
3 changed files with 53 additions and 0 deletions
|
@ -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
|
||||
|
|
34
src/video_core/renderer_vulkan/vk_shader_util.cpp
Normal file
34
src/video_core/renderer_vulkan/vk_shader_util.cpp
Normal file
|
@ -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
|
17
src/video_core/renderer_vulkan/vk_shader_util.h
Normal file
17
src/video_core/renderer_vulkan/vk_shader_util.h
Normal file
|
@ -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
|
Loading…
Reference in a new issue