Blender V5.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
8
9#include "vk_shader_module.hh"
10#include "vk_backend.hh"
11#include "vk_shader.hh"
12
13#include <iomanip>
14#include <sstream>
15
16namespace blender::gpu {
18{
20 if (vk_shader_module != VK_NULL_HANDLE) {
22 vk_shader_module = VK_NULL_HANDLE;
23 }
24}
25
27{
28 BLI_assert(vk_shader_module == VK_NULL_HANDLE);
29 if (compilation_result.GetCompilationStatus() != shaderc_compilation_status_success &&
30 spirv_binary.is_empty())
31 {
32 return;
33 }
34
35 VkShaderModuleCreateInfo create_info = {};
36 create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
37 if (!spirv_binary.is_empty()) {
38 create_info.codeSize = spirv_binary.size() * sizeof(uint32_t);
39 create_info.pCode = spirv_binary.data();
40 }
41 else {
42 create_info.codeSize = (compilation_result.end() - compilation_result.begin()) *
43 sizeof(uint32_t);
44 create_info.pCode = compilation_result.begin();
45 }
46
47 const VKDevice &device = VKBackend::get().device;
48 device.functions.vkCreateShaderModule(
49 device.vk_handle(), &create_info, nullptr, &vk_shader_module);
51}
52
54{
57 std::string key = combined_sources;
58 key.append(extra.data(), extra.size());
59 uint64_t hash = hasher(key);
60 std::stringstream ss;
61 ss << std::setfill('0') << std::setw(sizeof(uint64_t) * 2) << std::hex << hash;
62 sources_hash = ss.str();
63 BLI_assert(!sources_hash.empty());
64}
65
66} // namespace blender::gpu
constexpr const char * c_str() const
constexpr int64_t size() const
constexpr const char * data() const
static VKBackend & get()
VkDevice vk_handle() const
Definition vk_device.hh:338
VolkDeviceTable functions
Definition vk_device.hh:280
static VKDiscardPool & discard_pool_get()
void discard_shader_module(VkShaderModule vk_shader_module)
shaderc::SpvCompilationResult compilation_result
void finalize(StringRefNull name)
void build_sources_hash(StringRef extra)
void object_label(GLenum type, GLuint object, const char *name)
Definition gl_debug.cc:331
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
unsigned int uint32_t
Definition BKE_text.h:81
#define hash
Definition noise_c.cc:156
int size() const
Definition vector.hh:130