Blender V4.3
vk_shader_module.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "vk_shader_module.hh"
10#include "vk_backend.hh"
11#include "vk_memory.hh"
12#include "vk_shader.hh"
13
14#include <iomanip>
15#include <sstream>
16
17namespace blender::gpu {
19{
20 VKDevice &device = VKBackend::get().device;
21 VKDiscardPool &discard_pool = device.discard_pool_for_current_thread();
22 if (vk_shader_module != VK_NULL_HANDLE) {
24 vk_shader_module = VK_NULL_HANDLE;
25 }
26}
27
29{
30 BLI_assert(vk_shader_module == VK_NULL_HANDLE);
31 if (compilation_result.GetCompilationStatus() != shaderc_compilation_status_success &&
33 {
34 return;
35 }
36
38
39 VkShaderModuleCreateInfo create_info = {};
40 create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
41 if (!spirv_binary.is_empty()) {
42 create_info.codeSize = spirv_binary.size() * sizeof(uint32_t);
43 create_info.pCode = spirv_binary.data();
44 }
45 else {
46 create_info.codeSize = (compilation_result.end() - compilation_result.begin()) *
47 sizeof(uint32_t);
48 create_info.pCode = compilation_result.begin();
49 }
50
51 const VKDevice &device = VKBackend::get().device;
52 vkCreateShaderModule(
53 device.vk_handle(), &create_info, vk_allocation_callbacks, &vk_shader_module);
55}
56
58{
62 std::stringstream ss;
63 ss << std::setfill('0') << std::setw(sizeof(uint64_t) * 2) << std::hex << hash;
64 sources_hash = ss.str();
65 BLI_assert(!sources_hash.empty());
66}
67
68} // namespace blender::gpu
#define BLI_assert(a)
Definition BLI_assert.h:50
int64_t size() const
bool is_empty() const
static VKBackend & get()
Definition vk_backend.hh:92
VkDevice vk_handle() const
Definition vk_device.hh:224
VKDiscardPool & discard_pool_for_current_thread()
Definition vk_device.cc:399
void discard_shader_module(VkShaderModule vk_shader_module)
shaderc::SpvCompilationResult compilation_result
void finalize(StringRefNull name)
void object_label(GLenum type, GLuint object, const char *name)
Definition gl_debug.cc:344
#define hash
Definition noise.c:154
unsigned int uint32_t
Definition stdint.h:80
unsigned __int64 uint64_t
Definition stdint.h:90
#define VK_ALLOCATION_CALLBACKS
Definition vk_memory.hh:58