| 124 | } |
| 125 | |
| 126 | GraphicsPipeline::GraphicsPipeline(vkb::core::DeviceC &device, |
| 127 | VkPipelineCache pipeline_cache, |
| 128 | vkb::rendering::PipelineStateC &pipeline_state) : |
| 129 | Pipeline{device} |
| 130 | { |
| 131 | std::vector<VkShaderModule> shader_modules; |
| 132 | |
| 133 | std::vector<VkPipelineShaderStageCreateInfo> stage_create_infos; |
| 134 | |
| 135 | // Create specialization info from tracked state. This is shared by all shaders. |
| 136 | std::vector<uint8_t> data{}; |
| 137 | std::vector<VkSpecializationMapEntry> map_entries{}; |
| 138 | |
| 139 | const auto specialization_constant_state = pipeline_state.get_specialization_constant_state().get_specialization_constant_state(); |
| 140 | |
| 141 | for (const auto specialization_constant : specialization_constant_state) |
| 142 | { |
| 143 | map_entries.push_back({specialization_constant.first, to_u32(data.size()), specialization_constant.second.size()}); |
| 144 | data.insert(data.end(), specialization_constant.second.begin(), specialization_constant.second.end()); |
| 145 | } |
| 146 | |
| 147 | VkSpecializationInfo specialization_info{}; |
| 148 | specialization_info.mapEntryCount = to_u32(map_entries.size()); |
| 149 | specialization_info.pMapEntries = map_entries.data(); |
| 150 | specialization_info.dataSize = data.size(); |
| 151 | specialization_info.pData = data.data(); |
| 152 | |
| 153 | for (const ShaderModule *shader_module : pipeline_state.get_pipeline_layout().get_shader_modules()) |
| 154 | { |
| 155 | VkPipelineShaderStageCreateInfo stage_create_info{VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO}; |
| 156 | |
| 157 | stage_create_info.stage = shader_module->get_stage(); |
| 158 | stage_create_info.pName = shader_module->get_entry_point().c_str(); |
| 159 | |
| 160 | // Create the Vulkan handle |
| 161 | VkShaderModuleCreateInfo vk_create_info{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; |
| 162 | |
| 163 | vk_create_info.codeSize = shader_module->get_binary().size() * sizeof(uint32_t); |
| 164 | vk_create_info.pCode = shader_module->get_binary().data(); |
| 165 | |
| 166 | VkResult result = vkCreateShaderModule(device.get_handle(), &vk_create_info, nullptr, &stage_create_info.module); |
| 167 | if (result != VK_SUCCESS) |
| 168 | { |
| 169 | throw VulkanException{result}; |
| 170 | } |
| 171 | |
| 172 | device.get_debug_utils().set_debug_name(device.get_handle(), |
| 173 | VK_OBJECT_TYPE_SHADER_MODULE, reinterpret_cast<uint64_t>(stage_create_info.module), |
| 174 | shader_module->get_debug_name().c_str()); |
| 175 | |
| 176 | stage_create_info.pSpecializationInfo = &specialization_info; |
| 177 | |
| 178 | stage_create_infos.push_back(stage_create_info); |
| 179 | shader_modules.push_back(stage_create_info.module); |
| 180 | } |
| 181 | |
| 182 | VkGraphicsPipelineCreateInfo create_info{VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO}; |
| 183 |
nothing calls this directly
no test coverage detected