1 /*
2 * Copyright 2019 Google LLC
3 * SPDX-License-Identifier: MIT
4 *
5 * based in part on anv and radv which are:
6 * Copyright © 2015 Intel Corporation
7 * Copyright © 2016 Red Hat.
8 * Copyright © 2016 Bas Nieuwenhuizen
9 */
10
11 #ifndef VN_COMMAND_BUFFER_H
12 #define VN_COMMAND_BUFFER_H
13
14 #include "vn_common.h"
15
16 #include "vn_cs.h"
17
18 struct vn_command_pool {
19 struct vn_object_base base;
20
21 VkAllocationCallbacks allocator;
22 struct vn_device *device;
23 uint32_t queue_family_index;
24
25 struct list_head command_buffers;
26
27 /* The list contains the recycled query records allocated from the same
28 * command pool.
29 *
30 * For normal cmd pool, no additional locking is needed as below have
31 * already been protected by external synchronization:
32 * - alloc: record query, reset query and patch-in query records from the
33 * secondary cmds
34 * - recycle: explicit and implicit cmd reset, cmd free and pool reset
35 * - free: pool purge reset and pool destroy
36 *
37 * For feedback cmd pool, external locking is needed for now for below:
38 * - alloc: queue submission
39 * - recycle: queue submission and companion cmd reset/free
40 * - free: device destroy
41 */
42 struct list_head free_query_records;
43
44 /* for scrubbing VK_IMAGE_LAYOUT_PRESENT_SRC_KHR */
45 struct vn_cached_storage storage;
46 };
47 VK_DEFINE_NONDISP_HANDLE_CASTS(vn_command_pool,
48 base.base,
49 VkCommandPool,
50 VK_OBJECT_TYPE_COMMAND_POOL)
51
52 enum vn_command_buffer_state {
53 VN_COMMAND_BUFFER_STATE_INITIAL,
54 VN_COMMAND_BUFFER_STATE_RECORDING,
55 VN_COMMAND_BUFFER_STATE_EXECUTABLE,
56 VN_COMMAND_BUFFER_STATE_INVALID,
57 };
58
59 /* command buffer builder to:
60 * - fix wsi image ownership and layout transitions
61 * - scrub ignored bits in VkCommandBufferBeginInfo
62 * - support asynchronization query optimization (query feedback)
63 */
64 struct vn_command_buffer_builder {
65 /* track the active legacy render pass */
66 const struct vn_render_pass *render_pass;
67 /* track the wsi images requiring layout fixes */
68 const struct vn_image **present_src_images;
69 /* track if inside a render pass instance */
70 bool in_render_pass;
71 /* track the active subpass for view mask used in the subpass */
72 uint32_t subpass_index;
73 /* track the active view mask inside a render pass instance */
74 uint32_t view_mask;
75 /* track if VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT was set */
76 bool is_simultaneous;
77 /* track the recorded queries and resets */
78 struct list_head query_records;
79 };
80
81 struct vn_query_feedback_cmd;
82
83 struct vn_command_buffer {
84 struct vn_object_base base;
85
86 struct vn_command_pool *pool;
87 VkCommandBufferLevel level;
88 enum vn_command_buffer_state state;
89 struct vn_cs_encoder cs;
90
91 struct vn_command_buffer_builder builder;
92
93 struct vn_query_feedback_cmd *linked_qfb_cmd;
94
95 struct list_head head;
96 };
97 VK_DEFINE_HANDLE_CASTS(vn_command_buffer,
98 base.base,
99 VkCommandBuffer,
100 VK_OBJECT_TYPE_COMMAND_BUFFER)
101
102 /* Queries recorded to support qfb.
103 * - query_count is the actual queries used with multiview considered
104 * - copy is whether the record is for result copy or query reset
105 *
106 * The query records are tracked at each cmd with the recording order. Those
107 * from the secondary cmds are patched into the primary ones at this moment.
108 */
109 struct vn_cmd_query_record {
110 struct vn_query_pool *query_pool;
111 uint32_t query;
112 uint32_t query_count;
113 bool copy;
114
115 struct list_head head;
116 };
117
118 struct vn_cmd_query_record *
119 vn_cmd_pool_alloc_query_record(struct vn_command_pool *cmd_pool,
120 struct vn_query_pool *query_pool,
121 uint32_t query,
122 uint32_t query_count,
123 bool copy);
124
125 static inline void
vn_cmd_pool_free_query_records(struct vn_command_pool * cmd_pool,struct list_head * query_records)126 vn_cmd_pool_free_query_records(struct vn_command_pool *cmd_pool,
127 struct list_head *query_records)
128 {
129 list_splicetail(query_records, &cmd_pool->free_query_records);
130 }
131
132 #endif /* VN_COMMAND_BUFFER_H */
133