blob: e5cc74919e662e0c95dde126de41bf5ba339b6ae [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#pragma once
28#include "base_node.h"
29#include "query_state.h"
30#include "command_validation.h"
31#include "hash_vk_types.h"
32#include "subresource_adapter.h"
33#include "image_layout_map.h"
34#include "pipeline_state.h"
35#include "device_state.h"
36#include "descriptor_sets.h"
37#include "qfo_transfer.h"
38
Jeremy Gebben1ec89332021-08-05 13:51:49 -060039struct SUBPASS_INFO;
40class FRAMEBUFFER_STATE;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -060041class RENDER_PASS_STATE;
42class CoreChecks;
43class ValidationStateTracker;
44
45class EVENT_STATE : public BASE_NODE {
46 public:
47 int write_in_use;
48 VkPipelineStageFlags2KHR stageMask = VkPipelineStageFlags2KHR(0);
49 VkEventCreateFlags flags;
50
51 EVENT_STATE(VkEvent event_, VkEventCreateFlags flags_)
52 : BASE_NODE(event_, kVulkanObjectTypeEvent), write_in_use(0), flags(flags_) {}
53
54 VkEvent event() const { return handle_.Cast<VkEvent>(); }
55};
56
57// Only CoreChecks uses this, but the state tracker stores it.
58constexpr static auto kInvalidLayout = image_layout_map::kInvalidLayout;
59using ImageSubresourceLayoutMap = image_layout_map::ImageSubresourceLayoutMap;
60typedef layer_data::unordered_map<VkEvent, VkPipelineStageFlags2KHR> EventToStageMap;
61
62// Track command pools and their command buffers
63class COMMAND_POOL_STATE : public BASE_NODE {
64 public:
Jeremy Gebbencd7fa282021-10-27 10:25:32 -060065 ValidationStateTracker *dev_data;
Jeremy Gebben1ec89332021-08-05 13:51:49 -060066 const VkCommandPoolCreateFlags createFlags;
67 const uint32_t queueFamilyIndex;
68 const VkQueueFlags queue_flags;
69 const bool unprotected; // can't be used for protected memory
Jeremy Gebben159b3cc2021-06-03 09:09:03 -060070 // Cmd buffers allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -060071 layer_data::unordered_map<VkCommandBuffer, CMD_BUFFER_STATE *> commandBuffers;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -060072
Jeremy Gebbencd7fa282021-10-27 10:25:32 -060073 COMMAND_POOL_STATE(ValidationStateTracker *dev, VkCommandPool cp, const VkCommandPoolCreateInfo *pCreateInfo,
74 VkQueueFlags flags);
75 virtual ~COMMAND_POOL_STATE() { Destroy(); }
Jeremy Gebben159b3cc2021-06-03 09:09:03 -060076
77 VkCommandPool commandPool() const { return handle_.Cast<VkCommandPool>(); }
78
Jeremy Gebbencd7fa282021-10-27 10:25:32 -060079 void Allocate(const VkCommandBufferAllocateInfo *create_info, const VkCommandBuffer *command_buffers);
80 void Free(uint32_t count, const VkCommandBuffer *command_buffers);
81 void Reset();
Jeremy Gebben159b3cc2021-06-03 09:09:03 -060082
Jeremy Gebbencd7fa282021-10-27 10:25:32 -060083 void Destroy() override;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -060084};
85
Jeremy Gebben159b3cc2021-06-03 09:09:03 -060086// Autogenerated as part of the command_validation.h codegen
87const char *CommandTypeString(CMD_TYPE type);
88
89enum CB_STATE {
90 CB_NEW, // Newly created CB w/o any cmds
91 CB_RECORDING, // BeginCB has been called on this CB
92 CB_RECORDED, // EndCB has been called on this CB
93 CB_INVALID_COMPLETE, // had a complete recording, but was since invalidated
94 CB_INVALID_INCOMPLETE, // fouled before recording was completed
95};
96
97// CB Status -- used to track status of various bindings on cmd buffer objects
98typedef uint64_t CBStatusFlags;
99enum CBStatusFlagBits : uint64_t {
100 // clang-format off
101 CBSTATUS_NONE = 0x00000000, // No status is set
102 CBSTATUS_LINE_WIDTH_SET = 0x00000001, // Line width has been set
103 CBSTATUS_DEPTH_BIAS_SET = 0x00000002, // Depth bias has been set
104 CBSTATUS_BLEND_CONSTANTS_SET = 0x00000004, // Blend constants state has been set
105 CBSTATUS_DEPTH_BOUNDS_SET = 0x00000008, // Depth bounds state object has been set
106 CBSTATUS_STENCIL_READ_MASK_SET = 0x00000010, // Stencil read mask has been set
107 CBSTATUS_STENCIL_WRITE_MASK_SET = 0x00000020, // Stencil write mask has been set
108 CBSTATUS_STENCIL_REFERENCE_SET = 0x00000040, // Stencil reference has been set
109 CBSTATUS_VIEWPORT_SET = 0x00000080,
110 CBSTATUS_SCISSOR_SET = 0x00000100,
111 CBSTATUS_INDEX_BUFFER_BOUND = 0x00000200, // Index buffer has been set
112 CBSTATUS_EXCLUSIVE_SCISSOR_SET = 0x00000400,
113 CBSTATUS_SHADING_RATE_PALETTE_SET = 0x00000800,
114 CBSTATUS_LINE_STIPPLE_SET = 0x00001000,
115 CBSTATUS_VIEWPORT_W_SCALING_SET = 0x00002000,
116 CBSTATUS_CULL_MODE_SET = 0x00004000,
117 CBSTATUS_FRONT_FACE_SET = 0x00008000,
118 CBSTATUS_PRIMITIVE_TOPOLOGY_SET = 0x00010000,
119 CBSTATUS_VIEWPORT_WITH_COUNT_SET = 0x00020000,
120 CBSTATUS_SCISSOR_WITH_COUNT_SET = 0x00040000,
121 CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET = 0x00080000,
122 CBSTATUS_DEPTH_TEST_ENABLE_SET = 0x00100000,
123 CBSTATUS_DEPTH_WRITE_ENABLE_SET = 0x00200000,
124 CBSTATUS_DEPTH_COMPARE_OP_SET = 0x00400000,
125 CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET = 0x00800000,
126 CBSTATUS_STENCIL_TEST_ENABLE_SET = 0x01000000,
127 CBSTATUS_STENCIL_OP_SET = 0x02000000,
128 CBSTATUS_DISCARD_RECTANGLE_SET = 0x04000000,
129 CBSTATUS_SAMPLE_LOCATIONS_SET = 0x08000000,
130 CBSTATUS_COARSE_SAMPLE_ORDER_SET = 0x10000000,
131 CBSTATUS_PATCH_CONTROL_POINTS_SET = 0x20000000,
132 CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET = 0x40000000,
133 CBSTATUS_DEPTH_BIAS_ENABLE_SET = 0x80000000,
134 CBSTATUS_LOGIC_OP_SET = 0x100000000,
135 CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET = 0x200000000,
136 CBSTATUS_VERTEX_INPUT_SET = 0x400000000,
ziga-lunarg67b7c392022-03-26 01:45:34 +0100137 CBSTATUS_COLOR_WRITE_ENABLE_SET = 0x800000000,
138 CBSTATUS_ALL_STATE_SET = 0xFFFFFFDFF, // All state set (intentionally exclude index buffer)
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600139 // clang-format on
140};
141
142VkDynamicState ConvertToDynamicState(CBStatusFlagBits flag);
143CBStatusFlagBits ConvertToCBStatusFlagBits(VkDynamicState state);
144std::string DynamicStateString(CBStatusFlags input_value);
145
146struct BufferBinding {
147 std::shared_ptr<BUFFER_STATE> buffer_state;
148 VkDeviceSize size;
149 VkDeviceSize offset;
150 VkDeviceSize stride;
151
152 BufferBinding() : buffer_state(), size(0), offset(0), stride(0) {}
153 virtual ~BufferBinding() {}
154
155 virtual void reset() { *this = BufferBinding(); }
156};
157
158struct IndexBufferBinding : BufferBinding {
159 VkIndexType index_type;
160
161 IndexBufferBinding() : BufferBinding(), index_type(static_cast<VkIndexType>(0)) {}
162 virtual ~IndexBufferBinding() {}
163
164 virtual void reset() override { *this = IndexBufferBinding(); }
165};
166
167struct CBVertexBufferBindingInfo {
168 std::vector<BufferBinding> vertex_buffer_bindings;
169};
170
Jeremy Gebben4a8881f2022-01-10 17:04:30 -0700171typedef layer_data::unordered_map<const IMAGE_STATE *, std::shared_ptr<ImageSubresourceLayoutMap>> CommandBufferImageLayoutMap;
172
173typedef layer_data::unordered_map<const GlobalImageLayoutRangeMap *, std::shared_ptr<ImageSubresourceLayoutMap>>
174 CommandBufferAliasedLayoutMap;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600175
176class CMD_BUFFER_STATE : public REFCOUNTED_NODE {
177 public:
178 VkCommandBufferAllocateInfo createInfo = {};
179 VkCommandBufferBeginInfo beginInfo;
180 VkCommandBufferInheritanceInfo inheritanceInfo;
Jeremy Gebbencd7fa282021-10-27 10:25:32 -0600181 // since command buffers can only be destroyed by their command pool, this does not need to be a shared_ptr
182 const COMMAND_POOL_STATE *command_pool;
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600183 ValidationStateTracker *dev_data;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600184 bool hasDrawCmd;
185 bool hasTraceRaysCmd;
186 bool hasBuildAccelerationStructureCmd;
187 bool hasDispatchCmd;
188 bool unprotected; // can't be used for protected memory
189
190 CB_STATE state; // Track cmd buffer update state
191 uint64_t commandCount; // Number of commands recorded. Currently only used with VK_KHR_performance_query
192 uint64_t submitCount; // Number of times CB has been submitted
193 typedef uint64_t ImageLayoutUpdateCount;
194 ImageLayoutUpdateCount image_layout_change_count; // The sequence number for changes to image layout (for cached validation)
195 CBStatusFlags status; // Track status of various bindings on cmd buffer
196 CBStatusFlags static_status; // All state bits provided by current graphics pipeline
197 // rather than dynamic state
198 CBStatusFlags dynamic_status; // dynamic state set up in pipeline
Tony-LunarG40b33882021-12-02 12:40:11 -0700199 std::string begin_rendering_func_name;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600200 // Currently storing "lastBound" objects on per-CB basis
201 // long-term may want to create caches of "lastBound" states and could have
202 // each individual CMD_NODE referencing its own "lastBound" state
203 // Store last bound state for Gfx & Compute pipeline bind points
204 std::array<LAST_BOUND_STATE, BindPoint_Count> lastBound; // index is LvlBindPoint.
205
206 struct CmdDrawDispatchInfo {
207 CMD_TYPE cmd_type;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600208 std::vector<std::pair<const uint32_t, DescriptorRequirement>> binding_infos;
209 VkFramebuffer framebuffer;
210 std::shared_ptr<std::vector<SUBPASS_INFO>> subpasses;
211 std::shared_ptr<std::vector<IMAGE_VIEW_STATE *>> attachments;
212 };
213 layer_data::unordered_map<VkDescriptorSet, std::vector<CmdDrawDispatchInfo>> validate_descriptorsets_in_queuesubmit;
214
215 // If VK_NV_inherited_viewport_scissor is enabled and VkCommandBufferInheritanceViewportScissorInfoNV::viewportScissor2D is
216 // true, then is the nonempty list of viewports passed in pViewportDepths. Otherwise, this is empty.
217 std::vector<VkViewport> inheritedViewportDepths;
218
219 // For each draw command D recorded to this command buffer, let
220 // * g_D be the graphics pipeline used
221 // * v_G be the viewportCount of g_D (0 if g_D disables rasterization or enables VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT)
222 // * s_G be the scissorCount of g_D (0 if g_D disables rasterization or enables VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT_EXT)
223 // Then this value is max(0, max(v_G for all D in cb), max(s_G for all D in cb))
224 uint32_t usedViewportScissorCount;
225 uint32_t pipelineStaticViewportCount; // v_G for currently-bound graphics pipeline.
226 uint32_t pipelineStaticScissorCount; // s_G for currently-bound graphics pipeline.
227
228 uint32_t viewportMask;
229 uint32_t viewportWithCountMask;
230 uint32_t viewportWithCountCount;
231 uint32_t scissorMask;
232 uint32_t scissorWithCountMask;
233 uint32_t scissorWithCountCount;
234
235 // Dynamic viewports set in this command buffer; if bit j of viewportMask is set then dynamicViewports[j] is valid, but the
236 // converse need not be true.
237 std::vector<VkViewport> dynamicViewports;
238
239 // Bits set when binding graphics pipeline defining corresponding static state, or executing any secondary command buffer.
240 // Bits unset by calling a corresponding vkCmdSet[State] cmd.
241 uint32_t trashedViewportMask;
242 uint32_t trashedScissorMask;
243 bool trashedViewportCount;
244 bool trashedScissorCount;
245
246 // True iff any draw command recorded to this command buffer consumes dynamic viewport/scissor with count state.
247 bool usedDynamicViewportCount;
248 bool usedDynamicScissorCount;
249
250 uint32_t initial_device_mask;
251 VkPrimitiveTopology primitiveTopology;
252
253 safe_VkRenderPassBeginInfo activeRenderPassBeginInfo;
254 std::shared_ptr<RENDER_PASS_STATE> activeRenderPass;
255 std::shared_ptr<std::vector<SUBPASS_INFO>> active_subpasses;
256 std::shared_ptr<std::vector<IMAGE_VIEW_STATE *>> active_attachments;
257 std::set<std::shared_ptr<IMAGE_VIEW_STATE>> attachments_view_states;
258
259 VkSubpassContents activeSubpassContents;
260 uint32_t active_render_pass_device_mask;
261 uint32_t activeSubpass;
262 std::shared_ptr<FRAMEBUFFER_STATE> activeFramebuffer;
263 layer_data::unordered_set<std::shared_ptr<FRAMEBUFFER_STATE>> framebuffers;
264 // Unified data structs to track objects bound to this command buffer as well as object
265 // dependencies that have been broken : either destroyed objects, or updated descriptor sets
Jeremy Gebben610d3a62022-01-01 12:53:17 -0700266 layer_data::unordered_set<std::shared_ptr<BASE_NODE>> object_bindings;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600267 layer_data::unordered_map<VulkanTypedHandle, LogObjectList> broken_bindings;
268
269 QFOTransferBarrierSets<QFOBufferTransferBarrier> qfo_transfer_buffer_barriers;
270 QFOTransferBarrierSets<QFOImageTransferBarrier> qfo_transfer_image_barriers;
271
272 layer_data::unordered_set<VkEvent> waitedEvents;
273 std::vector<VkEvent> writeEventsBeforeWait;
274 std::vector<VkEvent> events;
275 layer_data::unordered_set<QueryObject> activeQueries;
276 layer_data::unordered_set<QueryObject> startedQueries;
277 layer_data::unordered_set<QueryObject> resetQueries;
ziga-lunarg96c7d822022-02-28 19:39:17 +0100278 layer_data::unordered_set<QueryObject> updatedQueries;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600279 CommandBufferImageLayoutMap image_layout_map;
Jeremy Gebben4a8881f2022-01-10 17:04:30 -0700280 CommandBufferAliasedLayoutMap aliased_image_layout_map; // storage for potentially aliased images
281
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600282 CBVertexBufferBindingInfo current_vertex_buffer_binding_info;
283 bool vertex_buffer_used; // Track for perf warning to make sure any bound vtx buffer used
284 VkCommandBuffer primaryCommandBuffer;
285 // If primary, the secondary command buffers we will call.
286 // If secondary, the primary command buffers we will be called by.
287 layer_data::unordered_set<CMD_BUFFER_STATE *> linkedCommandBuffers;
288 // Validation functions run at primary CB queue submit time
Jeremy Gebbene5361dd2021-11-18 14:23:56 -0700289 using QueueCallback = std::function<bool(const ValidationStateTracker &device_data, const class QUEUE_STATE &queue_state,
290 const CMD_BUFFER_STATE &cb_state)>;
291 std::vector<QueueCallback> queue_submit_functions;
Hans-Kristian Arntzen59c2c3f2021-06-14 11:40:12 +0200292 // Used by some layers to defer actions until vkCmdEndRenderPass time.
293 // Layers using this are responsible for inserting the callbacks into queue_submit_functions.
Jeremy Gebbene5361dd2021-11-18 14:23:56 -0700294 std::vector<QueueCallback> queue_submit_functions_after_render_pass;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600295 // Validation functions run when secondary CB is executed in primary
Jeremy Gebben057f9d52021-11-05 14:12:31 -0600296 std::vector<std::function<bool(const CMD_BUFFER_STATE &secondary, const CMD_BUFFER_STATE *primary, const FRAMEBUFFER_STATE *)>>
297 cmd_execute_commands_functions;
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700298 std::vector<std::function<bool(CMD_BUFFER_STATE &cb, bool do_validate, EventToStageMap *localEventToStageMap)>> eventUpdates;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600299 std::vector<std::function<bool(const ValidationStateTracker *device_data, bool do_validate, VkQueryPool &firstPerfQueryPool,
300 uint32_t perfQueryPass, QueryMap *localQueryToStateMap)>>
301 queryUpdates;
Jeremy Gebben87db52f2021-10-14 13:55:09 -0600302 layer_data::unordered_set<const cvdescriptorset::DescriptorSet *> validated_descriptor_sets;
303 layer_data::unordered_map<const cvdescriptorset::DescriptorSet *, cvdescriptorset::DescriptorSet::CachedValidation>
304 descriptorset_cache;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600305 // Contents valid only after an index buffer is bound (CBSTATUS_INDEX_BUFFER_BOUND set)
306 IndexBufferBinding index_buffer_binding;
307 bool performance_lock_acquired = false;
308 bool performance_lock_released = false;
309
310 // Cache of current insert label...
311 LoggingLabel debug_label;
312
313 std::vector<uint8_t> push_constant_data;
314 PushConstantRangesId push_constant_data_ranges;
315
316 std::map<VkShaderStageFlagBits, std::vector<uint8_t>>
317 push_constant_data_update; // vector's value is enum PushConstantByteState.
318 VkPipelineLayout push_constant_pipeline_layout_set;
319
320 // Used for Best Practices tracking
321 uint32_t small_indexed_draw_call_count;
322
323 bool transform_feedback_active{false};
ziga-lunarg40f5fbc2021-08-14 23:06:41 +0200324 bool conditional_rendering_active{false};
ziga-lunarg39eeaf22021-09-03 19:12:44 +0200325 bool conditional_rendering_inside_render_pass{false};
326 uint32_t conditional_rendering_subpass{0};
ziga-lunarg67b7c392022-03-26 01:45:34 +0100327 uint32_t dynamicColorWriteEnableAttachmentCount{0};
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700328 mutable ReadWriteLock lock;
329 ReadLockGuard ReadLock() const { return ReadLockGuard(lock); }
330 WriteLockGuard WriteLock() { return WriteLockGuard(lock); }
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600331
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600332 CMD_BUFFER_STATE(ValidationStateTracker *, VkCommandBuffer cb, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -0600333 const COMMAND_POOL_STATE *cmd_pool);
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600334
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600335 virtual ~CMD_BUFFER_STATE() { Destroy(); }
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600336
337 void Destroy() override;
338
339 VkCommandBuffer commandBuffer() const { return handle_.Cast<VkCommandBuffer>(); }
340
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600341 IMAGE_VIEW_STATE *GetActiveAttachmentImageViewState(uint32_t index);
342 const IMAGE_VIEW_STATE *GetActiveAttachmentImageViewState(uint32_t index) const;
343
Jeremy Gebben610d3a62022-01-01 12:53:17 -0700344 void AddChild(std::shared_ptr<BASE_NODE> &base_node);
Jeremy Gebben9f537102021-10-05 16:37:12 -0600345 template <typename StateObject>
346 void AddChild(std::shared_ptr<StateObject> &child_node) {
Jeremy Gebben610d3a62022-01-01 12:53:17 -0700347 auto base = std::static_pointer_cast<BASE_NODE>(child_node);
348 AddChild(base);
Jeremy Gebben9f537102021-10-05 16:37:12 -0600349 }
350
Jeremy Gebben610d3a62022-01-01 12:53:17 -0700351 void RemoveChild(std::shared_ptr<BASE_NODE> &base_node);
352 template <typename StateObject>
353 void RemoveChild(std::shared_ptr<StateObject> &child_node) {
354 auto base = std::static_pointer_cast<BASE_NODE>(child_node);
355 RemoveChild(base);
356 }
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600357
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600358 virtual void Reset();
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600359
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600360 void IncrementResources();
361
362 void ResetPushConstantDataIfIncompatible(const PIPELINE_LAYOUT_STATE *pipeline_layout_state);
363
Jeremy Gebben6335df62021-11-01 10:50:13 -0600364 const ImageSubresourceLayoutMap *GetImageSubresourceLayoutMap(const IMAGE_STATE &image_state) const;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600365 ImageSubresourceLayoutMap *GetImageSubresourceLayoutMap(const IMAGE_STATE &image_state);
ziga-lunarg189ae5d2021-10-19 13:09:58 +0200366 const CommandBufferImageLayoutMap& GetImageSubresourceLayoutMap() const;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600367
368 const QFOTransferBarrierSets<QFOImageTransferBarrier> &GetQFOBarrierSets(const QFOImageTransferBarrier &type_tag) const {
369 return qfo_transfer_image_barriers;
370 }
371
372 const QFOTransferBarrierSets<QFOBufferTransferBarrier> &GetQFOBarrierSets(const QFOBufferTransferBarrier &type_tag) const {
373 return qfo_transfer_buffer_barriers;
374 }
375
376 QFOTransferBarrierSets<QFOImageTransferBarrier> &GetQFOBarrierSets(const QFOImageTransferBarrier &type_tag) {
377 return qfo_transfer_image_barriers;
378 }
379
380 QFOTransferBarrierSets<QFOBufferTransferBarrier> &GetQFOBarrierSets(const QFOBufferTransferBarrier &type_tag) {
381 return qfo_transfer_buffer_barriers;
382 }
383
384 PIPELINE_STATE *GetCurrentPipeline(VkPipelineBindPoint pipelineBindPoint) const {
385 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
386 return lastBound[lv_bind_point].pipeline_state;
387 }
388
389 void GetCurrentPipelineAndDesriptorSets(VkPipelineBindPoint pipelineBindPoint, const PIPELINE_STATE **rtn_pipe,
390 const std::vector<LAST_BOUND_STATE::PER_SET> **rtn_sets) const {
391 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
392 const auto &last_bound_it = lastBound[lv_bind_point];
393 if (!last_bound_it.IsUsing()) {
394 return;
395 }
396 *rtn_pipe = last_bound_it.pipeline_state;
397 *rtn_sets = &(last_bound_it.per_set);
398 }
399
400 VkQueueFlags GetQueueFlags() const {
401 return command_pool->queue_flags;
402 }
403
Jeremy Gebbenefead332021-06-18 08:22:44 -0600404 template <typename Barrier>
Jeremy Gebben7ba56152021-06-18 10:40:10 -0600405 inline bool IsReleaseOp(const Barrier &barrier) const {
406 return (IsTransferOp(barrier)) && (command_pool->queueFamilyIndex == barrier.srcQueueFamilyIndex);
407 }
408 template <typename Barrier>
409 inline bool IsAcquireOp(const Barrier &barrier) const {
410 return (IsTransferOp(barrier)) && (command_pool->queueFamilyIndex == barrier.dstQueueFamilyIndex);
Jeremy Gebbenefead332021-06-18 08:22:44 -0600411 }
412
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600413 void Begin(const VkCommandBufferBeginInfo *pBeginInfo);
414 void End(VkResult result);
415
416 void BeginQuery(const QueryObject &query_obj);
417 void EndQuery(const QueryObject &query_obj);
418 void EndQueries(VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount);
419 void ResetQueryPool(VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount);
420
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600421 void BeginRenderPass(CMD_TYPE cmd_type, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents);
422 void NextSubpass(CMD_TYPE cmd_type, VkSubpassContents contents);
423 void EndRenderPass(CMD_TYPE cmd_type);
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600424
Tony-LunarG40b33882021-12-02 12:40:11 -0700425 void BeginRendering(CMD_TYPE cmd_type, const VkRenderingInfo *pRenderingInfo);
amhagana448ea52021-11-02 14:09:14 -0400426
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600427 void ExecuteCommands(uint32_t commandBuffersCount, const VkCommandBuffer *pCommandBuffers);
428
429 void UpdateLastBoundDescriptorSets(VkPipelineBindPoint pipeline_bind_point, const PIPELINE_LAYOUT_STATE *pipeline_layout,
430 uint32_t first_set, uint32_t set_count, const VkDescriptorSet *pDescriptorSets,
Jeremy Gebben4d51c552022-01-06 21:27:15 -0700431 std::shared_ptr<cvdescriptorset::DescriptorSet> &push_descriptor_set,
432 uint32_t dynamic_offset_count, const uint32_t *p_dynamic_offsets);
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600433
434 void PushDescriptorSetState(VkPipelineBindPoint pipelineBindPoint, PIPELINE_LAYOUT_STATE *pipeline_layout, uint32_t set,
435 uint32_t descriptorWriteCount, const VkWriteDescriptorSet *pDescriptorWrites);
436
sfricke-samsung85584a72021-09-30 21:43:38 -0700437 void UpdateStateCmdDrawDispatchType(CMD_TYPE cmd_type, VkPipelineBindPoint bind_point);
438 void UpdateStateCmdDrawType(CMD_TYPE cmd_type, VkPipelineBindPoint bind_point);
439 void UpdateDrawState(CMD_TYPE cmd_type, const VkPipelineBindPoint bind_point);
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600440
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600441 virtual void RecordCmd(CMD_TYPE cmd_type);
442 void RecordStateCmd(CMD_TYPE cmd_type, CBStatusFlags state_bits);
ziga-lunarg67b7c392022-03-26 01:45:34 +0100443 void RecordColorWriteEnableStateCmd(CMD_TYPE cmd_type, CBStatusFlags state_bits, uint32_t attachment_count);
Jeremy Gebben9f537102021-10-05 16:37:12 -0600444 void RecordTransferCmd(CMD_TYPE cmd_type, std::shared_ptr<BINDABLE> &&buf1, std::shared_ptr<BINDABLE> &&buf2 = nullptr);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -0600445 void RecordSetEvent(CMD_TYPE cmd_type, VkEvent event, VkPipelineStageFlags2KHR stageMask);
446 void RecordResetEvent(CMD_TYPE cmd_type, VkEvent event, VkPipelineStageFlags2KHR stageMask);
Jeremy Gebben332d4dd2022-01-01 12:40:02 -0700447 virtual void RecordWaitEvents(CMD_TYPE cmd_type, uint32_t eventCount, const VkEvent *pEvents,
448 VkPipelineStageFlags2KHR src_stage_mask);
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -0600449 void RecordWriteTimestamp(CMD_TYPE cmd_type, VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool, uint32_t slot);
450
451 void RecordBarriers(uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount,
452 const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount,
453 const VkImageMemoryBarrier *pImageMemoryBarriers);
454 void RecordBarriers(const VkDependencyInfoKHR &dep_info);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600455
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600456 void SetImageViewLayout(const IMAGE_VIEW_STATE &view_state, VkImageLayout layout, VkImageLayout layoutStencil);
457 void SetImageViewInitialLayout(const IMAGE_VIEW_STATE &view_state, VkImageLayout layout);
458
459 void SetImageLayout(const IMAGE_STATE &image_state, const VkImageSubresourceRange &image_subresource_range,
460 VkImageLayout layout, VkImageLayout expected_layout = kInvalidLayout);
461 void SetImageLayout(const IMAGE_STATE &image_state, const VkImageSubresourceLayers &image_subresource_layers,
462 VkImageLayout layout);
463 void SetImageInitialLayout(VkImage image, const VkImageSubresourceRange &range, VkImageLayout layout);
464 void SetImageInitialLayout(const IMAGE_STATE &image_state, const VkImageSubresourceRange &range, VkImageLayout layout);
465 void SetImageInitialLayout(const IMAGE_STATE &image_state, const VkImageSubresourceLayers &layers, VkImageLayout layout);
466
Jeremy Gebben57642982021-09-14 14:14:55 -0600467 void Submit(uint32_t perf_submit_pass);
ziga-lunarg96c7d822022-02-28 19:39:17 +0100468 void Retire(uint32_t perf_submit_pass, const std::function<bool(const QueryObject &)> &is_query_updated_after);
Jeremy Gebben57642982021-09-14 14:14:55 -0600469
amhagana448ea52021-11-02 14:09:14 -0400470 uint32_t GetDynamicColorAttachmentCount() {
471 if (activeRenderPass) {
472 if (activeRenderPass->use_dynamic_rendering_inherited) {
473 return activeRenderPass->inheritance_rendering_info.colorAttachmentCount;
474 }
475 if (activeRenderPass->use_dynamic_rendering) {
Aaron Hagan92a44f82021-11-19 09:34:56 -0500476 return activeRenderPass->dynamic_rendering_begin_rendering_info.colorAttachmentCount;
amhagana448ea52021-11-02 14:09:14 -0400477 }
478 }
479 return 0;
480 }
481 uint32_t GetDynamicColorAttachmentImageIndex(uint32_t index) { return index; }
482 uint32_t GetDynamicColorResolveAttachmentImageIndex(uint32_t index) { return index + GetDynamicColorAttachmentCount(); }
483 uint32_t GetDynamicDepthAttachmentImageIndex() { return 2 * GetDynamicColorAttachmentCount(); }
484 uint32_t GetDynamicDepthResolveAttachmentImageIndex() { return 2 * GetDynamicColorAttachmentCount() + 1; }
485 uint32_t GetDynamicStencilAttachmentImageIndex() { return 2 * GetDynamicColorAttachmentCount() + 2; }
486 uint32_t GetDynamicStencilResolveAttachmentImageIndex() { return 2 * GetDynamicColorAttachmentCount() + 3; }
487
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600488 protected:
Jeremy Gebbenc9a24032021-11-02 11:36:08 -0600489 void NotifyInvalidate(const BASE_NODE::NodeList &invalid_nodes, bool unlink) override;
Jeremy Gebben1ec89332021-08-05 13:51:49 -0600490 void UpdateAttachmentsView(const VkRenderPassBeginInfo *pRenderPassBegin);
aitor-lunarga131fca2022-02-17 22:55:55 +0100491 void UnbindResources();
Jeremy Gebben159b3cc2021-06-03 09:09:03 -0600492};
Jeremy Gebben7ba56152021-06-18 10:40:10 -0600493
494// specializations for barriers that cannot do queue family ownership transfers
495template <>
496inline bool CMD_BUFFER_STATE::IsReleaseOp(const VkMemoryBarrier &barrier) const {
497 return false;
498}
499template <>
500inline bool CMD_BUFFER_STATE::IsReleaseOp(const VkMemoryBarrier2KHR &barrier) const {
501 return false;
502}
503template <>
504inline bool CMD_BUFFER_STATE::IsReleaseOp(const VkSubpassDependency2 &barrier) const {
505 return false;
506}
507template <>
508inline bool CMD_BUFFER_STATE::IsAcquireOp(const VkMemoryBarrier &barrier) const {
509 return false;
510}
511template <>
512inline bool CMD_BUFFER_STATE::IsAcquireOp(const VkMemoryBarrier2KHR &barrier) const {
513 return false;
514}
515template <>
516inline bool CMD_BUFFER_STATE::IsAcquireOp(const VkSubpassDependency2 &barrier) const {
517 return false;
518}