blob: 2e2f3de2b2e2ac33d206376df05342f1fb7af195 [file] [log] [blame]
Jeremy Gebben4d51c552022-01-06 21:27:15 -07001/* Copyright (c) 2015-2022 The Khronos Group Inc.
2 * Copyright (c) 2015-2022 Valve Corporation
3 * Copyright (c) 2015-2022 LunarG, Inc.
4 * Copyright (C) 2015-2022 Google Inc.
Jeremy Gebben159b3cc2021-06-03 09:09:03 -06005 * Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * Author: Courtney Goeltzenleuchter <courtneygo@google.com>
20 * Author: Tobin Ehlis <tobine@google.com>
21 * Author: Chris Forbes <chrisf@ijw.co.nz>
22 * Author: Mark Lobodzinski <mark@lunarg.com>
23 * Author: Dave Houlton <daveh@lunarg.com>
24 * Author: John Zulauf <jzulauf@lunarg.com>
25 * Author: Tobias Hector <tobias.hector@amd.com>
26 */
27#include "cmd_buffer_state.h"
28#include "render_pass_state.h"
Jeremy Gebben1ec89332021-08-05 13:51:49 -060029#include "state_tracker.h"
30#include "image_state.h"
Jeremy Gebben159b3cc2021-06-03 09:09:03 -060031
Jeremy Gebbencd7fa282021-10-27 10:25:32 -060032COMMAND_POOL_STATE::COMMAND_POOL_STATE(ValidationStateTracker *dev, VkCommandPool cp, const VkCommandPoolCreateInfo *pCreateInfo,
33 VkQueueFlags flags)
34 : BASE_NODE(cp, kVulkanObjectTypeCommandPool),
35 dev_data(dev),
36 createFlags(pCreateInfo->flags),
37 queueFamilyIndex(pCreateInfo->queueFamilyIndex),
38 queue_flags(flags),
39 unprotected((pCreateInfo->flags & VK_COMMAND_POOL_CREATE_PROTECTED_BIT) == 0) {}
40
41void COMMAND_POOL_STATE::Allocate(const VkCommandBufferAllocateInfo *create_info, const VkCommandBuffer *command_buffers) {
42 for (uint32_t i = 0; i < create_info->commandBufferCount; i++) {
43 auto new_cb = dev_data->CreateCmdBufferState(command_buffers[i], create_info, this);
44 commandBuffers.emplace(command_buffers[i], new_cb.get());
Jeremy Gebben082a9832021-10-28 13:40:11 -060045 dev_data->Add(std::move(new_cb));
Jeremy Gebbencd7fa282021-10-27 10:25:32 -060046 }
47}
48
49void COMMAND_POOL_STATE::Free(uint32_t count, const VkCommandBuffer *command_buffers) {
50 for (uint32_t i = 0; i < count; i++) {
51 auto iter = commandBuffers.find(command_buffers[i]);
52 if (iter != commandBuffers.end()) {
Jeremy Gebben082a9832021-10-28 13:40:11 -060053 dev_data->Destroy<CMD_BUFFER_STATE>(iter->first);
Jeremy Gebbencd7fa282021-10-27 10:25:32 -060054 commandBuffers.erase(iter);
55 }
56 }
57}
58
59void COMMAND_POOL_STATE::Reset() {
60 for (auto &entry : commandBuffers) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -070061 auto guard = entry.second->WriteLock();
Jeremy Gebbencd7fa282021-10-27 10:25:32 -060062 entry.second->Reset();
63 }
64}
65
66void COMMAND_POOL_STATE::Destroy() {
67 for (auto &entry : commandBuffers) {
Jeremy Gebben082a9832021-10-28 13:40:11 -060068 dev_data->Destroy<CMD_BUFFER_STATE>(entry.first);
Jeremy Gebbencd7fa282021-10-27 10:25:32 -060069 }
70 commandBuffers.clear();
71 BASE_NODE::Destroy();
72}
73
Jeremy Gebben159b3cc2021-06-03 09:09:03 -060074const char *CommandTypeString(CMD_TYPE type) {
75 // Autogenerated as part of the command_validation.h codegen
76 return kGeneratedCommandNameList[type];
77}
78
79VkDynamicState ConvertToDynamicState(CBStatusFlagBits flag) {
80 switch (flag) {
81 case CBSTATUS_LINE_WIDTH_SET:
82 return VK_DYNAMIC_STATE_LINE_WIDTH;
83 case CBSTATUS_DEPTH_BIAS_SET:
84 return VK_DYNAMIC_STATE_DEPTH_BIAS;
85 case CBSTATUS_BLEND_CONSTANTS_SET:
86 return VK_DYNAMIC_STATE_BLEND_CONSTANTS;
87 case CBSTATUS_DEPTH_BOUNDS_SET:
88 return VK_DYNAMIC_STATE_DEPTH_BOUNDS;
89 case CBSTATUS_STENCIL_READ_MASK_SET:
90 return VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK;
91 case CBSTATUS_STENCIL_WRITE_MASK_SET:
92 return VK_DYNAMIC_STATE_STENCIL_WRITE_MASK;
93 case CBSTATUS_STENCIL_REFERENCE_SET:
94 return VK_DYNAMIC_STATE_STENCIL_REFERENCE;
95 case CBSTATUS_VIEWPORT_SET:
96 return VK_DYNAMIC_STATE_VIEWPORT;
97 case CBSTATUS_SCISSOR_SET:
98 return VK_DYNAMIC_STATE_SCISSOR;
99 case CBSTATUS_EXCLUSIVE_SCISSOR_SET:
100 return VK_DYNAMIC_STATE_EXCLUSIVE_SCISSOR_NV;
101 case CBSTATUS_SHADING_RATE_PALETTE_SET:
102 return VK_DYNAMIC_STATE_VIEWPORT_SHADING_RATE_PALETTE_NV;
103 case CBSTATUS_LINE_STIPPLE_SET:
104 return VK_DYNAMIC_STATE_LINE_STIPPLE_EXT;
105 case CBSTATUS_VIEWPORT_W_SCALING_SET:
106 return VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV;
107 case CBSTATUS_CULL_MODE_SET:
108 return VK_DYNAMIC_STATE_CULL_MODE_EXT;
109 case CBSTATUS_FRONT_FACE_SET:
110 return VK_DYNAMIC_STATE_FRONT_FACE_EXT;
111 case CBSTATUS_PRIMITIVE_TOPOLOGY_SET:
112 return VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY_EXT;
113 case CBSTATUS_VIEWPORT_WITH_COUNT_SET:
114 return VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT;
115 case CBSTATUS_SCISSOR_WITH_COUNT_SET:
116 return VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT_EXT;
117 case CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET:
118 return VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT;
119 case CBSTATUS_DEPTH_TEST_ENABLE_SET:
120 return VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE_EXT;
121 case CBSTATUS_DEPTH_WRITE_ENABLE_SET:
122 return VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE_EXT;
123 case CBSTATUS_DEPTH_COMPARE_OP_SET:
124 return VK_DYNAMIC_STATE_DEPTH_COMPARE_OP_EXT;
125 case CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET:
126 return VK_DYNAMIC_STATE_DEPTH_BOUNDS_TEST_ENABLE_EXT;
127 case CBSTATUS_STENCIL_TEST_ENABLE_SET:
128 return VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE_EXT;
129 case CBSTATUS_STENCIL_OP_SET:
130 return VK_DYNAMIC_STATE_STENCIL_OP_EXT;
131 case CBSTATUS_DISCARD_RECTANGLE_SET:
132 return VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT;
133 case CBSTATUS_SAMPLE_LOCATIONS_SET:
134 return VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT;
135 case CBSTATUS_COARSE_SAMPLE_ORDER_SET:
136 return VK_DYNAMIC_STATE_VIEWPORT_COARSE_SAMPLE_ORDER_NV;
137 case CBSTATUS_PATCH_CONTROL_POINTS_SET:
138 return VK_DYNAMIC_STATE_PATCH_CONTROL_POINTS_EXT;
139 case CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET:
140 return VK_DYNAMIC_STATE_RASTERIZER_DISCARD_ENABLE_EXT;
141 case CBSTATUS_DEPTH_BIAS_ENABLE_SET:
142 return VK_DYNAMIC_STATE_DEPTH_BIAS_ENABLE_EXT;
143 case CBSTATUS_LOGIC_OP_SET:
144 return VK_DYNAMIC_STATE_LOGIC_OP_EXT;
145 case CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET:
146 return VK_DYNAMIC_STATE_PRIMITIVE_RESTART_ENABLE_EXT;
147 case CBSTATUS_VERTEX_INPUT_SET:
148 return VK_DYNAMIC_STATE_VERTEX_INPUT_EXT;
ziga-lunarg67b7c392022-03-26 01:45:34 +0100149 case CBSTATUS_COLOR_WRITE_ENABLE_SET:
150 return VK_DYNAMIC_STATE_COLOR_WRITE_ENABLE_EXT;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600151 default:
152 // CBSTATUS_INDEX_BUFFER_BOUND is not in VkDynamicState
153 return VK_DYNAMIC_STATE_MAX_ENUM;
154 }
155 return VK_DYNAMIC_STATE_MAX_ENUM;
156}
157
158CBStatusFlagBits ConvertToCBStatusFlagBits(VkDynamicState state) {
159 switch (state) {
160 case VK_DYNAMIC_STATE_VIEWPORT:
161 return CBSTATUS_VIEWPORT_SET;
162 case VK_DYNAMIC_STATE_SCISSOR:
163 return CBSTATUS_SCISSOR_SET;
164 case VK_DYNAMIC_STATE_LINE_WIDTH:
165 return CBSTATUS_LINE_WIDTH_SET;
166 case VK_DYNAMIC_STATE_DEPTH_BIAS:
167 return CBSTATUS_DEPTH_BIAS_SET;
168 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
169 return CBSTATUS_BLEND_CONSTANTS_SET;
170 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
171 return CBSTATUS_DEPTH_BOUNDS_SET;
172 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
173 return CBSTATUS_STENCIL_READ_MASK_SET;
174 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
175 return CBSTATUS_STENCIL_WRITE_MASK_SET;
176 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
177 return CBSTATUS_STENCIL_REFERENCE_SET;
178 case VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV:
179 return CBSTATUS_VIEWPORT_W_SCALING_SET;
180 case VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT:
181 return CBSTATUS_DISCARD_RECTANGLE_SET;
182 case VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT:
183 return CBSTATUS_SAMPLE_LOCATIONS_SET;
184 case VK_DYNAMIC_STATE_VIEWPORT_SHADING_RATE_PALETTE_NV:
185 return CBSTATUS_SHADING_RATE_PALETTE_SET;
186 case VK_DYNAMIC_STATE_VIEWPORT_COARSE_SAMPLE_ORDER_NV:
187 return CBSTATUS_COARSE_SAMPLE_ORDER_SET;
188 case VK_DYNAMIC_STATE_EXCLUSIVE_SCISSOR_NV:
189 return CBSTATUS_EXCLUSIVE_SCISSOR_SET;
190 case VK_DYNAMIC_STATE_LINE_STIPPLE_EXT:
191 return CBSTATUS_LINE_STIPPLE_SET;
192 case VK_DYNAMIC_STATE_CULL_MODE_EXT:
193 return CBSTATUS_CULL_MODE_SET;
194 case VK_DYNAMIC_STATE_FRONT_FACE_EXT:
195 return CBSTATUS_FRONT_FACE_SET;
196 case VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY_EXT:
197 return CBSTATUS_PRIMITIVE_TOPOLOGY_SET;
198 case VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT:
199 return CBSTATUS_VIEWPORT_WITH_COUNT_SET;
200 case VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT_EXT:
201 return CBSTATUS_SCISSOR_WITH_COUNT_SET;
202 case VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT:
203 return CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
204 case VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE_EXT:
205 return CBSTATUS_DEPTH_TEST_ENABLE_SET;
206 case VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE_EXT:
207 return CBSTATUS_DEPTH_WRITE_ENABLE_SET;
208 case VK_DYNAMIC_STATE_DEPTH_COMPARE_OP_EXT:
209 return CBSTATUS_DEPTH_COMPARE_OP_SET;
210 case VK_DYNAMIC_STATE_DEPTH_BOUNDS_TEST_ENABLE_EXT:
211 return CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET;
212 case VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE_EXT:
213 return CBSTATUS_STENCIL_TEST_ENABLE_SET;
214 case VK_DYNAMIC_STATE_STENCIL_OP_EXT:
215 return CBSTATUS_STENCIL_OP_SET;
216 case VK_DYNAMIC_STATE_PATCH_CONTROL_POINTS_EXT:
217 return CBSTATUS_PATCH_CONTROL_POINTS_SET;
218 case VK_DYNAMIC_STATE_RASTERIZER_DISCARD_ENABLE_EXT:
219 return CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET;
220 case VK_DYNAMIC_STATE_DEPTH_BIAS_ENABLE_EXT:
221 return CBSTATUS_DEPTH_BIAS_ENABLE_SET;
222 case VK_DYNAMIC_STATE_LOGIC_OP_EXT:
223 return CBSTATUS_LOGIC_OP_SET;
224 case VK_DYNAMIC_STATE_PRIMITIVE_RESTART_ENABLE_EXT:
225 return CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET;
226 case VK_DYNAMIC_STATE_VERTEX_INPUT_EXT:
227 return CBSTATUS_VERTEX_INPUT_SET;
ziga-lunarg67b7c392022-03-26 01:45:34 +0100228 case VK_DYNAMIC_STATE_COLOR_WRITE_ENABLE_EXT:
229 return CBSTATUS_COLOR_WRITE_ENABLE_SET;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600230 default:
231 return CBSTATUS_NONE;
232 }
233 return CBSTATUS_NONE;
234}
235
Jeremy Gebbencd7fa282021-10-27 10:25:32 -0600236CMD_BUFFER_STATE::CMD_BUFFER_STATE(ValidationStateTracker *dev, VkCommandBuffer cb, const VkCommandBufferAllocateInfo *pCreateInfo,
237 const COMMAND_POOL_STATE *pool)
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600238 : REFCOUNTED_NODE(cb, kVulkanObjectTypeCommandBuffer),
239 createInfo(*pCreateInfo),
240 command_pool(pool),
Jeremy Gebbencd7fa282021-10-27 10:25:32 -0600241 dev_data(dev),
Jeremy Gebbenf087ddb2022-08-04 09:36:17 -0600242 unprotected(pool->unprotected),
243 lastBound({*this, *this, *this}) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600244 Reset();
245}
246
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600247// Get the image viewstate for a given framebuffer attachment
248IMAGE_VIEW_STATE *CMD_BUFFER_STATE::GetActiveAttachmentImageViewState(uint32_t index) {
249 assert(active_attachments && index != VK_ATTACHMENT_UNUSED && (index < active_attachments->size()));
250 return active_attachments->at(index);
251}
252
253// Get the image viewstate for a given framebuffer attachment
254const IMAGE_VIEW_STATE *CMD_BUFFER_STATE::GetActiveAttachmentImageViewState(uint32_t index) const {
ziga-lunarg452a5f92021-09-08 15:33:03 +0200255 if (!active_attachments || index == VK_ATTACHMENT_UNUSED || (index >= active_attachments->size())) {
256 return nullptr;
257 }
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600258 return active_attachments->at(index);
259}
260
Jeremy Gebben610d3a62022-01-01 12:53:17 -0700261void CMD_BUFFER_STATE::AddChild(std::shared_ptr<BASE_NODE> &child_node) {
Jeremy Gebbenc9a24032021-11-02 11:36:08 -0600262 assert(child_node);
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600263 if (child_node->AddParent(this)) {
Jeremy Gebbenc9a24032021-11-02 11:36:08 -0600264 object_bindings.insert(child_node);
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600265 }
266}
267
Jeremy Gebben610d3a62022-01-01 12:53:17 -0700268void CMD_BUFFER_STATE::RemoveChild(std::shared_ptr<BASE_NODE> &child_node) {
Jeremy Gebbenc9a24032021-11-02 11:36:08 -0600269 assert(child_node);
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600270 child_node->RemoveParent(this);
Jeremy Gebbenc9a24032021-11-02 11:36:08 -0600271 object_bindings.erase(child_node);
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600272}
273
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600274// Reset the command buffer state
275// Maintain the createInfo and set state to CB_NEW, but clear all other state
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600276void CMD_BUFFER_STATE::Reset() {
Jeremy Gebbened5fab52022-08-01 09:49:27 -0600277 assert(!InUse());
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600278 // Reset CB state (note that createInfo is not cleared)
279 memset(&beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
280 memset(&inheritanceInfo, 0, sizeof(VkCommandBufferInheritanceInfo));
sjfricke52defd42022-08-08 16:37:46 +0900281 has_draw_cmd = false;
Hans-Kristian Arntzen0f234382022-06-16 12:37:43 +0200282 has_draw_cmd_in_current_render_pass = false;
sjfricke52defd42022-08-08 16:37:46 +0900283 has_dispatch_cmd = false;
284 has_trace_rays_cmd = false;
285 has_build_as_cmd = false;
ziga-lunarg0acda6f2022-04-25 22:41:52 +0200286 hasRenderPassInstance = false;
287 suspendsRenderPassInstance = false;
288 resumesRenderPassInstance = false;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600289 state = CB_NEW;
290 commandCount = 0;
291 submitCount = 0;
292 image_layout_change_count = 1; // Start at 1. 0 is insert value for validation cache versions, s.t. new == dirty
293 status = 0;
294 static_status = 0;
295 inheritedViewportDepths.clear();
296 usedViewportScissorCount = 0;
297 pipelineStaticViewportCount = 0;
298 pipelineStaticScissorCount = 0;
299 viewportMask = 0;
300 viewportWithCountMask = 0;
301 viewportWithCountCount = 0;
302 scissorMask = 0;
303 scissorWithCountMask = 0;
304 scissorWithCountCount = 0;
305 trashedViewportMask = 0;
306 trashedScissorMask = 0;
307 trashedViewportCount = false;
308 trashedScissorCount = false;
309 usedDynamicViewportCount = false;
310 usedDynamicScissorCount = false;
311 primitiveTopology = VK_PRIMITIVE_TOPOLOGY_MAX_ENUM;
ziga-lunarg67b7c392022-03-26 01:45:34 +0100312 dynamicColorWriteEnableAttachmentCount = 0;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600313
314 activeRenderPassBeginInfo = safe_VkRenderPassBeginInfo();
315 activeRenderPass = nullptr;
316 active_attachments = nullptr;
317 active_subpasses = nullptr;
318 attachments_view_states.clear();
319 activeSubpassContents = VK_SUBPASS_CONTENTS_INLINE;
320 activeSubpass = 0;
321 broken_bindings.clear();
322 waitedEvents.clear();
323 events.clear();
324 writeEventsBeforeWait.clear();
325 activeQueries.clear();
326 startedQueries.clear();
327 image_layout_map.clear();
Jeremy Gebben4a8881f2022-01-10 17:04:30 -0700328 aliased_image_layout_map.clear();
paul-lunargf7101f12022-09-19 17:40:30 +0200329 descriptorset_cache.clear();
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600330 current_vertex_buffer_binding_info.vertex_buffer_bindings.clear();
331 vertex_buffer_used = false;
332 primaryCommandBuffer = VK_NULL_HANDLE;
333
334 linkedCommandBuffers.clear();
335 // Remove reverse command buffer links.
336 Invalidate(true);
337
338 queue_submit_functions.clear();
Hans-Kristian Arntzen59c2c3f2021-06-14 11:40:12 +0200339 queue_submit_functions_after_render_pass.clear();
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600340 cmd_execute_commands_functions.clear();
341 eventUpdates.clear();
342 queryUpdates.clear();
343
344 // Remove object bindings
345 for (const auto &obj : object_bindings) {
Jeremy Gebbenc9a24032021-11-02 11:36:08 -0600346 obj->RemoveParent(this);
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600347 }
348 object_bindings.clear();
349
350 for (auto &item : lastBound) {
351 item.Reset();
352 }
353 // Remove this cmdBuffer's reference from each FrameBuffer's CB ref list
354 for (auto &framebuffer : framebuffers) {
355 framebuffer->RemoveParent(this);
356 }
357 framebuffers.clear();
358 activeFramebuffer = VK_NULL_HANDLE;
359 index_buffer_binding.reset();
360
361 qfo_transfer_image_barriers.Reset();
362 qfo_transfer_buffer_barriers.Reset();
363
364 // Clean up the label data
365 debug_label.Reset();
366 validate_descriptorsets_in_queuesubmit.clear();
367
368 // Best practices info
369 small_indexed_draw_call_count = 0;
370
371 transform_feedback_active = false;
372
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600373 // Clean up the label data
374 ResetCmdDebugUtilsLabel(dev_data->report_data, commandBuffer());
375
376 if (dev_data->command_buffer_reset_callback) {
377 (*dev_data->command_buffer_reset_callback)(commandBuffer());
378 }
379}
380
381// Track which resources are in-flight by atomically incrementing their "in_use" count
382void CMD_BUFFER_STATE::IncrementResources() {
383 submitCount++;
384
385 // TODO : We should be able to remove the NULL look-up checks from the code below as long as
386 // all the corresponding cases are verified to cause CB_INVALID state and the CB_INVALID state
387 // should then be flagged prior to calling this function
388 for (auto event : writeEventsBeforeWait) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -0600389 auto event_state = dev_data->Get<EVENT_STATE>(event);
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600390 if (event_state) event_state->write_in_use++;
391 }
392}
393
394// Discussed in details in https://github.com/KhronosGroup/Vulkan-Docs/issues/1081
395// Internal discussion and CTS were written to prove that this is not called after an incompatible vkCmdBindPipeline
396// "Binding a pipeline with a layout that is not compatible with the push constant layout does not disturb the push constant values"
397//
398// vkCmdBindDescriptorSet has nothing to do with push constants and don't need to call this after neither
399//
400// Part of this assumes apps at draw/dispath/traceRays/etc time will have it properly compatabile or else other VU will be triggered
401void CMD_BUFFER_STATE::ResetPushConstantDataIfIncompatible(const PIPELINE_LAYOUT_STATE *pipeline_layout_state) {
402 if (pipeline_layout_state == nullptr) {
403 return;
404 }
405 if (push_constant_data_ranges == pipeline_layout_state->push_constant_ranges) {
406 return;
407 }
408
409 push_constant_data_ranges = pipeline_layout_state->push_constant_ranges;
410 push_constant_data.clear();
411 push_constant_data_update.clear();
412 uint32_t size_needed = 0;
413 for (const auto &push_constant_range : *push_constant_data_ranges) {
414 auto size = push_constant_range.offset + push_constant_range.size;
415 size_needed = std::max(size_needed, size);
416
417 auto stage_flags = push_constant_range.stageFlags;
418 uint32_t bit_shift = 0;
419 while (stage_flags) {
420 if (stage_flags & 1) {
421 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
422 const auto it = push_constant_data_update.find(flag);
423
424 if (it != push_constant_data_update.end()) {
425 if (it->second.size() < push_constant_range.offset) {
426 it->second.resize(push_constant_range.offset, PC_Byte_Not_Set);
427 }
428 if (it->second.size() < size) {
429 it->second.resize(size, PC_Byte_Not_Updated);
430 }
431 } else {
432 std::vector<uint8_t> bytes;
433 bytes.resize(push_constant_range.offset, PC_Byte_Not_Set);
434 bytes.resize(size, PC_Byte_Not_Updated);
435 push_constant_data_update[flag] = bytes;
436 }
437 }
438 stage_flags = stage_flags >> 1;
439 ++bit_shift;
440 }
441 }
442 push_constant_data.resize(size_needed, 0);
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600443}
444
445void CMD_BUFFER_STATE::Destroy() {
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600446 // Allow any derived class to clean up command buffer state
447 if (dev_data->command_buffer_reset_callback) {
448 (*dev_data->command_buffer_reset_callback)(commandBuffer());
449 }
450 if (dev_data->command_buffer_free_callback) {
451 (*dev_data->command_buffer_free_callback)(commandBuffer());
452 }
453
454 // Remove the cb debug labels
455 EraseCmdDebugUtilsLabel(dev_data->report_data, commandBuffer());
Jeremy Gebbenca406242022-08-03 19:31:00 -0600456 {
457 auto guard = WriteLock();
458 Reset();
459 }
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600460 BASE_NODE::Destroy();
461}
462
Jeremy Gebbenc9a24032021-11-02 11:36:08 -0600463void CMD_BUFFER_STATE::NotifyInvalidate(const BASE_NODE::NodeList &invalid_nodes, bool unlink) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700464 {
465 auto guard = WriteLock();
466 if (state == CB_RECORDING) {
467 state = CB_INVALID_INCOMPLETE;
468 } else if (state == CB_RECORDED) {
469 state = CB_INVALID_COMPLETE;
470 }
471 assert(!invalid_nodes.empty());
472 LogObjectList log_list;
Jeremy Gebben610d3a62022-01-01 12:53:17 -0700473 for (auto &obj : invalid_nodes) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700474 log_list.object_list.emplace_back(obj->Handle());
475 }
476 broken_bindings.emplace(invalid_nodes[0]->Handle(), log_list);
477
478 if (unlink) {
479 for (auto &obj : invalid_nodes) {
480 object_bindings.erase(obj);
481 switch (obj->Type()) {
482 case kVulkanObjectTypeCommandBuffer:
483 linkedCommandBuffers.erase(static_cast<CMD_BUFFER_STATE *>(obj.get()));
484 break;
485 case kVulkanObjectTypeImage:
486 image_layout_map.erase(static_cast<IMAGE_STATE *>(obj.get()));
487 break;
488 default:
489 break;
490 }
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600491 }
492 }
493 }
Jeremy Gebbenc9a24032021-11-02 11:36:08 -0600494 BASE_NODE::NotifyInvalidate(invalid_nodes, unlink);
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600495}
496
ziga-lunarg189ae5d2021-10-19 13:09:58 +0200497const CommandBufferImageLayoutMap& CMD_BUFFER_STATE::GetImageSubresourceLayoutMap() const { return image_layout_map; }
498
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600499// The const variant only need the image as it is the key for the map
Jeremy Gebben6335df62021-11-01 10:50:13 -0600500const ImageSubresourceLayoutMap *CMD_BUFFER_STATE::GetImageSubresourceLayoutMap(const IMAGE_STATE &image_state) const {
501 auto it = image_layout_map.find(&image_state);
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600502 if (it == image_layout_map.cend()) {
503 return nullptr;
504 }
Jeremy Gebben4a8881f2022-01-10 17:04:30 -0700505 return it->second.get();
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600506}
507
508// The non-const variant only needs the image state, as the factory requires it to construct a new entry
509ImageSubresourceLayoutMap *CMD_BUFFER_STATE::GetImageSubresourceLayoutMap(const IMAGE_STATE &image_state) {
Jeremy Gebben6335df62021-11-01 10:50:13 -0600510 auto &layout_map = image_layout_map[&image_state];
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600511 if (!layout_map) {
Jeremy Gebben4a8881f2022-01-10 17:04:30 -0700512 // Make sure we don't create a nullptr keyed entry for a zombie Image
513 if (image_state.Destroyed() || !image_state.layout_range_map) {
514 return nullptr;
515 }
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600516 // Was an empty slot... fill it in.
Jeremy Gebben4a8881f2022-01-10 17:04:30 -0700517 if (image_state.CanAlias()) {
518 // Aliasing images need to share the same local layout map.
519 // Since they use the same global layout state, use it as a key
520 // for the local state. We don't need a lock on the global range
521 // map to do a lookup based on its pointer.
522 const auto *global_layout_map = image_state.layout_range_map.get();
523 auto iter = aliased_image_layout_map.find(global_layout_map);
524 if (iter != aliased_image_layout_map.end()) {
525 layout_map = iter->second;
526 } else {
527 layout_map = std::make_shared<ImageSubresourceLayoutMap>(image_state);
528 // Save the local layout map for the next aliased image.
529 // The global layout map pointer is only used as a key into the local lookup
530 // table so it doesn't need to be locked.
531 aliased_image_layout_map.emplace(global_layout_map, layout_map);
532 }
533
534 } else {
535 layout_map = std::make_shared<ImageSubresourceLayoutMap>(image_state);
536 }
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600537 }
Jeremy Gebben4a8881f2022-01-10 17:04:30 -0700538 return layout_map.get();
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600539}
540
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600541static bool SetQueryState(QueryObject object, QueryState value, QueryMap *localQueryToStateMap) {
542 (*localQueryToStateMap)[object] = value;
543 return false;
544}
545
546void CMD_BUFFER_STATE::BeginQuery(const QueryObject &query_obj) {
547 activeQueries.insert(query_obj);
548 startedQueries.insert(query_obj);
Jeremy Gebben221bb372022-09-19 14:19:32 -0600549 queryUpdates.emplace_back([query_obj](CMD_BUFFER_STATE &cb_state_arg, bool do_validate, VkQueryPool &firstPerfQueryPool,
550 uint32_t perfQueryPass, QueryMap *localQueryToStateMap) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600551 SetQueryState(QueryObject(query_obj, perfQueryPass), QUERYSTATE_RUNNING, localQueryToStateMap);
552 return false;
553 });
ziga-lunarg96c7d822022-02-28 19:39:17 +0100554 updatedQueries.insert(query_obj);
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600555}
556
557void CMD_BUFFER_STATE::EndQuery(const QueryObject &query_obj) {
558 activeQueries.erase(query_obj);
Jeremy Gebben221bb372022-09-19 14:19:32 -0600559 queryUpdates.emplace_back([query_obj](CMD_BUFFER_STATE &cb_state_arg, bool do_validate, VkQueryPool &firstPerfQueryPool,
560 uint32_t perfQueryPass, QueryMap *localQueryToStateMap) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600561 return SetQueryState(QueryObject(query_obj, perfQueryPass), QUERYSTATE_ENDED, localQueryToStateMap);
562 });
ziga-lunarg96c7d822022-02-28 19:39:17 +0100563 updatedQueries.insert(query_obj);
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600564}
565
Jeremy Gebbenc615f792022-09-19 16:31:24 -0600566bool CMD_BUFFER_STATE::UpdatesQuery(const QueryObject &query_obj) const {
567 // Clear out the perf_pass from the caller because it isn't known when the command buffer is recorded.
568 auto key = query_obj;
569 key.perf_pass = 0;
Jeremy Gebben221bb372022-09-19 14:19:32 -0600570 for (auto *sub_cb : linkedCommandBuffers) {
571 auto guard = sub_cb->ReadLock();
572 if (sub_cb->updatedQueries.find(key) != sub_cb->updatedQueries.end()) {
573 return true;
574 }
575 }
Jeremy Gebbenc615f792022-09-19 16:31:24 -0600576 return updatedQueries.find(key) != updatedQueries.end();
577}
578
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600579static bool SetQueryStateMulti(VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount, uint32_t perfPass, QueryState value,
580 QueryMap *localQueryToStateMap) {
581 for (uint32_t i = 0; i < queryCount; i++) {
582 QueryObject object = QueryObject(QueryObject(queryPool, firstQuery + i), perfPass);
583 (*localQueryToStateMap)[object] = value;
584 }
585 return false;
586}
587
588void CMD_BUFFER_STATE::EndQueries(VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount) {
589 for (uint32_t slot = firstQuery; slot < (firstQuery + queryCount); slot++) {
590 QueryObject query = {queryPool, slot};
591 activeQueries.erase(query);
ziga-lunarg96c7d822022-02-28 19:39:17 +0100592 updatedQueries.insert(query);
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600593 }
Jeremy Gebben221bb372022-09-19 14:19:32 -0600594 queryUpdates.emplace_back([queryPool, firstQuery, queryCount](CMD_BUFFER_STATE &cb_state_arg, bool do_validate,
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600595 VkQueryPool &firstPerfQueryPool, uint32_t perfQueryPass,
596 QueryMap *localQueryToStateMap) {
Lars-Ivar Hesselberg Simonsen1a5646f2021-10-25 15:06:16 +0200597 return SetQueryStateMulti(queryPool, firstQuery, queryCount, perfQueryPass, QUERYSTATE_ENDED, localQueryToStateMap);
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600598 });
599}
600
601void CMD_BUFFER_STATE::ResetQueryPool(VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount) {
602 for (uint32_t slot = firstQuery; slot < (firstQuery + queryCount); slot++) {
603 QueryObject query = {queryPool, slot};
604 resetQueries.insert(query);
ziga-lunarg96c7d822022-02-28 19:39:17 +0100605 updatedQueries.insert(query);
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600606 }
607
Jeremy Gebben221bb372022-09-19 14:19:32 -0600608 queryUpdates.emplace_back([queryPool, firstQuery, queryCount](CMD_BUFFER_STATE &cb_state_arg, bool do_validate,
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600609 VkQueryPool &firstPerfQueryPool, uint32_t perfQueryPass,
610 QueryMap *localQueryToStateMap) {
611 return SetQueryStateMulti(queryPool, firstQuery, queryCount, perfQueryPass, QUERYSTATE_RESET, localQueryToStateMap);
612 });
613}
614
615void UpdateSubpassAttachments(const safe_VkSubpassDescription2 &subpass, std::vector<SUBPASS_INFO> &subpasses) {
616 for (uint32_t index = 0; index < subpass.inputAttachmentCount; ++index) {
617 const uint32_t attachment_index = subpass.pInputAttachments[index].attachment;
618 if (attachment_index != VK_ATTACHMENT_UNUSED) {
619 subpasses[attachment_index].used = true;
620 subpasses[attachment_index].usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
621 subpasses[attachment_index].layout = subpass.pInputAttachments[index].layout;
622 }
623 }
624
625 for (uint32_t index = 0; index < subpass.colorAttachmentCount; ++index) {
626 const uint32_t attachment_index = subpass.pColorAttachments[index].attachment;
627 if (attachment_index != VK_ATTACHMENT_UNUSED) {
628 subpasses[attachment_index].used = true;
629 subpasses[attachment_index].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
630 subpasses[attachment_index].layout = subpass.pColorAttachments[index].layout;
631 }
632 if (subpass.pResolveAttachments) {
633 const uint32_t attachment_index2 = subpass.pResolveAttachments[index].attachment;
634 if (attachment_index2 != VK_ATTACHMENT_UNUSED) {
635 subpasses[attachment_index2].used = true;
636 subpasses[attachment_index2].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
637 subpasses[attachment_index2].layout = subpass.pResolveAttachments[index].layout;
638 }
639 }
640 }
641
642 if (subpass.pDepthStencilAttachment) {
643 const uint32_t attachment_index = subpass.pDepthStencilAttachment->attachment;
644 if (attachment_index != VK_ATTACHMENT_UNUSED) {
645 subpasses[attachment_index].used = true;
646 subpasses[attachment_index].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
647 subpasses[attachment_index].layout = subpass.pDepthStencilAttachment->layout;
648 }
649 }
650}
651
652void CMD_BUFFER_STATE::UpdateAttachmentsView(const VkRenderPassBeginInfo *pRenderPassBegin) {
653 auto &attachments = *(active_attachments.get());
654 const bool imageless = (activeFramebuffer->createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) ? true : false;
655 const VkRenderPassAttachmentBeginInfo *attachment_info_struct = nullptr;
656 if (pRenderPassBegin) attachment_info_struct = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(pRenderPassBegin->pNext);
657
658 for (uint32_t i = 0; i < attachments.size(); ++i) {
659 if (imageless) {
660 if (attachment_info_struct && i < attachment_info_struct->attachmentCount) {
Jeremy Gebben9f537102021-10-05 16:37:12 -0600661 auto res = attachments_view_states.insert(dev_data->Get<IMAGE_VIEW_STATE>(attachment_info_struct->pAttachments[i]));
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600662 attachments[i] = res.first->get();
663 }
664 } else {
665 auto res = attachments_view_states.insert(activeFramebuffer->attachments_view_state[i]);
666 attachments[i] = res.first->get();
667 }
668 }
669}
670
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600671void CMD_BUFFER_STATE::BeginRenderPass(CMD_TYPE cmd_type, const VkRenderPassBeginInfo *pRenderPassBegin,
672 const VkSubpassContents contents) {
673 RecordCmd(cmd_type);
Jeremy Gebben9f537102021-10-05 16:37:12 -0600674 activeFramebuffer = dev_data->Get<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer);
675 activeRenderPass = dev_data->Get<RENDER_PASS_STATE>(pRenderPassBegin->renderPass);
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600676 activeRenderPassBeginInfo = safe_VkRenderPassBeginInfo(pRenderPassBegin);
677 activeSubpass = 0;
678 activeSubpassContents = contents;
679
aitor-lunarga131fca2022-02-17 22:55:55 +0100680 if (activeRenderPass) {
681 // Connect this RP to cmdBuffer
682 if (!dev_data->disabled[command_buffer_state]) {
683 AddChild(activeRenderPass);
684 }
685
686 // Spec states that after BeginRenderPass all resources should be rebound
687 if (activeRenderPass->has_multiview_enabled) {
688 UnbindResources();
689 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600690 }
691
692 auto chained_device_group_struct = LvlFindInChain<VkDeviceGroupRenderPassBeginInfo>(pRenderPassBegin->pNext);
693 if (chained_device_group_struct) {
694 active_render_pass_device_mask = chained_device_group_struct->deviceMask;
695 } else {
696 active_render_pass_device_mask = initial_device_mask;
697 }
698
699 active_subpasses = nullptr;
700 active_attachments = nullptr;
Hans-Kristian Arntzen0f234382022-06-16 12:37:43 +0200701 has_draw_cmd_in_current_render_pass = false;
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600702
703 if (activeFramebuffer) {
704 framebuffers.insert(activeFramebuffer);
705
706 // Set cb_state->active_subpasses
707 active_subpasses = std::make_shared<std::vector<SUBPASS_INFO>>(activeFramebuffer->createInfo.attachmentCount);
708 const auto &subpass = activeRenderPass->createInfo.pSubpasses[activeSubpass];
709 UpdateSubpassAttachments(subpass, *active_subpasses);
710
711 // Set cb_state->active_attachments & cb_state->attachments_view_states
712 active_attachments = std::make_shared<std::vector<IMAGE_VIEW_STATE *>>(activeFramebuffer->createInfo.attachmentCount);
713 UpdateAttachmentsView(pRenderPassBegin);
714
715 // Connect this framebuffer and its children to this cmdBuffer
Jeremy Gebben610d3a62022-01-01 12:53:17 -0700716 AddChild(activeFramebuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600717 }
718}
719
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600720void CMD_BUFFER_STATE::NextSubpass(CMD_TYPE cmd_type, VkSubpassContents contents) {
721 RecordCmd(cmd_type);
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600722 activeSubpass++;
723 activeSubpassContents = contents;
724
725 // Update cb_state->active_subpasses
aitor-lunarga131fca2022-02-17 22:55:55 +0100726 if (activeRenderPass) {
727 if (activeFramebuffer) {
728 active_subpasses = nullptr;
729 active_subpasses = std::make_shared<std::vector<SUBPASS_INFO>>(activeFramebuffer->createInfo.attachmentCount);
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600730
ziga-lunarg31a3e772022-03-22 11:48:46 +0100731 if (activeSubpass < activeRenderPass->createInfo.subpassCount) {
732 const auto &subpass = activeRenderPass->createInfo.pSubpasses[activeSubpass];
733 UpdateSubpassAttachments(subpass, *active_subpasses);
734 }
aitor-lunarga131fca2022-02-17 22:55:55 +0100735 }
736
737 // Spec states that after NextSubpass all resources should be rebound
738 if (activeRenderPass->has_multiview_enabled) {
739 UnbindResources();
740 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600741 }
742}
743
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600744void CMD_BUFFER_STATE::EndRenderPass(CMD_TYPE cmd_type) {
745 RecordCmd(cmd_type);
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600746 activeRenderPass = nullptr;
747 active_attachments = nullptr;
748 active_subpasses = nullptr;
749 activeSubpass = 0;
750 activeFramebuffer = VK_NULL_HANDLE;
751}
752
Tony-LunarG40b33882021-12-02 12:40:11 -0700753void CMD_BUFFER_STATE::BeginRendering(CMD_TYPE cmd_type, const VkRenderingInfo *pRenderingInfo) {
amhagana448ea52021-11-02 14:09:14 -0400754 RecordCmd(cmd_type);
Tony-LunarG40b33882021-12-02 12:40:11 -0700755 begin_rendering_func_name = CommandTypeString(cmd_type);
amhagana448ea52021-11-02 14:09:14 -0400756 activeRenderPass = std::make_shared<RENDER_PASS_STATE>(pRenderingInfo);
757
758 auto chained_device_group_struct = LvlFindInChain<VkDeviceGroupRenderPassBeginInfo>(pRenderingInfo->pNext);
759 if (chained_device_group_struct) {
760 active_render_pass_device_mask = chained_device_group_struct->deviceMask;
761 } else {
762 active_render_pass_device_mask = initial_device_mask;
763 }
764
765 activeSubpassContents = ((pRenderingInfo->flags & VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR) ? VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS : VK_SUBPASS_CONTENTS_INLINE);
ziga-lunarg143bdbf2022-05-04 19:04:58 +0200766 if (!hasRenderPassInstance && pRenderingInfo->flags & VK_RENDERING_RESUMING_BIT) {
ziga-lunarg0acda6f2022-04-25 22:41:52 +0200767 resumesRenderPassInstance = true;
768 }
ziga-lunarg143bdbf2022-05-04 19:04:58 +0200769 suspendsRenderPassInstance = (pRenderingInfo->flags & VK_RENDERING_SUSPENDING_BIT) > 0;
770 hasRenderPassInstance = true;
amhagana448ea52021-11-02 14:09:14 -0400771
772 active_attachments = nullptr;
Hans-Kristian Arntzen0f234382022-06-16 12:37:43 +0200773 has_draw_cmd_in_current_render_pass = false;
amhagana448ea52021-11-02 14:09:14 -0400774 uint32_t attachment_count = (pRenderingInfo->colorAttachmentCount + 2) * 2;
775
776 // Set cb_state->active_attachments & cb_state->attachments_view_states
777 active_attachments = std::make_shared<std::vector<IMAGE_VIEW_STATE *>>(attachment_count);
778 auto &attachments = *(active_attachments.get());
779
780 for (uint32_t i = 0; i < pRenderingInfo->colorAttachmentCount; ++i) {
781 auto& colorAttachment = attachments[GetDynamicColorAttachmentImageIndex(i)];
782 auto& colorResolveAttachment = attachments[GetDynamicColorResolveAttachmentImageIndex(i)];
783 colorAttachment = nullptr;
784 colorResolveAttachment = nullptr;
785
786 if (pRenderingInfo->pColorAttachments[i].imageView != VK_NULL_HANDLE) {
Jeremy Gebben9f537102021-10-05 16:37:12 -0600787 auto res =
788 attachments_view_states.insert(dev_data->Get<IMAGE_VIEW_STATE>(pRenderingInfo->pColorAttachments[i].imageView));
amhagana448ea52021-11-02 14:09:14 -0400789 colorAttachment = res.first->get();
790 if (pRenderingInfo->pColorAttachments[i].resolveMode != VK_RESOLVE_MODE_NONE &&
791 pRenderingInfo->pColorAttachments[i].resolveImageView != VK_NULL_HANDLE) {
792 colorResolveAttachment = res.first->get();
793 }
794 }
795 }
796
797 if (pRenderingInfo->pDepthAttachment && pRenderingInfo->pDepthAttachment->imageView != VK_NULL_HANDLE) {
798 auto& depthAttachment = attachments[GetDynamicDepthAttachmentImageIndex()];
799 auto& depthResolveAttachment = attachments[GetDynamicDepthResolveAttachmentImageIndex()];
800 depthAttachment = nullptr;
801 depthResolveAttachment = nullptr;
802
Jeremy Gebben9f537102021-10-05 16:37:12 -0600803 auto res = attachments_view_states.insert(dev_data->Get<IMAGE_VIEW_STATE>(pRenderingInfo->pDepthAttachment->imageView));
amhagana448ea52021-11-02 14:09:14 -0400804 depthAttachment = res.first->get();
805 if (pRenderingInfo->pDepthAttachment->resolveMode != VK_RESOLVE_MODE_NONE &&
806 pRenderingInfo->pDepthAttachment->resolveImageView != VK_NULL_HANDLE) {
807 depthResolveAttachment = res.first->get();
808 }
sjfricke52defd42022-08-08 16:37:46 +0900809 }
amhagana448ea52021-11-02 14:09:14 -0400810
811 if (pRenderingInfo->pStencilAttachment && pRenderingInfo->pStencilAttachment->imageView != VK_NULL_HANDLE) {
812 auto& stencilAttachment = attachments[GetDynamicStencilAttachmentImageIndex()];
813 auto& stencilResolveAttachment = attachments[GetDynamicStencilResolveAttachmentImageIndex()];
814 stencilAttachment = nullptr;
815 stencilResolveAttachment = nullptr;
816
Jeremy Gebben9f537102021-10-05 16:37:12 -0600817 auto res = attachments_view_states.insert(dev_data->Get<IMAGE_VIEW_STATE>(pRenderingInfo->pStencilAttachment->imageView));
amhagana448ea52021-11-02 14:09:14 -0400818 stencilAttachment = res.first->get();
819 if (pRenderingInfo->pStencilAttachment->resolveMode != VK_RESOLVE_MODE_NONE &&
820 pRenderingInfo->pStencilAttachment->resolveImageView != VK_NULL_HANDLE) {
821 stencilResolveAttachment = res.first->get();
822 }
823 }
824}
825
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600826void CMD_BUFFER_STATE::Begin(const VkCommandBufferBeginInfo *pBeginInfo) {
827 if (CB_RECORDED == state || CB_INVALID_COMPLETE == state) {
828 Reset();
829 }
paul-lunargf7101f12022-09-19 17:40:30 +0200830
831 descriptorset_cache.clear();
paul-lunargf7101f12022-09-19 17:40:30 +0200832
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600833 // Set updated state here in case implicit reset occurs above
834 state = CB_RECORDING;
835 beginInfo = *pBeginInfo;
836 if (beginInfo.pInheritanceInfo && (createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY)) {
837 inheritanceInfo = *(beginInfo.pInheritanceInfo);
838 beginInfo.pInheritanceInfo = &inheritanceInfo;
839 // If we are a secondary command-buffer and inheriting. Update the items we should inherit.
840 if ((createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
841 (beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
amhagana448ea52021-11-02 14:09:14 -0400842 if (beginInfo.pInheritanceInfo->renderPass) {
Jeremy Gebben9f537102021-10-05 16:37:12 -0600843 activeRenderPass = dev_data->Get<RENDER_PASS_STATE>(beginInfo.pInheritanceInfo->renderPass);
amhagana448ea52021-11-02 14:09:14 -0400844 activeSubpass = beginInfo.pInheritanceInfo->subpass;
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600845
amhagana448ea52021-11-02 14:09:14 -0400846 if (beginInfo.pInheritanceInfo->framebuffer) {
Jeremy Gebben9f537102021-10-05 16:37:12 -0600847 activeFramebuffer = dev_data->Get<FRAMEBUFFER_STATE>(beginInfo.pInheritanceInfo->framebuffer);
amhagana448ea52021-11-02 14:09:14 -0400848 active_subpasses = nullptr;
849 active_attachments = nullptr;
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600850
amhagana448ea52021-11-02 14:09:14 -0400851 if (activeFramebuffer) {
852 framebuffers.insert(activeFramebuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600853
amhagana448ea52021-11-02 14:09:14 -0400854 // Set active_subpasses
855 active_subpasses = std::make_shared<std::vector<SUBPASS_INFO>>(activeFramebuffer->createInfo.attachmentCount);
856 const auto& subpass = activeRenderPass->createInfo.pSubpasses[activeSubpass];
857 UpdateSubpassAttachments(subpass, *active_subpasses);
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600858
amhagana448ea52021-11-02 14:09:14 -0400859 // Set active_attachments & attachments_view_states
860 active_attachments =
861 std::make_shared<std::vector<IMAGE_VIEW_STATE*>>(activeFramebuffer->createInfo.attachmentCount);
862 UpdateAttachmentsView(nullptr);
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600863
amhagana448ea52021-11-02 14:09:14 -0400864 // Connect this framebuffer and its children to this cmdBuffer
865 if (!dev_data->disabled[command_buffer_state]) {
Jeremy Gebben610d3a62022-01-01 12:53:17 -0700866 AddChild(activeFramebuffer);
amhagana448ea52021-11-02 14:09:14 -0400867 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600868 }
869 }
870 }
amhagana448ea52021-11-02 14:09:14 -0400871 else
872 {
Tony-LunarG40b33882021-12-02 12:40:11 -0700873 auto inheritance_rendering_info = lvl_find_in_chain<VkCommandBufferInheritanceRenderingInfo>(beginInfo.pInheritanceInfo->pNext);
amhagana448ea52021-11-02 14:09:14 -0400874 if (inheritance_rendering_info) {
875 activeRenderPass = std::make_shared<RENDER_PASS_STATE>(inheritance_rendering_info);
876 }
877 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600878
879 // Check for VkCommandBufferInheritanceViewportScissorInfoNV (VK_NV_inherited_viewport_scissor)
880 auto p_inherited_viewport_scissor_info =
881 LvlFindInChain<VkCommandBufferInheritanceViewportScissorInfoNV>(beginInfo.pInheritanceInfo->pNext);
882 if (p_inherited_viewport_scissor_info != nullptr && p_inherited_viewport_scissor_info->viewportScissor2D) {
883 auto pViewportDepths = p_inherited_viewport_scissor_info->pViewportDepths;
884 inheritedViewportDepths.assign(pViewportDepths,
885 pViewportDepths + p_inherited_viewport_scissor_info->viewportDepthCount);
886 }
887 }
888 }
889
890 auto chained_device_group_struct = LvlFindInChain<VkDeviceGroupCommandBufferBeginInfo>(pBeginInfo->pNext);
891 if (chained_device_group_struct) {
892 initial_device_mask = chained_device_group_struct->deviceMask;
893 } else {
894 initial_device_mask = (1 << dev_data->physical_device_count) - 1;
895 }
896 performance_lock_acquired = dev_data->performance_lock_acquired;
ziga-lunarg96c7d822022-02-28 19:39:17 +0100897 updatedQueries.clear();
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600898}
899
900void CMD_BUFFER_STATE::End(VkResult result) {
901 // Cached validation is specific to a specific recording of a specific command buffer.
Jeremy Gebben87db52f2021-10-14 13:55:09 -0600902 descriptorset_cache.clear();
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600903 if (VK_SUCCESS == result) {
904 state = CB_RECORDED;
905 }
906}
907
908void CMD_BUFFER_STATE::ExecuteCommands(uint32_t commandBuffersCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600909 RecordCmd(CMD_EXECUTECOMMANDS);
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600910 for (uint32_t i = 0; i < commandBuffersCount; i++) {
Jeremy Gebben221bb372022-09-19 14:19:32 -0600911 auto sub_command_buffer = pCommandBuffers[i];
912 auto sub_cb_state = dev_data->GetWrite<CMD_BUFFER_STATE>(sub_command_buffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600913 assert(sub_cb_state);
914 if (!(sub_cb_state->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
915 if (beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) {
916 // TODO: Because this is a state change, clearing the VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT needs to be moved
917 // from the validation step to the recording step
918 beginInfo.flags &= ~VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
919 }
920 }
921
922 // Propagate inital layout and current layout state to the primary cmd buffer
923 // NOTE: The update/population of the image_layout_map is done in CoreChecks, but for other classes derived from
924 // ValidationStateTracker these maps will be empty, so leaving the propagation in the the state tracker should be a no-op
925 // for those other classes.
926 for (const auto &sub_layout_map_entry : sub_cb_state->image_layout_map) {
Jeremy Gebben6335df62021-11-01 10:50:13 -0600927 const auto *image_state = sub_layout_map_entry.first;
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600928
929 auto *cb_subres_map = GetImageSubresourceLayoutMap(*image_state);
Jeremy Gebben4a8881f2022-01-10 17:04:30 -0700930 if (cb_subres_map) {
931 const auto &sub_cb_subres_map = sub_layout_map_entry.second;
932 cb_subres_map->UpdateFrom(*sub_cb_subres_map);
933 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600934 }
935
936 sub_cb_state->primaryCommandBuffer = commandBuffer();
Jeremy Gebben9f537102021-10-05 16:37:12 -0600937 linkedCommandBuffers.insert(sub_cb_state.get());
Jeremy Gebben610d3a62022-01-01 12:53:17 -0700938 AddChild(sub_cb_state);
Jeremy Gebben221bb372022-09-19 14:19:32 -0600939 // Add a query update that runs all the query updates that happen in the sub command buffer.
940 // This avoids locking ambiguity because primary command buffers are locked when these
941 // callbacks run, but secondary command buffers are not.
942 queryUpdates.push_back([sub_command_buffer](CMD_BUFFER_STATE &cb_state_arg, bool do_validate,
943 VkQueryPool &firstPerfQueryPool, uint32_t perfQueryPass,
944 QueryMap *localQueryToStateMap) {
945 bool skip = false;
946 auto sub_cb_state_arg = cb_state_arg.dev_data->GetWrite<CMD_BUFFER_STATE>(sub_command_buffer);
947 for (auto &function : sub_cb_state_arg->queryUpdates) {
948 skip |= function(*sub_cb_state_arg, do_validate, firstPerfQueryPool, perfQueryPass, localQueryToStateMap);
949 }
950 return skip;
951 });
aitor-lunarge8c5f8b2022-03-28 20:29:42 +0200952 for (auto &function : sub_cb_state->eventUpdates) {
953 eventUpdates.push_back(function);
954 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600955 for (auto &function : sub_cb_state->queue_submit_functions) {
956 queue_submit_functions.push_back(function);
957 }
958
959 // State is trashed after executing secondary command buffers.
960 // Importantly, this function runs after CoreChecks::PreCallValidateCmdExecuteCommands.
961 trashedViewportMask = ~uint32_t(0);
962 trashedScissorMask = ~uint32_t(0);
963 trashedViewportCount = true;
964 trashedScissorCount = true;
sjfricke52defd42022-08-08 16:37:46 +0900965
966 // Pass along if any commands are used in the secondary command buffer
967 if (sub_cb_state->has_draw_cmd) {
968 has_draw_cmd = true;
969 }
970 if (sub_cb_state->has_dispatch_cmd) {
971 has_dispatch_cmd = true;
972 }
973 if (sub_cb_state->has_trace_rays_cmd) {
974 has_trace_rays_cmd = true;
975 }
976 if (sub_cb_state->has_build_as_cmd) {
977 has_build_as_cmd = true;
978 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600979 }
980}
981
982void CMD_BUFFER_STATE::PushDescriptorSetState(VkPipelineBindPoint pipelineBindPoint, PIPELINE_LAYOUT_STATE *pipeline_layout,
983 uint32_t set, uint32_t descriptorWriteCount,
984 const VkWriteDescriptorSet *pDescriptorWrites) {
985 // Short circuit invalid updates
986 if (!pipeline_layout || (set >= pipeline_layout->set_layouts.size()) || !pipeline_layout->set_layouts[set] ||
987 !pipeline_layout->set_layouts[set]->IsPushDescriptor()) {
988 return;
989 }
990
991 // We need a descriptor set to update the bindings with, compatible with the passed layout
992 const auto &dsl = pipeline_layout->set_layouts[set];
993 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
994 auto &last_bound = lastBound[lv_bind_point];
995 auto &push_descriptor_set = last_bound.push_descriptor_set;
996 // If we are disturbing the current push_desriptor_set clear it
997 if (!push_descriptor_set || !CompatForSet(set, last_bound, pipeline_layout->compat_for_set)) {
Jeremy Gebben4d51c552022-01-06 21:27:15 -0700998 last_bound.UnbindAndResetPushDescriptorSet(
Jeremy Gebbenf087ddb2022-08-04 09:36:17 -0600999 std::make_shared<cvdescriptorset::DescriptorSet>(VK_NULL_HANDLE, nullptr, dsl, 0, dev_data));
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001000 }
1001
Jeremy Gebben4d51c552022-01-06 21:27:15 -07001002 UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout, set, 1, nullptr, push_descriptor_set, 0, nullptr);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001003 last_bound.pipeline_layout = pipeline_layout->layout();
1004
1005 // Now that we have either the new or extant push_descriptor set ... do the write updates against it
1006 push_descriptor_set->PerformPushDescriptorsUpdate(dev_data, descriptorWriteCount, pDescriptorWrites);
1007}
1008
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001009// Generic function to handle state update for all CmdDraw* type functions
sjfricke52defd42022-08-08 16:37:46 +09001010void CMD_BUFFER_STATE::UpdateDrawCmd(CMD_TYPE cmd_type) {
1011 has_draw_cmd = true;
Hans-Kristian Arntzen0f234382022-06-16 12:37:43 +02001012 has_draw_cmd_in_current_render_pass = true;
sjfricke52defd42022-08-08 16:37:46 +09001013 UpdatePipelineState(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001014
1015 // Update the consumed viewport/scissor count.
1016 uint32_t &used = usedViewportScissorCount;
1017 used = std::max(used, pipelineStaticViewportCount);
1018 used = std::max(used, pipelineStaticScissorCount);
1019 usedDynamicViewportCount |= !!(dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET); // !! silences MSVC warn
1020 usedDynamicScissorCount |= !!(dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET);
1021}
1022
sjfricke52defd42022-08-08 16:37:46 +09001023// Generic function to handle state update for all CmdDispatch* type functions
1024void CMD_BUFFER_STATE::UpdateDispatchCmd(CMD_TYPE cmd_type) {
1025 has_dispatch_cmd = true;
1026 UpdatePipelineState(cmd_type, VK_PIPELINE_BIND_POINT_COMPUTE);
1027}
1028
1029// Generic function to handle state update for all CmdTraceRay* type functions
1030void CMD_BUFFER_STATE::UpdateTraceRayCmd(CMD_TYPE cmd_type) {
1031 has_trace_rays_cmd = true;
1032 UpdatePipelineState(cmd_type, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
1033}
1034
1035// Generic function to handle state update for all Provoking functions calls (draw/dispatch/traceray/etc)
1036void CMD_BUFFER_STATE::UpdatePipelineState(CMD_TYPE cmd_type, const VkPipelineBindPoint bind_point) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06001037 RecordCmd(cmd_type);
1038
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001039 const auto lv_bind_point = ConvertToLvlBindPoint(bind_point);
1040 auto &state = lastBound[lv_bind_point];
1041 PIPELINE_STATE *pipe = state.pipeline_state;
1042 if (VK_NULL_HANDLE != state.pipeline_layout) {
1043 for (const auto &set_binding_pair : pipe->active_slots) {
1044 uint32_t set_index = set_binding_pair.first;
Charles Bakera263fee2022-02-18 12:45:21 +13001045 if (set_index >= state.per_set.size()) {
1046 continue;
1047 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001048 // Pull the set node
Jeremy Gebben4d51c552022-01-06 21:27:15 -07001049 auto &descriptor_set = state.per_set[set_index].bound_descriptor_set;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001050
1051 // For the "bindless" style resource usage with many descriptors, need to optimize command <-> descriptor binding
1052
1053 // TODO: If recreating the reduced_map here shows up in profilinging, need to find a way of sharing with the
1054 // Validate pass. Though in the case of "many" descriptors, typically the descriptor count >> binding count
1055 cvdescriptorset::PrefilterBindRequestMap reduced_map(*descriptor_set, set_binding_pair.second);
1056 const auto &binding_req_map = reduced_map.FilteredMap(*this, *pipe);
1057
1058 if (reduced_map.IsManyDescriptors()) {
1059 // Only update validate binding tags if we meet the "many" criteria in the Prefilter class
1060 descriptor_set->UpdateValidationCache(*this, *pipe, binding_req_map);
1061 }
1062
1063 // We can skip updating the state if "nothing" has changed since the last validation.
1064 // See CoreChecks::ValidateCmdBufDrawState for more details.
1065 bool descriptor_set_changed =
1066 !reduced_map.IsManyDescriptors() ||
1067 // Update if descriptor set (or contents) has changed
Jeremy Gebben4d51c552022-01-06 21:27:15 -07001068 state.per_set[set_index].validated_set != descriptor_set.get() ||
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001069 state.per_set[set_index].validated_set_change_count != descriptor_set->GetChangeCount() ||
1070 (!dev_data->disabled[image_layout_validation] &&
1071 state.per_set[set_index].validated_set_image_layout_change_count != image_layout_change_count);
1072 bool need_update = descriptor_set_changed ||
1073 // Update if previous bindingReqMap doesn't include new bindingReqMap
1074 !std::includes(state.per_set[set_index].validated_set_binding_req_map.begin(),
1075 state.per_set[set_index].validated_set_binding_req_map.end(), binding_req_map.begin(),
1076 binding_req_map.end());
1077
1078 if (need_update) {
Jeremy Gebben4d51c552022-01-06 21:27:15 -07001079 if (!dev_data->disabled[command_buffer_state] && !descriptor_set->IsPushDescriptor()) {
1080 AddChild(descriptor_set);
1081 }
1082
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001083 // Bind this set and its active descriptor resources to the command buffer
1084 if (!descriptor_set_changed && reduced_map.IsManyDescriptors()) {
1085 // Only record the bindings that haven't already been recorded
1086 BindingReqMap delta_reqs;
1087 std::set_difference(binding_req_map.begin(), binding_req_map.end(),
1088 state.per_set[set_index].validated_set_binding_req_map.begin(),
1089 state.per_set[set_index].validated_set_binding_req_map.end(),
1090 layer_data::insert_iterator<BindingReqMap>(delta_reqs, delta_reqs.begin()));
sfricke-samsung85584a72021-09-30 21:43:38 -07001091 descriptor_set->UpdateDrawState(dev_data, this, cmd_type, pipe, delta_reqs);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001092 } else {
sfricke-samsung85584a72021-09-30 21:43:38 -07001093 descriptor_set->UpdateDrawState(dev_data, this, cmd_type, pipe, binding_req_map);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001094 }
1095
Jeremy Gebben4d51c552022-01-06 21:27:15 -07001096 state.per_set[set_index].validated_set = descriptor_set.get();
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001097 state.per_set[set_index].validated_set_change_count = descriptor_set->GetChangeCount();
1098 state.per_set[set_index].validated_set_image_layout_change_count = image_layout_change_count;
1099 if (reduced_map.IsManyDescriptors()) {
1100 // Check whether old == new before assigning, the equality check is much cheaper than
1101 // freeing and reallocating the map.
1102 if (state.per_set[set_index].validated_set_binding_req_map != set_binding_pair.second) {
1103 state.per_set[set_index].validated_set_binding_req_map = set_binding_pair.second;
1104 }
1105 } else {
1106 state.per_set[set_index].validated_set_binding_req_map = BindingReqMap();
1107 }
1108 }
1109 }
1110 }
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07001111 if (pipe && pipe->vertex_input_state && !pipe->vertex_input_state->binding_descriptions.empty()) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001112 vertex_buffer_used = true;
1113 }
1114}
1115
1116// Update pipeline_layout bind points applying the "Pipeline Layout Compatibility" rules.
1117// One of pDescriptorSets or push_descriptor_set should be nullptr, indicating whether this
1118// is called for CmdBindDescriptorSets or CmdPushDescriptorSet.
1119void CMD_BUFFER_STATE::UpdateLastBoundDescriptorSets(VkPipelineBindPoint pipeline_bind_point,
1120 const PIPELINE_LAYOUT_STATE *pipeline_layout, uint32_t first_set,
1121 uint32_t set_count, const VkDescriptorSet *pDescriptorSets,
Jeremy Gebben4d51c552022-01-06 21:27:15 -07001122 std::shared_ptr<cvdescriptorset::DescriptorSet> &push_descriptor_set,
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001123 uint32_t dynamic_offset_count, const uint32_t *p_dynamic_offsets) {
1124 assert((pDescriptorSets == nullptr) ^ (push_descriptor_set == nullptr));
1125 // Defensive
1126 assert(pipeline_layout);
1127 if (!pipeline_layout) return;
1128
1129 uint32_t required_size = first_set + set_count;
1130 const uint32_t last_binding_index = required_size - 1;
1131 assert(last_binding_index < pipeline_layout->compat_for_set.size());
1132
1133 // Some useful shorthand
1134 const auto lv_bind_point = ConvertToLvlBindPoint(pipeline_bind_point);
1135 auto &last_bound = lastBound[lv_bind_point];
Jeremy Gebben856b8c62021-12-01 15:20:07 -07001136 last_bound.pipeline_layout = pipeline_layout->layout();
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001137 auto &pipe_compat_ids = pipeline_layout->compat_for_set;
Jeremy Gebben856b8c62021-12-01 15:20:07 -07001138 // Resize binding arrays
1139 uint32_t last_set_index = first_set + set_count - 1;
1140 if (last_set_index >= last_bound.per_set.size()) {
1141 last_bound.per_set.resize(last_set_index + 1);
1142 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001143 const uint32_t current_size = static_cast<uint32_t>(last_bound.per_set.size());
1144
1145 // We need this three times in this function, but nowhere else
Jeremy Gebben4d51c552022-01-06 21:27:15 -07001146 auto push_descriptor_cleanup = [&last_bound](const std::shared_ptr<cvdescriptorset::DescriptorSet> &ds) -> bool {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001147 if (ds && ds->IsPushDescriptor()) {
Jeremy Gebben4d51c552022-01-06 21:27:15 -07001148 assert(ds == last_bound.push_descriptor_set);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001149 last_bound.push_descriptor_set = nullptr;
1150 return true;
1151 }
1152 return false;
1153 };
1154
1155 // Clean up the "disturbed" before and after the range to be set
1156 if (required_size < current_size) {
1157 if (last_bound.per_set[last_binding_index].compat_id_for_set != pipe_compat_ids[last_binding_index]) {
1158 // We're disturbing those after last, we'll shrink below, but first need to check for and cleanup the push_descriptor
1159 for (auto set_idx = required_size; set_idx < current_size; ++set_idx) {
1160 if (push_descriptor_cleanup(last_bound.per_set[set_idx].bound_descriptor_set)) break;
1161 }
1162 } else {
1163 // We're not disturbing past last, so leave the upper binding data alone.
1164 required_size = current_size;
1165 }
1166 }
1167
1168 // We resize if we need more set entries or if those past "last" are disturbed
1169 if (required_size != current_size) {
1170 last_bound.per_set.resize(required_size);
1171 }
1172
1173 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
1174 for (uint32_t set_idx = 0; set_idx < first_set; ++set_idx) {
1175 if (last_bound.per_set[set_idx].compat_id_for_set != pipe_compat_ids[set_idx]) {
1176 push_descriptor_cleanup(last_bound.per_set[set_idx].bound_descriptor_set);
1177 last_bound.per_set[set_idx].bound_descriptor_set = nullptr;
1178 last_bound.per_set[set_idx].dynamicOffsets.clear();
1179 last_bound.per_set[set_idx].compat_id_for_set = pipe_compat_ids[set_idx];
1180 }
1181 }
1182
1183 // Now update the bound sets with the input sets
1184 const uint32_t *input_dynamic_offsets = p_dynamic_offsets; // "read" pointer for dynamic offset data
1185 for (uint32_t input_idx = 0; input_idx < set_count; input_idx++) {
1186 auto set_idx = input_idx + first_set; // set_idx is index within layout, input_idx is index within input descriptor sets
Jeremy Gebben4d51c552022-01-06 21:27:15 -07001187 auto descriptor_set =
1188 push_descriptor_set ? push_descriptor_set : dev_data->Get<cvdescriptorset::DescriptorSet>(pDescriptorSets[input_idx]);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001189
1190 // Record binding (or push)
Jeremy Gebben4d51c552022-01-06 21:27:15 -07001191 if (descriptor_set != last_bound.push_descriptor_set) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001192 // Only cleanup the push descriptors if they aren't the currently used set.
1193 push_descriptor_cleanup(last_bound.per_set[set_idx].bound_descriptor_set);
1194 }
1195 last_bound.per_set[set_idx].bound_descriptor_set = descriptor_set;
1196 last_bound.per_set[set_idx].compat_id_for_set = pipe_compat_ids[set_idx]; // compat ids are canonical *per* set index
1197
1198 if (descriptor_set) {
1199 auto set_dynamic_descriptor_count = descriptor_set->GetDynamicDescriptorCount();
1200 // TODO: Add logic for tracking push_descriptor offsets (here or in caller)
1201 if (set_dynamic_descriptor_count && input_dynamic_offsets) {
1202 const uint32_t *end_offset = input_dynamic_offsets + set_dynamic_descriptor_count;
1203 last_bound.per_set[set_idx].dynamicOffsets = std::vector<uint32_t>(input_dynamic_offsets, end_offset);
1204 input_dynamic_offsets = end_offset;
1205 assert(input_dynamic_offsets <= (p_dynamic_offsets + dynamic_offset_count));
1206 } else {
1207 last_bound.per_set[set_idx].dynamicOffsets.clear();
1208 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001209 }
1210 }
1211}
1212
1213// Set image layout for given VkImageSubresourceRange struct
1214void CMD_BUFFER_STATE::SetImageLayout(const IMAGE_STATE &image_state, const VkImageSubresourceRange &image_subresource_range,
1215 VkImageLayout layout, VkImageLayout expected_layout) {
1216 auto *subresource_map = GetImageSubresourceLayoutMap(image_state);
Jeremy Gebben4a8881f2022-01-10 17:04:30 -07001217 if (subresource_map && subresource_map->SetSubresourceRangeLayout(*this, image_subresource_range, layout, expected_layout)) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001218 image_layout_change_count++; // Change the version of this data to force revalidation
1219 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001220}
1221
1222// Set the initial image layout for all slices of an image view
1223void CMD_BUFFER_STATE::SetImageViewInitialLayout(const IMAGE_VIEW_STATE &view_state, VkImageLayout layout) {
1224 if (dev_data->disabled[image_layout_validation]) {
1225 return;
1226 }
1227 IMAGE_STATE *image_state = view_state.image_state.get();
1228 auto *subresource_map = GetImageSubresourceLayoutMap(*image_state);
Jeremy Gebben4a8881f2022-01-10 17:04:30 -07001229 if (subresource_map) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001230 subresource_map->SetSubresourceRangeInitialLayout(*this, layout, view_state);
1231 }
1232}
1233
1234// Set the initial image layout for a passed non-normalized subresource range
1235void CMD_BUFFER_STATE::SetImageInitialLayout(const IMAGE_STATE &image_state, const VkImageSubresourceRange &range,
1236 VkImageLayout layout) {
1237 auto *subresource_map = GetImageSubresourceLayoutMap(image_state);
Jeremy Gebben4a8881f2022-01-10 17:04:30 -07001238 if (subresource_map) {
1239 subresource_map->SetSubresourceRangeInitialLayout(*this, image_state.NormalizeSubresourceRange(range), layout);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001240 }
1241}
1242
1243void CMD_BUFFER_STATE::SetImageInitialLayout(VkImage image, const VkImageSubresourceRange &range, VkImageLayout layout) {
Jeremy Gebbenf4449392022-01-28 10:09:10 -07001244 auto image_state = dev_data->Get<IMAGE_STATE>(image);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001245 if (!image_state) return;
1246 SetImageInitialLayout(*image_state, range, layout);
1247}
1248
1249void CMD_BUFFER_STATE::SetImageInitialLayout(const IMAGE_STATE &image_state, const VkImageSubresourceLayers &layers,
1250 VkImageLayout layout) {
1251 SetImageInitialLayout(image_state, RangeFromLayers(layers), layout);
1252}
1253
1254// Set image layout for all slices of an image view
1255void CMD_BUFFER_STATE::SetImageViewLayout(const IMAGE_VIEW_STATE &view_state, VkImageLayout layout, VkImageLayout layoutStencil) {
1256 const IMAGE_STATE *image_state = view_state.image_state.get();
1257
1258 VkImageSubresourceRange sub_range = view_state.normalized_subresource_range;
1259
1260 if (sub_range.aspectMask == (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT) && layoutStencil != kInvalidLayout) {
1261 sub_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
1262 SetImageLayout(*image_state, sub_range, layout);
1263 sub_range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
1264 SetImageLayout(*image_state, sub_range, layoutStencil);
1265 } else {
1266 SetImageLayout(*image_state, sub_range, layout);
1267 }
1268}
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06001269
Hans-Kristian Arntzen0f234382022-06-16 12:37:43 +02001270void CMD_BUFFER_STATE::RecordCmd(CMD_TYPE cmd_type) { commandCount++; }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06001271
1272void CMD_BUFFER_STATE::RecordStateCmd(CMD_TYPE cmd_type, CBStatusFlags state_bits) {
1273 RecordCmd(cmd_type);
1274 status |= state_bits;
1275 static_status &= ~state_bits;
1276}
1277
ziga-lunarg67b7c392022-03-26 01:45:34 +01001278void CMD_BUFFER_STATE::RecordColorWriteEnableStateCmd(CMD_TYPE cmd_type, CBStatusFlags state_bits, uint32_t attachment_count) {
1279 RecordStateCmd(cmd_type, state_bits);
1280 dynamicColorWriteEnableAttachmentCount = std::max(dynamicColorWriteEnableAttachmentCount, attachment_count);
1281}
1282
Jeremy Gebben9f537102021-10-05 16:37:12 -06001283void CMD_BUFFER_STATE::RecordTransferCmd(CMD_TYPE cmd_type, std::shared_ptr<BINDABLE> &&buf1, std::shared_ptr<BINDABLE> &&buf2) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06001284 RecordCmd(cmd_type);
1285 if (buf1) {
Jeremy Gebben610d3a62022-01-01 12:53:17 -07001286 AddChild(buf1);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06001287 }
1288 if (buf2) {
Jeremy Gebben610d3a62022-01-01 12:53:17 -07001289 AddChild(buf2);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06001290 }
1291}
Jeremy Gebben29110d22021-08-17 13:30:50 -06001292
1293static bool SetEventStageMask(VkEvent event, VkPipelineStageFlags2KHR stageMask, EventToStageMap *localEventToStageMap) {
1294 (*localEventToStageMap)[event] = stageMask;
1295 return false;
1296}
1297
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06001298void CMD_BUFFER_STATE::RecordSetEvent(CMD_TYPE cmd_type, VkEvent event, VkPipelineStageFlags2KHR stageMask) {
1299 RecordCmd(cmd_type);
1300 if (!dev_data->disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001301 auto event_state = dev_data->Get<EVENT_STATE>(event);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001302 if (event_state) {
Jeremy Gebben610d3a62022-01-01 12:53:17 -07001303 AddChild(event_state);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001304 }
1305 }
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06001306 events.push_back(event);
1307 if (!waitedEvents.count(event)) {
1308 writeEventsBeforeWait.push_back(event);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001309 }
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001310 eventUpdates.emplace_back([event, stageMask](CMD_BUFFER_STATE &, bool do_validate, EventToStageMap *localEventToStageMap) {
1311 return SetEventStageMask(event, stageMask, localEventToStageMap);
1312 });
Jeremy Gebben29110d22021-08-17 13:30:50 -06001313}
1314
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06001315void CMD_BUFFER_STATE::RecordResetEvent(CMD_TYPE cmd_type, VkEvent event, VkPipelineStageFlags2KHR stageMask) {
1316 RecordCmd(cmd_type);
1317 if (!dev_data->disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001318 auto event_state = dev_data->Get<EVENT_STATE>(event);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001319 if (event_state) {
Jeremy Gebben610d3a62022-01-01 12:53:17 -07001320 AddChild(event_state);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001321 }
1322 }
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06001323 events.push_back(event);
1324 if (!waitedEvents.count(event)) {
1325 writeEventsBeforeWait.push_back(event);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001326 }
1327
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001328 eventUpdates.emplace_back([event](CMD_BUFFER_STATE &, bool do_validate, EventToStageMap *localEventToStageMap) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06001329 return SetEventStageMask(event, VkPipelineStageFlags2KHR(0), localEventToStageMap);
1330 });
Jeremy Gebben29110d22021-08-17 13:30:50 -06001331}
1332
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001333void CMD_BUFFER_STATE::RecordWaitEvents(CMD_TYPE cmd_type, uint32_t eventCount, const VkEvent *pEvents,
1334 VkPipelineStageFlags2KHR src_stage_mask) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06001335 RecordCmd(cmd_type);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001336 for (uint32_t i = 0; i < eventCount; ++i) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06001337 if (!dev_data->disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001338 auto event_state = dev_data->Get<EVENT_STATE>(pEvents[i]);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001339 if (event_state) {
Jeremy Gebben610d3a62022-01-01 12:53:17 -07001340 AddChild(event_state);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001341 }
1342 }
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06001343 waitedEvents.insert(pEvents[i]);
1344 events.push_back(pEvents[i]);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001345 }
1346}
1347
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06001348void CMD_BUFFER_STATE::RecordBarriers(uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
1349 uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier *pBufferMemoryBarriers,
1350 uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier *pImageMemoryBarriers) {
1351 if (dev_data->disabled[command_buffer_state]) return;
Jeremy Gebben29110d22021-08-17 13:30:50 -06001352
Jeremy Gebben29110d22021-08-17 13:30:50 -06001353 for (uint32_t i = 0; i < bufferMemoryBarrierCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001354 auto buffer_state = dev_data->Get<BUFFER_STATE>(pBufferMemoryBarriers[i].buffer);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001355 if (buffer_state) {
Jeremy Gebben610d3a62022-01-01 12:53:17 -07001356 AddChild(buffer_state);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001357 }
1358 }
1359 for (uint32_t i = 0; i < imageMemoryBarrierCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001360 auto image_state = dev_data->Get<IMAGE_STATE>(pImageMemoryBarriers[i].image);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001361 if (image_state) {
Jeremy Gebben610d3a62022-01-01 12:53:17 -07001362 AddChild(image_state);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001363 }
1364 }
1365}
1366
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06001367void CMD_BUFFER_STATE::RecordBarriers(const VkDependencyInfoKHR &dep_info) {
1368 if (dev_data->disabled[command_buffer_state]) return;
Jeremy Gebben29110d22021-08-17 13:30:50 -06001369
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06001370 for (uint32_t i = 0; i < dep_info.bufferMemoryBarrierCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001371 auto buffer_state = dev_data->Get<BUFFER_STATE>(dep_info.pBufferMemoryBarriers[i].buffer);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001372 if (buffer_state) {
Jeremy Gebben610d3a62022-01-01 12:53:17 -07001373 AddChild(buffer_state);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001374 }
1375 }
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06001376 for (uint32_t i = 0; i < dep_info.imageMemoryBarrierCount; i++) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001377 auto image_state = dev_data->Get<IMAGE_STATE>(dep_info.pImageMemoryBarriers[i].image);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001378 if (image_state) {
Jeremy Gebben610d3a62022-01-01 12:53:17 -07001379 AddChild(image_state);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001380 }
1381 }
1382}
1383
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06001384void CMD_BUFFER_STATE::RecordWriteTimestamp(CMD_TYPE cmd_type, VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
1385 uint32_t slot) {
1386 RecordCmd(cmd_type);
1387 if (dev_data->disabled[query_validation]) return;
1388
1389 if (!dev_data->disabled[command_buffer_state]) {
Jeremy Gebbenb20a8242021-11-05 15:14:43 -06001390 auto pool_state = dev_data->Get<QUERY_POOL_STATE>(queryPool);
Jeremy Gebben610d3a62022-01-01 12:53:17 -07001391 AddChild(pool_state);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001392 }
1393 QueryObject query = {queryPool, slot};
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06001394 EndQuery(query);
Jeremy Gebben29110d22021-08-17 13:30:50 -06001395}
Jeremy Gebben4af0aa82021-09-08 09:35:16 -06001396
Jeremy Gebben57642982021-09-14 14:14:55 -06001397void CMD_BUFFER_STATE::Submit(uint32_t perf_submit_pass) {
1398 VkQueryPool first_pool = VK_NULL_HANDLE;
1399 EventToStageMap local_event_to_stage_map;
1400 QueryMap local_query_to_state_map;
1401 for (auto &function : queryUpdates) {
Jeremy Gebben221bb372022-09-19 14:19:32 -06001402 function(*this, /*do_validate*/ false, first_pool, perf_submit_pass, &local_query_to_state_map);
Jeremy Gebben57642982021-09-14 14:14:55 -06001403 }
Jeremy Gebben4af0aa82021-09-08 09:35:16 -06001404
Jeremy Gebben57642982021-09-14 14:14:55 -06001405 for (const auto &query_state_pair : local_query_to_state_map) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07001406 auto query_pool_state = dev_data->Get<QUERY_POOL_STATE>(query_state_pair.first.pool);
1407 query_pool_state->SetQueryState(query_state_pair.first.query, query_state_pair.first.perf_pass, query_state_pair.second);
Jeremy Gebben57642982021-09-14 14:14:55 -06001408 }
Jeremy Gebben4af0aa82021-09-08 09:35:16 -06001409
Jeremy Gebben57642982021-09-14 14:14:55 -06001410 for (const auto &function : eventUpdates) {
Jeremy Gebben332d4dd2022-01-01 12:40:02 -07001411 function(*this, /*do_validate*/ false, &local_event_to_stage_map);
Jeremy Gebben57642982021-09-14 14:14:55 -06001412 }
Jeremy Gebben4af0aa82021-09-08 09:35:16 -06001413
Jeremy Gebben57642982021-09-14 14:14:55 -06001414 for (const auto &eventStagePair : local_event_to_stage_map) {
Jeremy Gebben9f537102021-10-05 16:37:12 -06001415 auto event_state = dev_data->Get<EVENT_STATE>(eventStagePair.first);
1416 event_state->stageMask = eventStagePair.second;
Jeremy Gebben57642982021-09-14 14:14:55 -06001417 }
1418}
Jeremy Gebben4af0aa82021-09-08 09:35:16 -06001419
ziga-lunarg96c7d822022-02-28 19:39:17 +01001420void CMD_BUFFER_STATE::Retire(uint32_t perf_submit_pass, const std::function<bool(const QueryObject &)>& is_query_updated_after) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001421 // First perform decrement on general case bound objects
1422 for (auto event : writeEventsBeforeWait) {
Jeremy Gebbend177d922021-10-28 13:42:10 -06001423 auto event_state = dev_data->Get<EVENT_STATE>(event);
1424 if (event_state) {
1425 event_state->write_in_use--;
Jeremy Gebben57642982021-09-14 14:14:55 -06001426 }
1427 }
1428 QueryMap local_query_to_state_map;
1429 VkQueryPool first_pool = VK_NULL_HANDLE;
1430 for (auto &function : queryUpdates) {
Jeremy Gebben221bb372022-09-19 14:19:32 -06001431 function(*this, /*do_validate*/ false, first_pool, perf_submit_pass, &local_query_to_state_map);
Jeremy Gebben57642982021-09-14 14:14:55 -06001432 }
1433
1434 for (const auto &query_state_pair : local_query_to_state_map) {
ziga-lunarg96c7d822022-02-28 19:39:17 +01001435 if (query_state_pair.second == QUERYSTATE_ENDED && !is_query_updated_after(query_state_pair.first)) {
Jeremy Gebben1858ae92021-12-02 11:28:05 -07001436 auto query_pool_state = dev_data->Get<QUERY_POOL_STATE>(query_state_pair.first.pool);
1437 query_pool_state->SetQueryState(query_state_pair.first.query, query_state_pair.first.perf_pass, QUERYSTATE_AVAILABLE);
Jeremy Gebben4af0aa82021-09-08 09:35:16 -06001438 }
1439 }
1440}
aitor-lunarga131fca2022-02-17 22:55:55 +01001441
1442void CMD_BUFFER_STATE::UnbindResources() {
aitor-lunarga131fca2022-02-17 22:55:55 +01001443 // Vertex and index buffers
1444 index_buffer_binding.reset();
1445 vertex_buffer_used = false;
1446 current_vertex_buffer_binding_info.vertex_buffer_bindings.clear();
1447
1448 // Push constants
1449 push_constant_data.clear();
1450 push_constant_data_ranges.reset();
1451 push_constant_data_update.clear();
1452 push_constant_pipeline_layout_set = VK_NULL_HANDLE;
1453
Aitor Camacho8ef96de2022-06-13 19:13:03 +02001454 // Reset status of cb to force rebinding of all resources
1455 // Index buffer included
1456 status = CBSTATUS_NONE;
1457
1458 // Pipeline and descriptor sets
1459 lastBound[BindPoint_Graphics].Reset();
Nathaniel Cesario8d5c9d92022-07-25 12:59:16 -06001460}
1461
1462bool CMD_BUFFER_STATE::RasterizationDisabled() const {
1463 auto pipeline = lastBound[BindPoint_Graphics].pipeline_state;
1464 if (pipeline) {
1465 if (pipeline->IsDynamic(VK_DYNAMIC_STATE_RASTERIZER_DISCARD_ENABLE_EXT)) {
1466 return rasterization_disabled;
1467 } else {
1468 return pipeline->RasterizationDisabled();
1469 }
1470 }
1471
1472 return false;
1473}