blob: 34377b15a9c0b7b4e1b26b0e968122b150095349 [file] [log] [blame]
Tony-LunarGb5fae462020-03-05 12:43:25 -07001/* Copyright (c) 2020 The Khronos Group Inc.
2 * Copyright (c) 2020 Valve Corporation
3 * Copyright (c) 2020 LunarG, Inc.
Tony-LunarG04717522019-10-17 10:41:17 -06004 *
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-LunarGb5fae462020-03-05 12:43:25 -070025#include "gpu_utils.h"
Tony-LunarG04717522019-10-17 10:41:17 -060026#include <map>
Tony-LunarGb5fae462020-03-05 12:43:25 -070027class DebugPrintf;
Tony-LunarG04717522019-10-17 10:41:17 -060028
Tony-LunarGb5fae462020-03-05 12:43:25 -070029struct DPFDeviceMemoryBlock {
Tony-LunarG04717522019-10-17 10:41:17 -060030 VkBuffer buffer;
31 VmaAllocation allocation;
32};
33
Tony-LunarGb5fae462020-03-05 12:43:25 -070034struct DPFBufferInfo {
35 DPFDeviceMemoryBlock output_mem_block;
Tony-LunarG04717522019-10-17 10:41:17 -060036 VkDescriptorSet desc_set;
37 VkDescriptorPool desc_pool;
38 VkPipelineBindPoint pipeline_bind_point;
Tony-LunarGb5fae462020-03-05 12:43:25 -070039 DPFBufferInfo(DPFDeviceMemoryBlock output_mem_block, VkDescriptorSet desc_set, VkDescriptorPool desc_pool,
Tony-LunarG04717522019-10-17 10:41:17 -060040 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-LunarG04717522019-10-17 10:41:17 -060043
Tony-LunarGb5fae462020-03-05 12:43:25 -070044struct DPFShaderTracker {
Tony-LunarG04717522019-10-17 10:41:17 -060045 VkPipeline pipeline;
46 VkShaderModule shader_module;
47 std::vector<unsigned int> pgm;
48};
49
50enum vartype { varsigned, varunsigned, varfloat };
Tony-LunarGb5fae462020-03-05 12:43:25 -070051struct DPFSubstring {
Tony-LunarG04717522019-10-17 10:41:17 -060052 std::string string;
53 bool needs_value;
54 vartype type;
55 uint64_t longval = 0;
56};
57
Tony-LunarGb5fae462020-03-05 12:43:25 -070058struct DPFOutputRecord {
Tony-LunarG04717522019-10-17 10:41:17 -060059 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-LunarGb5fae462020-03-05 12:43:25 -070070class DebugPrintf : public ValidationStateTracker {
Tony-LunarG04717522019-10-17 10:41:17 -060071 VkPhysicalDeviceFeatures supported_features;
Tony-LunarG1dce2392019-10-23 16:49:29 -060072
Tony-LunarG04717522019-10-17 10:41:17 -060073 uint32_t unique_shader_module_id = 0;
Tony-LunarGb5fae462020-03-05 12:43:25 -070074 std::unordered_map<VkCommandBuffer, std::vector<DPFBufferInfo>> command_buffer_map;
Tony-LunarG04717522019-10-17 10:41:17 -060075 uint32_t output_buffer_size;
Tony-LunarG1dce2392019-10-23 16:49:29 -060076
77 public:
78 bool aborted = false;
Tony-LunarG43416b42019-10-31 16:47:24 -060079 bool verbose = false;
80 bool use_stdout = false;
Tony-LunarG1dce2392019-10-23 16:49:29 -060081 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-LunarGb5fae462020-03-05 12:43:25 -070087 std::unique_ptr<UtilDescriptorSetManager> desc_set_manager;
88 std::unordered_map<uint32_t, DPFShaderTracker> shader_map;
Tony-LunarG04717522019-10-17 10:41:17 -060089 PFN_vkSetDeviceLoaderData vkSetDeviceLoaderData;
Tony-LunarG1dce2392019-10-23 16:49:29 -060090 VmaAllocator vmaAllocator = {};
Tony-LunarGb5fae462020-03-05 12:43:25 -070091 std::map<VkQueue, UtilQueueBarrierCommandInfo> queue_barrier_command_infos;
92 std::vector<DPFBufferInfo>& GetBufferInfo(const VkCommandBuffer command_buffer) {
Tony-LunarG04717522019-10-17 10:41:17 -060093 auto buffer_list = command_buffer_map.find(command_buffer);
94 if (buffer_list == command_buffer_map.end()) {
Tony-LunarGb5fae462020-03-05 12:43:25 -070095 std::vector<DPFBufferInfo> new_list{};
Tony-LunarG04717522019-10-17 10:41:17 -060096 command_buffer_map[command_buffer] = new_list;
97 return command_buffer_map[command_buffer];
98 }
99 return buffer_list->second;
100 }
Tony-LunarG04717522019-10-17 10:41:17 -0600101
Tony-LunarG1dce2392019-10-23 16:49:29 -0600102 template <typename T>
103 void ReportSetupProblem(T object, const char* const specific_message) const;
Tony-LunarG04717522019-10-17 10:41:17 -0600104 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-LunarG1dce2392019-10-23 16:49:29 -0600109 void PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator);
Tony-LunarG04717522019-10-17 10:41:17 -0600110 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-LunarG04717522019-10-17 10:41:17 -0600138 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-LunarG04717522019-10-17 10:41:17 -0600150 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-LunarGb5fae462020-03-05 12:43:25 -0700156 std::vector<DPFSubstring> ParseFormatString(std::string format_string);
Tony-LunarG04717522019-10-17 10:41:17 -0600157 std::string FindFormatString(std::vector<unsigned int> pgm, uint32_t string_id);
Tony-LunarG1dce2392019-10-23 16:49:29 -0600158 void AnalyzeAndGenerateMessages(VkCommandBuffer command_buffer, VkQueue queue, VkPipelineBindPoint pipeline_bind_point,
159 uint32_t operation_index, uint32_t* const debug_output_buffer);
Tony-LunarG04717522019-10-17 10:41:17 -0600160 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-LunarG1dce2392019-10-23 16:49:29 -0600184 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-LunarG04717522019-10-17 10:41:17 -0600206 void PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence,
207 VkResult result);
Tony-LunarGb5fae462020-03-05 12:43:25 -0700208 void AllocateDebugPrintfResources(const VkCommandBuffer cmd_buffer, const VkPipelineBindPoint bind_point);
Tony-LunarG43416b42019-10-31 16:47:24 -0600209 void SendStringToCallback(std::vector<VkLayerDbgFunctionState> debug_callback_list, std::string shader_message);
Tony-LunarG04717522019-10-17 10:41:17 -0600210};