blob: 0aadd11cdb4d790661fff286d6e9a6e3d0ef9b7c [file] [log] [blame]
Tony-LunarG4c253372022-01-18 13:51:07 -07001/* Copyright (c) 2018-2022 The Khronos Group Inc.
2 * Copyright (c) 2018-2022 Valve Corporation
3 * Copyright (c) 2018-2022 LunarG, Inc.
Karl Schultz7b024b42018-08-30 16:18:18 -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 *
Tony-LunarG2ba1cb32019-09-25 15:16:11 -060017 * Author: Karl Schultz <karl@lunarg.com>
18 * Author: Tony Barbour <tony@lunarg.com>
Karl Schultz7b024b42018-08-30 16:18:18 -060019 */
20
Tony-LunarG2ba1cb32019-09-25 15:16:11 -060021#pragma once
22
23#include "chassis.h"
24#include "state_tracker.h"
Tony-LunarG0e564722019-03-19 16:09:14 -060025#include "vk_mem_alloc.h"
Tony-LunarGb5fae462020-03-05 12:43:25 -070026#include "gpu_utils.h"
Tony-LunarG2ba1cb32019-09-25 15:16:11 -060027class GpuAssisted;
Tony-LunarG0e564722019-03-19 16:09:14 -060028
Tony-LunarG2ba1cb32019-09-25 15:16:11 -060029struct GpuAssistedDeviceMemoryBlock {
Mark Lobodzinski2a3ee4a2019-03-13 13:11:39 -060030 VkBuffer buffer;
Tony-LunarG0e564722019-03-19 16:09:14 -060031 VmaAllocation allocation;
Jeremy Gebbencbf22862021-03-03 12:01:22 -070032 layer_data::unordered_map<uint32_t, const cvdescriptorset::Descriptor*> update_at_submit;
Mark Lobodzinski2a3ee4a2019-03-13 13:11:39 -060033};
34
Tony-LunarGa3ec16c2021-04-06 12:19:57 -060035struct GpuAssistedPreDrawResources {
36 VkDescriptorPool desc_pool;
37 VkDescriptorSet desc_set;
Tony-LunarGf0d4e2b2021-04-14 11:52:28 -060038 VkBuffer buffer;
39 VkDeviceSize offset;
40 uint32_t stride;
41 VkDeviceSize buf_size;
Tony-LunarGa3ec16c2021-04-06 12:19:57 -060042};
43
Tony-LunarG2ba1cb32019-09-25 15:16:11 -060044struct GpuAssistedBufferInfo {
45 GpuAssistedDeviceMemoryBlock output_mem_block;
46 GpuAssistedDeviceMemoryBlock di_input_mem_block; // Descriptor Indexing input
47 GpuAssistedDeviceMemoryBlock bda_input_mem_block; // Buffer Device Address input
Tony-LunarGa3ec16c2021-04-06 12:19:57 -060048 GpuAssistedPreDrawResources pre_draw_resources;
Mark Lobodzinski2a3ee4a2019-03-13 13:11:39 -060049 VkDescriptorSet desc_set;
50 VkDescriptorPool desc_pool;
Jason Macnak67407e72019-07-11 11:05:09 -070051 VkPipelineBindPoint pipeline_bind_point;
Tony-LunarG7de10e82020-11-24 11:31:55 -070052 CMD_TYPE cmd_type;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -060053 GpuAssistedBufferInfo(GpuAssistedDeviceMemoryBlock output_mem_block, GpuAssistedDeviceMemoryBlock di_input_mem_block,
Tony-LunarGa3ec16c2021-04-06 12:19:57 -060054 GpuAssistedDeviceMemoryBlock bda_input_mem_block, GpuAssistedPreDrawResources pre_draw_resources,
55 VkDescriptorSet desc_set, VkDescriptorPool desc_pool, VkPipelineBindPoint pipeline_bind_point,
56 CMD_TYPE cmd_type)
Jason Macnak67407e72019-07-11 11:05:09 -070057 : output_mem_block(output_mem_block),
Tony-LunarG8eb5a002019-07-25 16:49:00 -060058 di_input_mem_block(di_input_mem_block),
59 bda_input_mem_block(bda_input_mem_block),
Tony-LunarGa3ec16c2021-04-06 12:19:57 -060060 pre_draw_resources(pre_draw_resources),
Jason Macnak67407e72019-07-11 11:05:09 -070061 desc_set(desc_set),
62 desc_pool(desc_pool),
Tony-LunarG7de10e82020-11-24 11:31:55 -070063 pipeline_bind_point(pipeline_bind_point),
64 cmd_type(cmd_type){};
Mark Lobodzinski2a3ee4a2019-03-13 13:11:39 -060065};
66
Tony-LunarG2ba1cb32019-09-25 15:16:11 -060067struct GpuAssistedShaderTracker {
68 VkPipeline pipeline;
69 VkShaderModule shader_module;
sfricke-samsung7fac88a2022-01-26 11:44:22 -080070 std::vector<uint32_t> pgm;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -060071};
72
Tony-LunarG7de10e82020-11-24 11:31:55 -070073struct GpuVuid {
74 const char* uniform_access_oob = kVUIDUndefined;
75 const char* storage_access_oob = kVUIDUndefined;
Tony-LunarG64aeaf72021-04-14 11:13:35 -060076 const char* count_exceeds_bufsize_1 = kVUIDUndefined;
77 const char* count_exceeds_bufsize = kVUIDUndefined;
Tony-LunarG1a7c9f92021-04-29 16:04:42 -060078 const char* count_exceeds_device_limit = kVUIDUndefined;
Tony-LunarG3723a3a2021-05-04 14:52:39 -060079 const char* first_instance_not_zero = kVUIDUndefined;
Tony-LunarG7de10e82020-11-24 11:31:55 -070080};
81
Tony-LunarG2ba1cb32019-09-25 15:16:11 -060082struct GpuAssistedAccelerationStructureBuildValidationBufferInfo {
Jason Macnak83cfd582019-07-31 10:14:24 -070083 // The acceleration structure that is being built.
84 VkAccelerationStructureNV acceleration_structure = VK_NULL_HANDLE;
85
86 // The descriptor pool and descriptor set being used to validate a given build.
87 VkDescriptorPool descriptor_pool = VK_NULL_HANDLE;
88 VkDescriptorSet descriptor_set = VK_NULL_HANDLE;
89
90 // The storage buffer used by the validating compute shader whichcontains info about
91 // the valid handles and which is written to communicate found invalid handles.
92 VkBuffer validation_buffer = VK_NULL_HANDLE;
93 VmaAllocation validation_buffer_allocation = VK_NULL_HANDLE;
94};
95
Tony-LunarG2ba1cb32019-09-25 15:16:11 -060096struct GpuAssistedAccelerationStructureBuildValidationState {
Jason Macnak83cfd582019-07-31 10:14:24 -070097 bool initialized = false;
98
99 VkPipeline pipeline = VK_NULL_HANDLE;
100 VkPipelineLayout pipeline_layout = VK_NULL_HANDLE;
101
102 VkAccelerationStructureNV replacement_as = VK_NULL_HANDLE;
103 VmaAllocation replacement_as_allocation = VK_NULL_HANDLE;
104 uint64_t replacement_as_handle = 0;
105
Jason Macnak83cfd582019-07-31 10:14:24 -0700106};
107
Tony-LunarGa3ec16c2021-04-06 12:19:57 -0600108struct GpuAssistedPreDrawValidationState {
109 bool globals_created = false;
110 VkShaderModule validation_shader_module = VK_NULL_HANDLE;
111 VkDescriptorSetLayout validation_ds_layout = VK_NULL_HANDLE;
112 VkPipelineLayout validation_pipeline_layout = VK_NULL_HANDLE;
Tony-LunarG463bae32022-02-25 09:31:17 -0700113 VkPipeline dyn_rendering_pipeline = VK_NULL_HANDLE;
Tony-LunarGa3ec16c2021-04-06 12:19:57 -0600114 layer_data::unordered_map <VkRenderPass, VkPipeline> renderpass_to_pipeline;
115};
116
117struct GpuAssistedCmdDrawIndirectState {
118 VkBuffer buffer;
119 VkDeviceSize offset;
Tony-LunarG3723a3a2021-05-04 14:52:39 -0600120 uint32_t drawCount;
Tony-LunarGa3ec16c2021-04-06 12:19:57 -0600121 uint32_t stride;
122 VkBuffer count_buffer;
123 VkDeviceSize count_buffer_offset;
124};
125
Jeremy Gebben135550d2022-03-21 07:15:07 -0600126namespace gpuav_state {
127class CommandBuffer : public CMD_BUFFER_STATE {
Jeremy Gebbenf6bb4bb2021-08-11 15:41:09 -0600128 public:
129 std::vector<GpuAssistedBufferInfo> gpuav_buffer_list;
130 std::vector<GpuAssistedAccelerationStructureBuildValidationBufferInfo> as_validation_buffers;
131
Jeremy Gebben135550d2022-03-21 07:15:07 -0600132 CommandBuffer(GpuAssisted* ga, VkCommandBuffer cb, const VkCommandBufferAllocateInfo* pCreateInfo,
133 const COMMAND_POOL_STATE* pool);
Jeremy Gebbenf6bb4bb2021-08-11 15:41:09 -0600134
135 void Reset() final;
136};
Jeremy Gebben135550d2022-03-21 07:15:07 -0600137}; // namespace gpuav_state
Jeremy Gebbenf6bb4bb2021-08-11 15:41:09 -0600138
Jeremy Gebben135550d2022-03-21 07:15:07 -0600139VALSTATETRACK_DERIVED_STATE_OBJECT(VkCommandBuffer, gpuav_state::CommandBuffer, CMD_BUFFER_STATE);
Jeremy Gebben78684b12022-02-23 17:31:56 -0700140
Tony-LunarG99b880b2019-09-26 11:19:52 -0600141class GpuAssisted : public ValidationStateTracker {
Tony-LunarG1dce2392019-10-23 16:49:29 -0600142 public:
Mark Lobodzinski0dcb87d2020-03-30 16:09:24 -0600143 GpuAssisted() { container_type = LayerObjectTypeGpuAssisted; }
144
Mark Lobodzinskia8151b02020-02-27 13:38:08 -0700145 template <typename T>
146 void ReportSetupProblem(T object, const char* const specific_message) const;
Tony-LunarG5c38b182020-06-10 16:15:32 -0600147 bool CheckForDescriptorIndexing(DeviceFeatures enabled_features) const;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600148 void PreCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700149 const VkAllocationCallbacks* pAllocator, VkDevice* pDevice, void* modified_create_info) override;
Jeremy Gebben36a3b832022-03-23 10:54:18 -0600150 void CreateDevice(const VkDeviceCreateInfo* pCreateInfo) override;
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700151 void PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator) override;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600152 void PostCallRecordBindAccelerationStructureMemoryNV(VkDevice device, uint32_t bindInfoCount,
153 const VkBindAccelerationStructureMemoryInfoNV* pBindInfos,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700154 VkResult result) override;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600155 void PreCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo,
156 const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700157 void* cpl_state_data) override;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600158 void PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo,
159 const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700160 VkResult result) override;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600161 bool PreCallValidateCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
162 VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask,
163 uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
164 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700165 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers) const override;
Jeremy Gebbena3705f42021-01-19 16:47:43 -0700166 bool PreCallValidateCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
167 const VkDependencyInfoKHR* pDependencyInfos) const override;
Tony-LunarG1364cf52021-11-17 16:10:11 -0700168 bool PreCallValidateCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents,
169 const VkDependencyInfo* pDependencyInfos) const override;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600170 void PreCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700171 VkBuffer* pBuffer, void* cb_state_data) override;
Jeremy Gebben21782012022-03-15 16:23:27 -0600172 void CreateAccelerationStructureBuildValidationState();
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600173 void DestroyAccelerationStructureBuildValidationState();
174 void PreCallRecordCmdBuildAccelerationStructureNV(VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV* pInfo,
175 VkBuffer instanceData, VkDeviceSize instanceOffset, VkBool32 update,
176 VkAccelerationStructureNV dst, VkAccelerationStructureNV src,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700177 VkBuffer scratch, VkDeviceSize scratchOffset) override;
Jeremy Gebben135550d2022-03-21 07:15:07 -0600178 void ProcessAccelerationStructureBuildValidationBuffer(VkQueue queue, gpuav_state::CommandBuffer* cb_node);
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600179 void PreCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
180 const VkGraphicsPipelineCreateInfo* pCreateInfos,
181 const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700182 void* cgpl_state_data) override;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600183 void PreCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
184 const VkComputePipelineCreateInfo* pCreateInfos,
185 const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700186 void* ccpl_state_data) override;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600187 void PreCallRecordCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
188 const VkRayTracingPipelineCreateInfoNV* pCreateInfos,
189 const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700190 void* crtpl_state_data) override;
sourav parmarcd5fb182020-07-17 12:58:44 -0700191 void PreCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
192 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -0500193 const VkRayTracingPipelineCreateInfoKHR* pCreateInfos,
194 const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700195 void* crtpl_state_data) override;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600196 void PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
197 const VkGraphicsPipelineCreateInfo* pCreateInfos,
198 const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, VkResult result,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700199 void* cgpl_state_data) override;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600200 void PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
201 const VkComputePipelineCreateInfo* pCreateInfos,
202 const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, VkResult result,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700203 void* ccpl_state_data) override;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600204 void PostCallRecordCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
205 const VkRayTracingPipelineCreateInfoNV* pCreateInfos,
206 const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines, VkResult result,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700207 void* crtpl_state_data) override;
sourav parmarcd5fb182020-07-17 12:58:44 -0700208 void PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
209 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -0500210 const VkRayTracingPipelineCreateInfoKHR* pCreateInfos,
211 const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700212 VkResult result, void* crtpl_state_data) override;
213 void PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator) override;
Tony-LunarGa3ec16c2021-04-06 12:19:57 -0600214 void PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks *pAllocator) override;
sfricke-samsung7fac88a2022-01-26 11:44:22 -0800215 bool InstrumentShader(const VkShaderModuleCreateInfo* pCreateInfo, std::vector<uint32_t>& new_pgm, uint32_t* unique_shader_id);
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600216 void PreCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo* pCreateInfo,
217 const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700218 void* csm_state_data) override;
Tony-LunarG7de10e82020-11-24 11:31:55 -0700219 void AnalyzeAndGenerateMessages(VkCommandBuffer command_buffer, VkQueue queue, GpuAssistedBufferInfo &buffer_info,
220 uint32_t operation_index, uint32_t* const debug_output_buffer);
sfricke-samsung7fac88a2022-01-26 11:44:22 -0800221
Tony-LunarGc28e28a2020-08-14 10:37:48 -0600222 void SetDescriptorInitialized(uint32_t* pData, uint32_t index, const cvdescriptorset::Descriptor* descriptor);
Jeremy Gebben135550d2022-03-21 07:15:07 -0600223 void UpdateInstrumentationBuffer(gpuav_state::CommandBuffer* cb_node);
Tony-LunarG7de10e82020-11-24 11:31:55 -0700224 const GpuVuid& GetGpuVuid(CMD_TYPE cmd_type) const;
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700225 void PreCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence) override;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600226 void PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700227 VkResult result) override;
Jeremy Gebbena3705f42021-01-19 16:47:43 -0700228 void PreCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR* pSubmits,
229 VkFence fence) override;
Tony-LunarG26fe2842021-11-16 14:07:59 -0700230 void PreCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2* pSubmits, VkFence fence) override;
231 void RecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR* pSubmits, VkFence fence, VkResult result);
Jeremy Gebbena3705f42021-01-19 16:47:43 -0700232 void PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR* pSubmits, VkFence fence,
233 VkResult result) override;
Tony-LunarG26fe2842021-11-16 14:07:59 -0700234 void PostCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2* pSubmits, VkFence fence,
235 VkResult result) override;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600236 void PreCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700237 uint32_t firstInstance) override;
Tony-LunarG745150c2021-07-02 15:07:31 -0600238 void PreCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount, const VkMultiDrawInfoEXT* pVertexInfo,
239 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride) override;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600240 void PreCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700241 uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance) override;
Tony-LunarG745150c2021-07-02 15:07:31 -0600242 void PreCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
243 const VkMultiDrawIndexedInfoEXT* pIndexInfo, uint32_t instanceCount,
244 uint32_t firstInstance, uint32_t stride, const int32_t* pVertexOffset) override;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600245 void PreCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700246 uint32_t stride) override;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600247 void PreCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700248 uint32_t stride) override;
Tony-LunarG2fb8ff02020-06-11 12:45:07 -0600249 void PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
250 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700251 uint32_t stride) override;
Tony-LunarG2fb8ff02020-06-11 12:45:07 -0600252 void PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
253 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700254 uint32_t stride) override;
Tony-LunarG54176fb2020-12-02 10:47:22 -0700255 void PreCallRecordCmdDrawIndirectByteCountEXT(VkCommandBuffer commandBuffer, uint32_t instanceCount, uint32_t firstInstance,
256 VkBuffer counterBuffer, VkDeviceSize counterBufferOffset, uint32_t counterOffset,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700257 uint32_t vertexStride) override;
Tony-LunarG2fb8ff02020-06-11 12:45:07 -0600258 void PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
259 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700260 uint32_t stride) override;
Tony-LunarG2fb8ff02020-06-11 12:45:07 -0600261 void PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
262 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700263 uint32_t stride) override;
264 void PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount, uint32_t firstTask) override;
Tony-LunarG2fb8ff02020-06-11 12:45:07 -0600265 void PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700266 uint32_t drawCount, uint32_t stride) override;
Tony-LunarG2fb8ff02020-06-11 12:45:07 -0600267 void PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
268 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700269 uint32_t stride) override;
270 void PreCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) override;
271 void PreCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset) override;
Tony-LunarGd13f9b52020-09-08 15:45:45 -0600272 void PreCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY, uint32_t baseGroupZ,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700273 uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) override;
Tony-LunarG52c8c602020-09-10 16:29:56 -0600274 void PreCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700275 uint32_t baseGroupZ, uint32_t groupCountX, uint32_t groupCountY,
276 uint32_t groupCountZ) override;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600277 void PreCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
278 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
279 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
280 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
281 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
282 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700283 uint32_t width, uint32_t height, uint32_t depth) override;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600284 void PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
285 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
286 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
287 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
288 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
289 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700290 uint32_t width, uint32_t height, uint32_t depth) override;
sourav parmarcd5fb182020-07-17 12:58:44 -0700291 void PreCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
292 const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable,
293 const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable,
294 const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable,
295 const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, uint32_t width,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700296 uint32_t height, uint32_t depth) override;
sourav parmarcd5fb182020-07-17 12:58:44 -0700297 void PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
298 const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable,
299 const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable,
300 const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable,
301 const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, uint32_t width,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700302 uint32_t height, uint32_t depth) override;
Jeff Bolz443c2ca2020-03-19 12:11:51 -0500303 void PreCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
sourav parmarcd5fb182020-07-17 12:58:44 -0700304 const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable,
305 const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable,
306 const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable,
Shannon McPherson54e1f892020-11-27 11:04:19 -0700307 const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700308 VkDeviceAddress indirectDeviceAddress) override;
Jeff Bolz443c2ca2020-03-19 12:11:51 -0500309 void PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
sourav parmarcd5fb182020-07-17 12:58:44 -0700310 const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable,
311 const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable,
312 const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable,
Shannon McPherson54e1f892020-11-27 11:04:19 -0700313 const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700314 VkDeviceAddress indirectDeviceAddress) override;
Tony-LunarGa3ec16c2021-04-06 12:19:57 -0600315 void AllocateValidationResources(const VkCommandBuffer cmd_buffer, const VkPipelineBindPoint bind_point, CMD_TYPE cmd, const GpuAssistedCmdDrawIndirectState *cdic_state = nullptr);
316 void AllocatePreDrawValidationResources(GpuAssistedDeviceMemoryBlock output_block, GpuAssistedPreDrawResources& resources,
317 const LAST_BOUND_STATE& state, VkPipeline *pPipeline, const GpuAssistedCmdDrawIndirectState *cdic_state);
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600318 void PostCallRecordGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700319 VkPhysicalDeviceProperties* pPhysicalDeviceProperties) override;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600320 void PostCallRecordGetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
Mark Lobodzinskib8e22b52020-12-03 15:22:35 -0700321 VkPhysicalDeviceProperties2* pPhysicalDeviceProperties2) override;
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600322
Jeremy Gebben9f537102021-10-05 16:37:12 -0600323 std::shared_ptr<SHADER_MODULE_STATE> GetShaderModuleState(VkShaderModule shader_module) {
324 return Get<SHADER_MODULE_STATE>(shader_module);
325 }
326 std::shared_ptr<const SHADER_MODULE_STATE> GetShaderModuleState(VkShaderModule shader_module) const {
327 return Get<SHADER_MODULE_STATE>(shader_module);
328 }
329 std::shared_ptr<const PIPELINE_STATE> GetPipelineState(VkPipeline pipeline) const { return Get<PIPELINE_STATE>(pipeline); }
330 std::shared_ptr<PIPELINE_STATE> GetPipelineState(VkPipeline pipeline) { return Get<PIPELINE_STATE>(pipeline); }
331
Jeremy Gebbenf6bb4bb2021-08-11 15:41:09 -0600332 const std::vector<GpuAssistedBufferInfo>& GetBufferInfo(const CMD_BUFFER_STATE* cb_node) const {
333 assert(cb_node);
Jeremy Gebben135550d2022-03-21 07:15:07 -0600334 return static_cast<const gpuav_state::CommandBuffer*>(cb_node)->gpuav_buffer_list;
Jeremy Gebbenf6bb4bb2021-08-11 15:41:09 -0600335 }
336
337 std::vector<GpuAssistedBufferInfo>& GetBufferInfo(CMD_BUFFER_STATE* cb_node) {
338 assert(cb_node);
Jeremy Gebben135550d2022-03-21 07:15:07 -0600339 return static_cast<gpuav_state::CommandBuffer*>(cb_node)->gpuav_buffer_list;
Jeremy Gebbenf6bb4bb2021-08-11 15:41:09 -0600340 }
341
342 std::shared_ptr<CMD_BUFFER_STATE> CreateCmdBufferState(VkCommandBuffer cb, const VkCommandBufferAllocateInfo* create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -0600343 const COMMAND_POOL_STATE* pool) final;
Jeremy Gebbenf6bb4bb2021-08-11 15:41:09 -0600344
345 void DestroyBuffer(GpuAssistedBufferInfo& buffer_info);
346 void DestroyBuffer(GpuAssistedAccelerationStructureBuildValidationBufferInfo& buffer_info);
Jeremy Gebben14499e82022-03-17 11:03:10 -0600347
348 private:
349 void PreRecordCommandBuffer(VkCommandBuffer command_buffer);
350 bool CommandBufferNeedsProcessing(VkCommandBuffer command_buffer);
351 void ProcessCommandBuffer(VkQueue queue, VkCommandBuffer command_buffer);
352
353 VkPhysicalDeviceFeatures supported_features;
354 VkBool32 shaderInt64;
355 uint32_t unique_shader_module_id = 0;
356 uint32_t output_buffer_size;
357 bool buffer_oob_enabled;
358 bool validate_draw_indirect;
Jeremy Gebben14499e82022-03-17 11:03:10 -0600359 GpuAssistedAccelerationStructureBuildValidationState acceleration_structure_validation_state;
360 GpuAssistedPreDrawValidationState pre_draw_validation_state;
361
362 public:
363 bool aborted = false;
364 bool descriptor_indexing = false;
365 uint32_t adjusted_max_desc_sets;
366 uint32_t desc_set_bind_index;
367 VkDescriptorSetLayout debug_desc_layout = VK_NULL_HANDLE;
368 VkDescriptorSetLayout dummy_desc_layout = VK_NULL_HANDLE;
369 std::unique_ptr<UtilDescriptorSetManager> desc_set_manager;
370 layer_data::unordered_map<uint32_t, GpuAssistedShaderTracker> shader_map;
371 PFN_vkSetDeviceLoaderData vkSetDeviceLoaderData;
372 VmaAllocator vmaAllocator = {};
373 std::map<VkQueue, UtilQueueBarrierCommandInfo> queue_barrier_command_infos;
Tony-LunarG2ba1cb32019-09-25 15:16:11 -0600374};