blob: 2c69cfc43229f5f73b6d429cb201bc31fc9b88ab [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:
Mark Lobodzinski0dcb87d2020-03-30 16:09:24 -060078 DebugPrintf() { container_type = LayerObjectTypeDebugPrintf; }
79
Tony-LunarG1dce2392019-10-23 16:49:29 -060080 bool aborted = false;
Tony-LunarG43416b42019-10-31 16:47:24 -060081 bool verbose = false;
82 bool use_stdout = false;
Tony-LunarG1dce2392019-10-23 16:49:29 -060083 VkDevice device;
84 VkPhysicalDevice physicalDevice;
85 uint32_t adjusted_max_desc_sets;
86 uint32_t desc_set_bind_index;
Tony-LunarG57ada962020-05-01 16:21:00 -060087 VkDescriptorSetLayout debug_desc_layout = VK_NULL_HANDLE;
88 VkDescriptorSetLayout dummy_desc_layout = VK_NULL_HANDLE;
Tony-LunarGb5fae462020-03-05 12:43:25 -070089 std::unique_ptr<UtilDescriptorSetManager> desc_set_manager;
90 std::unordered_map<uint32_t, DPFShaderTracker> shader_map;
Tony-LunarG04717522019-10-17 10:41:17 -060091 PFN_vkSetDeviceLoaderData vkSetDeviceLoaderData;
Tony-LunarG1dce2392019-10-23 16:49:29 -060092 VmaAllocator vmaAllocator = {};
Tony-LunarGb5fae462020-03-05 12:43:25 -070093 std::map<VkQueue, UtilQueueBarrierCommandInfo> queue_barrier_command_infos;
94 std::vector<DPFBufferInfo>& GetBufferInfo(const VkCommandBuffer command_buffer) {
Tony-LunarG04717522019-10-17 10:41:17 -060095 auto buffer_list = command_buffer_map.find(command_buffer);
96 if (buffer_list == command_buffer_map.end()) {
Tony-LunarGb5fae462020-03-05 12:43:25 -070097 std::vector<DPFBufferInfo> new_list{};
Tony-LunarG04717522019-10-17 10:41:17 -060098 command_buffer_map[command_buffer] = new_list;
99 return command_buffer_map[command_buffer];
100 }
101 return buffer_list->second;
102 }
Tony-LunarG04717522019-10-17 10:41:17 -0600103
Tony-LunarG1dce2392019-10-23 16:49:29 -0600104 template <typename T>
105 void ReportSetupProblem(T object, const char* const specific_message) const;
Tony-LunarG04717522019-10-17 10:41:17 -0600106 void PreCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo,
Mark Lobodzinskib588cd42020-09-30 11:03:34 -0600107 const VkAllocationCallbacks* pAllocator, VkDevice* pDevice, void* modified_create_info);
Tony-LunarG04717522019-10-17 10:41:17 -0600108 void PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo,
109 const VkAllocationCallbacks* pAllocator, VkDevice* pDevice, VkResult result);
Tony-LunarG1dce2392019-10-23 16:49:29 -0600110 void PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator);
Tony-LunarG04717522019-10-17 10:41:17 -0600111 void PreCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo,
112 const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout,
113 void* cpl_state_data);
114 void PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo,
115 const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout,
116 VkResult result);
117 void ResetCommandBuffer(VkCommandBuffer commandBuffer);
118 bool PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
119 VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask,
120 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
121 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
122 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers) const;
123 void PreCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
124 const VkGraphicsPipelineCreateInfo* pCreateInfos,
125 const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines,
126 void* cgpl_state_data);
127 void PreCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
128 const VkComputePipelineCreateInfo* pCreateInfos,
129 const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines,
130 void* ccpl_state_data);
131 void PreCallRecordCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
132 const VkRayTracingPipelineCreateInfoNV* pCreateInfos,
133 const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines,
134 void* crtpl_state_data);
sourav parmarcd5fb182020-07-17 12:58:44 -0700135 void PreCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
136 VkPipelineCache pipelineCache, uint32_t count,
Tony-LunarG04717522019-10-17 10:41:17 -0600137 const VkRayTracingPipelineCreateInfoKHR* pCreateInfos,
138 const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines,
139 void* crtpl_state_data);
Tony-LunarG04717522019-10-17 10:41:17 -0600140 void PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
141 const VkGraphicsPipelineCreateInfo* pCreateInfos,
142 const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, VkResult result,
143 void* cgpl_state_data);
144 void PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
145 const VkComputePipelineCreateInfo* pCreateInfos,
146 const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, VkResult result,
147 void* ccpl_state_data);
148 void PostCallRecordCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
149 const VkRayTracingPipelineCreateInfoNV* pCreateInfos,
150 const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, VkResult result,
151 void* crtpl_state_data);
Tony-LunarG04717522019-10-17 10:41:17 -0600152 void PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator);
153 bool InstrumentShader(const VkShaderModuleCreateInfo* pCreateInfo, std::vector<unsigned int>& new_pgm,
154 uint32_t* unique_shader_id);
155 void PreCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo* pCreateInfo,
156 const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule,
157 void* csm_state_data);
Tony-LunarGb5fae462020-03-05 12:43:25 -0700158 std::vector<DPFSubstring> ParseFormatString(std::string format_string);
Tony-LunarG04717522019-10-17 10:41:17 -0600159 std::string FindFormatString(std::vector<unsigned int> pgm, uint32_t string_id);
Tony-LunarG1dce2392019-10-23 16:49:29 -0600160 void AnalyzeAndGenerateMessages(VkCommandBuffer command_buffer, VkQueue queue, VkPipelineBindPoint pipeline_bind_point,
161 uint32_t operation_index, uint32_t* const debug_output_buffer);
Tony-LunarG04717522019-10-17 10:41:17 -0600162 void PreCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex,
163 uint32_t firstInstance);
164 void PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount,
165 uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance);
166 void PreCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count,
167 uint32_t stride);
168 void PreCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count,
169 uint32_t stride);
Tony-LunarG2fb8ff02020-06-11 12:45:07 -0600170 void PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
171 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
172 uint32_t stride);
173 void PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
174 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
175 uint32_t stride);
176 void PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
177 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
178 uint32_t stride);
179 void PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
180 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
181 uint32_t stride);
Tony-LunarG54176fb2020-12-02 10:47:22 -0700182 void PreCallRecordCmdDrawIndirectByteCountEXT(VkCommandBuffer commandBuffer, uint32_t instanceCount, uint32_t firstInstance,
183 VkBuffer counterBuffer, VkDeviceSize counterBufferOffset, uint32_t counterOffset,
184 uint32_t vertexStride);
Tony-LunarG2fb8ff02020-06-11 12:45:07 -0600185 void PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount, uint32_t firstTask);
186 void PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
187 uint32_t drawCount, uint32_t stride);
188 void PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
189 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
190 uint32_t stride);
Tony-LunarG04717522019-10-17 10:41:17 -0600191 void PreCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z);
192 void PreCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset);
Tony-LunarGd13f9b52020-09-08 15:45:45 -0600193 void PreCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY, uint32_t baseGroupZ,
194 uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ);
Tony-LunarG52c8c602020-09-10 16:29:56 -0600195 void PreCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY,
196 uint32_t baseGroupZ, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ);
Tony-LunarG04717522019-10-17 10:41:17 -0600197 void PreCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
198 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
199 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
200 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
201 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
202 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
203 uint32_t width, uint32_t height, uint32_t depth);
204 void PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
205 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
206 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
207 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
208 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
209 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
210 uint32_t width, uint32_t height, uint32_t depth);
sourav parmarcd5fb182020-07-17 12:58:44 -0700211 void PreCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
212 const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable,
213 const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable,
214 const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable,
215 const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, uint32_t width,
216 uint32_t height, uint32_t depth);
217 void PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
218 const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable,
219 const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable,
220 const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable,
221 const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, uint32_t width,
222 uint32_t height, uint32_t depth);
Tony-LunarG1dce2392019-10-23 16:49:29 -0600223 void PreCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
sourav parmarcd5fb182020-07-17 12:58:44 -0700224 const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable,
225 const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable,
226 const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable,
Shannon McPherson54e1f892020-11-27 11:04:19 -0700227 const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable,
228 VkDeviceAddress indirectDeviceAddress);
Tony-LunarG1dce2392019-10-23 16:49:29 -0600229 void PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
sourav parmarcd5fb182020-07-17 12:58:44 -0700230 const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable,
231 const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable,
232 const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable,
Shannon McPherson54e1f892020-11-27 11:04:19 -0700233 const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable,
234 VkDeviceAddress indirectDeviceAddress);
Tony-LunarG04717522019-10-17 10:41:17 -0600235 void PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence,
236 VkResult result);
Tony-LunarGb5fae462020-03-05 12:43:25 -0700237 void AllocateDebugPrintfResources(const VkCommandBuffer cmd_buffer, const VkPipelineBindPoint bind_point);
Tony-LunarG04717522019-10-17 10:41:17 -0600238};