Tony-LunarG | 4c25337 | 2022-01-18 13:51:07 -0700 | [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 | 0471752 | 2019-10-17 10:41:17 -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 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 20 | #include "debug_printf.h" |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 21 | #include "spirv-tools/optimizer.hpp" |
| 22 | #include "spirv-tools/instrument.hpp" |
| 23 | #include <iostream> |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 24 | #include "layer_chassis_dispatch.h" |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 25 | #include "sync_utils.h" |
Jeremy Gebben | 159b3cc | 2021-06-03 09:09:03 -0600 | [diff] [blame] | 26 | #include "cmd_buffer_state.h" |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 27 | |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 28 | static const VkShaderStageFlags kShaderStageAllRayTracing = |
| 29 | VK_SHADER_STAGE_ANY_HIT_BIT_NV | VK_SHADER_STAGE_CALLABLE_BIT_NV | VK_SHADER_STAGE_CLOSEST_HIT_BIT_NV | |
| 30 | VK_SHADER_STAGE_INTERSECTION_BIT_NV | VK_SHADER_STAGE_MISS_BIT_NV | VK_SHADER_STAGE_RAYGEN_BIT_NV; |
| 31 | |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 32 | // Perform initializations that can be done at Create Device time. |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 33 | void DebugPrintf::CreateDevice(const VkDeviceCreateInfo *pCreateInfo) { |
Jeremy Gebben | 3371786 | 2022-03-28 15:53:56 -0600 | [diff] [blame^] | 34 | if (enabled[gpu_validation]) { |
| 35 | ReportSetupProblem(device, |
| 36 | "Debug Printf cannot be enabled when gpu assisted validation is enabled. " |
| 37 | "Debug Printf disabled."); |
| 38 | aborted = true; |
| 39 | return; |
| 40 | } |
Tony-LunarG | 43416b4 | 2019-10-31 16:47:24 -0600 | [diff] [blame] | 41 | |
| 42 | const char *size_string = getLayerOption("khronos_validation.printf_buffer_size"); |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 43 | output_buffer_size = *size_string ? atoi(size_string) : 1024; |
Tony-LunarG | c99dbef | 2021-06-14 15:11:50 -0600 | [diff] [blame] | 44 | |
| 45 | std::string verbose_string = getLayerOption("khronos_validation.printf_verbose"); |
| 46 | transform(verbose_string.begin(), verbose_string.end(), verbose_string.begin(), ::tolower); |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 47 | verbose = verbose_string.length() ? !verbose_string.compare("true") : false; |
Tony-LunarG | c99dbef | 2021-06-14 15:11:50 -0600 | [diff] [blame] | 48 | |
| 49 | std::string stdout_string = getLayerOption("khronos_validation.printf_to_stdout"); |
| 50 | transform(stdout_string.begin(), stdout_string.end(), stdout_string.begin(), ::tolower); |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 51 | use_stdout = stdout_string.length() ? !stdout_string.compare("true") : false; |
| 52 | if (getenv("DEBUG_PRINTF_TO_STDOUT")) use_stdout = true; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 53 | |
Jeremy Gebben | 3371786 | 2022-03-28 15:53:56 -0600 | [diff] [blame^] | 54 | // GpuAssistedBase::CreateDevice will set up bindings |
| 55 | VkDescriptorSetLayoutBinding binding = {3, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, |
| 56 | VK_SHADER_STAGE_ALL_GRAPHICS | VK_SHADER_STAGE_MESH_BIT_NV | |
| 57 | VK_SHADER_STAGE_TASK_BIT_NV | VK_SHADER_STAGE_COMPUTE_BIT | |
| 58 | kShaderStageAllRayTracing, |
| 59 | NULL}; |
| 60 | bindings_.push_back(binding); |
| 61 | |
| 62 | GpuAssistedBase::CreateDevice(pCreateInfo); |
| 63 | |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 64 | if (phys_dev_props.apiVersion < VK_API_VERSION_1_1) { |
Tony-LunarG | bbbed67 | 2020-03-04 10:51:11 -0700 | [diff] [blame] | 65 | ReportSetupProblem(device, "Debug Printf requires Vulkan 1.1 or later. Debug Printf disabled."); |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 66 | aborted = true; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 67 | return; |
| 68 | } |
| 69 | |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 70 | DispatchGetPhysicalDeviceFeatures(physical_device, &supported_features); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 71 | if (!supported_features.fragmentStoresAndAtomics || !supported_features.vertexPipelineStoresAndAtomics) { |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 72 | ReportSetupProblem(device, |
Tony-LunarG | bbbed67 | 2020-03-04 10:51:11 -0700 | [diff] [blame] | 73 | "Debug Printf requires fragmentStoresAndAtomics and vertexPipelineStoresAndAtomics. " |
| 74 | "Debug Printf disabled."); |
Jeremy Gebben | 36a3b83 | 2022-03-23 10:54:18 -0600 | [diff] [blame] | 75 | aborted = true; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 76 | return; |
| 77 | } |
Tony-LunarG | 9586e73 | 2020-03-04 10:50:30 -0700 | [diff] [blame] | 78 | |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | // Modify the pipeline layout to include our debug descriptor set and any needed padding with the dummy descriptor set. |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 82 | void DebugPrintf::PreCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo, |
| 83 | const VkAllocationCallbacks *pAllocator, VkPipelineLayout *pPipelineLayout, |
| 84 | void *cpl_state_data) { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 85 | if (aborted) { |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | create_pipeline_layout_api_state *cpl_state = reinterpret_cast<create_pipeline_layout_api_state *>(cpl_state_data); |
| 90 | |
| 91 | if (cpl_state->modified_create_info.setLayoutCount >= adjusted_max_desc_sets) { |
| 92 | std::ostringstream strm; |
| 93 | strm << "Pipeline Layout conflict with validation's descriptor set at slot " << desc_set_bind_index << ". " |
Tony-LunarG | bbbed67 | 2020-03-04 10:51:11 -0700 | [diff] [blame] | 94 | << "Application has too many descriptor sets in the pipeline layout to continue with debug printf. " |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 95 | << "Not modifying the pipeline layout. " |
| 96 | << "Instrumented shaders are replaced with non-instrumented shaders."; |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 97 | ReportSetupProblem(device, strm.str().c_str()); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 98 | } else { |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 99 | UtilPreCallRecordCreatePipelineLayout(cpl_state, this, pCreateInfo); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 103 | void DebugPrintf::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo, |
| 104 | const VkAllocationCallbacks *pAllocator, VkPipelineLayout *pPipelineLayout, |
| 105 | VkResult result) { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 106 | ValidationStateTracker::PostCallRecordCreatePipelineLayout(device, pCreateInfo, pAllocator, pPipelineLayout, result); |
| 107 | if (result != VK_SUCCESS) { |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 108 | ReportSetupProblem(device, "Unable to create pipeline layout. Device could become unstable."); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 109 | aborted = true; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | // Free the device memory and descriptor set associated with a command buffer. |
Jeremy Gebben | f6bb4bb | 2021-08-11 15:41:09 -0600 | [diff] [blame] | 114 | void DebugPrintf::DestroyBuffer(DPFBufferInfo &buffer_info) { |
| 115 | vmaDestroyBuffer(vmaAllocator, buffer_info.output_mem_block.buffer, buffer_info.output_mem_block.allocation); |
| 116 | if (buffer_info.desc_set != VK_NULL_HANDLE) { |
| 117 | desc_set_manager->PutBackDescriptorSet(buffer_info.desc_pool, buffer_info.desc_set); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 118 | } |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | // Just gives a warning about a possible deadlock. |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 122 | bool DebugPrintf::PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 123 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 124 | uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, |
| 125 | uint32_t bufferMemoryBarrierCount, |
| 126 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, |
| 127 | const VkImageMemoryBarrier *pImageMemoryBarriers) const { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 128 | if (srcStageMask & VK_PIPELINE_STAGE_HOST_BIT) { |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 129 | ReportSetupProblem(commandBuffer, |
| 130 | "CmdWaitEvents recorded with VK_PIPELINE_STAGE_HOST_BIT set. " |
Tony-LunarG | bbbed67 | 2020-03-04 10:51:11 -0700 | [diff] [blame] | 131 | "Debug Printf waits on queue completion. " |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 132 | "This wait could block the host's signaling of this event, resulting in deadlock."); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 133 | } |
| 134 | return false; |
| 135 | } |
| 136 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 137 | bool DebugPrintf::PreCallValidateCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 138 | const VkDependencyInfoKHR *pDependencyInfos) const { |
Jeremy Gebben | f18d436 | 2022-01-27 14:37:25 -0700 | [diff] [blame] | 139 | VkPipelineStageFlags2KHR src_stage_mask = 0; |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 140 | |
| 141 | for (uint32_t i = 0; i < eventCount; i++) { |
| 142 | auto stage_masks = sync_utils::GetGlobalStageMasks(pDependencyInfos[i]); |
Jeremy Gebben | f18d436 | 2022-01-27 14:37:25 -0700 | [diff] [blame] | 143 | src_stage_mask |= stage_masks.src; |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Jeremy Gebben | f18d436 | 2022-01-27 14:37:25 -0700 | [diff] [blame] | 146 | if (src_stage_mask & VK_PIPELINE_STAGE_HOST_BIT) { |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 147 | ReportSetupProblem(commandBuffer, |
| 148 | "CmdWaitEvents2KHR recorded with VK_PIPELINE_STAGE_HOST_BIT set. " |
| 149 | "Debug Printf waits on queue completion. " |
| 150 | "This wait could block the host's signaling of this event, resulting in deadlock."); |
| 151 | } |
| 152 | return false; |
| 153 | } |
| 154 | |
Tony-LunarG | 1364cf5 | 2021-11-17 16:10:11 -0700 | [diff] [blame] | 155 | bool DebugPrintf::PreCallValidateCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents, |
| 156 | const VkDependencyInfo *pDependencyInfos) const { |
Jeremy Gebben | f18d436 | 2022-01-27 14:37:25 -0700 | [diff] [blame] | 157 | VkPipelineStageFlags2 src_stage_mask = 0; |
Tony-LunarG | 1364cf5 | 2021-11-17 16:10:11 -0700 | [diff] [blame] | 158 | |
| 159 | for (uint32_t i = 0; i < eventCount; i++) { |
| 160 | auto stage_masks = sync_utils::GetGlobalStageMasks(pDependencyInfos[i]); |
Jeremy Gebben | f18d436 | 2022-01-27 14:37:25 -0700 | [diff] [blame] | 161 | src_stage_mask |= stage_masks.src; |
Tony-LunarG | 1364cf5 | 2021-11-17 16:10:11 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Jeremy Gebben | f18d436 | 2022-01-27 14:37:25 -0700 | [diff] [blame] | 164 | if (src_stage_mask & VK_PIPELINE_STAGE_HOST_BIT) { |
Tony-LunarG | 1364cf5 | 2021-11-17 16:10:11 -0700 | [diff] [blame] | 165 | ReportSetupProblem(commandBuffer, |
| 166 | "CmdWaitEvents2 recorded with VK_PIPELINE_STAGE_HOST_BIT set. " |
| 167 | "Debug Printf waits on queue completion. " |
| 168 | "This wait could block the host's signaling of this event, resulting in deadlock."); |
| 169 | } |
| 170 | return false; |
| 171 | } |
| 172 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 173 | void DebugPrintf::PreCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 174 | const VkGraphicsPipelineCreateInfo *pCreateInfos, |
| 175 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
| 176 | void *cgpl_state_data) { |
Tony-LunarG | 00e7b7d | 2021-06-30 12:59:43 -0600 | [diff] [blame] | 177 | if (aborted) return; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 178 | std::vector<safe_VkGraphicsPipelineCreateInfo> new_pipeline_create_infos; |
| 179 | create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data); |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 180 | UtilPreCallRecordPipelineCreations(count, pCreateInfos, pAllocator, pPipelines, cgpl_state->pipe_state, |
| 181 | &new_pipeline_create_infos, VK_PIPELINE_BIND_POINT_GRAPHICS, this); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 182 | cgpl_state->printf_create_infos = new_pipeline_create_infos; |
| 183 | cgpl_state->pCreateInfos = reinterpret_cast<VkGraphicsPipelineCreateInfo *>(cgpl_state->printf_create_infos.data()); |
| 184 | } |
| 185 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 186 | void DebugPrintf::PreCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 187 | const VkComputePipelineCreateInfo *pCreateInfos, |
| 188 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
| 189 | void *ccpl_state_data) { |
Tony-LunarG | 00e7b7d | 2021-06-30 12:59:43 -0600 | [diff] [blame] | 190 | if (aborted) return; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 191 | std::vector<safe_VkComputePipelineCreateInfo> new_pipeline_create_infos; |
| 192 | auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data); |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 193 | UtilPreCallRecordPipelineCreations(count, pCreateInfos, pAllocator, pPipelines, ccpl_state->pipe_state, |
| 194 | &new_pipeline_create_infos, VK_PIPELINE_BIND_POINT_COMPUTE, this); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 195 | ccpl_state->printf_create_infos = new_pipeline_create_infos; |
Tony-LunarG | 9b9dc02 | 2020-10-08 13:55:37 -0600 | [diff] [blame] | 196 | ccpl_state->pCreateInfos = reinterpret_cast<VkComputePipelineCreateInfo *>(ccpl_state->printf_create_infos.data()); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 197 | } |
| 198 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 199 | void DebugPrintf::PreCallRecordCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 200 | const VkRayTracingPipelineCreateInfoNV *pCreateInfos, |
| 201 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
| 202 | void *crtpl_state_data) { |
Tony-LunarG | 00e7b7d | 2021-06-30 12:59:43 -0600 | [diff] [blame] | 203 | if (aborted) return; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 204 | std::vector<safe_VkRayTracingPipelineCreateInfoCommon> new_pipeline_create_infos; |
| 205 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data); |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 206 | UtilPreCallRecordPipelineCreations(count, pCreateInfos, pAllocator, pPipelines, crtpl_state->pipe_state, |
| 207 | &new_pipeline_create_infos, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV, this); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 208 | crtpl_state->printf_create_infos = new_pipeline_create_infos; |
Tony-LunarG | 9b9dc02 | 2020-10-08 13:55:37 -0600 | [diff] [blame] | 209 | crtpl_state->pCreateInfos = reinterpret_cast<VkRayTracingPipelineCreateInfoNV *>(crtpl_state->printf_create_infos.data()); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 210 | } |
| 211 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 212 | void DebugPrintf::PreCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation, |
| 213 | VkPipelineCache pipelineCache, uint32_t count, |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 214 | const VkRayTracingPipelineCreateInfoKHR *pCreateInfos, |
| 215 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
| 216 | void *crtpl_state_data) { |
Tony-LunarG | 00e7b7d | 2021-06-30 12:59:43 -0600 | [diff] [blame] | 217 | if (aborted) return; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 218 | std::vector<safe_VkRayTracingPipelineCreateInfoCommon> new_pipeline_create_infos; |
| 219 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data); |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 220 | UtilPreCallRecordPipelineCreations(count, pCreateInfos, pAllocator, pPipelines, crtpl_state->pipe_state, |
| 221 | &new_pipeline_create_infos, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, this); |
Tony-LunarG | 9b9dc02 | 2020-10-08 13:55:37 -0600 | [diff] [blame] | 222 | crtpl_state->printf_create_infos = new_pipeline_create_infos; |
| 223 | crtpl_state->pCreateInfos = reinterpret_cast<VkRayTracingPipelineCreateInfoKHR *>(crtpl_state->printf_create_infos.data()); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 224 | } |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 225 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 226 | void DebugPrintf::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 227 | const VkGraphicsPipelineCreateInfo *pCreateInfos, |
| 228 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
| 229 | VkResult result, void *cgpl_state_data) { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 230 | ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pAllocator, |
| 231 | pPipelines, result, cgpl_state_data); |
Tony-LunarG | 00e7b7d | 2021-06-30 12:59:43 -0600 | [diff] [blame] | 232 | if (aborted) return; |
Tony-LunarG | c876c6e | 2020-09-09 15:19:43 -0600 | [diff] [blame] | 233 | create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data); |
| 234 | UtilCopyCreatePipelineFeedbackData(count, pCreateInfos, cgpl_state->printf_create_infos.data()); |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 235 | UtilPostCallRecordPipelineCreations(count, pCreateInfos, pAllocator, pPipelines, VK_PIPELINE_BIND_POINT_GRAPHICS, this); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 236 | } |
| 237 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 238 | void DebugPrintf::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 239 | const VkComputePipelineCreateInfo *pCreateInfos, |
| 240 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
| 241 | VkResult result, void *ccpl_state_data) { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 242 | ValidationStateTracker::PostCallRecordCreateComputePipelines(device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines, |
| 243 | result, ccpl_state_data); |
Tony-LunarG | 00e7b7d | 2021-06-30 12:59:43 -0600 | [diff] [blame] | 244 | if (aborted) return; |
Tony-LunarG | c876c6e | 2020-09-09 15:19:43 -0600 | [diff] [blame] | 245 | create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data); |
| 246 | UtilCopyCreatePipelineFeedbackData(count, pCreateInfos, ccpl_state->printf_create_infos.data()); |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 247 | UtilPostCallRecordPipelineCreations(count, pCreateInfos, pAllocator, pPipelines, VK_PIPELINE_BIND_POINT_COMPUTE, this); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 248 | } |
| 249 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 250 | void DebugPrintf::PostCallRecordCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 251 | const VkRayTracingPipelineCreateInfoNV *pCreateInfos, |
| 252 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
| 253 | VkResult result, void *crtpl_state_data) { |
Tony-LunarG | c876c6e | 2020-09-09 15:19:43 -0600 | [diff] [blame] | 254 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 255 | ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(device, pipelineCache, count, pCreateInfos, pAllocator, |
| 256 | pPipelines, result, crtpl_state_data); |
Tony-LunarG | 00e7b7d | 2021-06-30 12:59:43 -0600 | [diff] [blame] | 257 | if (aborted) return; |
Tony-LunarG | 9b9dc02 | 2020-10-08 13:55:37 -0600 | [diff] [blame] | 258 | UtilCopyCreatePipelineFeedbackData(count, pCreateInfos, crtpl_state->printf_create_infos.data()); |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 259 | UtilPostCallRecordPipelineCreations(count, pCreateInfos, pAllocator, pPipelines, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV, this); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 260 | } |
| 261 | |
Tony-LunarG | fb2ab87 | 2021-01-13 15:17:15 -0700 | [diff] [blame] | 262 | void DebugPrintf::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation, |
| 263 | VkPipelineCache pipelineCache, uint32_t count, |
| 264 | const VkRayTracingPipelineCreateInfoKHR *pCreateInfos, |
| 265 | const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, |
| 266 | VkResult result, void *crtpl_state_data) { |
| 267 | auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data); |
| 268 | ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR( |
| 269 | device, deferredOperation, pipelineCache, count, pCreateInfos, pAllocator, pPipelines, result, crtpl_state_data); |
Tony-LunarG | 00e7b7d | 2021-06-30 12:59:43 -0600 | [diff] [blame] | 270 | if (aborted) return; |
Tony-LunarG | fb2ab87 | 2021-01-13 15:17:15 -0700 | [diff] [blame] | 271 | UtilCopyCreatePipelineFeedbackData(count, pCreateInfos, crtpl_state->printf_create_infos.data()); |
aitor-lunarg | 3c14529 | 2022-03-25 17:30:11 +0100 | [diff] [blame] | 272 | |
| 273 | bool is_operation_deferred = (deferredOperation != VK_NULL_HANDLE && result == VK_OPERATION_DEFERRED_KHR); |
| 274 | if (is_operation_deferred) { |
| 275 | std::vector<safe_VkRayTracingPipelineCreateInfoKHR> infos{pCreateInfos, pCreateInfos + count}; |
| 276 | auto register_fn = [this, infos, pAllocator](const std::vector<VkPipeline> &pipelines) { |
| 277 | UtilPostCallRecordPipelineCreations(static_cast<uint32_t>(infos.size()), |
| 278 | reinterpret_cast<const VkRayTracingPipelineCreateInfoKHR *>(infos.data()), |
| 279 | pAllocator, pipelines.data(), VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, this); |
| 280 | }; |
| 281 | |
| 282 | auto layer_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| 283 | if (wrap_handles) { |
| 284 | deferredOperation = layer_data->Unwrap(deferredOperation); |
| 285 | } |
| 286 | std::vector<std::function<void(const std::vector<VkPipeline> &)>> cleanup_fn; |
| 287 | auto find_res = layer_data->deferred_operation_post_check.pop(deferredOperation); |
| 288 | if (find_res->first) { |
| 289 | cleanup_fn = std::move(find_res->second); |
| 290 | } |
| 291 | cleanup_fn.emplace_back(register_fn); |
| 292 | layer_data->deferred_operation_post_check.insert(deferredOperation, cleanup_fn); |
| 293 | } else { |
| 294 | UtilPostCallRecordPipelineCreations(count, pCreateInfos, pAllocator, pPipelines, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, |
| 295 | this); |
| 296 | } |
Tony-LunarG | fb2ab87 | 2021-01-13 15:17:15 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 299 | // Remove all the shader trackers associated with this destroyed pipeline. |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 300 | void DebugPrintf::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks *pAllocator) { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 301 | for (auto it = shader_map.begin(); it != shader_map.end();) { |
| 302 | if (it->second.pipeline == pipeline) { |
| 303 | it = shader_map.erase(it); |
| 304 | } else { |
| 305 | ++it; |
| 306 | } |
| 307 | } |
| 308 | ValidationStateTracker::PreCallRecordDestroyPipeline(device, pipeline, pAllocator); |
| 309 | } |
| 310 | // Call the SPIR-V Optimizer to run the instrumentation pass on the shader. |
sfricke-samsung | 7fac88a | 2022-01-26 11:44:22 -0800 | [diff] [blame] | 311 | bool DebugPrintf::InstrumentShader(const VkShaderModuleCreateInfo *pCreateInfo, std::vector<uint32_t> &new_pgm, |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 312 | uint32_t *unique_shader_id) { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 313 | if (aborted) return false; |
| 314 | if (pCreateInfo->pCode[0] != spv::MagicNumber) return false; |
| 315 | |
| 316 | // Load original shader SPIR-V |
| 317 | uint32_t num_words = static_cast<uint32_t>(pCreateInfo->codeSize / 4); |
| 318 | new_pgm.clear(); |
| 319 | new_pgm.reserve(num_words); |
| 320 | new_pgm.insert(new_pgm.end(), &pCreateInfo->pCode[0], &pCreateInfo->pCode[num_words]); |
| 321 | |
| 322 | // Call the optimizer to instrument the shader. |
| 323 | // Use the unique_shader_module_id as a shader ID so we can look up its handle later in the shader_map. |
| 324 | // If descriptor indexing is enabled, enable length checks and updated descriptor checks |
| 325 | using namespace spvtools; |
sfricke-samsung | 45996a4 | 2021-09-16 13:45:27 -0700 | [diff] [blame] | 326 | spv_target_env target_env = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4)); |
Tony-LunarG | f29f77f | 2020-08-26 15:48:00 -0600 | [diff] [blame] | 327 | spvtools::ValidatorOptions val_options; |
| 328 | AdjustValidatorOptions(device_extensions, enabled_features, val_options); |
| 329 | spvtools::OptimizerOptions opt_options; |
| 330 | opt_options.set_run_validator(true); |
| 331 | opt_options.set_validator_options(val_options); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 332 | Optimizer optimizer(target_env); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 333 | const spvtools::MessageConsumer debug_printf_console_message_consumer = |
Tony-LunarG | 7964170 | 2020-07-13 15:43:05 -0600 | [diff] [blame] | 334 | [this](spv_message_level_t level, const char *, const spv_position_t &position, const char *message) -> void { |
| 335 | switch (level) { |
| 336 | case SPV_MSG_FATAL: |
| 337 | case SPV_MSG_INTERNAL_ERROR: |
| 338 | case SPV_MSG_ERROR: |
| 339 | this->LogError(this->device, "UNASSIGNED-Debug-Printf", "Error during shader instrumentation: line %zu: %s", |
| 340 | position.index, message); |
| 341 | break; |
| 342 | default: |
| 343 | break; |
| 344 | } |
| 345 | }; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 346 | optimizer.SetMessageConsumer(debug_printf_console_message_consumer); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 347 | optimizer.RegisterPass(CreateInstDebugPrintfPass(desc_set_bind_index, unique_shader_module_id)); |
Tony-LunarG | f29f77f | 2020-08-26 15:48:00 -0600 | [diff] [blame] | 348 | bool pass = optimizer.Run(new_pgm.data(), new_pgm.size(), &new_pgm, opt_options); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 349 | if (!pass) { |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 350 | ReportSetupProblem(device, "Failure to instrument shader. Proceeding with non-instrumented shader."); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 351 | } |
| 352 | *unique_shader_id = unique_shader_module_id++; |
| 353 | return pass; |
| 354 | } |
| 355 | // Create the instrumented shader data to provide to the driver. |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 356 | void DebugPrintf::PreCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo, |
| 357 | const VkAllocationCallbacks *pAllocator, VkShaderModule *pShaderModule, |
| 358 | void *csm_state_data) { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 359 | create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data); |
| 360 | bool pass = InstrumentShader(pCreateInfo, csm_state->instrumented_pgm, &csm_state->unique_shader_id); |
| 361 | if (pass) { |
| 362 | csm_state->instrumented_create_info.pCode = csm_state->instrumented_pgm.data(); |
sfricke-samsung | 7fac88a | 2022-01-26 11:44:22 -0800 | [diff] [blame] | 363 | csm_state->instrumented_create_info.codeSize = csm_state->instrumented_pgm.size() * sizeof(uint32_t); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 364 | } |
| 365 | } |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 366 | |
| 367 | vartype vartype_lookup(char intype) { |
| 368 | switch (intype) { |
| 369 | case 'd': |
| 370 | case 'i': |
| 371 | return varsigned; |
| 372 | break; |
| 373 | |
| 374 | case 'f': |
| 375 | case 'F': |
| 376 | case 'a': |
| 377 | case 'A': |
| 378 | case 'e': |
| 379 | case 'E': |
| 380 | case 'g': |
| 381 | case 'G': |
| 382 | return varfloat; |
| 383 | break; |
| 384 | |
| 385 | case 'u': |
| 386 | case 'x': |
| 387 | case 'o': |
| 388 | default: |
| 389 | return varunsigned; |
| 390 | break; |
| 391 | } |
| 392 | } |
| 393 | |
Tony-LunarG | a19e31e | 2020-03-30 13:30:29 -0600 | [diff] [blame] | 394 | std::vector<DPFSubstring> DebugPrintf::ParseFormatString(const std::string format_string) { |
| 395 | const char types[] = {'d', 'i', 'o', 'u', 'x', 'X', 'a', 'A', 'e', 'E', 'f', 'F', 'g', 'G', 'v', '\0'}; |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 396 | std::vector<DPFSubstring> parsed_strings; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 397 | size_t pos = 0; |
| 398 | size_t begin = 0; |
| 399 | size_t percent = 0; |
| 400 | |
| 401 | while (begin < format_string.length()) { |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 402 | DPFSubstring substring; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 403 | |
| 404 | // Find a percent sign |
| 405 | pos = percent = format_string.find_first_of('%', pos); |
| 406 | if (pos == std::string::npos) { |
| 407 | // End of the format string Push the rest of the characters |
| 408 | substring.string = format_string.substr(begin, format_string.length()); |
| 409 | substring.needs_value = false; |
| 410 | parsed_strings.push_back(substring); |
| 411 | break; |
| 412 | } |
| 413 | pos++; |
| 414 | if (format_string[pos] == '%') { |
| 415 | pos++; |
| 416 | continue; // %% - skip it |
| 417 | } |
| 418 | // Find the type of the value |
| 419 | pos = format_string.find_first_of(types, pos); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 420 | if (pos == format_string.npos) { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 421 | // This really shouldn't happen with a legal value string |
| 422 | pos = format_string.length(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 423 | } else { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 424 | char tempstring[32]; |
| 425 | int count = 0; |
| 426 | std::string specifier = {}; |
| 427 | |
| 428 | if (format_string[pos] == 'v') { |
| 429 | // Vector must be of size 2, 3, or 4 |
| 430 | // and format %v<size><type> |
| 431 | specifier = format_string.substr(percent, pos - percent); |
| 432 | count = atoi(&format_string[pos + 1]); |
| 433 | pos += 2; |
| 434 | |
| 435 | // skip v<count>, handle long |
| 436 | specifier.push_back(format_string[pos]); |
| 437 | if (format_string[pos + 1] == 'l') { |
| 438 | specifier.push_back('l'); |
| 439 | pos++; |
| 440 | } |
| 441 | |
| 442 | // Take the preceding characters, and the percent through the type |
| 443 | substring.string = format_string.substr(begin, percent - begin); |
| 444 | substring.string += specifier; |
| 445 | substring.needs_value = true; |
| 446 | substring.type = vartype_lookup(specifier.back()); |
| 447 | parsed_strings.push_back(substring); |
| 448 | |
| 449 | // Continue with a comma separated list |
| 450 | sprintf(tempstring, ", %s", specifier.c_str()); |
| 451 | substring.string = tempstring; |
| 452 | for (int i = 0; i < (count - 1); i++) { |
| 453 | parsed_strings.push_back(substring); |
| 454 | } |
| 455 | } else { |
| 456 | // Single non-vector value |
| 457 | if (format_string[pos + 1] == 'l') pos++; // Save long size |
| 458 | substring.string = format_string.substr(begin, pos - begin + 1); |
| 459 | substring.needs_value = true; |
| 460 | substring.type = vartype_lookup(format_string[pos]); |
| 461 | parsed_strings.push_back(substring); |
| 462 | } |
| 463 | begin = pos + 1; |
| 464 | } |
| 465 | } |
| 466 | return parsed_strings; |
| 467 | } |
| 468 | |
sfricke-samsung | 7fac88a | 2022-01-26 11:44:22 -0800 | [diff] [blame] | 469 | std::string DebugPrintf::FindFormatString(std::vector<uint32_t> pgm, uint32_t string_id) { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 470 | std::string format_string; |
sfricke-samsung | ef15e48 | 2022-01-26 11:32:49 -0800 | [diff] [blame] | 471 | SHADER_MODULE_STATE module_state(pgm); |
| 472 | if (module_state.words.size() > 0) { |
| 473 | for (const auto &insn : module_state) { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 474 | if (insn.opcode() == spv::OpString) { |
| 475 | uint32_t offset = insn.offset(); |
| 476 | if (pgm[offset + 1] == string_id) { |
| 477 | format_string = reinterpret_cast<char *>(&pgm[offset + 2]); |
| 478 | break; |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | return format_string; |
| 485 | } |
| 486 | |
Corentin Wallez | 171ac5e | 2020-03-31 16:09:05 +0200 | [diff] [blame] | 487 | // GCC and clang don't like using variables as format strings in sprintf. |
| 488 | // #pragma GCC is recognized by both compilers |
| 489 | #if defined(__GNUC__) || defined(__clang__) |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 490 | #pragma GCC diagnostic push |
| 491 | #pragma GCC diagnostic ignored "-Wformat-security" |
| 492 | #endif |
| 493 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 494 | void snprintf_with_malloc(std::stringstream &shader_message, DPFSubstring substring, size_t needed, void *values) { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 495 | char *buffer = static_cast<char *>(malloc((needed + 1) * sizeof(char))); // Add 1 for terminator |
| 496 | if (substring.longval) { |
| 497 | snprintf(buffer, needed, substring.string.c_str(), substring.longval); |
| 498 | } else if (!substring.needs_value) { |
| 499 | snprintf(buffer, needed, substring.string.c_str()); |
| 500 | } else { |
| 501 | switch (substring.type) { |
| 502 | case varunsigned: |
| 503 | needed = snprintf(buffer, needed, substring.string.c_str(), *static_cast<uint32_t *>(values) - 1); |
| 504 | break; |
| 505 | |
| 506 | case varsigned: |
| 507 | needed = snprintf(buffer, needed, substring.string.c_str(), *static_cast<int32_t *>(values) - 1); |
| 508 | break; |
| 509 | |
| 510 | case varfloat: |
| 511 | needed = snprintf(buffer, needed, substring.string.c_str(), *static_cast<float *>(values) - 1); |
| 512 | break; |
| 513 | } |
| 514 | } |
| 515 | shader_message << buffer; |
| 516 | free(buffer); |
| 517 | } |
| 518 | |
Tony-LunarG | 7de10e8 | 2020-11-24 11:31:55 -0700 | [diff] [blame] | 519 | void DebugPrintf::AnalyzeAndGenerateMessages(VkCommandBuffer command_buffer, VkQueue queue, DPFBufferInfo &buffer_info, |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 520 | uint32_t operation_index, uint32_t *const debug_output_buffer) { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 521 | // Word Content |
| 522 | // 0 Size of output record, including this word |
| 523 | // 1 Shader ID |
| 524 | // 2 Instruction Position |
| 525 | // 3 Stage Ordinal |
| 526 | // 4 Stage - specific Info Word 0 |
| 527 | // 5 Stage - specific Info Word 1 |
| 528 | // 6 Stage - specific Info Word 2 |
| 529 | // 7 Printf Format String Id |
| 530 | // 8 Printf Values Word 0 (optional) |
| 531 | // 9 Printf Values Word 1 (optional) |
Tony-LunarG | 12a7ec3 | 2019-11-01 13:00:05 -0600 | [diff] [blame] | 532 | uint32_t expect = debug_output_buffer[0]; |
| 533 | if (!expect) return; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 534 | |
Tony-LunarG | 12a7ec3 | 2019-11-01 13:00:05 -0600 | [diff] [blame] | 535 | uint32_t index = 1; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 536 | while (debug_output_buffer[index]) { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 537 | std::stringstream shader_message; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 538 | VkShaderModule shader_module_handle = VK_NULL_HANDLE; |
| 539 | VkPipeline pipeline_handle = VK_NULL_HANDLE; |
sfricke-samsung | 7fac88a | 2022-01-26 11:44:22 -0800 | [diff] [blame] | 540 | std::vector<uint32_t> pgm; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 541 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 542 | DPFOutputRecord *debug_record = reinterpret_cast<DPFOutputRecord *>(&debug_output_buffer[index]); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 543 | // Lookup the VkShaderModule handle and SPIR-V code used to create the shader, using the unique shader ID value returned |
| 544 | // by the instrumented shader. |
| 545 | auto it = shader_map.find(debug_record->shader_id); |
| 546 | if (it != shader_map.end()) { |
| 547 | shader_module_handle = it->second.shader_module; |
| 548 | pipeline_handle = it->second.pipeline; |
| 549 | pgm = it->second.pgm; |
| 550 | } |
| 551 | // Search through the shader source for the printf format string for this invocation |
| 552 | auto format_string = FindFormatString(pgm, debug_record->format_string_id); |
| 553 | // Break the format string into strings with 1 or 0 value |
| 554 | auto format_substrings = ParseFormatString(format_string); |
| 555 | void *values = static_cast<void *>(&debug_record->values); |
| 556 | const uint32_t static_size = 1024; |
| 557 | // Sprintf each format substring into a temporary string then add that to the message |
| 558 | for (auto &substring : format_substrings) { |
| 559 | char temp_string[static_size]; |
| 560 | size_t needed = 0; |
Tony-LunarG | ef469c9 | 2021-05-14 06:33:22 -0600 | [diff] [blame] | 561 | std::vector<std::string> format_strings = { "%ul", "%lu", "%lx" }; |
| 562 | size_t ul_pos = 0; |
| 563 | bool print_hex = true; |
| 564 | for (auto ul_string : format_strings) { |
| 565 | ul_pos = substring.string.find(ul_string); |
| 566 | if (ul_pos != std::string::npos) { |
| 567 | if (ul_string == "%lu") print_hex = false; |
| 568 | break; |
| 569 | } |
| 570 | } |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 571 | if (ul_pos != std::string::npos) { |
| 572 | // Unsigned 64 bit value |
| 573 | substring.longval = *static_cast<uint64_t *>(values); |
| 574 | values = static_cast<uint64_t *>(values) + 1; |
Tony-LunarG | ef469c9 | 2021-05-14 06:33:22 -0600 | [diff] [blame] | 575 | if (print_hex) { |
| 576 | substring.string.replace(ul_pos + 1, 2, PRIx64); |
| 577 | } else { |
| 578 | substring.string.replace(ul_pos + 1, 2, PRIu64); |
| 579 | } |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 580 | needed = snprintf(temp_string, static_size, substring.string.c_str(), substring.longval); |
| 581 | } else { |
| 582 | if (substring.needs_value) { |
| 583 | switch (substring.type) { |
| 584 | case varunsigned: |
| 585 | needed = snprintf(temp_string, static_size, substring.string.c_str(), *static_cast<uint32_t *>(values)); |
| 586 | break; |
| 587 | |
| 588 | case varsigned: |
| 589 | needed = snprintf(temp_string, static_size, substring.string.c_str(), *static_cast<int32_t *>(values)); |
| 590 | break; |
| 591 | |
| 592 | case varfloat: |
| 593 | needed = snprintf(temp_string, static_size, substring.string.c_str(), *static_cast<float *>(values)); |
| 594 | break; |
| 595 | } |
| 596 | values = static_cast<uint32_t *>(values) + 1; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 597 | } else { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 598 | needed = snprintf(temp_string, static_size, substring.string.c_str()); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 599 | } |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 600 | } |
| 601 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 602 | if (needed < static_size) { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 603 | shader_message << temp_string; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 604 | } else { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 605 | // Static buffer not big enough for message, use malloc to get enough |
| 606 | snprintf_with_malloc(shader_message, substring, needed, values); |
| 607 | } |
| 608 | } |
Tony-LunarG | 43416b4 | 2019-10-31 16:47:24 -0600 | [diff] [blame] | 609 | |
| 610 | if (verbose) { |
| 611 | std::string stage_message; |
| 612 | std::string common_message; |
| 613 | std::string filename_message; |
| 614 | std::string source_message; |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 615 | UtilGenerateStageMessage(&debug_output_buffer[index], stage_message); |
| 616 | UtilGenerateCommonMessage(report_data, command_buffer, &debug_output_buffer[index], shader_module_handle, |
Tony-LunarG | 7de10e8 | 2020-11-24 11:31:55 -0700 | [diff] [blame] | 617 | pipeline_handle, buffer_info.pipeline_bind_point, operation_index, common_message); |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 618 | UtilGenerateSourceMessages(pgm, &debug_output_buffer[index], true, filename_message, source_message); |
Tony-LunarG | 43416b4 | 2019-10-31 16:47:24 -0600 | [diff] [blame] | 619 | if (use_stdout) { |
Tony-LunarG | 5af54eb | 2020-03-27 15:32:51 -0600 | [diff] [blame] | 620 | std::cout << "UNASSIGNED-DEBUG-PRINTF " << common_message.c_str() << " " << stage_message.c_str() << " " |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 621 | << shader_message.str().c_str() << " " << filename_message.c_str() << " " << source_message.c_str(); |
Tony-LunarG | 43416b4 | 2019-10-31 16:47:24 -0600 | [diff] [blame] | 622 | } else { |
Tony-LunarG | 5af54eb | 2020-03-27 15:32:51 -0600 | [diff] [blame] | 623 | LogInfo(queue, "UNASSIGNED-DEBUG-PRINTF", "%s %s %s %s%s", common_message.c_str(), stage_message.c_str(), |
| 624 | shader_message.str().c_str(), filename_message.c_str(), source_message.c_str()); |
Tony-LunarG | 43416b4 | 2019-10-31 16:47:24 -0600 | [diff] [blame] | 625 | } |
| 626 | } else { |
Tony-LunarG | 5af54eb | 2020-03-27 15:32:51 -0600 | [diff] [blame] | 627 | if (use_stdout) { |
Tony-LunarG | 43416b4 | 2019-10-31 16:47:24 -0600 | [diff] [blame] | 628 | std::cout << shader_message.str(); |
Tony-LunarG | 5af54eb | 2020-03-27 15:32:51 -0600 | [diff] [blame] | 629 | } else { |
| 630 | // Don't let LogInfo process any '%'s in the string |
| 631 | LogInfo(device, "UNASSIGNED-DEBUG-PRINTF", "%s", shader_message.str().c_str()); |
| 632 | } |
Tony-LunarG | 43416b4 | 2019-10-31 16:47:24 -0600 | [diff] [blame] | 633 | } |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 634 | index += debug_record->size; |
| 635 | } |
Tony-LunarG | 12a7ec3 | 2019-11-01 13:00:05 -0600 | [diff] [blame] | 636 | if ((index - 1) != expect) { |
Tony-LunarG | 5af54eb | 2020-03-27 15:32:51 -0600 | [diff] [blame] | 637 | LogWarning(device, "UNASSIGNED-DEBUG-PRINTF", |
| 638 | "WARNING - Debug Printf message was truncated, likely due to a buffer size that was too small for the message"); |
Tony-LunarG | 12a7ec3 | 2019-11-01 13:00:05 -0600 | [diff] [blame] | 639 | } |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 640 | memset(debug_output_buffer, 0, 4 * (debug_output_buffer[0] + 1)); |
| 641 | } |
Tony-LunarG | 43416b4 | 2019-10-31 16:47:24 -0600 | [diff] [blame] | 642 | |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 643 | #if defined(__GNUC__) |
| 644 | #pragma GCC diagnostic pop |
| 645 | #endif |
| 646 | |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 647 | bool DebugPrintf::CommandBufferNeedsProcessing(VkCommandBuffer command_buffer) { |
| 648 | bool buffers_present = false; |
Jeremy Gebben | 37c5c5d | 2022-03-21 07:16:03 -0600 | [diff] [blame] | 649 | auto cb_node = Get<debug_printf_state::CommandBuffer>(command_buffer); |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 650 | if (GetBufferInfo(cb_node.get()).size()) { |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 651 | buffers_present = true; |
| 652 | } |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 653 | for (const auto *secondaryCmdBuffer : cb_node->linkedCommandBuffers) { |
Jeremy Gebben | f6bb4bb | 2021-08-11 15:41:09 -0600 | [diff] [blame] | 654 | if (GetBufferInfo(secondaryCmdBuffer).size()) { |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 655 | buffers_present = true; |
| 656 | } |
| 657 | } |
| 658 | return buffers_present; |
| 659 | } |
| 660 | |
| 661 | void DebugPrintf::ProcessCommandBuffer(VkQueue queue, VkCommandBuffer command_buffer) { |
Jeremy Gebben | 37c5c5d | 2022-03-21 07:16:03 -0600 | [diff] [blame] | 662 | auto cb_node = Get<debug_printf_state::CommandBuffer>(command_buffer); |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 663 | UtilProcessInstrumentationBuffer(queue, cb_node.get(), this); |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 664 | for (auto *secondary_cmd_buffer : cb_node->linkedCommandBuffers) { |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 665 | UtilProcessInstrumentationBuffer(queue, secondary_cmd_buffer, this); |
| 666 | } |
| 667 | } |
| 668 | |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 669 | // Issue a memory barrier to make GPU-written data available to host. |
| 670 | // Wait for the queue to complete execution. |
| 671 | // Check the debug buffers for all the command buffers that were submitted. |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 672 | void DebugPrintf::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, VkFence fence, |
| 673 | VkResult result) { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 674 | ValidationStateTracker::PostCallRecordQueueSubmit(queue, submitCount, pSubmits, fence, result); |
| 675 | |
Mark Lobodzinski | 09379db | 2020-05-07 08:22:01 -0600 | [diff] [blame] | 676 | if (aborted || (result != VK_SUCCESS)) return; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 677 | bool buffers_present = false; |
| 678 | // Don't QueueWaitIdle if there's nothing to process |
| 679 | for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) { |
| 680 | const VkSubmitInfo *submit = &pSubmits[submit_idx]; |
| 681 | for (uint32_t i = 0; i < submit->commandBufferCount; i++) { |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 682 | buffers_present |= CommandBufferNeedsProcessing(submit->pCommandBuffers[i]); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | if (!buffers_present) return; |
| 686 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 687 | UtilSubmitBarrier(queue, this); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 688 | |
| 689 | DispatchQueueWaitIdle(queue); |
| 690 | |
| 691 | for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) { |
| 692 | const VkSubmitInfo *submit = &pSubmits[submit_idx]; |
| 693 | for (uint32_t i = 0; i < submit->commandBufferCount; i++) { |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 694 | ProcessCommandBuffer(queue, submit->pCommandBuffers[i]); |
| 695 | } |
| 696 | } |
| 697 | } |
| 698 | |
Tony-LunarG | 26fe284 | 2021-11-16 14:07:59 -0700 | [diff] [blame] | 699 | void DebugPrintf::RecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2 *pSubmits, VkFence fence, |
| 700 | VkResult result) { |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 701 | if (aborted || (result != VK_SUCCESS)) return; |
| 702 | bool buffers_present = false; |
| 703 | // Don't QueueWaitIdle if there's nothing to process |
| 704 | for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) { |
| 705 | const auto *submit = &pSubmits[submit_idx]; |
| 706 | for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) { |
| 707 | buffers_present |= CommandBufferNeedsProcessing(submit->pCommandBufferInfos[i].commandBuffer); |
| 708 | } |
| 709 | } |
| 710 | if (!buffers_present) return; |
| 711 | |
| 712 | UtilSubmitBarrier(queue, this); |
| 713 | |
| 714 | DispatchQueueWaitIdle(queue); |
| 715 | |
| 716 | for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) { |
Tony-LunarG | 26fe284 | 2021-11-16 14:07:59 -0700 | [diff] [blame] | 717 | const VkSubmitInfo2 *submit = &pSubmits[submit_idx]; |
Jeremy Gebben | a3705f4 | 2021-01-19 16:47:43 -0700 | [diff] [blame] | 718 | for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) { |
| 719 | ProcessCommandBuffer(queue, submit->pCommandBufferInfos[i].commandBuffer); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | } |
| 723 | |
Tony-LunarG | 26fe284 | 2021-11-16 14:07:59 -0700 | [diff] [blame] | 724 | void DebugPrintf::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits, |
| 725 | VkFence fence, VkResult result) { |
| 726 | ValidationStateTracker::PostCallRecordQueueSubmit2KHR(queue, submitCount, pSubmits, fence, result); |
| 727 | RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result); |
| 728 | } |
| 729 | |
| 730 | void DebugPrintf::PostCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2 *pSubmits, VkFence fence, |
| 731 | VkResult result) { |
| 732 | ValidationStateTracker::PostCallRecordQueueSubmit2(queue, submitCount, pSubmits, fence, result); |
| 733 | RecordQueueSubmit2(queue, submitCount, pSubmits, fence, result); |
| 734 | } |
| 735 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 736 | void DebugPrintf::PreCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, |
| 737 | uint32_t firstVertex, uint32_t firstInstance) { |
| 738 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 739 | } |
| 740 | |
Tony-LunarG | 745150c | 2021-07-02 15:07:31 -0600 | [diff] [blame] | 741 | void DebugPrintf::PreCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount, |
| 742 | const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount, |
| 743 | uint32_t firstInstance, uint32_t stride) { |
| 744 | for(uint32_t i = 0; i < drawCount; i++) { |
| 745 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 746 | } |
| 747 | } |
| 748 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 749 | void DebugPrintf::PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 750 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) { |
| 751 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 752 | } |
| 753 | |
Tony-LunarG | 745150c | 2021-07-02 15:07:31 -0600 | [diff] [blame] | 754 | void DebugPrintf::PreCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount, |
| 755 | const VkMultiDrawIndexedInfoEXT *pIndexInfo, uint32_t instanceCount, |
| 756 | uint32_t firstInstance, uint32_t stride, const int32_t *pVertexOffset) { |
| 757 | for (uint32_t i = 0; i < drawCount; i++) { |
| 758 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 759 | } |
| 760 | } |
| 761 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 762 | void DebugPrintf::PreCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, |
| 763 | uint32_t stride) { |
| 764 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 765 | } |
| 766 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 767 | void DebugPrintf::PreCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 768 | uint32_t count, uint32_t stride) { |
| 769 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 770 | } |
| 771 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 772 | void DebugPrintf::PreCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) { |
| 773 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 774 | } |
| 775 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 776 | void DebugPrintf::PreCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) { |
| 777 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 778 | } |
| 779 | |
Tony-LunarG | d13f9b5 | 2020-09-08 15:45:45 -0600 | [diff] [blame] | 780 | void DebugPrintf::PreCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY, |
| 781 | uint32_t baseGroupZ, uint32_t groupCountX, uint32_t groupCountY, |
| 782 | uint32_t groupCountZ) { |
| 783 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE); |
| 784 | } |
| 785 | |
Tony-LunarG | 52c8c60 | 2020-09-10 16:29:56 -0600 | [diff] [blame] | 786 | void DebugPrintf::PreCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY, |
| 787 | uint32_t baseGroupZ, uint32_t groupCountX, uint32_t groupCountY, |
| 788 | uint32_t groupCountZ) { |
| 789 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE); |
| 790 | } |
| 791 | |
Tony-LunarG | 2fb8ff0 | 2020-06-11 12:45:07 -0600 | [diff] [blame] | 792 | void DebugPrintf::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 793 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 794 | uint32_t stride) { |
| 795 | ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 796 | maxDrawCount, stride); |
| 797 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 798 | } |
| 799 | |
| 800 | void DebugPrintf::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 801 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 802 | uint32_t stride) { |
| 803 | ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 804 | maxDrawCount, stride); |
| 805 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 806 | } |
| 807 | |
| 808 | void DebugPrintf::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 809 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 810 | uint32_t maxDrawCount, uint32_t stride) { |
| 811 | ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, |
| 812 | countBufferOffset, maxDrawCount, stride); |
| 813 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 814 | } |
| 815 | |
| 816 | void DebugPrintf::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 817 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 818 | uint32_t maxDrawCount, uint32_t stride) { |
| 819 | ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, |
| 820 | maxDrawCount, stride); |
| 821 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 822 | } |
| 823 | |
Tony-LunarG | 54176fb | 2020-12-02 10:47:22 -0700 | [diff] [blame] | 824 | void DebugPrintf::PreCallRecordCmdDrawIndirectByteCountEXT(VkCommandBuffer commandBuffer, uint32_t instanceCount, |
| 825 | uint32_t firstInstance, VkBuffer counterBuffer, |
| 826 | VkDeviceSize counterBufferOffset, uint32_t counterOffset, |
| 827 | uint32_t vertexStride) { |
| 828 | ValidationStateTracker::PreCallRecordCmdDrawIndirectByteCountEXT(commandBuffer, instanceCount, firstInstance, counterBuffer, |
| 829 | counterBufferOffset, counterOffset, vertexStride); |
| 830 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 831 | } |
| 832 | |
Tony-LunarG | 2fb8ff0 | 2020-06-11 12:45:07 -0600 | [diff] [blame] | 833 | void DebugPrintf::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount, uint32_t firstTask) { |
| 834 | ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(commandBuffer, taskCount, firstTask); |
| 835 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 836 | } |
| 837 | |
| 838 | void DebugPrintf::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 839 | uint32_t drawCount, uint32_t stride) { |
| 840 | ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(commandBuffer, buffer, offset, drawCount, stride); |
| 841 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 842 | } |
| 843 | |
| 844 | void DebugPrintf::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 845 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, |
| 846 | uint32_t maxDrawCount, uint32_t stride) { |
| 847 | ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(commandBuffer, buffer, offset, countBuffer, |
| 848 | countBufferOffset, maxDrawCount, stride); |
| 849 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS); |
| 850 | } |
| 851 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 852 | void DebugPrintf::PreCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer, |
| 853 | VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer, |
| 854 | VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride, |
| 855 | VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset, |
| 856 | VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer, |
| 857 | VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride, |
| 858 | uint32_t width, uint32_t height, uint32_t depth) { |
| 859 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV); |
| 860 | } |
| 861 | |
| 862 | void DebugPrintf::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer, |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 863 | VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer, |
| 864 | VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride, |
| 865 | VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset, |
| 866 | VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer, |
| 867 | VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride, |
| 868 | uint32_t width, uint32_t height, uint32_t depth) { |
Jeremy Gebben | 37c5c5d | 2022-03-21 07:16:03 -0600 | [diff] [blame] | 869 | auto cb_state = Get<debug_printf_state::CommandBuffer>(commandBuffer); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 870 | cb_state->hasTraceRaysCmd = true; |
| 871 | } |
| 872 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 873 | void DebugPrintf::PreCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer, |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 874 | const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable, |
| 875 | const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable, |
| 876 | const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable, |
| 877 | const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width, |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 878 | uint32_t height, uint32_t depth) { |
| 879 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR); |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 880 | } |
| 881 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 882 | void DebugPrintf::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer, |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 883 | const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable, |
| 884 | const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable, |
| 885 | const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable, |
| 886 | const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width, |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 887 | uint32_t height, uint32_t depth) { |
Jeremy Gebben | 37c5c5d | 2022-03-21 07:16:03 -0600 | [diff] [blame] | 888 | auto cb_state = Get<debug_printf_state::CommandBuffer>(commandBuffer); |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 889 | cb_state->hasTraceRaysCmd = true; |
| 890 | } |
| 891 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 892 | void DebugPrintf::PreCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer, |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 893 | const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable, |
| 894 | const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable, |
| 895 | const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable, |
| 896 | const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, |
Shannon McPherson | 54e1f89 | 2020-11-27 11:04:19 -0700 | [diff] [blame] | 897 | VkDeviceAddress indirectDeviceAddress) { |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 898 | AllocateDebugPrintfResources(commandBuffer, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR); |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 899 | } |
| 900 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 901 | void DebugPrintf::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer, |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 902 | const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable, |
| 903 | const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable, |
| 904 | const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable, |
| 905 | const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, |
Shannon McPherson | 54e1f89 | 2020-11-27 11:04:19 -0700 | [diff] [blame] | 906 | VkDeviceAddress indirectDeviceAddress) { |
Jeremy Gebben | 37c5c5d | 2022-03-21 07:16:03 -0600 | [diff] [blame] | 907 | auto cb_state = Get<debug_printf_state::CommandBuffer>(commandBuffer); |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 908 | cb_state->hasTraceRaysCmd = true; |
| 909 | } |
| 910 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 911 | void DebugPrintf::AllocateDebugPrintfResources(const VkCommandBuffer cmd_buffer, const VkPipelineBindPoint bind_point) { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 912 | if (bind_point != VK_PIPELINE_BIND_POINT_GRAPHICS && bind_point != VK_PIPELINE_BIND_POINT_COMPUTE && |
| 913 | bind_point != VK_PIPELINE_BIND_POINT_RAY_TRACING_NV) { |
| 914 | return; |
| 915 | } |
| 916 | VkResult result; |
| 917 | |
| 918 | if (aborted) return; |
| 919 | |
| 920 | std::vector<VkDescriptorSet> desc_sets; |
| 921 | VkDescriptorPool desc_pool = VK_NULL_HANDLE; |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 922 | result = desc_set_manager->GetDescriptorSets(1, &desc_pool, debug_desc_layout, &desc_sets); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 923 | assert(result == VK_SUCCESS); |
| 924 | if (result != VK_SUCCESS) { |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 925 | ReportSetupProblem(device, "Unable to allocate descriptor sets. Device could become unstable."); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 926 | aborted = true; |
| 927 | return; |
| 928 | } |
| 929 | |
| 930 | VkDescriptorBufferInfo output_desc_buffer_info = {}; |
| 931 | output_desc_buffer_info.range = output_buffer_size; |
| 932 | |
Jeremy Gebben | 37c5c5d | 2022-03-21 07:16:03 -0600 | [diff] [blame] | 933 | auto cb_node = Get<debug_printf_state::CommandBuffer>(cmd_buffer); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 934 | if (!cb_node) { |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 935 | ReportSetupProblem(device, "Unrecognized command buffer"); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 936 | aborted = true; |
| 937 | return; |
| 938 | } |
| 939 | |
Nathaniel Cesario | bcb7968 | 2022-03-31 21:13:52 -0600 | [diff] [blame] | 940 | const auto lv_bind_point = ConvertToLvlBindPoint(bind_point); |
| 941 | const auto *pipeline_state = cb_node->lastBound[lv_bind_point].pipeline_state; |
| 942 | |
| 943 | // TODO (ncesario) remove once VK_EXT_graphics_pipeline_library support is added for debug printf |
| 944 | if (pipeline_state && pipeline_state->IsGraphicsLibrary()) { |
| 945 | ReportSetupProblem(device, "Debug printf does not currently support VK_EXT_graphics_pipeline_library"); |
| 946 | aborted = true; |
| 947 | return; |
| 948 | } |
| 949 | |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 950 | // Allocate memory for the output block that the gpu will use to return values for printf |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame] | 951 | DPFDeviceMemoryBlock output_block = {}; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 952 | VkBufferCreateInfo buffer_info = {VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; |
| 953 | buffer_info.size = output_buffer_size; |
| 954 | buffer_info.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; |
| 955 | VmaAllocationCreateInfo alloc_info = {}; |
| 956 | alloc_info.usage = VMA_MEMORY_USAGE_GPU_TO_CPU; |
| 957 | result = vmaCreateBuffer(vmaAllocator, &buffer_info, &alloc_info, &output_block.buffer, &output_block.allocation, nullptr); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 958 | if (result != VK_SUCCESS) { |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 959 | ReportSetupProblem(device, "Unable to allocate device memory. Device could become unstable."); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 960 | aborted = true; |
| 961 | return; |
| 962 | } |
| 963 | |
| 964 | // Clear the output block to zeros so that only printf values from the gpu will be present |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 965 | uint32_t *data; |
| 966 | result = vmaMapMemory(vmaAllocator, output_block.allocation, reinterpret_cast<void **>(&data)); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 967 | if (result == VK_SUCCESS) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 968 | memset(data, 0, output_buffer_size); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 969 | vmaUnmapMemory(vmaAllocator, output_block.allocation); |
| 970 | } |
| 971 | |
Nathaniel Cesario | fc6291e | 2021-04-06 00:22:15 -0600 | [diff] [blame] | 972 | auto desc_writes = LvlInitStruct<VkWriteDescriptorSet>(); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 973 | const uint32_t desc_count = 1; |
| 974 | |
| 975 | // Write the descriptor |
| 976 | output_desc_buffer_info.buffer = output_block.buffer; |
| 977 | output_desc_buffer_info.offset = 0; |
| 978 | |
Nathaniel Cesario | fc6291e | 2021-04-06 00:22:15 -0600 | [diff] [blame] | 979 | desc_writes.descriptorCount = 1; |
| 980 | desc_writes.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; |
| 981 | desc_writes.pBufferInfo = &output_desc_buffer_info; |
| 982 | desc_writes.dstSet = desc_sets[0]; |
| 983 | desc_writes.dstBinding = 3; |
| 984 | DispatchUpdateDescriptorSets(device, desc_count, &desc_writes, 0, NULL); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 985 | |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 986 | if (pipeline_state) { |
Nathaniel Cesario | 3fd4f76 | 2022-02-16 16:07:06 -0700 | [diff] [blame] | 987 | const auto &pipeline_layout = pipeline_state->PipelineLayoutState(); |
| 988 | if (pipeline_layout->set_layouts.size() <= desc_set_bind_index) { |
| 989 | DispatchCmdBindDescriptorSets(cmd_buffer, bind_point, pipeline_layout->layout(), desc_set_bind_index, 1, |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 990 | desc_sets.data(), 0, nullptr); |
| 991 | } |
| 992 | // Record buffer and memory info in CB state tracking |
Jeremy Gebben | f6bb4bb | 2021-08-11 15:41:09 -0600 | [diff] [blame] | 993 | cb_node->buffer_infos.emplace_back(output_block, desc_sets[0], desc_pool, bind_point); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 994 | } else { |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 995 | ReportSetupProblem(device, "Unable to find pipeline state"); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 996 | vmaDestroyBuffer(vmaAllocator, output_block.buffer, output_block.allocation); |
| 997 | aborted = true; |
| 998 | return; |
| 999 | } |
| 1000 | } |
Jeremy Gebben | f6bb4bb | 2021-08-11 15:41:09 -0600 | [diff] [blame] | 1001 | |
| 1002 | std::shared_ptr<CMD_BUFFER_STATE> DebugPrintf::CreateCmdBufferState(VkCommandBuffer cb, |
| 1003 | const VkCommandBufferAllocateInfo *pCreateInfo, |
Jeremy Gebben | cd7fa28 | 2021-10-27 10:25:32 -0600 | [diff] [blame] | 1004 | const COMMAND_POOL_STATE *pool) { |
Jeremy Gebben | 37c5c5d | 2022-03-21 07:16:03 -0600 | [diff] [blame] | 1005 | return std::static_pointer_cast<CMD_BUFFER_STATE>( |
| 1006 | std::make_shared<debug_printf_state::CommandBuffer>(this, cb, pCreateInfo, pool)); |
Jeremy Gebben | f6bb4bb | 2021-08-11 15:41:09 -0600 | [diff] [blame] | 1007 | } |
| 1008 | |
Jeremy Gebben | 37c5c5d | 2022-03-21 07:16:03 -0600 | [diff] [blame] | 1009 | debug_printf_state::CommandBuffer::CommandBuffer(DebugPrintf *dp, VkCommandBuffer cb, |
Jeremy Gebben | cd7fa28 | 2021-10-27 10:25:32 -0600 | [diff] [blame] | 1010 | const VkCommandBufferAllocateInfo *pCreateInfo, const COMMAND_POOL_STATE *pool) |
Jeremy Gebben | f6bb4bb | 2021-08-11 15:41:09 -0600 | [diff] [blame] | 1011 | : CMD_BUFFER_STATE(dp, cb, pCreateInfo, pool) {} |
| 1012 | |
Jeremy Gebben | 37c5c5d | 2022-03-21 07:16:03 -0600 | [diff] [blame] | 1013 | void debug_printf_state::CommandBuffer::Reset() { |
Jeremy Gebben | f6bb4bb | 2021-08-11 15:41:09 -0600 | [diff] [blame] | 1014 | CMD_BUFFER_STATE::Reset(); |
| 1015 | auto debug_printf = static_cast<DebugPrintf *>(dev_data); |
| 1016 | // Free the device memory and descriptor set(s) associated with a command buffer. |
| 1017 | if (debug_printf->aborted) { |
| 1018 | return; |
| 1019 | } |
| 1020 | for (auto &buffer_info : buffer_infos) { |
| 1021 | debug_printf->DestroyBuffer(buffer_info); |
| 1022 | } |
| 1023 | buffer_infos.clear(); |
| 1024 | } |