| 25 | namespace vkb |
| 26 | { |
| 27 | ShaderModule::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 | |
| 54 | ShaderModule::ShaderModule(ShaderModule &&other) : |
| 55 | device{other.device}, |
nothing calls this directly
no test coverage detected