2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
28 #include "tu_private.h"
30 #include "registers/adreno_pm4.xml.h"
31 #include "registers/adreno_common.xml.h"
33 #include "vk_format.h"
37 #define OVERFLOW_FLAG_REG REG_A6XX_CP_SCRATCH_REG(0)
40 tu_bo_list_init(struct tu_bo_list
*list
)
42 list
->count
= list
->capacity
= 0;
43 list
->bo_infos
= NULL
;
47 tu_bo_list_destroy(struct tu_bo_list
*list
)
53 tu_bo_list_reset(struct tu_bo_list
*list
)
59 * \a flags consists of MSM_SUBMIT_BO_FLAGS.
62 tu_bo_list_add_info(struct tu_bo_list
*list
,
63 const struct drm_msm_gem_submit_bo
*bo_info
)
65 assert(bo_info
->handle
!= 0);
67 for (uint32_t i
= 0; i
< list
->count
; ++i
) {
68 if (list
->bo_infos
[i
].handle
== bo_info
->handle
) {
69 assert(list
->bo_infos
[i
].presumed
== bo_info
->presumed
);
70 list
->bo_infos
[i
].flags
|= bo_info
->flags
;
75 /* grow list->bo_infos if needed */
76 if (list
->count
== list
->capacity
) {
77 uint32_t new_capacity
= MAX2(2 * list
->count
, 16);
78 struct drm_msm_gem_submit_bo
*new_bo_infos
= realloc(
79 list
->bo_infos
, new_capacity
* sizeof(struct drm_msm_gem_submit_bo
));
81 return TU_BO_LIST_FAILED
;
82 list
->bo_infos
= new_bo_infos
;
83 list
->capacity
= new_capacity
;
86 list
->bo_infos
[list
->count
] = *bo_info
;
91 tu_bo_list_add(struct tu_bo_list
*list
,
92 const struct tu_bo
*bo
,
95 return tu_bo_list_add_info(list
, &(struct drm_msm_gem_submit_bo
) {
97 .handle
= bo
->gem_handle
,
103 tu_bo_list_merge(struct tu_bo_list
*list
, const struct tu_bo_list
*other
)
105 for (uint32_t i
= 0; i
< other
->count
; i
++) {
106 if (tu_bo_list_add_info(list
, other
->bo_infos
+ i
) == TU_BO_LIST_FAILED
)
107 return VK_ERROR_OUT_OF_HOST_MEMORY
;
114 tu_tiling_config_update_tile_layout(struct tu_tiling_config
*tiling
,
115 const struct tu_device
*dev
,
116 const struct tu_render_pass
*pass
)
118 const uint32_t tile_align_w
= pass
->tile_align_w
;
119 const uint32_t max_tile_width
= 1024;
121 /* note: don't offset the tiling config by render_area.offset,
122 * because binning pass can't deal with it
123 * this means we might end up with more tiles than necessary,
124 * but load/store/etc are still scissored to the render_area
126 tiling
->tile0
.offset
= (VkOffset2D
) {};
128 const uint32_t ra_width
=
129 tiling
->render_area
.extent
.width
+
130 (tiling
->render_area
.offset
.x
- tiling
->tile0
.offset
.x
);
131 const uint32_t ra_height
=
132 tiling
->render_area
.extent
.height
+
133 (tiling
->render_area
.offset
.y
- tiling
->tile0
.offset
.y
);
135 /* start from 1 tile */
136 tiling
->tile_count
= (VkExtent2D
) {
140 tiling
->tile0
.extent
= (VkExtent2D
) {
141 .width
= util_align_npot(ra_width
, tile_align_w
),
142 .height
= align(ra_height
, TILE_ALIGN_H
),
145 if (unlikely(dev
->physical_device
->instance
->debug_flags
& TU_DEBUG_FORCEBIN
)) {
146 /* start with 2x2 tiles */
147 tiling
->tile_count
.width
= 2;
148 tiling
->tile_count
.height
= 2;
149 tiling
->tile0
.extent
.width
= util_align_npot(DIV_ROUND_UP(ra_width
, 2), tile_align_w
);
150 tiling
->tile0
.extent
.height
= align(DIV_ROUND_UP(ra_height
, 2), TILE_ALIGN_H
);
153 /* do not exceed max tile width */
154 while (tiling
->tile0
.extent
.width
> max_tile_width
) {
155 tiling
->tile_count
.width
++;
156 tiling
->tile0
.extent
.width
=
157 util_align_npot(DIV_ROUND_UP(ra_width
, tiling
->tile_count
.width
), tile_align_w
);
160 /* will force to sysmem, don't bother trying to have a valid tile config
161 * TODO: just skip all GMEM stuff when sysmem is forced?
163 if (!pass
->gmem_pixels
)
166 /* do not exceed gmem size */
167 while (tiling
->tile0
.extent
.width
* tiling
->tile0
.extent
.height
> pass
->gmem_pixels
) {
168 if (tiling
->tile0
.extent
.width
> MAX2(tile_align_w
, tiling
->tile0
.extent
.height
)) {
169 tiling
->tile_count
.width
++;
170 tiling
->tile0
.extent
.width
=
171 util_align_npot(DIV_ROUND_UP(ra_width
, tiling
->tile_count
.width
), tile_align_w
);
173 /* if this assert fails then layout is impossible.. */
174 assert(tiling
->tile0
.extent
.height
> TILE_ALIGN_H
);
175 tiling
->tile_count
.height
++;
176 tiling
->tile0
.extent
.height
=
177 align(DIV_ROUND_UP(ra_height
, tiling
->tile_count
.height
), TILE_ALIGN_H
);
183 tu_tiling_config_update_pipe_layout(struct tu_tiling_config
*tiling
,
184 const struct tu_device
*dev
)
186 const uint32_t max_pipe_count
= 32; /* A6xx */
188 /* start from 1 tile per pipe */
189 tiling
->pipe0
= (VkExtent2D
) {
193 tiling
->pipe_count
= tiling
->tile_count
;
195 while (tiling
->pipe_count
.width
* tiling
->pipe_count
.height
> max_pipe_count
) {
196 if (tiling
->pipe0
.width
< tiling
->pipe0
.height
) {
197 tiling
->pipe0
.width
+= 1;
198 tiling
->pipe_count
.width
=
199 DIV_ROUND_UP(tiling
->tile_count
.width
, tiling
->pipe0
.width
);
201 tiling
->pipe0
.height
+= 1;
202 tiling
->pipe_count
.height
=
203 DIV_ROUND_UP(tiling
->tile_count
.height
, tiling
->pipe0
.height
);
209 tu_tiling_config_update_pipes(struct tu_tiling_config
*tiling
,
210 const struct tu_device
*dev
)
212 const uint32_t max_pipe_count
= 32; /* A6xx */
213 const uint32_t used_pipe_count
=
214 tiling
->pipe_count
.width
* tiling
->pipe_count
.height
;
215 const VkExtent2D last_pipe
= {
216 .width
= (tiling
->tile_count
.width
- 1) % tiling
->pipe0
.width
+ 1,
217 .height
= (tiling
->tile_count
.height
- 1) % tiling
->pipe0
.height
+ 1,
220 assert(used_pipe_count
<= max_pipe_count
);
221 assert(max_pipe_count
<= ARRAY_SIZE(tiling
->pipe_config
));
223 for (uint32_t y
= 0; y
< tiling
->pipe_count
.height
; y
++) {
224 for (uint32_t x
= 0; x
< tiling
->pipe_count
.width
; x
++) {
225 const uint32_t pipe_x
= tiling
->pipe0
.width
* x
;
226 const uint32_t pipe_y
= tiling
->pipe0
.height
* y
;
227 const uint32_t pipe_w
= (x
== tiling
->pipe_count
.width
- 1)
229 : tiling
->pipe0
.width
;
230 const uint32_t pipe_h
= (y
== tiling
->pipe_count
.height
- 1)
232 : tiling
->pipe0
.height
;
233 const uint32_t n
= tiling
->pipe_count
.width
* y
+ x
;
235 tiling
->pipe_config
[n
] = A6XX_VSC_PIPE_CONFIG_REG_X(pipe_x
) |
236 A6XX_VSC_PIPE_CONFIG_REG_Y(pipe_y
) |
237 A6XX_VSC_PIPE_CONFIG_REG_W(pipe_w
) |
238 A6XX_VSC_PIPE_CONFIG_REG_H(pipe_h
);
239 tiling
->pipe_sizes
[n
] = CP_SET_BIN_DATA5_0_VSC_SIZE(pipe_w
* pipe_h
);
243 memset(tiling
->pipe_config
+ used_pipe_count
, 0,
244 sizeof(uint32_t) * (max_pipe_count
- used_pipe_count
));
248 tu_tiling_config_get_tile(const struct tu_tiling_config
*tiling
,
249 const struct tu_device
*dev
,
252 struct tu_tile
*tile
)
254 /* find the pipe and the slot for tile (tx, ty) */
255 const uint32_t px
= tx
/ tiling
->pipe0
.width
;
256 const uint32_t py
= ty
/ tiling
->pipe0
.height
;
257 const uint32_t sx
= tx
- tiling
->pipe0
.width
* px
;
258 const uint32_t sy
= ty
- tiling
->pipe0
.height
* py
;
259 /* last pipe has different width */
260 const uint32_t pipe_width
=
261 MIN2(tiling
->pipe0
.width
,
262 tiling
->tile_count
.width
- px
* tiling
->pipe0
.width
);
264 assert(tx
< tiling
->tile_count
.width
&& ty
< tiling
->tile_count
.height
);
265 assert(px
< tiling
->pipe_count
.width
&& py
< tiling
->pipe_count
.height
);
266 assert(sx
< tiling
->pipe0
.width
&& sy
< tiling
->pipe0
.height
);
268 /* convert to 1D indices */
269 tile
->pipe
= tiling
->pipe_count
.width
* py
+ px
;
270 tile
->slot
= pipe_width
* sy
+ sx
;
272 /* get the blit area for the tile */
273 tile
->begin
= (VkOffset2D
) {
274 .x
= tiling
->tile0
.offset
.x
+ tiling
->tile0
.extent
.width
* tx
,
275 .y
= tiling
->tile0
.offset
.y
+ tiling
->tile0
.extent
.height
* ty
,
278 (tx
== tiling
->tile_count
.width
- 1)
279 ? tiling
->render_area
.offset
.x
+ tiling
->render_area
.extent
.width
280 : tile
->begin
.x
+ tiling
->tile0
.extent
.width
;
282 (ty
== tiling
->tile_count
.height
- 1)
283 ? tiling
->render_area
.offset
.y
+ tiling
->render_area
.extent
.height
284 : tile
->begin
.y
+ tiling
->tile0
.extent
.height
;
287 enum a3xx_msaa_samples
288 tu_msaa_samples(uint32_t samples
)
300 assert(!"invalid sample count");
305 static enum a4xx_index_size
306 tu6_index_size(VkIndexType type
)
309 case VK_INDEX_TYPE_UINT16
:
310 return INDEX4_SIZE_16_BIT
;
311 case VK_INDEX_TYPE_UINT32
:
312 return INDEX4_SIZE_32_BIT
;
314 unreachable("invalid VkIndexType");
315 return INDEX4_SIZE_8_BIT
;
320 tu6_emit_event_write(struct tu_cmd_buffer
*cmd
,
322 enum vgt_event_type event
,
327 tu_cs_emit_pkt7(cs
, CP_EVENT_WRITE
, need_seqno
? 4 : 1);
328 tu_cs_emit(cs
, CP_EVENT_WRITE_0_EVENT(event
));
330 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
);
331 seqno
= ++cmd
->scratch_seqno
;
332 tu_cs_emit(cs
, seqno
);
339 tu6_emit_cache_flush(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
341 tu6_emit_event_write(cmd
, cs
, 0x31, false);
345 tu6_emit_lrz_flush(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
347 tu6_emit_event_write(cmd
, cs
, LRZ_FLUSH
, false);
351 tu6_emit_wfi(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
353 if (cmd
->wait_for_idle
) {
355 cmd
->wait_for_idle
= false;
360 tu6_emit_zs(struct tu_cmd_buffer
*cmd
,
361 const struct tu_subpass
*subpass
,
364 const struct tu_framebuffer
*fb
= cmd
->state
.framebuffer
;
366 const uint32_t a
= subpass
->depth_stencil_attachment
.attachment
;
367 if (a
== VK_ATTACHMENT_UNUSED
) {
369 A6XX_RB_DEPTH_BUFFER_INFO(.depth_format
= DEPTH6_NONE
),
370 A6XX_RB_DEPTH_BUFFER_PITCH(0),
371 A6XX_RB_DEPTH_BUFFER_ARRAY_PITCH(0),
372 A6XX_RB_DEPTH_BUFFER_BASE(0),
373 A6XX_RB_DEPTH_BUFFER_BASE_GMEM(0));
376 A6XX_GRAS_SU_DEPTH_BUFFER_INFO(.depth_format
= DEPTH6_NONE
));
379 A6XX_GRAS_LRZ_BUFFER_BASE(0),
380 A6XX_GRAS_LRZ_BUFFER_PITCH(0),
381 A6XX_GRAS_LRZ_FAST_CLEAR_BUFFER_BASE(0));
383 tu_cs_emit_regs(cs
, A6XX_RB_STENCIL_INFO(0));
388 const struct tu_image_view
*iview
= fb
->attachments
[a
].attachment
;
389 const struct tu_render_pass_attachment
*attachment
=
390 &cmd
->state
.pass
->attachments
[a
];
391 enum a6xx_depth_format fmt
= tu6_pipe2depth(attachment
->format
);
393 tu_cs_emit_pkt4(cs
, REG_A6XX_RB_DEPTH_BUFFER_INFO
, 6);
394 tu_cs_emit(cs
, A6XX_RB_DEPTH_BUFFER_INFO(.depth_format
= fmt
).value
);
395 tu_cs_image_ref(cs
, iview
, 0);
396 tu_cs_emit(cs
, attachment
->gmem_offset
);
399 A6XX_GRAS_SU_DEPTH_BUFFER_INFO(.depth_format
= fmt
));
401 tu_cs_emit_pkt4(cs
, REG_A6XX_RB_DEPTH_FLAG_BUFFER_BASE_LO
, 3);
402 tu_cs_image_flag_ref(cs
, iview
, 0);
405 A6XX_GRAS_LRZ_BUFFER_BASE(0),
406 A6XX_GRAS_LRZ_BUFFER_PITCH(0),
407 A6XX_GRAS_LRZ_FAST_CLEAR_BUFFER_BASE(0));
409 if (attachment
->format
== VK_FORMAT_S8_UINT
) {
410 tu_cs_emit_pkt4(cs
, REG_A6XX_RB_STENCIL_INFO
, 6);
411 tu_cs_emit(cs
, A6XX_RB_STENCIL_INFO(.separate_stencil
= true).value
);
412 tu_cs_image_ref(cs
, iview
, 0);
413 tu_cs_emit(cs
, attachment
->gmem_offset
);
416 A6XX_RB_STENCIL_INFO(0));
421 tu6_emit_mrt(struct tu_cmd_buffer
*cmd
,
422 const struct tu_subpass
*subpass
,
425 const struct tu_framebuffer
*fb
= cmd
->state
.framebuffer
;
427 for (uint32_t i
= 0; i
< subpass
->color_count
; ++i
) {
428 uint32_t a
= subpass
->color_attachments
[i
].attachment
;
429 if (a
== VK_ATTACHMENT_UNUSED
)
432 const struct tu_image_view
*iview
= fb
->attachments
[a
].attachment
;
434 tu_cs_emit_pkt4(cs
, REG_A6XX_RB_MRT_BUF_INFO(i
), 6);
435 tu_cs_emit(cs
, iview
->RB_MRT_BUF_INFO
);
436 tu_cs_image_ref(cs
, iview
, 0);
437 tu_cs_emit(cs
, cmd
->state
.pass
->attachments
[a
].gmem_offset
);
440 A6XX_SP_FS_MRT_REG(i
, .dword
= iview
->SP_FS_MRT_REG
));
442 tu_cs_emit_pkt4(cs
, REG_A6XX_RB_MRT_FLAG_BUFFER_ADDR_LO(i
), 3);
443 tu_cs_image_flag_ref(cs
, iview
, 0);
447 A6XX_RB_SRGB_CNTL(.dword
= subpass
->srgb_cntl
));
449 A6XX_SP_SRGB_CNTL(.dword
= subpass
->srgb_cntl
));
452 A6XX_RB_RENDER_COMPONENTS(.dword
= subpass
->render_components
));
454 A6XX_SP_FS_RENDER_COMPONENTS(.dword
= subpass
->render_components
));
456 tu_cs_emit_regs(cs
, A6XX_GRAS_MAX_LAYER_INDEX(fb
->layers
- 1));
460 tu6_emit_msaa(struct tu_cs
*cs
, VkSampleCountFlagBits vk_samples
)
462 const enum a3xx_msaa_samples samples
= tu_msaa_samples(vk_samples
);
463 bool msaa_disable
= samples
== MSAA_ONE
;
466 A6XX_SP_TP_RAS_MSAA_CNTL(samples
),
467 A6XX_SP_TP_DEST_MSAA_CNTL(.samples
= samples
,
468 .msaa_disable
= msaa_disable
));
471 A6XX_GRAS_RAS_MSAA_CNTL(samples
),
472 A6XX_GRAS_DEST_MSAA_CNTL(.samples
= samples
,
473 .msaa_disable
= msaa_disable
));
476 A6XX_RB_RAS_MSAA_CNTL(samples
),
477 A6XX_RB_DEST_MSAA_CNTL(.samples
= samples
,
478 .msaa_disable
= msaa_disable
));
481 A6XX_RB_MSAA_CNTL(samples
));
485 tu6_emit_bin_size(struct tu_cs
*cs
,
486 uint32_t bin_w
, uint32_t bin_h
, uint32_t flags
)
489 A6XX_GRAS_BIN_CONTROL(.binw
= bin_w
,
494 A6XX_RB_BIN_CONTROL(.binw
= bin_w
,
498 /* no flag for RB_BIN_CONTROL2... */
500 A6XX_RB_BIN_CONTROL2(.binw
= bin_w
,
505 tu6_emit_render_cntl(struct tu_cmd_buffer
*cmd
,
506 const struct tu_subpass
*subpass
,
510 const struct tu_framebuffer
*fb
= cmd
->state
.framebuffer
;
512 cntl
|= A6XX_RB_RENDER_CNTL_UNK4
;
514 cntl
|= A6XX_RB_RENDER_CNTL_BINNING
;
516 uint32_t mrts_ubwc_enable
= 0;
517 for (uint32_t i
= 0; i
< subpass
->color_count
; ++i
) {
518 uint32_t a
= subpass
->color_attachments
[i
].attachment
;
519 if (a
== VK_ATTACHMENT_UNUSED
)
522 const struct tu_image_view
*iview
= fb
->attachments
[a
].attachment
;
523 if (iview
->ubwc_enabled
)
524 mrts_ubwc_enable
|= 1 << i
;
527 cntl
|= A6XX_RB_RENDER_CNTL_FLAG_MRTS(mrts_ubwc_enable
);
529 const uint32_t a
= subpass
->depth_stencil_attachment
.attachment
;
530 if (a
!= VK_ATTACHMENT_UNUSED
) {
531 const struct tu_image_view
*iview
= fb
->attachments
[a
].attachment
;
532 if (iview
->ubwc_enabled
)
533 cntl
|= A6XX_RB_RENDER_CNTL_FLAG_DEPTH
;
536 /* In the !binning case, we need to set RB_RENDER_CNTL in the draw_cs
537 * in order to set it correctly for the different subpasses. However,
538 * that means the packets we're emitting also happen during binning. So
539 * we need to guard the write on !BINNING at CP execution time.
541 tu_cs_reserve(cs
, 3 + 4);
542 tu_cs_emit_pkt7(cs
, CP_COND_REG_EXEC
, 2);
543 tu_cs_emit(cs
, CP_COND_REG_EXEC_0_MODE(RENDER_MODE
) |
544 CP_COND_REG_EXEC_0_GMEM
| CP_COND_REG_EXEC_0_SYSMEM
);
545 tu_cs_emit(cs
, CP_COND_REG_EXEC_1_DWORDS(4));
548 tu_cs_emit_pkt7(cs
, CP_REG_WRITE
, 3);
549 tu_cs_emit(cs
, CP_REG_WRITE_0_TRACKER(TRACK_RENDER_CNTL
));
550 tu_cs_emit(cs
, REG_A6XX_RB_RENDER_CNTL
);
551 tu_cs_emit(cs
, cntl
);
555 tu6_emit_blit_scissor(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
, bool align
)
557 const VkRect2D
*render_area
= &cmd
->state
.tiling_config
.render_area
;
558 uint32_t x1
= render_area
->offset
.x
;
559 uint32_t y1
= render_area
->offset
.y
;
560 uint32_t x2
= x1
+ render_area
->extent
.width
- 1;
561 uint32_t y2
= y1
+ render_area
->extent
.height
- 1;
564 x1
= x1
& ~(GMEM_ALIGN_W
- 1);
565 y1
= y1
& ~(GMEM_ALIGN_H
- 1);
566 x2
= ALIGN_POT(x2
+ 1, GMEM_ALIGN_W
) - 1;
567 y2
= ALIGN_POT(y2
+ 1, GMEM_ALIGN_H
) - 1;
571 A6XX_RB_BLIT_SCISSOR_TL(.x
= x1
, .y
= y1
),
572 A6XX_RB_BLIT_SCISSOR_BR(.x
= x2
, .y
= y2
));
576 tu6_emit_window_scissor(struct tu_cs
*cs
,
583 A6XX_GRAS_SC_WINDOW_SCISSOR_TL(.x
= x1
, .y
= y1
),
584 A6XX_GRAS_SC_WINDOW_SCISSOR_BR(.x
= x2
, .y
= y2
));
587 A6XX_GRAS_RESOLVE_CNTL_1(.x
= x1
, .y
= y1
),
588 A6XX_GRAS_RESOLVE_CNTL_2(.x
= x2
, .y
= y2
));
592 tu6_emit_window_offset(struct tu_cs
*cs
, uint32_t x1
, uint32_t y1
)
595 A6XX_RB_WINDOW_OFFSET(.x
= x1
, .y
= y1
));
598 A6XX_RB_WINDOW_OFFSET2(.x
= x1
, .y
= y1
));
601 A6XX_SP_WINDOW_OFFSET(.x
= x1
, .y
= y1
));
604 A6XX_SP_TP_WINDOW_OFFSET(.x
= x1
, .y
= y1
));
608 use_hw_binning(struct tu_cmd_buffer
*cmd
)
610 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
612 if (unlikely(cmd
->device
->physical_device
->instance
->debug_flags
& TU_DEBUG_NOBIN
))
615 if (unlikely(cmd
->device
->physical_device
->instance
->debug_flags
& TU_DEBUG_FORCEBIN
))
618 return (tiling
->tile_count
.width
* tiling
->tile_count
.height
) > 2;
622 use_sysmem_rendering(struct tu_cmd_buffer
*cmd
)
624 if (unlikely(cmd
->device
->physical_device
->instance
->debug_flags
& TU_DEBUG_SYSMEM
))
627 /* can't fit attachments into gmem */
628 if (!cmd
->state
.pass
->gmem_pixels
)
631 if (cmd
->state
.framebuffer
->layers
> 1)
634 return cmd
->state
.tiling_config
.force_sysmem
;
638 tu6_emit_tile_select(struct tu_cmd_buffer
*cmd
,
640 const struct tu_tile
*tile
)
642 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
643 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_YIELD
));
645 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
646 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_GMEM
));
648 const uint32_t x1
= tile
->begin
.x
;
649 const uint32_t y1
= tile
->begin
.y
;
650 const uint32_t x2
= tile
->end
.x
- 1;
651 const uint32_t y2
= tile
->end
.y
- 1;
652 tu6_emit_window_scissor(cs
, x1
, y1
, x2
, y2
);
653 tu6_emit_window_offset(cs
, x1
, y1
);
656 A6XX_VPC_SO_OVERRIDE(.so_disable
= false));
658 if (use_hw_binning(cmd
)) {
659 tu_cs_emit_pkt7(cs
, CP_WAIT_FOR_ME
, 0);
661 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
664 tu_cs_emit_pkt7(cs
, CP_REG_TEST
, 1);
665 tu_cs_emit(cs
, A6XX_CP_REG_TEST_0_REG(OVERFLOW_FLAG_REG
) |
666 A6XX_CP_REG_TEST_0_BIT(0) |
667 A6XX_CP_REG_TEST_0_WAIT_FOR_ME
);
669 tu_cs_reserve(cs
, 3 + 11);
670 tu_cs_emit_pkt7(cs
, CP_COND_REG_EXEC
, 2);
671 tu_cs_emit(cs
, CP_COND_REG_EXEC_0_MODE(PRED_TEST
));
672 tu_cs_emit(cs
, CP_COND_REG_EXEC_1_DWORDS(11));
674 /* if (no overflow) */ {
675 tu_cs_emit_pkt7(cs
, CP_SET_BIN_DATA5
, 7);
676 tu_cs_emit(cs
, cmd
->state
.tiling_config
.pipe_sizes
[tile
->pipe
] |
677 CP_SET_BIN_DATA5_0_VSC_N(tile
->slot
));
678 tu_cs_emit_qw(cs
, cmd
->vsc_data
.iova
+ tile
->pipe
* cmd
->vsc_data_pitch
);
679 tu_cs_emit_qw(cs
, cmd
->vsc_data
.iova
+ (tile
->pipe
* 4) + (32 * cmd
->vsc_data_pitch
));
680 tu_cs_emit_qw(cs
, cmd
->vsc_data2
.iova
+ (tile
->pipe
* cmd
->vsc_data2_pitch
));
682 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
685 /* use a NOP packet to skip over the 'else' side: */
686 tu_cs_emit_pkt7(cs
, CP_NOP
, 2);
688 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
692 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
695 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
698 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
704 tu6_emit_sysmem_resolve(struct tu_cmd_buffer
*cmd
,
709 const struct tu_framebuffer
*fb
= cmd
->state
.framebuffer
;
710 struct tu_image_view
*dst
= fb
->attachments
[a
].attachment
;
711 struct tu_image_view
*src
= fb
->attachments
[gmem_a
].attachment
;
713 tu_resolve_sysmem(cmd
, cs
, src
, dst
, fb
->layers
, &cmd
->state
.tiling_config
.render_area
);
717 tu6_emit_tile_store(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
719 const struct tu_render_pass
*pass
= cmd
->state
.pass
;
720 const struct tu_subpass
*subpass
= &pass
->subpasses
[pass
->subpass_count
-1];
722 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 3);
723 tu_cs_emit(cs
, CP_SET_DRAW_STATE__0_COUNT(0) |
724 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
725 CP_SET_DRAW_STATE__0_GROUP_ID(0));
726 tu_cs_emit(cs
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
727 tu_cs_emit(cs
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
729 tu_cs_emit_pkt7(cs
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
732 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
733 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_RESOLVE
));
735 tu6_emit_blit_scissor(cmd
, cs
, true);
737 for (uint32_t a
= 0; a
< pass
->attachment_count
; ++a
) {
738 if (pass
->attachments
[a
].gmem_offset
>= 0)
739 tu_store_gmem_attachment(cmd
, cs
, a
, a
);
742 if (subpass
->resolve_attachments
) {
743 for (unsigned i
= 0; i
< subpass
->color_count
; i
++) {
744 uint32_t a
= subpass
->resolve_attachments
[i
].attachment
;
745 if (a
!= VK_ATTACHMENT_UNUSED
)
746 tu_store_gmem_attachment(cmd
, cs
, a
,
747 subpass
->color_attachments
[i
].attachment
);
753 tu6_emit_restart_index(struct tu_cs
*cs
, uint32_t restart_index
)
756 A6XX_PC_RESTART_INDEX(restart_index
));
760 tu6_init_hw(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
762 const struct tu_physical_device
*phys_dev
= cmd
->device
->physical_device
;
764 tu6_emit_cache_flush(cmd
, cs
);
766 tu_cs_emit_write_reg(cs
, REG_A6XX_HLSQ_UPDATE_CNTL
, 0xfffff);
769 A6XX_RB_CCU_CNTL(.offset
= phys_dev
->ccu_offset_bypass
));
770 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8E04
, 0x00100000);
771 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_AE04
, 0x8);
772 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_AE00
, 0);
773 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_AE0F
, 0x3f);
774 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_B605
, 0x44);
775 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_B600
, 0x100000);
776 tu_cs_emit_write_reg(cs
, REG_A6XX_HLSQ_UNKNOWN_BE00
, 0x80);
777 tu_cs_emit_write_reg(cs
, REG_A6XX_HLSQ_UNKNOWN_BE01
, 0);
779 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9600
, 0);
780 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_8600
, 0x880);
781 tu_cs_emit_write_reg(cs
, REG_A6XX_HLSQ_UNKNOWN_BE04
, 0);
782 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_AE03
, 0x00000410);
783 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_IBO_COUNT
, 0);
784 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_B182
, 0);
785 tu_cs_emit_write_reg(cs
, REG_A6XX_HLSQ_UNKNOWN_BB11
, 0);
786 tu_cs_emit_write_reg(cs
, REG_A6XX_UCHE_UNKNOWN_0E12
, 0x3200000);
787 tu_cs_emit_write_reg(cs
, REG_A6XX_UCHE_CLIENT_PF
, 4);
788 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8E01
, 0x0);
789 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_A982
, 0);
790 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_A9A8
, 0);
791 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_AB00
, 0x5);
792 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_GS_SIV_CNTL
, 0x0000ffff);
794 tu_cs_emit_write_reg(cs
, REG_A6XX_VFD_ADD_OFFSET
, A6XX_VFD_ADD_OFFSET_VERTEX
);
795 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8811
, 0x00000010);
796 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_MODE_CNTL
, 0x1f);
798 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_SRGB_CNTL
, 0);
800 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_8110
, 0);
802 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_RENDER_CONTROL0
, 0x401);
803 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_RENDER_CONTROL1
, 0);
804 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_FS_OUTPUT_CNTL0
, 0);
805 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8818
, 0);
806 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8819
, 0);
807 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881A
, 0);
808 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881B
, 0);
809 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881C
, 0);
810 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881D
, 0);
811 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881E
, 0);
812 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_88F0
, 0);
814 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9101
, 0xffff00);
815 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9107
, 0);
817 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9236
,
818 A6XX_VPC_UNKNOWN_9236_POINT_COORD_INVERT(0));
819 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9300
, 0);
821 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_SO_OVERRIDE
,
822 A6XX_VPC_SO_OVERRIDE_SO_DISABLE
);
824 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9801
, 0);
825 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9980
, 0);
826 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9990
, 0);
828 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_PRIMITIVE_CNTL_6
, 0);
829 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9B07
, 0);
831 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_A81B
, 0);
833 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_B183
, 0);
835 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_8099
, 0);
836 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_809B
, 0);
837 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_80A0
, 2);
838 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_80AF
, 0);
839 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9210
, 0);
840 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9211
, 0);
841 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9602
, 0);
842 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9981
, 0x3);
843 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9E72
, 0);
844 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9108
, 0x3);
845 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_TP_UNKNOWN_B309
, 0x000000a2);
846 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8878
, 0);
847 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8879
, 0);
848 tu_cs_emit_write_reg(cs
, REG_A6XX_HLSQ_CONTROL_5_REG
, 0xfc);
850 tu_cs_emit_write_reg(cs
, REG_A6XX_VFD_MODE_CNTL
, 0x00000000);
852 tu_cs_emit_write_reg(cs
, REG_A6XX_VFD_UNKNOWN_A008
, 0);
854 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_MODE_CNTL
, 0x0000001f);
856 /* we don't use this yet.. probably best to disable.. */
857 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 3);
858 tu_cs_emit(cs
, CP_SET_DRAW_STATE__0_COUNT(0) |
859 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
860 CP_SET_DRAW_STATE__0_GROUP_ID(0));
861 tu_cs_emit(cs
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
862 tu_cs_emit(cs
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
864 /* Set not to use streamout by default, */
865 tu_cs_emit_pkt7(cs
, CP_CONTEXT_REG_BUNCH
, 4);
866 tu_cs_emit(cs
, REG_A6XX_VPC_SO_CNTL
);
868 tu_cs_emit(cs
, REG_A6XX_VPC_SO_BUF_CNTL
);
872 A6XX_SP_HS_CTRL_REG0(0));
875 A6XX_SP_GS_CTRL_REG0(0));
878 A6XX_GRAS_LRZ_CNTL(0));
881 A6XX_RB_LRZ_CNTL(0));
884 A6XX_SP_TP_BORDER_COLOR_BASE_ADDR(.bo
= &cmd
->device
->border_color
));
886 A6XX_SP_PS_TP_BORDER_COLOR_BASE_ADDR(.bo
= &cmd
->device
->border_color
));
888 tu_cs_sanity_check(cs
);
892 tu6_cache_flush(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
896 seqno
= tu6_emit_event_write(cmd
, cs
, RB_DONE_TS
, true);
898 tu_cs_emit_pkt7(cs
, CP_WAIT_REG_MEM
, 6);
899 tu_cs_emit(cs
, CP_WAIT_REG_MEM_0_FUNCTION(WRITE_EQ
) |
900 CP_WAIT_REG_MEM_0_POLL_MEMORY
);
901 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
);
902 tu_cs_emit(cs
, CP_WAIT_REG_MEM_3_REF(seqno
));
903 tu_cs_emit(cs
, CP_WAIT_REG_MEM_4_MASK(~0));
904 tu_cs_emit(cs
, CP_WAIT_REG_MEM_5_DELAY_LOOP_CYCLES(16));
906 seqno
= tu6_emit_event_write(cmd
, cs
, CACHE_FLUSH_TS
, true);
908 tu_cs_emit_pkt7(cs
, CP_WAIT_MEM_GTE
, 4);
909 tu_cs_emit(cs
, CP_WAIT_MEM_GTE_0_RESERVED(0));
910 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
);
911 tu_cs_emit(cs
, CP_WAIT_MEM_GTE_3_REF(seqno
));
915 update_vsc_pipe(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
917 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
920 A6XX_VSC_BIN_SIZE(.width
= tiling
->tile0
.extent
.width
,
921 .height
= tiling
->tile0
.extent
.height
),
922 A6XX_VSC_SIZE_ADDRESS(.bo
= &cmd
->vsc_data
,
923 .bo_offset
= 32 * cmd
->vsc_data_pitch
));
926 A6XX_VSC_BIN_COUNT(.nx
= tiling
->tile_count
.width
,
927 .ny
= tiling
->tile_count
.height
));
929 tu_cs_emit_pkt4(cs
, REG_A6XX_VSC_PIPE_CONFIG_REG(0), 32);
930 for (unsigned i
= 0; i
< 32; i
++)
931 tu_cs_emit(cs
, tiling
->pipe_config
[i
]);
934 A6XX_VSC_PIPE_DATA2_ADDRESS(.bo
= &cmd
->vsc_data2
),
935 A6XX_VSC_PIPE_DATA2_PITCH(cmd
->vsc_data2_pitch
),
936 A6XX_VSC_PIPE_DATA2_ARRAY_PITCH(cmd
->vsc_data2
.size
));
939 A6XX_VSC_PIPE_DATA_ADDRESS(.bo
= &cmd
->vsc_data
),
940 A6XX_VSC_PIPE_DATA_PITCH(cmd
->vsc_data_pitch
),
941 A6XX_VSC_PIPE_DATA_ARRAY_PITCH(cmd
->vsc_data
.size
));
945 emit_vsc_overflow_test(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
947 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
948 const uint32_t used_pipe_count
=
949 tiling
->pipe_count
.width
* tiling
->pipe_count
.height
;
951 /* Clear vsc_scratch: */
952 tu_cs_emit_pkt7(cs
, CP_MEM_WRITE
, 3);
953 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(vsc_scratch
));
956 /* Check for overflow, write vsc_scratch if detected: */
957 for (int i
= 0; i
< used_pipe_count
; i
++) {
958 tu_cs_emit_pkt7(cs
, CP_COND_WRITE5
, 8);
959 tu_cs_emit(cs
, CP_COND_WRITE5_0_FUNCTION(WRITE_GE
) |
960 CP_COND_WRITE5_0_WRITE_MEMORY
);
961 tu_cs_emit(cs
, CP_COND_WRITE5_1_POLL_ADDR_LO(REG_A6XX_VSC_SIZE_REG(i
)));
962 tu_cs_emit(cs
, CP_COND_WRITE5_2_POLL_ADDR_HI(0));
963 tu_cs_emit(cs
, CP_COND_WRITE5_3_REF(cmd
->vsc_data_pitch
));
964 tu_cs_emit(cs
, CP_COND_WRITE5_4_MASK(~0));
965 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(vsc_scratch
));
966 tu_cs_emit(cs
, CP_COND_WRITE5_7_WRITE_DATA(1 + cmd
->vsc_data_pitch
));
968 tu_cs_emit_pkt7(cs
, CP_COND_WRITE5
, 8);
969 tu_cs_emit(cs
, CP_COND_WRITE5_0_FUNCTION(WRITE_GE
) |
970 CP_COND_WRITE5_0_WRITE_MEMORY
);
971 tu_cs_emit(cs
, CP_COND_WRITE5_1_POLL_ADDR_LO(REG_A6XX_VSC_SIZE2_REG(i
)));
972 tu_cs_emit(cs
, CP_COND_WRITE5_2_POLL_ADDR_HI(0));
973 tu_cs_emit(cs
, CP_COND_WRITE5_3_REF(cmd
->vsc_data2_pitch
));
974 tu_cs_emit(cs
, CP_COND_WRITE5_4_MASK(~0));
975 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(vsc_scratch
));
976 tu_cs_emit(cs
, CP_COND_WRITE5_7_WRITE_DATA(3 + cmd
->vsc_data2_pitch
));
979 tu_cs_emit_pkt7(cs
, CP_WAIT_MEM_WRITES
, 0);
981 tu_cs_emit_pkt7(cs
, CP_WAIT_FOR_ME
, 0);
983 tu_cs_emit_pkt7(cs
, CP_MEM_TO_REG
, 3);
984 tu_cs_emit(cs
, CP_MEM_TO_REG_0_REG(OVERFLOW_FLAG_REG
) |
985 CP_MEM_TO_REG_0_CNT(1 - 1));
986 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(vsc_scratch
));
989 * This is a bit awkward, we really want a way to invert the
990 * CP_REG_TEST/CP_COND_REG_EXEC logic, so that we can conditionally
991 * execute cmds to use hwbinning when a bit is *not* set. This
992 * dance is to invert OVERFLOW_FLAG_REG
994 * A CP_NOP packet is used to skip executing the 'else' clause
998 /* b0 will be set if VSC_DATA or VSC_DATA2 overflow: */
999 tu_cs_emit_pkt7(cs
, CP_REG_TEST
, 1);
1000 tu_cs_emit(cs
, A6XX_CP_REG_TEST_0_REG(OVERFLOW_FLAG_REG
) |
1001 A6XX_CP_REG_TEST_0_BIT(0) |
1002 A6XX_CP_REG_TEST_0_WAIT_FOR_ME
);
1004 tu_cs_reserve(cs
, 3 + 7);
1005 tu_cs_emit_pkt7(cs
, CP_COND_REG_EXEC
, 2);
1006 tu_cs_emit(cs
, CP_COND_REG_EXEC_0_MODE(PRED_TEST
));
1007 tu_cs_emit(cs
, CP_COND_REG_EXEC_1_DWORDS(7));
1011 * On overflow, mirror the value to control->vsc_overflow
1012 * which CPU is checking to detect overflow (see
1013 * check_vsc_overflow())
1015 tu_cs_emit_pkt7(cs
, CP_REG_TO_MEM
, 3);
1016 tu_cs_emit(cs
, CP_REG_TO_MEM_0_REG(OVERFLOW_FLAG_REG
) |
1017 CP_REG_TO_MEM_0_CNT(0));
1018 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(vsc_overflow
));
1020 tu_cs_emit_pkt4(cs
, OVERFLOW_FLAG_REG
, 1);
1021 tu_cs_emit(cs
, 0x0);
1023 tu_cs_emit_pkt7(cs
, CP_NOP
, 2); /* skip 'else' when 'if' is taken */
1025 tu_cs_emit_pkt4(cs
, OVERFLOW_FLAG_REG
, 1);
1026 tu_cs_emit(cs
, 0x1);
1031 tu6_emit_binning_pass(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1033 struct tu_physical_device
*phys_dev
= cmd
->device
->physical_device
;
1034 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1036 uint32_t x1
= tiling
->tile0
.offset
.x
;
1037 uint32_t y1
= tiling
->tile0
.offset
.y
;
1038 uint32_t x2
= tiling
->render_area
.offset
.x
+ tiling
->render_area
.extent
.width
- 1;
1039 uint32_t y2
= tiling
->render_area
.offset
.y
+ tiling
->render_area
.extent
.height
- 1;
1041 tu6_emit_window_scissor(cs
, x1
, y1
, x2
, y2
);
1043 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
1044 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_BINNING
));
1046 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
1047 tu_cs_emit(cs
, 0x1);
1049 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
1050 tu_cs_emit(cs
, 0x1);
1055 A6XX_VFD_MODE_CNTL(.binning_pass
= true));
1057 update_vsc_pipe(cmd
, cs
);
1060 A6XX_PC_UNKNOWN_9805(.unknown
= phys_dev
->magic
.PC_UNKNOWN_9805
));
1063 A6XX_SP_UNKNOWN_A0F8(.unknown
= phys_dev
->magic
.SP_UNKNOWN_A0F8
));
1065 tu_cs_emit_pkt7(cs
, CP_EVENT_WRITE
, 1);
1066 tu_cs_emit(cs
, UNK_2C
);
1069 A6XX_RB_WINDOW_OFFSET(.x
= 0, .y
= 0));
1072 A6XX_SP_TP_WINDOW_OFFSET(.x
= 0, .y
= 0));
1074 /* emit IB to binning drawcmds: */
1075 tu_cs_emit_call(cs
, &cmd
->draw_cs
);
1077 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 3);
1078 tu_cs_emit(cs
, CP_SET_DRAW_STATE__0_COUNT(0) |
1079 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
1080 CP_SET_DRAW_STATE__0_GROUP_ID(0));
1081 tu_cs_emit(cs
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
1082 tu_cs_emit(cs
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
1084 tu_cs_emit_pkt7(cs
, CP_EVENT_WRITE
, 1);
1085 tu_cs_emit(cs
, UNK_2D
);
1087 tu6_emit_event_write(cmd
, cs
, CACHE_INVALIDATE
, false);
1088 tu6_cache_flush(cmd
, cs
);
1092 tu_cs_emit_pkt7(cs
, CP_WAIT_FOR_ME
, 0);
1094 emit_vsc_overflow_test(cmd
, cs
);
1096 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
1097 tu_cs_emit(cs
, 0x0);
1099 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
1100 tu_cs_emit(cs
, 0x0);
1102 cmd
->wait_for_idle
= false;
1106 tu_emit_load_clear(struct tu_cmd_buffer
*cmd
,
1107 const VkRenderPassBeginInfo
*info
)
1109 struct tu_cs
*cs
= &cmd
->draw_cs
;
1111 tu_cond_exec_start(cs
, CP_COND_EXEC_0_RENDER_MODE_GMEM
);
1113 tu6_emit_blit_scissor(cmd
, cs
, true);
1115 for (uint32_t i
= 0; i
< cmd
->state
.pass
->attachment_count
; ++i
)
1116 tu_load_gmem_attachment(cmd
, cs
, i
, false);
1118 tu6_emit_blit_scissor(cmd
, cs
, false);
1120 for (uint32_t i
= 0; i
< cmd
->state
.pass
->attachment_count
; ++i
)
1121 tu_clear_gmem_attachment(cmd
, cs
, i
, info
);
1123 tu_cond_exec_end(cs
);
1125 tu_cond_exec_start(cs
, CP_COND_EXEC_0_RENDER_MODE_SYSMEM
);
1127 for (uint32_t i
= 0; i
< cmd
->state
.pass
->attachment_count
; ++i
)
1128 tu_clear_sysmem_attachment(cmd
, cs
, i
, info
);
1130 tu_cond_exec_end(cs
);
1134 tu6_sysmem_render_begin(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
,
1135 const struct VkRect2D
*renderArea
)
1137 const struct tu_physical_device
*phys_dev
= cmd
->device
->physical_device
;
1138 const struct tu_framebuffer
*fb
= cmd
->state
.framebuffer
;
1140 assert(fb
->width
> 0 && fb
->height
> 0);
1141 tu6_emit_window_scissor(cs
, 0, 0, fb
->width
- 1, fb
->height
- 1);
1142 tu6_emit_window_offset(cs
, 0, 0);
1144 tu6_emit_bin_size(cs
, 0, 0, 0xc00000); /* 0xc00000 = BYPASS? */
1146 tu6_emit_lrz_flush(cmd
, cs
);
1148 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
1149 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_BYPASS
));
1151 tu_cs_emit_pkt7(cs
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1152 tu_cs_emit(cs
, 0x0);
1154 tu6_emit_event_write(cmd
, cs
, PC_CCU_INVALIDATE_COLOR
, false);
1155 tu6_emit_event_write(cmd
, cs
, PC_CCU_INVALIDATE_DEPTH
, false);
1156 tu6_emit_event_write(cmd
, cs
, CACHE_INVALIDATE
, false);
1158 tu6_emit_wfi(cmd
, cs
);
1160 A6XX_RB_CCU_CNTL(.offset
= phys_dev
->ccu_offset_bypass
));
1162 /* enable stream-out, with sysmem there is only one pass: */
1164 A6XX_VPC_SO_OVERRIDE(.so_disable
= false));
1166 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
1167 tu_cs_emit(cs
, 0x1);
1169 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
1170 tu_cs_emit(cs
, 0x0);
1172 tu_cs_sanity_check(cs
);
1176 tu6_sysmem_render_end(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1178 /* Do any resolves of the last subpass. These are handled in the
1179 * tile_store_ib in the gmem path.
1181 const struct tu_subpass
*subpass
= cmd
->state
.subpass
;
1182 if (subpass
->resolve_attachments
) {
1183 for (unsigned i
= 0; i
< subpass
->color_count
; i
++) {
1184 uint32_t a
= subpass
->resolve_attachments
[i
].attachment
;
1185 if (a
!= VK_ATTACHMENT_UNUSED
)
1186 tu6_emit_sysmem_resolve(cmd
, cs
, a
,
1187 subpass
->color_attachments
[i
].attachment
);
1191 tu_cs_emit_call(cs
, &cmd
->draw_epilogue_cs
);
1193 tu_cs_emit_pkt7(cs
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1194 tu_cs_emit(cs
, 0x0);
1196 tu6_emit_lrz_flush(cmd
, cs
);
1198 tu6_emit_event_write(cmd
, cs
, PC_CCU_FLUSH_COLOR_TS
, true);
1199 tu6_emit_event_write(cmd
, cs
, PC_CCU_FLUSH_DEPTH_TS
, true);
1201 tu_cs_sanity_check(cs
);
1206 tu6_tile_render_begin(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1208 struct tu_physical_device
*phys_dev
= cmd
->device
->physical_device
;
1210 tu6_emit_lrz_flush(cmd
, cs
);
1214 tu6_emit_cache_flush(cmd
, cs
);
1216 tu_cs_emit_pkt7(cs
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1217 tu_cs_emit(cs
, 0x0);
1219 /* TODO: flushing with barriers instead of blindly always flushing */
1220 tu6_emit_event_write(cmd
, cs
, PC_CCU_FLUSH_COLOR_TS
, true);
1221 tu6_emit_event_write(cmd
, cs
, PC_CCU_FLUSH_DEPTH_TS
, true);
1222 tu6_emit_event_write(cmd
, cs
, PC_CCU_INVALIDATE_COLOR
, false);
1223 tu6_emit_event_write(cmd
, cs
, PC_CCU_INVALIDATE_DEPTH
, false);
1227 A6XX_RB_CCU_CNTL(.offset
= phys_dev
->ccu_offset_gmem
, .gmem
= 1));
1229 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1230 if (use_hw_binning(cmd
)) {
1231 /* enable stream-out during binning pass: */
1232 tu_cs_emit_regs(cs
, A6XX_VPC_SO_OVERRIDE(.so_disable
=false));
1234 tu6_emit_bin_size(cs
,
1235 tiling
->tile0
.extent
.width
,
1236 tiling
->tile0
.extent
.height
,
1237 A6XX_RB_BIN_CONTROL_BINNING_PASS
| 0x6000000);
1239 tu6_emit_render_cntl(cmd
, cmd
->state
.subpass
, cs
, true);
1241 tu6_emit_binning_pass(cmd
, cs
);
1243 /* and disable stream-out for draw pass: */
1244 tu_cs_emit_regs(cs
, A6XX_VPC_SO_OVERRIDE(.so_disable
=true));
1246 tu6_emit_bin_size(cs
,
1247 tiling
->tile0
.extent
.width
,
1248 tiling
->tile0
.extent
.height
,
1249 A6XX_RB_BIN_CONTROL_USE_VIZ
| 0x6000000);
1252 A6XX_VFD_MODE_CNTL(0));
1254 tu_cs_emit_regs(cs
, A6XX_PC_UNKNOWN_9805(.unknown
= phys_dev
->magic
.PC_UNKNOWN_9805
));
1256 tu_cs_emit_regs(cs
, A6XX_SP_UNKNOWN_A0F8(.unknown
= phys_dev
->magic
.SP_UNKNOWN_A0F8
));
1258 tu_cs_emit_pkt7(cs
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1259 tu_cs_emit(cs
, 0x1);
1261 /* no binning pass, so enable stream-out for draw pass:: */
1262 tu_cs_emit_regs(cs
, A6XX_VPC_SO_OVERRIDE(.so_disable
=false));
1264 tu6_emit_bin_size(cs
,
1265 tiling
->tile0
.extent
.width
,
1266 tiling
->tile0
.extent
.height
,
1270 tu_cs_sanity_check(cs
);
1274 tu6_render_tile(struct tu_cmd_buffer
*cmd
,
1276 const struct tu_tile
*tile
)
1278 tu6_emit_tile_select(cmd
, cs
, tile
);
1280 tu_cs_emit_call(cs
, &cmd
->draw_cs
);
1281 cmd
->wait_for_idle
= true;
1283 if (use_hw_binning(cmd
)) {
1284 tu_cs_emit_pkt7(cs
, CP_REG_TEST
, 1);
1285 tu_cs_emit(cs
, A6XX_CP_REG_TEST_0_REG(OVERFLOW_FLAG_REG
) |
1286 A6XX_CP_REG_TEST_0_BIT(0) |
1287 A6XX_CP_REG_TEST_0_WAIT_FOR_ME
);
1289 tu_cs_reserve(cs
, 3 + 2);
1290 tu_cs_emit_pkt7(cs
, CP_COND_REG_EXEC
, 2);
1291 tu_cs_emit(cs
, CP_COND_REG_EXEC_0_MODE(PRED_TEST
));
1292 tu_cs_emit(cs
, CP_COND_REG_EXEC_1_DWORDS(2));
1294 /* if (no overflow) */ {
1295 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
1296 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_ENDVIS
));
1300 tu_cs_emit_ib(cs
, &cmd
->state
.tile_store_ib
);
1302 tu_cs_sanity_check(cs
);
1306 tu6_tile_render_end(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1308 tu_cs_emit_call(cs
, &cmd
->draw_epilogue_cs
);
1311 A6XX_GRAS_LRZ_CNTL(0));
1313 tu6_emit_lrz_flush(cmd
, cs
);
1315 tu6_emit_event_write(cmd
, cs
, PC_CCU_RESOLVE_TS
, true);
1317 tu_cs_sanity_check(cs
);
1321 tu_cmd_render_tiles(struct tu_cmd_buffer
*cmd
)
1323 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1325 tu6_tile_render_begin(cmd
, &cmd
->cs
);
1327 for (uint32_t y
= 0; y
< tiling
->tile_count
.height
; y
++) {
1328 for (uint32_t x
= 0; x
< tiling
->tile_count
.width
; x
++) {
1329 struct tu_tile tile
;
1330 tu_tiling_config_get_tile(tiling
, cmd
->device
, x
, y
, &tile
);
1331 tu6_render_tile(cmd
, &cmd
->cs
, &tile
);
1335 tu6_tile_render_end(cmd
, &cmd
->cs
);
1339 tu_cmd_render_sysmem(struct tu_cmd_buffer
*cmd
)
1341 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1343 tu6_sysmem_render_begin(cmd
, &cmd
->cs
, &tiling
->render_area
);
1345 tu_cs_emit_call(&cmd
->cs
, &cmd
->draw_cs
);
1346 cmd
->wait_for_idle
= true;
1348 tu6_sysmem_render_end(cmd
, &cmd
->cs
);
1352 tu_cmd_prepare_tile_store_ib(struct tu_cmd_buffer
*cmd
)
1354 const uint32_t tile_store_space
= 11 + (35 * 2) * cmd
->state
.pass
->attachment_count
;
1355 struct tu_cs sub_cs
;
1358 tu_cs_begin_sub_stream(&cmd
->sub_cs
, tile_store_space
, &sub_cs
);
1359 if (result
!= VK_SUCCESS
) {
1360 cmd
->record_result
= result
;
1364 /* emit to tile-store sub_cs */
1365 tu6_emit_tile_store(cmd
, &sub_cs
);
1367 cmd
->state
.tile_store_ib
= tu_cs_end_sub_stream(&cmd
->sub_cs
, &sub_cs
);
1371 tu_cmd_update_tiling_config(struct tu_cmd_buffer
*cmd
,
1372 const VkRect2D
*render_area
)
1374 const struct tu_device
*dev
= cmd
->device
;
1375 struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1377 tiling
->render_area
= *render_area
;
1378 tiling
->force_sysmem
= false;
1380 tu_tiling_config_update_tile_layout(tiling
, dev
, cmd
->state
.pass
);
1381 tu_tiling_config_update_pipe_layout(tiling
, dev
);
1382 tu_tiling_config_update_pipes(tiling
, dev
);
1385 const struct tu_dynamic_state default_dynamic_state
= {
1401 .blend_constants
= { 0.0f
, 0.0f
, 0.0f
, 0.0f
},
1407 .stencil_compare_mask
=
1412 .stencil_write_mask
=
1417 .stencil_reference
=
1424 static void UNUSED
/* FINISHME */
1425 tu_bind_dynamic_state(struct tu_cmd_buffer
*cmd_buffer
,
1426 const struct tu_dynamic_state
*src
)
1428 struct tu_dynamic_state
*dest
= &cmd_buffer
->state
.dynamic
;
1429 uint32_t copy_mask
= src
->mask
;
1430 uint32_t dest_mask
= 0;
1432 tu_use_args(cmd_buffer
); /* FINISHME */
1434 /* Make sure to copy the number of viewports/scissors because they can
1435 * only be specified at pipeline creation time.
1437 dest
->viewport
.count
= src
->viewport
.count
;
1438 dest
->scissor
.count
= src
->scissor
.count
;
1439 dest
->discard_rectangle
.count
= src
->discard_rectangle
.count
;
1441 if (copy_mask
& TU_DYNAMIC_VIEWPORT
) {
1442 if (memcmp(&dest
->viewport
.viewports
, &src
->viewport
.viewports
,
1443 src
->viewport
.count
* sizeof(VkViewport
))) {
1444 typed_memcpy(dest
->viewport
.viewports
, src
->viewport
.viewports
,
1445 src
->viewport
.count
);
1446 dest_mask
|= TU_DYNAMIC_VIEWPORT
;
1450 if (copy_mask
& TU_DYNAMIC_SCISSOR
) {
1451 if (memcmp(&dest
->scissor
.scissors
, &src
->scissor
.scissors
,
1452 src
->scissor
.count
* sizeof(VkRect2D
))) {
1453 typed_memcpy(dest
->scissor
.scissors
, src
->scissor
.scissors
,
1454 src
->scissor
.count
);
1455 dest_mask
|= TU_DYNAMIC_SCISSOR
;
1459 if (copy_mask
& TU_DYNAMIC_LINE_WIDTH
) {
1460 if (dest
->line_width
!= src
->line_width
) {
1461 dest
->line_width
= src
->line_width
;
1462 dest_mask
|= TU_DYNAMIC_LINE_WIDTH
;
1466 if (copy_mask
& TU_DYNAMIC_DEPTH_BIAS
) {
1467 if (memcmp(&dest
->depth_bias
, &src
->depth_bias
,
1468 sizeof(src
->depth_bias
))) {
1469 dest
->depth_bias
= src
->depth_bias
;
1470 dest_mask
|= TU_DYNAMIC_DEPTH_BIAS
;
1474 if (copy_mask
& TU_DYNAMIC_BLEND_CONSTANTS
) {
1475 if (memcmp(&dest
->blend_constants
, &src
->blend_constants
,
1476 sizeof(src
->blend_constants
))) {
1477 typed_memcpy(dest
->blend_constants
, src
->blend_constants
, 4);
1478 dest_mask
|= TU_DYNAMIC_BLEND_CONSTANTS
;
1482 if (copy_mask
& TU_DYNAMIC_DEPTH_BOUNDS
) {
1483 if (memcmp(&dest
->depth_bounds
, &src
->depth_bounds
,
1484 sizeof(src
->depth_bounds
))) {
1485 dest
->depth_bounds
= src
->depth_bounds
;
1486 dest_mask
|= TU_DYNAMIC_DEPTH_BOUNDS
;
1490 if (copy_mask
& TU_DYNAMIC_STENCIL_COMPARE_MASK
) {
1491 if (memcmp(&dest
->stencil_compare_mask
, &src
->stencil_compare_mask
,
1492 sizeof(src
->stencil_compare_mask
))) {
1493 dest
->stencil_compare_mask
= src
->stencil_compare_mask
;
1494 dest_mask
|= TU_DYNAMIC_STENCIL_COMPARE_MASK
;
1498 if (copy_mask
& TU_DYNAMIC_STENCIL_WRITE_MASK
) {
1499 if (memcmp(&dest
->stencil_write_mask
, &src
->stencil_write_mask
,
1500 sizeof(src
->stencil_write_mask
))) {
1501 dest
->stencil_write_mask
= src
->stencil_write_mask
;
1502 dest_mask
|= TU_DYNAMIC_STENCIL_WRITE_MASK
;
1506 if (copy_mask
& TU_DYNAMIC_STENCIL_REFERENCE
) {
1507 if (memcmp(&dest
->stencil_reference
, &src
->stencil_reference
,
1508 sizeof(src
->stencil_reference
))) {
1509 dest
->stencil_reference
= src
->stencil_reference
;
1510 dest_mask
|= TU_DYNAMIC_STENCIL_REFERENCE
;
1514 if (copy_mask
& TU_DYNAMIC_DISCARD_RECTANGLE
) {
1515 if (memcmp(&dest
->discard_rectangle
.rectangles
,
1516 &src
->discard_rectangle
.rectangles
,
1517 src
->discard_rectangle
.count
* sizeof(VkRect2D
))) {
1518 typed_memcpy(dest
->discard_rectangle
.rectangles
,
1519 src
->discard_rectangle
.rectangles
,
1520 src
->discard_rectangle
.count
);
1521 dest_mask
|= TU_DYNAMIC_DISCARD_RECTANGLE
;
1527 tu_create_cmd_buffer(struct tu_device
*device
,
1528 struct tu_cmd_pool
*pool
,
1529 VkCommandBufferLevel level
,
1530 VkCommandBuffer
*pCommandBuffer
)
1532 struct tu_cmd_buffer
*cmd_buffer
;
1533 cmd_buffer
= vk_zalloc(&pool
->alloc
, sizeof(*cmd_buffer
), 8,
1534 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1535 if (cmd_buffer
== NULL
)
1536 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1538 cmd_buffer
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1539 cmd_buffer
->device
= device
;
1540 cmd_buffer
->pool
= pool
;
1541 cmd_buffer
->level
= level
;
1544 list_addtail(&cmd_buffer
->pool_link
, &pool
->cmd_buffers
);
1545 cmd_buffer
->queue_family_index
= pool
->queue_family_index
;
1548 /* Init the pool_link so we can safely call list_del when we destroy
1549 * the command buffer
1551 list_inithead(&cmd_buffer
->pool_link
);
1552 cmd_buffer
->queue_family_index
= TU_QUEUE_GENERAL
;
1555 tu_bo_list_init(&cmd_buffer
->bo_list
);
1556 tu_cs_init(&cmd_buffer
->cs
, device
, TU_CS_MODE_GROW
, 4096);
1557 tu_cs_init(&cmd_buffer
->draw_cs
, device
, TU_CS_MODE_GROW
, 4096);
1558 tu_cs_init(&cmd_buffer
->draw_epilogue_cs
, device
, TU_CS_MODE_GROW
, 4096);
1559 tu_cs_init(&cmd_buffer
->sub_cs
, device
, TU_CS_MODE_SUB_STREAM
, 2048);
1561 *pCommandBuffer
= tu_cmd_buffer_to_handle(cmd_buffer
);
1563 list_inithead(&cmd_buffer
->upload
.list
);
1565 VkResult result
= tu_bo_init_new(device
, &cmd_buffer
->scratch_bo
, 0x1000);
1566 if (result
!= VK_SUCCESS
)
1567 goto fail_scratch_bo
;
1569 /* TODO: resize on overflow */
1570 cmd_buffer
->vsc_data_pitch
= device
->vsc_data_pitch
;
1571 cmd_buffer
->vsc_data2_pitch
= device
->vsc_data2_pitch
;
1572 cmd_buffer
->vsc_data
= device
->vsc_data
;
1573 cmd_buffer
->vsc_data2
= device
->vsc_data2
;
1578 list_del(&cmd_buffer
->pool_link
);
1583 tu_cmd_buffer_destroy(struct tu_cmd_buffer
*cmd_buffer
)
1585 tu_bo_finish(cmd_buffer
->device
, &cmd_buffer
->scratch_bo
);
1587 list_del(&cmd_buffer
->pool_link
);
1589 for (unsigned i
= 0; i
< VK_PIPELINE_BIND_POINT_RANGE_SIZE
; i
++)
1590 free(cmd_buffer
->descriptors
[i
].push_set
.set
.mapped_ptr
);
1592 tu_cs_finish(&cmd_buffer
->cs
);
1593 tu_cs_finish(&cmd_buffer
->draw_cs
);
1594 tu_cs_finish(&cmd_buffer
->draw_epilogue_cs
);
1595 tu_cs_finish(&cmd_buffer
->sub_cs
);
1597 tu_bo_list_destroy(&cmd_buffer
->bo_list
);
1598 vk_free(&cmd_buffer
->pool
->alloc
, cmd_buffer
);
1602 tu_reset_cmd_buffer(struct tu_cmd_buffer
*cmd_buffer
)
1604 cmd_buffer
->wait_for_idle
= true;
1606 cmd_buffer
->record_result
= VK_SUCCESS
;
1608 tu_bo_list_reset(&cmd_buffer
->bo_list
);
1609 tu_cs_reset(&cmd_buffer
->cs
);
1610 tu_cs_reset(&cmd_buffer
->draw_cs
);
1611 tu_cs_reset(&cmd_buffer
->draw_epilogue_cs
);
1612 tu_cs_reset(&cmd_buffer
->sub_cs
);
1614 for (unsigned i
= 0; i
< VK_PIPELINE_BIND_POINT_RANGE_SIZE
; i
++) {
1615 cmd_buffer
->descriptors
[i
].valid
= 0;
1616 cmd_buffer
->descriptors
[i
].push_dirty
= false;
1619 cmd_buffer
->status
= TU_CMD_BUFFER_STATUS_INITIAL
;
1621 return cmd_buffer
->record_result
;
1625 tu_AllocateCommandBuffers(VkDevice _device
,
1626 const VkCommandBufferAllocateInfo
*pAllocateInfo
,
1627 VkCommandBuffer
*pCommandBuffers
)
1629 TU_FROM_HANDLE(tu_device
, device
, _device
);
1630 TU_FROM_HANDLE(tu_cmd_pool
, pool
, pAllocateInfo
->commandPool
);
1632 VkResult result
= VK_SUCCESS
;
1635 for (i
= 0; i
< pAllocateInfo
->commandBufferCount
; i
++) {
1637 if (!list_is_empty(&pool
->free_cmd_buffers
)) {
1638 struct tu_cmd_buffer
*cmd_buffer
= list_first_entry(
1639 &pool
->free_cmd_buffers
, struct tu_cmd_buffer
, pool_link
);
1641 list_del(&cmd_buffer
->pool_link
);
1642 list_addtail(&cmd_buffer
->pool_link
, &pool
->cmd_buffers
);
1644 result
= tu_reset_cmd_buffer(cmd_buffer
);
1645 cmd_buffer
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1646 cmd_buffer
->level
= pAllocateInfo
->level
;
1648 pCommandBuffers
[i
] = tu_cmd_buffer_to_handle(cmd_buffer
);
1650 result
= tu_create_cmd_buffer(device
, pool
, pAllocateInfo
->level
,
1651 &pCommandBuffers
[i
]);
1653 if (result
!= VK_SUCCESS
)
1657 if (result
!= VK_SUCCESS
) {
1658 tu_FreeCommandBuffers(_device
, pAllocateInfo
->commandPool
, i
,
1661 /* From the Vulkan 1.0.66 spec:
1663 * "vkAllocateCommandBuffers can be used to create multiple
1664 * command buffers. If the creation of any of those command
1665 * buffers fails, the implementation must destroy all
1666 * successfully created command buffer objects from this
1667 * command, set all entries of the pCommandBuffers array to
1668 * NULL and return the error."
1670 memset(pCommandBuffers
, 0,
1671 sizeof(*pCommandBuffers
) * pAllocateInfo
->commandBufferCount
);
1678 tu_FreeCommandBuffers(VkDevice device
,
1679 VkCommandPool commandPool
,
1680 uint32_t commandBufferCount
,
1681 const VkCommandBuffer
*pCommandBuffers
)
1683 for (uint32_t i
= 0; i
< commandBufferCount
; i
++) {
1684 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, pCommandBuffers
[i
]);
1687 if (cmd_buffer
->pool
) {
1688 list_del(&cmd_buffer
->pool_link
);
1689 list_addtail(&cmd_buffer
->pool_link
,
1690 &cmd_buffer
->pool
->free_cmd_buffers
);
1692 tu_cmd_buffer_destroy(cmd_buffer
);
1698 tu_ResetCommandBuffer(VkCommandBuffer commandBuffer
,
1699 VkCommandBufferResetFlags flags
)
1701 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
1702 return tu_reset_cmd_buffer(cmd_buffer
);
1706 tu_BeginCommandBuffer(VkCommandBuffer commandBuffer
,
1707 const VkCommandBufferBeginInfo
*pBeginInfo
)
1709 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
1710 VkResult result
= VK_SUCCESS
;
1712 if (cmd_buffer
->status
!= TU_CMD_BUFFER_STATUS_INITIAL
) {
1713 /* If the command buffer has already been resetted with
1714 * vkResetCommandBuffer, no need to do it again.
1716 result
= tu_reset_cmd_buffer(cmd_buffer
);
1717 if (result
!= VK_SUCCESS
)
1721 memset(&cmd_buffer
->state
, 0, sizeof(cmd_buffer
->state
));
1722 cmd_buffer
->usage_flags
= pBeginInfo
->flags
;
1724 tu_cs_begin(&cmd_buffer
->cs
);
1725 tu_cs_begin(&cmd_buffer
->draw_cs
);
1726 tu_cs_begin(&cmd_buffer
->draw_epilogue_cs
);
1728 cmd_buffer
->scratch_seqno
= 0;
1730 /* setup initial configuration into command buffer */
1731 if (cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
) {
1732 switch (cmd_buffer
->queue_family_index
) {
1733 case TU_QUEUE_GENERAL
:
1734 tu6_init_hw(cmd_buffer
, &cmd_buffer
->cs
);
1739 } else if (cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_SECONDARY
&&
1740 (pBeginInfo
->flags
& VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
)) {
1741 assert(pBeginInfo
->pInheritanceInfo
);
1742 cmd_buffer
->state
.pass
= tu_render_pass_from_handle(pBeginInfo
->pInheritanceInfo
->renderPass
);
1743 cmd_buffer
->state
.subpass
= &cmd_buffer
->state
.pass
->subpasses
[pBeginInfo
->pInheritanceInfo
->subpass
];
1746 cmd_buffer
->status
= TU_CMD_BUFFER_STATUS_RECORDING
;
1752 tu_CmdBindVertexBuffers(VkCommandBuffer commandBuffer
,
1753 uint32_t firstBinding
,
1754 uint32_t bindingCount
,
1755 const VkBuffer
*pBuffers
,
1756 const VkDeviceSize
*pOffsets
)
1758 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1760 assert(firstBinding
+ bindingCount
<= MAX_VBS
);
1762 for (uint32_t i
= 0; i
< bindingCount
; i
++) {
1763 cmd
->state
.vb
.buffers
[firstBinding
+ i
] =
1764 tu_buffer_from_handle(pBuffers
[i
]);
1765 cmd
->state
.vb
.offsets
[firstBinding
+ i
] = pOffsets
[i
];
1768 /* VB states depend on VkPipelineVertexInputStateCreateInfo */
1769 cmd
->state
.dirty
|= TU_CMD_DIRTY_VERTEX_BUFFERS
;
1773 tu_CmdBindIndexBuffer(VkCommandBuffer commandBuffer
,
1775 VkDeviceSize offset
,
1776 VkIndexType indexType
)
1778 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1779 TU_FROM_HANDLE(tu_buffer
, buf
, buffer
);
1781 /* initialize/update the restart index */
1782 if (!cmd
->state
.index_buffer
|| cmd
->state
.index_type
!= indexType
) {
1783 struct tu_cs
*draw_cs
= &cmd
->draw_cs
;
1785 tu6_emit_restart_index(
1786 draw_cs
, indexType
== VK_INDEX_TYPE_UINT32
? 0xffffffff : 0xffff);
1788 tu_cs_sanity_check(draw_cs
);
1792 if (cmd
->state
.index_buffer
!= buf
)
1793 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_READ
);
1795 cmd
->state
.index_buffer
= buf
;
1796 cmd
->state
.index_offset
= offset
;
1797 cmd
->state
.index_type
= indexType
;
1801 tu_CmdBindDescriptorSets(VkCommandBuffer commandBuffer
,
1802 VkPipelineBindPoint pipelineBindPoint
,
1803 VkPipelineLayout _layout
,
1805 uint32_t descriptorSetCount
,
1806 const VkDescriptorSet
*pDescriptorSets
,
1807 uint32_t dynamicOffsetCount
,
1808 const uint32_t *pDynamicOffsets
)
1810 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
1811 TU_FROM_HANDLE(tu_pipeline_layout
, layout
, _layout
);
1812 unsigned dyn_idx
= 0;
1814 struct tu_descriptor_state
*descriptors_state
=
1815 tu_get_descriptors_state(cmd_buffer
, pipelineBindPoint
);
1817 for (unsigned i
= 0; i
< descriptorSetCount
; ++i
) {
1818 unsigned idx
= i
+ firstSet
;
1819 TU_FROM_HANDLE(tu_descriptor_set
, set
, pDescriptorSets
[i
]);
1821 descriptors_state
->sets
[idx
] = set
;
1822 descriptors_state
->valid
|= (1u << idx
);
1824 /* Note: the actual input attachment indices come from the shader
1825 * itself, so we can't generate the patched versions of these until
1826 * draw time when both the pipeline and descriptors are bound and
1827 * we're inside the render pass.
1829 unsigned dst_idx
= layout
->set
[idx
].input_attachment_start
;
1830 memcpy(&descriptors_state
->input_attachments
[dst_idx
* A6XX_TEX_CONST_DWORDS
],
1831 set
->dynamic_descriptors
,
1832 set
->layout
->input_attachment_count
* A6XX_TEX_CONST_DWORDS
* 4);
1834 for(unsigned j
= 0; j
< set
->layout
->dynamic_offset_count
; ++j
, ++dyn_idx
) {
1835 /* Dynamic buffers come after input attachments in the descriptor set
1836 * itself, but due to how the Vulkan descriptor set binding works, we
1837 * have to put input attachments and dynamic buffers in separate
1838 * buffers in the descriptor_state and then combine them at draw
1839 * time. Binding a descriptor set only invalidates the descriptor
1840 * sets after it, but if we try to tightly pack the descriptors after
1841 * the input attachments then we could corrupt dynamic buffers in the
1842 * descriptor set before it, or we'd have to move all the dynamic
1843 * buffers over. We just put them into separate buffers to make
1844 * binding as well as the later patching of input attachments easy.
1846 unsigned src_idx
= j
+ set
->layout
->input_attachment_count
;
1847 unsigned dst_idx
= j
+ layout
->set
[idx
].dynamic_offset_start
;
1848 assert(dyn_idx
< dynamicOffsetCount
);
1851 &descriptors_state
->dynamic_descriptors
[dst_idx
* A6XX_TEX_CONST_DWORDS
];
1853 &set
->dynamic_descriptors
[src_idx
* A6XX_TEX_CONST_DWORDS
];
1854 uint32_t offset
= pDynamicOffsets
[dyn_idx
];
1856 /* Patch the storage/uniform descriptors right away. */
1857 if (layout
->set
[idx
].layout
->dynamic_ubo
& (1 << j
)) {
1858 /* Note: we can assume here that the addition won't roll over and
1859 * change the SIZE field.
1861 uint64_t va
= src
[0] | ((uint64_t)src
[1] << 32);
1866 memcpy(dst
, src
, A6XX_TEX_CONST_DWORDS
* 4);
1867 /* Note: A6XX_IBO_5_DEPTH is always 0 */
1868 uint64_t va
= dst
[4] | ((uint64_t)dst
[5] << 32);
1876 if (pipelineBindPoint
== VK_PIPELINE_BIND_POINT_COMPUTE
)
1877 cmd_buffer
->state
.dirty
|= TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
;
1879 cmd_buffer
->state
.dirty
|= TU_CMD_DIRTY_DESCRIPTOR_SETS
;
1882 void tu_CmdBindTransformFeedbackBuffersEXT(VkCommandBuffer commandBuffer
,
1883 uint32_t firstBinding
,
1884 uint32_t bindingCount
,
1885 const VkBuffer
*pBuffers
,
1886 const VkDeviceSize
*pOffsets
,
1887 const VkDeviceSize
*pSizes
)
1889 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1890 assert(firstBinding
+ bindingCount
<= IR3_MAX_SO_BUFFERS
);
1892 for (uint32_t i
= 0; i
< bindingCount
; i
++) {
1893 uint32_t idx
= firstBinding
+ i
;
1894 TU_FROM_HANDLE(tu_buffer
, buf
, pBuffers
[i
]);
1896 if (pOffsets
[i
] != 0)
1897 cmd
->state
.streamout_reset
|= 1 << idx
;
1899 cmd
->state
.streamout_buf
.buffers
[idx
] = buf
;
1900 cmd
->state
.streamout_buf
.offsets
[idx
] = pOffsets
[i
];
1901 cmd
->state
.streamout_buf
.sizes
[idx
] = pSizes
[i
];
1903 cmd
->state
.streamout_enabled
|= 1 << idx
;
1906 cmd
->state
.dirty
|= TU_CMD_DIRTY_STREAMOUT_BUFFERS
;
1909 void tu_CmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer
,
1910 uint32_t firstCounterBuffer
,
1911 uint32_t counterBufferCount
,
1912 const VkBuffer
*pCounterBuffers
,
1913 const VkDeviceSize
*pCounterBufferOffsets
)
1915 assert(firstCounterBuffer
+ counterBufferCount
<= IR3_MAX_SO_BUFFERS
);
1916 /* TODO do something with counter buffer? */
1919 void tu_CmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer
,
1920 uint32_t firstCounterBuffer
,
1921 uint32_t counterBufferCount
,
1922 const VkBuffer
*pCounterBuffers
,
1923 const VkDeviceSize
*pCounterBufferOffsets
)
1925 assert(firstCounterBuffer
+ counterBufferCount
<= IR3_MAX_SO_BUFFERS
);
1926 /* TODO do something with counter buffer? */
1928 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1929 cmd
->state
.streamout_enabled
= 0;
1933 tu_CmdPushConstants(VkCommandBuffer commandBuffer
,
1934 VkPipelineLayout layout
,
1935 VkShaderStageFlags stageFlags
,
1938 const void *pValues
)
1940 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1941 memcpy((void*) cmd
->push_constants
+ offset
, pValues
, size
);
1942 cmd
->state
.dirty
|= TU_CMD_DIRTY_PUSH_CONSTANTS
;
1946 tu_EndCommandBuffer(VkCommandBuffer commandBuffer
)
1948 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
1950 if (cmd_buffer
->scratch_seqno
) {
1951 tu_bo_list_add(&cmd_buffer
->bo_list
, &cmd_buffer
->scratch_bo
,
1952 MSM_SUBMIT_BO_WRITE
);
1955 if (cmd_buffer
->use_vsc_data
) {
1956 tu_bo_list_add(&cmd_buffer
->bo_list
, &cmd_buffer
->vsc_data
,
1957 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
1958 tu_bo_list_add(&cmd_buffer
->bo_list
, &cmd_buffer
->vsc_data2
,
1959 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
1962 tu_bo_list_add(&cmd_buffer
->bo_list
, &cmd_buffer
->device
->border_color
,
1963 MSM_SUBMIT_BO_READ
);
1965 for (uint32_t i
= 0; i
< cmd_buffer
->draw_cs
.bo_count
; i
++) {
1966 tu_bo_list_add(&cmd_buffer
->bo_list
, cmd_buffer
->draw_cs
.bos
[i
],
1967 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
1970 for (uint32_t i
= 0; i
< cmd_buffer
->draw_epilogue_cs
.bo_count
; i
++) {
1971 tu_bo_list_add(&cmd_buffer
->bo_list
, cmd_buffer
->draw_epilogue_cs
.bos
[i
],
1972 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
1975 for (uint32_t i
= 0; i
< cmd_buffer
->sub_cs
.bo_count
; i
++) {
1976 tu_bo_list_add(&cmd_buffer
->bo_list
, cmd_buffer
->sub_cs
.bos
[i
],
1977 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
1980 tu_cs_end(&cmd_buffer
->cs
);
1981 tu_cs_end(&cmd_buffer
->draw_cs
);
1982 tu_cs_end(&cmd_buffer
->draw_epilogue_cs
);
1984 cmd_buffer
->status
= TU_CMD_BUFFER_STATUS_EXECUTABLE
;
1986 return cmd_buffer
->record_result
;
1990 tu_CmdBindPipeline(VkCommandBuffer commandBuffer
,
1991 VkPipelineBindPoint pipelineBindPoint
,
1992 VkPipeline _pipeline
)
1994 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1995 TU_FROM_HANDLE(tu_pipeline
, pipeline
, _pipeline
);
1997 switch (pipelineBindPoint
) {
1998 case VK_PIPELINE_BIND_POINT_GRAPHICS
:
1999 cmd
->state
.pipeline
= pipeline
;
2000 cmd
->state
.dirty
|= TU_CMD_DIRTY_PIPELINE
;
2002 case VK_PIPELINE_BIND_POINT_COMPUTE
:
2003 cmd
->state
.compute_pipeline
= pipeline
;
2004 cmd
->state
.dirty
|= TU_CMD_DIRTY_COMPUTE_PIPELINE
;
2007 unreachable("unrecognized pipeline bind point");
2011 tu_bo_list_add(&cmd
->bo_list
, &pipeline
->program
.binary_bo
,
2012 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
2013 for (uint32_t i
= 0; i
< pipeline
->cs
.bo_count
; i
++) {
2014 tu_bo_list_add(&cmd
->bo_list
, pipeline
->cs
.bos
[i
],
2015 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
2020 tu_CmdSetViewport(VkCommandBuffer commandBuffer
,
2021 uint32_t firstViewport
,
2022 uint32_t viewportCount
,
2023 const VkViewport
*pViewports
)
2025 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2027 assert(firstViewport
== 0 && viewportCount
== 1);
2028 cmd
->state
.dynamic
.viewport
.viewports
[0] = pViewports
[0];
2029 cmd
->state
.dirty
|= TU_CMD_DIRTY_DYNAMIC_VIEWPORT
;
2033 tu_CmdSetScissor(VkCommandBuffer commandBuffer
,
2034 uint32_t firstScissor
,
2035 uint32_t scissorCount
,
2036 const VkRect2D
*pScissors
)
2038 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2040 assert(firstScissor
== 0 && scissorCount
== 1);
2041 cmd
->state
.dynamic
.scissor
.scissors
[0] = pScissors
[0];
2042 cmd
->state
.dirty
|= TU_CMD_DIRTY_DYNAMIC_SCISSOR
;
2046 tu_CmdSetLineWidth(VkCommandBuffer commandBuffer
, float lineWidth
)
2048 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2050 cmd
->state
.dynamic
.line_width
= lineWidth
;
2052 /* line width depends on VkPipelineRasterizationStateCreateInfo */
2053 cmd
->state
.dirty
|= TU_CMD_DIRTY_DYNAMIC_LINE_WIDTH
;
2057 tu_CmdSetDepthBias(VkCommandBuffer commandBuffer
,
2058 float depthBiasConstantFactor
,
2059 float depthBiasClamp
,
2060 float depthBiasSlopeFactor
)
2062 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2063 struct tu_cs
*draw_cs
= &cmd
->draw_cs
;
2065 tu6_emit_depth_bias(draw_cs
, depthBiasConstantFactor
, depthBiasClamp
,
2066 depthBiasSlopeFactor
);
2068 tu_cs_sanity_check(draw_cs
);
2072 tu_CmdSetBlendConstants(VkCommandBuffer commandBuffer
,
2073 const float blendConstants
[4])
2075 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2076 struct tu_cs
*draw_cs
= &cmd
->draw_cs
;
2078 tu6_emit_blend_constants(draw_cs
, blendConstants
);
2080 tu_cs_sanity_check(draw_cs
);
2084 tu_CmdSetDepthBounds(VkCommandBuffer commandBuffer
,
2085 float minDepthBounds
,
2086 float maxDepthBounds
)
2091 tu_CmdSetStencilCompareMask(VkCommandBuffer commandBuffer
,
2092 VkStencilFaceFlags faceMask
,
2093 uint32_t compareMask
)
2095 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2097 if (faceMask
& VK_STENCIL_FACE_FRONT_BIT
)
2098 cmd
->state
.dynamic
.stencil_compare_mask
.front
= compareMask
;
2099 if (faceMask
& VK_STENCIL_FACE_BACK_BIT
)
2100 cmd
->state
.dynamic
.stencil_compare_mask
.back
= compareMask
;
2102 /* the front/back compare masks must be updated together */
2103 cmd
->state
.dirty
|= TU_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
;
2107 tu_CmdSetStencilWriteMask(VkCommandBuffer commandBuffer
,
2108 VkStencilFaceFlags faceMask
,
2111 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2113 if (faceMask
& VK_STENCIL_FACE_FRONT_BIT
)
2114 cmd
->state
.dynamic
.stencil_write_mask
.front
= writeMask
;
2115 if (faceMask
& VK_STENCIL_FACE_BACK_BIT
)
2116 cmd
->state
.dynamic
.stencil_write_mask
.back
= writeMask
;
2118 /* the front/back write masks must be updated together */
2119 cmd
->state
.dirty
|= TU_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
;
2123 tu_CmdSetStencilReference(VkCommandBuffer commandBuffer
,
2124 VkStencilFaceFlags faceMask
,
2127 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2129 if (faceMask
& VK_STENCIL_FACE_FRONT_BIT
)
2130 cmd
->state
.dynamic
.stencil_reference
.front
= reference
;
2131 if (faceMask
& VK_STENCIL_FACE_BACK_BIT
)
2132 cmd
->state
.dynamic
.stencil_reference
.back
= reference
;
2134 /* the front/back references must be updated together */
2135 cmd
->state
.dirty
|= TU_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
;
2139 tu_CmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer
,
2140 const VkSampleLocationsInfoEXT
* pSampleLocationsInfo
)
2142 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2144 tu6_emit_sample_locations(&cmd
->draw_cs
, pSampleLocationsInfo
);
2148 tu_CmdExecuteCommands(VkCommandBuffer commandBuffer
,
2149 uint32_t commandBufferCount
,
2150 const VkCommandBuffer
*pCmdBuffers
)
2152 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2155 assert(commandBufferCount
> 0);
2157 for (uint32_t i
= 0; i
< commandBufferCount
; i
++) {
2158 TU_FROM_HANDLE(tu_cmd_buffer
, secondary
, pCmdBuffers
[i
]);
2160 result
= tu_bo_list_merge(&cmd
->bo_list
, &secondary
->bo_list
);
2161 if (result
!= VK_SUCCESS
) {
2162 cmd
->record_result
= result
;
2166 if (secondary
->usage_flags
&
2167 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
) {
2168 assert(tu_cs_is_empty(&secondary
->cs
));
2170 result
= tu_cs_add_entries(&cmd
->draw_cs
, &secondary
->draw_cs
);
2171 if (result
!= VK_SUCCESS
) {
2172 cmd
->record_result
= result
;
2176 result
= tu_cs_add_entries(&cmd
->draw_epilogue_cs
,
2177 &secondary
->draw_epilogue_cs
);
2178 if (result
!= VK_SUCCESS
) {
2179 cmd
->record_result
= result
;
2183 assert(tu_cs_is_empty(&secondary
->draw_cs
));
2184 assert(tu_cs_is_empty(&secondary
->draw_epilogue_cs
));
2186 for (uint32_t j
= 0; j
< secondary
->cs
.bo_count
; j
++) {
2187 tu_bo_list_add(&cmd
->bo_list
, secondary
->cs
.bos
[j
],
2188 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
2191 tu_cs_add_entries(&cmd
->cs
, &secondary
->cs
);
2194 cmd
->state
.dirty
= ~0u; /* TODO: set dirty only what needs to be */
2198 tu_CreateCommandPool(VkDevice _device
,
2199 const VkCommandPoolCreateInfo
*pCreateInfo
,
2200 const VkAllocationCallbacks
*pAllocator
,
2201 VkCommandPool
*pCmdPool
)
2203 TU_FROM_HANDLE(tu_device
, device
, _device
);
2204 struct tu_cmd_pool
*pool
;
2206 pool
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*pool
), 8,
2207 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2209 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2212 pool
->alloc
= *pAllocator
;
2214 pool
->alloc
= device
->alloc
;
2216 list_inithead(&pool
->cmd_buffers
);
2217 list_inithead(&pool
->free_cmd_buffers
);
2219 pool
->queue_family_index
= pCreateInfo
->queueFamilyIndex
;
2221 *pCmdPool
= tu_cmd_pool_to_handle(pool
);
2227 tu_DestroyCommandPool(VkDevice _device
,
2228 VkCommandPool commandPool
,
2229 const VkAllocationCallbacks
*pAllocator
)
2231 TU_FROM_HANDLE(tu_device
, device
, _device
);
2232 TU_FROM_HANDLE(tu_cmd_pool
, pool
, commandPool
);
2237 list_for_each_entry_safe(struct tu_cmd_buffer
, cmd_buffer
,
2238 &pool
->cmd_buffers
, pool_link
)
2240 tu_cmd_buffer_destroy(cmd_buffer
);
2243 list_for_each_entry_safe(struct tu_cmd_buffer
, cmd_buffer
,
2244 &pool
->free_cmd_buffers
, pool_link
)
2246 tu_cmd_buffer_destroy(cmd_buffer
);
2249 vk_free2(&device
->alloc
, pAllocator
, pool
);
2253 tu_ResetCommandPool(VkDevice device
,
2254 VkCommandPool commandPool
,
2255 VkCommandPoolResetFlags flags
)
2257 TU_FROM_HANDLE(tu_cmd_pool
, pool
, commandPool
);
2260 list_for_each_entry(struct tu_cmd_buffer
, cmd_buffer
, &pool
->cmd_buffers
,
2263 result
= tu_reset_cmd_buffer(cmd_buffer
);
2264 if (result
!= VK_SUCCESS
)
2272 tu_TrimCommandPool(VkDevice device
,
2273 VkCommandPool commandPool
,
2274 VkCommandPoolTrimFlags flags
)
2276 TU_FROM_HANDLE(tu_cmd_pool
, pool
, commandPool
);
2281 list_for_each_entry_safe(struct tu_cmd_buffer
, cmd_buffer
,
2282 &pool
->free_cmd_buffers
, pool_link
)
2284 tu_cmd_buffer_destroy(cmd_buffer
);
2289 tu_CmdBeginRenderPass(VkCommandBuffer commandBuffer
,
2290 const VkRenderPassBeginInfo
*pRenderPassBegin
,
2291 VkSubpassContents contents
)
2293 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2294 TU_FROM_HANDLE(tu_render_pass
, pass
, pRenderPassBegin
->renderPass
);
2295 TU_FROM_HANDLE(tu_framebuffer
, fb
, pRenderPassBegin
->framebuffer
);
2297 cmd
->state
.pass
= pass
;
2298 cmd
->state
.subpass
= pass
->subpasses
;
2299 cmd
->state
.framebuffer
= fb
;
2301 tu_cmd_update_tiling_config(cmd
, &pRenderPassBegin
->renderArea
);
2302 tu_cmd_prepare_tile_store_ib(cmd
);
2304 tu_emit_load_clear(cmd
, pRenderPassBegin
);
2306 tu6_emit_zs(cmd
, cmd
->state
.subpass
, &cmd
->draw_cs
);
2307 tu6_emit_mrt(cmd
, cmd
->state
.subpass
, &cmd
->draw_cs
);
2308 tu6_emit_msaa(&cmd
->draw_cs
, cmd
->state
.subpass
->samples
);
2309 tu6_emit_render_cntl(cmd
, cmd
->state
.subpass
, &cmd
->draw_cs
, false);
2311 /* note: use_hw_binning only checks tiling config */
2312 if (use_hw_binning(cmd
))
2313 cmd
->use_vsc_data
= true;
2315 for (uint32_t i
= 0; i
< fb
->attachment_count
; ++i
) {
2316 const struct tu_image_view
*iview
= fb
->attachments
[i
].attachment
;
2317 tu_bo_list_add(&cmd
->bo_list
, iview
->image
->bo
,
2318 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
2321 /* Flag input attachment descriptors for re-emission if necessary */
2322 cmd
->state
.dirty
|= TU_CMD_DIRTY_INPUT_ATTACHMENTS
;
2326 tu_CmdBeginRenderPass2(VkCommandBuffer commandBuffer
,
2327 const VkRenderPassBeginInfo
*pRenderPassBeginInfo
,
2328 const VkSubpassBeginInfoKHR
*pSubpassBeginInfo
)
2330 tu_CmdBeginRenderPass(commandBuffer
, pRenderPassBeginInfo
,
2331 pSubpassBeginInfo
->contents
);
2335 tu_CmdNextSubpass(VkCommandBuffer commandBuffer
, VkSubpassContents contents
)
2337 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2338 const struct tu_render_pass
*pass
= cmd
->state
.pass
;
2339 struct tu_cs
*cs
= &cmd
->draw_cs
;
2341 const struct tu_subpass
*subpass
= cmd
->state
.subpass
++;
2343 tu_cond_exec_start(cs
, CP_COND_EXEC_0_RENDER_MODE_GMEM
);
2345 if (subpass
->resolve_attachments
) {
2346 tu6_emit_blit_scissor(cmd
, cs
, true);
2348 for (unsigned i
= 0; i
< subpass
->color_count
; i
++) {
2349 uint32_t a
= subpass
->resolve_attachments
[i
].attachment
;
2350 if (a
== VK_ATTACHMENT_UNUSED
)
2353 tu_store_gmem_attachment(cmd
, cs
, a
,
2354 subpass
->color_attachments
[i
].attachment
);
2356 if (pass
->attachments
[a
].gmem_offset
< 0)
2360 * check if the resolved attachment is needed by later subpasses,
2361 * if it is, should be doing a GMEM->GMEM resolve instead of GMEM->MEM->GMEM..
2363 tu_finishme("missing GMEM->GMEM resolve path\n");
2364 tu_load_gmem_attachment(cmd
, cs
, a
, true);
2368 tu_cond_exec_end(cs
);
2370 tu_cond_exec_start(cs
, CP_COND_EXEC_0_RENDER_MODE_SYSMEM
);
2372 /* Emit flushes so that input attachments will read the correct value.
2373 * TODO: use subpass dependencies to flush or not
2375 tu6_emit_event_write(cmd
, cs
, PC_CCU_FLUSH_COLOR_TS
, true);
2376 tu6_emit_event_write(cmd
, cs
, PC_CCU_FLUSH_DEPTH_TS
, true);
2378 if (subpass
->resolve_attachments
) {
2379 tu6_emit_event_write(cmd
, cs
, CACHE_INVALIDATE
, false);
2381 for (unsigned i
= 0; i
< subpass
->color_count
; i
++) {
2382 uint32_t a
= subpass
->resolve_attachments
[i
].attachment
;
2383 if (a
== VK_ATTACHMENT_UNUSED
)
2386 tu6_emit_sysmem_resolve(cmd
, cs
, a
,
2387 subpass
->color_attachments
[i
].attachment
);
2390 tu6_emit_event_write(cmd
, cs
, PC_CCU_FLUSH_COLOR_TS
, true);
2393 tu_cond_exec_end(cs
);
2395 /* subpass->input_count > 0 then texture cache invalidate is likely to be needed */
2396 if (cmd
->state
.subpass
->input_count
)
2397 tu6_emit_event_write(cmd
, cs
, CACHE_INVALIDATE
, false);
2399 /* emit mrt/zs/msaa/ubwc state for the subpass that is starting */
2400 tu6_emit_zs(cmd
, cmd
->state
.subpass
, cs
);
2401 tu6_emit_mrt(cmd
, cmd
->state
.subpass
, cs
);
2402 tu6_emit_msaa(cs
, cmd
->state
.subpass
->samples
);
2403 tu6_emit_render_cntl(cmd
, cmd
->state
.subpass
, cs
, false);
2405 /* Flag input attachment descriptors for re-emission if necessary */
2406 cmd
->state
.dirty
|= TU_CMD_DIRTY_INPUT_ATTACHMENTS
;
2410 tu_CmdNextSubpass2(VkCommandBuffer commandBuffer
,
2411 const VkSubpassBeginInfoKHR
*pSubpassBeginInfo
,
2412 const VkSubpassEndInfoKHR
*pSubpassEndInfo
)
2414 tu_CmdNextSubpass(commandBuffer
, pSubpassBeginInfo
->contents
);
2420 * Number of vertices.
2425 * Index of the first vertex.
2427 int32_t vertex_offset
;
2430 * First instance id.
2432 uint32_t first_instance
;
2435 * Number of instances.
2437 uint32_t instance_count
;
2440 * First index (indexed draws only).
2442 uint32_t first_index
;
2445 * Whether it's an indexed draw.
2450 * Indirect draw parameters resource.
2452 struct tu_buffer
*indirect
;
2453 uint64_t indirect_offset
;
2457 * Draw count parameters resource.
2459 struct tu_buffer
*count_buffer
;
2460 uint64_t count_buffer_offset
;
2463 * Stream output parameters resource.
2465 struct tu_buffer
*streamout_buffer
;
2466 uint64_t streamout_buffer_offset
;
2469 #define ENABLE_ALL (CP_SET_DRAW_STATE__0_BINNING | CP_SET_DRAW_STATE__0_GMEM | CP_SET_DRAW_STATE__0_SYSMEM)
2470 #define ENABLE_DRAW (CP_SET_DRAW_STATE__0_GMEM | CP_SET_DRAW_STATE__0_SYSMEM)
2471 #define ENABLE_NON_GMEM (CP_SET_DRAW_STATE__0_BINNING | CP_SET_DRAW_STATE__0_SYSMEM)
2473 enum tu_draw_state_group_id
2475 TU_DRAW_STATE_PROGRAM
,
2476 TU_DRAW_STATE_PROGRAM_BINNING
,
2478 TU_DRAW_STATE_VI_BINNING
,
2482 TU_DRAW_STATE_BLEND
,
2483 TU_DRAW_STATE_VS_CONST
,
2484 TU_DRAW_STATE_GS_CONST
,
2485 TU_DRAW_STATE_FS_CONST
,
2486 TU_DRAW_STATE_DESC_SETS
,
2487 TU_DRAW_STATE_DESC_SETS_GMEM
,
2488 TU_DRAW_STATE_DESC_SETS_LOAD
,
2489 TU_DRAW_STATE_VS_PARAMS
,
2491 TU_DRAW_STATE_COUNT
,
2494 struct tu_draw_state_group
2496 enum tu_draw_state_group_id id
;
2497 uint32_t enable_mask
;
2498 struct tu_cs_entry ib
;
2501 static inline uint32_t
2502 tu6_stage2opcode(gl_shader_stage type
)
2505 case MESA_SHADER_VERTEX
:
2506 case MESA_SHADER_TESS_CTRL
:
2507 case MESA_SHADER_TESS_EVAL
:
2508 case MESA_SHADER_GEOMETRY
:
2509 return CP_LOAD_STATE6_GEOM
;
2510 case MESA_SHADER_FRAGMENT
:
2511 case MESA_SHADER_COMPUTE
:
2512 case MESA_SHADER_KERNEL
:
2513 return CP_LOAD_STATE6_FRAG
;
2515 unreachable("bad shader type");
2519 static inline enum a6xx_state_block
2520 tu6_stage2shadersb(gl_shader_stage type
)
2523 case MESA_SHADER_VERTEX
:
2524 return SB6_VS_SHADER
;
2525 case MESA_SHADER_GEOMETRY
:
2526 return SB6_GS_SHADER
;
2527 case MESA_SHADER_FRAGMENT
:
2528 return SB6_FS_SHADER
;
2529 case MESA_SHADER_COMPUTE
:
2530 case MESA_SHADER_KERNEL
:
2531 return SB6_CS_SHADER
;
2533 unreachable("bad shader type");
2539 tu6_emit_user_consts(struct tu_cs
*cs
, const struct tu_pipeline
*pipeline
,
2540 struct tu_descriptor_state
*descriptors_state
,
2541 gl_shader_stage type
,
2542 uint32_t *push_constants
)
2544 const struct tu_program_descriptor_linkage
*link
=
2545 &pipeline
->program
.link
[type
];
2546 const struct ir3_ubo_analysis_state
*state
= &link
->ubo_state
;
2548 if (link
->push_consts
.count
> 0) {
2549 unsigned num_units
= link
->push_consts
.count
;
2550 unsigned offset
= link
->push_consts
.lo
;
2551 tu_cs_emit_pkt7(cs
, tu6_stage2opcode(type
), 3 + num_units
* 4);
2552 tu_cs_emit(cs
, CP_LOAD_STATE6_0_DST_OFF(offset
) |
2553 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
2554 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
2555 CP_LOAD_STATE6_0_STATE_BLOCK(tu6_stage2shadersb(type
)) |
2556 CP_LOAD_STATE6_0_NUM_UNIT(num_units
));
2559 for (unsigned i
= 0; i
< num_units
* 4; i
++)
2560 tu_cs_emit(cs
, push_constants
[i
+ offset
* 4]);
2563 for (uint32_t i
= 0; i
< state
->num_enabled
; i
++) {
2564 uint32_t size
= state
->range
[i
].end
- state
->range
[i
].start
;
2565 uint32_t offset
= state
->range
[i
].start
;
2567 /* and even if the start of the const buffer is before
2568 * first_immediate, the end may not be:
2570 size
= MIN2(size
, (16 * link
->constlen
) - state
->range
[i
].offset
);
2575 /* things should be aligned to vec4: */
2576 debug_assert((state
->range
[i
].offset
% 16) == 0);
2577 debug_assert((size
% 16) == 0);
2578 debug_assert((offset
% 16) == 0);
2580 /* Dig out the descriptor from the descriptor state and read the VA from
2583 assert(state
->range
[i
].bindless
);
2584 uint32_t *base
= state
->range
[i
].bindless_base
== MAX_SETS
?
2585 descriptors_state
->dynamic_descriptors
:
2586 descriptors_state
->sets
[state
->range
[i
].bindless_base
]->mapped_ptr
;
2587 unsigned block
= state
->range
[i
].block
;
2588 /* If the block in the shader here is in the dynamic descriptor set, it
2589 * is an index into the dynamic descriptor set which is combined from
2590 * dynamic descriptors and input attachments on-the-fly, and we don't
2591 * have access to it here. Instead we work backwards to get the index
2592 * into dynamic_descriptors.
2594 if (state
->range
[i
].bindless_base
== MAX_SETS
)
2595 block
-= pipeline
->layout
->input_attachment_count
;
2596 uint32_t *desc
= base
+ block
* A6XX_TEX_CONST_DWORDS
;
2597 uint64_t va
= desc
[0] | ((uint64_t)(desc
[1] & A6XX_UBO_1_BASE_HI__MASK
) << 32);
2600 tu_cs_emit_pkt7(cs
, tu6_stage2opcode(type
), 3);
2601 tu_cs_emit(cs
, CP_LOAD_STATE6_0_DST_OFF(state
->range
[i
].offset
/ 16) |
2602 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
2603 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
2604 CP_LOAD_STATE6_0_STATE_BLOCK(tu6_stage2shadersb(type
)) |
2605 CP_LOAD_STATE6_0_NUM_UNIT(size
/ 16));
2606 tu_cs_emit_qw(cs
, va
+ offset
);
2610 static struct tu_cs_entry
2611 tu6_emit_consts(struct tu_cmd_buffer
*cmd
,
2612 const struct tu_pipeline
*pipeline
,
2613 struct tu_descriptor_state
*descriptors_state
,
2614 gl_shader_stage type
)
2617 tu_cs_begin_sub_stream(&cmd
->sub_cs
, 512, &cs
); /* TODO: maximum size? */
2619 tu6_emit_user_consts(&cs
, pipeline
, descriptors_state
, type
, cmd
->push_constants
);
2621 return tu_cs_end_sub_stream(&cmd
->sub_cs
, &cs
);
2625 tu6_emit_vs_params(struct tu_cmd_buffer
*cmd
,
2626 const struct tu_draw_info
*draw
,
2627 struct tu_cs_entry
*entry
)
2629 /* TODO: fill out more than just base instance */
2630 const struct tu_program_descriptor_linkage
*link
=
2631 &cmd
->state
.pipeline
->program
.link
[MESA_SHADER_VERTEX
];
2632 const struct ir3_const_state
*const_state
= &link
->const_state
;
2635 if (const_state
->offsets
.driver_param
>= link
->constlen
) {
2636 *entry
= (struct tu_cs_entry
) {};
2640 VkResult result
= tu_cs_begin_sub_stream(&cmd
->sub_cs
, 8, &cs
);
2641 if (result
!= VK_SUCCESS
)
2644 tu_cs_emit_pkt7(&cs
, CP_LOAD_STATE6_GEOM
, 3 + 4);
2645 tu_cs_emit(&cs
, CP_LOAD_STATE6_0_DST_OFF(const_state
->offsets
.driver_param
) |
2646 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
2647 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
2648 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_VS_SHADER
) |
2649 CP_LOAD_STATE6_0_NUM_UNIT(1));
2653 STATIC_ASSERT(IR3_DP_INSTID_BASE
== 2);
2657 tu_cs_emit(&cs
, draw
->first_instance
);
2660 *entry
= tu_cs_end_sub_stream(&cmd
->sub_cs
, &cs
);
2665 tu6_emit_descriptor_sets(struct tu_cmd_buffer
*cmd
,
2666 const struct tu_pipeline
*pipeline
,
2667 VkPipelineBindPoint bind_point
,
2668 struct tu_cs_entry
*entry
,
2671 struct tu_cs
*draw_state
= &cmd
->sub_cs
;
2672 struct tu_pipeline_layout
*layout
= pipeline
->layout
;
2673 struct tu_descriptor_state
*descriptors_state
=
2674 tu_get_descriptors_state(cmd
, bind_point
);
2675 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
2676 const uint32_t *input_attachment_idx
=
2677 pipeline
->program
.input_attachment_idx
;
2678 uint32_t num_dynamic_descs
= layout
->dynamic_offset_count
+
2679 layout
->input_attachment_count
;
2680 struct ts_cs_memory dynamic_desc_set
;
2683 if (num_dynamic_descs
> 0) {
2684 /* allocate and fill out dynamic descriptor set */
2685 result
= tu_cs_alloc(draw_state
, num_dynamic_descs
,
2686 A6XX_TEX_CONST_DWORDS
, &dynamic_desc_set
);
2687 if (result
!= VK_SUCCESS
)
2690 memcpy(dynamic_desc_set
.map
, descriptors_state
->input_attachments
,
2691 layout
->input_attachment_count
* A6XX_TEX_CONST_DWORDS
* 4);
2694 /* Patch input attachments to refer to GMEM instead */
2695 for (unsigned i
= 0; i
< layout
->input_attachment_count
; i
++) {
2697 &dynamic_desc_set
.map
[A6XX_TEX_CONST_DWORDS
* i
];
2699 /* The compiler has already laid out input_attachment_idx in the
2700 * final order of input attachments, so there's no need to go
2701 * through the pipeline layout finding input attachments.
2703 unsigned attachment_idx
= input_attachment_idx
[i
];
2705 /* It's possible for the pipeline layout to include an input
2706 * attachment which doesn't actually exist for the current
2707 * subpass. Of course, this is only valid so long as the pipeline
2708 * doesn't try to actually load that attachment. Just skip
2709 * patching in that scenario to avoid out-of-bounds accesses.
2711 if (attachment_idx
>= cmd
->state
.subpass
->input_count
)
2714 uint32_t a
= cmd
->state
.subpass
->input_attachments
[attachment_idx
].attachment
;
2715 const struct tu_render_pass_attachment
*att
= &cmd
->state
.pass
->attachments
[a
];
2717 assert(att
->gmem_offset
>= 0);
2719 dst
[0] &= ~(A6XX_TEX_CONST_0_SWAP__MASK
| A6XX_TEX_CONST_0_TILE_MODE__MASK
);
2720 dst
[0] |= A6XX_TEX_CONST_0_TILE_MODE(TILE6_2
);
2721 dst
[2] &= ~(A6XX_TEX_CONST_2_TYPE__MASK
| A6XX_TEX_CONST_2_PITCH__MASK
);
2723 A6XX_TEX_CONST_2_TYPE(A6XX_TEX_2D
) |
2724 A6XX_TEX_CONST_2_PITCH(tiling
->tile0
.extent
.width
* att
->cpp
);
2726 dst
[4] = cmd
->device
->physical_device
->gmem_base
+ att
->gmem_offset
;
2727 dst
[5] = A6XX_TEX_CONST_5_DEPTH(1);
2728 for (unsigned i
= 6; i
< A6XX_TEX_CONST_DWORDS
; i
++)
2731 if (cmd
->level
== VK_COMMAND_BUFFER_LEVEL_SECONDARY
)
2732 tu_finishme("patch input attachment pitch for secondary cmd buffer");
2736 memcpy(dynamic_desc_set
.map
+ layout
->input_attachment_count
* A6XX_TEX_CONST_DWORDS
,
2737 descriptors_state
->dynamic_descriptors
,
2738 layout
->dynamic_offset_count
* A6XX_TEX_CONST_DWORDS
* 4);
2741 uint32_t sp_bindless_base_reg
, hlsq_bindless_base_reg
;
2742 uint32_t hlsq_update_value
;
2743 switch (bind_point
) {
2744 case VK_PIPELINE_BIND_POINT_GRAPHICS
:
2745 sp_bindless_base_reg
= REG_A6XX_SP_BINDLESS_BASE(0);
2746 hlsq_bindless_base_reg
= REG_A6XX_HLSQ_BINDLESS_BASE(0);
2747 hlsq_update_value
= 0x7c000;
2749 case VK_PIPELINE_BIND_POINT_COMPUTE
:
2750 sp_bindless_base_reg
= REG_A6XX_SP_CS_BINDLESS_BASE(0);
2751 hlsq_bindless_base_reg
= REG_A6XX_HLSQ_CS_BINDLESS_BASE(0);
2752 hlsq_update_value
= 0x3e00;
2755 unreachable("bad bind point");
2758 /* Be careful here to *not* refer to the pipeline, so that if only the
2759 * pipeline changes we don't have to emit this again (except if there are
2760 * dynamic descriptors in the pipeline layout). This means always emitting
2761 * all the valid descriptors, which means that we always have to put the
2762 * dynamic descriptor in the driver-only slot at the end
2764 uint32_t num_user_sets
= util_last_bit(descriptors_state
->valid
);
2765 uint32_t num_sets
= num_user_sets
;
2766 if (num_dynamic_descs
> 0) {
2767 num_user_sets
= MAX_SETS
;
2768 num_sets
= num_user_sets
+ 1;
2771 unsigned regs
[2] = { sp_bindless_base_reg
, hlsq_bindless_base_reg
};
2774 result
= tu_cs_begin_sub_stream(draw_state
, ARRAY_SIZE(regs
) * (1 + num_sets
* 2) + 2, &cs
);
2775 if (result
!= VK_SUCCESS
)
2779 for (unsigned i
= 0; i
< ARRAY_SIZE(regs
); i
++) {
2780 tu_cs_emit_pkt4(&cs
, regs
[i
], num_sets
* 2);
2781 for (unsigned j
= 0; j
< num_user_sets
; j
++) {
2782 if (descriptors_state
->valid
& (1 << j
)) {
2783 /* magic | 3 copied from the blob */
2784 tu_cs_emit_qw(&cs
, descriptors_state
->sets
[j
]->va
| 3);
2786 tu_cs_emit_qw(&cs
, 0 | 3);
2789 if (num_dynamic_descs
> 0) {
2790 tu_cs_emit_qw(&cs
, dynamic_desc_set
.iova
| 3);
2794 tu_cs_emit_regs(&cs
, A6XX_HLSQ_UPDATE_CNTL(hlsq_update_value
));
2797 *entry
= tu_cs_end_sub_stream(draw_state
, &cs
);
2802 tu6_emit_streamout(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
2804 struct tu_streamout_state
*tf
= &cmd
->state
.pipeline
->streamout
;
2806 for (unsigned i
= 0; i
< IR3_MAX_SO_BUFFERS
; i
++) {
2807 struct tu_buffer
*buf
= cmd
->state
.streamout_buf
.buffers
[i
];
2812 offset
= cmd
->state
.streamout_buf
.offsets
[i
];
2814 tu_cs_emit_regs(cs
, A6XX_VPC_SO_BUFFER_BASE(i
, .bo
= buf
->bo
,
2815 .bo_offset
= buf
->bo_offset
));
2816 tu_cs_emit_regs(cs
, A6XX_VPC_SO_BUFFER_SIZE(i
, buf
->size
));
2818 if (cmd
->state
.streamout_reset
& (1 << i
)) {
2819 tu_cs_emit_regs(cs
, A6XX_VPC_SO_BUFFER_OFFSET(i
, offset
));
2820 cmd
->state
.streamout_reset
&= ~(1 << i
);
2822 tu_cs_emit_pkt7(cs
, CP_MEM_TO_REG
, 3);
2823 tu_cs_emit(cs
, CP_MEM_TO_REG_0_REG(REG_A6XX_VPC_SO_BUFFER_OFFSET(i
)) |
2824 CP_MEM_TO_REG_0_SHIFT_BY_2
| CP_MEM_TO_REG_0_UNK31
|
2825 CP_MEM_TO_REG_0_CNT(0));
2826 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+
2827 ctrl_offset(flush_base
[i
].offset
));
2830 tu_cs_emit_regs(cs
, A6XX_VPC_SO_FLUSH_BASE(i
, .bo
= &cmd
->scratch_bo
,
2832 ctrl_offset(flush_base
[i
])));
2835 if (cmd
->state
.streamout_enabled
) {
2836 tu_cs_emit_pkt7(cs
, CP_CONTEXT_REG_BUNCH
, 12 + (2 * tf
->prog_count
));
2837 tu_cs_emit(cs
, REG_A6XX_VPC_SO_BUF_CNTL
);
2838 tu_cs_emit(cs
, tf
->vpc_so_buf_cntl
);
2839 tu_cs_emit(cs
, REG_A6XX_VPC_SO_NCOMP(0));
2840 tu_cs_emit(cs
, tf
->ncomp
[0]);
2841 tu_cs_emit(cs
, REG_A6XX_VPC_SO_NCOMP(1));
2842 tu_cs_emit(cs
, tf
->ncomp
[1]);
2843 tu_cs_emit(cs
, REG_A6XX_VPC_SO_NCOMP(2));
2844 tu_cs_emit(cs
, tf
->ncomp
[2]);
2845 tu_cs_emit(cs
, REG_A6XX_VPC_SO_NCOMP(3));
2846 tu_cs_emit(cs
, tf
->ncomp
[3]);
2847 tu_cs_emit(cs
, REG_A6XX_VPC_SO_CNTL
);
2848 tu_cs_emit(cs
, A6XX_VPC_SO_CNTL_ENABLE
);
2849 for (unsigned i
= 0; i
< tf
->prog_count
; i
++) {
2850 tu_cs_emit(cs
, REG_A6XX_VPC_SO_PROG
);
2851 tu_cs_emit(cs
, tf
->prog
[i
]);
2854 tu_cs_emit_pkt7(cs
, CP_CONTEXT_REG_BUNCH
, 4);
2855 tu_cs_emit(cs
, REG_A6XX_VPC_SO_CNTL
);
2857 tu_cs_emit(cs
, REG_A6XX_VPC_SO_BUF_CNTL
);
2863 tu6_bind_draw_states(struct tu_cmd_buffer
*cmd
,
2865 const struct tu_draw_info
*draw
)
2867 const struct tu_pipeline
*pipeline
= cmd
->state
.pipeline
;
2868 const struct tu_dynamic_state
*dynamic
= &cmd
->state
.dynamic
;
2869 struct tu_draw_state_group draw_state_groups
[TU_DRAW_STATE_COUNT
];
2870 uint32_t draw_state_group_count
= 0;
2873 struct tu_descriptor_state
*descriptors_state
=
2874 &cmd
->descriptors
[VK_PIPELINE_BIND_POINT_GRAPHICS
];
2879 A6XX_PC_PRIMITIVE_CNTL_0(.primitive_restart
=
2880 pipeline
->ia
.primitive_restart
&& draw
->indexed
));
2882 if (cmd
->state
.dirty
&
2883 (TU_CMD_DIRTY_PIPELINE
| TU_CMD_DIRTY_DYNAMIC_LINE_WIDTH
) &&
2884 (pipeline
->dynamic_state
.mask
& TU_DYNAMIC_LINE_WIDTH
)) {
2885 tu6_emit_gras_su_cntl(cs
, pipeline
->rast
.gras_su_cntl
,
2886 dynamic
->line_width
);
2889 if ((cmd
->state
.dirty
& TU_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
) &&
2890 (pipeline
->dynamic_state
.mask
& TU_DYNAMIC_STENCIL_COMPARE_MASK
)) {
2891 tu6_emit_stencil_compare_mask(cs
, dynamic
->stencil_compare_mask
.front
,
2892 dynamic
->stencil_compare_mask
.back
);
2895 if ((cmd
->state
.dirty
& TU_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
) &&
2896 (pipeline
->dynamic_state
.mask
& TU_DYNAMIC_STENCIL_WRITE_MASK
)) {
2897 tu6_emit_stencil_write_mask(cs
, dynamic
->stencil_write_mask
.front
,
2898 dynamic
->stencil_write_mask
.back
);
2901 if ((cmd
->state
.dirty
& TU_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
) &&
2902 (pipeline
->dynamic_state
.mask
& TU_DYNAMIC_STENCIL_REFERENCE
)) {
2903 tu6_emit_stencil_reference(cs
, dynamic
->stencil_reference
.front
,
2904 dynamic
->stencil_reference
.back
);
2907 if ((cmd
->state
.dirty
& TU_CMD_DIRTY_DYNAMIC_VIEWPORT
) &&
2908 (pipeline
->dynamic_state
.mask
& TU_DYNAMIC_VIEWPORT
)) {
2909 tu6_emit_viewport(cs
, &cmd
->state
.dynamic
.viewport
.viewports
[0]);
2912 if ((cmd
->state
.dirty
& TU_CMD_DIRTY_DYNAMIC_SCISSOR
) &&
2913 (pipeline
->dynamic_state
.mask
& TU_DYNAMIC_SCISSOR
)) {
2914 tu6_emit_scissor(cs
, &cmd
->state
.dynamic
.scissor
.scissors
[0]);
2917 if (cmd
->state
.dirty
&
2918 (TU_CMD_DIRTY_PIPELINE
| TU_CMD_DIRTY_VERTEX_BUFFERS
)) {
2919 for (uint32_t i
= 0; i
< pipeline
->vi
.count
; i
++) {
2920 const uint32_t binding
= pipeline
->vi
.bindings
[i
];
2921 const struct tu_buffer
*buf
= cmd
->state
.vb
.buffers
[binding
];
2922 const VkDeviceSize offset
= buf
->bo_offset
+
2923 cmd
->state
.vb
.offsets
[binding
];
2924 const VkDeviceSize size
=
2925 offset
< buf
->size
? buf
->size
- offset
: 0;
2928 A6XX_VFD_FETCH_BASE(i
, .bo
= buf
->bo
, .bo_offset
= offset
),
2929 A6XX_VFD_FETCH_SIZE(i
, size
));
2933 if (cmd
->state
.dirty
& TU_CMD_DIRTY_PIPELINE
) {
2934 draw_state_groups
[draw_state_group_count
++] =
2935 (struct tu_draw_state_group
) {
2936 .id
= TU_DRAW_STATE_PROGRAM
,
2937 .enable_mask
= ENABLE_DRAW
,
2938 .ib
= pipeline
->program
.state_ib
,
2940 draw_state_groups
[draw_state_group_count
++] =
2941 (struct tu_draw_state_group
) {
2942 .id
= TU_DRAW_STATE_PROGRAM_BINNING
,
2943 .enable_mask
= CP_SET_DRAW_STATE__0_BINNING
,
2944 .ib
= pipeline
->program
.binning_state_ib
,
2946 draw_state_groups
[draw_state_group_count
++] =
2947 (struct tu_draw_state_group
) {
2948 .id
= TU_DRAW_STATE_VI
,
2949 .enable_mask
= ENABLE_DRAW
,
2950 .ib
= pipeline
->vi
.state_ib
,
2952 draw_state_groups
[draw_state_group_count
++] =
2953 (struct tu_draw_state_group
) {
2954 .id
= TU_DRAW_STATE_VI_BINNING
,
2955 .enable_mask
= CP_SET_DRAW_STATE__0_BINNING
,
2956 .ib
= pipeline
->vi
.binning_state_ib
,
2958 draw_state_groups
[draw_state_group_count
++] =
2959 (struct tu_draw_state_group
) {
2960 .id
= TU_DRAW_STATE_VP
,
2961 .enable_mask
= ENABLE_ALL
,
2962 .ib
= pipeline
->vp
.state_ib
,
2964 draw_state_groups
[draw_state_group_count
++] =
2965 (struct tu_draw_state_group
) {
2966 .id
= TU_DRAW_STATE_RAST
,
2967 .enable_mask
= ENABLE_ALL
,
2968 .ib
= pipeline
->rast
.state_ib
,
2970 draw_state_groups
[draw_state_group_count
++] =
2971 (struct tu_draw_state_group
) {
2972 .id
= TU_DRAW_STATE_DS
,
2973 .enable_mask
= ENABLE_ALL
,
2974 .ib
= pipeline
->ds
.state_ib
,
2976 draw_state_groups
[draw_state_group_count
++] =
2977 (struct tu_draw_state_group
) {
2978 .id
= TU_DRAW_STATE_BLEND
,
2979 .enable_mask
= ENABLE_ALL
,
2980 .ib
= pipeline
->blend
.state_ib
,
2984 if (cmd
->state
.dirty
&
2985 (TU_CMD_DIRTY_PIPELINE
| TU_CMD_DIRTY_DESCRIPTOR_SETS
| TU_CMD_DIRTY_PUSH_CONSTANTS
)) {
2986 draw_state_groups
[draw_state_group_count
++] =
2987 (struct tu_draw_state_group
) {
2988 .id
= TU_DRAW_STATE_VS_CONST
,
2989 .enable_mask
= ENABLE_ALL
,
2990 .ib
= tu6_emit_consts(cmd
, pipeline
, descriptors_state
, MESA_SHADER_VERTEX
)
2992 draw_state_groups
[draw_state_group_count
++] =
2993 (struct tu_draw_state_group
) {
2994 .id
= TU_DRAW_STATE_GS_CONST
,
2995 .enable_mask
= ENABLE_ALL
,
2996 .ib
= tu6_emit_consts(cmd
, pipeline
, descriptors_state
, MESA_SHADER_GEOMETRY
)
2998 draw_state_groups
[draw_state_group_count
++] =
2999 (struct tu_draw_state_group
) {
3000 .id
= TU_DRAW_STATE_FS_CONST
,
3001 .enable_mask
= ENABLE_DRAW
,
3002 .ib
= tu6_emit_consts(cmd
, pipeline
, descriptors_state
, MESA_SHADER_FRAGMENT
)
3006 if (cmd
->state
.dirty
& TU_CMD_DIRTY_STREAMOUT_BUFFERS
)
3007 tu6_emit_streamout(cmd
, cs
);
3009 /* If there are any any dynamic descriptors, then we may need to re-emit
3010 * them after every pipeline change in case the number of input attachments
3011 * changes. We also always need to re-emit after a pipeline change if there
3012 * are any input attachments, because the input attachment index comes from
3013 * the pipeline. Finally, it can also happen that the subpass changes
3014 * without the pipeline changing, in which case the GMEM descriptors need
3015 * to be patched differently.
3017 * TODO: We could probably be clever and avoid re-emitting state on
3018 * pipeline changes if the number of input attachments is always 0. We
3019 * could also only re-emit dynamic state.
3021 if (cmd
->state
.dirty
& TU_CMD_DIRTY_DESCRIPTOR_SETS
||
3022 ((pipeline
->layout
->dynamic_offset_count
+
3023 pipeline
->layout
->input_attachment_count
> 0) &&
3024 cmd
->state
.dirty
& TU_CMD_DIRTY_PIPELINE
) ||
3025 (pipeline
->layout
->input_attachment_count
> 0 &&
3026 cmd
->state
.dirty
& TU_CMD_DIRTY_INPUT_ATTACHMENTS
)) {
3027 struct tu_cs_entry desc_sets
, desc_sets_gmem
;
3028 bool need_gmem_desc_set
= pipeline
->layout
->input_attachment_count
> 0;
3030 result
= tu6_emit_descriptor_sets(cmd
, pipeline
,
3031 VK_PIPELINE_BIND_POINT_GRAPHICS
,
3033 if (result
!= VK_SUCCESS
)
3036 draw_state_groups
[draw_state_group_count
++] =
3037 (struct tu_draw_state_group
) {
3038 .id
= TU_DRAW_STATE_DESC_SETS
,
3039 .enable_mask
= need_gmem_desc_set
? ENABLE_NON_GMEM
: ENABLE_ALL
,
3043 if (need_gmem_desc_set
) {
3044 result
= tu6_emit_descriptor_sets(cmd
, pipeline
,
3045 VK_PIPELINE_BIND_POINT_GRAPHICS
,
3046 &desc_sets_gmem
, true);
3047 if (result
!= VK_SUCCESS
)
3050 draw_state_groups
[draw_state_group_count
++] =
3051 (struct tu_draw_state_group
) {
3052 .id
= TU_DRAW_STATE_DESC_SETS_GMEM
,
3053 .enable_mask
= CP_SET_DRAW_STATE__0_GMEM
,
3054 .ib
= desc_sets_gmem
,
3058 /* We need to reload the descriptors every time the descriptor sets
3059 * change. However, the commands we send only depend on the pipeline
3060 * because the whole point is to cache descriptors which are used by the
3061 * pipeline. There's a problem here, in that the firmware has an
3062 * "optimization" which skips executing groups that are set to the same
3063 * value as the last draw. This means that if the descriptor sets change
3064 * but not the pipeline, we'd try to re-execute the same buffer which
3065 * the firmware would ignore and we wouldn't pre-load the new
3066 * descriptors. The blob seems to re-emit the LOAD_STATE group whenever
3067 * the descriptor sets change, which we emulate here by copying the
3068 * pre-prepared buffer.
3070 const struct tu_cs_entry
*load_entry
= &pipeline
->load_state
.state_ib
;
3071 if (load_entry
->size
> 0) {
3072 struct tu_cs load_cs
;
3073 result
= tu_cs_begin_sub_stream(&cmd
->sub_cs
, load_entry
->size
, &load_cs
);
3074 if (result
!= VK_SUCCESS
)
3076 tu_cs_emit_array(&load_cs
,
3077 (uint32_t *)((char *)load_entry
->bo
->map
+ load_entry
->offset
),
3078 load_entry
->size
/ 4);
3079 struct tu_cs_entry load_copy
= tu_cs_end_sub_stream(&cmd
->sub_cs
, &load_cs
);
3081 draw_state_groups
[draw_state_group_count
++] =
3082 (struct tu_draw_state_group
) {
3083 .id
= TU_DRAW_STATE_DESC_SETS_LOAD
,
3084 /* The blob seems to not enable this for binning, even when
3085 * resources would actually be used in the binning shader.
3086 * Presumably the overhead of prefetching the resources isn't
3089 .enable_mask
= ENABLE_DRAW
,
3095 struct tu_cs_entry vs_params
;
3096 result
= tu6_emit_vs_params(cmd
, draw
, &vs_params
);
3097 if (result
!= VK_SUCCESS
)
3100 draw_state_groups
[draw_state_group_count
++] =
3101 (struct tu_draw_state_group
) {
3102 .id
= TU_DRAW_STATE_VS_PARAMS
,
3103 .enable_mask
= ENABLE_ALL
,
3107 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 3 * draw_state_group_count
);
3108 for (uint32_t i
= 0; i
< draw_state_group_count
; i
++) {
3109 const struct tu_draw_state_group
*group
= &draw_state_groups
[i
];
3110 debug_assert((group
->enable_mask
& ~ENABLE_ALL
) == 0);
3111 uint32_t cp_set_draw_state
=
3112 CP_SET_DRAW_STATE__0_COUNT(group
->ib
.size
/ 4) |
3113 group
->enable_mask
|
3114 CP_SET_DRAW_STATE__0_GROUP_ID(group
->id
);
3116 if (group
->ib
.size
) {
3117 iova
= group
->ib
.bo
->iova
+ group
->ib
.offset
;
3119 cp_set_draw_state
|= CP_SET_DRAW_STATE__0_DISABLE
;
3123 tu_cs_emit(cs
, cp_set_draw_state
);
3124 tu_cs_emit_qw(cs
, iova
);
3127 tu_cs_sanity_check(cs
);
3130 if (cmd
->state
.dirty
& TU_CMD_DIRTY_VERTEX_BUFFERS
) {
3131 for (uint32_t i
= 0; i
< MAX_VBS
; i
++) {
3132 const struct tu_buffer
*buf
= cmd
->state
.vb
.buffers
[i
];
3134 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_READ
);
3137 if (cmd
->state
.dirty
& TU_CMD_DIRTY_DESCRIPTOR_SETS
) {
3139 for_each_bit(i
, descriptors_state
->valid
) {
3140 struct tu_descriptor_set
*set
= descriptors_state
->sets
[i
];
3141 for (unsigned j
= 0; j
< set
->layout
->buffer_count
; ++j
) {
3142 if (set
->buffers
[j
]) {
3143 tu_bo_list_add(&cmd
->bo_list
, set
->buffers
[j
],
3144 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
3147 if (set
->size
> 0) {
3148 tu_bo_list_add(&cmd
->bo_list
, &set
->pool
->bo
,
3149 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
3153 if (cmd
->state
.dirty
& TU_CMD_DIRTY_STREAMOUT_BUFFERS
) {
3154 for (unsigned i
= 0; i
< IR3_MAX_SO_BUFFERS
; i
++) {
3155 const struct tu_buffer
*buf
= cmd
->state
.streamout_buf
.buffers
[i
];
3157 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
,
3158 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
3163 /* There are too many graphics dirty bits to list here, so just list the
3164 * bits to preserve instead. The only things not emitted here are
3165 * compute-related state.
3167 cmd
->state
.dirty
&= TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
;
3169 /* Fragment shader state overwrites compute shader state, so flag the
3170 * compute pipeline for re-emit.
3172 cmd
->state
.dirty
|= TU_CMD_DIRTY_COMPUTE_PIPELINE
;
3177 tu6_emit_draw_indirect(struct tu_cmd_buffer
*cmd
,
3179 const struct tu_draw_info
*draw
)
3181 const enum pc_di_primtype primtype
= cmd
->state
.pipeline
->ia
.primtype
;
3182 bool has_gs
= cmd
->state
.pipeline
->active_stages
&
3183 VK_SHADER_STAGE_GEOMETRY_BIT
;
3186 A6XX_VFD_INDEX_OFFSET(draw
->vertex_offset
),
3187 A6XX_VFD_INSTANCE_START_OFFSET(draw
->first_instance
));
3189 if (draw
->indexed
) {
3190 const enum a4xx_index_size index_size
=
3191 tu6_index_size(cmd
->state
.index_type
);
3192 const uint32_t index_bytes
=
3193 (cmd
->state
.index_type
== VK_INDEX_TYPE_UINT32
) ? 4 : 2;
3194 const struct tu_buffer
*index_buf
= cmd
->state
.index_buffer
;
3195 unsigned max_indicies
=
3196 (index_buf
->size
- cmd
->state
.index_offset
) / index_bytes
;
3198 const uint32_t cp_draw_indx
=
3199 CP_DRAW_INDX_OFFSET_0_PRIM_TYPE(primtype
) |
3200 CP_DRAW_INDX_OFFSET_0_SOURCE_SELECT(DI_SRC_SEL_DMA
) |
3201 CP_DRAW_INDX_OFFSET_0_INDEX_SIZE(index_size
) |
3202 CP_DRAW_INDX_OFFSET_0_VIS_CULL(USE_VISIBILITY
) |
3203 COND(has_gs
, CP_DRAW_INDX_OFFSET_0_GS_ENABLE
) | 0x2000;
3205 tu_cs_emit_pkt7(cs
, CP_DRAW_INDX_INDIRECT
, 6);
3206 tu_cs_emit(cs
, cp_draw_indx
);
3207 tu_cs_emit_qw(cs
, index_buf
->bo
->iova
+ cmd
->state
.index_offset
);
3208 tu_cs_emit(cs
, A5XX_CP_DRAW_INDX_INDIRECT_3_MAX_INDICES(max_indicies
));
3209 tu_cs_emit_qw(cs
, draw
->indirect
->bo
->iova
+ draw
->indirect_offset
);
3211 const uint32_t cp_draw_indx
=
3212 CP_DRAW_INDX_OFFSET_0_PRIM_TYPE(primtype
) |
3213 CP_DRAW_INDX_OFFSET_0_SOURCE_SELECT(DI_SRC_SEL_AUTO_INDEX
) |
3214 CP_DRAW_INDX_OFFSET_0_VIS_CULL(USE_VISIBILITY
) |
3215 COND(has_gs
, CP_DRAW_INDX_OFFSET_0_GS_ENABLE
) | 0x2000;
3217 tu_cs_emit_pkt7(cs
, CP_DRAW_INDIRECT
, 3);
3218 tu_cs_emit(cs
, cp_draw_indx
);
3219 tu_cs_emit_qw(cs
, draw
->indirect
->bo
->iova
+ draw
->indirect_offset
);
3222 tu_bo_list_add(&cmd
->bo_list
, draw
->indirect
->bo
, MSM_SUBMIT_BO_READ
);
3226 tu6_emit_draw_direct(struct tu_cmd_buffer
*cmd
,
3228 const struct tu_draw_info
*draw
)
3231 const enum pc_di_primtype primtype
= cmd
->state
.pipeline
->ia
.primtype
;
3232 bool has_gs
= cmd
->state
.pipeline
->active_stages
&
3233 VK_SHADER_STAGE_GEOMETRY_BIT
;
3236 A6XX_VFD_INDEX_OFFSET(draw
->vertex_offset
),
3237 A6XX_VFD_INSTANCE_START_OFFSET(draw
->first_instance
));
3239 /* TODO hw binning */
3240 if (draw
->indexed
) {
3241 const enum a4xx_index_size index_size
=
3242 tu6_index_size(cmd
->state
.index_type
);
3243 const uint32_t index_bytes
=
3244 (cmd
->state
.index_type
== VK_INDEX_TYPE_UINT32
) ? 4 : 2;
3245 const struct tu_buffer
*buf
= cmd
->state
.index_buffer
;
3246 const VkDeviceSize offset
= buf
->bo_offset
+ cmd
->state
.index_offset
+
3247 index_bytes
* draw
->first_index
;
3248 const uint32_t size
= index_bytes
* draw
->count
;
3250 const uint32_t cp_draw_indx
=
3251 CP_DRAW_INDX_OFFSET_0_PRIM_TYPE(primtype
) |
3252 CP_DRAW_INDX_OFFSET_0_SOURCE_SELECT(DI_SRC_SEL_DMA
) |
3253 CP_DRAW_INDX_OFFSET_0_INDEX_SIZE(index_size
) |
3254 CP_DRAW_INDX_OFFSET_0_VIS_CULL(USE_VISIBILITY
) |
3255 COND(has_gs
, CP_DRAW_INDX_OFFSET_0_GS_ENABLE
) | 0x2000;
3257 tu_cs_emit_pkt7(cs
, CP_DRAW_INDX_OFFSET
, 7);
3258 tu_cs_emit(cs
, cp_draw_indx
);
3259 tu_cs_emit(cs
, draw
->instance_count
);
3260 tu_cs_emit(cs
, draw
->count
);
3261 tu_cs_emit(cs
, 0x0); /* XXX */
3262 tu_cs_emit_qw(cs
, buf
->bo
->iova
+ offset
);
3263 tu_cs_emit(cs
, size
);
3265 const uint32_t cp_draw_indx
=
3266 CP_DRAW_INDX_OFFSET_0_PRIM_TYPE(primtype
) |
3267 CP_DRAW_INDX_OFFSET_0_SOURCE_SELECT(DI_SRC_SEL_AUTO_INDEX
) |
3268 CP_DRAW_INDX_OFFSET_0_VIS_CULL(USE_VISIBILITY
) |
3269 COND(has_gs
, CP_DRAW_INDX_OFFSET_0_GS_ENABLE
) | 0x2000;
3271 tu_cs_emit_pkt7(cs
, CP_DRAW_INDX_OFFSET
, 3);
3272 tu_cs_emit(cs
, cp_draw_indx
);
3273 tu_cs_emit(cs
, draw
->instance_count
);
3274 tu_cs_emit(cs
, draw
->count
);
3279 tu_draw(struct tu_cmd_buffer
*cmd
, const struct tu_draw_info
*draw
)
3281 struct tu_cs
*cs
= &cmd
->draw_cs
;
3284 result
= tu6_bind_draw_states(cmd
, cs
, draw
);
3285 if (result
!= VK_SUCCESS
) {
3286 cmd
->record_result
= result
;
3291 tu6_emit_draw_indirect(cmd
, cs
, draw
);
3293 tu6_emit_draw_direct(cmd
, cs
, draw
);
3295 if (cmd
->state
.streamout_enabled
) {
3296 for (unsigned i
= 0; i
< IR3_MAX_SO_BUFFERS
; i
++) {
3297 if (cmd
->state
.streamout_enabled
& (1 << i
))
3298 tu6_emit_event_write(cmd
, cs
, FLUSH_SO_0
+ i
, false);
3302 cmd
->wait_for_idle
= true;
3304 tu_cs_sanity_check(cs
);
3308 tu_CmdDraw(VkCommandBuffer commandBuffer
,
3309 uint32_t vertexCount
,
3310 uint32_t instanceCount
,
3311 uint32_t firstVertex
,
3312 uint32_t firstInstance
)
3314 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3315 struct tu_draw_info info
= {};
3317 info
.count
= vertexCount
;
3318 info
.instance_count
= instanceCount
;
3319 info
.first_instance
= firstInstance
;
3320 info
.vertex_offset
= firstVertex
;
3322 tu_draw(cmd_buffer
, &info
);
3326 tu_CmdDrawIndexed(VkCommandBuffer commandBuffer
,
3327 uint32_t indexCount
,
3328 uint32_t instanceCount
,
3329 uint32_t firstIndex
,
3330 int32_t vertexOffset
,
3331 uint32_t firstInstance
)
3333 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3334 struct tu_draw_info info
= {};
3336 info
.indexed
= true;
3337 info
.count
= indexCount
;
3338 info
.instance_count
= instanceCount
;
3339 info
.first_index
= firstIndex
;
3340 info
.vertex_offset
= vertexOffset
;
3341 info
.first_instance
= firstInstance
;
3343 tu_draw(cmd_buffer
, &info
);
3347 tu_CmdDrawIndirect(VkCommandBuffer commandBuffer
,
3349 VkDeviceSize offset
,
3353 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3354 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
3355 struct tu_draw_info info
= {};
3357 info
.count
= drawCount
;
3358 info
.indirect
= buffer
;
3359 info
.indirect_offset
= offset
;
3360 info
.stride
= stride
;
3362 tu_draw(cmd_buffer
, &info
);
3366 tu_CmdDrawIndexedIndirect(VkCommandBuffer commandBuffer
,
3368 VkDeviceSize offset
,
3372 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3373 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
3374 struct tu_draw_info info
= {};
3376 info
.indexed
= true;
3377 info
.count
= drawCount
;
3378 info
.indirect
= buffer
;
3379 info
.indirect_offset
= offset
;
3380 info
.stride
= stride
;
3382 tu_draw(cmd_buffer
, &info
);
3385 void tu_CmdDrawIndirectByteCountEXT(VkCommandBuffer commandBuffer
,
3386 uint32_t instanceCount
,
3387 uint32_t firstInstance
,
3388 VkBuffer _counterBuffer
,
3389 VkDeviceSize counterBufferOffset
,
3390 uint32_t counterOffset
,
3391 uint32_t vertexStride
)
3393 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3394 TU_FROM_HANDLE(tu_buffer
, buffer
, _counterBuffer
);
3396 struct tu_draw_info info
= {};
3398 info
.instance_count
= instanceCount
;
3399 info
.first_instance
= firstInstance
;
3400 info
.streamout_buffer
= buffer
;
3401 info
.streamout_buffer_offset
= counterBufferOffset
;
3402 info
.stride
= vertexStride
;
3404 tu_draw(cmd_buffer
, &info
);
3407 struct tu_dispatch_info
3410 * Determine the layout of the grid (in block units) to be used.
3415 * A starting offset for the grid. If unaligned is set, the offset
3416 * must still be aligned.
3418 uint32_t offsets
[3];
3420 * Whether it's an unaligned compute dispatch.
3425 * Indirect compute parameters resource.
3427 struct tu_buffer
*indirect
;
3428 uint64_t indirect_offset
;
3432 tu_emit_compute_driver_params(struct tu_cs
*cs
, struct tu_pipeline
*pipeline
,
3433 const struct tu_dispatch_info
*info
)
3435 gl_shader_stage type
= MESA_SHADER_COMPUTE
;
3436 const struct tu_program_descriptor_linkage
*link
=
3437 &pipeline
->program
.link
[type
];
3438 const struct ir3_const_state
*const_state
= &link
->const_state
;
3439 uint32_t offset
= const_state
->offsets
.driver_param
;
3441 if (link
->constlen
<= offset
)
3444 if (!info
->indirect
) {
3445 uint32_t driver_params
[IR3_DP_CS_COUNT
] = {
3446 [IR3_DP_NUM_WORK_GROUPS_X
] = info
->blocks
[0],
3447 [IR3_DP_NUM_WORK_GROUPS_Y
] = info
->blocks
[1],
3448 [IR3_DP_NUM_WORK_GROUPS_Z
] = info
->blocks
[2],
3449 [IR3_DP_LOCAL_GROUP_SIZE_X
] = pipeline
->compute
.local_size
[0],
3450 [IR3_DP_LOCAL_GROUP_SIZE_Y
] = pipeline
->compute
.local_size
[1],
3451 [IR3_DP_LOCAL_GROUP_SIZE_Z
] = pipeline
->compute
.local_size
[2],
3454 uint32_t num_consts
= MIN2(const_state
->num_driver_params
,
3455 (link
->constlen
- offset
) * 4);
3456 /* push constants */
3457 tu_cs_emit_pkt7(cs
, tu6_stage2opcode(type
), 3 + num_consts
);
3458 tu_cs_emit(cs
, CP_LOAD_STATE6_0_DST_OFF(offset
) |
3459 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
3460 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
3461 CP_LOAD_STATE6_0_STATE_BLOCK(tu6_stage2shadersb(type
)) |
3462 CP_LOAD_STATE6_0_NUM_UNIT(num_consts
/ 4));
3466 for (i
= 0; i
< num_consts
; i
++)
3467 tu_cs_emit(cs
, driver_params
[i
]);
3469 tu_finishme("Indirect driver params");
3474 tu_dispatch(struct tu_cmd_buffer
*cmd
,
3475 const struct tu_dispatch_info
*info
)
3477 struct tu_cs
*cs
= &cmd
->cs
;
3478 struct tu_pipeline
*pipeline
= cmd
->state
.compute_pipeline
;
3479 struct tu_descriptor_state
*descriptors_state
=
3480 &cmd
->descriptors
[VK_PIPELINE_BIND_POINT_COMPUTE
];
3483 if (cmd
->state
.dirty
& TU_CMD_DIRTY_COMPUTE_PIPELINE
)
3484 tu_cs_emit_ib(cs
, &pipeline
->program
.state_ib
);
3486 struct tu_cs_entry ib
;
3488 ib
= tu6_emit_consts(cmd
, pipeline
, descriptors_state
, MESA_SHADER_COMPUTE
);
3490 tu_cs_emit_ib(cs
, &ib
);
3492 tu_emit_compute_driver_params(cs
, pipeline
, info
);
3494 if (cmd
->state
.dirty
& TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
) {
3495 result
= tu6_emit_descriptor_sets(cmd
, pipeline
,
3496 VK_PIPELINE_BIND_POINT_COMPUTE
, &ib
,
3498 if (result
!= VK_SUCCESS
) {
3499 cmd
->record_result
= result
;
3505 for_each_bit(i
, descriptors_state
->valid
) {
3506 struct tu_descriptor_set
*set
= descriptors_state
->sets
[i
];
3507 for (unsigned j
= 0; j
< set
->layout
->buffer_count
; ++j
) {
3508 if (set
->buffers
[j
]) {
3509 tu_bo_list_add(&cmd
->bo_list
, set
->buffers
[j
],
3510 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
3514 if (set
->size
> 0) {
3515 tu_bo_list_add(&cmd
->bo_list
, &set
->pool
->bo
,
3516 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
3522 tu_cs_emit_ib(cs
, &ib
);
3524 if (cmd
->state
.dirty
& TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
)
3525 tu_cs_emit_ib(cs
, &pipeline
->load_state
.state_ib
);
3528 ~(TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
| TU_CMD_DIRTY_COMPUTE_PIPELINE
);
3530 /* Compute shader state overwrites fragment shader state, so we flag the
3531 * graphics pipeline for re-emit.
3533 cmd
->state
.dirty
|= TU_CMD_DIRTY_PIPELINE
;
3535 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
3536 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_COMPUTE
));
3538 const uint32_t *local_size
= pipeline
->compute
.local_size
;
3539 const uint32_t *num_groups
= info
->blocks
;
3541 A6XX_HLSQ_CS_NDRANGE_0(.kerneldim
= 3,
3542 .localsizex
= local_size
[0] - 1,
3543 .localsizey
= local_size
[1] - 1,
3544 .localsizez
= local_size
[2] - 1),
3545 A6XX_HLSQ_CS_NDRANGE_1(.globalsize_x
= local_size
[0] * num_groups
[0]),
3546 A6XX_HLSQ_CS_NDRANGE_2(.globaloff_x
= 0),
3547 A6XX_HLSQ_CS_NDRANGE_3(.globalsize_y
= local_size
[1] * num_groups
[1]),
3548 A6XX_HLSQ_CS_NDRANGE_4(.globaloff_y
= 0),
3549 A6XX_HLSQ_CS_NDRANGE_5(.globalsize_z
= local_size
[2] * num_groups
[2]),
3550 A6XX_HLSQ_CS_NDRANGE_6(.globaloff_z
= 0));
3553 A6XX_HLSQ_CS_KERNEL_GROUP_X(1),
3554 A6XX_HLSQ_CS_KERNEL_GROUP_Y(1),
3555 A6XX_HLSQ_CS_KERNEL_GROUP_Z(1));
3557 if (info
->indirect
) {
3558 uint64_t iova
= tu_buffer_iova(info
->indirect
) + info
->indirect_offset
;
3560 tu_bo_list_add(&cmd
->bo_list
, info
->indirect
->bo
,
3561 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
3563 tu_cs_emit_pkt7(cs
, CP_EXEC_CS_INDIRECT
, 4);
3564 tu_cs_emit(cs
, 0x00000000);
3565 tu_cs_emit_qw(cs
, iova
);
3567 A5XX_CP_EXEC_CS_INDIRECT_3_LOCALSIZEX(local_size
[0] - 1) |
3568 A5XX_CP_EXEC_CS_INDIRECT_3_LOCALSIZEY(local_size
[1] - 1) |
3569 A5XX_CP_EXEC_CS_INDIRECT_3_LOCALSIZEZ(local_size
[2] - 1));
3571 tu_cs_emit_pkt7(cs
, CP_EXEC_CS
, 4);
3572 tu_cs_emit(cs
, 0x00000000);
3573 tu_cs_emit(cs
, CP_EXEC_CS_1_NGROUPS_X(info
->blocks
[0]));
3574 tu_cs_emit(cs
, CP_EXEC_CS_2_NGROUPS_Y(info
->blocks
[1]));
3575 tu_cs_emit(cs
, CP_EXEC_CS_3_NGROUPS_Z(info
->blocks
[2]));
3580 tu6_emit_cache_flush(cmd
, cs
);
3584 tu_CmdDispatchBase(VkCommandBuffer commandBuffer
,
3592 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3593 struct tu_dispatch_info info
= {};
3599 info
.offsets
[0] = base_x
;
3600 info
.offsets
[1] = base_y
;
3601 info
.offsets
[2] = base_z
;
3602 tu_dispatch(cmd_buffer
, &info
);
3606 tu_CmdDispatch(VkCommandBuffer commandBuffer
,
3611 tu_CmdDispatchBase(commandBuffer
, 0, 0, 0, x
, y
, z
);
3615 tu_CmdDispatchIndirect(VkCommandBuffer commandBuffer
,
3617 VkDeviceSize offset
)
3619 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3620 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
3621 struct tu_dispatch_info info
= {};
3623 info
.indirect
= buffer
;
3624 info
.indirect_offset
= offset
;
3626 tu_dispatch(cmd_buffer
, &info
);
3630 tu_CmdEndRenderPass(VkCommandBuffer commandBuffer
)
3632 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3634 tu_cs_end(&cmd_buffer
->draw_cs
);
3635 tu_cs_end(&cmd_buffer
->draw_epilogue_cs
);
3637 if (use_sysmem_rendering(cmd_buffer
))
3638 tu_cmd_render_sysmem(cmd_buffer
);
3640 tu_cmd_render_tiles(cmd_buffer
);
3642 /* discard draw_cs and draw_epilogue_cs entries now that the tiles are
3644 tu_cs_discard_entries(&cmd_buffer
->draw_cs
);
3645 tu_cs_begin(&cmd_buffer
->draw_cs
);
3646 tu_cs_discard_entries(&cmd_buffer
->draw_epilogue_cs
);
3647 tu_cs_begin(&cmd_buffer
->draw_epilogue_cs
);
3649 cmd_buffer
->state
.pass
= NULL
;
3650 cmd_buffer
->state
.subpass
= NULL
;
3651 cmd_buffer
->state
.framebuffer
= NULL
;
3655 tu_CmdEndRenderPass2(VkCommandBuffer commandBuffer
,
3656 const VkSubpassEndInfoKHR
*pSubpassEndInfo
)
3658 tu_CmdEndRenderPass(commandBuffer
);
3661 struct tu_barrier_info
3663 uint32_t eventCount
;
3664 const VkEvent
*pEvents
;
3665 VkPipelineStageFlags srcStageMask
;
3669 tu_barrier(struct tu_cmd_buffer
*cmd
,
3670 uint32_t memoryBarrierCount
,
3671 const VkMemoryBarrier
*pMemoryBarriers
,
3672 uint32_t bufferMemoryBarrierCount
,
3673 const VkBufferMemoryBarrier
*pBufferMemoryBarriers
,
3674 uint32_t imageMemoryBarrierCount
,
3675 const VkImageMemoryBarrier
*pImageMemoryBarriers
,
3676 const struct tu_barrier_info
*info
)
3678 /* renderpass case is only for subpass self-dependencies
3679 * which means syncing the render output with texture cache
3680 * note: only the CACHE_INVALIDATE is needed in GMEM mode
3681 * and in sysmem mode we might not need either color/depth flush
3683 if (cmd
->state
.pass
) {
3684 tu6_emit_event_write(cmd
, &cmd
->draw_cs
, PC_CCU_FLUSH_COLOR_TS
, true);
3685 tu6_emit_event_write(cmd
, &cmd
->draw_cs
, PC_CCU_FLUSH_DEPTH_TS
, true);
3686 tu6_emit_event_write(cmd
, &cmd
->draw_cs
, CACHE_INVALIDATE
, false);
3692 tu_CmdPipelineBarrier(VkCommandBuffer commandBuffer
,
3693 VkPipelineStageFlags srcStageMask
,
3694 VkPipelineStageFlags dstStageMask
,
3695 VkDependencyFlags dependencyFlags
,
3696 uint32_t memoryBarrierCount
,
3697 const VkMemoryBarrier
*pMemoryBarriers
,
3698 uint32_t bufferMemoryBarrierCount
,
3699 const VkBufferMemoryBarrier
*pBufferMemoryBarriers
,
3700 uint32_t imageMemoryBarrierCount
,
3701 const VkImageMemoryBarrier
*pImageMemoryBarriers
)
3703 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3704 struct tu_barrier_info info
;
3706 info
.eventCount
= 0;
3707 info
.pEvents
= NULL
;
3708 info
.srcStageMask
= srcStageMask
;
3710 tu_barrier(cmd_buffer
, memoryBarrierCount
, pMemoryBarriers
,
3711 bufferMemoryBarrierCount
, pBufferMemoryBarriers
,
3712 imageMemoryBarrierCount
, pImageMemoryBarriers
, &info
);
3716 write_event(struct tu_cmd_buffer
*cmd
, struct tu_event
*event
, unsigned value
)
3718 struct tu_cs
*cs
= &cmd
->cs
;
3720 tu_bo_list_add(&cmd
->bo_list
, &event
->bo
, MSM_SUBMIT_BO_WRITE
);
3722 /* TODO: any flush required before/after ? */
3724 tu_cs_emit_pkt7(cs
, CP_MEM_WRITE
, 3);
3725 tu_cs_emit_qw(cs
, event
->bo
.iova
); /* ADDR_LO/HI */
3726 tu_cs_emit(cs
, value
);
3730 tu_CmdSetEvent(VkCommandBuffer commandBuffer
,
3732 VkPipelineStageFlags stageMask
)
3734 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3735 TU_FROM_HANDLE(tu_event
, event
, _event
);
3737 write_event(cmd
, event
, 1);
3741 tu_CmdResetEvent(VkCommandBuffer commandBuffer
,
3743 VkPipelineStageFlags stageMask
)
3745 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3746 TU_FROM_HANDLE(tu_event
, event
, _event
);
3748 write_event(cmd
, event
, 0);
3752 tu_CmdWaitEvents(VkCommandBuffer commandBuffer
,
3753 uint32_t eventCount
,
3754 const VkEvent
*pEvents
,
3755 VkPipelineStageFlags srcStageMask
,
3756 VkPipelineStageFlags dstStageMask
,
3757 uint32_t memoryBarrierCount
,
3758 const VkMemoryBarrier
*pMemoryBarriers
,
3759 uint32_t bufferMemoryBarrierCount
,
3760 const VkBufferMemoryBarrier
*pBufferMemoryBarriers
,
3761 uint32_t imageMemoryBarrierCount
,
3762 const VkImageMemoryBarrier
*pImageMemoryBarriers
)
3764 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3765 struct tu_cs
*cs
= &cmd
->cs
;
3767 /* TODO: any flush required before/after? (CP_WAIT_FOR_ME?) */
3769 for (uint32_t i
= 0; i
< eventCount
; i
++) {
3770 TU_FROM_HANDLE(tu_event
, event
, pEvents
[i
]);
3772 tu_bo_list_add(&cmd
->bo_list
, &event
->bo
, MSM_SUBMIT_BO_READ
);
3774 tu_cs_emit_pkt7(cs
, CP_WAIT_REG_MEM
, 6);
3775 tu_cs_emit(cs
, CP_WAIT_REG_MEM_0_FUNCTION(WRITE_EQ
) |
3776 CP_WAIT_REG_MEM_0_POLL_MEMORY
);
3777 tu_cs_emit_qw(cs
, event
->bo
.iova
); /* POLL_ADDR_LO/HI */
3778 tu_cs_emit(cs
, CP_WAIT_REG_MEM_3_REF(1));
3779 tu_cs_emit(cs
, CP_WAIT_REG_MEM_4_MASK(~0u));
3780 tu_cs_emit(cs
, CP_WAIT_REG_MEM_5_DELAY_LOOP_CYCLES(20));
3785 tu_CmdSetDeviceMask(VkCommandBuffer commandBuffer
, uint32_t deviceMask
)