1 /*
2 * Copyright © 2021 Collabora Ltd.
3 * SPDX-License-Identifier: MIT
4 */
5
6 #ifndef PANVK_CMD_BUFFER_H
7 #define PANVK_CMD_BUFFER_H
8
9 #ifndef PAN_ARCH
10 #error "PAN_ARCH must be defined"
11 #endif
12
13 #include <stdint.h>
14
15 #include "vulkan/runtime/vk_command_buffer.h"
16
17 #include "panvk_cmd_desc_state.h"
18 #include "panvk_cmd_push_constant.h"
19 #include "panvk_descriptor_set.h"
20 #include "panvk_descriptor_set_layout.h"
21 #include "panvk_device.h"
22 #include "panvk_macros.h"
23 #include "panvk_mempool.h"
24 #include "panvk_shader.h"
25
26 #include "pan_jc.h"
27
28 #include "util/list.h"
29
30 #include "genxml/gen_macros.h"
31
32 #define MAX_BIND_POINTS 2 /* compute + graphics */
33 #define MAX_VBS 16
34 #define MAX_RTS 8
35
36 struct panvk_batch {
37 struct list_head node;
38 struct util_dynarray jobs;
39 struct util_dynarray event_ops;
40 struct pan_jc vtc_jc;
41 struct pan_jc frag_jc;
42 struct {
43 struct panfrost_ptr desc;
44 uint32_t desc_stride;
45 uint32_t bo_count;
46
47 /* One slot per color, two more slots for the depth/stencil buffers. */
48 struct pan_kmod_bo *bos[MAX_RTS + 2];
49 uint32_t layer_count;
50 } fb;
51 struct {
52 struct pan_kmod_bo *src, *dst;
53 } blit;
54 struct panfrost_ptr tls;
55 struct {
56 struct pan_tiler_context ctx;
57 struct panfrost_ptr heap_desc;
58 struct panfrost_ptr ctx_descs;
59 struct mali_tiler_heap_packed heap_templ;
60 struct mali_tiler_context_packed ctx_templ;
61 } tiler;
62 struct pan_tls_info tlsinfo;
63 unsigned wls_total_size;
64 bool issued;
65 };
66
67 enum panvk_cmd_event_op_type {
68 PANVK_EVENT_OP_SET,
69 PANVK_EVENT_OP_RESET,
70 PANVK_EVENT_OP_WAIT,
71 };
72
73 struct panvk_cmd_event_op {
74 enum panvk_cmd_event_op_type type;
75 struct panvk_event *event;
76 };
77
78 struct panvk_attrib_buf {
79 mali_ptr address;
80 unsigned size;
81 };
82
83 struct panvk_resolve_attachment {
84 VkResolveModeFlagBits mode;
85 struct panvk_image_view *src_iview;
86 struct panvk_image_view *dst_iview;
87 };
88
89 struct panvk_cmd_graphics_state {
90 struct panvk_descriptor_state desc_state;
91
92 struct {
93 struct vk_vertex_input_state vi;
94 struct vk_sample_locations_state sl;
95 } dynamic;
96
97 uint32_t dirty;
98
99 struct panvk_graphics_sysvals sysvals;
100
101 struct panvk_shader_link link;
102 bool linked;
103
104 struct {
105 const struct panvk_shader *shader;
106 mali_ptr rsd;
107 #if PAN_ARCH <= 7
108 struct panvk_shader_desc_state desc;
109 #endif
110 } fs;
111
112 struct {
113 const struct panvk_shader *shader;
114 mali_ptr attribs;
115 mali_ptr attrib_bufs;
116 #if PAN_ARCH <= 7
117 struct panvk_shader_desc_state desc;
118 #endif
119 } vs;
120
121 struct {
122 struct panvk_attrib_buf bufs[MAX_VBS];
123 unsigned count;
124 } vb;
125
126 /* Index buffer */
127 struct {
128 struct panvk_buffer *buffer;
129 uint64_t offset;
130 uint8_t index_size;
131 uint32_t first_vertex, base_vertex, base_instance;
132 } ib;
133
134 struct {
135 VkRenderingFlags flags;
136 uint32_t layer_count;
137
138 enum vk_rp_attachment_flags bound_attachments;
139 struct {
140 VkFormat fmts[MAX_RTS];
141 uint8_t samples[MAX_RTS];
142 struct panvk_resolve_attachment resolve[MAX_RTS];
143 } color_attachments;
144
145 struct pan_image_view zs_pview;
146
147 struct {
148 struct panvk_resolve_attachment resolve;
149 } z_attachment, s_attachment;
150
151 struct {
152 struct pan_fb_info info;
153 bool crc_valid[MAX_RTS];
154 uint32_t bo_count;
155 struct pan_kmod_bo *bos[MAX_RTS + 2];
156 } fb;
157 } render;
158
159 mali_ptr vpd;
160 mali_ptr push_uniforms;
161 };
162
163 struct panvk_cmd_compute_state {
164 struct panvk_descriptor_state desc_state;
165 const struct panvk_shader *shader;
166 struct panvk_compute_sysvals sysvals;
167 mali_ptr push_uniforms;
168 #if PAN_ARCH <= 7
169 struct {
170 struct panvk_shader_desc_state desc;
171 } cs;
172 #endif
173 };
174
175 struct panvk_cmd_buffer {
176 struct vk_command_buffer vk;
177
178 struct panvk_pool desc_pool;
179 struct panvk_pool varying_pool;
180 struct panvk_pool tls_pool;
181 struct list_head batches;
182 struct list_head push_sets;
183 struct panvk_batch *cur_batch;
184
185 struct {
186 struct panvk_cmd_graphics_state gfx;
187 struct panvk_cmd_compute_state compute;
188 struct panvk_push_constant_state push_constants;
189 } state;
190 };
191
192 VK_DEFINE_HANDLE_CASTS(panvk_cmd_buffer, vk.base, VkCommandBuffer,
193 VK_OBJECT_TYPE_COMMAND_BUFFER)
194
195 #define panvk_cmd_buffer_obj_list_init(cmdbuf, list_name) \
196 list_inithead(&(cmdbuf)->list_name)
197
198 #define panvk_cmd_buffer_obj_list_cleanup(cmdbuf, list_name) \
199 do { \
200 struct panvk_cmd_pool *__pool = \
201 container_of(cmdbuf->vk.pool, struct panvk_cmd_pool, vk); \
202 list_splicetail(&(cmdbuf)->list_name, &__pool->list_name); \
203 } while (0)
204
205 #define panvk_cmd_buffer_obj_list_reset(cmdbuf, list_name) \
206 do { \
207 struct panvk_cmd_pool *__pool = \
208 container_of(cmdbuf->vk.pool, struct panvk_cmd_pool, vk); \
209 list_splicetail(&(cmdbuf)->list_name, &__pool->list_name); \
210 list_inithead(&(cmdbuf)->list_name); \
211 } while (0)
212
213 static inline struct panvk_descriptor_state *
panvk_cmd_get_desc_state(struct panvk_cmd_buffer * cmdbuf,VkPipelineBindPoint bindpoint)214 panvk_cmd_get_desc_state(struct panvk_cmd_buffer *cmdbuf,
215 VkPipelineBindPoint bindpoint)
216 {
217 switch (bindpoint) {
218 case VK_PIPELINE_BIND_POINT_GRAPHICS:
219 return &cmdbuf->state.gfx.desc_state;
220
221 case VK_PIPELINE_BIND_POINT_COMPUTE:
222 return &cmdbuf->state.compute.desc_state;
223
224 default:
225 assert(!"Unsupported bind point");
226 return NULL;
227 }
228 }
229
230 extern const struct vk_command_buffer_ops panvk_per_arch(cmd_buffer_ops);
231
232 struct panvk_batch *
233 panvk_per_arch(cmd_open_batch)(struct panvk_cmd_buffer *cmdbuf);
234
235 void panvk_per_arch(cmd_close_batch)(struct panvk_cmd_buffer *cmdbuf);
236
237 VkResult panvk_per_arch(cmd_alloc_fb_desc)(struct panvk_cmd_buffer *cmdbuf);
238
239 VkResult panvk_per_arch(cmd_alloc_tls_desc)(struct panvk_cmd_buffer *cmdbuf,
240 bool gfx);
241
242 VkResult
243 panvk_per_arch(cmd_prepare_tiler_context)(struct panvk_cmd_buffer *cmdbuf,
244 uint32_t layer_idx);
245
246 void panvk_per_arch(cmd_preload_fb_after_batch_split)(
247 struct panvk_cmd_buffer *cmdbuf);
248
249 void panvk_per_arch(cmd_bind_shaders)(struct vk_command_buffer *vk_cmd,
250 uint32_t stage_count,
251 const gl_shader_stage *stages,
252 struct vk_shader **const shaders);
253
254 #endif
255