MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Samples / ShaderModule

Method ShaderModule

framework/core/shader_module.cpp:27–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25namespace vkb
26{
27ShaderModule::ShaderModule(vkb::core::DeviceC &device,
28 VkShaderStageFlagBits stage,
29 const ShaderSource &shader_source,
30 const std::string &entry_point,
31 const ShaderVariant &shader_variant) :
32 device{device}, stage{stage}, entry_point{entry_point}
33{
34 debug_name = fmt::format("{} [variant {:X}] [entrypoint {}]", shader_source.get_filename(), shader_variant.get_id(), entry_point);
35
36 // Shaders in binary SPIR-V format can be loaded directly
37 spirv = vkb::fs::read_shader_binary_u32(shader_source.get_filename());
38
39 // Reflection is used to dynamically create descriptor bindings
40
41 SPIRVReflection spirv_reflection;
42 // Reflect all shader resources
43 if (!spirv_reflection.reflect_shader_resources(stage, spirv, resources, shader_variant))
44 {
45 throw VulkanException{VK_ERROR_INITIALIZATION_FAILED};
46 }
47
48 // Generate a unique id, determined by source and variant
49 std::hash<std::string> hasher{};
50 id = hasher(std::string{reinterpret_cast<const char *>(spirv.data()),
51 reinterpret_cast<const char *>(spirv.data() + spirv.size())});
52}
53
54ShaderModule::ShaderModule(ShaderModule &&other) :
55 device{other.device},

Callers

nothing calls this directly

Calls 4

read_shader_binary_u32Function · 0.85
sizeMethod · 0.80
get_idMethod · 0.45

Tested by

no test coverage detected