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
,
118 const uint32_t tile_align_w
= 64; /* note: 32 when no input attachments */
119 const uint32_t tile_align_h
= 16;
120 const uint32_t max_tile_width
= 1024;
122 /* note: don't offset the tiling config by render_area.offset,
123 * because binning pass can't deal with it
124 * this means we might end up with more tiles than necessary,
125 * but load/store/etc are still scissored to the render_area
127 tiling
->tile0
.offset
= (VkOffset2D
) {};
129 const uint32_t ra_width
=
130 tiling
->render_area
.extent
.width
+
131 (tiling
->render_area
.offset
.x
- tiling
->tile0
.offset
.x
);
132 const uint32_t ra_height
=
133 tiling
->render_area
.extent
.height
+
134 (tiling
->render_area
.offset
.y
- tiling
->tile0
.offset
.y
);
136 /* start from 1 tile */
137 tiling
->tile_count
= (VkExtent2D
) {
141 tiling
->tile0
.extent
= (VkExtent2D
) {
142 .width
= align(ra_width
, tile_align_w
),
143 .height
= align(ra_height
, tile_align_h
),
146 if (unlikely(dev
->physical_device
->instance
->debug_flags
& TU_DEBUG_FORCEBIN
)) {
147 /* start with 2x2 tiles */
148 tiling
->tile_count
.width
= 2;
149 tiling
->tile_count
.height
= 2;
150 tiling
->tile0
.extent
.width
= align(DIV_ROUND_UP(ra_width
, 2), tile_align_w
);
151 tiling
->tile0
.extent
.height
= align(DIV_ROUND_UP(ra_height
, 2), tile_align_h
);
154 /* do not exceed max tile width */
155 while (tiling
->tile0
.extent
.width
> max_tile_width
) {
156 tiling
->tile_count
.width
++;
157 tiling
->tile0
.extent
.width
=
158 align(DIV_ROUND_UP(ra_width
, tiling
->tile_count
.width
), tile_align_w
);
161 /* will force to sysmem, don't bother trying to have a valid tile config
162 * TODO: just skip all GMEM stuff when sysmem is forced?
167 /* do not exceed gmem size */
168 while (tiling
->tile0
.extent
.width
* tiling
->tile0
.extent
.height
> pixels
) {
169 if (tiling
->tile0
.extent
.width
> MAX2(tile_align_w
, tiling
->tile0
.extent
.height
)) {
170 tiling
->tile_count
.width
++;
171 tiling
->tile0
.extent
.width
=
172 align(DIV_ROUND_UP(ra_width
, tiling
->tile_count
.width
), tile_align_w
);
174 /* if this assert fails then layout is impossible.. */
175 assert(tiling
->tile0
.extent
.height
> tile_align_h
);
176 tiling
->tile_count
.height
++;
177 tiling
->tile0
.extent
.height
=
178 align(DIV_ROUND_UP(ra_height
, tiling
->tile_count
.height
), tile_align_h
);
184 tu_tiling_config_update_pipe_layout(struct tu_tiling_config
*tiling
,
185 const struct tu_device
*dev
)
187 const uint32_t max_pipe_count
= 32; /* A6xx */
189 /* start from 1 tile per pipe */
190 tiling
->pipe0
= (VkExtent2D
) {
194 tiling
->pipe_count
= tiling
->tile_count
;
196 while (tiling
->pipe_count
.width
* tiling
->pipe_count
.height
> max_pipe_count
) {
197 if (tiling
->pipe0
.width
< tiling
->pipe0
.height
) {
198 tiling
->pipe0
.width
+= 1;
199 tiling
->pipe_count
.width
=
200 DIV_ROUND_UP(tiling
->tile_count
.width
, tiling
->pipe0
.width
);
202 tiling
->pipe0
.height
+= 1;
203 tiling
->pipe_count
.height
=
204 DIV_ROUND_UP(tiling
->tile_count
.height
, tiling
->pipe0
.height
);
210 tu_tiling_config_update_pipes(struct tu_tiling_config
*tiling
,
211 const struct tu_device
*dev
)
213 const uint32_t max_pipe_count
= 32; /* A6xx */
214 const uint32_t used_pipe_count
=
215 tiling
->pipe_count
.width
* tiling
->pipe_count
.height
;
216 const VkExtent2D last_pipe
= {
217 .width
= (tiling
->tile_count
.width
- 1) % tiling
->pipe0
.width
+ 1,
218 .height
= (tiling
->tile_count
.height
- 1) % tiling
->pipe0
.height
+ 1,
221 assert(used_pipe_count
<= max_pipe_count
);
222 assert(max_pipe_count
<= ARRAY_SIZE(tiling
->pipe_config
));
224 for (uint32_t y
= 0; y
< tiling
->pipe_count
.height
; y
++) {
225 for (uint32_t x
= 0; x
< tiling
->pipe_count
.width
; x
++) {
226 const uint32_t pipe_x
= tiling
->pipe0
.width
* x
;
227 const uint32_t pipe_y
= tiling
->pipe0
.height
* y
;
228 const uint32_t pipe_w
= (x
== tiling
->pipe_count
.width
- 1)
230 : tiling
->pipe0
.width
;
231 const uint32_t pipe_h
= (y
== tiling
->pipe_count
.height
- 1)
233 : tiling
->pipe0
.height
;
234 const uint32_t n
= tiling
->pipe_count
.width
* y
+ x
;
236 tiling
->pipe_config
[n
] = A6XX_VSC_PIPE_CONFIG_REG_X(pipe_x
) |
237 A6XX_VSC_PIPE_CONFIG_REG_Y(pipe_y
) |
238 A6XX_VSC_PIPE_CONFIG_REG_W(pipe_w
) |
239 A6XX_VSC_PIPE_CONFIG_REG_H(pipe_h
);
240 tiling
->pipe_sizes
[n
] = CP_SET_BIN_DATA5_0_VSC_SIZE(pipe_w
* pipe_h
);
244 memset(tiling
->pipe_config
+ used_pipe_count
, 0,
245 sizeof(uint32_t) * (max_pipe_count
- used_pipe_count
));
249 tu_tiling_config_get_tile(const struct tu_tiling_config
*tiling
,
250 const struct tu_device
*dev
,
253 struct tu_tile
*tile
)
255 /* find the pipe and the slot for tile (tx, ty) */
256 const uint32_t px
= tx
/ tiling
->pipe0
.width
;
257 const uint32_t py
= ty
/ tiling
->pipe0
.height
;
258 const uint32_t sx
= tx
- tiling
->pipe0
.width
* px
;
259 const uint32_t sy
= ty
- tiling
->pipe0
.height
* py
;
260 /* last pipe has different width */
261 const uint32_t pipe_width
=
262 MIN2(tiling
->pipe0
.width
,
263 tiling
->tile_count
.width
- px
* tiling
->pipe0
.width
);
265 assert(tx
< tiling
->tile_count
.width
&& ty
< tiling
->tile_count
.height
);
266 assert(px
< tiling
->pipe_count
.width
&& py
< tiling
->pipe_count
.height
);
267 assert(sx
< tiling
->pipe0
.width
&& sy
< tiling
->pipe0
.height
);
269 /* convert to 1D indices */
270 tile
->pipe
= tiling
->pipe_count
.width
* py
+ px
;
271 tile
->slot
= pipe_width
* sy
+ sx
;
273 /* get the blit area for the tile */
274 tile
->begin
= (VkOffset2D
) {
275 .x
= tiling
->tile0
.offset
.x
+ tiling
->tile0
.extent
.width
* tx
,
276 .y
= tiling
->tile0
.offset
.y
+ tiling
->tile0
.extent
.height
* ty
,
279 (tx
== tiling
->tile_count
.width
- 1)
280 ? tiling
->render_area
.offset
.x
+ tiling
->render_area
.extent
.width
281 : tile
->begin
.x
+ tiling
->tile0
.extent
.width
;
283 (ty
== tiling
->tile_count
.height
- 1)
284 ? tiling
->render_area
.offset
.y
+ tiling
->render_area
.extent
.height
285 : tile
->begin
.y
+ tiling
->tile0
.extent
.height
;
288 enum a3xx_msaa_samples
289 tu_msaa_samples(uint32_t samples
)
301 assert(!"invalid sample count");
306 static enum a4xx_index_size
307 tu6_index_size(VkIndexType type
)
310 case VK_INDEX_TYPE_UINT16
:
311 return INDEX4_SIZE_16_BIT
;
312 case VK_INDEX_TYPE_UINT32
:
313 return INDEX4_SIZE_32_BIT
;
315 unreachable("invalid VkIndexType");
316 return INDEX4_SIZE_8_BIT
;
321 tu6_emit_event_write(struct tu_cmd_buffer
*cmd
,
323 enum vgt_event_type event
,
328 tu_cs_emit_pkt7(cs
, CP_EVENT_WRITE
, need_seqno
? 4 : 1);
329 tu_cs_emit(cs
, CP_EVENT_WRITE_0_EVENT(event
));
331 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
);
332 seqno
= ++cmd
->scratch_seqno
;
333 tu_cs_emit(cs
, seqno
);
340 tu6_emit_cache_flush(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
342 tu6_emit_event_write(cmd
, cs
, 0x31, false);
346 tu6_emit_lrz_flush(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
348 tu6_emit_event_write(cmd
, cs
, LRZ_FLUSH
, false);
352 tu6_emit_wfi(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
354 if (cmd
->wait_for_idle
) {
356 cmd
->wait_for_idle
= false;
361 tu6_emit_zs(struct tu_cmd_buffer
*cmd
,
362 const struct tu_subpass
*subpass
,
365 const struct tu_framebuffer
*fb
= cmd
->state
.framebuffer
;
367 const uint32_t a
= subpass
->depth_stencil_attachment
.attachment
;
368 if (a
== VK_ATTACHMENT_UNUSED
) {
370 A6XX_RB_DEPTH_BUFFER_INFO(.depth_format
= DEPTH6_NONE
),
371 A6XX_RB_DEPTH_BUFFER_PITCH(0),
372 A6XX_RB_DEPTH_BUFFER_ARRAY_PITCH(0),
373 A6XX_RB_DEPTH_BUFFER_BASE(0),
374 A6XX_RB_DEPTH_BUFFER_BASE_GMEM(0));
377 A6XX_GRAS_SU_DEPTH_BUFFER_INFO(.depth_format
= DEPTH6_NONE
));
380 A6XX_GRAS_LRZ_BUFFER_BASE(0),
381 A6XX_GRAS_LRZ_BUFFER_PITCH(0),
382 A6XX_GRAS_LRZ_FAST_CLEAR_BUFFER_BASE(0));
384 tu_cs_emit_regs(cs
, A6XX_RB_STENCIL_INFO(0));
389 const struct tu_image_view
*iview
= fb
->attachments
[a
].attachment
;
390 enum a6xx_depth_format fmt
= tu6_pipe2depth(iview
->vk_format
);
393 A6XX_RB_DEPTH_BUFFER_INFO(.depth_format
= fmt
),
394 A6XX_RB_DEPTH_BUFFER_PITCH(tu_image_stride(iview
->image
, iview
->base_mip
)),
395 A6XX_RB_DEPTH_BUFFER_ARRAY_PITCH(iview
->image
->layout
.layer_size
),
396 A6XX_RB_DEPTH_BUFFER_BASE(tu_image_view_base_ref(iview
)),
397 A6XX_RB_DEPTH_BUFFER_BASE_GMEM(cmd
->state
.pass
->attachments
[a
].gmem_offset
));
400 A6XX_GRAS_SU_DEPTH_BUFFER_INFO(.depth_format
= fmt
));
403 A6XX_RB_DEPTH_FLAG_BUFFER_BASE(tu_image_view_ubwc_base_ref(iview
)),
404 A6XX_RB_DEPTH_FLAG_BUFFER_PITCH(tu_image_view_ubwc_pitches(iview
)));
407 A6XX_GRAS_LRZ_BUFFER_BASE(0),
408 A6XX_GRAS_LRZ_BUFFER_PITCH(0),
409 A6XX_GRAS_LRZ_FAST_CLEAR_BUFFER_BASE(0));
412 A6XX_RB_STENCIL_INFO(0));
418 tu6_emit_mrt(struct tu_cmd_buffer
*cmd
,
419 const struct tu_subpass
*subpass
,
422 const struct tu_framebuffer
*fb
= cmd
->state
.framebuffer
;
423 unsigned char mrt_comp
[MAX_RTS
] = { 0 };
424 unsigned srgb_cntl
= 0;
426 for (uint32_t i
= 0; i
< subpass
->color_count
; ++i
) {
427 uint32_t a
= subpass
->color_attachments
[i
].attachment
;
428 if (a
== VK_ATTACHMENT_UNUSED
)
431 const struct tu_image_view
*iview
= fb
->attachments
[a
].attachment
;
435 if (vk_format_is_srgb(iview
->vk_format
))
436 srgb_cntl
|= (1 << i
);
438 struct tu_native_format format
=
439 tu6_format_image(iview
->image
, iview
->vk_format
, iview
->base_mip
);
442 A6XX_RB_MRT_BUF_INFO(i
,
443 .color_tile_mode
= format
.tile_mode
,
444 .color_format
= format
.fmt
,
445 .color_swap
= format
.swap
),
446 A6XX_RB_MRT_PITCH(i
, tu_image_stride(iview
->image
, iview
->base_mip
)),
447 A6XX_RB_MRT_ARRAY_PITCH(i
, iview
->image
->layout
.layer_size
),
448 A6XX_RB_MRT_BASE(i
, tu_image_view_base_ref(iview
)),
449 A6XX_RB_MRT_BASE_GMEM(i
, cmd
->state
.pass
->attachments
[a
].gmem_offset
));
452 A6XX_SP_FS_MRT_REG(i
,
453 .color_format
= format
.fmt
,
454 .color_sint
= vk_format_is_sint(iview
->vk_format
),
455 .color_uint
= vk_format_is_uint(iview
->vk_format
)));
458 A6XX_RB_MRT_FLAG_BUFFER_ADDR(i
, tu_image_view_ubwc_base_ref(iview
)),
459 A6XX_RB_MRT_FLAG_BUFFER_PITCH(i
, tu_image_view_ubwc_pitches(iview
)));
463 A6XX_RB_SRGB_CNTL(.dword
= srgb_cntl
));
466 A6XX_SP_SRGB_CNTL(.dword
= srgb_cntl
));
469 A6XX_RB_RENDER_COMPONENTS(
477 .rt7
= mrt_comp
[7]));
480 A6XX_SP_FS_RENDER_COMPONENTS(
488 .rt7
= mrt_comp
[7]));
490 // XXX: We probably can't hardcode LAYER_CNTL_TYPE.
492 A6XX_GRAS_LAYER_CNTL(.layered
= fb
->layers
> 1,
493 .type
= LAYER_2D_ARRAY
));
497 tu6_emit_msaa(struct tu_cs
*cs
, VkSampleCountFlagBits vk_samples
)
499 const enum a3xx_msaa_samples samples
= tu_msaa_samples(vk_samples
);
500 bool msaa_disable
= samples
== MSAA_ONE
;
503 A6XX_SP_TP_RAS_MSAA_CNTL(samples
),
504 A6XX_SP_TP_DEST_MSAA_CNTL(.samples
= samples
,
505 .msaa_disable
= msaa_disable
));
508 A6XX_GRAS_RAS_MSAA_CNTL(samples
),
509 A6XX_GRAS_DEST_MSAA_CNTL(.samples
= samples
,
510 .msaa_disable
= msaa_disable
));
513 A6XX_RB_RAS_MSAA_CNTL(samples
),
514 A6XX_RB_DEST_MSAA_CNTL(.samples
= samples
,
515 .msaa_disable
= msaa_disable
));
518 A6XX_RB_MSAA_CNTL(samples
));
522 tu6_emit_bin_size(struct tu_cs
*cs
,
523 uint32_t bin_w
, uint32_t bin_h
, uint32_t flags
)
526 A6XX_GRAS_BIN_CONTROL(.binw
= bin_w
,
531 A6XX_RB_BIN_CONTROL(.binw
= bin_w
,
535 /* no flag for RB_BIN_CONTROL2... */
537 A6XX_RB_BIN_CONTROL2(.binw
= bin_w
,
542 tu6_emit_render_cntl(struct tu_cmd_buffer
*cmd
,
543 const struct tu_subpass
*subpass
,
547 const struct tu_framebuffer
*fb
= cmd
->state
.framebuffer
;
549 cntl
|= A6XX_RB_RENDER_CNTL_UNK4
;
551 cntl
|= A6XX_RB_RENDER_CNTL_BINNING
;
553 uint32_t mrts_ubwc_enable
= 0;
554 for (uint32_t i
= 0; i
< subpass
->color_count
; ++i
) {
555 uint32_t a
= subpass
->color_attachments
[i
].attachment
;
556 if (a
== VK_ATTACHMENT_UNUSED
)
559 const struct tu_image_view
*iview
= fb
->attachments
[a
].attachment
;
560 if (iview
->image
->layout
.ubwc_layer_size
!= 0)
561 mrts_ubwc_enable
|= 1 << i
;
564 cntl
|= A6XX_RB_RENDER_CNTL_FLAG_MRTS(mrts_ubwc_enable
);
566 const uint32_t a
= subpass
->depth_stencil_attachment
.attachment
;
567 if (a
!= VK_ATTACHMENT_UNUSED
) {
568 const struct tu_image_view
*iview
= fb
->attachments
[a
].attachment
;
569 if (iview
->image
->layout
.ubwc_layer_size
!= 0)
570 cntl
|= A6XX_RB_RENDER_CNTL_FLAG_DEPTH
;
573 /* In the !binning case, we need to set RB_RENDER_CNTL in the draw_cs
574 * in order to set it correctly for the different subpasses. However,
575 * that means the packets we're emitting also happen during binning. So
576 * we need to guard the write on !BINNING at CP execution time.
578 tu_cs_reserve(cs
, 3 + 4);
579 tu_cs_emit_pkt7(cs
, CP_COND_REG_EXEC
, 2);
580 tu_cs_emit(cs
, CP_COND_REG_EXEC_0_MODE(RENDER_MODE
) |
581 CP_COND_REG_EXEC_0_GMEM
| CP_COND_REG_EXEC_0_SYSMEM
);
582 tu_cs_emit(cs
, CP_COND_REG_EXEC_1_DWORDS(4));
585 tu_cs_emit_pkt7(cs
, CP_REG_WRITE
, 3);
586 tu_cs_emit(cs
, CP_REG_WRITE_0_TRACKER(TRACK_RENDER_CNTL
));
587 tu_cs_emit(cs
, REG_A6XX_RB_RENDER_CNTL
);
588 tu_cs_emit(cs
, cntl
);
592 tu6_emit_blit_scissor(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
, bool align
)
594 const VkRect2D
*render_area
= &cmd
->state
.tiling_config
.render_area
;
595 uint32_t x1
= render_area
->offset
.x
;
596 uint32_t y1
= render_area
->offset
.y
;
597 uint32_t x2
= x1
+ render_area
->extent
.width
- 1;
598 uint32_t y2
= y1
+ render_area
->extent
.height
- 1;
601 x1
= x1
& ~(GMEM_ALIGN_W
- 1);
602 y1
= y1
& ~(GMEM_ALIGN_H
- 1);
603 x2
= ALIGN_POT(x2
+ 1, GMEM_ALIGN_W
) - 1;
604 y2
= ALIGN_POT(y2
+ 1, GMEM_ALIGN_H
) - 1;
608 A6XX_RB_BLIT_SCISSOR_TL(.x
= x1
, .y
= y1
),
609 A6XX_RB_BLIT_SCISSOR_BR(.x
= x2
, .y
= y2
));
613 tu6_emit_window_scissor(struct tu_cs
*cs
,
620 A6XX_GRAS_SC_WINDOW_SCISSOR_TL(.x
= x1
, .y
= y1
),
621 A6XX_GRAS_SC_WINDOW_SCISSOR_BR(.x
= x2
, .y
= y2
));
624 A6XX_GRAS_RESOLVE_CNTL_1(.x
= x1
, .y
= y1
),
625 A6XX_GRAS_RESOLVE_CNTL_2(.x
= x2
, .y
= y2
));
629 tu6_emit_window_offset(struct tu_cs
*cs
, uint32_t x1
, uint32_t y1
)
632 A6XX_RB_WINDOW_OFFSET(.x
= x1
, .y
= y1
));
635 A6XX_RB_WINDOW_OFFSET2(.x
= x1
, .y
= y1
));
638 A6XX_SP_WINDOW_OFFSET(.x
= x1
, .y
= y1
));
641 A6XX_SP_TP_WINDOW_OFFSET(.x
= x1
, .y
= y1
));
645 use_hw_binning(struct tu_cmd_buffer
*cmd
)
647 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
649 if (unlikely(cmd
->device
->physical_device
->instance
->debug_flags
& TU_DEBUG_NOBIN
))
652 if (unlikely(cmd
->device
->physical_device
->instance
->debug_flags
& TU_DEBUG_FORCEBIN
))
655 return (tiling
->tile_count
.width
* tiling
->tile_count
.height
) > 2;
659 use_sysmem_rendering(struct tu_cmd_buffer
*cmd
)
661 if (unlikely(cmd
->device
->physical_device
->instance
->debug_flags
& TU_DEBUG_SYSMEM
))
664 /* can't fit attachments into gmem */
665 if (!cmd
->state
.pass
->gmem_pixels
)
668 if (cmd
->state
.framebuffer
->layers
> 1)
671 return cmd
->state
.tiling_config
.force_sysmem
;
675 tu6_emit_tile_select(struct tu_cmd_buffer
*cmd
,
677 const struct tu_tile
*tile
)
679 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
680 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_YIELD
));
682 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
683 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_GMEM
));
685 const uint32_t x1
= tile
->begin
.x
;
686 const uint32_t y1
= tile
->begin
.y
;
687 const uint32_t x2
= tile
->end
.x
- 1;
688 const uint32_t y2
= tile
->end
.y
- 1;
689 tu6_emit_window_scissor(cs
, x1
, y1
, x2
, y2
);
690 tu6_emit_window_offset(cs
, x1
, y1
);
693 A6XX_VPC_SO_OVERRIDE(.so_disable
= false));
695 if (use_hw_binning(cmd
)) {
696 tu_cs_emit_pkt7(cs
, CP_WAIT_FOR_ME
, 0);
698 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
701 tu_cs_emit_pkt7(cs
, CP_REG_TEST
, 1);
702 tu_cs_emit(cs
, A6XX_CP_REG_TEST_0_REG(OVERFLOW_FLAG_REG
) |
703 A6XX_CP_REG_TEST_0_BIT(0) |
704 A6XX_CP_REG_TEST_0_WAIT_FOR_ME
);
706 tu_cs_reserve(cs
, 3 + 11);
707 tu_cs_emit_pkt7(cs
, CP_COND_REG_EXEC
, 2);
708 tu_cs_emit(cs
, CP_COND_REG_EXEC_0_MODE(PRED_TEST
));
709 tu_cs_emit(cs
, CP_COND_REG_EXEC_1_DWORDS(11));
711 /* if (no overflow) */ {
712 tu_cs_emit_pkt7(cs
, CP_SET_BIN_DATA5
, 7);
713 tu_cs_emit(cs
, cmd
->state
.tiling_config
.pipe_sizes
[tile
->pipe
] |
714 CP_SET_BIN_DATA5_0_VSC_N(tile
->slot
));
715 tu_cs_emit_qw(cs
, cmd
->vsc_data
.iova
+ tile
->pipe
* cmd
->vsc_data_pitch
);
716 tu_cs_emit_qw(cs
, cmd
->vsc_data
.iova
+ (tile
->pipe
* 4) + (32 * cmd
->vsc_data_pitch
));
717 tu_cs_emit_qw(cs
, cmd
->vsc_data2
.iova
+ (tile
->pipe
* cmd
->vsc_data2_pitch
));
719 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
722 /* use a NOP packet to skip over the 'else' side: */
723 tu_cs_emit_pkt7(cs
, CP_NOP
, 2);
725 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
729 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
733 A6XX_RB_UNKNOWN_8804(0));
736 A6XX_SP_TP_UNKNOWN_B304(0));
739 A6XX_GRAS_UNKNOWN_80A4(0));
741 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
744 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
750 tu6_emit_sysmem_resolve(struct tu_cmd_buffer
*cmd
,
755 const struct tu_framebuffer
*fb
= cmd
->state
.framebuffer
;
756 struct tu_image_view
*dst
= fb
->attachments
[a
].attachment
;
757 struct tu_image_view
*src
= fb
->attachments
[gmem_a
].attachment
;
759 tu_resolve_sysmem(cmd
, cs
, src
, dst
, fb
->layers
, &cmd
->state
.tiling_config
.render_area
);
763 tu6_emit_tile_store(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
765 const struct tu_render_pass
*pass
= cmd
->state
.pass
;
766 const struct tu_subpass
*subpass
= &pass
->subpasses
[pass
->subpass_count
-1];
768 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 3);
769 tu_cs_emit(cs
, CP_SET_DRAW_STATE__0_COUNT(0) |
770 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
771 CP_SET_DRAW_STATE__0_GROUP_ID(0));
772 tu_cs_emit(cs
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
773 tu_cs_emit(cs
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
775 tu_cs_emit_pkt7(cs
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
778 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
779 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_RESOLVE
));
781 /* blit scissor may have been changed by CmdClearAttachments */
782 tu6_emit_blit_scissor(cmd
, cs
, false);
784 for (uint32_t a
= 0; a
< pass
->attachment_count
; ++a
) {
785 if (pass
->attachments
[a
].gmem_offset
>= 0)
786 tu_store_gmem_attachment(cmd
, cs
, a
, a
);
789 if (subpass
->resolve_attachments
) {
790 for (unsigned i
= 0; i
< subpass
->color_count
; i
++) {
791 uint32_t a
= subpass
->resolve_attachments
[i
].attachment
;
792 if (a
!= VK_ATTACHMENT_UNUSED
)
793 tu_store_gmem_attachment(cmd
, cs
, a
,
794 subpass
->color_attachments
[i
].attachment
);
800 tu6_emit_restart_index(struct tu_cs
*cs
, uint32_t restart_index
)
803 A6XX_PC_RESTART_INDEX(restart_index
));
807 tu6_init_hw(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
809 const struct tu_physical_device
*phys_dev
= cmd
->device
->physical_device
;
811 tu6_emit_cache_flush(cmd
, cs
);
813 tu_cs_emit_write_reg(cs
, REG_A6XX_HLSQ_UPDATE_CNTL
, 0xfffff);
816 A6XX_RB_CCU_CNTL(.offset
= phys_dev
->ccu_offset_bypass
));
817 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8E04
, 0x00100000);
818 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_AE04
, 0x8);
819 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_AE00
, 0);
820 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_AE0F
, 0x3f);
821 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_B605
, 0x44);
822 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_B600
, 0x100000);
823 tu_cs_emit_write_reg(cs
, REG_A6XX_HLSQ_UNKNOWN_BE00
, 0x80);
824 tu_cs_emit_write_reg(cs
, REG_A6XX_HLSQ_UNKNOWN_BE01
, 0);
826 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9600
, 0);
827 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_8600
, 0x880);
828 tu_cs_emit_write_reg(cs
, REG_A6XX_HLSQ_UNKNOWN_BE04
, 0);
829 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_AE03
, 0x00000410);
830 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_IBO_COUNT
, 0);
831 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_B182
, 0);
832 tu_cs_emit_write_reg(cs
, REG_A6XX_HLSQ_UNKNOWN_BB11
, 0);
833 tu_cs_emit_write_reg(cs
, REG_A6XX_UCHE_UNKNOWN_0E12
, 0x3200000);
834 tu_cs_emit_write_reg(cs
, REG_A6XX_UCHE_CLIENT_PF
, 4);
835 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8E01
, 0x0);
836 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_A982
, 0);
837 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_A9A8
, 0);
838 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_AB00
, 0x5);
839 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_GS_SIV_CNTL
, 0x0000ffff);
841 tu_cs_emit_write_reg(cs
, REG_A6XX_VFD_ADD_OFFSET
, A6XX_VFD_ADD_OFFSET_VERTEX
);
842 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8811
, 0x00000010);
843 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_MODE_CNTL
, 0x1f);
845 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_SRGB_CNTL
, 0);
847 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_8110
, 0);
849 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_RENDER_CONTROL0
, 0x401);
850 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_RENDER_CONTROL1
, 0);
851 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_FS_OUTPUT_CNTL0
, 0);
852 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8818
, 0);
853 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8819
, 0);
854 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881A
, 0);
855 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881B
, 0);
856 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881C
, 0);
857 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881D
, 0);
858 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881E
, 0);
859 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_88F0
, 0);
861 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9101
, 0xffff00);
862 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9107
, 0);
864 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9236
, 1);
865 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9300
, 0);
867 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_SO_OVERRIDE
,
868 A6XX_VPC_SO_OVERRIDE_SO_DISABLE
);
870 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9801
, 0);
871 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9806
, 0);
872 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9980
, 0);
873 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9990
, 0);
875 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_PRIMITIVE_CNTL_6
, 0);
876 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9B07
, 0);
878 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_A81B
, 0);
880 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_B183
, 0);
882 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_8099
, 0);
883 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_809B
, 0);
884 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_80A0
, 2);
885 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_80AF
, 0);
886 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9210
, 0);
887 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9211
, 0);
888 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9602
, 0);
889 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9981
, 0x3);
890 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9E72
, 0);
891 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9108
, 0x3);
892 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_TP_UNKNOWN_B304
, 0);
893 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_TP_UNKNOWN_B309
, 0x000000a2);
894 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8804
, 0);
895 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_80A4
, 0);
896 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_80A5
, 0);
897 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_80A6
, 0);
898 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8805
, 0);
899 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8806
, 0);
900 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8878
, 0);
901 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8879
, 0);
902 tu_cs_emit_write_reg(cs
, REG_A6XX_HLSQ_CONTROL_5_REG
, 0xfc);
904 tu_cs_emit_write_reg(cs
, REG_A6XX_VFD_MODE_CNTL
, 0x00000000);
906 tu_cs_emit_write_reg(cs
, REG_A6XX_VFD_UNKNOWN_A008
, 0);
908 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_MODE_CNTL
, 0x0000001f);
910 /* we don't use this yet.. probably best to disable.. */
911 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 3);
912 tu_cs_emit(cs
, CP_SET_DRAW_STATE__0_COUNT(0) |
913 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
914 CP_SET_DRAW_STATE__0_GROUP_ID(0));
915 tu_cs_emit(cs
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
916 tu_cs_emit(cs
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
918 /* Set not to use streamout by default, */
919 tu_cs_emit_pkt7(cs
, CP_CONTEXT_REG_BUNCH
, 4);
920 tu_cs_emit(cs
, REG_A6XX_VPC_SO_CNTL
);
922 tu_cs_emit(cs
, REG_A6XX_VPC_SO_BUF_CNTL
);
926 A6XX_SP_HS_CTRL_REG0(0));
929 A6XX_SP_GS_CTRL_REG0(0));
932 A6XX_GRAS_LRZ_CNTL(0));
935 A6XX_RB_LRZ_CNTL(0));
938 A6XX_SP_TP_BORDER_COLOR_BASE_ADDR(.bo
= &cmd
->device
->border_color
));
940 A6XX_SP_PS_TP_BORDER_COLOR_BASE_ADDR(.bo
= &cmd
->device
->border_color
));
942 tu_cs_sanity_check(cs
);
946 tu6_cache_flush(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
950 seqno
= tu6_emit_event_write(cmd
, cs
, RB_DONE_TS
, true);
952 tu_cs_emit_pkt7(cs
, CP_WAIT_REG_MEM
, 6);
953 tu_cs_emit(cs
, CP_WAIT_REG_MEM_0_FUNCTION(WRITE_EQ
) |
954 CP_WAIT_REG_MEM_0_POLL_MEMORY
);
955 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
);
956 tu_cs_emit(cs
, CP_WAIT_REG_MEM_3_REF(seqno
));
957 tu_cs_emit(cs
, CP_WAIT_REG_MEM_4_MASK(~0));
958 tu_cs_emit(cs
, CP_WAIT_REG_MEM_5_DELAY_LOOP_CYCLES(16));
960 seqno
= tu6_emit_event_write(cmd
, cs
, CACHE_FLUSH_TS
, true);
962 tu_cs_emit_pkt7(cs
, CP_WAIT_MEM_GTE
, 4);
963 tu_cs_emit(cs
, CP_WAIT_MEM_GTE_0_RESERVED(0));
964 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
);
965 tu_cs_emit(cs
, CP_WAIT_MEM_GTE_3_REF(seqno
));
969 update_vsc_pipe(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
971 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
974 A6XX_VSC_BIN_SIZE(.width
= tiling
->tile0
.extent
.width
,
975 .height
= tiling
->tile0
.extent
.height
),
976 A6XX_VSC_SIZE_ADDRESS(.bo
= &cmd
->vsc_data
,
977 .bo_offset
= 32 * cmd
->vsc_data_pitch
));
980 A6XX_VSC_BIN_COUNT(.nx
= tiling
->tile_count
.width
,
981 .ny
= tiling
->tile_count
.height
));
983 tu_cs_emit_pkt4(cs
, REG_A6XX_VSC_PIPE_CONFIG_REG(0), 32);
984 for (unsigned i
= 0; i
< 32; i
++)
985 tu_cs_emit(cs
, tiling
->pipe_config
[i
]);
988 A6XX_VSC_PIPE_DATA2_ADDRESS(.bo
= &cmd
->vsc_data2
),
989 A6XX_VSC_PIPE_DATA2_PITCH(cmd
->vsc_data2_pitch
),
990 A6XX_VSC_PIPE_DATA2_ARRAY_PITCH(cmd
->vsc_data2
.size
));
993 A6XX_VSC_PIPE_DATA_ADDRESS(.bo
= &cmd
->vsc_data
),
994 A6XX_VSC_PIPE_DATA_PITCH(cmd
->vsc_data_pitch
),
995 A6XX_VSC_PIPE_DATA_ARRAY_PITCH(cmd
->vsc_data
.size
));
999 emit_vsc_overflow_test(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1001 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1002 const uint32_t used_pipe_count
=
1003 tiling
->pipe_count
.width
* tiling
->pipe_count
.height
;
1005 /* Clear vsc_scratch: */
1006 tu_cs_emit_pkt7(cs
, CP_MEM_WRITE
, 3);
1007 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(vsc_scratch
));
1008 tu_cs_emit(cs
, 0x0);
1010 /* Check for overflow, write vsc_scratch if detected: */
1011 for (int i
= 0; i
< used_pipe_count
; i
++) {
1012 tu_cs_emit_pkt7(cs
, CP_COND_WRITE5
, 8);
1013 tu_cs_emit(cs
, CP_COND_WRITE5_0_FUNCTION(WRITE_GE
) |
1014 CP_COND_WRITE5_0_WRITE_MEMORY
);
1015 tu_cs_emit(cs
, CP_COND_WRITE5_1_POLL_ADDR_LO(REG_A6XX_VSC_SIZE_REG(i
)));
1016 tu_cs_emit(cs
, CP_COND_WRITE5_2_POLL_ADDR_HI(0));
1017 tu_cs_emit(cs
, CP_COND_WRITE5_3_REF(cmd
->vsc_data_pitch
));
1018 tu_cs_emit(cs
, CP_COND_WRITE5_4_MASK(~0));
1019 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(vsc_scratch
));
1020 tu_cs_emit(cs
, CP_COND_WRITE5_7_WRITE_DATA(1 + cmd
->vsc_data_pitch
));
1022 tu_cs_emit_pkt7(cs
, CP_COND_WRITE5
, 8);
1023 tu_cs_emit(cs
, CP_COND_WRITE5_0_FUNCTION(WRITE_GE
) |
1024 CP_COND_WRITE5_0_WRITE_MEMORY
);
1025 tu_cs_emit(cs
, CP_COND_WRITE5_1_POLL_ADDR_LO(REG_A6XX_VSC_SIZE2_REG(i
)));
1026 tu_cs_emit(cs
, CP_COND_WRITE5_2_POLL_ADDR_HI(0));
1027 tu_cs_emit(cs
, CP_COND_WRITE5_3_REF(cmd
->vsc_data2_pitch
));
1028 tu_cs_emit(cs
, CP_COND_WRITE5_4_MASK(~0));
1029 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(vsc_scratch
));
1030 tu_cs_emit(cs
, CP_COND_WRITE5_7_WRITE_DATA(3 + cmd
->vsc_data2_pitch
));
1033 tu_cs_emit_pkt7(cs
, CP_WAIT_MEM_WRITES
, 0);
1035 tu_cs_emit_pkt7(cs
, CP_WAIT_FOR_ME
, 0);
1037 tu_cs_emit_pkt7(cs
, CP_MEM_TO_REG
, 3);
1038 tu_cs_emit(cs
, CP_MEM_TO_REG_0_REG(OVERFLOW_FLAG_REG
) |
1039 CP_MEM_TO_REG_0_CNT(1 - 1));
1040 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(vsc_scratch
));
1043 * This is a bit awkward, we really want a way to invert the
1044 * CP_REG_TEST/CP_COND_REG_EXEC logic, so that we can conditionally
1045 * execute cmds to use hwbinning when a bit is *not* set. This
1046 * dance is to invert OVERFLOW_FLAG_REG
1048 * A CP_NOP packet is used to skip executing the 'else' clause
1052 /* b0 will be set if VSC_DATA or VSC_DATA2 overflow: */
1053 tu_cs_emit_pkt7(cs
, CP_REG_TEST
, 1);
1054 tu_cs_emit(cs
, A6XX_CP_REG_TEST_0_REG(OVERFLOW_FLAG_REG
) |
1055 A6XX_CP_REG_TEST_0_BIT(0) |
1056 A6XX_CP_REG_TEST_0_WAIT_FOR_ME
);
1058 tu_cs_reserve(cs
, 3 + 7);
1059 tu_cs_emit_pkt7(cs
, CP_COND_REG_EXEC
, 2);
1060 tu_cs_emit(cs
, CP_COND_REG_EXEC_0_MODE(PRED_TEST
));
1061 tu_cs_emit(cs
, CP_COND_REG_EXEC_1_DWORDS(7));
1065 * On overflow, mirror the value to control->vsc_overflow
1066 * which CPU is checking to detect overflow (see
1067 * check_vsc_overflow())
1069 tu_cs_emit_pkt7(cs
, CP_REG_TO_MEM
, 3);
1070 tu_cs_emit(cs
, CP_REG_TO_MEM_0_REG(OVERFLOW_FLAG_REG
) |
1071 CP_REG_TO_MEM_0_CNT(0));
1072 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(vsc_overflow
));
1074 tu_cs_emit_pkt4(cs
, OVERFLOW_FLAG_REG
, 1);
1075 tu_cs_emit(cs
, 0x0);
1077 tu_cs_emit_pkt7(cs
, CP_NOP
, 2); /* skip 'else' when 'if' is taken */
1079 tu_cs_emit_pkt4(cs
, OVERFLOW_FLAG_REG
, 1);
1080 tu_cs_emit(cs
, 0x1);
1085 tu6_emit_binning_pass(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1087 struct tu_physical_device
*phys_dev
= cmd
->device
->physical_device
;
1088 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1090 uint32_t x1
= tiling
->tile0
.offset
.x
;
1091 uint32_t y1
= tiling
->tile0
.offset
.y
;
1092 uint32_t x2
= tiling
->render_area
.offset
.x
+ tiling
->render_area
.extent
.width
- 1;
1093 uint32_t y2
= tiling
->render_area
.offset
.y
+ tiling
->render_area
.extent
.height
- 1;
1095 tu6_emit_window_scissor(cs
, x1
, y1
, x2
, y2
);
1097 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
1098 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_BINNING
));
1100 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
1101 tu_cs_emit(cs
, 0x1);
1103 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
1104 tu_cs_emit(cs
, 0x1);
1109 A6XX_VFD_MODE_CNTL(.binning_pass
= true));
1111 update_vsc_pipe(cmd
, cs
);
1114 A6XX_PC_UNKNOWN_9805(.unknown
= phys_dev
->magic
.PC_UNKNOWN_9805
));
1117 A6XX_SP_UNKNOWN_A0F8(.unknown
= phys_dev
->magic
.SP_UNKNOWN_A0F8
));
1119 tu_cs_emit_pkt7(cs
, CP_EVENT_WRITE
, 1);
1120 tu_cs_emit(cs
, UNK_2C
);
1123 A6XX_RB_WINDOW_OFFSET(.x
= 0, .y
= 0));
1126 A6XX_SP_TP_WINDOW_OFFSET(.x
= 0, .y
= 0));
1128 /* emit IB to binning drawcmds: */
1129 tu_cs_emit_call(cs
, &cmd
->draw_cs
);
1131 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 3);
1132 tu_cs_emit(cs
, CP_SET_DRAW_STATE__0_COUNT(0) |
1133 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
1134 CP_SET_DRAW_STATE__0_GROUP_ID(0));
1135 tu_cs_emit(cs
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
1136 tu_cs_emit(cs
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
1138 tu_cs_emit_pkt7(cs
, CP_EVENT_WRITE
, 1);
1139 tu_cs_emit(cs
, UNK_2D
);
1141 tu6_emit_event_write(cmd
, cs
, CACHE_INVALIDATE
, false);
1142 tu6_cache_flush(cmd
, cs
);
1146 tu_cs_emit_pkt7(cs
, CP_WAIT_FOR_ME
, 0);
1148 emit_vsc_overflow_test(cmd
, cs
);
1150 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
1151 tu_cs_emit(cs
, 0x0);
1153 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
1154 tu_cs_emit(cs
, 0x0);
1156 cmd
->wait_for_idle
= false;
1160 tu_emit_load_clear(struct tu_cmd_buffer
*cmd
,
1161 const VkRenderPassBeginInfo
*info
)
1163 struct tu_cs
*cs
= &cmd
->draw_cs
;
1165 tu_cond_exec_start(cs
, CP_COND_EXEC_0_RENDER_MODE_GMEM
);
1167 tu6_emit_blit_scissor(cmd
, cs
, true);
1169 for (uint32_t i
= 0; i
< cmd
->state
.pass
->attachment_count
; ++i
)
1170 tu_load_gmem_attachment(cmd
, cs
, i
);
1172 tu6_emit_blit_scissor(cmd
, cs
, false);
1174 for (uint32_t i
= 0; i
< cmd
->state
.pass
->attachment_count
; ++i
)
1175 tu_clear_gmem_attachment(cmd
, cs
, i
, info
);
1177 tu_cond_exec_end(cs
);
1179 tu_cond_exec_start(cs
, CP_COND_EXEC_0_RENDER_MODE_SYSMEM
);
1181 for (uint32_t i
= 0; i
< cmd
->state
.pass
->attachment_count
; ++i
)
1182 tu_clear_sysmem_attachment(cmd
, cs
, i
, info
);
1184 tu_cond_exec_end(cs
);
1188 tu6_sysmem_render_begin(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
,
1189 const struct VkRect2D
*renderArea
)
1191 const struct tu_physical_device
*phys_dev
= cmd
->device
->physical_device
;
1192 const struct tu_framebuffer
*fb
= cmd
->state
.framebuffer
;
1194 assert(fb
->width
> 0 && fb
->height
> 0);
1195 tu6_emit_window_scissor(cs
, 0, 0, fb
->width
- 1, fb
->height
- 1);
1196 tu6_emit_window_offset(cs
, 0, 0);
1198 tu6_emit_bin_size(cs
, 0, 0, 0xc00000); /* 0xc00000 = BYPASS? */
1200 tu6_emit_lrz_flush(cmd
, cs
);
1202 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
1203 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_BYPASS
));
1205 tu_cs_emit_pkt7(cs
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1206 tu_cs_emit(cs
, 0x0);
1208 tu6_emit_event_write(cmd
, cs
, PC_CCU_INVALIDATE_COLOR
, false);
1209 tu6_emit_event_write(cmd
, cs
, PC_CCU_INVALIDATE_DEPTH
, false);
1210 tu6_emit_event_write(cmd
, cs
, CACHE_INVALIDATE
, false);
1212 tu6_emit_wfi(cmd
, cs
);
1214 A6XX_RB_CCU_CNTL(.offset
= phys_dev
->ccu_offset_bypass
));
1216 /* enable stream-out, with sysmem there is only one pass: */
1218 A6XX_VPC_SO_OVERRIDE(.so_disable
= false));
1220 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
1221 tu_cs_emit(cs
, 0x1);
1223 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
1224 tu_cs_emit(cs
, 0x0);
1226 tu_cs_sanity_check(cs
);
1230 tu6_sysmem_render_end(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1232 /* Do any resolves of the last subpass. These are handled in the
1233 * tile_store_ib in the gmem path.
1235 const struct tu_subpass
*subpass
= cmd
->state
.subpass
;
1236 if (subpass
->resolve_attachments
) {
1237 for (unsigned i
= 0; i
< subpass
->color_count
; i
++) {
1238 uint32_t a
= subpass
->resolve_attachments
[i
].attachment
;
1239 if (a
!= VK_ATTACHMENT_UNUSED
)
1240 tu6_emit_sysmem_resolve(cmd
, cs
, a
,
1241 subpass
->color_attachments
[i
].attachment
);
1245 tu_cs_emit_call(cs
, &cmd
->draw_epilogue_cs
);
1247 tu_cs_emit_pkt7(cs
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1248 tu_cs_emit(cs
, 0x0);
1250 tu6_emit_lrz_flush(cmd
, cs
);
1252 tu6_emit_event_write(cmd
, cs
, PC_CCU_FLUSH_COLOR_TS
, true);
1253 tu6_emit_event_write(cmd
, cs
, PC_CCU_FLUSH_DEPTH_TS
, true);
1255 tu_cs_sanity_check(cs
);
1260 tu6_tile_render_begin(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1262 struct tu_physical_device
*phys_dev
= cmd
->device
->physical_device
;
1264 tu6_emit_lrz_flush(cmd
, cs
);
1268 tu6_emit_cache_flush(cmd
, cs
);
1270 tu_cs_emit_pkt7(cs
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1271 tu_cs_emit(cs
, 0x0);
1273 /* TODO: flushing with barriers instead of blindly always flushing */
1274 tu6_emit_event_write(cmd
, cs
, PC_CCU_FLUSH_COLOR_TS
, true);
1275 tu6_emit_event_write(cmd
, cs
, PC_CCU_FLUSH_DEPTH_TS
, true);
1276 tu6_emit_event_write(cmd
, cs
, PC_CCU_INVALIDATE_COLOR
, false);
1277 tu6_emit_event_write(cmd
, cs
, PC_CCU_INVALIDATE_DEPTH
, false);
1281 A6XX_RB_CCU_CNTL(.offset
= phys_dev
->ccu_offset_gmem
, .gmem
= 1));
1283 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1284 if (use_hw_binning(cmd
)) {
1285 /* enable stream-out during binning pass: */
1286 tu_cs_emit_regs(cs
, A6XX_VPC_SO_OVERRIDE(.so_disable
=false));
1288 tu6_emit_bin_size(cs
,
1289 tiling
->tile0
.extent
.width
,
1290 tiling
->tile0
.extent
.height
,
1291 A6XX_RB_BIN_CONTROL_BINNING_PASS
| 0x6000000);
1293 tu6_emit_render_cntl(cmd
, cmd
->state
.subpass
, cs
, true);
1295 tu6_emit_binning_pass(cmd
, cs
);
1297 /* and disable stream-out for draw pass: */
1298 tu_cs_emit_regs(cs
, A6XX_VPC_SO_OVERRIDE(.so_disable
=true));
1300 tu6_emit_bin_size(cs
,
1301 tiling
->tile0
.extent
.width
,
1302 tiling
->tile0
.extent
.height
,
1303 A6XX_RB_BIN_CONTROL_USE_VIZ
| 0x6000000);
1306 A6XX_VFD_MODE_CNTL(0));
1308 tu_cs_emit_regs(cs
, A6XX_PC_UNKNOWN_9805(.unknown
= phys_dev
->magic
.PC_UNKNOWN_9805
));
1310 tu_cs_emit_regs(cs
, A6XX_SP_UNKNOWN_A0F8(.unknown
= phys_dev
->magic
.SP_UNKNOWN_A0F8
));
1312 tu_cs_emit_pkt7(cs
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1313 tu_cs_emit(cs
, 0x1);
1315 /* no binning pass, so enable stream-out for draw pass:: */
1316 tu_cs_emit_regs(cs
, A6XX_VPC_SO_OVERRIDE(.so_disable
=false));
1318 tu6_emit_bin_size(cs
,
1319 tiling
->tile0
.extent
.width
,
1320 tiling
->tile0
.extent
.height
,
1324 tu_cs_sanity_check(cs
);
1328 tu6_render_tile(struct tu_cmd_buffer
*cmd
,
1330 const struct tu_tile
*tile
)
1332 tu6_emit_tile_select(cmd
, cs
, tile
);
1334 tu_cs_emit_call(cs
, &cmd
->draw_cs
);
1335 cmd
->wait_for_idle
= true;
1337 if (use_hw_binning(cmd
)) {
1338 tu_cs_emit_pkt7(cs
, CP_REG_TEST
, 1);
1339 tu_cs_emit(cs
, A6XX_CP_REG_TEST_0_REG(OVERFLOW_FLAG_REG
) |
1340 A6XX_CP_REG_TEST_0_BIT(0) |
1341 A6XX_CP_REG_TEST_0_WAIT_FOR_ME
);
1343 tu_cs_reserve(cs
, 3 + 2);
1344 tu_cs_emit_pkt7(cs
, CP_COND_REG_EXEC
, 2);
1345 tu_cs_emit(cs
, CP_COND_REG_EXEC_0_MODE(PRED_TEST
));
1346 tu_cs_emit(cs
, CP_COND_REG_EXEC_1_DWORDS(2));
1348 /* if (no overflow) */ {
1349 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
1350 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_ENDVIS
));
1354 tu_cs_emit_ib(cs
, &cmd
->state
.tile_store_ib
);
1356 tu_cs_sanity_check(cs
);
1360 tu6_tile_render_end(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1362 tu_cs_emit_call(cs
, &cmd
->draw_epilogue_cs
);
1365 A6XX_GRAS_LRZ_CNTL(0));
1367 tu6_emit_lrz_flush(cmd
, cs
);
1369 tu6_emit_event_write(cmd
, cs
, CACHE_FLUSH_TS
, true);
1371 tu_cs_sanity_check(cs
);
1375 tu_cmd_render_tiles(struct tu_cmd_buffer
*cmd
)
1377 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1379 tu6_tile_render_begin(cmd
, &cmd
->cs
);
1381 for (uint32_t y
= 0; y
< tiling
->tile_count
.height
; y
++) {
1382 for (uint32_t x
= 0; x
< tiling
->tile_count
.width
; x
++) {
1383 struct tu_tile tile
;
1384 tu_tiling_config_get_tile(tiling
, cmd
->device
, x
, y
, &tile
);
1385 tu6_render_tile(cmd
, &cmd
->cs
, &tile
);
1389 tu6_tile_render_end(cmd
, &cmd
->cs
);
1393 tu_cmd_render_sysmem(struct tu_cmd_buffer
*cmd
)
1395 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1397 tu6_sysmem_render_begin(cmd
, &cmd
->cs
, &tiling
->render_area
);
1399 tu_cs_emit_call(&cmd
->cs
, &cmd
->draw_cs
);
1400 cmd
->wait_for_idle
= true;
1402 tu6_sysmem_render_end(cmd
, &cmd
->cs
);
1406 tu_cmd_prepare_tile_store_ib(struct tu_cmd_buffer
*cmd
)
1408 const uint32_t tile_store_space
= 11 + (35 * 2) * cmd
->state
.pass
->attachment_count
;
1409 struct tu_cs sub_cs
;
1412 tu_cs_begin_sub_stream(&cmd
->sub_cs
, tile_store_space
, &sub_cs
);
1413 if (result
!= VK_SUCCESS
) {
1414 cmd
->record_result
= result
;
1418 /* emit to tile-store sub_cs */
1419 tu6_emit_tile_store(cmd
, &sub_cs
);
1421 cmd
->state
.tile_store_ib
= tu_cs_end_sub_stream(&cmd
->sub_cs
, &sub_cs
);
1425 tu_cmd_update_tiling_config(struct tu_cmd_buffer
*cmd
,
1426 const VkRect2D
*render_area
)
1428 const struct tu_device
*dev
= cmd
->device
;
1429 struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1431 tiling
->render_area
= *render_area
;
1432 tiling
->force_sysmem
= false;
1434 tu_tiling_config_update_tile_layout(tiling
, dev
, cmd
->state
.pass
->gmem_pixels
);
1435 tu_tiling_config_update_pipe_layout(tiling
, dev
);
1436 tu_tiling_config_update_pipes(tiling
, dev
);
1439 const struct tu_dynamic_state default_dynamic_state
= {
1455 .blend_constants
= { 0.0f
, 0.0f
, 0.0f
, 0.0f
},
1461 .stencil_compare_mask
=
1466 .stencil_write_mask
=
1471 .stencil_reference
=
1478 static void UNUSED
/* FINISHME */
1479 tu_bind_dynamic_state(struct tu_cmd_buffer
*cmd_buffer
,
1480 const struct tu_dynamic_state
*src
)
1482 struct tu_dynamic_state
*dest
= &cmd_buffer
->state
.dynamic
;
1483 uint32_t copy_mask
= src
->mask
;
1484 uint32_t dest_mask
= 0;
1486 tu_use_args(cmd_buffer
); /* FINISHME */
1488 /* Make sure to copy the number of viewports/scissors because they can
1489 * only be specified at pipeline creation time.
1491 dest
->viewport
.count
= src
->viewport
.count
;
1492 dest
->scissor
.count
= src
->scissor
.count
;
1493 dest
->discard_rectangle
.count
= src
->discard_rectangle
.count
;
1495 if (copy_mask
& TU_DYNAMIC_VIEWPORT
) {
1496 if (memcmp(&dest
->viewport
.viewports
, &src
->viewport
.viewports
,
1497 src
->viewport
.count
* sizeof(VkViewport
))) {
1498 typed_memcpy(dest
->viewport
.viewports
, src
->viewport
.viewports
,
1499 src
->viewport
.count
);
1500 dest_mask
|= TU_DYNAMIC_VIEWPORT
;
1504 if (copy_mask
& TU_DYNAMIC_SCISSOR
) {
1505 if (memcmp(&dest
->scissor
.scissors
, &src
->scissor
.scissors
,
1506 src
->scissor
.count
* sizeof(VkRect2D
))) {
1507 typed_memcpy(dest
->scissor
.scissors
, src
->scissor
.scissors
,
1508 src
->scissor
.count
);
1509 dest_mask
|= TU_DYNAMIC_SCISSOR
;
1513 if (copy_mask
& TU_DYNAMIC_LINE_WIDTH
) {
1514 if (dest
->line_width
!= src
->line_width
) {
1515 dest
->line_width
= src
->line_width
;
1516 dest_mask
|= TU_DYNAMIC_LINE_WIDTH
;
1520 if (copy_mask
& TU_DYNAMIC_DEPTH_BIAS
) {
1521 if (memcmp(&dest
->depth_bias
, &src
->depth_bias
,
1522 sizeof(src
->depth_bias
))) {
1523 dest
->depth_bias
= src
->depth_bias
;
1524 dest_mask
|= TU_DYNAMIC_DEPTH_BIAS
;
1528 if (copy_mask
& TU_DYNAMIC_BLEND_CONSTANTS
) {
1529 if (memcmp(&dest
->blend_constants
, &src
->blend_constants
,
1530 sizeof(src
->blend_constants
))) {
1531 typed_memcpy(dest
->blend_constants
, src
->blend_constants
, 4);
1532 dest_mask
|= TU_DYNAMIC_BLEND_CONSTANTS
;
1536 if (copy_mask
& TU_DYNAMIC_DEPTH_BOUNDS
) {
1537 if (memcmp(&dest
->depth_bounds
, &src
->depth_bounds
,
1538 sizeof(src
->depth_bounds
))) {
1539 dest
->depth_bounds
= src
->depth_bounds
;
1540 dest_mask
|= TU_DYNAMIC_DEPTH_BOUNDS
;
1544 if (copy_mask
& TU_DYNAMIC_STENCIL_COMPARE_MASK
) {
1545 if (memcmp(&dest
->stencil_compare_mask
, &src
->stencil_compare_mask
,
1546 sizeof(src
->stencil_compare_mask
))) {
1547 dest
->stencil_compare_mask
= src
->stencil_compare_mask
;
1548 dest_mask
|= TU_DYNAMIC_STENCIL_COMPARE_MASK
;
1552 if (copy_mask
& TU_DYNAMIC_STENCIL_WRITE_MASK
) {
1553 if (memcmp(&dest
->stencil_write_mask
, &src
->stencil_write_mask
,
1554 sizeof(src
->stencil_write_mask
))) {
1555 dest
->stencil_write_mask
= src
->stencil_write_mask
;
1556 dest_mask
|= TU_DYNAMIC_STENCIL_WRITE_MASK
;
1560 if (copy_mask
& TU_DYNAMIC_STENCIL_REFERENCE
) {
1561 if (memcmp(&dest
->stencil_reference
, &src
->stencil_reference
,
1562 sizeof(src
->stencil_reference
))) {
1563 dest
->stencil_reference
= src
->stencil_reference
;
1564 dest_mask
|= TU_DYNAMIC_STENCIL_REFERENCE
;
1568 if (copy_mask
& TU_DYNAMIC_DISCARD_RECTANGLE
) {
1569 if (memcmp(&dest
->discard_rectangle
.rectangles
,
1570 &src
->discard_rectangle
.rectangles
,
1571 src
->discard_rectangle
.count
* sizeof(VkRect2D
))) {
1572 typed_memcpy(dest
->discard_rectangle
.rectangles
,
1573 src
->discard_rectangle
.rectangles
,
1574 src
->discard_rectangle
.count
);
1575 dest_mask
|= TU_DYNAMIC_DISCARD_RECTANGLE
;
1581 tu_create_cmd_buffer(struct tu_device
*device
,
1582 struct tu_cmd_pool
*pool
,
1583 VkCommandBufferLevel level
,
1584 VkCommandBuffer
*pCommandBuffer
)
1586 struct tu_cmd_buffer
*cmd_buffer
;
1587 cmd_buffer
= vk_zalloc(&pool
->alloc
, sizeof(*cmd_buffer
), 8,
1588 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1589 if (cmd_buffer
== NULL
)
1590 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1592 cmd_buffer
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1593 cmd_buffer
->device
= device
;
1594 cmd_buffer
->pool
= pool
;
1595 cmd_buffer
->level
= level
;
1598 list_addtail(&cmd_buffer
->pool_link
, &pool
->cmd_buffers
);
1599 cmd_buffer
->queue_family_index
= pool
->queue_family_index
;
1602 /* Init the pool_link so we can safely call list_del when we destroy
1603 * the command buffer
1605 list_inithead(&cmd_buffer
->pool_link
);
1606 cmd_buffer
->queue_family_index
= TU_QUEUE_GENERAL
;
1609 tu_bo_list_init(&cmd_buffer
->bo_list
);
1610 tu_cs_init(&cmd_buffer
->cs
, device
, TU_CS_MODE_GROW
, 4096);
1611 tu_cs_init(&cmd_buffer
->draw_cs
, device
, TU_CS_MODE_GROW
, 4096);
1612 tu_cs_init(&cmd_buffer
->draw_epilogue_cs
, device
, TU_CS_MODE_GROW
, 4096);
1613 tu_cs_init(&cmd_buffer
->sub_cs
, device
, TU_CS_MODE_SUB_STREAM
, 2048);
1615 *pCommandBuffer
= tu_cmd_buffer_to_handle(cmd_buffer
);
1617 list_inithead(&cmd_buffer
->upload
.list
);
1619 VkResult result
= tu_bo_init_new(device
, &cmd_buffer
->scratch_bo
, 0x1000);
1620 if (result
!= VK_SUCCESS
)
1621 goto fail_scratch_bo
;
1623 /* TODO: resize on overflow */
1624 cmd_buffer
->vsc_data_pitch
= device
->vsc_data_pitch
;
1625 cmd_buffer
->vsc_data2_pitch
= device
->vsc_data2_pitch
;
1626 cmd_buffer
->vsc_data
= device
->vsc_data
;
1627 cmd_buffer
->vsc_data2
= device
->vsc_data2
;
1632 list_del(&cmd_buffer
->pool_link
);
1637 tu_cmd_buffer_destroy(struct tu_cmd_buffer
*cmd_buffer
)
1639 tu_bo_finish(cmd_buffer
->device
, &cmd_buffer
->scratch_bo
);
1641 list_del(&cmd_buffer
->pool_link
);
1643 for (unsigned i
= 0; i
< VK_PIPELINE_BIND_POINT_RANGE_SIZE
; i
++)
1644 free(cmd_buffer
->descriptors
[i
].push_set
.set
.mapped_ptr
);
1646 tu_cs_finish(&cmd_buffer
->cs
);
1647 tu_cs_finish(&cmd_buffer
->draw_cs
);
1648 tu_cs_finish(&cmd_buffer
->draw_epilogue_cs
);
1649 tu_cs_finish(&cmd_buffer
->sub_cs
);
1651 tu_bo_list_destroy(&cmd_buffer
->bo_list
);
1652 vk_free(&cmd_buffer
->pool
->alloc
, cmd_buffer
);
1656 tu_reset_cmd_buffer(struct tu_cmd_buffer
*cmd_buffer
)
1658 cmd_buffer
->wait_for_idle
= true;
1660 cmd_buffer
->record_result
= VK_SUCCESS
;
1662 tu_bo_list_reset(&cmd_buffer
->bo_list
);
1663 tu_cs_reset(&cmd_buffer
->cs
);
1664 tu_cs_reset(&cmd_buffer
->draw_cs
);
1665 tu_cs_reset(&cmd_buffer
->draw_epilogue_cs
);
1666 tu_cs_reset(&cmd_buffer
->sub_cs
);
1668 for (unsigned i
= 0; i
< VK_PIPELINE_BIND_POINT_RANGE_SIZE
; i
++) {
1669 cmd_buffer
->descriptors
[i
].valid
= 0;
1670 cmd_buffer
->descriptors
[i
].push_dirty
= false;
1673 cmd_buffer
->status
= TU_CMD_BUFFER_STATUS_INITIAL
;
1675 return cmd_buffer
->record_result
;
1679 tu_AllocateCommandBuffers(VkDevice _device
,
1680 const VkCommandBufferAllocateInfo
*pAllocateInfo
,
1681 VkCommandBuffer
*pCommandBuffers
)
1683 TU_FROM_HANDLE(tu_device
, device
, _device
);
1684 TU_FROM_HANDLE(tu_cmd_pool
, pool
, pAllocateInfo
->commandPool
);
1686 VkResult result
= VK_SUCCESS
;
1689 for (i
= 0; i
< pAllocateInfo
->commandBufferCount
; i
++) {
1691 if (!list_is_empty(&pool
->free_cmd_buffers
)) {
1692 struct tu_cmd_buffer
*cmd_buffer
= list_first_entry(
1693 &pool
->free_cmd_buffers
, struct tu_cmd_buffer
, pool_link
);
1695 list_del(&cmd_buffer
->pool_link
);
1696 list_addtail(&cmd_buffer
->pool_link
, &pool
->cmd_buffers
);
1698 result
= tu_reset_cmd_buffer(cmd_buffer
);
1699 cmd_buffer
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1700 cmd_buffer
->level
= pAllocateInfo
->level
;
1702 pCommandBuffers
[i
] = tu_cmd_buffer_to_handle(cmd_buffer
);
1704 result
= tu_create_cmd_buffer(device
, pool
, pAllocateInfo
->level
,
1705 &pCommandBuffers
[i
]);
1707 if (result
!= VK_SUCCESS
)
1711 if (result
!= VK_SUCCESS
) {
1712 tu_FreeCommandBuffers(_device
, pAllocateInfo
->commandPool
, i
,
1715 /* From the Vulkan 1.0.66 spec:
1717 * "vkAllocateCommandBuffers can be used to create multiple
1718 * command buffers. If the creation of any of those command
1719 * buffers fails, the implementation must destroy all
1720 * successfully created command buffer objects from this
1721 * command, set all entries of the pCommandBuffers array to
1722 * NULL and return the error."
1724 memset(pCommandBuffers
, 0,
1725 sizeof(*pCommandBuffers
) * pAllocateInfo
->commandBufferCount
);
1732 tu_FreeCommandBuffers(VkDevice device
,
1733 VkCommandPool commandPool
,
1734 uint32_t commandBufferCount
,
1735 const VkCommandBuffer
*pCommandBuffers
)
1737 for (uint32_t i
= 0; i
< commandBufferCount
; i
++) {
1738 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, pCommandBuffers
[i
]);
1741 if (cmd_buffer
->pool
) {
1742 list_del(&cmd_buffer
->pool_link
);
1743 list_addtail(&cmd_buffer
->pool_link
,
1744 &cmd_buffer
->pool
->free_cmd_buffers
);
1746 tu_cmd_buffer_destroy(cmd_buffer
);
1752 tu_ResetCommandBuffer(VkCommandBuffer commandBuffer
,
1753 VkCommandBufferResetFlags flags
)
1755 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
1756 return tu_reset_cmd_buffer(cmd_buffer
);
1760 tu_BeginCommandBuffer(VkCommandBuffer commandBuffer
,
1761 const VkCommandBufferBeginInfo
*pBeginInfo
)
1763 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
1764 VkResult result
= VK_SUCCESS
;
1766 if (cmd_buffer
->status
!= TU_CMD_BUFFER_STATUS_INITIAL
) {
1767 /* If the command buffer has already been resetted with
1768 * vkResetCommandBuffer, no need to do it again.
1770 result
= tu_reset_cmd_buffer(cmd_buffer
);
1771 if (result
!= VK_SUCCESS
)
1775 memset(&cmd_buffer
->state
, 0, sizeof(cmd_buffer
->state
));
1776 cmd_buffer
->usage_flags
= pBeginInfo
->flags
;
1778 tu_cs_begin(&cmd_buffer
->cs
);
1779 tu_cs_begin(&cmd_buffer
->draw_cs
);
1780 tu_cs_begin(&cmd_buffer
->draw_epilogue_cs
);
1782 cmd_buffer
->scratch_seqno
= 0;
1784 /* setup initial configuration into command buffer */
1785 if (cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
) {
1786 switch (cmd_buffer
->queue_family_index
) {
1787 case TU_QUEUE_GENERAL
:
1788 tu6_init_hw(cmd_buffer
, &cmd_buffer
->cs
);
1793 } else if (cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_SECONDARY
&&
1794 (pBeginInfo
->flags
& VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
)) {
1795 assert(pBeginInfo
->pInheritanceInfo
);
1796 cmd_buffer
->state
.pass
= tu_render_pass_from_handle(pBeginInfo
->pInheritanceInfo
->renderPass
);
1797 cmd_buffer
->state
.subpass
= &cmd_buffer
->state
.pass
->subpasses
[pBeginInfo
->pInheritanceInfo
->subpass
];
1800 cmd_buffer
->status
= TU_CMD_BUFFER_STATUS_RECORDING
;
1806 tu_CmdBindVertexBuffers(VkCommandBuffer commandBuffer
,
1807 uint32_t firstBinding
,
1808 uint32_t bindingCount
,
1809 const VkBuffer
*pBuffers
,
1810 const VkDeviceSize
*pOffsets
)
1812 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1814 assert(firstBinding
+ bindingCount
<= MAX_VBS
);
1816 for (uint32_t i
= 0; i
< bindingCount
; i
++) {
1817 cmd
->state
.vb
.buffers
[firstBinding
+ i
] =
1818 tu_buffer_from_handle(pBuffers
[i
]);
1819 cmd
->state
.vb
.offsets
[firstBinding
+ i
] = pOffsets
[i
];
1822 /* VB states depend on VkPipelineVertexInputStateCreateInfo */
1823 cmd
->state
.dirty
|= TU_CMD_DIRTY_VERTEX_BUFFERS
;
1827 tu_CmdBindIndexBuffer(VkCommandBuffer commandBuffer
,
1829 VkDeviceSize offset
,
1830 VkIndexType indexType
)
1832 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1833 TU_FROM_HANDLE(tu_buffer
, buf
, buffer
);
1835 /* initialize/update the restart index */
1836 if (!cmd
->state
.index_buffer
|| cmd
->state
.index_type
!= indexType
) {
1837 struct tu_cs
*draw_cs
= &cmd
->draw_cs
;
1839 tu6_emit_restart_index(
1840 draw_cs
, indexType
== VK_INDEX_TYPE_UINT32
? 0xffffffff : 0xffff);
1842 tu_cs_sanity_check(draw_cs
);
1846 if (cmd
->state
.index_buffer
!= buf
)
1847 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_READ
);
1849 cmd
->state
.index_buffer
= buf
;
1850 cmd
->state
.index_offset
= offset
;
1851 cmd
->state
.index_type
= indexType
;
1855 tu_CmdBindDescriptorSets(VkCommandBuffer commandBuffer
,
1856 VkPipelineBindPoint pipelineBindPoint
,
1857 VkPipelineLayout _layout
,
1859 uint32_t descriptorSetCount
,
1860 const VkDescriptorSet
*pDescriptorSets
,
1861 uint32_t dynamicOffsetCount
,
1862 const uint32_t *pDynamicOffsets
)
1864 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
1865 TU_FROM_HANDLE(tu_pipeline_layout
, layout
, _layout
);
1866 unsigned dyn_idx
= 0;
1868 struct tu_descriptor_state
*descriptors_state
=
1869 tu_get_descriptors_state(cmd_buffer
, pipelineBindPoint
);
1871 for (unsigned i
= 0; i
< descriptorSetCount
; ++i
) {
1872 unsigned idx
= i
+ firstSet
;
1873 TU_FROM_HANDLE(tu_descriptor_set
, set
, pDescriptorSets
[i
]);
1875 descriptors_state
->sets
[idx
] = set
;
1876 descriptors_state
->valid
|= (1u << idx
);
1878 /* Note: the actual input attachment indices come from the shader
1879 * itself, so we can't generate the patched versions of these until
1880 * draw time when both the pipeline and descriptors are bound and
1881 * we're inside the render pass.
1883 unsigned dst_idx
= layout
->set
[idx
].input_attachment_start
;
1884 memcpy(&descriptors_state
->input_attachments
[dst_idx
* A6XX_TEX_CONST_DWORDS
],
1885 set
->dynamic_descriptors
,
1886 set
->layout
->input_attachment_count
* A6XX_TEX_CONST_DWORDS
* 4);
1888 for(unsigned j
= 0; j
< set
->layout
->dynamic_offset_count
; ++j
, ++dyn_idx
) {
1889 /* Dynamic buffers come after input attachments in the descriptor set
1890 * itself, but due to how the Vulkan descriptor set binding works, we
1891 * have to put input attachments and dynamic buffers in separate
1892 * buffers in the descriptor_state and then combine them at draw
1893 * time. Binding a descriptor set only invalidates the descriptor
1894 * sets after it, but if we try to tightly pack the descriptors after
1895 * the input attachments then we could corrupt dynamic buffers in the
1896 * descriptor set before it, or we'd have to move all the dynamic
1897 * buffers over. We just put them into separate buffers to make
1898 * binding as well as the later patching of input attachments easy.
1900 unsigned src_idx
= j
+ set
->layout
->input_attachment_count
;
1901 unsigned dst_idx
= j
+ layout
->set
[idx
].dynamic_offset_start
;
1902 assert(dyn_idx
< dynamicOffsetCount
);
1905 &descriptors_state
->dynamic_descriptors
[dst_idx
* A6XX_TEX_CONST_DWORDS
];
1907 &set
->dynamic_descriptors
[src_idx
* A6XX_TEX_CONST_DWORDS
];
1908 uint32_t offset
= pDynamicOffsets
[dyn_idx
];
1910 /* Patch the storage/uniform descriptors right away. */
1911 if (layout
->set
[idx
].layout
->dynamic_ubo
& (1 << j
)) {
1912 /* Note: we can assume here that the addition won't roll over and
1913 * change the SIZE field.
1915 uint64_t va
= src
[0] | ((uint64_t)src
[1] << 32);
1920 memcpy(dst
, src
, A6XX_TEX_CONST_DWORDS
* 4);
1921 /* Note: A6XX_IBO_5_DEPTH is always 0 */
1922 uint64_t va
= dst
[4] | ((uint64_t)dst
[5] << 32);
1930 if (pipelineBindPoint
== VK_PIPELINE_BIND_POINT_COMPUTE
)
1931 cmd_buffer
->state
.dirty
|= TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
;
1933 cmd_buffer
->state
.dirty
|= TU_CMD_DIRTY_DESCRIPTOR_SETS
;
1936 void tu_CmdBindTransformFeedbackBuffersEXT(VkCommandBuffer commandBuffer
,
1937 uint32_t firstBinding
,
1938 uint32_t bindingCount
,
1939 const VkBuffer
*pBuffers
,
1940 const VkDeviceSize
*pOffsets
,
1941 const VkDeviceSize
*pSizes
)
1943 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1944 assert(firstBinding
+ bindingCount
<= IR3_MAX_SO_BUFFERS
);
1946 for (uint32_t i
= 0; i
< bindingCount
; i
++) {
1947 uint32_t idx
= firstBinding
+ i
;
1948 TU_FROM_HANDLE(tu_buffer
, buf
, pBuffers
[i
]);
1950 if (pOffsets
[i
] != 0)
1951 cmd
->state
.streamout_reset
|= 1 << idx
;
1953 cmd
->state
.streamout_buf
.buffers
[idx
] = buf
;
1954 cmd
->state
.streamout_buf
.offsets
[idx
] = pOffsets
[i
];
1955 cmd
->state
.streamout_buf
.sizes
[idx
] = pSizes
[i
];
1957 cmd
->state
.streamout_enabled
|= 1 << idx
;
1960 cmd
->state
.dirty
|= TU_CMD_DIRTY_STREAMOUT_BUFFERS
;
1963 void tu_CmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer
,
1964 uint32_t firstCounterBuffer
,
1965 uint32_t counterBufferCount
,
1966 const VkBuffer
*pCounterBuffers
,
1967 const VkDeviceSize
*pCounterBufferOffsets
)
1969 assert(firstCounterBuffer
+ counterBufferCount
<= IR3_MAX_SO_BUFFERS
);
1970 /* TODO do something with counter buffer? */
1973 void tu_CmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer
,
1974 uint32_t firstCounterBuffer
,
1975 uint32_t counterBufferCount
,
1976 const VkBuffer
*pCounterBuffers
,
1977 const VkDeviceSize
*pCounterBufferOffsets
)
1979 assert(firstCounterBuffer
+ counterBufferCount
<= IR3_MAX_SO_BUFFERS
);
1980 /* TODO do something with counter buffer? */
1982 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1983 cmd
->state
.streamout_enabled
= 0;
1987 tu_CmdPushConstants(VkCommandBuffer commandBuffer
,
1988 VkPipelineLayout layout
,
1989 VkShaderStageFlags stageFlags
,
1992 const void *pValues
)
1994 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1995 memcpy((void*) cmd
->push_constants
+ offset
, pValues
, size
);
1996 cmd
->state
.dirty
|= TU_CMD_DIRTY_PUSH_CONSTANTS
;
2000 tu_EndCommandBuffer(VkCommandBuffer commandBuffer
)
2002 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
2004 if (cmd_buffer
->scratch_seqno
) {
2005 tu_bo_list_add(&cmd_buffer
->bo_list
, &cmd_buffer
->scratch_bo
,
2006 MSM_SUBMIT_BO_WRITE
);
2009 if (cmd_buffer
->use_vsc_data
) {
2010 tu_bo_list_add(&cmd_buffer
->bo_list
, &cmd_buffer
->vsc_data
,
2011 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
2012 tu_bo_list_add(&cmd_buffer
->bo_list
, &cmd_buffer
->vsc_data2
,
2013 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
2016 tu_bo_list_add(&cmd_buffer
->bo_list
, &cmd_buffer
->device
->border_color
,
2017 MSM_SUBMIT_BO_READ
);
2019 for (uint32_t i
= 0; i
< cmd_buffer
->draw_cs
.bo_count
; i
++) {
2020 tu_bo_list_add(&cmd_buffer
->bo_list
, cmd_buffer
->draw_cs
.bos
[i
],
2021 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
2024 for (uint32_t i
= 0; i
< cmd_buffer
->draw_epilogue_cs
.bo_count
; i
++) {
2025 tu_bo_list_add(&cmd_buffer
->bo_list
, cmd_buffer
->draw_epilogue_cs
.bos
[i
],
2026 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
2029 for (uint32_t i
= 0; i
< cmd_buffer
->sub_cs
.bo_count
; i
++) {
2030 tu_bo_list_add(&cmd_buffer
->bo_list
, cmd_buffer
->sub_cs
.bos
[i
],
2031 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
2034 tu_cs_end(&cmd_buffer
->cs
);
2035 tu_cs_end(&cmd_buffer
->draw_cs
);
2036 tu_cs_end(&cmd_buffer
->draw_epilogue_cs
);
2038 cmd_buffer
->status
= TU_CMD_BUFFER_STATUS_EXECUTABLE
;
2040 return cmd_buffer
->record_result
;
2044 tu_CmdBindPipeline(VkCommandBuffer commandBuffer
,
2045 VkPipelineBindPoint pipelineBindPoint
,
2046 VkPipeline _pipeline
)
2048 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2049 TU_FROM_HANDLE(tu_pipeline
, pipeline
, _pipeline
);
2051 switch (pipelineBindPoint
) {
2052 case VK_PIPELINE_BIND_POINT_GRAPHICS
:
2053 cmd
->state
.pipeline
= pipeline
;
2054 cmd
->state
.dirty
|= TU_CMD_DIRTY_PIPELINE
;
2056 case VK_PIPELINE_BIND_POINT_COMPUTE
:
2057 cmd
->state
.compute_pipeline
= pipeline
;
2058 cmd
->state
.dirty
|= TU_CMD_DIRTY_COMPUTE_PIPELINE
;
2061 unreachable("unrecognized pipeline bind point");
2065 tu_bo_list_add(&cmd
->bo_list
, &pipeline
->program
.binary_bo
,
2066 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
2067 for (uint32_t i
= 0; i
< pipeline
->cs
.bo_count
; i
++) {
2068 tu_bo_list_add(&cmd
->bo_list
, pipeline
->cs
.bos
[i
],
2069 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
2074 tu_CmdSetViewport(VkCommandBuffer commandBuffer
,
2075 uint32_t firstViewport
,
2076 uint32_t viewportCount
,
2077 const VkViewport
*pViewports
)
2079 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2081 assert(firstViewport
== 0 && viewportCount
== 1);
2082 cmd
->state
.dynamic
.viewport
.viewports
[0] = pViewports
[0];
2083 cmd
->state
.dirty
|= TU_CMD_DIRTY_DYNAMIC_VIEWPORT
;
2087 tu_CmdSetScissor(VkCommandBuffer commandBuffer
,
2088 uint32_t firstScissor
,
2089 uint32_t scissorCount
,
2090 const VkRect2D
*pScissors
)
2092 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2094 assert(firstScissor
== 0 && scissorCount
== 1);
2095 cmd
->state
.dynamic
.scissor
.scissors
[0] = pScissors
[0];
2096 cmd
->state
.dirty
|= TU_CMD_DIRTY_DYNAMIC_SCISSOR
;
2100 tu_CmdSetLineWidth(VkCommandBuffer commandBuffer
, float lineWidth
)
2102 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2104 cmd
->state
.dynamic
.line_width
= lineWidth
;
2106 /* line width depends on VkPipelineRasterizationStateCreateInfo */
2107 cmd
->state
.dirty
|= TU_CMD_DIRTY_DYNAMIC_LINE_WIDTH
;
2111 tu_CmdSetDepthBias(VkCommandBuffer commandBuffer
,
2112 float depthBiasConstantFactor
,
2113 float depthBiasClamp
,
2114 float depthBiasSlopeFactor
)
2116 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2117 struct tu_cs
*draw_cs
= &cmd
->draw_cs
;
2119 tu6_emit_depth_bias(draw_cs
, depthBiasConstantFactor
, depthBiasClamp
,
2120 depthBiasSlopeFactor
);
2122 tu_cs_sanity_check(draw_cs
);
2126 tu_CmdSetBlendConstants(VkCommandBuffer commandBuffer
,
2127 const float blendConstants
[4])
2129 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2130 struct tu_cs
*draw_cs
= &cmd
->draw_cs
;
2132 tu6_emit_blend_constants(draw_cs
, blendConstants
);
2134 tu_cs_sanity_check(draw_cs
);
2138 tu_CmdSetDepthBounds(VkCommandBuffer commandBuffer
,
2139 float minDepthBounds
,
2140 float maxDepthBounds
)
2145 tu_CmdSetStencilCompareMask(VkCommandBuffer commandBuffer
,
2146 VkStencilFaceFlags faceMask
,
2147 uint32_t compareMask
)
2149 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2151 if (faceMask
& VK_STENCIL_FACE_FRONT_BIT
)
2152 cmd
->state
.dynamic
.stencil_compare_mask
.front
= compareMask
;
2153 if (faceMask
& VK_STENCIL_FACE_BACK_BIT
)
2154 cmd
->state
.dynamic
.stencil_compare_mask
.back
= compareMask
;
2156 /* the front/back compare masks must be updated together */
2157 cmd
->state
.dirty
|= TU_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
;
2161 tu_CmdSetStencilWriteMask(VkCommandBuffer commandBuffer
,
2162 VkStencilFaceFlags faceMask
,
2165 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2167 if (faceMask
& VK_STENCIL_FACE_FRONT_BIT
)
2168 cmd
->state
.dynamic
.stencil_write_mask
.front
= writeMask
;
2169 if (faceMask
& VK_STENCIL_FACE_BACK_BIT
)
2170 cmd
->state
.dynamic
.stencil_write_mask
.back
= writeMask
;
2172 /* the front/back write masks must be updated together */
2173 cmd
->state
.dirty
|= TU_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
;
2177 tu_CmdSetStencilReference(VkCommandBuffer commandBuffer
,
2178 VkStencilFaceFlags faceMask
,
2181 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2183 if (faceMask
& VK_STENCIL_FACE_FRONT_BIT
)
2184 cmd
->state
.dynamic
.stencil_reference
.front
= reference
;
2185 if (faceMask
& VK_STENCIL_FACE_BACK_BIT
)
2186 cmd
->state
.dynamic
.stencil_reference
.back
= reference
;
2188 /* the front/back references must be updated together */
2189 cmd
->state
.dirty
|= TU_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
;
2193 tu_CmdExecuteCommands(VkCommandBuffer commandBuffer
,
2194 uint32_t commandBufferCount
,
2195 const VkCommandBuffer
*pCmdBuffers
)
2197 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2200 assert(commandBufferCount
> 0);
2202 for (uint32_t i
= 0; i
< commandBufferCount
; i
++) {
2203 TU_FROM_HANDLE(tu_cmd_buffer
, secondary
, pCmdBuffers
[i
]);
2205 result
= tu_bo_list_merge(&cmd
->bo_list
, &secondary
->bo_list
);
2206 if (result
!= VK_SUCCESS
) {
2207 cmd
->record_result
= result
;
2211 if (secondary
->usage_flags
&
2212 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
) {
2213 assert(tu_cs_is_empty(&secondary
->cs
));
2215 result
= tu_cs_add_entries(&cmd
->draw_cs
, &secondary
->draw_cs
);
2216 if (result
!= VK_SUCCESS
) {
2217 cmd
->record_result
= result
;
2221 result
= tu_cs_add_entries(&cmd
->draw_epilogue_cs
,
2222 &secondary
->draw_epilogue_cs
);
2223 if (result
!= VK_SUCCESS
) {
2224 cmd
->record_result
= result
;
2228 assert(tu_cs_is_empty(&secondary
->draw_cs
));
2229 assert(tu_cs_is_empty(&secondary
->draw_epilogue_cs
));
2231 for (uint32_t j
= 0; j
< secondary
->cs
.bo_count
; j
++) {
2232 tu_bo_list_add(&cmd
->bo_list
, secondary
->cs
.bos
[j
],
2233 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
2236 tu_cs_emit_call(&cmd
->cs
, &secondary
->cs
);
2239 cmd
->state
.dirty
= ~0u; /* TODO: set dirty only what needs to be */
2243 tu_CreateCommandPool(VkDevice _device
,
2244 const VkCommandPoolCreateInfo
*pCreateInfo
,
2245 const VkAllocationCallbacks
*pAllocator
,
2246 VkCommandPool
*pCmdPool
)
2248 TU_FROM_HANDLE(tu_device
, device
, _device
);
2249 struct tu_cmd_pool
*pool
;
2251 pool
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*pool
), 8,
2252 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2254 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2257 pool
->alloc
= *pAllocator
;
2259 pool
->alloc
= device
->alloc
;
2261 list_inithead(&pool
->cmd_buffers
);
2262 list_inithead(&pool
->free_cmd_buffers
);
2264 pool
->queue_family_index
= pCreateInfo
->queueFamilyIndex
;
2266 *pCmdPool
= tu_cmd_pool_to_handle(pool
);
2272 tu_DestroyCommandPool(VkDevice _device
,
2273 VkCommandPool commandPool
,
2274 const VkAllocationCallbacks
*pAllocator
)
2276 TU_FROM_HANDLE(tu_device
, device
, _device
);
2277 TU_FROM_HANDLE(tu_cmd_pool
, pool
, commandPool
);
2282 list_for_each_entry_safe(struct tu_cmd_buffer
, cmd_buffer
,
2283 &pool
->cmd_buffers
, pool_link
)
2285 tu_cmd_buffer_destroy(cmd_buffer
);
2288 list_for_each_entry_safe(struct tu_cmd_buffer
, cmd_buffer
,
2289 &pool
->free_cmd_buffers
, pool_link
)
2291 tu_cmd_buffer_destroy(cmd_buffer
);
2294 vk_free2(&device
->alloc
, pAllocator
, pool
);
2298 tu_ResetCommandPool(VkDevice device
,
2299 VkCommandPool commandPool
,
2300 VkCommandPoolResetFlags flags
)
2302 TU_FROM_HANDLE(tu_cmd_pool
, pool
, commandPool
);
2305 list_for_each_entry(struct tu_cmd_buffer
, cmd_buffer
, &pool
->cmd_buffers
,
2308 result
= tu_reset_cmd_buffer(cmd_buffer
);
2309 if (result
!= VK_SUCCESS
)
2317 tu_TrimCommandPool(VkDevice device
,
2318 VkCommandPool commandPool
,
2319 VkCommandPoolTrimFlags flags
)
2321 TU_FROM_HANDLE(tu_cmd_pool
, pool
, commandPool
);
2326 list_for_each_entry_safe(struct tu_cmd_buffer
, cmd_buffer
,
2327 &pool
->free_cmd_buffers
, pool_link
)
2329 tu_cmd_buffer_destroy(cmd_buffer
);
2334 tu_CmdBeginRenderPass(VkCommandBuffer commandBuffer
,
2335 const VkRenderPassBeginInfo
*pRenderPassBegin
,
2336 VkSubpassContents contents
)
2338 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2339 TU_FROM_HANDLE(tu_render_pass
, pass
, pRenderPassBegin
->renderPass
);
2340 TU_FROM_HANDLE(tu_framebuffer
, fb
, pRenderPassBegin
->framebuffer
);
2342 cmd
->state
.pass
= pass
;
2343 cmd
->state
.subpass
= pass
->subpasses
;
2344 cmd
->state
.framebuffer
= fb
;
2346 tu_cmd_update_tiling_config(cmd
, &pRenderPassBegin
->renderArea
);
2347 tu_cmd_prepare_tile_store_ib(cmd
);
2349 tu_emit_load_clear(cmd
, pRenderPassBegin
);
2351 tu6_emit_zs(cmd
, cmd
->state
.subpass
, &cmd
->draw_cs
);
2352 tu6_emit_mrt(cmd
, cmd
->state
.subpass
, &cmd
->draw_cs
);
2353 tu6_emit_msaa(&cmd
->draw_cs
, cmd
->state
.subpass
->samples
);
2354 tu6_emit_render_cntl(cmd
, cmd
->state
.subpass
, &cmd
->draw_cs
, false);
2356 /* note: use_hw_binning only checks tiling config */
2357 if (use_hw_binning(cmd
))
2358 cmd
->use_vsc_data
= true;
2360 for (uint32_t i
= 0; i
< fb
->attachment_count
; ++i
) {
2361 const struct tu_image_view
*iview
= fb
->attachments
[i
].attachment
;
2362 tu_bo_list_add(&cmd
->bo_list
, iview
->image
->bo
,
2363 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
2366 /* Flag input attachment descriptors for re-emission if necessary */
2367 cmd
->state
.dirty
|= TU_CMD_DIRTY_INPUT_ATTACHMENTS
;
2371 tu_CmdBeginRenderPass2(VkCommandBuffer commandBuffer
,
2372 const VkRenderPassBeginInfo
*pRenderPassBeginInfo
,
2373 const VkSubpassBeginInfoKHR
*pSubpassBeginInfo
)
2375 tu_CmdBeginRenderPass(commandBuffer
, pRenderPassBeginInfo
,
2376 pSubpassBeginInfo
->contents
);
2380 tu_CmdNextSubpass(VkCommandBuffer commandBuffer
, VkSubpassContents contents
)
2382 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2383 const struct tu_render_pass
*pass
= cmd
->state
.pass
;
2384 struct tu_cs
*cs
= &cmd
->draw_cs
;
2386 const struct tu_subpass
*subpass
= cmd
->state
.subpass
++;
2388 tu_cond_exec_start(cs
, CP_COND_EXEC_0_RENDER_MODE_GMEM
);
2390 if (subpass
->resolve_attachments
) {
2391 for (unsigned i
= 0; i
< subpass
->color_count
; i
++) {
2392 uint32_t a
= subpass
->resolve_attachments
[i
].attachment
;
2393 if (a
== VK_ATTACHMENT_UNUSED
)
2396 tu_store_gmem_attachment(cmd
, cs
, a
,
2397 subpass
->color_attachments
[i
].attachment
);
2399 if (pass
->attachments
[a
].gmem_offset
< 0)
2403 * check if the resolved attachment is needed by later subpasses,
2404 * if it is, should be doing a GMEM->GMEM resolve instead of GMEM->MEM->GMEM..
2406 tu_finishme("missing GMEM->GMEM resolve path\n");
2407 tu_emit_load_gmem_attachment(cmd
, cs
, a
);
2411 tu_cond_exec_end(cs
);
2413 tu_cond_exec_start(cs
, CP_COND_EXEC_0_RENDER_MODE_SYSMEM
);
2415 /* Emit flushes so that input attachments will read the correct value.
2416 * TODO: use subpass dependencies to flush or not
2418 tu6_emit_event_write(cmd
, cs
, PC_CCU_FLUSH_COLOR_TS
, true);
2419 tu6_emit_event_write(cmd
, cs
, PC_CCU_FLUSH_DEPTH_TS
, true);
2421 if (subpass
->resolve_attachments
) {
2422 tu6_emit_event_write(cmd
, cs
, CACHE_INVALIDATE
, false);
2424 for (unsigned i
= 0; i
< subpass
->color_count
; i
++) {
2425 uint32_t a
= subpass
->resolve_attachments
[i
].attachment
;
2426 if (a
== VK_ATTACHMENT_UNUSED
)
2429 tu6_emit_sysmem_resolve(cmd
, cs
, a
,
2430 subpass
->color_attachments
[i
].attachment
);
2433 tu6_emit_event_write(cmd
, cs
, PC_CCU_FLUSH_COLOR_TS
, true);
2436 tu_cond_exec_end(cs
);
2438 /* subpass->input_count > 0 then texture cache invalidate is likely to be needed */
2439 if (cmd
->state
.subpass
->input_count
)
2440 tu6_emit_event_write(cmd
, cs
, CACHE_INVALIDATE
, false);
2442 /* emit mrt/zs/msaa/ubwc state for the subpass that is starting */
2443 tu6_emit_zs(cmd
, cmd
->state
.subpass
, cs
);
2444 tu6_emit_mrt(cmd
, cmd
->state
.subpass
, cs
);
2445 tu6_emit_msaa(cs
, cmd
->state
.subpass
->samples
);
2446 tu6_emit_render_cntl(cmd
, cmd
->state
.subpass
, cs
, false);
2448 /* Flag input attachment descriptors for re-emission if necessary */
2449 cmd
->state
.dirty
|= TU_CMD_DIRTY_INPUT_ATTACHMENTS
;
2453 tu_CmdNextSubpass2(VkCommandBuffer commandBuffer
,
2454 const VkSubpassBeginInfoKHR
*pSubpassBeginInfo
,
2455 const VkSubpassEndInfoKHR
*pSubpassEndInfo
)
2457 tu_CmdNextSubpass(commandBuffer
, pSubpassBeginInfo
->contents
);
2463 * Number of vertices.
2468 * Index of the first vertex.
2470 int32_t vertex_offset
;
2473 * First instance id.
2475 uint32_t first_instance
;
2478 * Number of instances.
2480 uint32_t instance_count
;
2483 * First index (indexed draws only).
2485 uint32_t first_index
;
2488 * Whether it's an indexed draw.
2493 * Indirect draw parameters resource.
2495 struct tu_buffer
*indirect
;
2496 uint64_t indirect_offset
;
2500 * Draw count parameters resource.
2502 struct tu_buffer
*count_buffer
;
2503 uint64_t count_buffer_offset
;
2506 * Stream output parameters resource.
2508 struct tu_buffer
*streamout_buffer
;
2509 uint64_t streamout_buffer_offset
;
2512 #define ENABLE_ALL (CP_SET_DRAW_STATE__0_BINNING | CP_SET_DRAW_STATE__0_GMEM | CP_SET_DRAW_STATE__0_SYSMEM)
2513 #define ENABLE_DRAW (CP_SET_DRAW_STATE__0_GMEM | CP_SET_DRAW_STATE__0_SYSMEM)
2514 #define ENABLE_NON_GMEM (CP_SET_DRAW_STATE__0_BINNING | CP_SET_DRAW_STATE__0_SYSMEM)
2516 enum tu_draw_state_group_id
2518 TU_DRAW_STATE_PROGRAM
,
2519 TU_DRAW_STATE_PROGRAM_BINNING
,
2521 TU_DRAW_STATE_VI_BINNING
,
2525 TU_DRAW_STATE_BLEND
,
2526 TU_DRAW_STATE_VS_CONST
,
2527 TU_DRAW_STATE_FS_CONST
,
2528 TU_DRAW_STATE_DESC_SETS
,
2529 TU_DRAW_STATE_DESC_SETS_GMEM
,
2530 TU_DRAW_STATE_DESC_SETS_LOAD
,
2531 TU_DRAW_STATE_VS_PARAMS
,
2533 TU_DRAW_STATE_COUNT
,
2536 struct tu_draw_state_group
2538 enum tu_draw_state_group_id id
;
2539 uint32_t enable_mask
;
2540 struct tu_cs_entry ib
;
2543 static inline uint32_t
2544 tu6_stage2opcode(gl_shader_stage type
)
2547 case MESA_SHADER_VERTEX
:
2548 case MESA_SHADER_TESS_CTRL
:
2549 case MESA_SHADER_TESS_EVAL
:
2550 case MESA_SHADER_GEOMETRY
:
2551 return CP_LOAD_STATE6_GEOM
;
2552 case MESA_SHADER_FRAGMENT
:
2553 case MESA_SHADER_COMPUTE
:
2554 case MESA_SHADER_KERNEL
:
2555 return CP_LOAD_STATE6_FRAG
;
2557 unreachable("bad shader type");
2561 static inline enum a6xx_state_block
2562 tu6_stage2shadersb(gl_shader_stage type
)
2565 case MESA_SHADER_VERTEX
:
2566 return SB6_VS_SHADER
;
2567 case MESA_SHADER_FRAGMENT
:
2568 return SB6_FS_SHADER
;
2569 case MESA_SHADER_COMPUTE
:
2570 case MESA_SHADER_KERNEL
:
2571 return SB6_CS_SHADER
;
2573 unreachable("bad shader type");
2579 tu6_emit_user_consts(struct tu_cs
*cs
, const struct tu_pipeline
*pipeline
,
2580 struct tu_descriptor_state
*descriptors_state
,
2581 gl_shader_stage type
,
2582 uint32_t *push_constants
)
2584 const struct tu_program_descriptor_linkage
*link
=
2585 &pipeline
->program
.link
[type
];
2586 const struct ir3_ubo_analysis_state
*state
= &link
->ubo_state
;
2588 if (link
->push_consts
.count
> 0) {
2589 unsigned num_units
= link
->push_consts
.count
;
2590 unsigned offset
= link
->push_consts
.lo
;
2591 tu_cs_emit_pkt7(cs
, tu6_stage2opcode(type
), 3 + num_units
* 4);
2592 tu_cs_emit(cs
, CP_LOAD_STATE6_0_DST_OFF(offset
) |
2593 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
2594 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
2595 CP_LOAD_STATE6_0_STATE_BLOCK(tu6_stage2shadersb(type
)) |
2596 CP_LOAD_STATE6_0_NUM_UNIT(num_units
));
2599 for (unsigned i
= 0; i
< num_units
* 4; i
++)
2600 tu_cs_emit(cs
, push_constants
[i
+ offset
* 4]);
2603 for (uint32_t i
= 0; i
< state
->num_enabled
; i
++) {
2604 uint32_t size
= state
->range
[i
].end
- state
->range
[i
].start
;
2605 uint32_t offset
= state
->range
[i
].start
;
2607 /* and even if the start of the const buffer is before
2608 * first_immediate, the end may not be:
2610 size
= MIN2(size
, (16 * link
->constlen
) - state
->range
[i
].offset
);
2615 /* things should be aligned to vec4: */
2616 debug_assert((state
->range
[i
].offset
% 16) == 0);
2617 debug_assert((size
% 16) == 0);
2618 debug_assert((offset
% 16) == 0);
2620 /* Dig out the descriptor from the descriptor state and read the VA from
2623 assert(state
->range
[i
].bindless
);
2624 uint32_t *base
= state
->range
[i
].bindless_base
== MAX_SETS
?
2625 descriptors_state
->dynamic_descriptors
:
2626 descriptors_state
->sets
[state
->range
[i
].bindless_base
]->mapped_ptr
;
2627 unsigned block
= state
->range
[i
].block
;
2628 /* If the block in the shader here is in the dynamic descriptor set, it
2629 * is an index into the dynamic descriptor set which is combined from
2630 * dynamic descriptors and input attachments on-the-fly, and we don't
2631 * have access to it here. Instead we work backwards to get the index
2632 * into dynamic_descriptors.
2634 if (state
->range
[i
].bindless_base
== MAX_SETS
)
2635 block
-= pipeline
->layout
->input_attachment_count
;
2636 uint32_t *desc
= base
+ block
* A6XX_TEX_CONST_DWORDS
;
2637 uint64_t va
= desc
[0] | ((uint64_t)(desc
[1] & A6XX_UBO_1_BASE_HI__MASK
) << 32);
2640 tu_cs_emit_pkt7(cs
, tu6_stage2opcode(type
), 3);
2641 tu_cs_emit(cs
, CP_LOAD_STATE6_0_DST_OFF(state
->range
[i
].offset
/ 16) |
2642 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
2643 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
2644 CP_LOAD_STATE6_0_STATE_BLOCK(tu6_stage2shadersb(type
)) |
2645 CP_LOAD_STATE6_0_NUM_UNIT(size
/ 16));
2646 tu_cs_emit_qw(cs
, va
+ offset
);
2650 static struct tu_cs_entry
2651 tu6_emit_consts(struct tu_cmd_buffer
*cmd
,
2652 const struct tu_pipeline
*pipeline
,
2653 struct tu_descriptor_state
*descriptors_state
,
2654 gl_shader_stage type
)
2657 tu_cs_begin_sub_stream(&cmd
->sub_cs
, 512, &cs
); /* TODO: maximum size? */
2659 tu6_emit_user_consts(&cs
, pipeline
, descriptors_state
, type
, cmd
->push_constants
);
2661 return tu_cs_end_sub_stream(&cmd
->sub_cs
, &cs
);
2665 tu6_emit_vs_params(struct tu_cmd_buffer
*cmd
,
2666 const struct tu_draw_info
*draw
,
2667 struct tu_cs_entry
*entry
)
2669 /* TODO: fill out more than just base instance */
2670 const struct tu_program_descriptor_linkage
*link
=
2671 &cmd
->state
.pipeline
->program
.link
[MESA_SHADER_VERTEX
];
2672 const struct ir3_const_state
*const_state
= &link
->const_state
;
2675 if (const_state
->offsets
.driver_param
>= link
->constlen
) {
2676 *entry
= (struct tu_cs_entry
) {};
2680 VkResult result
= tu_cs_begin_sub_stream(&cmd
->sub_cs
, 8, &cs
);
2681 if (result
!= VK_SUCCESS
)
2684 tu_cs_emit_pkt7(&cs
, CP_LOAD_STATE6_GEOM
, 3 + 4);
2685 tu_cs_emit(&cs
, CP_LOAD_STATE6_0_DST_OFF(const_state
->offsets
.driver_param
) |
2686 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
2687 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
2688 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_VS_SHADER
) |
2689 CP_LOAD_STATE6_0_NUM_UNIT(1));
2693 STATIC_ASSERT(IR3_DP_INSTID_BASE
== 2);
2697 tu_cs_emit(&cs
, draw
->first_instance
);
2700 *entry
= tu_cs_end_sub_stream(&cmd
->sub_cs
, &cs
);
2705 tu6_emit_descriptor_sets(struct tu_cmd_buffer
*cmd
,
2706 const struct tu_pipeline
*pipeline
,
2707 VkPipelineBindPoint bind_point
,
2708 struct tu_cs_entry
*entry
,
2711 struct tu_cs
*draw_state
= &cmd
->sub_cs
;
2712 struct tu_pipeline_layout
*layout
= pipeline
->layout
;
2713 struct tu_descriptor_state
*descriptors_state
=
2714 tu_get_descriptors_state(cmd
, bind_point
);
2715 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
2716 const uint32_t *input_attachment_idx
=
2717 pipeline
->program
.input_attachment_idx
;
2718 uint32_t num_dynamic_descs
= layout
->dynamic_offset_count
+
2719 layout
->input_attachment_count
;
2720 struct ts_cs_memory dynamic_desc_set
;
2723 if (num_dynamic_descs
> 0) {
2724 /* allocate and fill out dynamic descriptor set */
2725 result
= tu_cs_alloc(draw_state
, num_dynamic_descs
,
2726 A6XX_TEX_CONST_DWORDS
, &dynamic_desc_set
);
2727 if (result
!= VK_SUCCESS
)
2730 memcpy(dynamic_desc_set
.map
, descriptors_state
->input_attachments
,
2731 layout
->input_attachment_count
* A6XX_TEX_CONST_DWORDS
* 4);
2734 /* Patch input attachments to refer to GMEM instead */
2735 for (unsigned i
= 0; i
< layout
->input_attachment_count
; i
++) {
2737 &dynamic_desc_set
.map
[A6XX_TEX_CONST_DWORDS
* i
];
2739 /* The compiler has already laid out input_attachment_idx in the
2740 * final order of input attachments, so there's no need to go
2741 * through the pipeline layout finding input attachments.
2743 unsigned attachment_idx
= input_attachment_idx
[i
];
2745 /* It's possible for the pipeline layout to include an input
2746 * attachment which doesn't actually exist for the current
2747 * subpass. Of course, this is only valid so long as the pipeline
2748 * doesn't try to actually load that attachment. Just skip
2749 * patching in that scenario to avoid out-of-bounds accesses.
2751 if (attachment_idx
>= cmd
->state
.subpass
->input_count
)
2754 uint32_t a
= cmd
->state
.subpass
->input_attachments
[attachment_idx
].attachment
;
2755 const struct tu_render_pass_attachment
*att
= &cmd
->state
.pass
->attachments
[a
];
2757 assert(att
->gmem_offset
>= 0);
2759 dst
[0] &= ~(A6XX_TEX_CONST_0_SWAP__MASK
| A6XX_TEX_CONST_0_TILE_MODE__MASK
);
2760 dst
[0] |= A6XX_TEX_CONST_0_TILE_MODE(TILE6_2
);
2761 dst
[2] &= ~(A6XX_TEX_CONST_2_TYPE__MASK
| A6XX_TEX_CONST_2_PITCH__MASK
);
2763 A6XX_TEX_CONST_2_TYPE(A6XX_TEX_2D
) |
2764 A6XX_TEX_CONST_2_PITCH(tiling
->tile0
.extent
.width
* att
->cpp
);
2766 dst
[4] = cmd
->device
->physical_device
->gmem_base
+ att
->gmem_offset
;
2767 dst
[5] = A6XX_TEX_CONST_5_DEPTH(1);
2768 for (unsigned i
= 6; i
< A6XX_TEX_CONST_DWORDS
; i
++)
2771 if (cmd
->level
== VK_COMMAND_BUFFER_LEVEL_SECONDARY
)
2772 tu_finishme("patch input attachment pitch for secondary cmd buffer");
2776 memcpy(dynamic_desc_set
.map
+ layout
->input_attachment_count
* A6XX_TEX_CONST_DWORDS
,
2777 descriptors_state
->dynamic_descriptors
,
2778 layout
->dynamic_offset_count
* A6XX_TEX_CONST_DWORDS
* 4);
2781 uint32_t sp_bindless_base_reg
, hlsq_bindless_base_reg
;
2782 uint32_t hlsq_update_value
;
2783 switch (bind_point
) {
2784 case VK_PIPELINE_BIND_POINT_GRAPHICS
:
2785 sp_bindless_base_reg
= REG_A6XX_SP_BINDLESS_BASE(0);
2786 hlsq_bindless_base_reg
= REG_A6XX_HLSQ_BINDLESS_BASE(0);
2787 hlsq_update_value
= 0x7c000;
2789 case VK_PIPELINE_BIND_POINT_COMPUTE
:
2790 sp_bindless_base_reg
= REG_A6XX_SP_CS_BINDLESS_BASE(0);
2791 hlsq_bindless_base_reg
= REG_A6XX_HLSQ_CS_BINDLESS_BASE(0);
2792 hlsq_update_value
= 0x3e00;
2795 unreachable("bad bind point");
2798 /* Be careful here to *not* refer to the pipeline, so that if only the
2799 * pipeline changes we don't have to emit this again (except if there are
2800 * dynamic descriptors in the pipeline layout). This means always emitting
2801 * all the valid descriptors, which means that we always have to put the
2802 * dynamic descriptor in the driver-only slot at the end
2804 uint32_t num_user_sets
= util_last_bit(descriptors_state
->valid
);
2805 uint32_t num_sets
= num_user_sets
;
2806 if (num_dynamic_descs
> 0) {
2807 num_user_sets
= MAX_SETS
;
2808 num_sets
= num_user_sets
+ 1;
2811 unsigned regs
[2] = { sp_bindless_base_reg
, hlsq_bindless_base_reg
};
2814 result
= tu_cs_begin_sub_stream(draw_state
, ARRAY_SIZE(regs
) * (1 + num_sets
* 2) + 2, &cs
);
2815 if (result
!= VK_SUCCESS
)
2819 for (unsigned i
= 0; i
< ARRAY_SIZE(regs
); i
++) {
2820 tu_cs_emit_pkt4(&cs
, regs
[i
], num_sets
* 2);
2821 for (unsigned j
= 0; j
< num_user_sets
; j
++) {
2822 if (descriptors_state
->valid
& (1 << j
)) {
2823 /* magic | 3 copied from the blob */
2824 tu_cs_emit_qw(&cs
, descriptors_state
->sets
[j
]->va
| 3);
2826 tu_cs_emit_qw(&cs
, 0 | 3);
2829 if (num_dynamic_descs
> 0) {
2830 tu_cs_emit_qw(&cs
, dynamic_desc_set
.iova
| 3);
2834 tu_cs_emit_regs(&cs
, A6XX_HLSQ_UPDATE_CNTL(hlsq_update_value
));
2837 *entry
= tu_cs_end_sub_stream(draw_state
, &cs
);
2842 tu6_emit_streamout(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
2844 struct tu_streamout_state
*tf
= &cmd
->state
.pipeline
->streamout
;
2846 for (unsigned i
= 0; i
< IR3_MAX_SO_BUFFERS
; i
++) {
2847 struct tu_buffer
*buf
= cmd
->state
.streamout_buf
.buffers
[i
];
2852 offset
= cmd
->state
.streamout_buf
.offsets
[i
];
2854 tu_cs_emit_regs(cs
, A6XX_VPC_SO_BUFFER_BASE(i
, .bo
= buf
->bo
,
2855 .bo_offset
= buf
->bo_offset
));
2856 tu_cs_emit_regs(cs
, A6XX_VPC_SO_BUFFER_SIZE(i
, buf
->size
));
2858 if (cmd
->state
.streamout_reset
& (1 << i
)) {
2859 offset
*= tf
->stride
[i
];
2861 tu_cs_emit_regs(cs
, A6XX_VPC_SO_BUFFER_OFFSET(i
, offset
));
2862 cmd
->state
.streamout_reset
&= ~(1 << i
);
2864 tu_cs_emit_pkt7(cs
, CP_MEM_TO_REG
, 3);
2865 tu_cs_emit(cs
, CP_MEM_TO_REG_0_REG(REG_A6XX_VPC_SO_BUFFER_OFFSET(i
)) |
2866 CP_MEM_TO_REG_0_SHIFT_BY_2
| CP_MEM_TO_REG_0_UNK31
|
2867 CP_MEM_TO_REG_0_CNT(0));
2868 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+
2869 ctrl_offset(flush_base
[i
].offset
));
2872 tu_cs_emit_regs(cs
, A6XX_VPC_SO_FLUSH_BASE(i
, .bo
= &cmd
->scratch_bo
,
2874 ctrl_offset(flush_base
[i
])));
2877 if (cmd
->state
.streamout_enabled
) {
2878 tu_cs_emit_pkt7(cs
, CP_CONTEXT_REG_BUNCH
, 12 + (2 * tf
->prog_count
));
2879 tu_cs_emit(cs
, REG_A6XX_VPC_SO_BUF_CNTL
);
2880 tu_cs_emit(cs
, tf
->vpc_so_buf_cntl
);
2881 tu_cs_emit(cs
, REG_A6XX_VPC_SO_NCOMP(0));
2882 tu_cs_emit(cs
, tf
->ncomp
[0]);
2883 tu_cs_emit(cs
, REG_A6XX_VPC_SO_NCOMP(1));
2884 tu_cs_emit(cs
, tf
->ncomp
[1]);
2885 tu_cs_emit(cs
, REG_A6XX_VPC_SO_NCOMP(2));
2886 tu_cs_emit(cs
, tf
->ncomp
[2]);
2887 tu_cs_emit(cs
, REG_A6XX_VPC_SO_NCOMP(3));
2888 tu_cs_emit(cs
, tf
->ncomp
[3]);
2889 tu_cs_emit(cs
, REG_A6XX_VPC_SO_CNTL
);
2890 tu_cs_emit(cs
, A6XX_VPC_SO_CNTL_ENABLE
);
2891 for (unsigned i
= 0; i
< tf
->prog_count
; i
++) {
2892 tu_cs_emit(cs
, REG_A6XX_VPC_SO_PROG
);
2893 tu_cs_emit(cs
, tf
->prog
[i
]);
2896 tu_cs_emit_pkt7(cs
, CP_CONTEXT_REG_BUNCH
, 4);
2897 tu_cs_emit(cs
, REG_A6XX_VPC_SO_CNTL
);
2899 tu_cs_emit(cs
, REG_A6XX_VPC_SO_BUF_CNTL
);
2905 tu6_bind_draw_states(struct tu_cmd_buffer
*cmd
,
2907 const struct tu_draw_info
*draw
)
2909 const struct tu_pipeline
*pipeline
= cmd
->state
.pipeline
;
2910 const struct tu_dynamic_state
*dynamic
= &cmd
->state
.dynamic
;
2911 struct tu_draw_state_group draw_state_groups
[TU_DRAW_STATE_COUNT
];
2912 uint32_t draw_state_group_count
= 0;
2915 struct tu_descriptor_state
*descriptors_state
=
2916 &cmd
->descriptors
[VK_PIPELINE_BIND_POINT_GRAPHICS
];
2921 A6XX_PC_PRIMITIVE_CNTL_0(.primitive_restart
=
2922 pipeline
->ia
.primitive_restart
&& draw
->indexed
));
2924 if (cmd
->state
.dirty
&
2925 (TU_CMD_DIRTY_PIPELINE
| TU_CMD_DIRTY_DYNAMIC_LINE_WIDTH
) &&
2926 (pipeline
->dynamic_state
.mask
& TU_DYNAMIC_LINE_WIDTH
)) {
2927 tu6_emit_gras_su_cntl(cs
, pipeline
->rast
.gras_su_cntl
,
2928 dynamic
->line_width
);
2931 if ((cmd
->state
.dirty
& TU_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
) &&
2932 (pipeline
->dynamic_state
.mask
& TU_DYNAMIC_STENCIL_COMPARE_MASK
)) {
2933 tu6_emit_stencil_compare_mask(cs
, dynamic
->stencil_compare_mask
.front
,
2934 dynamic
->stencil_compare_mask
.back
);
2937 if ((cmd
->state
.dirty
& TU_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
) &&
2938 (pipeline
->dynamic_state
.mask
& TU_DYNAMIC_STENCIL_WRITE_MASK
)) {
2939 tu6_emit_stencil_write_mask(cs
, dynamic
->stencil_write_mask
.front
,
2940 dynamic
->stencil_write_mask
.back
);
2943 if ((cmd
->state
.dirty
& TU_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
) &&
2944 (pipeline
->dynamic_state
.mask
& TU_DYNAMIC_STENCIL_REFERENCE
)) {
2945 tu6_emit_stencil_reference(cs
, dynamic
->stencil_reference
.front
,
2946 dynamic
->stencil_reference
.back
);
2949 if ((cmd
->state
.dirty
& TU_CMD_DIRTY_DYNAMIC_VIEWPORT
) &&
2950 (pipeline
->dynamic_state
.mask
& TU_DYNAMIC_VIEWPORT
)) {
2951 tu6_emit_viewport(cs
, &cmd
->state
.dynamic
.viewport
.viewports
[0]);
2954 if ((cmd
->state
.dirty
& TU_CMD_DIRTY_DYNAMIC_SCISSOR
) &&
2955 (pipeline
->dynamic_state
.mask
& TU_DYNAMIC_SCISSOR
)) {
2956 tu6_emit_scissor(cs
, &cmd
->state
.dynamic
.scissor
.scissors
[0]);
2959 if (cmd
->state
.dirty
&
2960 (TU_CMD_DIRTY_PIPELINE
| TU_CMD_DIRTY_VERTEX_BUFFERS
)) {
2961 for (uint32_t i
= 0; i
< pipeline
->vi
.count
; i
++) {
2962 const uint32_t binding
= pipeline
->vi
.bindings
[i
];
2963 const struct tu_buffer
*buf
= cmd
->state
.vb
.buffers
[binding
];
2964 const VkDeviceSize offset
= buf
->bo_offset
+
2965 cmd
->state
.vb
.offsets
[binding
];
2966 const VkDeviceSize size
=
2967 offset
< buf
->size
? buf
->size
- offset
: 0;
2970 A6XX_VFD_FETCH_BASE(i
, .bo
= buf
->bo
, .bo_offset
= offset
),
2971 A6XX_VFD_FETCH_SIZE(i
, size
));
2975 if (cmd
->state
.dirty
& TU_CMD_DIRTY_PIPELINE
) {
2976 draw_state_groups
[draw_state_group_count
++] =
2977 (struct tu_draw_state_group
) {
2978 .id
= TU_DRAW_STATE_PROGRAM
,
2979 .enable_mask
= ENABLE_DRAW
,
2980 .ib
= pipeline
->program
.state_ib
,
2982 draw_state_groups
[draw_state_group_count
++] =
2983 (struct tu_draw_state_group
) {
2984 .id
= TU_DRAW_STATE_PROGRAM_BINNING
,
2985 .enable_mask
= CP_SET_DRAW_STATE__0_BINNING
,
2986 .ib
= pipeline
->program
.binning_state_ib
,
2988 draw_state_groups
[draw_state_group_count
++] =
2989 (struct tu_draw_state_group
) {
2990 .id
= TU_DRAW_STATE_VI
,
2991 .enable_mask
= ENABLE_DRAW
,
2992 .ib
= pipeline
->vi
.state_ib
,
2994 draw_state_groups
[draw_state_group_count
++] =
2995 (struct tu_draw_state_group
) {
2996 .id
= TU_DRAW_STATE_VI_BINNING
,
2997 .enable_mask
= CP_SET_DRAW_STATE__0_BINNING
,
2998 .ib
= pipeline
->vi
.binning_state_ib
,
3000 draw_state_groups
[draw_state_group_count
++] =
3001 (struct tu_draw_state_group
) {
3002 .id
= TU_DRAW_STATE_VP
,
3003 .enable_mask
= ENABLE_ALL
,
3004 .ib
= pipeline
->vp
.state_ib
,
3006 draw_state_groups
[draw_state_group_count
++] =
3007 (struct tu_draw_state_group
) {
3008 .id
= TU_DRAW_STATE_RAST
,
3009 .enable_mask
= ENABLE_ALL
,
3010 .ib
= pipeline
->rast
.state_ib
,
3012 draw_state_groups
[draw_state_group_count
++] =
3013 (struct tu_draw_state_group
) {
3014 .id
= TU_DRAW_STATE_DS
,
3015 .enable_mask
= ENABLE_ALL
,
3016 .ib
= pipeline
->ds
.state_ib
,
3018 draw_state_groups
[draw_state_group_count
++] =
3019 (struct tu_draw_state_group
) {
3020 .id
= TU_DRAW_STATE_BLEND
,
3021 .enable_mask
= ENABLE_ALL
,
3022 .ib
= pipeline
->blend
.state_ib
,
3026 if (cmd
->state
.dirty
&
3027 (TU_CMD_DIRTY_PIPELINE
| TU_CMD_DIRTY_DESCRIPTOR_SETS
| TU_CMD_DIRTY_PUSH_CONSTANTS
)) {
3028 draw_state_groups
[draw_state_group_count
++] =
3029 (struct tu_draw_state_group
) {
3030 .id
= TU_DRAW_STATE_VS_CONST
,
3031 .enable_mask
= ENABLE_ALL
,
3032 .ib
= tu6_emit_consts(cmd
, pipeline
, descriptors_state
, MESA_SHADER_VERTEX
)
3034 draw_state_groups
[draw_state_group_count
++] =
3035 (struct tu_draw_state_group
) {
3036 .id
= TU_DRAW_STATE_FS_CONST
,
3037 .enable_mask
= ENABLE_DRAW
,
3038 .ib
= tu6_emit_consts(cmd
, pipeline
, descriptors_state
, MESA_SHADER_FRAGMENT
)
3042 if (cmd
->state
.dirty
& TU_CMD_DIRTY_STREAMOUT_BUFFERS
)
3043 tu6_emit_streamout(cmd
, cs
);
3045 /* If there are any any dynamic descriptors, then we may need to re-emit
3046 * them after every pipeline change in case the number of input attachments
3047 * changes. We also always need to re-emit after a pipeline change if there
3048 * are any input attachments, because the input attachment index comes from
3049 * the pipeline. Finally, it can also happen that the subpass changes
3050 * without the pipeline changing, in which case the GMEM descriptors need
3051 * to be patched differently.
3053 * TODO: We could probably be clever and avoid re-emitting state on
3054 * pipeline changes if the number of input attachments is always 0. We
3055 * could also only re-emit dynamic state.
3057 if (cmd
->state
.dirty
& TU_CMD_DIRTY_DESCRIPTOR_SETS
||
3058 ((pipeline
->layout
->dynamic_offset_count
+
3059 pipeline
->layout
->input_attachment_count
> 0) &&
3060 cmd
->state
.dirty
& TU_CMD_DIRTY_PIPELINE
) ||
3061 (pipeline
->layout
->input_attachment_count
> 0 &&
3062 cmd
->state
.dirty
& TU_CMD_DIRTY_INPUT_ATTACHMENTS
)) {
3063 struct tu_cs_entry desc_sets
, desc_sets_gmem
;
3064 bool need_gmem_desc_set
= pipeline
->layout
->input_attachment_count
> 0;
3066 result
= tu6_emit_descriptor_sets(cmd
, pipeline
,
3067 VK_PIPELINE_BIND_POINT_GRAPHICS
,
3069 if (result
!= VK_SUCCESS
)
3072 draw_state_groups
[draw_state_group_count
++] =
3073 (struct tu_draw_state_group
) {
3074 .id
= TU_DRAW_STATE_DESC_SETS
,
3075 .enable_mask
= need_gmem_desc_set
? ENABLE_NON_GMEM
: ENABLE_ALL
,
3079 if (need_gmem_desc_set
) {
3080 result
= tu6_emit_descriptor_sets(cmd
, pipeline
,
3081 VK_PIPELINE_BIND_POINT_GRAPHICS
,
3082 &desc_sets_gmem
, true);
3083 if (result
!= VK_SUCCESS
)
3086 draw_state_groups
[draw_state_group_count
++] =
3087 (struct tu_draw_state_group
) {
3088 .id
= TU_DRAW_STATE_DESC_SETS_GMEM
,
3089 .enable_mask
= CP_SET_DRAW_STATE__0_GMEM
,
3090 .ib
= desc_sets_gmem
,
3094 /* We need to reload the descriptors every time the descriptor sets
3095 * change. However, the commands we send only depend on the pipeline
3096 * because the whole point is to cache descriptors which are used by the
3097 * pipeline. There's a problem here, in that the firmware has an
3098 * "optimization" which skips executing groups that are set to the same
3099 * value as the last draw. This means that if the descriptor sets change
3100 * but not the pipeline, we'd try to re-execute the same buffer which
3101 * the firmware would ignore and we wouldn't pre-load the new
3102 * descriptors. The blob seems to re-emit the LOAD_STATE group whenever
3103 * the descriptor sets change, which we emulate here by copying the
3104 * pre-prepared buffer.
3106 const struct tu_cs_entry
*load_entry
= &pipeline
->load_state
.state_ib
;
3107 if (load_entry
->size
> 0) {
3108 struct tu_cs load_cs
;
3109 result
= tu_cs_begin_sub_stream(&cmd
->sub_cs
, load_entry
->size
, &load_cs
);
3110 if (result
!= VK_SUCCESS
)
3112 tu_cs_emit_array(&load_cs
,
3113 (uint32_t *)((char *)load_entry
->bo
->map
+ load_entry
->offset
),
3114 load_entry
->size
/ 4);
3115 struct tu_cs_entry load_copy
= tu_cs_end_sub_stream(&cmd
->sub_cs
, &load_cs
);
3117 draw_state_groups
[draw_state_group_count
++] =
3118 (struct tu_draw_state_group
) {
3119 .id
= TU_DRAW_STATE_DESC_SETS_LOAD
,
3120 /* The blob seems to not enable this for binning, even when
3121 * resources would actually be used in the binning shader.
3122 * Presumably the overhead of prefetching the resources isn't
3125 .enable_mask
= ENABLE_DRAW
,
3131 struct tu_cs_entry vs_params
;
3132 result
= tu6_emit_vs_params(cmd
, draw
, &vs_params
);
3133 if (result
!= VK_SUCCESS
)
3136 draw_state_groups
[draw_state_group_count
++] =
3137 (struct tu_draw_state_group
) {
3138 .id
= TU_DRAW_STATE_VS_PARAMS
,
3139 .enable_mask
= ENABLE_ALL
,
3143 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 3 * draw_state_group_count
);
3144 for (uint32_t i
= 0; i
< draw_state_group_count
; i
++) {
3145 const struct tu_draw_state_group
*group
= &draw_state_groups
[i
];
3146 debug_assert((group
->enable_mask
& ~ENABLE_ALL
) == 0);
3147 uint32_t cp_set_draw_state
=
3148 CP_SET_DRAW_STATE__0_COUNT(group
->ib
.size
/ 4) |
3149 group
->enable_mask
|
3150 CP_SET_DRAW_STATE__0_GROUP_ID(group
->id
);
3152 if (group
->ib
.size
) {
3153 iova
= group
->ib
.bo
->iova
+ group
->ib
.offset
;
3155 cp_set_draw_state
|= CP_SET_DRAW_STATE__0_DISABLE
;
3159 tu_cs_emit(cs
, cp_set_draw_state
);
3160 tu_cs_emit_qw(cs
, iova
);
3163 tu_cs_sanity_check(cs
);
3166 if (cmd
->state
.dirty
& TU_CMD_DIRTY_VERTEX_BUFFERS
) {
3167 for (uint32_t i
= 0; i
< MAX_VBS
; i
++) {
3168 const struct tu_buffer
*buf
= cmd
->state
.vb
.buffers
[i
];
3170 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_READ
);
3173 if (cmd
->state
.dirty
& TU_CMD_DIRTY_DESCRIPTOR_SETS
) {
3175 for_each_bit(i
, descriptors_state
->valid
) {
3176 struct tu_descriptor_set
*set
= descriptors_state
->sets
[i
];
3177 for (unsigned j
= 0; j
< set
->layout
->buffer_count
; ++j
) {
3178 if (set
->buffers
[j
]) {
3179 tu_bo_list_add(&cmd
->bo_list
, set
->buffers
[j
],
3180 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
3183 if (set
->size
> 0) {
3184 tu_bo_list_add(&cmd
->bo_list
, &set
->pool
->bo
,
3185 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
3189 if (cmd
->state
.dirty
& TU_CMD_DIRTY_STREAMOUT_BUFFERS
) {
3190 for (unsigned i
= 0; i
< IR3_MAX_SO_BUFFERS
; i
++) {
3191 const struct tu_buffer
*buf
= cmd
->state
.streamout_buf
.buffers
[i
];
3193 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
,
3194 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
3199 /* There are too many graphics dirty bits to list here, so just list the
3200 * bits to preserve instead. The only things not emitted here are
3201 * compute-related state.
3203 cmd
->state
.dirty
&= TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
;
3205 /* Fragment shader state overwrites compute shader state, so flag the
3206 * compute pipeline for re-emit.
3208 cmd
->state
.dirty
|= TU_CMD_DIRTY_COMPUTE_PIPELINE
;
3213 tu6_emit_draw_indirect(struct tu_cmd_buffer
*cmd
,
3215 const struct tu_draw_info
*draw
)
3217 const enum pc_di_primtype primtype
= cmd
->state
.pipeline
->ia
.primtype
;
3218 bool has_gs
= cmd
->state
.pipeline
->active_stages
&
3219 VK_SHADER_STAGE_GEOMETRY_BIT
;
3222 A6XX_VFD_INDEX_OFFSET(draw
->vertex_offset
),
3223 A6XX_VFD_INSTANCE_START_OFFSET(draw
->first_instance
));
3225 if (draw
->indexed
) {
3226 const enum a4xx_index_size index_size
=
3227 tu6_index_size(cmd
->state
.index_type
);
3228 const uint32_t index_bytes
=
3229 (cmd
->state
.index_type
== VK_INDEX_TYPE_UINT32
) ? 4 : 2;
3230 const struct tu_buffer
*index_buf
= cmd
->state
.index_buffer
;
3231 unsigned max_indicies
=
3232 (index_buf
->size
- cmd
->state
.index_offset
) / index_bytes
;
3234 const uint32_t cp_draw_indx
=
3235 CP_DRAW_INDX_OFFSET_0_PRIM_TYPE(primtype
) |
3236 CP_DRAW_INDX_OFFSET_0_SOURCE_SELECT(DI_SRC_SEL_DMA
) |
3237 CP_DRAW_INDX_OFFSET_0_INDEX_SIZE(index_size
) |
3238 CP_DRAW_INDX_OFFSET_0_VIS_CULL(USE_VISIBILITY
) |
3239 COND(has_gs
, CP_DRAW_INDX_OFFSET_0_GS_ENABLE
) | 0x2000;
3241 tu_cs_emit_pkt7(cs
, CP_DRAW_INDX_INDIRECT
, 6);
3242 tu_cs_emit(cs
, cp_draw_indx
);
3243 tu_cs_emit_qw(cs
, index_buf
->bo
->iova
+ cmd
->state
.index_offset
);
3244 tu_cs_emit(cs
, A5XX_CP_DRAW_INDX_INDIRECT_3_MAX_INDICES(max_indicies
));
3245 tu_cs_emit_qw(cs
, draw
->indirect
->bo
->iova
+ draw
->indirect_offset
);
3247 const uint32_t cp_draw_indx
=
3248 CP_DRAW_INDX_OFFSET_0_PRIM_TYPE(primtype
) |
3249 CP_DRAW_INDX_OFFSET_0_SOURCE_SELECT(DI_SRC_SEL_AUTO_INDEX
) |
3250 CP_DRAW_INDX_OFFSET_0_VIS_CULL(USE_VISIBILITY
) |
3251 COND(has_gs
, CP_DRAW_INDX_OFFSET_0_GS_ENABLE
) | 0x2000;
3253 tu_cs_emit_pkt7(cs
, CP_DRAW_INDIRECT
, 3);
3254 tu_cs_emit(cs
, cp_draw_indx
);
3255 tu_cs_emit_qw(cs
, draw
->indirect
->bo
->iova
+ draw
->indirect_offset
);
3258 tu_bo_list_add(&cmd
->bo_list
, draw
->indirect
->bo
, MSM_SUBMIT_BO_READ
);
3262 tu6_emit_draw_direct(struct tu_cmd_buffer
*cmd
,
3264 const struct tu_draw_info
*draw
)
3267 const enum pc_di_primtype primtype
= cmd
->state
.pipeline
->ia
.primtype
;
3268 bool has_gs
= cmd
->state
.pipeline
->active_stages
&
3269 VK_SHADER_STAGE_GEOMETRY_BIT
;
3272 A6XX_VFD_INDEX_OFFSET(draw
->vertex_offset
),
3273 A6XX_VFD_INSTANCE_START_OFFSET(draw
->first_instance
));
3275 /* TODO hw binning */
3276 if (draw
->indexed
) {
3277 const enum a4xx_index_size index_size
=
3278 tu6_index_size(cmd
->state
.index_type
);
3279 const uint32_t index_bytes
=
3280 (cmd
->state
.index_type
== VK_INDEX_TYPE_UINT32
) ? 4 : 2;
3281 const struct tu_buffer
*buf
= cmd
->state
.index_buffer
;
3282 const VkDeviceSize offset
= buf
->bo_offset
+ cmd
->state
.index_offset
+
3283 index_bytes
* draw
->first_index
;
3284 const uint32_t size
= index_bytes
* draw
->count
;
3286 const uint32_t cp_draw_indx
=
3287 CP_DRAW_INDX_OFFSET_0_PRIM_TYPE(primtype
) |
3288 CP_DRAW_INDX_OFFSET_0_SOURCE_SELECT(DI_SRC_SEL_DMA
) |
3289 CP_DRAW_INDX_OFFSET_0_INDEX_SIZE(index_size
) |
3290 CP_DRAW_INDX_OFFSET_0_VIS_CULL(USE_VISIBILITY
) |
3291 COND(has_gs
, CP_DRAW_INDX_OFFSET_0_GS_ENABLE
) | 0x2000;
3293 tu_cs_emit_pkt7(cs
, CP_DRAW_INDX_OFFSET
, 7);
3294 tu_cs_emit(cs
, cp_draw_indx
);
3295 tu_cs_emit(cs
, draw
->instance_count
);
3296 tu_cs_emit(cs
, draw
->count
);
3297 tu_cs_emit(cs
, 0x0); /* XXX */
3298 tu_cs_emit_qw(cs
, buf
->bo
->iova
+ offset
);
3299 tu_cs_emit(cs
, size
);
3301 const uint32_t cp_draw_indx
=
3302 CP_DRAW_INDX_OFFSET_0_PRIM_TYPE(primtype
) |
3303 CP_DRAW_INDX_OFFSET_0_SOURCE_SELECT(DI_SRC_SEL_AUTO_INDEX
) |
3304 CP_DRAW_INDX_OFFSET_0_VIS_CULL(USE_VISIBILITY
) |
3305 COND(has_gs
, CP_DRAW_INDX_OFFSET_0_GS_ENABLE
) | 0x2000;
3307 tu_cs_emit_pkt7(cs
, CP_DRAW_INDX_OFFSET
, 3);
3308 tu_cs_emit(cs
, cp_draw_indx
);
3309 tu_cs_emit(cs
, draw
->instance_count
);
3310 tu_cs_emit(cs
, draw
->count
);
3315 tu_draw(struct tu_cmd_buffer
*cmd
, const struct tu_draw_info
*draw
)
3317 struct tu_cs
*cs
= &cmd
->draw_cs
;
3320 result
= tu6_bind_draw_states(cmd
, cs
, draw
);
3321 if (result
!= VK_SUCCESS
) {
3322 cmd
->record_result
= result
;
3327 tu6_emit_draw_indirect(cmd
, cs
, draw
);
3329 tu6_emit_draw_direct(cmd
, cs
, draw
);
3331 if (cmd
->state
.streamout_enabled
) {
3332 for (unsigned i
= 0; i
< IR3_MAX_SO_BUFFERS
; i
++) {
3333 if (cmd
->state
.streamout_enabled
& (1 << i
))
3334 tu6_emit_event_write(cmd
, cs
, FLUSH_SO_0
+ i
, false);
3338 cmd
->wait_for_idle
= true;
3340 tu_cs_sanity_check(cs
);
3344 tu_CmdDraw(VkCommandBuffer commandBuffer
,
3345 uint32_t vertexCount
,
3346 uint32_t instanceCount
,
3347 uint32_t firstVertex
,
3348 uint32_t firstInstance
)
3350 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3351 struct tu_draw_info info
= {};
3353 info
.count
= vertexCount
;
3354 info
.instance_count
= instanceCount
;
3355 info
.first_instance
= firstInstance
;
3356 info
.vertex_offset
= firstVertex
;
3358 tu_draw(cmd_buffer
, &info
);
3362 tu_CmdDrawIndexed(VkCommandBuffer commandBuffer
,
3363 uint32_t indexCount
,
3364 uint32_t instanceCount
,
3365 uint32_t firstIndex
,
3366 int32_t vertexOffset
,
3367 uint32_t firstInstance
)
3369 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3370 struct tu_draw_info info
= {};
3372 info
.indexed
= true;
3373 info
.count
= indexCount
;
3374 info
.instance_count
= instanceCount
;
3375 info
.first_index
= firstIndex
;
3376 info
.vertex_offset
= vertexOffset
;
3377 info
.first_instance
= firstInstance
;
3379 tu_draw(cmd_buffer
, &info
);
3383 tu_CmdDrawIndirect(VkCommandBuffer commandBuffer
,
3385 VkDeviceSize offset
,
3389 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3390 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
3391 struct tu_draw_info info
= {};
3393 info
.count
= drawCount
;
3394 info
.indirect
= buffer
;
3395 info
.indirect_offset
= offset
;
3396 info
.stride
= stride
;
3398 tu_draw(cmd_buffer
, &info
);
3402 tu_CmdDrawIndexedIndirect(VkCommandBuffer commandBuffer
,
3404 VkDeviceSize offset
,
3408 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3409 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
3410 struct tu_draw_info info
= {};
3412 info
.indexed
= true;
3413 info
.count
= drawCount
;
3414 info
.indirect
= buffer
;
3415 info
.indirect_offset
= offset
;
3416 info
.stride
= stride
;
3418 tu_draw(cmd_buffer
, &info
);
3421 void tu_CmdDrawIndirectByteCountEXT(VkCommandBuffer commandBuffer
,
3422 uint32_t instanceCount
,
3423 uint32_t firstInstance
,
3424 VkBuffer _counterBuffer
,
3425 VkDeviceSize counterBufferOffset
,
3426 uint32_t counterOffset
,
3427 uint32_t vertexStride
)
3429 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3430 TU_FROM_HANDLE(tu_buffer
, buffer
, _counterBuffer
);
3432 struct tu_draw_info info
= {};
3434 info
.instance_count
= instanceCount
;
3435 info
.first_instance
= firstInstance
;
3436 info
.streamout_buffer
= buffer
;
3437 info
.streamout_buffer_offset
= counterBufferOffset
;
3438 info
.stride
= vertexStride
;
3440 tu_draw(cmd_buffer
, &info
);
3443 struct tu_dispatch_info
3446 * Determine the layout of the grid (in block units) to be used.
3451 * A starting offset for the grid. If unaligned is set, the offset
3452 * must still be aligned.
3454 uint32_t offsets
[3];
3456 * Whether it's an unaligned compute dispatch.
3461 * Indirect compute parameters resource.
3463 struct tu_buffer
*indirect
;
3464 uint64_t indirect_offset
;
3468 tu_emit_compute_driver_params(struct tu_cs
*cs
, struct tu_pipeline
*pipeline
,
3469 const struct tu_dispatch_info
*info
)
3471 gl_shader_stage type
= MESA_SHADER_COMPUTE
;
3472 const struct tu_program_descriptor_linkage
*link
=
3473 &pipeline
->program
.link
[type
];
3474 const struct ir3_const_state
*const_state
= &link
->const_state
;
3475 uint32_t offset
= const_state
->offsets
.driver_param
;
3477 if (link
->constlen
<= offset
)
3480 if (!info
->indirect
) {
3481 uint32_t driver_params
[IR3_DP_CS_COUNT
] = {
3482 [IR3_DP_NUM_WORK_GROUPS_X
] = info
->blocks
[0],
3483 [IR3_DP_NUM_WORK_GROUPS_Y
] = info
->blocks
[1],
3484 [IR3_DP_NUM_WORK_GROUPS_Z
] = info
->blocks
[2],
3485 [IR3_DP_LOCAL_GROUP_SIZE_X
] = pipeline
->compute
.local_size
[0],
3486 [IR3_DP_LOCAL_GROUP_SIZE_Y
] = pipeline
->compute
.local_size
[1],
3487 [IR3_DP_LOCAL_GROUP_SIZE_Z
] = pipeline
->compute
.local_size
[2],
3490 uint32_t num_consts
= MIN2(const_state
->num_driver_params
,
3491 (link
->constlen
- offset
) * 4);
3492 /* push constants */
3493 tu_cs_emit_pkt7(cs
, tu6_stage2opcode(type
), 3 + num_consts
);
3494 tu_cs_emit(cs
, CP_LOAD_STATE6_0_DST_OFF(offset
) |
3495 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
3496 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
3497 CP_LOAD_STATE6_0_STATE_BLOCK(tu6_stage2shadersb(type
)) |
3498 CP_LOAD_STATE6_0_NUM_UNIT(num_consts
/ 4));
3502 for (i
= 0; i
< num_consts
; i
++)
3503 tu_cs_emit(cs
, driver_params
[i
]);
3505 tu_finishme("Indirect driver params");
3510 tu_dispatch(struct tu_cmd_buffer
*cmd
,
3511 const struct tu_dispatch_info
*info
)
3513 struct tu_cs
*cs
= &cmd
->cs
;
3514 struct tu_pipeline
*pipeline
= cmd
->state
.compute_pipeline
;
3515 struct tu_descriptor_state
*descriptors_state
=
3516 &cmd
->descriptors
[VK_PIPELINE_BIND_POINT_COMPUTE
];
3519 if (cmd
->state
.dirty
& TU_CMD_DIRTY_COMPUTE_PIPELINE
)
3520 tu_cs_emit_ib(cs
, &pipeline
->program
.state_ib
);
3522 struct tu_cs_entry ib
;
3524 ib
= tu6_emit_consts(cmd
, pipeline
, descriptors_state
, MESA_SHADER_COMPUTE
);
3526 tu_cs_emit_ib(cs
, &ib
);
3528 tu_emit_compute_driver_params(cs
, pipeline
, info
);
3530 if (cmd
->state
.dirty
& TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
) {
3531 result
= tu6_emit_descriptor_sets(cmd
, pipeline
,
3532 VK_PIPELINE_BIND_POINT_COMPUTE
, &ib
,
3534 if (result
!= VK_SUCCESS
) {
3535 cmd
->record_result
= result
;
3541 for_each_bit(i
, descriptors_state
->valid
) {
3542 struct tu_descriptor_set
*set
= descriptors_state
->sets
[i
];
3543 for (unsigned j
= 0; j
< set
->layout
->buffer_count
; ++j
) {
3544 if (set
->buffers
[j
]) {
3545 tu_bo_list_add(&cmd
->bo_list
, set
->buffers
[j
],
3546 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
3550 if (set
->size
> 0) {
3551 tu_bo_list_add(&cmd
->bo_list
, &set
->pool
->bo
,
3552 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
3558 tu_cs_emit_ib(cs
, &ib
);
3560 if (cmd
->state
.dirty
& TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
)
3561 tu_cs_emit_ib(cs
, &pipeline
->load_state
.state_ib
);
3564 ~(TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
| TU_CMD_DIRTY_COMPUTE_PIPELINE
);
3566 /* Compute shader state overwrites fragment shader state, so we flag the
3567 * graphics pipeline for re-emit.
3569 cmd
->state
.dirty
|= TU_CMD_DIRTY_PIPELINE
;
3571 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
3572 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_COMPUTE
));
3574 const uint32_t *local_size
= pipeline
->compute
.local_size
;
3575 const uint32_t *num_groups
= info
->blocks
;
3577 A6XX_HLSQ_CS_NDRANGE_0(.kerneldim
= 3,
3578 .localsizex
= local_size
[0] - 1,
3579 .localsizey
= local_size
[1] - 1,
3580 .localsizez
= local_size
[2] - 1),
3581 A6XX_HLSQ_CS_NDRANGE_1(.globalsize_x
= local_size
[0] * num_groups
[0]),
3582 A6XX_HLSQ_CS_NDRANGE_2(.globaloff_x
= 0),
3583 A6XX_HLSQ_CS_NDRANGE_3(.globalsize_y
= local_size
[1] * num_groups
[1]),
3584 A6XX_HLSQ_CS_NDRANGE_4(.globaloff_y
= 0),
3585 A6XX_HLSQ_CS_NDRANGE_5(.globalsize_z
= local_size
[2] * num_groups
[2]),
3586 A6XX_HLSQ_CS_NDRANGE_6(.globaloff_z
= 0));
3589 A6XX_HLSQ_CS_KERNEL_GROUP_X(1),
3590 A6XX_HLSQ_CS_KERNEL_GROUP_Y(1),
3591 A6XX_HLSQ_CS_KERNEL_GROUP_Z(1));
3593 if (info
->indirect
) {
3594 uint64_t iova
= tu_buffer_iova(info
->indirect
) + info
->indirect_offset
;
3596 tu_bo_list_add(&cmd
->bo_list
, info
->indirect
->bo
,
3597 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
3599 tu_cs_emit_pkt7(cs
, CP_EXEC_CS_INDIRECT
, 4);
3600 tu_cs_emit(cs
, 0x00000000);
3601 tu_cs_emit_qw(cs
, iova
);
3603 A5XX_CP_EXEC_CS_INDIRECT_3_LOCALSIZEX(local_size
[0] - 1) |
3604 A5XX_CP_EXEC_CS_INDIRECT_3_LOCALSIZEY(local_size
[1] - 1) |
3605 A5XX_CP_EXEC_CS_INDIRECT_3_LOCALSIZEZ(local_size
[2] - 1));
3607 tu_cs_emit_pkt7(cs
, CP_EXEC_CS
, 4);
3608 tu_cs_emit(cs
, 0x00000000);
3609 tu_cs_emit(cs
, CP_EXEC_CS_1_NGROUPS_X(info
->blocks
[0]));
3610 tu_cs_emit(cs
, CP_EXEC_CS_2_NGROUPS_Y(info
->blocks
[1]));
3611 tu_cs_emit(cs
, CP_EXEC_CS_3_NGROUPS_Z(info
->blocks
[2]));
3616 tu6_emit_cache_flush(cmd
, cs
);
3620 tu_CmdDispatchBase(VkCommandBuffer commandBuffer
,
3628 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3629 struct tu_dispatch_info info
= {};
3635 info
.offsets
[0] = base_x
;
3636 info
.offsets
[1] = base_y
;
3637 info
.offsets
[2] = base_z
;
3638 tu_dispatch(cmd_buffer
, &info
);
3642 tu_CmdDispatch(VkCommandBuffer commandBuffer
,
3647 tu_CmdDispatchBase(commandBuffer
, 0, 0, 0, x
, y
, z
);
3651 tu_CmdDispatchIndirect(VkCommandBuffer commandBuffer
,
3653 VkDeviceSize offset
)
3655 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3656 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
3657 struct tu_dispatch_info info
= {};
3659 info
.indirect
= buffer
;
3660 info
.indirect_offset
= offset
;
3662 tu_dispatch(cmd_buffer
, &info
);
3666 tu_CmdEndRenderPass(VkCommandBuffer commandBuffer
)
3668 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3670 tu_cs_end(&cmd_buffer
->draw_cs
);
3671 tu_cs_end(&cmd_buffer
->draw_epilogue_cs
);
3673 if (use_sysmem_rendering(cmd_buffer
))
3674 tu_cmd_render_sysmem(cmd_buffer
);
3676 tu_cmd_render_tiles(cmd_buffer
);
3678 /* discard draw_cs and draw_epilogue_cs entries now that the tiles are
3680 tu_cs_discard_entries(&cmd_buffer
->draw_cs
);
3681 tu_cs_begin(&cmd_buffer
->draw_cs
);
3682 tu_cs_discard_entries(&cmd_buffer
->draw_epilogue_cs
);
3683 tu_cs_begin(&cmd_buffer
->draw_epilogue_cs
);
3685 cmd_buffer
->state
.pass
= NULL
;
3686 cmd_buffer
->state
.subpass
= NULL
;
3687 cmd_buffer
->state
.framebuffer
= NULL
;
3691 tu_CmdEndRenderPass2(VkCommandBuffer commandBuffer
,
3692 const VkSubpassEndInfoKHR
*pSubpassEndInfo
)
3694 tu_CmdEndRenderPass(commandBuffer
);
3697 struct tu_barrier_info
3699 uint32_t eventCount
;
3700 const VkEvent
*pEvents
;
3701 VkPipelineStageFlags srcStageMask
;
3705 tu_barrier(struct tu_cmd_buffer
*cmd
,
3706 uint32_t memoryBarrierCount
,
3707 const VkMemoryBarrier
*pMemoryBarriers
,
3708 uint32_t bufferMemoryBarrierCount
,
3709 const VkBufferMemoryBarrier
*pBufferMemoryBarriers
,
3710 uint32_t imageMemoryBarrierCount
,
3711 const VkImageMemoryBarrier
*pImageMemoryBarriers
,
3712 const struct tu_barrier_info
*info
)
3714 /* renderpass case is only for subpass self-dependencies
3715 * which means syncing the render output with texture cache
3716 * note: only the CACHE_INVALIDATE is needed in GMEM mode
3717 * and in sysmem mode we might not need either color/depth flush
3719 if (cmd
->state
.pass
) {
3720 tu6_emit_event_write(cmd
, &cmd
->draw_cs
, PC_CCU_FLUSH_COLOR_TS
, true);
3721 tu6_emit_event_write(cmd
, &cmd
->draw_cs
, PC_CCU_FLUSH_DEPTH_TS
, true);
3722 tu6_emit_event_write(cmd
, &cmd
->draw_cs
, CACHE_INVALIDATE
, false);
3728 tu_CmdPipelineBarrier(VkCommandBuffer commandBuffer
,
3729 VkPipelineStageFlags srcStageMask
,
3730 VkPipelineStageFlags dstStageMask
,
3731 VkDependencyFlags dependencyFlags
,
3732 uint32_t memoryBarrierCount
,
3733 const VkMemoryBarrier
*pMemoryBarriers
,
3734 uint32_t bufferMemoryBarrierCount
,
3735 const VkBufferMemoryBarrier
*pBufferMemoryBarriers
,
3736 uint32_t imageMemoryBarrierCount
,
3737 const VkImageMemoryBarrier
*pImageMemoryBarriers
)
3739 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3740 struct tu_barrier_info info
;
3742 info
.eventCount
= 0;
3743 info
.pEvents
= NULL
;
3744 info
.srcStageMask
= srcStageMask
;
3746 tu_barrier(cmd_buffer
, memoryBarrierCount
, pMemoryBarriers
,
3747 bufferMemoryBarrierCount
, pBufferMemoryBarriers
,
3748 imageMemoryBarrierCount
, pImageMemoryBarriers
, &info
);
3752 write_event(struct tu_cmd_buffer
*cmd
, struct tu_event
*event
, unsigned value
)
3754 struct tu_cs
*cs
= &cmd
->cs
;
3756 tu_bo_list_add(&cmd
->bo_list
, &event
->bo
, MSM_SUBMIT_BO_WRITE
);
3758 /* TODO: any flush required before/after ? */
3760 tu_cs_emit_pkt7(cs
, CP_MEM_WRITE
, 3);
3761 tu_cs_emit_qw(cs
, event
->bo
.iova
); /* ADDR_LO/HI */
3762 tu_cs_emit(cs
, value
);
3766 tu_CmdSetEvent(VkCommandBuffer commandBuffer
,
3768 VkPipelineStageFlags stageMask
)
3770 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3771 TU_FROM_HANDLE(tu_event
, event
, _event
);
3773 write_event(cmd
, event
, 1);
3777 tu_CmdResetEvent(VkCommandBuffer commandBuffer
,
3779 VkPipelineStageFlags stageMask
)
3781 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3782 TU_FROM_HANDLE(tu_event
, event
, _event
);
3784 write_event(cmd
, event
, 0);
3788 tu_CmdWaitEvents(VkCommandBuffer commandBuffer
,
3789 uint32_t eventCount
,
3790 const VkEvent
*pEvents
,
3791 VkPipelineStageFlags srcStageMask
,
3792 VkPipelineStageFlags dstStageMask
,
3793 uint32_t memoryBarrierCount
,
3794 const VkMemoryBarrier
*pMemoryBarriers
,
3795 uint32_t bufferMemoryBarrierCount
,
3796 const VkBufferMemoryBarrier
*pBufferMemoryBarriers
,
3797 uint32_t imageMemoryBarrierCount
,
3798 const VkImageMemoryBarrier
*pImageMemoryBarriers
)
3800 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3801 struct tu_cs
*cs
= &cmd
->cs
;
3803 /* TODO: any flush required before/after? (CP_WAIT_FOR_ME?) */
3805 for (uint32_t i
= 0; i
< eventCount
; i
++) {
3806 TU_FROM_HANDLE(tu_event
, event
, pEvents
[i
]);
3808 tu_bo_list_add(&cmd
->bo_list
, &event
->bo
, MSM_SUBMIT_BO_READ
);
3810 tu_cs_emit_pkt7(cs
, CP_WAIT_REG_MEM
, 6);
3811 tu_cs_emit(cs
, CP_WAIT_REG_MEM_0_FUNCTION(WRITE_EQ
) |
3812 CP_WAIT_REG_MEM_0_POLL_MEMORY
);
3813 tu_cs_emit_qw(cs
, event
->bo
.iova
); /* POLL_ADDR_LO/HI */
3814 tu_cs_emit(cs
, CP_WAIT_REG_MEM_3_REF(1));
3815 tu_cs_emit(cs
, CP_WAIT_REG_MEM_4_MASK(~0u));
3816 tu_cs_emit(cs
, CP_WAIT_REG_MEM_5_DELAY_LOOP_CYCLES(20));
3821 tu_CmdSetDeviceMask(VkCommandBuffer commandBuffer
, uint32_t deviceMask
)