Lionel Landwerlin | 2d9f563 | 2022-01-08 01:12:47 +0200 | [diff] [blame] | 1 | /* Copyright (c) 2015-2022 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2022 Valve Corporation |
| 3 | * Copyright (c) 2015-2022 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2022 Google Inc. |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 5 | * Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved. |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | * |
| 19 | * Author: Courtney Goeltzenleuchter <courtneygo@google.com> |
| 20 | * Author: Tobin Ehlis <tobine@google.com> |
| 21 | * Author: Chris Forbes <chrisf@ijw.co.nz> |
| 22 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 23 | * Author: Dave Houlton <daveh@lunarg.com> |
| 24 | * Author: John Zulauf <jzulauf@lunarg.com> |
| 25 | * Author: Tobias Hector <tobias.hector@amd.com> |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 26 | * Author: Jeremy Gebben <jeremyg@lunarg.com> |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 27 | */ |
| 28 | #include "pipeline_state.h" |
| 29 | #include "descriptor_sets.h" |
| 30 | #include "cmd_buffer_state.h" |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 31 | #include "state_tracker.h" |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 32 | #include "shader_module.h" |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 33 | |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 34 | static bool HasWriteableDescriptor(const std::vector<PipelineStageState::DescriptorUse> &descriptor_uses) { |
| 35 | return std::any_of(descriptor_uses.begin(), descriptor_uses.end(), |
ziga-lunarg | 1a53505 | 2022-03-10 01:04:28 +0100 | [diff] [blame] | 36 | [](const PipelineStageState::DescriptorUse &use) { return use.second.is_writable; }); |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | static bool HasAtomicDescriptor(const std::vector<PipelineStageState::DescriptorUse> &descriptor_uses) { |
| 40 | return std::any_of(descriptor_uses.begin(), descriptor_uses.end(), |
ziga-lunarg | 1a53505 | 2022-03-10 01:04:28 +0100 | [diff] [blame] | 41 | [](const PipelineStageState::DescriptorUse &use) { return use.second.is_atomic_operation; }); |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 42 | } |
| 43 | |
Jeremy Gebben | 3dfeacf | 2021-12-02 08:46:39 -0700 | [diff] [blame] | 44 | static bool WrotePrimitiveShadingRate(VkShaderStageFlagBits stage_flag, spirv_inst_iter entrypoint, |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 45 | const SHADER_MODULE_STATE *module_state) { |
Jeremy Gebben | 3dfeacf | 2021-12-02 08:46:39 -0700 | [diff] [blame] | 46 | bool primitiverate_written = false; |
| 47 | if (stage_flag == VK_SHADER_STAGE_VERTEX_BIT || stage_flag == VK_SHADER_STAGE_GEOMETRY_BIT || |
| 48 | stage_flag == VK_SHADER_STAGE_MESH_BIT_NV) { |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 49 | for (const auto &set : module_state->GetBuiltinDecorationList()) { |
| 50 | auto insn = module_state->at(set.offset); |
Jeremy Gebben | 3dfeacf | 2021-12-02 08:46:39 -0700 | [diff] [blame] | 51 | if (set.builtin == spv::BuiltInPrimitiveShadingRateKHR) { |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 52 | primitiverate_written = module_state->IsBuiltInWritten(insn, entrypoint); |
Jeremy Gebben | 3dfeacf | 2021-12-02 08:46:39 -0700 | [diff] [blame] | 53 | } |
| 54 | if (primitiverate_written) { |
| 55 | break; |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | return primitiverate_written; |
| 60 | } |
| 61 | |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 62 | PipelineStageState::PipelineStageState(const safe_VkPipelineShaderStageCreateInfo *stage, |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 63 | std::shared_ptr<const SHADER_MODULE_STATE> &module_state) |
| 64 | : module_state(module_state), |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 65 | create_info(stage), |
| 66 | stage_flag(stage->stage), |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 67 | entrypoint(module_state->FindEntrypoint(stage->pName, stage->stage)), |
| 68 | accessible_ids(module_state->MarkAccessibleIds(entrypoint)), |
| 69 | descriptor_uses(module_state->CollectInterfaceByDescriptorSlot(accessible_ids)), |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 70 | has_writable_descriptor(HasWriteableDescriptor(descriptor_uses)), |
Jeremy Gebben | 3dfeacf | 2021-12-02 08:46:39 -0700 | [diff] [blame] | 71 | has_atomic_descriptor(HasAtomicDescriptor(descriptor_uses)), |
ziga-lunarg | dab1c1e | 2022-04-21 23:53:49 +0200 | [diff] [blame] | 72 | wrote_primitive_shading_rate(WrotePrimitiveShadingRate(stage_flag, entrypoint, module_state.get())), |
ziga-lunarg | 143bdbf | 2022-05-04 19:04:58 +0200 | [diff] [blame] | 73 | writes_to_gl_layer(module_state->WritesToGlLayer()), |
| 74 | has_input_attachment_capability(module_state->HasInputAttachmentCapability()) {} |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 75 | |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 76 | // static |
| 77 | PIPELINE_STATE::StageStateVec PIPELINE_STATE::GetStageStates(const ValidationStateTracker &state_data, |
| 78 | const PIPELINE_STATE &pipe_state) { |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 79 | PIPELINE_STATE::StageStateVec stage_states; |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 80 | // shader stages need to be recorded in pipeline order |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 81 | const auto stages = pipe_state.GetShaderStages(); |
| 82 | |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 83 | for (uint32_t stage_idx = 0; stage_idx < 32; ++stage_idx) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 84 | bool stage_found = false; |
| 85 | const auto stage = static_cast<VkShaderStageFlagBits>(1 << stage_idx); |
| 86 | for (const auto &shader_stage : stages) { |
| 87 | if (shader_stage.stage == stage) { |
| 88 | auto module = state_data.Get<SHADER_MODULE_STATE>(shader_stage.module); |
| 89 | if (!module) { |
| 90 | // If module is null and there is a VkShaderModuleCreateInfo in the pNext chain of the stage info, then this |
| 91 | // module is part of a library and the state must be created |
| 92 | const auto shader_ci = LvlFindInChain<VkShaderModuleCreateInfo>(shader_stage.pNext); |
Tony-LunarG | cab5d81 | 2022-08-04 14:07:32 -0600 | [diff] [blame] | 93 | const uint32_t unique_shader_id = 0; |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 94 | if (shader_ci) { |
Tony-LunarG | cab5d81 | 2022-08-04 14:07:32 -0600 | [diff] [blame] | 95 | // TODO GPU-AV rework required to get this value properly |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 96 | module = state_data.CreateShaderModuleState(*shader_ci, unique_shader_id); |
| 97 | } else { |
Tony-LunarG | cab5d81 | 2022-08-04 14:07:32 -0600 | [diff] [blame] | 98 | // shader_module_identifier could legally provide a null module handle |
| 99 | VkShaderModuleCreateInfo dummy_module_ci = LvlInitStruct<VkShaderModuleCreateInfo>(); |
| 100 | dummy_module_ci.pCode = &unique_shader_id; // Ensure tripping invalid spirv |
| 101 | module = state_data.CreateShaderModuleState(dummy_module_ci, unique_shader_id); |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | stage_states.emplace_back(&shader_stage, module); |
| 105 | stage_found = true; |
| 106 | } |
| 107 | } |
| 108 | if (!stage_found) { |
| 109 | // Check if stage has been supplied by a library |
| 110 | switch (stage) { |
| 111 | case VK_SHADER_STAGE_VERTEX_BIT: |
| 112 | if (pipe_state.pre_raster_state && pipe_state.pre_raster_state->vertex_shader) { |
| 113 | stage_states.emplace_back(pipe_state.pre_raster_state->vertex_shader_ci, |
| 114 | pipe_state.pre_raster_state->vertex_shader); |
| 115 | } |
| 116 | break; |
| 117 | case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT: |
| 118 | if (pipe_state.pre_raster_state && pipe_state.pre_raster_state->tessc_shader) { |
| 119 | stage_states.emplace_back(pipe_state.pre_raster_state->tessc_shader_ci, |
| 120 | pipe_state.pre_raster_state->tessc_shader); |
| 121 | } |
| 122 | break; |
| 123 | case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT: |
| 124 | if (pipe_state.pre_raster_state && pipe_state.pre_raster_state->tesse_shader) { |
| 125 | stage_states.emplace_back(pipe_state.pre_raster_state->tesse_shader_ci, |
| 126 | pipe_state.pre_raster_state->tesse_shader); |
| 127 | } |
| 128 | break; |
| 129 | case VK_SHADER_STAGE_GEOMETRY_BIT: |
| 130 | if (pipe_state.pre_raster_state && pipe_state.pre_raster_state->geometry_shader) { |
| 131 | stage_states.emplace_back(pipe_state.pre_raster_state->geometry_shader_ci, |
| 132 | pipe_state.pre_raster_state->geometry_shader); |
| 133 | } |
| 134 | break; |
| 135 | case VK_SHADER_STAGE_FRAGMENT_BIT: |
| 136 | if (pipe_state.fragment_shader_state && pipe_state.fragment_shader_state->fragment_shader) { |
| 137 | stage_states.emplace_back(pipe_state.fragment_shader_state->fragment_shader_ci.get(), |
| 138 | pipe_state.fragment_shader_state->fragment_shader); |
| 139 | } |
| 140 | break; |
| 141 | default: |
| 142 | // no-op |
| 143 | break; |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | } |
| 147 | return stage_states; |
| 148 | } |
| 149 | |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 150 | // static |
| 151 | PIPELINE_STATE::ActiveSlotMap PIPELINE_STATE::GetActiveSlots(const StageStateVec &stage_states) { |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 152 | PIPELINE_STATE::ActiveSlotMap active_slots; |
| 153 | for (const auto &stage : stage_states) { |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 154 | if (stage.entrypoint == stage.module_state->end()) { |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 155 | continue; |
| 156 | } |
| 157 | // Capture descriptor uses for the pipeline |
| 158 | for (const auto &use : stage.descriptor_uses) { |
| 159 | // While validating shaders capture which slots are used by the pipeline |
| 160 | auto &entry = active_slots[use.first.set][use.first.binding]; |
| 161 | entry.is_writable |= use.second.is_writable; |
| 162 | |
| 163 | auto &reqs = entry.reqs; |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 164 | reqs |= stage.module_state->DescriptorTypeToReqs(use.second.type_id); |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 165 | if (use.second.is_atomic_operation) reqs |= DESCRIPTOR_REQ_VIEW_ATOMIC_OPERATION; |
| 166 | if (use.second.is_sampler_implicitLod_dref_proj) reqs |= DESCRIPTOR_REQ_SAMPLER_IMPLICITLOD_DREF_PROJ; |
| 167 | if (use.second.is_sampler_bias_offset) reqs |= DESCRIPTOR_REQ_SAMPLER_BIAS_OFFSET; |
Lionel Landwerlin | bc7401b | 2021-12-07 15:43:05 +0200 | [diff] [blame] | 168 | if (use.second.is_read_without_format) reqs |= DESCRIPTOR_REQ_IMAGE_READ_WITHOUT_FORMAT; |
| 169 | if (use.second.is_write_without_format) reqs |= DESCRIPTOR_REQ_IMAGE_WRITE_WITHOUT_FORMAT; |
Lionel Landwerlin | cdbe868 | 2021-12-08 15:10:37 +0200 | [diff] [blame] | 170 | if (use.second.is_dref_operation) reqs |= DESCRIPTOR_REQ_IMAGE_DREF; |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 171 | |
| 172 | if (use.second.samplers_used_by_image.size()) { |
| 173 | if (use.second.samplers_used_by_image.size() > entry.samplers_used_by_image.size()) { |
| 174 | entry.samplers_used_by_image.resize(use.second.samplers_used_by_image.size()); |
| 175 | } |
| 176 | uint32_t image_index = 0; |
| 177 | for (const auto &samplers : use.second.samplers_used_by_image) { |
| 178 | for (const auto &sampler : samplers) { |
Jeremy Gebben | 856b8c6 | 2021-12-01 15:20:07 -0700 | [diff] [blame] | 179 | entry.samplers_used_by_image[image_index].emplace(sampler); |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 180 | } |
| 181 | ++image_index; |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | return active_slots; |
| 187 | } |
| 188 | |
| 189 | static uint32_t GetMaxActiveSlot(const PIPELINE_STATE::ActiveSlotMap &active_slots) { |
| 190 | uint32_t max_active_slot = 0; |
| 191 | for (const auto &entry : active_slots) { |
| 192 | max_active_slot = std::max(max_active_slot, entry.first); |
| 193 | } |
| 194 | return max_active_slot; |
| 195 | } |
| 196 | |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 197 | static uint32_t GetActiveShaders(const PIPELINE_STATE::StageStateVec &stages) { |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 198 | uint32_t result = 0; |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 199 | for (const auto &stage : stages) { |
| 200 | result |= stage.stage_flag; |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 201 | } |
| 202 | return result; |
| 203 | } |
| 204 | |
| 205 | static layer_data::unordered_set<uint32_t> GetFSOutputLocations(const PIPELINE_STATE::StageStateVec &stage_states) { |
| 206 | layer_data::unordered_set<uint32_t> result; |
| 207 | for (const auto &stage : stage_states) { |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 208 | if (stage.entrypoint == stage.module_state->end()) { |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 209 | continue; |
| 210 | } |
| 211 | if (stage.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT) { |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 212 | result = stage.module_state->CollectWritableOutputLocationinFS(stage.entrypoint); |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 213 | break; |
| 214 | } |
| 215 | } |
| 216 | return result; |
| 217 | } |
| 218 | |
| 219 | static VkPrimitiveTopology GetTopologyAtRasterizer(const PIPELINE_STATE::StageStateVec &stage_states, |
| 220 | const safe_VkPipelineInputAssemblyStateCreateInfo *assembly_state) { |
| 221 | VkPrimitiveTopology result = assembly_state ? assembly_state->topology : static_cast<VkPrimitiveTopology>(0); |
| 222 | for (const auto &stage : stage_states) { |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 223 | if (stage.entrypoint == stage.module_state->end()) { |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 224 | continue; |
| 225 | } |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 226 | auto stage_topo = stage.module_state->GetTopology(stage.entrypoint); |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 227 | if (stage_topo) { |
| 228 | result = *stage_topo; |
| 229 | } |
| 230 | } |
| 231 | return result; |
| 232 | } |
| 233 | |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 234 | // static |
Nathaniel Cesario | ef6e205 | 2022-02-28 14:09:45 -0700 | [diff] [blame] | 235 | std::shared_ptr<VertexInputState> PIPELINE_STATE::CreateVertexInputState(const PIPELINE_STATE &p, |
| 236 | const ValidationStateTracker &state, |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 237 | const safe_VkGraphicsPipelineCreateInfo &create_info) { |
| 238 | const auto lib_type = GetGraphicsLibType(create_info); |
| 239 | if (lib_type & VK_GRAPHICS_PIPELINE_LIBRARY_VERTEX_INPUT_INTERFACE_BIT_EXT) { // Vertex input graphics library |
Nathaniel Cesario | ef6e205 | 2022-02-28 14:09:45 -0700 | [diff] [blame] | 240 | return std::make_shared<VertexInputState>(p, create_info); |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | const auto link_info = LvlFindInChain<VkPipelineLibraryCreateInfoKHR>(create_info.pNext); |
| 244 | if (link_info) { |
Nathaniel Cesario | 0f5906a | 2022-04-05 11:10:18 -0600 | [diff] [blame] | 245 | auto ss = GetLibSubState<VK_GRAPHICS_PIPELINE_LIBRARY_VERTEX_INPUT_INTERFACE_BIT_EXT>(state, *link_info); |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 246 | if (ss) { |
| 247 | return ss; |
| 248 | } |
Nathaniel Cesario | fe8d786 | 2022-02-16 17:27:29 -0700 | [diff] [blame] | 249 | } else { |
| 250 | if (lib_type == static_cast<VkGraphicsPipelineLibraryFlagsEXT>(0)) { // Not a graphics library |
Nathaniel Cesario | ef6e205 | 2022-02-28 14:09:45 -0700 | [diff] [blame] | 251 | return std::make_shared<VertexInputState>(p, create_info); |
Nathaniel Cesario | fe8d786 | 2022-02-16 17:27:29 -0700 | [diff] [blame] | 252 | } |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | // We shouldn't get here... |
| 256 | return {}; |
| 257 | } |
| 258 | |
| 259 | // static |
Nathaniel Cesario | ef6e205 | 2022-02-28 14:09:45 -0700 | [diff] [blame] | 260 | std::shared_ptr<PreRasterState> PIPELINE_STATE::CreatePreRasterState(const PIPELINE_STATE &p, const ValidationStateTracker &state, |
Nathaniel Cesario | 711be93 | 2022-03-15 13:08:00 -0600 | [diff] [blame] | 261 | const safe_VkGraphicsPipelineCreateInfo &create_info, |
| 262 | std::shared_ptr<const RENDER_PASS_STATE> rp) { |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 263 | const auto lib_type = GetGraphicsLibType(create_info); |
| 264 | if (lib_type & VK_GRAPHICS_PIPELINE_LIBRARY_PRE_RASTERIZATION_SHADERS_BIT_EXT) { // Pre-raster graphics library |
Nathaniel Cesario | 711be93 | 2022-03-15 13:08:00 -0600 | [diff] [blame] | 265 | return std::make_shared<PreRasterState>(p, state, create_info, rp); |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | const auto link_info = LvlFindInChain<VkPipelineLibraryCreateInfoKHR>(create_info.pNext); |
| 269 | if (link_info) { |
Nathaniel Cesario | 0f5906a | 2022-04-05 11:10:18 -0600 | [diff] [blame] | 270 | auto ss = GetLibSubState<VK_GRAPHICS_PIPELINE_LIBRARY_PRE_RASTERIZATION_SHADERS_BIT_EXT>(state, *link_info); |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 271 | if (ss) { |
| 272 | return ss; |
| 273 | } |
Nathaniel Cesario | fe8d786 | 2022-02-16 17:27:29 -0700 | [diff] [blame] | 274 | } else { |
| 275 | if (lib_type == static_cast<VkGraphicsPipelineLibraryFlagsEXT>(0)) { // Not a graphics library |
Nathaniel Cesario | 711be93 | 2022-03-15 13:08:00 -0600 | [diff] [blame] | 276 | return std::make_shared<PreRasterState>(p, state, create_info, rp); |
Nathaniel Cesario | fe8d786 | 2022-02-16 17:27:29 -0700 | [diff] [blame] | 277 | } |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | // We shouldn't get here... |
| 281 | return {}; |
| 282 | } |
| 283 | |
| 284 | // static |
| 285 | std::shared_ptr<FragmentShaderState> PIPELINE_STATE::CreateFragmentShaderState( |
Nathaniel Cesario | ef6e205 | 2022-02-28 14:09:45 -0700 | [diff] [blame] | 286 | const PIPELINE_STATE &p, const ValidationStateTracker &state, const VkGraphicsPipelineCreateInfo &create_info, |
Nathaniel Cesario | 711be93 | 2022-03-15 13:08:00 -0600 | [diff] [blame] | 287 | const safe_VkGraphicsPipelineCreateInfo &safe_create_info, std::shared_ptr<const RENDER_PASS_STATE> rp) { |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 288 | const auto lib_type = GetGraphicsLibType(create_info); |
| 289 | if (lib_type & VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT) { // Fragment shader graphics library |
Nathaniel Cesario | 711be93 | 2022-03-15 13:08:00 -0600 | [diff] [blame] | 290 | return std::make_shared<FragmentShaderState>(p, state, create_info, rp); |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | const auto link_info = LvlFindInChain<VkPipelineLibraryCreateInfoKHR>(create_info.pNext); |
| 294 | if (link_info) { |
Nathaniel Cesario | 0f5906a | 2022-04-05 11:10:18 -0600 | [diff] [blame] | 295 | auto ss = GetLibSubState<VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT>(state, *link_info); |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 296 | if (ss) { |
| 297 | return ss; |
| 298 | } |
Nathaniel Cesario | fe8d786 | 2022-02-16 17:27:29 -0700 | [diff] [blame] | 299 | } else { |
| 300 | if (lib_type == static_cast<VkGraphicsPipelineLibraryFlagsEXT>(0)) { // Not a graphics library |
Nathaniel Cesario | 711be93 | 2022-03-15 13:08:00 -0600 | [diff] [blame] | 301 | return std::make_shared<FragmentShaderState>(p, state, safe_create_info, rp); |
Nathaniel Cesario | fe8d786 | 2022-02-16 17:27:29 -0700 | [diff] [blame] | 302 | } |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | // We shouldn't get here... |
| 306 | return {}; |
| 307 | } |
| 308 | |
| 309 | // static |
| 310 | // Pointers that should be ignored have been set to null in safe_create_info, but if this is a graphics library we need the "raw" |
| 311 | // create_info. |
| 312 | std::shared_ptr<FragmentOutputState> PIPELINE_STATE::CreateFragmentOutputState( |
Nathaniel Cesario | ef6e205 | 2022-02-28 14:09:45 -0700 | [diff] [blame] | 313 | const PIPELINE_STATE &p, const ValidationStateTracker &state, const VkGraphicsPipelineCreateInfo &create_info, |
Nathaniel Cesario | 711be93 | 2022-03-15 13:08:00 -0600 | [diff] [blame] | 314 | const safe_VkGraphicsPipelineCreateInfo &safe_create_info, std::shared_ptr<const RENDER_PASS_STATE> rp) { |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 315 | const auto lib_type = GetGraphicsLibType(create_info); |
| 316 | if (lib_type & VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_OUTPUT_INTERFACE_BIT_EXT) { // Fragment output graphics library |
Nathaniel Cesario | 711be93 | 2022-03-15 13:08:00 -0600 | [diff] [blame] | 317 | return std::make_shared<FragmentOutputState>(p, create_info, rp); |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | const auto link_info = LvlFindInChain<VkPipelineLibraryCreateInfoKHR>(create_info.pNext); |
| 321 | if (link_info) { |
Nathaniel Cesario | 0f5906a | 2022-04-05 11:10:18 -0600 | [diff] [blame] | 322 | auto ss = GetLibSubState<VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_OUTPUT_INTERFACE_BIT_EXT>(state, *link_info); |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 323 | if (ss) { |
| 324 | return ss; |
| 325 | } |
Nathaniel Cesario | fe8d786 | 2022-02-16 17:27:29 -0700 | [diff] [blame] | 326 | } else { |
| 327 | if (lib_type == static_cast<VkGraphicsPipelineLibraryFlagsEXT>(0)) { // Not a graphics library |
Nathaniel Cesario | 711be93 | 2022-03-15 13:08:00 -0600 | [diff] [blame] | 328 | return std::make_shared<FragmentOutputState>(p, safe_create_info, rp); |
Nathaniel Cesario | fe8d786 | 2022-02-16 17:27:29 -0700 | [diff] [blame] | 329 | } |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | // We shouldn't get here... |
| 333 | return {}; |
| 334 | } |
| 335 | |
Nathaniel Cesario | 41f7c80 | 2022-03-01 14:28:58 -0700 | [diff] [blame] | 336 | template <typename Substate> |
| 337 | void AppendDynamicStateFromSubstate(const Substate &substate, std::vector<VkDynamicState> &dyn_states, |
| 338 | VkPipelineDynamicStateCreateFlags &flags) { |
| 339 | if (substate) { |
| 340 | const auto *dyn_state = substate->parent.DynamicState(); |
| 341 | if (dyn_state) { |
| 342 | flags |= dyn_state->flags; |
| 343 | for (uint32_t i = 0; i < dyn_state->dynamicStateCount; ++i) { |
| 344 | const auto itr = std::find(dyn_states.cbegin(), dyn_states.cend(), dyn_state->pDynamicStates[i]); |
| 345 | if (itr == dyn_states.cend()) { |
| 346 | dyn_states.emplace_back(dyn_state->pDynamicStates[i]); |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | |
Nathaniel Cesario | cb17f98 | 2022-06-02 15:33:49 -0600 | [diff] [blame] | 353 | std::vector<std::shared_ptr<const PIPELINE_LAYOUT_STATE>> PIPELINE_STATE::PipelineLayoutStateUnion() const { |
| 354 | std::vector<std::shared_ptr<const PIPELINE_LAYOUT_STATE>> ret; |
| 355 | ret.reserve(2); |
| 356 | // Only need to check pre-raster _or_ fragment shader layout; if either one is not merged_graphics_layout, then |
| 357 | // merged_graphics_layout is a union |
| 358 | if (pre_raster_state) { |
| 359 | if (pre_raster_state->pipeline_layout != fragment_shader_state->pipeline_layout) { |
| 360 | return {pre_raster_state->pipeline_layout, fragment_shader_state->pipeline_layout}; |
| 361 | } else { |
| 362 | return {pre_raster_state->pipeline_layout}; |
| 363 | } |
| 364 | } |
| 365 | return {merged_graphics_layout}; |
| 366 | } |
| 367 | |
Nathaniel Cesario | d4d8fce | 2022-05-06 15:01:10 -0600 | [diff] [blame] | 368 | template <> |
| 369 | VkPipeline PIPELINE_STATE::BasePipeline<VkGraphicsPipelineCreateInfo>() const { |
| 370 | assert(create_info.graphics.sType == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO); |
| 371 | return create_info.graphics.basePipelineHandle; |
| 372 | } |
| 373 | template <> |
| 374 | VkPipeline PIPELINE_STATE::BasePipeline<VkComputePipelineCreateInfo>() const { |
| 375 | assert(create_info.compute.sType == VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO); |
| 376 | return create_info.compute.basePipelineHandle; |
| 377 | } |
| 378 | template <> |
| 379 | VkPipeline PIPELINE_STATE::BasePipeline<VkRayTracingPipelineCreateInfoKHR>() const { |
| 380 | assert(create_info.raytracing.sType == VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR); |
| 381 | return create_info.raytracing.basePipelineHandle; |
| 382 | } |
| 383 | template <> |
| 384 | VkPipeline PIPELINE_STATE::BasePipeline<VkRayTracingPipelineCreateInfoNV>() const { |
| 385 | assert(create_info.raytracing.sType == VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_NV); |
| 386 | return create_info.raytracing.basePipelineHandle; |
| 387 | } |
| 388 | |
| 389 | template <> |
| 390 | int32_t PIPELINE_STATE::BasePipelineIndex<VkGraphicsPipelineCreateInfo>() const { |
| 391 | assert(create_info.graphics.sType == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO); |
| 392 | return create_info.graphics.basePipelineIndex; |
| 393 | } |
| 394 | template <> |
| 395 | int32_t PIPELINE_STATE::BasePipelineIndex<VkComputePipelineCreateInfo>() const { |
| 396 | assert(create_info.compute.sType == VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO); |
| 397 | return create_info.compute.basePipelineIndex; |
| 398 | } |
| 399 | template <> |
| 400 | int32_t PIPELINE_STATE::BasePipelineIndex<VkRayTracingPipelineCreateInfoKHR>() const { |
| 401 | assert(create_info.raytracing.sType == VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR); |
| 402 | return create_info.raytracing.basePipelineIndex; |
| 403 | } |
| 404 | template <> |
| 405 | int32_t PIPELINE_STATE::BasePipelineIndex<VkRayTracingPipelineCreateInfoNV>() const { |
| 406 | assert(create_info.raytracing.sType == VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_NV); |
| 407 | return create_info.raytracing.basePipelineIndex; |
| 408 | } |
| 409 | |
| 410 | template <> |
| 411 | VkShaderModule PIPELINE_STATE::PIPELINE_STATE::GetShaderModuleByCIIndex<VkGraphicsPipelineCreateInfo>(uint32_t i) { |
| 412 | assert(create_info.graphics.sType == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO); |
| 413 | return create_info.graphics.pStages[i].module; |
| 414 | } |
| 415 | template <> |
| 416 | VkShaderModule PIPELINE_STATE::GetShaderModuleByCIIndex<VkComputePipelineCreateInfo>(uint32_t) { |
| 417 | assert(create_info.compute.sType == VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO); |
| 418 | return create_info.compute.stage.module; |
| 419 | } |
| 420 | template <> |
| 421 | VkShaderModule PIPELINE_STATE::GetShaderModuleByCIIndex<VkRayTracingPipelineCreateInfoKHR>(uint32_t i) { |
| 422 | assert(create_info.raytracing.sType == VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR); |
| 423 | return create_info.raytracing.pStages[i].module; |
| 424 | } |
| 425 | template <> |
| 426 | VkShaderModule PIPELINE_STATE::GetShaderModuleByCIIndex<VkRayTracingPipelineCreateInfoNV>(uint32_t i) { |
| 427 | assert(create_info.raytracing.sType == VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_NV); |
| 428 | return create_info.raytracing.pStages[i].module; |
| 429 | } |
| 430 | |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 431 | PIPELINE_STATE::PIPELINE_STATE(const ValidationStateTracker *state_data, const VkGraphicsPipelineCreateInfo *pCreateInfo, |
| 432 | std::shared_ptr<const RENDER_PASS_STATE> &&rpstate, |
| 433 | std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) |
| 434 | : BASE_NODE(static_cast<VkPipeline>(VK_NULL_HANDLE), kVulkanObjectTypePipeline), |
Nathaniel Cesario | 711be93 | 2022-03-15 13:08:00 -0600 | [diff] [blame] | 435 | rp_state(rpstate), |
amhagan | a448ea5 | 2021-11-02 14:09:14 -0400 | [diff] [blame] | 436 | create_info(pCreateInfo, rpstate), |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 437 | graphics_lib_type(GetGraphicsLibType(create_info.graphics)), |
Nathaniel Cesario | ef6e205 | 2022-02-28 14:09:45 -0700 | [diff] [blame] | 438 | vertex_input_state(CreateVertexInputState(*this, *state_data, create_info.graphics)), |
Nathaniel Cesario | 711be93 | 2022-03-15 13:08:00 -0600 | [diff] [blame] | 439 | pre_raster_state(CreatePreRasterState(*this, *state_data, create_info.graphics, rpstate)), |
| 440 | fragment_shader_state(CreateFragmentShaderState(*this, *state_data, *pCreateInfo, create_info.graphics, rpstate)), |
| 441 | fragment_output_state(CreateFragmentOutputState(*this, *state_data, *pCreateInfo, create_info.graphics, rpstate)), |
ziga-lunarg | eb65bdb | 2022-04-29 15:24:21 +0200 | [diff] [blame] | 442 | rendering_create_info(LvlFindInChain<VkPipelineRenderingCreateInfo>(PNext())), |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 443 | stage_state(GetStageStates(*state_data, *this)), |
| 444 | fragmentShader_writable_output_location_list(GetFSOutputLocations(stage_state)), |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 445 | active_slots(GetActiveSlots(stage_state)), |
| 446 | max_active_slot(GetMaxActiveSlot(active_slots)), |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 447 | active_shaders(GetActiveShaders(stage_state)), |
Nathaniel Cesario | 711be93 | 2022-03-15 13:08:00 -0600 | [diff] [blame] | 448 | topology_at_rasterizer(GetTopologyAtRasterizer(stage_state, create_info.graphics.pInputAssemblyState)) { |
Nathaniel Cesario | 81257cb | 2022-02-16 17:15:58 -0700 | [diff] [blame] | 449 | const auto link_info = LvlFindInChain<VkPipelineLibraryCreateInfoKHR>(PNext()); |
| 450 | if (link_info) { |
Nathaniel Cesario | 41f7c80 | 2022-03-01 14:28:58 -0700 | [diff] [blame] | 451 | // accumulate dynamic state |
| 452 | // TODO is this correct? |
| 453 | auto *dyn_state_ci = const_cast<safe_VkPipelineDynamicStateCreateInfo *>(create_info.graphics.pDynamicState); |
| 454 | std::vector<VkDynamicState> dyn_states; |
Nathaniel Cesario | c4e8f26 | 2022-04-02 21:34:30 -0600 | [diff] [blame] | 455 | VkPipelineDynamicStateCreateFlags dyn_flags = 0; |
Nathaniel Cesario | 41f7c80 | 2022-03-01 14:28:58 -0700 | [diff] [blame] | 456 | if (create_info.graphics.pDynamicState) { |
| 457 | std::copy(dyn_state_ci->pDynamicStates, dyn_state_ci->pDynamicStates + dyn_state_ci->dynamicStateCount, |
| 458 | std::back_inserter(dyn_states)); |
| 459 | dyn_flags = dyn_state_ci->flags; |
| 460 | } |
| 461 | AppendDynamicStateFromSubstate(vertex_input_state, dyn_states, dyn_flags); |
| 462 | AppendDynamicStateFromSubstate(pre_raster_state, dyn_states, dyn_flags); |
| 463 | AppendDynamicStateFromSubstate(fragment_shader_state, dyn_states, dyn_flags); |
| 464 | AppendDynamicStateFromSubstate(fragment_output_state, dyn_states, dyn_flags); |
| 465 | if (dyn_states.size() > 0) { |
| 466 | // We have dynamic state |
Nathaniel Cesario | e1113e4 | 2022-03-22 14:49:09 -0600 | [diff] [blame] | 467 | if (!dyn_state_ci || (dyn_state_ci->dynamicStateCount < dyn_states.size())) { |
Nathaniel Cesario | 41f7c80 | 2022-03-01 14:28:58 -0700 | [diff] [blame] | 468 | // There is dynamic state defined in libraries that the is not included in this pipeline's create info |
Nathaniel Cesario | e1113e4 | 2022-03-22 14:49:09 -0600 | [diff] [blame] | 469 | if (!dyn_state_ci) { |
| 470 | // *All* dynamic state defined is coming from graphics libraries |
| 471 | // NOTE: heap allocation cleaned up in ~safe_VkGraphicsPipelineCreateInfo |
| 472 | dyn_state_ci = new safe_VkPipelineDynamicStateCreateInfo; |
| 473 | const_cast<safe_VkGraphicsPipelineCreateInfo *>(&create_info.graphics)->pDynamicState = dyn_state_ci; |
| 474 | } |
Nathaniel Cesario | 41f7c80 | 2022-03-01 14:28:58 -0700 | [diff] [blame] | 475 | dyn_state_ci->flags = dyn_flags; |
| 476 | dyn_state_ci->dynamicStateCount = static_cast<uint32_t>(dyn_states.size()); |
| 477 | // NOTE: heap allocation cleaned up in ~safe_VkPipelineDynamicStateCreateInfo |
| 478 | dyn_state_ci->pDynamicStates = new VkDynamicState[dyn_states.size()]; |
| 479 | std::copy(&dyn_states.front(), &dyn_states.front() + dyn_states.size(), |
| 480 | const_cast<VkDynamicState *>(dyn_state_ci->pDynamicStates)); |
| 481 | } |
| 482 | } |
| 483 | |
Nathaniel Cesario | 81257cb | 2022-02-16 17:15:58 -0700 | [diff] [blame] | 484 | const auto &exe_layout_state = state_data->Get<PIPELINE_LAYOUT_STATE>(create_info.graphics.layout); |
| 485 | const auto *exe_layout = exe_layout_state.get(); |
| 486 | const auto *pre_raster_layout = |
| 487 | (pre_raster_state && pre_raster_state->pipeline_layout) ? pre_raster_state->pipeline_layout.get() : nullptr; |
| 488 | const auto *fragment_shader_layout = (fragment_shader_state && fragment_shader_state->pipeline_layout) |
| 489 | ? fragment_shader_state->pipeline_layout.get() |
| 490 | : nullptr; |
| 491 | std::array<decltype(exe_layout), 3> layouts; |
Nathaniel Cesario | 16ba1ec | 2022-03-16 11:26:47 -0600 | [diff] [blame] | 492 | layouts[0] = exe_layout; |
Nathaniel Cesario | 81257cb | 2022-02-16 17:15:58 -0700 | [diff] [blame] | 493 | layouts[1] = fragment_shader_layout; |
Nathaniel Cesario | 16ba1ec | 2022-03-16 11:26:47 -0600 | [diff] [blame] | 494 | layouts[2] = pre_raster_layout; |
Nathaniel Cesario | 81257cb | 2022-02-16 17:15:58 -0700 | [diff] [blame] | 495 | merged_graphics_layout = std::make_shared<PIPELINE_LAYOUT_STATE>(layouts); |
Nathaniel Cesario | fe8d786 | 2022-02-16 17:27:29 -0700 | [diff] [blame] | 496 | |
| 497 | // TODO Could store the graphics_lib_type in the sub-state rather than searching for it again here. |
| 498 | // Or, could store a pointer back to the owning PIPELINE_STATE. |
| 499 | for (uint32_t i = 0; i < link_info->libraryCount; ++i) { |
| 500 | const auto &state = state_data->Get<PIPELINE_STATE>(link_info->pLibraries[i]); |
| 501 | if (state) { |
| 502 | graphics_lib_type |= state->graphics_lib_type; |
| 503 | } |
| 504 | } |
Nathaniel Cesario | 81257cb | 2022-02-16 17:15:58 -0700 | [diff] [blame] | 505 | } |
| 506 | } |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 507 | |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 508 | PIPELINE_STATE::PIPELINE_STATE(const ValidationStateTracker *state_data, const VkComputePipelineCreateInfo *pCreateInfo, |
| 509 | std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) |
| 510 | : BASE_NODE(static_cast<VkPipeline>(VK_NULL_HANDLE), kVulkanObjectTypePipeline), |
| 511 | create_info(pCreateInfo), |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 512 | stage_state(GetStageStates(*state_data, *this)), |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 513 | active_slots(GetActiveSlots(stage_state)), |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 514 | active_shaders(GetActiveShaders(stage_state)), |
| 515 | topology_at_rasterizer{}, |
| 516 | merged_graphics_layout(layout) { |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 517 | assert(active_shaders == VK_SHADER_STAGE_COMPUTE_BIT); |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 518 | } |
| 519 | |
Nathaniel Cesario | c8c11c1 | 2022-02-16 17:23:50 -0700 | [diff] [blame] | 520 | PIPELINE_STATE::PIPELINE_STATE(const ValidationStateTracker *state_data, const VkRayTracingPipelineCreateInfoKHR *pCreateInfo, |
| 521 | std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) |
| 522 | : BASE_NODE(static_cast<VkPipeline>(VK_NULL_HANDLE), kVulkanObjectTypePipeline), |
| 523 | create_info(pCreateInfo), |
| 524 | stage_state(GetStageStates(*state_data, *this)), |
| 525 | active_slots(GetActiveSlots(stage_state)), |
| 526 | active_shaders(GetActiveShaders(stage_state)), |
| 527 | topology_at_rasterizer{}, |
| 528 | merged_graphics_layout(std::move(layout)) { |
| 529 | assert(0 == (active_shaders & |
| 530 | ~(VK_SHADER_STAGE_RAYGEN_BIT_KHR | VK_SHADER_STAGE_ANY_HIT_BIT_KHR | VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR | |
| 531 | VK_SHADER_STAGE_MISS_BIT_KHR | VK_SHADER_STAGE_INTERSECTION_BIT_KHR | VK_SHADER_STAGE_CALLABLE_BIT_KHR))); |
| 532 | } |
| 533 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 534 | PIPELINE_STATE::PIPELINE_STATE(const ValidationStateTracker *state_data, const VkRayTracingPipelineCreateInfoNV *pCreateInfo, |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 535 | std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) |
| 536 | : BASE_NODE(static_cast<VkPipeline>(VK_NULL_HANDLE), kVulkanObjectTypePipeline), |
| 537 | create_info(pCreateInfo), |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 538 | stage_state(GetStageStates(*state_data, *this)), |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 539 | active_slots(GetActiveSlots(stage_state)), |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 540 | active_shaders(GetActiveShaders(stage_state)), |
| 541 | topology_at_rasterizer{}, |
| 542 | merged_graphics_layout(std::move(layout)) { |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 543 | assert(0 == (active_shaders & |
| 544 | ~(VK_SHADER_STAGE_RAYGEN_BIT_KHR | VK_SHADER_STAGE_ANY_HIT_BIT_KHR | VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR | |
| 545 | VK_SHADER_STAGE_MISS_BIT_KHR | VK_SHADER_STAGE_INTERSECTION_BIT_KHR | VK_SHADER_STAGE_CALLABLE_BIT_KHR))); |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 546 | } |
| 547 | |
Jeremy Gebben | f087ddb | 2022-08-04 09:36:17 -0600 | [diff] [blame^] | 548 | void LAST_BOUND_STATE::UnbindAndResetPushDescriptorSet(std::shared_ptr<cvdescriptorset::DescriptorSet> &&ds) { |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 549 | if (push_descriptor_set) { |
| 550 | for (auto &ps : per_set) { |
Jeremy Gebben | 4d51c55 | 2022-01-06 21:27:15 -0700 | [diff] [blame] | 551 | if (ps.bound_descriptor_set == push_descriptor_set) { |
Jeremy Gebben | f087ddb | 2022-08-04 09:36:17 -0600 | [diff] [blame^] | 552 | cb_state.RemoveChild(ps.bound_descriptor_set); |
Jeremy Gebben | 4d51c55 | 2022-01-06 21:27:15 -0700 | [diff] [blame] | 553 | ps.bound_descriptor_set.reset(); |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | } |
Jeremy Gebben | f087ddb | 2022-08-04 09:36:17 -0600 | [diff] [blame^] | 557 | cb_state.AddChild(ds); |
Jeremy Gebben | 4d51c55 | 2022-01-06 21:27:15 -0700 | [diff] [blame] | 558 | push_descriptor_set = std::move(ds); |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | void LAST_BOUND_STATE::Reset() { |
| 562 | pipeline_state = nullptr; |
| 563 | pipeline_layout = VK_NULL_HANDLE; |
| 564 | if (push_descriptor_set) { |
Jeremy Gebben | f087ddb | 2022-08-04 09:36:17 -0600 | [diff] [blame^] | 565 | cb_state.RemoveChild(push_descriptor_set); |
Jeremy Gebben | 4d51c55 | 2022-01-06 21:27:15 -0700 | [diff] [blame] | 566 | push_descriptor_set->Destroy(); |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 567 | } |
Jeremy Gebben | 4d51c55 | 2022-01-06 21:27:15 -0700 | [diff] [blame] | 568 | push_descriptor_set.reset(); |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 569 | per_set.clear(); |
| 570 | } |