Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame^] | 1 | /* Copyright (c) 2020 The Khronos Group Inc. |
| 2 | * Copyright (c) 2020 Valve Corporation |
| 3 | * Copyright (c) 2020 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 | |
| 20 | #pragma once |
| 21 | |
| 22 | #include "chassis.h" |
| 23 | #include "vk_mem_alloc.h" |
| 24 | #include "state_tracker.h" |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame^] | 25 | #include "gpu_utils.h" |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 26 | #include <map> |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame^] | 27 | class DebugPrintf; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 28 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame^] | 29 | struct DPFDeviceMemoryBlock { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 30 | VkBuffer buffer; |
| 31 | VmaAllocation allocation; |
| 32 | }; |
| 33 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame^] | 34 | struct DPFBufferInfo { |
| 35 | DPFDeviceMemoryBlock output_mem_block; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 36 | VkDescriptorSet desc_set; |
| 37 | VkDescriptorPool desc_pool; |
| 38 | VkPipelineBindPoint pipeline_bind_point; |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame^] | 39 | DPFBufferInfo(DPFDeviceMemoryBlock output_mem_block, VkDescriptorSet desc_set, VkDescriptorPool desc_pool, |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 40 | VkPipelineBindPoint pipeline_bind_point) |
| 41 | : output_mem_block(output_mem_block), desc_set(desc_set), desc_pool(desc_pool), pipeline_bind_point(pipeline_bind_point){}; |
| 42 | }; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 43 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame^] | 44 | struct DPFShaderTracker { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 45 | VkPipeline pipeline; |
| 46 | VkShaderModule shader_module; |
| 47 | std::vector<unsigned int> pgm; |
| 48 | }; |
| 49 | |
| 50 | enum vartype { varsigned, varunsigned, varfloat }; |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame^] | 51 | struct DPFSubstring { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 52 | std::string string; |
| 53 | bool needs_value; |
| 54 | vartype type; |
| 55 | uint64_t longval = 0; |
| 56 | }; |
| 57 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame^] | 58 | struct DPFOutputRecord { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 59 | uint32_t size; |
| 60 | uint32_t shader_id; |
| 61 | uint32_t instruction_position; |
| 62 | uint32_t stage; |
| 63 | uint32_t stage_word_1; |
| 64 | uint32_t stage_word_2; |
| 65 | uint32_t stage_word_3; |
| 66 | uint32_t format_string_id; |
| 67 | uint32_t values; |
| 68 | }; |
| 69 | |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame^] | 70 | class DebugPrintf : public ValidationStateTracker { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 71 | VkPhysicalDeviceFeatures supported_features; |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 72 | |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 73 | uint32_t unique_shader_module_id = 0; |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame^] | 74 | std::unordered_map<VkCommandBuffer, std::vector<DPFBufferInfo>> command_buffer_map; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 75 | uint32_t output_buffer_size; |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 76 | |
| 77 | public: |
| 78 | bool aborted = false; |
Tony-LunarG | 43416b4 | 2019-10-31 16:47:24 -0600 | [diff] [blame] | 79 | bool verbose = false; |
| 80 | bool use_stdout = false; |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 81 | VkDevice device; |
| 82 | VkPhysicalDevice physicalDevice; |
| 83 | uint32_t adjusted_max_desc_sets; |
| 84 | uint32_t desc_set_bind_index; |
| 85 | VkDescriptorSetLayout debug_desc_layout; |
| 86 | VkDescriptorSetLayout dummy_desc_layout; |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame^] | 87 | std::unique_ptr<UtilDescriptorSetManager> desc_set_manager; |
| 88 | std::unordered_map<uint32_t, DPFShaderTracker> shader_map; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 89 | PFN_vkSetDeviceLoaderData vkSetDeviceLoaderData; |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 90 | VmaAllocator vmaAllocator = {}; |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame^] | 91 | std::map<VkQueue, UtilQueueBarrierCommandInfo> queue_barrier_command_infos; |
| 92 | std::vector<DPFBufferInfo>& GetBufferInfo(const VkCommandBuffer command_buffer) { |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 93 | auto buffer_list = command_buffer_map.find(command_buffer); |
| 94 | if (buffer_list == command_buffer_map.end()) { |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame^] | 95 | std::vector<DPFBufferInfo> new_list{}; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 96 | command_buffer_map[command_buffer] = new_list; |
| 97 | return command_buffer_map[command_buffer]; |
| 98 | } |
| 99 | return buffer_list->second; |
| 100 | } |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 101 | |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 102 | template <typename T> |
| 103 | void ReportSetupProblem(T object, const char* const specific_message) const; |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 104 | void PreCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, |
| 105 | const VkAllocationCallbacks* pAllocator, VkDevice* pDevice, |
| 106 | safe_VkDeviceCreateInfo* modified_create_info); |
| 107 | void PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, |
| 108 | const VkAllocationCallbacks* pAllocator, VkDevice* pDevice, VkResult result); |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 109 | void PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 110 | void PreCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, |
| 111 | const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout, |
| 112 | void* cpl_state_data); |
| 113 | void PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, |
| 114 | const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout, |
| 115 | VkResult result); |
| 116 | void ResetCommandBuffer(VkCommandBuffer commandBuffer); |
| 117 | bool PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents, |
| 118 | VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, |
| 119 | uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, |
| 120 | uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers, |
| 121 | uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers) const; |
| 122 | void PreCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 123 | const VkGraphicsPipelineCreateInfo* pCreateInfos, |
| 124 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
| 125 | void* cgpl_state_data); |
| 126 | void PreCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 127 | const VkComputePipelineCreateInfo* pCreateInfos, |
| 128 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
| 129 | void* ccpl_state_data); |
| 130 | void PreCallRecordCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 131 | const VkRayTracingPipelineCreateInfoNV* pCreateInfos, |
| 132 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
| 133 | void* crtpl_state_data); |
| 134 | void PreCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 135 | const VkRayTracingPipelineCreateInfoKHR* pCreateInfos, |
| 136 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, |
| 137 | void* crtpl_state_data); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 138 | void PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 139 | const VkGraphicsPipelineCreateInfo* pCreateInfos, |
| 140 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, VkResult result, |
| 141 | void* cgpl_state_data); |
| 142 | void PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 143 | const VkComputePipelineCreateInfo* pCreateInfos, |
| 144 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, VkResult result, |
| 145 | void* ccpl_state_data); |
| 146 | void PostCallRecordCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, |
| 147 | const VkRayTracingPipelineCreateInfoNV* pCreateInfos, |
| 148 | const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, VkResult result, |
| 149 | void* crtpl_state_data); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 150 | void PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator); |
| 151 | bool InstrumentShader(const VkShaderModuleCreateInfo* pCreateInfo, std::vector<unsigned int>& new_pgm, |
| 152 | uint32_t* unique_shader_id); |
| 153 | void PreCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo* pCreateInfo, |
| 154 | const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule, |
| 155 | void* csm_state_data); |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame^] | 156 | std::vector<DPFSubstring> ParseFormatString(std::string format_string); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 157 | std::string FindFormatString(std::vector<unsigned int> pgm, uint32_t string_id); |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 158 | void AnalyzeAndGenerateMessages(VkCommandBuffer command_buffer, VkQueue queue, VkPipelineBindPoint pipeline_bind_point, |
| 159 | uint32_t operation_index, uint32_t* const debug_output_buffer); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 160 | void PreCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, |
| 161 | uint32_t firstInstance); |
| 162 | void PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, |
| 163 | uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance); |
| 164 | void PreCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, |
| 165 | uint32_t stride); |
| 166 | void PreCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, |
| 167 | uint32_t stride); |
| 168 | void PreCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z); |
| 169 | void PreCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset); |
| 170 | void PreCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer, |
| 171 | VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer, |
| 172 | VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride, |
| 173 | VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset, |
| 174 | VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer, |
| 175 | VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride, |
| 176 | uint32_t width, uint32_t height, uint32_t depth); |
| 177 | void PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer, |
| 178 | VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer, |
| 179 | VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride, |
| 180 | VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset, |
| 181 | VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer, |
| 182 | VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride, |
| 183 | uint32_t width, uint32_t height, uint32_t depth); |
Tony-LunarG | 1dce239 | 2019-10-23 16:49:29 -0600 | [diff] [blame] | 184 | void PreCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer, const VkStridedBufferRegionKHR* pRaygenShaderBindingTable, |
| 185 | const VkStridedBufferRegionKHR* pMissShaderBindingTable, |
| 186 | const VkStridedBufferRegionKHR* pHitShaderBindingTable, |
| 187 | const VkStridedBufferRegionKHR* pCallableShaderBindingTable, uint32_t width, uint32_t height, |
| 188 | uint32_t depth); |
| 189 | void PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer, const VkStridedBufferRegionKHR* pRaygenShaderBindingTable, |
| 190 | const VkStridedBufferRegionKHR* pMissShaderBindingTable, |
| 191 | const VkStridedBufferRegionKHR* pHitShaderBindingTable, |
| 192 | const VkStridedBufferRegionKHR* pCallableShaderBindingTable, uint32_t width, uint32_t height, |
| 193 | uint32_t depth); |
| 194 | void PreCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer, |
| 195 | const VkStridedBufferRegionKHR* pRaygenShaderBindingTable, |
| 196 | const VkStridedBufferRegionKHR* pMissShaderBindingTable, |
| 197 | const VkStridedBufferRegionKHR* pHitShaderBindingTable, |
| 198 | const VkStridedBufferRegionKHR* pCallableShaderBindingTable, VkBuffer buffer, |
| 199 | VkDeviceSize offset); |
| 200 | void PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer, |
| 201 | const VkStridedBufferRegionKHR* pRaygenShaderBindingTable, |
| 202 | const VkStridedBufferRegionKHR* pMissShaderBindingTable, |
| 203 | const VkStridedBufferRegionKHR* pHitShaderBindingTable, |
| 204 | const VkStridedBufferRegionKHR* pCallableShaderBindingTable, VkBuffer buffer, |
| 205 | VkDeviceSize offset); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 206 | void PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence, |
| 207 | VkResult result); |
Tony-LunarG | b5fae46 | 2020-03-05 12:43:25 -0700 | [diff] [blame^] | 208 | void AllocateDebugPrintfResources(const VkCommandBuffer cmd_buffer, const VkPipelineBindPoint bind_point); |
Tony-LunarG | 43416b4 | 2019-10-31 16:47:24 -0600 | [diff] [blame] | 209 | void SendStringToCallback(std::vector<VkLayerDbgFunctionState> debug_callback_list, std::string shader_message); |
Tony-LunarG | 0471752 | 2019-10-17 10:41:17 -0600 | [diff] [blame] | 210 | }; |