| 56 | } |
| 57 | |
| 58 | ComputePipeline::ComputePipeline(vkb::core::DeviceC &device, |
| 59 | VkPipelineCache pipeline_cache, |
| 60 | vkb::rendering::PipelineStateC &pipeline_state) : |
| 61 | Pipeline{device} |
| 62 | { |
| 63 | const ShaderModule *shader_module = pipeline_state.get_pipeline_layout().get_shader_modules().front(); |
| 64 | |
| 65 | if (shader_module->get_stage() != VK_SHADER_STAGE_COMPUTE_BIT) |
| 66 | { |
| 67 | throw VulkanException{VK_ERROR_INVALID_SHADER_NV, "Shader module stage is not compute"}; |
| 68 | } |
| 69 | |
| 70 | VkPipelineShaderStageCreateInfo stage{VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO}; |
| 71 | |
| 72 | stage.stage = shader_module->get_stage(); |
| 73 | stage.pName = shader_module->get_entry_point().c_str(); |
| 74 | |
| 75 | // Create the Vulkan handle |
| 76 | VkShaderModuleCreateInfo vk_create_info{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; |
| 77 | |
| 78 | vk_create_info.codeSize = shader_module->get_binary().size() * sizeof(uint32_t); |
| 79 | vk_create_info.pCode = shader_module->get_binary().data(); |
| 80 | |
| 81 | VkResult result = vkCreateShaderModule(device.get_handle(), &vk_create_info, nullptr, &stage.module); |
| 82 | if (result != VK_SUCCESS) |
| 83 | { |
| 84 | throw VulkanException{result}; |
| 85 | } |
| 86 | |
| 87 | device.get_debug_utils().set_debug_name(device.get_handle(), |
| 88 | VK_OBJECT_TYPE_SHADER_MODULE, reinterpret_cast<uint64_t>(stage.module), |
| 89 | shader_module->get_debug_name().c_str()); |
| 90 | |
| 91 | // Create specialization info from tracked state. |
| 92 | std::vector<uint8_t> data{}; |
| 93 | std::vector<VkSpecializationMapEntry> map_entries{}; |
| 94 | |
| 95 | const auto specialization_constant_state = pipeline_state.get_specialization_constant_state().get_specialization_constant_state(); |
| 96 | |
| 97 | for (const auto specialization_constant : specialization_constant_state) |
| 98 | { |
| 99 | map_entries.push_back({specialization_constant.first, to_u32(data.size()), specialization_constant.second.size()}); |
| 100 | data.insert(data.end(), specialization_constant.second.begin(), specialization_constant.second.end()); |
| 101 | } |
| 102 | |
| 103 | VkSpecializationInfo specialization_info{}; |
| 104 | specialization_info.mapEntryCount = to_u32(map_entries.size()); |
| 105 | specialization_info.pMapEntries = map_entries.data(); |
| 106 | specialization_info.dataSize = data.size(); |
| 107 | specialization_info.pData = data.data(); |
| 108 | |
| 109 | stage.pSpecializationInfo = &specialization_info; |
| 110 | |
| 111 | VkComputePipelineCreateInfo create_info{VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO}; |
| 112 | |
| 113 | create_info.layout = pipeline_state.get_pipeline_layout().get_handle(); |
| 114 | create_info.stage = stage; |
| 115 |
nothing calls this directly
no test coverage detected