sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2020-2022 The Khronos Group Inc. |
| 2 | * Copyright (c) 2020-2022 Valve Corporation |
| 3 | * Copyright (c) 2020-2022 LunarG, Inc. |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | * Author: Tony Barbour <tony@lunarg.com> |
| 18 | */ |
| 19 | #pragma once |
| 20 | #include "chassis.h" |
| 21 | #include "shader_validation.h" |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 22 | #include "cmd_buffer_state.h" |
Jeremy Gebben | 5160e03 | 2022-03-28 14:57:43 -0600 | [diff] [blame] | 23 | #include "state_tracker.h" |
| 24 | #include "vk_mem_alloc.h" |
Jeremy Gebben | fcfc33c | 2022-03-28 15:31:29 -0600 | [diff] [blame^] | 25 | #include "queue_state.h" |
Jeremy Gebben | 5160e03 | 2022-03-28 14:57:43 -0600 | [diff] [blame] | 26 | |
Jeremy Gebben | fcfc33c | 2022-03-28 15:31:29 -0600 | [diff] [blame^] | 27 | class GpuAssistedBase; |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 28 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 29 | class UtilDescriptorSetManager { |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 30 | public: |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 31 | UtilDescriptorSetManager(VkDevice device, uint32_t numBindingsInSet); |
| 32 | ~UtilDescriptorSetManager(); |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 33 | |
| 34 | VkResult GetDescriptorSet(VkDescriptorPool *desc_pool, VkDescriptorSetLayout ds_layout, VkDescriptorSet *desc_sets); |
| 35 | VkResult GetDescriptorSets(uint32_t count, VkDescriptorPool *pool, VkDescriptorSetLayout ds_layout, |
| 36 | std::vector<VkDescriptorSet> *desc_sets); |
| 37 | void PutBackDescriptorSet(VkDescriptorPool desc_pool, VkDescriptorSet desc_set); |
| 38 | |
| 39 | private: |
Jeremy Gebben | fcfc33c | 2022-03-28 15:31:29 -0600 | [diff] [blame^] | 40 | std::unique_lock<std::mutex> Lock() const { return std::unique_lock<std::mutex>(lock_); } |
| 41 | |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 42 | static const uint32_t kItemsPerChunk = 512; |
| 43 | struct PoolTracker { |
| 44 | uint32_t size; |
| 45 | uint32_t used; |
| 46 | }; |
| 47 | VkDevice device; |
| 48 | uint32_t numBindingsInSet; |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 49 | layer_data::unordered_map<VkDescriptorPool, struct PoolTracker> desc_pool_map_; |
Jeremy Gebben | fcfc33c | 2022-03-28 15:31:29 -0600 | [diff] [blame^] | 50 | mutable std::mutex lock_; |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 51 | }; |
Jeremy Gebben | fcfc33c | 2022-03-28 15:31:29 -0600 | [diff] [blame^] | 52 | |
| 53 | namespace gpu_utils_state { |
| 54 | class Queue : public QUEUE_STATE { |
| 55 | public: |
| 56 | Queue(GpuAssistedBase &state, VkQueue q, uint32_t index, VkDeviceQueueCreateFlags flags); |
| 57 | virtual ~Queue(); |
| 58 | void SubmitBarrier(); |
| 59 | |
| 60 | private: |
| 61 | GpuAssistedBase &state_; |
| 62 | VkCommandPool barrier_command_pool_{VK_NULL_HANDLE}; |
| 63 | VkCommandBuffer barrier_command_buffer_{VK_NULL_HANDLE}; |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 64 | }; |
Jeremy Gebben | fcfc33c | 2022-03-28 15:31:29 -0600 | [diff] [blame^] | 65 | } // namespace gpu_utils_state |
| 66 | VALSTATETRACK_DERIVED_STATE_OBJECT(VkQueue, gpu_utils_state::Queue, QUEUE_STATE); |
| 67 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 68 | VkResult UtilInitializeVma(VkPhysicalDevice physical_device, VkDevice device, VmaAllocator *pAllocator); |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 69 | template <typename ObjectType> |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 70 | void UtilPreCallRecordCreatePipelineLayout(create_pipeline_layout_api_state *cpl_state, ObjectType *object_ptr, |
| 71 | const VkPipelineLayoutCreateInfo *pCreateInfo) { |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 72 | // Modify the pipeline layout by: |
| 73 | // 1. Copying the caller's descriptor set desc_layouts |
| 74 | // 2. Fill in dummy descriptor layouts up to the max binding |
| 75 | // 3. Fill in with the debug descriptor layout at the max binding slot |
| 76 | cpl_state->new_layouts.reserve(object_ptr->adjusted_max_desc_sets); |
| 77 | cpl_state->new_layouts.insert(cpl_state->new_layouts.end(), &pCreateInfo->pSetLayouts[0], |
| 78 | &pCreateInfo->pSetLayouts[pCreateInfo->setLayoutCount]); |
| 79 | for (uint32_t i = pCreateInfo->setLayoutCount; i < object_ptr->adjusted_max_desc_sets - 1; ++i) { |
| 80 | cpl_state->new_layouts.push_back(object_ptr->dummy_desc_layout); |
| 81 | } |
| 82 | cpl_state->new_layouts.push_back(object_ptr->debug_desc_layout); |
| 83 | cpl_state->modified_create_info.pSetLayouts = cpl_state->new_layouts.data(); |
| 84 | cpl_state->modified_create_info.setLayoutCount = object_ptr->adjusted_max_desc_sets; |
| 85 | } |
| 86 | |
| 87 | template <typename CreateInfo> |
| 88 | struct CreatePipelineTraits {}; |
| 89 | template <> |
| 90 | struct CreatePipelineTraits<VkGraphicsPipelineCreateInfo> { |
| 91 | using SafeType = safe_VkGraphicsPipelineCreateInfo; |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 92 | static const SafeType &GetPipelineCI(const PIPELINE_STATE *pipeline_state) { |
| 93 | return pipeline_state->GetUnifiedCreateInfo().graphics; |
| 94 | } |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 95 | static uint32_t GetStageCount(const VkGraphicsPipelineCreateInfo &createInfo) { return createInfo.stageCount; } |
| 96 | static VkShaderModule GetShaderModule(const VkGraphicsPipelineCreateInfo &createInfo, uint32_t stage) { |
| 97 | return createInfo.pStages[stage].module; |
| 98 | } |
| 99 | static void SetShaderModule(SafeType *createInfo, VkShaderModule shader_module, uint32_t stage) { |
| 100 | createInfo->pStages[stage].module = shader_module; |
| 101 | } |
| 102 | }; |
| 103 | |
| 104 | template <> |
| 105 | struct CreatePipelineTraits<VkComputePipelineCreateInfo> { |
| 106 | using SafeType = safe_VkComputePipelineCreateInfo; |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 107 | static const SafeType &GetPipelineCI(const PIPELINE_STATE *pipeline_state) { |
| 108 | return pipeline_state->GetUnifiedCreateInfo().compute; |
| 109 | } |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 110 | static uint32_t GetStageCount(const VkComputePipelineCreateInfo &createInfo) { return 1; } |
| 111 | static VkShaderModule GetShaderModule(const VkComputePipelineCreateInfo &createInfo, uint32_t stage) { |
| 112 | return createInfo.stage.module; |
| 113 | } |
| 114 | static void SetShaderModule(SafeType *createInfo, VkShaderModule shader_module, uint32_t stage) { |
| 115 | assert(stage == 0); |
| 116 | createInfo->stage.module = shader_module; |
| 117 | } |
| 118 | }; |
| 119 | |
| 120 | template <> |
| 121 | struct CreatePipelineTraits<VkRayTracingPipelineCreateInfoNV> { |
| 122 | using SafeType = safe_VkRayTracingPipelineCreateInfoCommon; |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 123 | static const SafeType &GetPipelineCI(const PIPELINE_STATE *pipeline_state) { |
| 124 | return pipeline_state->GetUnifiedCreateInfo().raytracing; |
| 125 | } |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 126 | static uint32_t GetStageCount(const VkRayTracingPipelineCreateInfoNV &createInfo) { return createInfo.stageCount; } |
| 127 | static VkShaderModule GetShaderModule(const VkRayTracingPipelineCreateInfoNV &createInfo, uint32_t stage) { |
| 128 | return createInfo.pStages[stage].module; |
| 129 | } |
| 130 | static void SetShaderModule(SafeType *createInfo, VkShaderModule shader_module, uint32_t stage) { |
| 131 | createInfo->pStages[stage].module = shader_module; |
| 132 | } |
| 133 | }; |
| 134 | |
| 135 | template <> |
| 136 | struct CreatePipelineTraits<VkRayTracingPipelineCreateInfoKHR> { |
| 137 | using SafeType = safe_VkRayTracingPipelineCreateInfoCommon; |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 138 | static const SafeType &GetPipelineCI(const PIPELINE_STATE *pipeline_state) { |
| 139 | return pipeline_state->GetUnifiedCreateInfo().raytracing; |
| 140 | } |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 141 | static uint32_t GetStageCount(const VkRayTracingPipelineCreateInfoKHR &createInfo) { return createInfo.stageCount; } |
| 142 | static VkShaderModule GetShaderModule(const VkRayTracingPipelineCreateInfoKHR &createInfo, uint32_t stage) { |
| 143 | return createInfo.pStages[stage].module; |
| 144 | } |
| 145 | static void SetShaderModule(SafeType *createInfo, VkShaderModule shader_module, uint32_t stage) { |
| 146 | createInfo->pStages[stage].module = shader_module; |
| 147 | } |
| 148 | }; |
| 149 | |
| 150 | // Examine the pipelines to see if they use the debug descriptor set binding index. |
| 151 | // If any do, create new non-instrumented shader modules and use them to replace the instrumented |
| 152 | // shaders in the pipeline. Return the (possibly) modified create infos to the caller. |
| 153 | template <typename CreateInfo, typename SafeCreateInfo, typename ObjectType> |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 154 | void UtilPreCallRecordPipelineCreations(uint32_t count, const CreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator, |
| 155 | VkPipeline *pPipelines, std::vector<std::shared_ptr<PIPELINE_STATE>> &pipe_state, |
| 156 | std::vector<SafeCreateInfo> *new_pipeline_create_infos, |
| 157 | const VkPipelineBindPoint bind_point, ObjectType *object_ptr) { |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 158 | using Accessor = CreatePipelineTraits<CreateInfo>; |
| 159 | if (bind_point != VK_PIPELINE_BIND_POINT_GRAPHICS && bind_point != VK_PIPELINE_BIND_POINT_COMPUTE && |
| 160 | bind_point != VK_PIPELINE_BIND_POINT_RAY_TRACING_NV) { |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | // Walk through all the pipelines, make a copy of each and flag each pipeline that contains a shader that uses the debug |
| 165 | // descriptor set index. |
| 166 | for (uint32_t pipeline = 0; pipeline < count; ++pipeline) { |
| 167 | uint32_t stageCount = Accessor::GetStageCount(pCreateInfos[pipeline]); |
| 168 | new_pipeline_create_infos->push_back(Accessor::GetPipelineCI(pipe_state[pipeline].get())); |
Nathaniel Cesario | bcb7968 | 2022-03-31 21:13:52 -0600 | [diff] [blame] | 169 | const auto &pipe = pipe_state[pipeline]; |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 170 | |
Nathaniel Cesario | bcb7968 | 2022-03-31 21:13:52 -0600 | [diff] [blame] | 171 | if (!pipe->IsGraphicsLibrary()) { |
| 172 | bool replace_shaders = false; |
| 173 | if (pipe->active_slots.find(object_ptr->desc_set_bind_index) != pipe->active_slots.end()) { |
| 174 | replace_shaders = true; |
| 175 | } |
| 176 | // If the app requests all available sets, the pipeline layout was not modified at pipeline layout creation and the |
| 177 | // already instrumented shaders need to be replaced with uninstrumented shaders |
| 178 | const auto pipeline_layout = pipe->PipelineLayoutState(); |
| 179 | if (pipeline_layout->set_layouts.size() >= object_ptr->adjusted_max_desc_sets) { |
| 180 | replace_shaders = true; |
| 181 | } |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 182 | |
Nathaniel Cesario | bcb7968 | 2022-03-31 21:13:52 -0600 | [diff] [blame] | 183 | if (replace_shaders) { |
| 184 | for (uint32_t stage = 0; stage < stageCount; ++stage) { |
| 185 | const auto module_state = |
| 186 | object_ptr->template Get<SHADER_MODULE_STATE>(Accessor::GetShaderModule(pCreateInfos[pipeline], stage)); |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 187 | |
Nathaniel Cesario | bcb7968 | 2022-03-31 21:13:52 -0600 | [diff] [blame] | 188 | VkShaderModule shader_module; |
| 189 | auto create_info = LvlInitStruct<VkShaderModuleCreateInfo>(); |
| 190 | create_info.pCode = module_state->words.data(); |
| 191 | create_info.codeSize = module_state->words.size() * sizeof(uint32_t); |
| 192 | VkResult result = DispatchCreateShaderModule(object_ptr->device, &create_info, pAllocator, &shader_module); |
| 193 | if (result == VK_SUCCESS) { |
| 194 | Accessor::SetShaderModule(&(*new_pipeline_create_infos)[pipeline], shader_module, stage); |
| 195 | } else { |
| 196 | object_ptr->ReportSetupProblem(object_ptr->device, |
| 197 | "Unable to replace instrumented shader with non-instrumented one. " |
| 198 | "Device could become unstable."); |
| 199 | } |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | // For every pipeline: |
| 206 | // - For every shader in a pipeline: |
| 207 | // - If the shader had to be replaced in PreCallRecord (because the pipeline is using the debug desc set index): |
| 208 | // - Destroy it since it has been bound into the pipeline by now. This is our only chance to delete it. |
| 209 | // - Track the shader in the shader_map |
| 210 | // - Save the shader binary if it contains debug code |
| 211 | template <typename CreateInfo, typename ObjectType> |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 212 | void UtilPostCallRecordPipelineCreations(const uint32_t count, const CreateInfo *pCreateInfos, |
aitor-lunarg | 3c14529 | 2022-03-25 17:30:11 +0100 | [diff] [blame] | 213 | const VkAllocationCallbacks *pAllocator, const VkPipeline *pPipelines, |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 214 | const VkPipelineBindPoint bind_point, ObjectType *object_ptr) { |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 215 | using Accessor = CreatePipelineTraits<CreateInfo>; |
| 216 | if (bind_point != VK_PIPELINE_BIND_POINT_GRAPHICS && bind_point != VK_PIPELINE_BIND_POINT_COMPUTE && |
| 217 | bind_point != VK_PIPELINE_BIND_POINT_RAY_TRACING_NV) { |
| 218 | return; |
| 219 | } |
| 220 | for (uint32_t pipeline = 0; pipeline < count; ++pipeline) { |
Jeremy Gebben | b20a824 | 2021-11-05 15:14:43 -0600 | [diff] [blame] | 221 | auto pipeline_state = object_ptr->template Get<PIPELINE_STATE>(pPipelines[pipeline]); |
Nathaniel Cesario | bcb7968 | 2022-03-31 21:13:52 -0600 | [diff] [blame] | 222 | if (!pipeline_state || pipeline_state->IsGraphicsLibrary()) continue; |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 223 | |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 224 | const uint32_t stageCount = static_cast<uint32_t>(pipeline_state->stage_state.size()); |
| 225 | assert(stageCount > 0); |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 226 | |
| 227 | for (uint32_t stage = 0; stage < stageCount; ++stage) { |
| 228 | if (pipeline_state->active_slots.find(object_ptr->desc_set_bind_index) != pipeline_state->active_slots.end()) { |
| 229 | DispatchDestroyShaderModule(object_ptr->device, Accessor::GetShaderModule(pCreateInfos[pipeline], stage), |
| 230 | pAllocator); |
| 231 | } |
| 232 | |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 233 | std::shared_ptr<const SHADER_MODULE_STATE> module_state; |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 234 | if (bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 235 | module_state = object_ptr->template Get<SHADER_MODULE_STATE>( |
| 236 | pipeline_state->GetUnifiedCreateInfo().graphics.pStages[stage].module); |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 237 | } else if (bind_point == VK_PIPELINE_BIND_POINT_COMPUTE) { |
| 238 | assert(stage == 0); |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 239 | module_state = |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 240 | object_ptr->template Get<SHADER_MODULE_STATE>(pipeline_state->GetUnifiedCreateInfo().compute.stage.module); |
| 241 | } else if (bind_point == VK_PIPELINE_BIND_POINT_RAY_TRACING_NV) { |
| 242 | module_state = object_ptr->template Get<SHADER_MODULE_STATE>( |
| 243 | pipeline_state->GetUnifiedCreateInfo().raytracing.pStages[stage].module); |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 244 | } else { |
| 245 | assert(false); |
| 246 | } |
| 247 | |
| 248 | std::vector<unsigned int> code; |
| 249 | // Save the shader binary |
| 250 | // The core_validation ShaderModule tracker saves the binary too, but discards it when the ShaderModule |
| 251 | // is destroyed. Applications may destroy ShaderModules after they are placed in a pipeline and before |
| 252 | // the pipeline is used, so we have to keep another copy. |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 253 | if (module_state && module_state->has_valid_spirv) code = module_state->words; |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 254 | |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 255 | object_ptr->shader_map[module_state->gpu_validation_shader_id].pipeline = pipeline_state->pipeline(); |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 256 | // Be careful to use the originally bound (instrumented) shader here, even if PreCallRecord had to back it |
| 257 | // out with a non-instrumented shader. The non-instrumented shader (found in pCreateInfo) was destroyed above. |
| 258 | VkShaderModule shader_module = VK_NULL_HANDLE; |
| 259 | if (bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 260 | shader_module = pipeline_state->GetUnifiedCreateInfo().graphics.pStages[stage].module; |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 261 | } else if (bind_point == VK_PIPELINE_BIND_POINT_COMPUTE) { |
| 262 | assert(stage == 0); |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 263 | shader_module = pipeline_state->GetUnifiedCreateInfo().compute.stage.module; |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 264 | } else if (bind_point == VK_PIPELINE_BIND_POINT_RAY_TRACING_NV) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 265 | shader_module = pipeline_state->GetUnifiedCreateInfo().raytracing.pStages[stage].module; |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 266 | } else { |
| 267 | assert(false); |
| 268 | } |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 269 | object_ptr->shader_map[module_state->gpu_validation_shader_id].shader_module = shader_module; |
| 270 | object_ptr->shader_map[module_state->gpu_validation_shader_id].pgm = std::move(code); |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | } |
Tony-LunarG | c876c6e | 2020-09-09 15:19:43 -0600 | [diff] [blame] | 274 | template <typename CreateInfos, typename SafeCreateInfos> |
| 275 | void UtilCopyCreatePipelineFeedbackData(const uint32_t count, CreateInfos *pCreateInfos, SafeCreateInfos *pSafeCreateInfos) { |
| 276 | for (uint32_t i = 0; i < count; i++) { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 277 | auto src_feedback_struct = LvlFindInChain<VkPipelineCreationFeedbackCreateInfoEXT>(pSafeCreateInfos[i].pNext); |
Tony-LunarG | c876c6e | 2020-09-09 15:19:43 -0600 | [diff] [blame] | 278 | if (!src_feedback_struct) return; |
| 279 | auto dst_feedback_struct = const_cast<VkPipelineCreationFeedbackCreateInfoEXT *>( |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 280 | LvlFindInChain<VkPipelineCreationFeedbackCreateInfoEXT>(pCreateInfos[i].pNext)); |
Tony-LunarG | c876c6e | 2020-09-09 15:19:43 -0600 | [diff] [blame] | 281 | *dst_feedback_struct->pPipelineCreationFeedback = *src_feedback_struct->pPipelineCreationFeedback; |
| 282 | for (uint32_t j = 0; j < src_feedback_struct->pipelineStageCreationFeedbackCount; j++) { |
| 283 | dst_feedback_struct->pPipelineStageCreationFeedbacks[j] = src_feedback_struct->pPipelineStageCreationFeedbacks[j]; |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
Jeremy Gebben | fcfc33c | 2022-03-28 15:31:29 -0600 | [diff] [blame^] | 288 | VkResult UtilInitializeVma(VkPhysicalDevice physical_device, VkDevice device, VmaAllocator *pAllocator); |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 289 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 290 | void UtilGenerateStageMessage(const uint32_t *debug_record, std::string &msg); |
| 291 | void UtilGenerateCommonMessage(const debug_report_data *report_data, const VkCommandBuffer commandBuffer, |
| 292 | const uint32_t *debug_record, const VkShaderModule shader_module_handle, |
| 293 | const VkPipeline pipeline_handle, const VkPipelineBindPoint pipeline_bind_point, |
| 294 | const uint32_t operation_index, std::string &msg); |
sfricke-samsung | 7fac88a | 2022-01-26 11:44:22 -0800 | [diff] [blame] | 295 | void UtilGenerateSourceMessages(const std::vector<uint32_t> &pgm, const uint32_t *debug_record, bool from_printf, |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 296 | std::string &filename_msg, std::string &source_msg); |
Jeremy Gebben | 5160e03 | 2022-03-28 14:57:43 -0600 | [diff] [blame] | 297 | |
| 298 | struct GpuAssistedShaderTracker { |
| 299 | VkPipeline pipeline; |
| 300 | VkShaderModule shader_module; |
| 301 | std::vector<uint32_t> pgm; |
| 302 | }; |
| 303 | |
| 304 | class GpuAssistedBase : public ValidationStateTracker { |
| 305 | public: |
Jeremy Gebben | 3371786 | 2022-03-28 15:53:56 -0600 | [diff] [blame] | 306 | void PreCallRecordCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, |
| 307 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, void *modified_create_info) override; |
| 308 | void CreateDevice(const VkDeviceCreateInfo *pCreateInfo) override; |
| 309 | |
| 310 | void PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) override; |
| 311 | |
Jeremy Gebben | fcfc33c | 2022-03-28 15:31:29 -0600 | [diff] [blame^] | 312 | void PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, VkFence fence, |
| 313 | VkResult result) override; |
| 314 | void RecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits, VkFence fence, VkResult result); |
| 315 | void PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits, VkFence fence, |
| 316 | VkResult result) override; |
| 317 | void PostCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2 *pSubmits, VkFence fence, |
| 318 | VkResult result) override; |
Jeremy Gebben | 3371786 | 2022-03-28 15:53:56 -0600 | [diff] [blame] | 319 | template <typename T> |
| 320 | void ReportSetupProblem(T object, const char *const specific_message) const { |
| 321 | LogError(object, setup_vuid, "Setup Error. Detail: (%s)", specific_message); |
| 322 | } |
| 323 | |
Jeremy Gebben | fcfc33c | 2022-03-28 15:31:29 -0600 | [diff] [blame^] | 324 | protected: |
| 325 | virtual bool CommandBufferNeedsProcessing(VkCommandBuffer command_buffer) = 0; |
| 326 | virtual void ProcessCommandBuffer(VkQueue queue, VkCommandBuffer command_buffer) = 0; |
| 327 | |
| 328 | void SubmitBarrier(VkQueue queue) { |
| 329 | auto queue_state = Get<gpu_utils_state::Queue>(queue); |
| 330 | if (queue_state) { |
| 331 | queue_state->SubmitBarrier(); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | std::shared_ptr<QUEUE_STATE> CreateQueue(VkQueue q, uint32_t index, VkDeviceQueueCreateFlags flags) override { |
| 336 | return std::static_pointer_cast<QUEUE_STATE>(std::make_shared<gpu_utils_state::Queue>(*this, q, index, flags)); |
| 337 | } |
| 338 | |
| 339 | public: |
Jeremy Gebben | 5160e03 | 2022-03-28 14:57:43 -0600 | [diff] [blame] | 340 | bool aborted = false; |
Jeremy Gebben | fcfc33c | 2022-03-28 15:31:29 -0600 | [diff] [blame^] | 341 | PFN_vkSetDeviceLoaderData vkSetDeviceLoaderData; |
Jeremy Gebben | 5160e03 | 2022-03-28 14:57:43 -0600 | [diff] [blame] | 342 | const char *setup_vuid; |
| 343 | VkPhysicalDeviceFeatures supported_features{}; |
| 344 | VkPhysicalDeviceFeatures desired_features{}; |
| 345 | uint32_t adjusted_max_desc_sets = 0; |
| 346 | uint32_t unique_shader_module_id = 0; |
| 347 | uint32_t output_buffer_size = 0; |
| 348 | VkDescriptorSetLayout debug_desc_layout = VK_NULL_HANDLE; |
| 349 | VkDescriptorSetLayout dummy_desc_layout = VK_NULL_HANDLE; |
| 350 | uint32_t desc_set_bind_index = 0; |
| 351 | VmaAllocator vmaAllocator = {}; |
Jeremy Gebben | 5160e03 | 2022-03-28 14:57:43 -0600 | [diff] [blame] | 352 | std::unique_ptr<UtilDescriptorSetManager> desc_set_manager; |
Jeremy Gebben | 5160e03 | 2022-03-28 14:57:43 -0600 | [diff] [blame] | 353 | layer_data::unordered_map<uint32_t, GpuAssistedShaderTracker> shader_map; |
| 354 | std::vector<VkDescriptorSetLayoutBinding> bindings_; |
| 355 | }; |
| 356 | |