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 | |
Tony-LunarG | 1672d00 | 2022-08-03 14:35:34 -0600 | [diff] [blame] | 205 | static bool UsesShaderModuleId(const PIPELINE_STATE::StageStateVec &stages) { |
| 206 | bool result = false; |
| 207 | for (const auto &stage : stages) { |
| 208 | const auto module_id_info = LvlFindInChain<VkPipelineShaderStageModuleIdentifierCreateInfoEXT>(stage.create_info->pNext); |
| 209 | if (module_id_info) result |= (module_id_info->identifierSize > 0); |
| 210 | } |
| 211 | return result; |
| 212 | } |
| 213 | |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 214 | static layer_data::unordered_set<uint32_t> GetFSOutputLocations(const PIPELINE_STATE::StageStateVec &stage_states) { |
| 215 | layer_data::unordered_set<uint32_t> result; |
| 216 | for (const auto &stage : stage_states) { |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 217 | if (stage.entrypoint == stage.module_state->end()) { |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 218 | continue; |
| 219 | } |
| 220 | if (stage.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT) { |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 221 | result = stage.module_state->CollectWritableOutputLocationinFS(stage.entrypoint); |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 222 | break; |
| 223 | } |
| 224 | } |
| 225 | return result; |
| 226 | } |
| 227 | |
| 228 | static VkPrimitiveTopology GetTopologyAtRasterizer(const PIPELINE_STATE::StageStateVec &stage_states, |
| 229 | const safe_VkPipelineInputAssemblyStateCreateInfo *assembly_state) { |
| 230 | VkPrimitiveTopology result = assembly_state ? assembly_state->topology : static_cast<VkPrimitiveTopology>(0); |
| 231 | for (const auto &stage : stage_states) { |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 232 | if (stage.entrypoint == stage.module_state->end()) { |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 233 | continue; |
| 234 | } |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 235 | auto stage_topo = stage.module_state->GetTopology(stage.entrypoint); |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 236 | if (stage_topo) { |
| 237 | result = *stage_topo; |
| 238 | } |
| 239 | } |
| 240 | return result; |
| 241 | } |
| 242 | |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 243 | // static |
Nathaniel Cesario | ef6e205 | 2022-02-28 14:09:45 -0700 | [diff] [blame] | 244 | std::shared_ptr<VertexInputState> PIPELINE_STATE::CreateVertexInputState(const PIPELINE_STATE &p, |
| 245 | const ValidationStateTracker &state, |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 246 | const safe_VkGraphicsPipelineCreateInfo &create_info) { |
| 247 | const auto lib_type = GetGraphicsLibType(create_info); |
| 248 | 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] | 249 | return std::make_shared<VertexInputState>(p, create_info); |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | const auto link_info = LvlFindInChain<VkPipelineLibraryCreateInfoKHR>(create_info.pNext); |
| 253 | if (link_info) { |
Nathaniel Cesario | 0f5906a | 2022-04-05 11:10:18 -0600 | [diff] [blame] | 254 | 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] | 255 | if (ss) { |
| 256 | return ss; |
| 257 | } |
Nathaniel Cesario | fe8d786 | 2022-02-16 17:27:29 -0700 | [diff] [blame] | 258 | } else { |
| 259 | if (lib_type == static_cast<VkGraphicsPipelineLibraryFlagsEXT>(0)) { // Not a graphics library |
Nathaniel Cesario | ef6e205 | 2022-02-28 14:09:45 -0700 | [diff] [blame] | 260 | return std::make_shared<VertexInputState>(p, create_info); |
Nathaniel Cesario | fe8d786 | 2022-02-16 17:27:29 -0700 | [diff] [blame] | 261 | } |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | // We shouldn't get here... |
| 265 | return {}; |
| 266 | } |
| 267 | |
| 268 | // static |
Nathaniel Cesario | ef6e205 | 2022-02-28 14:09:45 -0700 | [diff] [blame] | 269 | 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] | 270 | const safe_VkGraphicsPipelineCreateInfo &create_info, |
| 271 | std::shared_ptr<const RENDER_PASS_STATE> rp) { |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 272 | const auto lib_type = GetGraphicsLibType(create_info); |
| 273 | 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] | 274 | return std::make_shared<PreRasterState>(p, state, create_info, rp); |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | const auto link_info = LvlFindInChain<VkPipelineLibraryCreateInfoKHR>(create_info.pNext); |
| 278 | if (link_info) { |
Nathaniel Cesario | 0f5906a | 2022-04-05 11:10:18 -0600 | [diff] [blame] | 279 | 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] | 280 | if (ss) { |
| 281 | return ss; |
| 282 | } |
Nathaniel Cesario | fe8d786 | 2022-02-16 17:27:29 -0700 | [diff] [blame] | 283 | } else { |
| 284 | if (lib_type == static_cast<VkGraphicsPipelineLibraryFlagsEXT>(0)) { // Not a graphics library |
Nathaniel Cesario | 711be93 | 2022-03-15 13:08:00 -0600 | [diff] [blame] | 285 | return std::make_shared<PreRasterState>(p, state, create_info, rp); |
Nathaniel Cesario | fe8d786 | 2022-02-16 17:27:29 -0700 | [diff] [blame] | 286 | } |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | // We shouldn't get here... |
| 290 | return {}; |
| 291 | } |
| 292 | |
| 293 | // static |
| 294 | std::shared_ptr<FragmentShaderState> PIPELINE_STATE::CreateFragmentShaderState( |
Nathaniel Cesario | ef6e205 | 2022-02-28 14:09:45 -0700 | [diff] [blame] | 295 | const PIPELINE_STATE &p, const ValidationStateTracker &state, const VkGraphicsPipelineCreateInfo &create_info, |
Nathaniel Cesario | 711be93 | 2022-03-15 13:08:00 -0600 | [diff] [blame] | 296 | 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] | 297 | const auto lib_type = GetGraphicsLibType(create_info); |
| 298 | 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] | 299 | return std::make_shared<FragmentShaderState>(p, state, create_info, rp); |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | const auto link_info = LvlFindInChain<VkPipelineLibraryCreateInfoKHR>(create_info.pNext); |
| 303 | if (link_info) { |
Nathaniel Cesario | 0f5906a | 2022-04-05 11:10:18 -0600 | [diff] [blame] | 304 | 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] | 305 | if (ss) { |
| 306 | return ss; |
| 307 | } |
Nathaniel Cesario | fe8d786 | 2022-02-16 17:27:29 -0700 | [diff] [blame] | 308 | } else { |
| 309 | if (lib_type == static_cast<VkGraphicsPipelineLibraryFlagsEXT>(0)) { // Not a graphics library |
Nathaniel Cesario | 711be93 | 2022-03-15 13:08:00 -0600 | [diff] [blame] | 310 | return std::make_shared<FragmentShaderState>(p, state, safe_create_info, rp); |
Nathaniel Cesario | fe8d786 | 2022-02-16 17:27:29 -0700 | [diff] [blame] | 311 | } |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | // We shouldn't get here... |
| 315 | return {}; |
| 316 | } |
| 317 | |
| 318 | // static |
| 319 | // 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" |
| 320 | // create_info. |
| 321 | std::shared_ptr<FragmentOutputState> PIPELINE_STATE::CreateFragmentOutputState( |
Nathaniel Cesario | ef6e205 | 2022-02-28 14:09:45 -0700 | [diff] [blame] | 322 | const PIPELINE_STATE &p, const ValidationStateTracker &state, const VkGraphicsPipelineCreateInfo &create_info, |
Nathaniel Cesario | 711be93 | 2022-03-15 13:08:00 -0600 | [diff] [blame] | 323 | 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] | 324 | const auto lib_type = GetGraphicsLibType(create_info); |
| 325 | 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] | 326 | return std::make_shared<FragmentOutputState>(p, create_info, rp); |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | const auto link_info = LvlFindInChain<VkPipelineLibraryCreateInfoKHR>(create_info.pNext); |
| 330 | if (link_info) { |
Nathaniel Cesario | 0f5906a | 2022-04-05 11:10:18 -0600 | [diff] [blame] | 331 | 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] | 332 | if (ss) { |
| 333 | return ss; |
| 334 | } |
Nathaniel Cesario | fe8d786 | 2022-02-16 17:27:29 -0700 | [diff] [blame] | 335 | } else { |
| 336 | if (lib_type == static_cast<VkGraphicsPipelineLibraryFlagsEXT>(0)) { // Not a graphics library |
Nathaniel Cesario | 711be93 | 2022-03-15 13:08:00 -0600 | [diff] [blame] | 337 | return std::make_shared<FragmentOutputState>(p, safe_create_info, rp); |
Nathaniel Cesario | fe8d786 | 2022-02-16 17:27:29 -0700 | [diff] [blame] | 338 | } |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | // We shouldn't get here... |
| 342 | return {}; |
| 343 | } |
| 344 | |
Nathaniel Cesario | 41f7c80 | 2022-03-01 14:28:58 -0700 | [diff] [blame] | 345 | template <typename Substate> |
| 346 | void AppendDynamicStateFromSubstate(const Substate &substate, std::vector<VkDynamicState> &dyn_states, |
| 347 | VkPipelineDynamicStateCreateFlags &flags) { |
| 348 | if (substate) { |
| 349 | const auto *dyn_state = substate->parent.DynamicState(); |
| 350 | if (dyn_state) { |
| 351 | flags |= dyn_state->flags; |
| 352 | for (uint32_t i = 0; i < dyn_state->dynamicStateCount; ++i) { |
| 353 | const auto itr = std::find(dyn_states.cbegin(), dyn_states.cend(), dyn_state->pDynamicStates[i]); |
| 354 | if (itr == dyn_states.cend()) { |
| 355 | dyn_states.emplace_back(dyn_state->pDynamicStates[i]); |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
Nathaniel Cesario | cb17f98 | 2022-06-02 15:33:49 -0600 | [diff] [blame] | 362 | std::vector<std::shared_ptr<const PIPELINE_LAYOUT_STATE>> PIPELINE_STATE::PipelineLayoutStateUnion() const { |
| 363 | std::vector<std::shared_ptr<const PIPELINE_LAYOUT_STATE>> ret; |
| 364 | ret.reserve(2); |
| 365 | // Only need to check pre-raster _or_ fragment shader layout; if either one is not merged_graphics_layout, then |
| 366 | // merged_graphics_layout is a union |
| 367 | if (pre_raster_state) { |
| 368 | if (pre_raster_state->pipeline_layout != fragment_shader_state->pipeline_layout) { |
| 369 | return {pre_raster_state->pipeline_layout, fragment_shader_state->pipeline_layout}; |
| 370 | } else { |
| 371 | return {pre_raster_state->pipeline_layout}; |
| 372 | } |
| 373 | } |
| 374 | return {merged_graphics_layout}; |
| 375 | } |
| 376 | |
Nathaniel Cesario | d4d8fce | 2022-05-06 15:01:10 -0600 | [diff] [blame] | 377 | template <> |
| 378 | VkPipeline PIPELINE_STATE::BasePipeline<VkGraphicsPipelineCreateInfo>() const { |
| 379 | assert(create_info.graphics.sType == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO); |
| 380 | return create_info.graphics.basePipelineHandle; |
| 381 | } |
| 382 | template <> |
| 383 | VkPipeline PIPELINE_STATE::BasePipeline<VkComputePipelineCreateInfo>() const { |
| 384 | assert(create_info.compute.sType == VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO); |
| 385 | return create_info.compute.basePipelineHandle; |
| 386 | } |
| 387 | template <> |
| 388 | VkPipeline PIPELINE_STATE::BasePipeline<VkRayTracingPipelineCreateInfoKHR>() const { |
| 389 | assert(create_info.raytracing.sType == VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR); |
| 390 | return create_info.raytracing.basePipelineHandle; |
| 391 | } |
| 392 | template <> |
| 393 | VkPipeline PIPELINE_STATE::BasePipeline<VkRayTracingPipelineCreateInfoNV>() const { |
| 394 | assert(create_info.raytracing.sType == VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_NV); |
| 395 | return create_info.raytracing.basePipelineHandle; |
| 396 | } |
| 397 | |
| 398 | template <> |
| 399 | int32_t PIPELINE_STATE::BasePipelineIndex<VkGraphicsPipelineCreateInfo>() const { |
| 400 | assert(create_info.graphics.sType == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO); |
| 401 | return create_info.graphics.basePipelineIndex; |
| 402 | } |
| 403 | template <> |
| 404 | int32_t PIPELINE_STATE::BasePipelineIndex<VkComputePipelineCreateInfo>() const { |
| 405 | assert(create_info.compute.sType == VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO); |
| 406 | return create_info.compute.basePipelineIndex; |
| 407 | } |
| 408 | template <> |
| 409 | int32_t PIPELINE_STATE::BasePipelineIndex<VkRayTracingPipelineCreateInfoKHR>() const { |
| 410 | assert(create_info.raytracing.sType == VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR); |
| 411 | return create_info.raytracing.basePipelineIndex; |
| 412 | } |
| 413 | template <> |
| 414 | int32_t PIPELINE_STATE::BasePipelineIndex<VkRayTracingPipelineCreateInfoNV>() const { |
| 415 | assert(create_info.raytracing.sType == VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_NV); |
| 416 | return create_info.raytracing.basePipelineIndex; |
| 417 | } |
| 418 | |
| 419 | template <> |
| 420 | VkShaderModule PIPELINE_STATE::PIPELINE_STATE::GetShaderModuleByCIIndex<VkGraphicsPipelineCreateInfo>(uint32_t i) { |
| 421 | assert(create_info.graphics.sType == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO); |
| 422 | return create_info.graphics.pStages[i].module; |
| 423 | } |
| 424 | template <> |
| 425 | VkShaderModule PIPELINE_STATE::GetShaderModuleByCIIndex<VkComputePipelineCreateInfo>(uint32_t) { |
| 426 | assert(create_info.compute.sType == VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO); |
| 427 | return create_info.compute.stage.module; |
| 428 | } |
| 429 | template <> |
| 430 | VkShaderModule PIPELINE_STATE::GetShaderModuleByCIIndex<VkRayTracingPipelineCreateInfoKHR>(uint32_t i) { |
| 431 | assert(create_info.raytracing.sType == VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR); |
| 432 | return create_info.raytracing.pStages[i].module; |
| 433 | } |
| 434 | template <> |
| 435 | VkShaderModule PIPELINE_STATE::GetShaderModuleByCIIndex<VkRayTracingPipelineCreateInfoNV>(uint32_t i) { |
| 436 | assert(create_info.raytracing.sType == VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_NV); |
| 437 | return create_info.raytracing.pStages[i].module; |
| 438 | } |
| 439 | |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 440 | PIPELINE_STATE::PIPELINE_STATE(const ValidationStateTracker *state_data, const VkGraphicsPipelineCreateInfo *pCreateInfo, |
| 441 | std::shared_ptr<const RENDER_PASS_STATE> &&rpstate, |
| 442 | std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) |
| 443 | : BASE_NODE(static_cast<VkPipeline>(VK_NULL_HANDLE), kVulkanObjectTypePipeline), |
Nathaniel Cesario | 711be93 | 2022-03-15 13:08:00 -0600 | [diff] [blame] | 444 | rp_state(rpstate), |
amhagan | a448ea5 | 2021-11-02 14:09:14 -0400 | [diff] [blame] | 445 | create_info(pCreateInfo, rpstate), |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 446 | graphics_lib_type(GetGraphicsLibType(create_info.graphics)), |
Nathaniel Cesario | ef6e205 | 2022-02-28 14:09:45 -0700 | [diff] [blame] | 447 | vertex_input_state(CreateVertexInputState(*this, *state_data, create_info.graphics)), |
Nathaniel Cesario | 711be93 | 2022-03-15 13:08:00 -0600 | [diff] [blame] | 448 | pre_raster_state(CreatePreRasterState(*this, *state_data, create_info.graphics, rpstate)), |
| 449 | fragment_shader_state(CreateFragmentShaderState(*this, *state_data, *pCreateInfo, create_info.graphics, rpstate)), |
| 450 | fragment_output_state(CreateFragmentOutputState(*this, *state_data, *pCreateInfo, create_info.graphics, rpstate)), |
ziga-lunarg | eb65bdb | 2022-04-29 15:24:21 +0200 | [diff] [blame] | 451 | rendering_create_info(LvlFindInChain<VkPipelineRenderingCreateInfo>(PNext())), |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 452 | stage_state(GetStageStates(*state_data, *this)), |
| 453 | fragmentShader_writable_output_location_list(GetFSOutputLocations(stage_state)), |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 454 | active_slots(GetActiveSlots(stage_state)), |
| 455 | max_active_slot(GetMaxActiveSlot(active_slots)), |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 456 | active_shaders(GetActiveShaders(stage_state)), |
Tony-LunarG | 1672d00 | 2022-08-03 14:35:34 -0600 | [diff] [blame] | 457 | topology_at_rasterizer(GetTopologyAtRasterizer(stage_state, create_info.graphics.pInputAssemblyState)), |
| 458 | uses_shader_module_id(UsesShaderModuleId(stage_state)) { |
Nathaniel Cesario | 81257cb | 2022-02-16 17:15:58 -0700 | [diff] [blame] | 459 | const auto link_info = LvlFindInChain<VkPipelineLibraryCreateInfoKHR>(PNext()); |
| 460 | if (link_info) { |
Nathaniel Cesario | 41f7c80 | 2022-03-01 14:28:58 -0700 | [diff] [blame] | 461 | // accumulate dynamic state |
| 462 | // TODO is this correct? |
| 463 | auto *dyn_state_ci = const_cast<safe_VkPipelineDynamicStateCreateInfo *>(create_info.graphics.pDynamicState); |
| 464 | std::vector<VkDynamicState> dyn_states; |
Nathaniel Cesario | c4e8f26 | 2022-04-02 21:34:30 -0600 | [diff] [blame] | 465 | VkPipelineDynamicStateCreateFlags dyn_flags = 0; |
Nathaniel Cesario | 41f7c80 | 2022-03-01 14:28:58 -0700 | [diff] [blame] | 466 | if (create_info.graphics.pDynamicState) { |
| 467 | std::copy(dyn_state_ci->pDynamicStates, dyn_state_ci->pDynamicStates + dyn_state_ci->dynamicStateCount, |
| 468 | std::back_inserter(dyn_states)); |
| 469 | dyn_flags = dyn_state_ci->flags; |
| 470 | } |
| 471 | AppendDynamicStateFromSubstate(vertex_input_state, dyn_states, dyn_flags); |
| 472 | AppendDynamicStateFromSubstate(pre_raster_state, dyn_states, dyn_flags); |
| 473 | AppendDynamicStateFromSubstate(fragment_shader_state, dyn_states, dyn_flags); |
| 474 | AppendDynamicStateFromSubstate(fragment_output_state, dyn_states, dyn_flags); |
| 475 | if (dyn_states.size() > 0) { |
| 476 | // We have dynamic state |
Nathaniel Cesario | e1113e4 | 2022-03-22 14:49:09 -0600 | [diff] [blame] | 477 | if (!dyn_state_ci || (dyn_state_ci->dynamicStateCount < dyn_states.size())) { |
Nathaniel Cesario | 41f7c80 | 2022-03-01 14:28:58 -0700 | [diff] [blame] | 478 | // 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] | 479 | if (!dyn_state_ci) { |
| 480 | // *All* dynamic state defined is coming from graphics libraries |
| 481 | // NOTE: heap allocation cleaned up in ~safe_VkGraphicsPipelineCreateInfo |
| 482 | dyn_state_ci = new safe_VkPipelineDynamicStateCreateInfo; |
| 483 | const_cast<safe_VkGraphicsPipelineCreateInfo *>(&create_info.graphics)->pDynamicState = dyn_state_ci; |
| 484 | } |
Nathaniel Cesario | 41f7c80 | 2022-03-01 14:28:58 -0700 | [diff] [blame] | 485 | dyn_state_ci->flags = dyn_flags; |
| 486 | dyn_state_ci->dynamicStateCount = static_cast<uint32_t>(dyn_states.size()); |
| 487 | // NOTE: heap allocation cleaned up in ~safe_VkPipelineDynamicStateCreateInfo |
| 488 | dyn_state_ci->pDynamicStates = new VkDynamicState[dyn_states.size()]; |
| 489 | std::copy(&dyn_states.front(), &dyn_states.front() + dyn_states.size(), |
| 490 | const_cast<VkDynamicState *>(dyn_state_ci->pDynamicStates)); |
| 491 | } |
| 492 | } |
| 493 | |
Nathaniel Cesario | 81257cb | 2022-02-16 17:15:58 -0700 | [diff] [blame] | 494 | const auto &exe_layout_state = state_data->Get<PIPELINE_LAYOUT_STATE>(create_info.graphics.layout); |
| 495 | const auto *exe_layout = exe_layout_state.get(); |
| 496 | const auto *pre_raster_layout = |
| 497 | (pre_raster_state && pre_raster_state->pipeline_layout) ? pre_raster_state->pipeline_layout.get() : nullptr; |
| 498 | const auto *fragment_shader_layout = (fragment_shader_state && fragment_shader_state->pipeline_layout) |
| 499 | ? fragment_shader_state->pipeline_layout.get() |
| 500 | : nullptr; |
| 501 | std::array<decltype(exe_layout), 3> layouts; |
Nathaniel Cesario | 16ba1ec | 2022-03-16 11:26:47 -0600 | [diff] [blame] | 502 | layouts[0] = exe_layout; |
Nathaniel Cesario | 81257cb | 2022-02-16 17:15:58 -0700 | [diff] [blame] | 503 | layouts[1] = fragment_shader_layout; |
Nathaniel Cesario | 16ba1ec | 2022-03-16 11:26:47 -0600 | [diff] [blame] | 504 | layouts[2] = pre_raster_layout; |
Nathaniel Cesario | 81257cb | 2022-02-16 17:15:58 -0700 | [diff] [blame] | 505 | merged_graphics_layout = std::make_shared<PIPELINE_LAYOUT_STATE>(layouts); |
Nathaniel Cesario | fe8d786 | 2022-02-16 17:27:29 -0700 | [diff] [blame] | 506 | |
| 507 | // TODO Could store the graphics_lib_type in the sub-state rather than searching for it again here. |
| 508 | // Or, could store a pointer back to the owning PIPELINE_STATE. |
| 509 | for (uint32_t i = 0; i < link_info->libraryCount; ++i) { |
| 510 | const auto &state = state_data->Get<PIPELINE_STATE>(link_info->pLibraries[i]); |
| 511 | if (state) { |
| 512 | graphics_lib_type |= state->graphics_lib_type; |
| 513 | } |
| 514 | } |
Nathaniel Cesario | 81257cb | 2022-02-16 17:15:58 -0700 | [diff] [blame] | 515 | } |
| 516 | } |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 517 | |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 518 | PIPELINE_STATE::PIPELINE_STATE(const ValidationStateTracker *state_data, const VkComputePipelineCreateInfo *pCreateInfo, |
| 519 | std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) |
| 520 | : BASE_NODE(static_cast<VkPipeline>(VK_NULL_HANDLE), kVulkanObjectTypePipeline), |
| 521 | create_info(pCreateInfo), |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 522 | stage_state(GetStageStates(*state_data, *this)), |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 523 | active_slots(GetActiveSlots(stage_state)), |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 524 | active_shaders(GetActiveShaders(stage_state)), |
| 525 | topology_at_rasterizer{}, |
Tony-LunarG | 1672d00 | 2022-08-03 14:35:34 -0600 | [diff] [blame] | 526 | uses_shader_module_id(UsesShaderModuleId(stage_state)), |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 527 | merged_graphics_layout(layout) { |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 528 | assert(active_shaders == VK_SHADER_STAGE_COMPUTE_BIT); |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 529 | } |
| 530 | |
Nathaniel Cesario | c8c11c1 | 2022-02-16 17:23:50 -0700 | [diff] [blame] | 531 | PIPELINE_STATE::PIPELINE_STATE(const ValidationStateTracker *state_data, const VkRayTracingPipelineCreateInfoKHR *pCreateInfo, |
| 532 | std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) |
| 533 | : BASE_NODE(static_cast<VkPipeline>(VK_NULL_HANDLE), kVulkanObjectTypePipeline), |
| 534 | create_info(pCreateInfo), |
| 535 | stage_state(GetStageStates(*state_data, *this)), |
| 536 | active_slots(GetActiveSlots(stage_state)), |
| 537 | active_shaders(GetActiveShaders(stage_state)), |
| 538 | topology_at_rasterizer{}, |
Tony-LunarG | 1672d00 | 2022-08-03 14:35:34 -0600 | [diff] [blame] | 539 | uses_shader_module_id(UsesShaderModuleId(stage_state)), |
Nathaniel Cesario | c8c11c1 | 2022-02-16 17:23:50 -0700 | [diff] [blame] | 540 | merged_graphics_layout(std::move(layout)) { |
| 541 | assert(0 == (active_shaders & |
| 542 | ~(VK_SHADER_STAGE_RAYGEN_BIT_KHR | VK_SHADER_STAGE_ANY_HIT_BIT_KHR | VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR | |
| 543 | VK_SHADER_STAGE_MISS_BIT_KHR | VK_SHADER_STAGE_INTERSECTION_BIT_KHR | VK_SHADER_STAGE_CALLABLE_BIT_KHR))); |
| 544 | } |
| 545 | |
Jeremy Gebben | 20da7a1 | 2022-02-25 14:07:46 -0700 | [diff] [blame] | 546 | PIPELINE_STATE::PIPELINE_STATE(const ValidationStateTracker *state_data, const VkRayTracingPipelineCreateInfoNV *pCreateInfo, |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 547 | std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) |
| 548 | : BASE_NODE(static_cast<VkPipeline>(VK_NULL_HANDLE), kVulkanObjectTypePipeline), |
| 549 | create_info(pCreateInfo), |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 550 | stage_state(GetStageStates(*state_data, *this)), |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 551 | active_slots(GetActiveSlots(stage_state)), |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 552 | active_shaders(GetActiveShaders(stage_state)), |
| 553 | topology_at_rasterizer{}, |
Tony-LunarG | 1672d00 | 2022-08-03 14:35:34 -0600 | [diff] [blame] | 554 | uses_shader_module_id(UsesShaderModuleId(stage_state)), |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 555 | merged_graphics_layout(std::move(layout)) { |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 556 | assert(0 == (active_shaders & |
| 557 | ~(VK_SHADER_STAGE_RAYGEN_BIT_KHR | VK_SHADER_STAGE_ANY_HIT_BIT_KHR | VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR | |
| 558 | 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] | 559 | } |
| 560 | |
Jeremy Gebben | f087ddb | 2022-08-04 09:36:17 -0600 | [diff] [blame] | 561 | void LAST_BOUND_STATE::UnbindAndResetPushDescriptorSet(std::shared_ptr<cvdescriptorset::DescriptorSet> &&ds) { |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 562 | if (push_descriptor_set) { |
| 563 | for (auto &ps : per_set) { |
Jeremy Gebben | 4d51c55 | 2022-01-06 21:27:15 -0700 | [diff] [blame] | 564 | if (ps.bound_descriptor_set == push_descriptor_set) { |
Jeremy Gebben | f087ddb | 2022-08-04 09:36:17 -0600 | [diff] [blame] | 565 | cb_state.RemoveChild(ps.bound_descriptor_set); |
Jeremy Gebben | 4d51c55 | 2022-01-06 21:27:15 -0700 | [diff] [blame] | 566 | ps.bound_descriptor_set.reset(); |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | } |
Jeremy Gebben | f087ddb | 2022-08-04 09:36:17 -0600 | [diff] [blame] | 570 | cb_state.AddChild(ds); |
Jeremy Gebben | 4d51c55 | 2022-01-06 21:27:15 -0700 | [diff] [blame] | 571 | push_descriptor_set = std::move(ds); |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | void LAST_BOUND_STATE::Reset() { |
| 575 | pipeline_state = nullptr; |
| 576 | pipeline_layout = VK_NULL_HANDLE; |
| 577 | if (push_descriptor_set) { |
Jeremy Gebben | f087ddb | 2022-08-04 09:36:17 -0600 | [diff] [blame] | 578 | cb_state.RemoveChild(push_descriptor_set); |
Jeremy Gebben | 4d51c55 | 2022-01-06 21:27:15 -0700 | [diff] [blame] | 579 | push_descriptor_set->Destroy(); |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 580 | } |
Jeremy Gebben | 4d51c55 | 2022-01-06 21:27:15 -0700 | [diff] [blame] | 581 | push_descriptor_set.reset(); |
Jeremy Gebben | adb3eb0 | 2021-06-15 12:55:19 -0600 | [diff] [blame] | 582 | per_set.clear(); |
| 583 | } |