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"
38 tu_bo_list_init(struct tu_bo_list
*list
)
40 list
->count
= list
->capacity
= 0;
41 list
->bo_infos
= NULL
;
45 tu_bo_list_destroy(struct tu_bo_list
*list
)
51 tu_bo_list_reset(struct tu_bo_list
*list
)
57 * \a flags consists of MSM_SUBMIT_BO_FLAGS.
60 tu_bo_list_add_info(struct tu_bo_list
*list
,
61 const struct drm_msm_gem_submit_bo
*bo_info
)
63 assert(bo_info
->handle
!= 0);
65 for (uint32_t i
= 0; i
< list
->count
; ++i
) {
66 if (list
->bo_infos
[i
].handle
== bo_info
->handle
) {
67 assert(list
->bo_infos
[i
].presumed
== bo_info
->presumed
);
68 list
->bo_infos
[i
].flags
|= bo_info
->flags
;
73 /* grow list->bo_infos if needed */
74 if (list
->count
== list
->capacity
) {
75 uint32_t new_capacity
= MAX2(2 * list
->count
, 16);
76 struct drm_msm_gem_submit_bo
*new_bo_infos
= realloc(
77 list
->bo_infos
, new_capacity
* sizeof(struct drm_msm_gem_submit_bo
));
79 return TU_BO_LIST_FAILED
;
80 list
->bo_infos
= new_bo_infos
;
81 list
->capacity
= new_capacity
;
84 list
->bo_infos
[list
->count
] = *bo_info
;
89 tu_bo_list_add(struct tu_bo_list
*list
,
90 const struct tu_bo
*bo
,
93 return tu_bo_list_add_info(list
, &(struct drm_msm_gem_submit_bo
) {
95 .handle
= bo
->gem_handle
,
101 tu_bo_list_merge(struct tu_bo_list
*list
, const struct tu_bo_list
*other
)
103 for (uint32_t i
= 0; i
< other
->count
; i
++) {
104 if (tu_bo_list_add_info(list
, other
->bo_infos
+ i
) == TU_BO_LIST_FAILED
)
105 return VK_ERROR_OUT_OF_HOST_MEMORY
;
112 tu_tiling_config_update_tile_layout(struct tu_tiling_config
*tiling
,
113 const struct tu_device
*dev
,
114 const struct tu_render_pass
*pass
)
116 const uint32_t tile_align_w
= pass
->tile_align_w
;
117 const uint32_t max_tile_width
= 1024;
119 /* note: don't offset the tiling config by render_area.offset,
120 * because binning pass can't deal with it
121 * this means we might end up with more tiles than necessary,
122 * but load/store/etc are still scissored to the render_area
124 tiling
->tile0
.offset
= (VkOffset2D
) {};
126 const uint32_t ra_width
=
127 tiling
->render_area
.extent
.width
+
128 (tiling
->render_area
.offset
.x
- tiling
->tile0
.offset
.x
);
129 const uint32_t ra_height
=
130 tiling
->render_area
.extent
.height
+
131 (tiling
->render_area
.offset
.y
- tiling
->tile0
.offset
.y
);
133 /* start from 1 tile */
134 tiling
->tile_count
= (VkExtent2D
) {
138 tiling
->tile0
.extent
= (VkExtent2D
) {
139 .width
= util_align_npot(ra_width
, tile_align_w
),
140 .height
= align(ra_height
, TILE_ALIGN_H
),
143 if (unlikely(dev
->physical_device
->instance
->debug_flags
& TU_DEBUG_FORCEBIN
)) {
144 /* start with 2x2 tiles */
145 tiling
->tile_count
.width
= 2;
146 tiling
->tile_count
.height
= 2;
147 tiling
->tile0
.extent
.width
= util_align_npot(DIV_ROUND_UP(ra_width
, 2), tile_align_w
);
148 tiling
->tile0
.extent
.height
= align(DIV_ROUND_UP(ra_height
, 2), TILE_ALIGN_H
);
151 /* do not exceed max tile width */
152 while (tiling
->tile0
.extent
.width
> max_tile_width
) {
153 tiling
->tile_count
.width
++;
154 tiling
->tile0
.extent
.width
=
155 util_align_npot(DIV_ROUND_UP(ra_width
, tiling
->tile_count
.width
), tile_align_w
);
158 /* will force to sysmem, don't bother trying to have a valid tile config
159 * TODO: just skip all GMEM stuff when sysmem is forced?
161 if (!pass
->gmem_pixels
)
164 /* do not exceed gmem size */
165 while (tiling
->tile0
.extent
.width
* tiling
->tile0
.extent
.height
> pass
->gmem_pixels
) {
166 if (tiling
->tile0
.extent
.width
> MAX2(tile_align_w
, tiling
->tile0
.extent
.height
)) {
167 tiling
->tile_count
.width
++;
168 tiling
->tile0
.extent
.width
=
169 util_align_npot(DIV_ROUND_UP(ra_width
, tiling
->tile_count
.width
), tile_align_w
);
171 /* if this assert fails then layout is impossible.. */
172 assert(tiling
->tile0
.extent
.height
> TILE_ALIGN_H
);
173 tiling
->tile_count
.height
++;
174 tiling
->tile0
.extent
.height
=
175 align(DIV_ROUND_UP(ra_height
, tiling
->tile_count
.height
), TILE_ALIGN_H
);
181 tu_tiling_config_update_pipe_layout(struct tu_tiling_config
*tiling
,
182 const struct tu_device
*dev
)
184 const uint32_t max_pipe_count
= 32; /* A6xx */
186 /* start from 1 tile per pipe */
187 tiling
->pipe0
= (VkExtent2D
) {
191 tiling
->pipe_count
= tiling
->tile_count
;
193 while (tiling
->pipe_count
.width
* tiling
->pipe_count
.height
> max_pipe_count
) {
194 if (tiling
->pipe0
.width
< tiling
->pipe0
.height
) {
195 tiling
->pipe0
.width
+= 1;
196 tiling
->pipe_count
.width
=
197 DIV_ROUND_UP(tiling
->tile_count
.width
, tiling
->pipe0
.width
);
199 tiling
->pipe0
.height
+= 1;
200 tiling
->pipe_count
.height
=
201 DIV_ROUND_UP(tiling
->tile_count
.height
, tiling
->pipe0
.height
);
207 tu_tiling_config_update_pipes(struct tu_tiling_config
*tiling
,
208 const struct tu_device
*dev
)
210 const uint32_t max_pipe_count
= 32; /* A6xx */
211 const uint32_t used_pipe_count
=
212 tiling
->pipe_count
.width
* tiling
->pipe_count
.height
;
213 const VkExtent2D last_pipe
= {
214 .width
= (tiling
->tile_count
.width
- 1) % tiling
->pipe0
.width
+ 1,
215 .height
= (tiling
->tile_count
.height
- 1) % tiling
->pipe0
.height
+ 1,
218 assert(used_pipe_count
<= max_pipe_count
);
219 assert(max_pipe_count
<= ARRAY_SIZE(tiling
->pipe_config
));
221 for (uint32_t y
= 0; y
< tiling
->pipe_count
.height
; y
++) {
222 for (uint32_t x
= 0; x
< tiling
->pipe_count
.width
; x
++) {
223 const uint32_t pipe_x
= tiling
->pipe0
.width
* x
;
224 const uint32_t pipe_y
= tiling
->pipe0
.height
* y
;
225 const uint32_t pipe_w
= (x
== tiling
->pipe_count
.width
- 1)
227 : tiling
->pipe0
.width
;
228 const uint32_t pipe_h
= (y
== tiling
->pipe_count
.height
- 1)
230 : tiling
->pipe0
.height
;
231 const uint32_t n
= tiling
->pipe_count
.width
* y
+ x
;
233 tiling
->pipe_config
[n
] = A6XX_VSC_PIPE_CONFIG_REG_X(pipe_x
) |
234 A6XX_VSC_PIPE_CONFIG_REG_Y(pipe_y
) |
235 A6XX_VSC_PIPE_CONFIG_REG_W(pipe_w
) |
236 A6XX_VSC_PIPE_CONFIG_REG_H(pipe_h
);
237 tiling
->pipe_sizes
[n
] = CP_SET_BIN_DATA5_0_VSC_SIZE(pipe_w
* pipe_h
);
241 memset(tiling
->pipe_config
+ used_pipe_count
, 0,
242 sizeof(uint32_t) * (max_pipe_count
- used_pipe_count
));
246 tu_tiling_config_get_tile(const struct tu_tiling_config
*tiling
,
247 const struct tu_device
*dev
,
250 struct tu_tile
*tile
)
252 /* find the pipe and the slot for tile (tx, ty) */
253 const uint32_t px
= tx
/ tiling
->pipe0
.width
;
254 const uint32_t py
= ty
/ tiling
->pipe0
.height
;
255 const uint32_t sx
= tx
- tiling
->pipe0
.width
* px
;
256 const uint32_t sy
= ty
- tiling
->pipe0
.height
* py
;
257 /* last pipe has different width */
258 const uint32_t pipe_width
=
259 MIN2(tiling
->pipe0
.width
,
260 tiling
->tile_count
.width
- px
* tiling
->pipe0
.width
);
262 assert(tx
< tiling
->tile_count
.width
&& ty
< tiling
->tile_count
.height
);
263 assert(px
< tiling
->pipe_count
.width
&& py
< tiling
->pipe_count
.height
);
264 assert(sx
< tiling
->pipe0
.width
&& sy
< tiling
->pipe0
.height
);
266 /* convert to 1D indices */
267 tile
->pipe
= tiling
->pipe_count
.width
* py
+ px
;
268 tile
->slot
= pipe_width
* sy
+ sx
;
270 /* get the blit area for the tile */
271 tile
->begin
= (VkOffset2D
) {
272 .x
= tiling
->tile0
.offset
.x
+ tiling
->tile0
.extent
.width
* tx
,
273 .y
= tiling
->tile0
.offset
.y
+ tiling
->tile0
.extent
.height
* ty
,
276 (tx
== tiling
->tile_count
.width
- 1)
277 ? tiling
->render_area
.offset
.x
+ tiling
->render_area
.extent
.width
278 : tile
->begin
.x
+ tiling
->tile0
.extent
.width
;
280 (ty
== tiling
->tile_count
.height
- 1)
281 ? tiling
->render_area
.offset
.y
+ tiling
->render_area
.extent
.height
282 : tile
->begin
.y
+ tiling
->tile0
.extent
.height
;
286 tu6_emit_event_write(struct tu_cmd_buffer
*cmd
,
288 enum vgt_event_type event
)
290 bool need_seqno
= false;
295 case PC_CCU_FLUSH_DEPTH_TS
:
296 case PC_CCU_FLUSH_COLOR_TS
:
297 case PC_CCU_RESOLVE_TS
:
304 tu_cs_emit_pkt7(cs
, CP_EVENT_WRITE
, need_seqno
? 4 : 1);
305 tu_cs_emit(cs
, CP_EVENT_WRITE_0_EVENT(event
));
307 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
);
313 tu6_emit_flushes(struct tu_cmd_buffer
*cmd_buffer
,
315 enum tu_cmd_flush_bits flushes
)
317 /* Experiments show that invalidating CCU while it still has data in it
318 * doesn't work, so make sure to always flush before invalidating in case
319 * any data remains that hasn't yet been made available through a barrier.
320 * However it does seem to work for UCHE.
322 if (flushes
& (TU_CMD_FLAG_CCU_FLUSH_COLOR
|
323 TU_CMD_FLAG_CCU_INVALIDATE_COLOR
))
324 tu6_emit_event_write(cmd_buffer
, cs
, PC_CCU_FLUSH_COLOR_TS
);
325 if (flushes
& (TU_CMD_FLAG_CCU_FLUSH_DEPTH
|
326 TU_CMD_FLAG_CCU_INVALIDATE_DEPTH
))
327 tu6_emit_event_write(cmd_buffer
, cs
, PC_CCU_FLUSH_DEPTH_TS
);
328 if (flushes
& TU_CMD_FLAG_CCU_INVALIDATE_COLOR
)
329 tu6_emit_event_write(cmd_buffer
, cs
, PC_CCU_INVALIDATE_COLOR
);
330 if (flushes
& TU_CMD_FLAG_CCU_INVALIDATE_DEPTH
)
331 tu6_emit_event_write(cmd_buffer
, cs
, PC_CCU_INVALIDATE_DEPTH
);
332 if (flushes
& TU_CMD_FLAG_CACHE_FLUSH
)
333 tu6_emit_event_write(cmd_buffer
, cs
, CACHE_FLUSH_TS
);
334 if (flushes
& TU_CMD_FLAG_CACHE_INVALIDATE
)
335 tu6_emit_event_write(cmd_buffer
, cs
, CACHE_INVALIDATE
);
336 if (flushes
& TU_CMD_FLAG_WFI
)
340 /* "Normal" cache flushes, that don't require any special handling */
343 tu_emit_cache_flush(struct tu_cmd_buffer
*cmd_buffer
,
346 tu6_emit_flushes(cmd_buffer
, cs
, cmd_buffer
->state
.cache
.flush_bits
);
347 cmd_buffer
->state
.cache
.flush_bits
= 0;
350 /* Renderpass cache flushes */
353 tu_emit_cache_flush_renderpass(struct tu_cmd_buffer
*cmd_buffer
,
356 tu6_emit_flushes(cmd_buffer
, cs
, cmd_buffer
->state
.renderpass_cache
.flush_bits
);
357 cmd_buffer
->state
.renderpass_cache
.flush_bits
= 0;
360 /* Cache flushes for things that use the color/depth read/write path (i.e.
361 * blits and draws). This deals with changing CCU state as well as the usual
366 tu_emit_cache_flush_ccu(struct tu_cmd_buffer
*cmd_buffer
,
368 enum tu_cmd_ccu_state ccu_state
)
370 enum tu_cmd_flush_bits flushes
= cmd_buffer
->state
.cache
.flush_bits
;
372 assert(ccu_state
!= TU_CMD_CCU_UNKNOWN
);
374 /* Changing CCU state must involve invalidating the CCU. In sysmem mode,
375 * the CCU may also contain data that we haven't flushed out yet, so we
376 * also need to flush. Also, in order to program RB_CCU_CNTL, we need to
377 * emit a WFI as it isn't pipelined.
379 if (ccu_state
!= cmd_buffer
->state
.ccu_state
) {
380 if (cmd_buffer
->state
.ccu_state
!= TU_CMD_CCU_GMEM
) {
382 TU_CMD_FLAG_CCU_FLUSH_COLOR
|
383 TU_CMD_FLAG_CCU_FLUSH_DEPTH
;
384 cmd_buffer
->state
.cache
.pending_flush_bits
&= ~(
385 TU_CMD_FLAG_CCU_FLUSH_COLOR
|
386 TU_CMD_FLAG_CCU_FLUSH_DEPTH
);
389 TU_CMD_FLAG_CCU_INVALIDATE_COLOR
|
390 TU_CMD_FLAG_CCU_INVALIDATE_DEPTH
|
392 cmd_buffer
->state
.cache
.pending_flush_bits
&= ~(
393 TU_CMD_FLAG_CCU_INVALIDATE_COLOR
|
394 TU_CMD_FLAG_CCU_INVALIDATE_DEPTH
);
397 tu6_emit_flushes(cmd_buffer
, cs
, flushes
);
398 cmd_buffer
->state
.cache
.flush_bits
= 0;
400 if (ccu_state
!= cmd_buffer
->state
.ccu_state
) {
401 struct tu_physical_device
*phys_dev
= cmd_buffer
->device
->physical_device
;
403 A6XX_RB_CCU_CNTL(.offset
=
404 ccu_state
== TU_CMD_CCU_GMEM
?
405 phys_dev
->ccu_offset_gmem
:
406 phys_dev
->ccu_offset_bypass
,
407 .gmem
= ccu_state
== TU_CMD_CCU_GMEM
));
408 cmd_buffer
->state
.ccu_state
= ccu_state
;
413 tu6_emit_zs(struct tu_cmd_buffer
*cmd
,
414 const struct tu_subpass
*subpass
,
417 const struct tu_framebuffer
*fb
= cmd
->state
.framebuffer
;
419 const uint32_t a
= subpass
->depth_stencil_attachment
.attachment
;
420 if (a
== VK_ATTACHMENT_UNUSED
) {
422 A6XX_RB_DEPTH_BUFFER_INFO(.depth_format
= DEPTH6_NONE
),
423 A6XX_RB_DEPTH_BUFFER_PITCH(0),
424 A6XX_RB_DEPTH_BUFFER_ARRAY_PITCH(0),
425 A6XX_RB_DEPTH_BUFFER_BASE(0),
426 A6XX_RB_DEPTH_BUFFER_BASE_GMEM(0));
429 A6XX_GRAS_SU_DEPTH_BUFFER_INFO(.depth_format
= DEPTH6_NONE
));
432 A6XX_GRAS_LRZ_BUFFER_BASE(0),
433 A6XX_GRAS_LRZ_BUFFER_PITCH(0),
434 A6XX_GRAS_LRZ_FAST_CLEAR_BUFFER_BASE(0));
436 tu_cs_emit_regs(cs
, A6XX_RB_STENCIL_INFO(0));
441 const struct tu_image_view
*iview
= fb
->attachments
[a
].attachment
;
442 const struct tu_render_pass_attachment
*attachment
=
443 &cmd
->state
.pass
->attachments
[a
];
444 enum a6xx_depth_format fmt
= tu6_pipe2depth(attachment
->format
);
446 tu_cs_emit_pkt4(cs
, REG_A6XX_RB_DEPTH_BUFFER_INFO
, 6);
447 tu_cs_emit(cs
, A6XX_RB_DEPTH_BUFFER_INFO(.depth_format
= fmt
).value
);
448 tu_cs_image_ref(cs
, iview
, 0);
449 tu_cs_emit(cs
, attachment
->gmem_offset
);
452 A6XX_GRAS_SU_DEPTH_BUFFER_INFO(.depth_format
= fmt
));
454 tu_cs_emit_pkt4(cs
, REG_A6XX_RB_DEPTH_FLAG_BUFFER_BASE_LO
, 3);
455 tu_cs_image_flag_ref(cs
, iview
, 0);
458 A6XX_GRAS_LRZ_BUFFER_BASE(0),
459 A6XX_GRAS_LRZ_BUFFER_PITCH(0),
460 A6XX_GRAS_LRZ_FAST_CLEAR_BUFFER_BASE(0));
462 if (attachment
->format
== VK_FORMAT_S8_UINT
) {
463 tu_cs_emit_pkt4(cs
, REG_A6XX_RB_STENCIL_INFO
, 6);
464 tu_cs_emit(cs
, A6XX_RB_STENCIL_INFO(.separate_stencil
= true).value
);
465 tu_cs_image_ref(cs
, iview
, 0);
466 tu_cs_emit(cs
, attachment
->gmem_offset
);
469 A6XX_RB_STENCIL_INFO(0));
474 tu6_emit_mrt(struct tu_cmd_buffer
*cmd
,
475 const struct tu_subpass
*subpass
,
478 const struct tu_framebuffer
*fb
= cmd
->state
.framebuffer
;
480 for (uint32_t i
= 0; i
< subpass
->color_count
; ++i
) {
481 uint32_t a
= subpass
->color_attachments
[i
].attachment
;
482 if (a
== VK_ATTACHMENT_UNUSED
)
485 const struct tu_image_view
*iview
= fb
->attachments
[a
].attachment
;
487 tu_cs_emit_pkt4(cs
, REG_A6XX_RB_MRT_BUF_INFO(i
), 6);
488 tu_cs_emit(cs
, iview
->RB_MRT_BUF_INFO
);
489 tu_cs_image_ref(cs
, iview
, 0);
490 tu_cs_emit(cs
, cmd
->state
.pass
->attachments
[a
].gmem_offset
);
493 A6XX_SP_FS_MRT_REG(i
, .dword
= iview
->SP_FS_MRT_REG
));
495 tu_cs_emit_pkt4(cs
, REG_A6XX_RB_MRT_FLAG_BUFFER_ADDR_LO(i
), 3);
496 tu_cs_image_flag_ref(cs
, iview
, 0);
500 A6XX_RB_SRGB_CNTL(.dword
= subpass
->srgb_cntl
));
502 A6XX_SP_SRGB_CNTL(.dword
= subpass
->srgb_cntl
));
504 tu_cs_emit_regs(cs
, A6XX_GRAS_MAX_LAYER_INDEX(fb
->layers
- 1));
508 tu6_emit_msaa(struct tu_cs
*cs
, VkSampleCountFlagBits vk_samples
)
510 const enum a3xx_msaa_samples samples
= tu_msaa_samples(vk_samples
);
511 bool msaa_disable
= samples
== MSAA_ONE
;
514 A6XX_SP_TP_RAS_MSAA_CNTL(samples
),
515 A6XX_SP_TP_DEST_MSAA_CNTL(.samples
= samples
,
516 .msaa_disable
= msaa_disable
));
519 A6XX_GRAS_RAS_MSAA_CNTL(samples
),
520 A6XX_GRAS_DEST_MSAA_CNTL(.samples
= samples
,
521 .msaa_disable
= msaa_disable
));
524 A6XX_RB_RAS_MSAA_CNTL(samples
),
525 A6XX_RB_DEST_MSAA_CNTL(.samples
= samples
,
526 .msaa_disable
= msaa_disable
));
529 A6XX_RB_MSAA_CNTL(samples
));
533 tu6_emit_bin_size(struct tu_cs
*cs
,
534 uint32_t bin_w
, uint32_t bin_h
, uint32_t flags
)
537 A6XX_GRAS_BIN_CONTROL(.binw
= bin_w
,
542 A6XX_RB_BIN_CONTROL(.binw
= bin_w
,
546 /* no flag for RB_BIN_CONTROL2... */
548 A6XX_RB_BIN_CONTROL2(.binw
= bin_w
,
553 tu6_emit_render_cntl(struct tu_cmd_buffer
*cmd
,
554 const struct tu_subpass
*subpass
,
558 const struct tu_framebuffer
*fb
= cmd
->state
.framebuffer
;
560 cntl
|= A6XX_RB_RENDER_CNTL_UNK4
;
562 cntl
|= A6XX_RB_RENDER_CNTL_BINNING
;
564 uint32_t mrts_ubwc_enable
= 0;
565 for (uint32_t i
= 0; i
< subpass
->color_count
; ++i
) {
566 uint32_t a
= subpass
->color_attachments
[i
].attachment
;
567 if (a
== VK_ATTACHMENT_UNUSED
)
570 const struct tu_image_view
*iview
= fb
->attachments
[a
].attachment
;
571 if (iview
->ubwc_enabled
)
572 mrts_ubwc_enable
|= 1 << i
;
575 cntl
|= A6XX_RB_RENDER_CNTL_FLAG_MRTS(mrts_ubwc_enable
);
577 const uint32_t a
= subpass
->depth_stencil_attachment
.attachment
;
578 if (a
!= VK_ATTACHMENT_UNUSED
) {
579 const struct tu_image_view
*iview
= fb
->attachments
[a
].attachment
;
580 if (iview
->ubwc_enabled
)
581 cntl
|= A6XX_RB_RENDER_CNTL_FLAG_DEPTH
;
584 /* In the !binning case, we need to set RB_RENDER_CNTL in the draw_cs
585 * in order to set it correctly for the different subpasses. However,
586 * that means the packets we're emitting also happen during binning. So
587 * we need to guard the write on !BINNING at CP execution time.
589 tu_cs_reserve(cs
, 3 + 4);
590 tu_cs_emit_pkt7(cs
, CP_COND_REG_EXEC
, 2);
591 tu_cs_emit(cs
, CP_COND_REG_EXEC_0_MODE(RENDER_MODE
) |
592 CP_COND_REG_EXEC_0_GMEM
| CP_COND_REG_EXEC_0_SYSMEM
);
593 tu_cs_emit(cs
, CP_COND_REG_EXEC_1_DWORDS(4));
596 tu_cs_emit_pkt7(cs
, CP_REG_WRITE
, 3);
597 tu_cs_emit(cs
, CP_REG_WRITE_0_TRACKER(TRACK_RENDER_CNTL
));
598 tu_cs_emit(cs
, REG_A6XX_RB_RENDER_CNTL
);
599 tu_cs_emit(cs
, cntl
);
603 tu6_emit_blit_scissor(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
, bool align
)
605 const VkRect2D
*render_area
= &cmd
->state
.tiling_config
.render_area
;
606 uint32_t x1
= render_area
->offset
.x
;
607 uint32_t y1
= render_area
->offset
.y
;
608 uint32_t x2
= x1
+ render_area
->extent
.width
- 1;
609 uint32_t y2
= y1
+ render_area
->extent
.height
- 1;
612 x1
= x1
& ~(GMEM_ALIGN_W
- 1);
613 y1
= y1
& ~(GMEM_ALIGN_H
- 1);
614 x2
= ALIGN_POT(x2
+ 1, GMEM_ALIGN_W
) - 1;
615 y2
= ALIGN_POT(y2
+ 1, GMEM_ALIGN_H
) - 1;
619 A6XX_RB_BLIT_SCISSOR_TL(.x
= x1
, .y
= y1
),
620 A6XX_RB_BLIT_SCISSOR_BR(.x
= x2
, .y
= y2
));
624 tu6_emit_window_scissor(struct tu_cs
*cs
,
631 A6XX_GRAS_SC_WINDOW_SCISSOR_TL(.x
= x1
, .y
= y1
),
632 A6XX_GRAS_SC_WINDOW_SCISSOR_BR(.x
= x2
, .y
= y2
));
635 A6XX_GRAS_RESOLVE_CNTL_1(.x
= x1
, .y
= y1
),
636 A6XX_GRAS_RESOLVE_CNTL_2(.x
= x2
, .y
= y2
));
640 tu6_emit_window_offset(struct tu_cs
*cs
, uint32_t x1
, uint32_t y1
)
643 A6XX_RB_WINDOW_OFFSET(.x
= x1
, .y
= y1
));
646 A6XX_RB_WINDOW_OFFSET2(.x
= x1
, .y
= y1
));
649 A6XX_SP_WINDOW_OFFSET(.x
= x1
, .y
= y1
));
652 A6XX_SP_TP_WINDOW_OFFSET(.x
= x1
, .y
= y1
));
656 tu_cs_emit_draw_state(struct tu_cs
*cs
, uint32_t id
, struct tu_draw_state state
)
658 uint32_t enable_mask
;
660 case TU_DRAW_STATE_PROGRAM
:
661 case TU_DRAW_STATE_VI
:
662 case TU_DRAW_STATE_FS_CONST
:
663 /* The blob seems to not enable this (DESC_SETS_LOAD) for binning, even
664 * when resources would actually be used in the binning shader.
665 * Presumably the overhead of prefetching the resources isn't
668 case TU_DRAW_STATE_DESC_SETS_LOAD
:
669 enable_mask
= CP_SET_DRAW_STATE__0_GMEM
|
670 CP_SET_DRAW_STATE__0_SYSMEM
;
672 case TU_DRAW_STATE_PROGRAM_BINNING
:
673 case TU_DRAW_STATE_VI_BINNING
:
674 enable_mask
= CP_SET_DRAW_STATE__0_BINNING
;
676 case TU_DRAW_STATE_INPUT_ATTACHMENTS_GMEM
:
677 enable_mask
= CP_SET_DRAW_STATE__0_GMEM
;
679 case TU_DRAW_STATE_INPUT_ATTACHMENTS_SYSMEM
:
680 enable_mask
= CP_SET_DRAW_STATE__0_SYSMEM
;
683 enable_mask
= CP_SET_DRAW_STATE__0_GMEM
|
684 CP_SET_DRAW_STATE__0_SYSMEM
|
685 CP_SET_DRAW_STATE__0_BINNING
;
689 tu_cs_emit(cs
, CP_SET_DRAW_STATE__0_COUNT(state
.size
) |
691 CP_SET_DRAW_STATE__0_GROUP_ID(id
) |
692 COND(!state
.size
, CP_SET_DRAW_STATE__0_DISABLE
));
693 tu_cs_emit_qw(cs
, state
.iova
);
696 /* note: get rid of this eventually */
698 tu_cs_emit_sds_ib(struct tu_cs
*cs
, uint32_t id
, struct tu_cs_entry entry
)
700 tu_cs_emit_draw_state(cs
, id
, (struct tu_draw_state
) {
701 .iova
= entry
.size
? entry
.bo
->iova
+ entry
.offset
: 0,
702 .size
= entry
.size
/ 4,
707 use_hw_binning(struct tu_cmd_buffer
*cmd
)
709 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
711 /* XFB commands are emitted for BINNING || SYSMEM, which makes it incompatible
712 * with non-hw binning GMEM rendering. this is required because some of the
713 * XFB commands need to only be executed once
715 if (cmd
->state
.xfb_used
)
718 if (unlikely(cmd
->device
->physical_device
->instance
->debug_flags
& TU_DEBUG_NOBIN
))
721 if (unlikely(cmd
->device
->physical_device
->instance
->debug_flags
& TU_DEBUG_FORCEBIN
))
724 return (tiling
->tile_count
.width
* tiling
->tile_count
.height
) > 2;
728 use_sysmem_rendering(struct tu_cmd_buffer
*cmd
)
730 if (unlikely(cmd
->device
->physical_device
->instance
->debug_flags
& TU_DEBUG_SYSMEM
))
733 /* can't fit attachments into gmem */
734 if (!cmd
->state
.pass
->gmem_pixels
)
737 if (cmd
->state
.framebuffer
->layers
> 1)
743 return cmd
->state
.tiling_config
.force_sysmem
;
747 tu6_emit_tile_select(struct tu_cmd_buffer
*cmd
,
749 const struct tu_tile
*tile
)
751 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
752 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_YIELD
));
754 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
755 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_GMEM
));
757 const uint32_t x1
= tile
->begin
.x
;
758 const uint32_t y1
= tile
->begin
.y
;
759 const uint32_t x2
= tile
->end
.x
- 1;
760 const uint32_t y2
= tile
->end
.y
- 1;
761 tu6_emit_window_scissor(cs
, x1
, y1
, x2
, y2
);
762 tu6_emit_window_offset(cs
, x1
, y1
);
765 A6XX_VPC_SO_OVERRIDE(.so_disable
= false));
767 if (use_hw_binning(cmd
)) {
768 tu_cs_emit_pkt7(cs
, CP_WAIT_FOR_ME
, 0);
770 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
773 tu_cs_emit_pkt7(cs
, CP_SET_BIN_DATA5
, 7);
774 tu_cs_emit(cs
, cmd
->state
.tiling_config
.pipe_sizes
[tile
->pipe
] |
775 CP_SET_BIN_DATA5_0_VSC_N(tile
->slot
));
776 tu_cs_emit_qw(cs
, cmd
->vsc_draw_strm
.iova
+ tile
->pipe
* cmd
->vsc_draw_strm_pitch
);
777 tu_cs_emit_qw(cs
, cmd
->vsc_draw_strm
.iova
+ (tile
->pipe
* 4) + (32 * cmd
->vsc_draw_strm_pitch
));
778 tu_cs_emit_qw(cs
, cmd
->vsc_prim_strm
.iova
+ (tile
->pipe
* cmd
->vsc_prim_strm_pitch
));
780 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
783 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
786 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
789 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
795 tu6_emit_sysmem_resolve(struct tu_cmd_buffer
*cmd
,
800 const struct tu_framebuffer
*fb
= cmd
->state
.framebuffer
;
801 struct tu_image_view
*dst
= fb
->attachments
[a
].attachment
;
802 struct tu_image_view
*src
= fb
->attachments
[gmem_a
].attachment
;
804 tu_resolve_sysmem(cmd
, cs
, src
, dst
, fb
->layers
, &cmd
->state
.tiling_config
.render_area
);
808 tu6_emit_sysmem_resolves(struct tu_cmd_buffer
*cmd
,
810 const struct tu_subpass
*subpass
)
812 if (subpass
->resolve_attachments
) {
813 /* From the documentation for vkCmdNextSubpass, section 7.4 "Render Pass
816 * End-of-subpass multisample resolves are treated as color
817 * attachment writes for the purposes of synchronization. That is,
818 * they are considered to execute in the
819 * VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT pipeline stage and
820 * their writes are synchronized with
821 * VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT. Synchronization between
822 * rendering within a subpass and any resolve operations at the end
823 * of the subpass occurs automatically, without need for explicit
824 * dependencies or pipeline barriers. However, if the resolve
825 * attachment is also used in a different subpass, an explicit
826 * dependency is needed.
828 * We use the CP_BLIT path for sysmem resolves, which is really a
829 * transfer command, so we have to manually flush similar to the gmem
830 * resolve case. However, a flush afterwards isn't needed because of the
831 * last sentence and the fact that we're in sysmem mode.
833 tu6_emit_event_write(cmd
, cs
, PC_CCU_FLUSH_COLOR_TS
);
834 tu6_emit_event_write(cmd
, cs
, CACHE_INVALIDATE
);
836 /* Wait for the flushes to land before using the 2D engine */
839 for (unsigned i
= 0; i
< subpass
->color_count
; i
++) {
840 uint32_t a
= subpass
->resolve_attachments
[i
].attachment
;
841 if (a
== VK_ATTACHMENT_UNUSED
)
844 tu6_emit_sysmem_resolve(cmd
, cs
, a
,
845 subpass
->color_attachments
[i
].attachment
);
851 tu6_emit_tile_store(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
853 const struct tu_render_pass
*pass
= cmd
->state
.pass
;
854 const struct tu_subpass
*subpass
= &pass
->subpasses
[pass
->subpass_count
-1];
856 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 3);
857 tu_cs_emit(cs
, CP_SET_DRAW_STATE__0_COUNT(0) |
858 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
859 CP_SET_DRAW_STATE__0_GROUP_ID(0));
860 tu_cs_emit(cs
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
861 tu_cs_emit(cs
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
863 tu_cs_emit_pkt7(cs
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
866 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
867 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_RESOLVE
));
869 tu6_emit_blit_scissor(cmd
, cs
, true);
871 for (uint32_t a
= 0; a
< pass
->attachment_count
; ++a
) {
872 if (pass
->attachments
[a
].gmem_offset
>= 0)
873 tu_store_gmem_attachment(cmd
, cs
, a
, a
);
876 if (subpass
->resolve_attachments
) {
877 for (unsigned i
= 0; i
< subpass
->color_count
; i
++) {
878 uint32_t a
= subpass
->resolve_attachments
[i
].attachment
;
879 if (a
!= VK_ATTACHMENT_UNUSED
)
880 tu_store_gmem_attachment(cmd
, cs
, a
,
881 subpass
->color_attachments
[i
].attachment
);
887 tu6_init_hw(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
889 const struct tu_physical_device
*phys_dev
= cmd
->device
->physical_device
;
891 tu6_emit_event_write(cmd
, cs
, CACHE_INVALIDATE
);
893 tu_cs_emit_write_reg(cs
, REG_A6XX_HLSQ_UPDATE_CNTL
, 0xfffff);
896 A6XX_RB_CCU_CNTL(.offset
= phys_dev
->ccu_offset_bypass
));
897 cmd
->state
.ccu_state
= TU_CMD_CCU_SYSMEM
;
898 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8E04
, 0x00100000);
899 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_AE04
, 0x8);
900 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_AE00
, 0);
901 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_AE0F
, 0x3f);
902 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_B605
, 0x44);
903 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_B600
, 0x100000);
904 tu_cs_emit_write_reg(cs
, REG_A6XX_HLSQ_UNKNOWN_BE00
, 0x80);
905 tu_cs_emit_write_reg(cs
, REG_A6XX_HLSQ_UNKNOWN_BE01
, 0);
907 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9600
, 0);
908 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_8600
, 0x880);
909 tu_cs_emit_write_reg(cs
, REG_A6XX_HLSQ_UNKNOWN_BE04
, 0);
910 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_AE03
, 0x00000410);
911 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_IBO_COUNT
, 0);
912 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_B182
, 0);
913 tu_cs_emit_write_reg(cs
, REG_A6XX_HLSQ_UNKNOWN_BB11
, 0);
914 tu_cs_emit_write_reg(cs
, REG_A6XX_UCHE_UNKNOWN_0E12
, 0x3200000);
915 tu_cs_emit_write_reg(cs
, REG_A6XX_UCHE_CLIENT_PF
, 4);
916 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8E01
, 0x0);
917 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_A982
, 0);
918 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_A9A8
, 0);
919 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_AB00
, 0x5);
920 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_GS_SIV_CNTL
, 0x0000ffff);
922 /* TODO: set A6XX_VFD_ADD_OFFSET_INSTANCE and fix ir3 to avoid adding base instance */
923 tu_cs_emit_write_reg(cs
, REG_A6XX_VFD_ADD_OFFSET
, A6XX_VFD_ADD_OFFSET_VERTEX
);
924 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8811
, 0x00000010);
925 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_MODE_CNTL
, 0x1f);
927 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_SRGB_CNTL
, 0);
929 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_8110
, 0);
931 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_RENDER_CONTROL0
, 0x401);
932 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_RENDER_CONTROL1
, 0);
933 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_FS_OUTPUT_CNTL0
, 0);
934 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8818
, 0);
935 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8819
, 0);
936 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881A
, 0);
937 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881B
, 0);
938 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881C
, 0);
939 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881D
, 0);
940 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881E
, 0);
941 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_88F0
, 0);
943 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9101
, 0xffff00);
944 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9107
, 0);
946 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9236
,
947 A6XX_VPC_UNKNOWN_9236_POINT_COORD_INVERT(0));
948 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9300
, 0);
950 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_SO_OVERRIDE
,
951 A6XX_VPC_SO_OVERRIDE_SO_DISABLE
);
953 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9801
, 0);
954 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9980
, 0);
955 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9990
, 0);
957 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_PRIMITIVE_CNTL_6
, 0);
958 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9B07
, 0);
960 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_A81B
, 0);
962 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_B183
, 0);
964 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_8099
, 0);
965 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_809B
, 0);
966 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_80A0
, 2);
967 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_80AF
, 0);
968 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9210
, 0);
969 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9211
, 0);
970 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9602
, 0);
971 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9981
, 0x3);
972 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9E72
, 0);
973 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9108
, 0x3);
974 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_TP_UNKNOWN_B309
, 0x000000a2);
975 tu_cs_emit_write_reg(cs
, REG_A6XX_HLSQ_CONTROL_5_REG
, 0xfc);
977 tu_cs_emit_write_reg(cs
, REG_A6XX_VFD_MODE_CNTL
, 0x00000000);
979 tu_cs_emit_write_reg(cs
, REG_A6XX_VFD_UNKNOWN_A008
, 0);
981 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_MODE_CNTL
, 0x0000001f);
983 /* we don't use this yet.. probably best to disable.. */
984 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 3);
985 tu_cs_emit(cs
, CP_SET_DRAW_STATE__0_COUNT(0) |
986 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
987 CP_SET_DRAW_STATE__0_GROUP_ID(0));
988 tu_cs_emit(cs
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
989 tu_cs_emit(cs
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
992 A6XX_SP_HS_CTRL_REG0(0));
995 A6XX_SP_GS_CTRL_REG0(0));
998 A6XX_GRAS_LRZ_CNTL(0));
1001 A6XX_RB_LRZ_CNTL(0));
1004 A6XX_SP_TP_BORDER_COLOR_BASE_ADDR(.bo
= &cmd
->device
->border_color
));
1006 A6XX_SP_PS_TP_BORDER_COLOR_BASE_ADDR(.bo
= &cmd
->device
->border_color
));
1008 tu_cs_sanity_check(cs
);
1012 update_vsc_pipe(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1014 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1017 A6XX_VSC_BIN_SIZE(.width
= tiling
->tile0
.extent
.width
,
1018 .height
= tiling
->tile0
.extent
.height
),
1019 A6XX_VSC_DRAW_STRM_SIZE_ADDRESS(.bo
= &cmd
->vsc_draw_strm
,
1020 .bo_offset
= 32 * cmd
->vsc_draw_strm_pitch
));
1023 A6XX_VSC_BIN_COUNT(.nx
= tiling
->tile_count
.width
,
1024 .ny
= tiling
->tile_count
.height
));
1026 tu_cs_emit_pkt4(cs
, REG_A6XX_VSC_PIPE_CONFIG_REG(0), 32);
1027 for (unsigned i
= 0; i
< 32; i
++)
1028 tu_cs_emit(cs
, tiling
->pipe_config
[i
]);
1031 A6XX_VSC_PRIM_STRM_ADDRESS(.bo
= &cmd
->vsc_prim_strm
),
1032 A6XX_VSC_PRIM_STRM_PITCH(cmd
->vsc_prim_strm_pitch
),
1033 A6XX_VSC_PRIM_STRM_LIMIT(cmd
->vsc_prim_strm_pitch
- 64));
1036 A6XX_VSC_DRAW_STRM_ADDRESS(.bo
= &cmd
->vsc_draw_strm
),
1037 A6XX_VSC_DRAW_STRM_PITCH(cmd
->vsc_draw_strm_pitch
),
1038 A6XX_VSC_DRAW_STRM_LIMIT(cmd
->vsc_draw_strm_pitch
- 64));
1042 emit_vsc_overflow_test(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1044 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1045 const uint32_t used_pipe_count
=
1046 tiling
->pipe_count
.width
* tiling
->pipe_count
.height
;
1048 /* Clear vsc_scratch: */
1049 tu_cs_emit_pkt7(cs
, CP_MEM_WRITE
, 3);
1050 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(vsc_scratch
));
1051 tu_cs_emit(cs
, 0x0);
1053 /* Check for overflow, write vsc_scratch if detected: */
1054 for (int i
= 0; i
< used_pipe_count
; i
++) {
1055 tu_cs_emit_pkt7(cs
, CP_COND_WRITE5
, 8);
1056 tu_cs_emit(cs
, CP_COND_WRITE5_0_FUNCTION(WRITE_GE
) |
1057 CP_COND_WRITE5_0_WRITE_MEMORY
);
1058 tu_cs_emit(cs
, CP_COND_WRITE5_1_POLL_ADDR_LO(REG_A6XX_VSC_DRAW_STRM_SIZE_REG(i
)));
1059 tu_cs_emit(cs
, CP_COND_WRITE5_2_POLL_ADDR_HI(0));
1060 tu_cs_emit(cs
, CP_COND_WRITE5_3_REF(cmd
->vsc_draw_strm_pitch
- 64));
1061 tu_cs_emit(cs
, CP_COND_WRITE5_4_MASK(~0));
1062 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(vsc_scratch
));
1063 tu_cs_emit(cs
, CP_COND_WRITE5_7_WRITE_DATA(1 + cmd
->vsc_draw_strm_pitch
));
1065 tu_cs_emit_pkt7(cs
, CP_COND_WRITE5
, 8);
1066 tu_cs_emit(cs
, CP_COND_WRITE5_0_FUNCTION(WRITE_GE
) |
1067 CP_COND_WRITE5_0_WRITE_MEMORY
);
1068 tu_cs_emit(cs
, CP_COND_WRITE5_1_POLL_ADDR_LO(REG_A6XX_VSC_PRIM_STRM_SIZE_REG(i
)));
1069 tu_cs_emit(cs
, CP_COND_WRITE5_2_POLL_ADDR_HI(0));
1070 tu_cs_emit(cs
, CP_COND_WRITE5_3_REF(cmd
->vsc_prim_strm_pitch
- 64));
1071 tu_cs_emit(cs
, CP_COND_WRITE5_4_MASK(~0));
1072 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(vsc_scratch
));
1073 tu_cs_emit(cs
, CP_COND_WRITE5_7_WRITE_DATA(3 + cmd
->vsc_prim_strm_pitch
));
1076 tu_cs_emit_pkt7(cs
, CP_WAIT_MEM_WRITES
, 0);
1080 tu6_emit_binning_pass(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1082 struct tu_physical_device
*phys_dev
= cmd
->device
->physical_device
;
1083 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1085 uint32_t x1
= tiling
->tile0
.offset
.x
;
1086 uint32_t y1
= tiling
->tile0
.offset
.y
;
1087 uint32_t x2
= tiling
->render_area
.offset
.x
+ tiling
->render_area
.extent
.width
- 1;
1088 uint32_t y2
= tiling
->render_area
.offset
.y
+ tiling
->render_area
.extent
.height
- 1;
1090 tu6_emit_window_scissor(cs
, x1
, y1
, x2
, y2
);
1092 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
1093 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_BINNING
));
1095 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
1096 tu_cs_emit(cs
, 0x1);
1098 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
1099 tu_cs_emit(cs
, 0x1);
1104 A6XX_VFD_MODE_CNTL(.binning_pass
= true));
1106 update_vsc_pipe(cmd
, cs
);
1109 A6XX_PC_UNKNOWN_9805(.unknown
= phys_dev
->magic
.PC_UNKNOWN_9805
));
1112 A6XX_SP_UNKNOWN_A0F8(.unknown
= phys_dev
->magic
.SP_UNKNOWN_A0F8
));
1114 tu_cs_emit_pkt7(cs
, CP_EVENT_WRITE
, 1);
1115 tu_cs_emit(cs
, UNK_2C
);
1118 A6XX_RB_WINDOW_OFFSET(.x
= 0, .y
= 0));
1121 A6XX_SP_TP_WINDOW_OFFSET(.x
= 0, .y
= 0));
1123 /* emit IB to binning drawcmds: */
1124 tu_cs_emit_call(cs
, &cmd
->draw_cs
);
1126 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 3);
1127 tu_cs_emit(cs
, CP_SET_DRAW_STATE__0_COUNT(0) |
1128 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
1129 CP_SET_DRAW_STATE__0_GROUP_ID(0));
1130 tu_cs_emit(cs
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
1131 tu_cs_emit(cs
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
1133 tu_cs_emit_pkt7(cs
, CP_EVENT_WRITE
, 1);
1134 tu_cs_emit(cs
, UNK_2D
);
1136 /* This flush is probably required because the VSC, which produces the
1137 * visibility stream, is a client of UCHE, whereas the CP needs to read the
1138 * visibility stream (without caching) to do draw skipping. The
1139 * WFI+WAIT_FOR_ME combination guarantees that the binning commands
1140 * submitted are finished before reading the VSC regs (in
1141 * emit_vsc_overflow_test) or the VSC_DATA buffer directly (implicitly as
1144 tu6_emit_event_write(cmd
, cs
, CACHE_FLUSH_TS
);
1148 tu_cs_emit_pkt7(cs
, CP_WAIT_FOR_ME
, 0);
1150 emit_vsc_overflow_test(cmd
, cs
);
1152 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
1153 tu_cs_emit(cs
, 0x0);
1155 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
1156 tu_cs_emit(cs
, 0x0);
1160 tu_emit_input_attachments(struct tu_cmd_buffer
*cmd
,
1161 const struct tu_subpass
*subpass
,
1162 struct tu_cs_entry
*ib
,
1165 /* note: we can probably emit input attachments just once for the whole
1166 * renderpass, this would avoid emitting both sysmem/gmem versions
1168 * emit two texture descriptors for each input, as a workaround for
1169 * d24s8, which can be sampled as both float (depth) and integer (stencil)
1170 * tu_shader lowers uint input attachment loads to use the 2nd descriptor
1172 * TODO: a smarter workaround
1175 if (!subpass
->input_count
)
1178 struct tu_cs_memory texture
;
1179 VkResult result
= tu_cs_alloc(&cmd
->sub_cs
, subpass
->input_count
* 2,
1180 A6XX_TEX_CONST_DWORDS
, &texture
);
1181 assert(result
== VK_SUCCESS
);
1183 for (unsigned i
= 0; i
< subpass
->input_count
* 2; i
++) {
1184 uint32_t a
= subpass
->input_attachments
[i
/ 2].attachment
;
1185 if (a
== VK_ATTACHMENT_UNUSED
)
1188 struct tu_image_view
*iview
=
1189 cmd
->state
.framebuffer
->attachments
[a
].attachment
;
1190 const struct tu_render_pass_attachment
*att
=
1191 &cmd
->state
.pass
->attachments
[a
];
1192 uint32_t *dst
= &texture
.map
[A6XX_TEX_CONST_DWORDS
* i
];
1194 memcpy(dst
, iview
->descriptor
, A6XX_TEX_CONST_DWORDS
* 4);
1196 if (i
% 2 == 1 && att
->format
== VK_FORMAT_D24_UNORM_S8_UINT
) {
1197 /* note this works because spec says fb and input attachments
1198 * must use identity swizzle
1200 dst
[0] &= ~(A6XX_TEX_CONST_0_FMT__MASK
|
1201 A6XX_TEX_CONST_0_SWIZ_X__MASK
| A6XX_TEX_CONST_0_SWIZ_Y__MASK
|
1202 A6XX_TEX_CONST_0_SWIZ_Z__MASK
| A6XX_TEX_CONST_0_SWIZ_W__MASK
);
1203 dst
[0] |= A6XX_TEX_CONST_0_FMT(FMT6_S8Z24_UINT
) |
1204 A6XX_TEX_CONST_0_SWIZ_X(A6XX_TEX_Y
) |
1205 A6XX_TEX_CONST_0_SWIZ_Y(A6XX_TEX_ZERO
) |
1206 A6XX_TEX_CONST_0_SWIZ_Z(A6XX_TEX_ZERO
) |
1207 A6XX_TEX_CONST_0_SWIZ_W(A6XX_TEX_ONE
);
1213 /* patched for gmem */
1214 dst
[0] &= ~(A6XX_TEX_CONST_0_SWAP__MASK
| A6XX_TEX_CONST_0_TILE_MODE__MASK
);
1215 dst
[0] |= A6XX_TEX_CONST_0_TILE_MODE(TILE6_2
);
1217 A6XX_TEX_CONST_2_TYPE(A6XX_TEX_2D
) |
1218 A6XX_TEX_CONST_2_PITCH(cmd
->state
.tiling_config
.tile0
.extent
.width
* att
->cpp
);
1220 dst
[4] = cmd
->device
->physical_device
->gmem_base
+ att
->gmem_offset
;
1221 dst
[5] = A6XX_TEX_CONST_5_DEPTH(1);
1222 for (unsigned i
= 6; i
< A6XX_TEX_CONST_DWORDS
; i
++)
1227 tu_cs_begin_sub_stream(&cmd
->sub_cs
, 9, &cs
);
1229 tu_cs_emit_pkt7(&cs
, CP_LOAD_STATE6_FRAG
, 3);
1230 tu_cs_emit(&cs
, CP_LOAD_STATE6_0_DST_OFF(0) |
1231 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
1232 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
1233 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_FS_TEX
) |
1234 CP_LOAD_STATE6_0_NUM_UNIT(subpass
->input_count
* 2));
1235 tu_cs_emit_qw(&cs
, texture
.iova
);
1237 tu_cs_emit_pkt4(&cs
, REG_A6XX_SP_FS_TEX_CONST_LO
, 2);
1238 tu_cs_emit_qw(&cs
, texture
.iova
);
1240 tu_cs_emit_regs(&cs
, A6XX_SP_FS_TEX_COUNT(subpass
->input_count
* 2));
1242 *ib
= tu_cs_end_sub_stream(&cmd
->sub_cs
, &cs
);
1246 tu_set_input_attachments(struct tu_cmd_buffer
*cmd
, const struct tu_subpass
*subpass
)
1248 struct tu_cs
*cs
= &cmd
->draw_cs
;
1250 tu_emit_input_attachments(cmd
, subpass
, &cmd
->state
.ia_gmem_ib
, true);
1251 tu_emit_input_attachments(cmd
, subpass
, &cmd
->state
.ia_sysmem_ib
, false);
1253 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 6);
1254 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_INPUT_ATTACHMENTS_GMEM
, cmd
->state
.ia_gmem_ib
);
1255 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_INPUT_ATTACHMENTS_SYSMEM
, cmd
->state
.ia_sysmem_ib
);
1259 tu_emit_renderpass_begin(struct tu_cmd_buffer
*cmd
,
1260 const VkRenderPassBeginInfo
*info
)
1262 struct tu_cs
*cs
= &cmd
->draw_cs
;
1264 tu_cond_exec_start(cs
, CP_COND_EXEC_0_RENDER_MODE_GMEM
);
1266 tu6_emit_blit_scissor(cmd
, cs
, true);
1268 for (uint32_t i
= 0; i
< cmd
->state
.pass
->attachment_count
; ++i
)
1269 tu_load_gmem_attachment(cmd
, cs
, i
, false);
1271 tu6_emit_blit_scissor(cmd
, cs
, false);
1273 for (uint32_t i
= 0; i
< cmd
->state
.pass
->attachment_count
; ++i
)
1274 tu_clear_gmem_attachment(cmd
, cs
, i
, info
);
1276 tu_cond_exec_end(cs
);
1278 tu_cond_exec_start(cs
, CP_COND_EXEC_0_RENDER_MODE_SYSMEM
);
1280 for (uint32_t i
= 0; i
< cmd
->state
.pass
->attachment_count
; ++i
)
1281 tu_clear_sysmem_attachment(cmd
, cs
, i
, info
);
1283 tu_cond_exec_end(cs
);
1287 tu6_sysmem_render_begin(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
,
1288 const struct VkRect2D
*renderArea
)
1290 const struct tu_framebuffer
*fb
= cmd
->state
.framebuffer
;
1292 assert(fb
->width
> 0 && fb
->height
> 0);
1293 tu6_emit_window_scissor(cs
, 0, 0, fb
->width
- 1, fb
->height
- 1);
1294 tu6_emit_window_offset(cs
, 0, 0);
1296 tu6_emit_bin_size(cs
, 0, 0, 0xc00000); /* 0xc00000 = BYPASS? */
1298 tu6_emit_event_write(cmd
, cs
, LRZ_FLUSH
);
1300 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
1301 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_BYPASS
));
1303 tu_cs_emit_pkt7(cs
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1304 tu_cs_emit(cs
, 0x0);
1306 tu_emit_cache_flush_ccu(cmd
, cs
, TU_CMD_CCU_SYSMEM
);
1308 /* enable stream-out, with sysmem there is only one pass: */
1310 A6XX_VPC_SO_OVERRIDE(.so_disable
= false));
1312 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
1313 tu_cs_emit(cs
, 0x1);
1315 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
1316 tu_cs_emit(cs
, 0x0);
1318 tu_cs_sanity_check(cs
);
1322 tu6_sysmem_render_end(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1324 /* Do any resolves of the last subpass. These are handled in the
1325 * tile_store_ib in the gmem path.
1327 tu6_emit_sysmem_resolves(cmd
, cs
, cmd
->state
.subpass
);
1329 tu_cs_emit_call(cs
, &cmd
->draw_epilogue_cs
);
1331 tu_cs_emit_pkt7(cs
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1332 tu_cs_emit(cs
, 0x0);
1334 tu6_emit_event_write(cmd
, cs
, LRZ_FLUSH
);
1336 tu_cs_sanity_check(cs
);
1340 tu6_tile_render_begin(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1342 struct tu_physical_device
*phys_dev
= cmd
->device
->physical_device
;
1344 tu6_emit_event_write(cmd
, cs
, LRZ_FLUSH
);
1348 tu_cs_emit_pkt7(cs
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1349 tu_cs_emit(cs
, 0x0);
1351 tu_emit_cache_flush_ccu(cmd
, cs
, TU_CMD_CCU_GMEM
);
1353 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1354 if (use_hw_binning(cmd
)) {
1355 /* enable stream-out during binning pass: */
1356 tu_cs_emit_regs(cs
, A6XX_VPC_SO_OVERRIDE(.so_disable
=false));
1358 tu6_emit_bin_size(cs
,
1359 tiling
->tile0
.extent
.width
,
1360 tiling
->tile0
.extent
.height
,
1361 A6XX_RB_BIN_CONTROL_BINNING_PASS
| 0x6000000);
1363 tu6_emit_render_cntl(cmd
, cmd
->state
.subpass
, cs
, true);
1365 tu6_emit_binning_pass(cmd
, cs
);
1367 /* and disable stream-out for draw pass: */
1368 tu_cs_emit_regs(cs
, A6XX_VPC_SO_OVERRIDE(.so_disable
=true));
1370 tu6_emit_bin_size(cs
,
1371 tiling
->tile0
.extent
.width
,
1372 tiling
->tile0
.extent
.height
,
1373 A6XX_RB_BIN_CONTROL_USE_VIZ
| 0x6000000);
1376 A6XX_VFD_MODE_CNTL(0));
1378 tu_cs_emit_regs(cs
, A6XX_PC_UNKNOWN_9805(.unknown
= phys_dev
->magic
.PC_UNKNOWN_9805
));
1380 tu_cs_emit_regs(cs
, A6XX_SP_UNKNOWN_A0F8(.unknown
= phys_dev
->magic
.SP_UNKNOWN_A0F8
));
1382 tu_cs_emit_pkt7(cs
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1383 tu_cs_emit(cs
, 0x1);
1385 /* no binning pass, so enable stream-out for draw pass:: */
1386 tu_cs_emit_regs(cs
, A6XX_VPC_SO_OVERRIDE(.so_disable
=false));
1388 tu6_emit_bin_size(cs
,
1389 tiling
->tile0
.extent
.width
,
1390 tiling
->tile0
.extent
.height
,
1394 tu_cs_sanity_check(cs
);
1398 tu6_render_tile(struct tu_cmd_buffer
*cmd
,
1400 const struct tu_tile
*tile
)
1402 tu6_emit_tile_select(cmd
, cs
, tile
);
1404 tu_cs_emit_call(cs
, &cmd
->draw_cs
);
1406 if (use_hw_binning(cmd
)) {
1407 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
1408 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_ENDVIS
));
1411 tu_cs_emit_ib(cs
, &cmd
->state
.tile_store_ib
);
1413 tu_cs_sanity_check(cs
);
1417 tu6_tile_render_end(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1419 tu_cs_emit_call(cs
, &cmd
->draw_epilogue_cs
);
1422 A6XX_GRAS_LRZ_CNTL(0));
1424 tu6_emit_event_write(cmd
, cs
, LRZ_FLUSH
);
1426 tu6_emit_event_write(cmd
, cs
, PC_CCU_RESOLVE_TS
);
1428 tu_cs_sanity_check(cs
);
1432 tu_cmd_render_tiles(struct tu_cmd_buffer
*cmd
)
1434 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1436 if (use_hw_binning(cmd
))
1437 cmd
->use_vsc_data
= true;
1439 tu6_tile_render_begin(cmd
, &cmd
->cs
);
1441 for (uint32_t y
= 0; y
< tiling
->tile_count
.height
; y
++) {
1442 for (uint32_t x
= 0; x
< tiling
->tile_count
.width
; x
++) {
1443 struct tu_tile tile
;
1444 tu_tiling_config_get_tile(tiling
, cmd
->device
, x
, y
, &tile
);
1445 tu6_render_tile(cmd
, &cmd
->cs
, &tile
);
1449 tu6_tile_render_end(cmd
, &cmd
->cs
);
1453 tu_cmd_render_sysmem(struct tu_cmd_buffer
*cmd
)
1455 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1457 tu6_sysmem_render_begin(cmd
, &cmd
->cs
, &tiling
->render_area
);
1459 tu_cs_emit_call(&cmd
->cs
, &cmd
->draw_cs
);
1461 tu6_sysmem_render_end(cmd
, &cmd
->cs
);
1465 tu_cmd_prepare_tile_store_ib(struct tu_cmd_buffer
*cmd
)
1467 const uint32_t tile_store_space
= 11 + (35 * 2) * cmd
->state
.pass
->attachment_count
;
1468 struct tu_cs sub_cs
;
1471 tu_cs_begin_sub_stream(&cmd
->sub_cs
, tile_store_space
, &sub_cs
);
1472 if (result
!= VK_SUCCESS
) {
1473 cmd
->record_result
= result
;
1477 /* emit to tile-store sub_cs */
1478 tu6_emit_tile_store(cmd
, &sub_cs
);
1480 cmd
->state
.tile_store_ib
= tu_cs_end_sub_stream(&cmd
->sub_cs
, &sub_cs
);
1484 tu_cmd_update_tiling_config(struct tu_cmd_buffer
*cmd
,
1485 const VkRect2D
*render_area
)
1487 const struct tu_device
*dev
= cmd
->device
;
1488 struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1490 tiling
->render_area
= *render_area
;
1491 tiling
->force_sysmem
= false;
1493 tu_tiling_config_update_tile_layout(tiling
, dev
, cmd
->state
.pass
);
1494 tu_tiling_config_update_pipe_layout(tiling
, dev
);
1495 tu_tiling_config_update_pipes(tiling
, dev
);
1499 tu_create_cmd_buffer(struct tu_device
*device
,
1500 struct tu_cmd_pool
*pool
,
1501 VkCommandBufferLevel level
,
1502 VkCommandBuffer
*pCommandBuffer
)
1504 struct tu_cmd_buffer
*cmd_buffer
;
1505 cmd_buffer
= vk_zalloc(&pool
->alloc
, sizeof(*cmd_buffer
), 8,
1506 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1507 if (cmd_buffer
== NULL
)
1508 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1510 cmd_buffer
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1511 cmd_buffer
->device
= device
;
1512 cmd_buffer
->pool
= pool
;
1513 cmd_buffer
->level
= level
;
1516 list_addtail(&cmd_buffer
->pool_link
, &pool
->cmd_buffers
);
1517 cmd_buffer
->queue_family_index
= pool
->queue_family_index
;
1520 /* Init the pool_link so we can safely call list_del when we destroy
1521 * the command buffer
1523 list_inithead(&cmd_buffer
->pool_link
);
1524 cmd_buffer
->queue_family_index
= TU_QUEUE_GENERAL
;
1527 tu_bo_list_init(&cmd_buffer
->bo_list
);
1528 tu_cs_init(&cmd_buffer
->cs
, device
, TU_CS_MODE_GROW
, 4096);
1529 tu_cs_init(&cmd_buffer
->draw_cs
, device
, TU_CS_MODE_GROW
, 4096);
1530 tu_cs_init(&cmd_buffer
->draw_epilogue_cs
, device
, TU_CS_MODE_GROW
, 4096);
1531 tu_cs_init(&cmd_buffer
->sub_cs
, device
, TU_CS_MODE_SUB_STREAM
, 2048);
1533 *pCommandBuffer
= tu_cmd_buffer_to_handle(cmd_buffer
);
1535 list_inithead(&cmd_buffer
->upload
.list
);
1537 VkResult result
= tu_bo_init_new(device
, &cmd_buffer
->scratch_bo
, 0x1000);
1538 if (result
!= VK_SUCCESS
)
1539 goto fail_scratch_bo
;
1541 /* TODO: resize on overflow */
1542 cmd_buffer
->vsc_draw_strm_pitch
= device
->vsc_draw_strm_pitch
;
1543 cmd_buffer
->vsc_prim_strm_pitch
= device
->vsc_prim_strm_pitch
;
1544 cmd_buffer
->vsc_draw_strm
= device
->vsc_draw_strm
;
1545 cmd_buffer
->vsc_prim_strm
= device
->vsc_prim_strm
;
1550 list_del(&cmd_buffer
->pool_link
);
1555 tu_cmd_buffer_destroy(struct tu_cmd_buffer
*cmd_buffer
)
1557 tu_bo_finish(cmd_buffer
->device
, &cmd_buffer
->scratch_bo
);
1559 list_del(&cmd_buffer
->pool_link
);
1561 tu_cs_finish(&cmd_buffer
->cs
);
1562 tu_cs_finish(&cmd_buffer
->draw_cs
);
1563 tu_cs_finish(&cmd_buffer
->draw_epilogue_cs
);
1564 tu_cs_finish(&cmd_buffer
->sub_cs
);
1566 tu_bo_list_destroy(&cmd_buffer
->bo_list
);
1567 vk_free(&cmd_buffer
->pool
->alloc
, cmd_buffer
);
1571 tu_reset_cmd_buffer(struct tu_cmd_buffer
*cmd_buffer
)
1573 cmd_buffer
->record_result
= VK_SUCCESS
;
1575 tu_bo_list_reset(&cmd_buffer
->bo_list
);
1576 tu_cs_reset(&cmd_buffer
->cs
);
1577 tu_cs_reset(&cmd_buffer
->draw_cs
);
1578 tu_cs_reset(&cmd_buffer
->draw_epilogue_cs
);
1579 tu_cs_reset(&cmd_buffer
->sub_cs
);
1581 for (unsigned i
= 0; i
< MAX_BIND_POINTS
; i
++)
1582 memset(&cmd_buffer
->descriptors
[i
].sets
, 0, sizeof(cmd_buffer
->descriptors
[i
].sets
));
1584 cmd_buffer
->status
= TU_CMD_BUFFER_STATUS_INITIAL
;
1586 return cmd_buffer
->record_result
;
1590 tu_AllocateCommandBuffers(VkDevice _device
,
1591 const VkCommandBufferAllocateInfo
*pAllocateInfo
,
1592 VkCommandBuffer
*pCommandBuffers
)
1594 TU_FROM_HANDLE(tu_device
, device
, _device
);
1595 TU_FROM_HANDLE(tu_cmd_pool
, pool
, pAllocateInfo
->commandPool
);
1597 VkResult result
= VK_SUCCESS
;
1600 for (i
= 0; i
< pAllocateInfo
->commandBufferCount
; i
++) {
1602 if (!list_is_empty(&pool
->free_cmd_buffers
)) {
1603 struct tu_cmd_buffer
*cmd_buffer
= list_first_entry(
1604 &pool
->free_cmd_buffers
, struct tu_cmd_buffer
, pool_link
);
1606 list_del(&cmd_buffer
->pool_link
);
1607 list_addtail(&cmd_buffer
->pool_link
, &pool
->cmd_buffers
);
1609 result
= tu_reset_cmd_buffer(cmd_buffer
);
1610 cmd_buffer
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1611 cmd_buffer
->level
= pAllocateInfo
->level
;
1613 pCommandBuffers
[i
] = tu_cmd_buffer_to_handle(cmd_buffer
);
1615 result
= tu_create_cmd_buffer(device
, pool
, pAllocateInfo
->level
,
1616 &pCommandBuffers
[i
]);
1618 if (result
!= VK_SUCCESS
)
1622 if (result
!= VK_SUCCESS
) {
1623 tu_FreeCommandBuffers(_device
, pAllocateInfo
->commandPool
, i
,
1626 /* From the Vulkan 1.0.66 spec:
1628 * "vkAllocateCommandBuffers can be used to create multiple
1629 * command buffers. If the creation of any of those command
1630 * buffers fails, the implementation must destroy all
1631 * successfully created command buffer objects from this
1632 * command, set all entries of the pCommandBuffers array to
1633 * NULL and return the error."
1635 memset(pCommandBuffers
, 0,
1636 sizeof(*pCommandBuffers
) * pAllocateInfo
->commandBufferCount
);
1643 tu_FreeCommandBuffers(VkDevice device
,
1644 VkCommandPool commandPool
,
1645 uint32_t commandBufferCount
,
1646 const VkCommandBuffer
*pCommandBuffers
)
1648 for (uint32_t i
= 0; i
< commandBufferCount
; i
++) {
1649 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, pCommandBuffers
[i
]);
1652 if (cmd_buffer
->pool
) {
1653 list_del(&cmd_buffer
->pool_link
);
1654 list_addtail(&cmd_buffer
->pool_link
,
1655 &cmd_buffer
->pool
->free_cmd_buffers
);
1657 tu_cmd_buffer_destroy(cmd_buffer
);
1663 tu_ResetCommandBuffer(VkCommandBuffer commandBuffer
,
1664 VkCommandBufferResetFlags flags
)
1666 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
1667 return tu_reset_cmd_buffer(cmd_buffer
);
1670 /* Initialize the cache, assuming all necessary flushes have happened but *not*
1674 tu_cache_init(struct tu_cache_state
*cache
)
1676 cache
->flush_bits
= 0;
1677 cache
->pending_flush_bits
= TU_CMD_FLAG_ALL_INVALIDATE
;
1681 tu_BeginCommandBuffer(VkCommandBuffer commandBuffer
,
1682 const VkCommandBufferBeginInfo
*pBeginInfo
)
1684 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
1685 VkResult result
= VK_SUCCESS
;
1687 if (cmd_buffer
->status
!= TU_CMD_BUFFER_STATUS_INITIAL
) {
1688 /* If the command buffer has already been resetted with
1689 * vkResetCommandBuffer, no need to do it again.
1691 result
= tu_reset_cmd_buffer(cmd_buffer
);
1692 if (result
!= VK_SUCCESS
)
1696 memset(&cmd_buffer
->state
, 0, sizeof(cmd_buffer
->state
));
1697 cmd_buffer
->state
.index_size
= 0xff; /* dirty restart index */
1699 tu_cache_init(&cmd_buffer
->state
.cache
);
1700 tu_cache_init(&cmd_buffer
->state
.renderpass_cache
);
1701 cmd_buffer
->usage_flags
= pBeginInfo
->flags
;
1703 tu_cs_begin(&cmd_buffer
->cs
);
1704 tu_cs_begin(&cmd_buffer
->draw_cs
);
1705 tu_cs_begin(&cmd_buffer
->draw_epilogue_cs
);
1707 /* setup initial configuration into command buffer */
1708 if (cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
) {
1709 switch (cmd_buffer
->queue_family_index
) {
1710 case TU_QUEUE_GENERAL
:
1711 tu6_init_hw(cmd_buffer
, &cmd_buffer
->cs
);
1716 } else if (cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_SECONDARY
) {
1717 if (pBeginInfo
->flags
& VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
) {
1718 assert(pBeginInfo
->pInheritanceInfo
);
1719 cmd_buffer
->state
.pass
= tu_render_pass_from_handle(pBeginInfo
->pInheritanceInfo
->renderPass
);
1720 cmd_buffer
->state
.subpass
=
1721 &cmd_buffer
->state
.pass
->subpasses
[pBeginInfo
->pInheritanceInfo
->subpass
];
1723 /* When executing in the middle of another command buffer, the CCU
1726 cmd_buffer
->state
.ccu_state
= TU_CMD_CCU_UNKNOWN
;
1730 cmd_buffer
->status
= TU_CMD_BUFFER_STATUS_RECORDING
;
1735 /* Sets vertex buffers to HW binding points. We emit VBs in SDS (so that bin
1736 * rendering can skip over unused state), so we need to collect all the
1737 * bindings together into a single state emit at draw time.
1740 tu_CmdBindVertexBuffers(VkCommandBuffer commandBuffer
,
1741 uint32_t firstBinding
,
1742 uint32_t bindingCount
,
1743 const VkBuffer
*pBuffers
,
1744 const VkDeviceSize
*pOffsets
)
1746 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1748 assert(firstBinding
+ bindingCount
<= MAX_VBS
);
1750 for (uint32_t i
= 0; i
< bindingCount
; i
++) {
1751 struct tu_buffer
*buf
= tu_buffer_from_handle(pBuffers
[i
]);
1753 cmd
->state
.vb
.buffers
[firstBinding
+ i
] = buf
;
1754 cmd
->state
.vb
.offsets
[firstBinding
+ i
] = pOffsets
[i
];
1756 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_READ
);
1759 cmd
->state
.dirty
|= TU_CMD_DIRTY_VERTEX_BUFFERS
;
1763 tu_CmdBindIndexBuffer(VkCommandBuffer commandBuffer
,
1765 VkDeviceSize offset
,
1766 VkIndexType indexType
)
1768 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1769 TU_FROM_HANDLE(tu_buffer
, buf
, buffer
);
1773 uint32_t index_size
, index_shift
, restart_index
;
1775 switch (indexType
) {
1776 case VK_INDEX_TYPE_UINT16
:
1777 index_size
= INDEX4_SIZE_16_BIT
;
1779 restart_index
= 0xffff;
1781 case VK_INDEX_TYPE_UINT32
:
1782 index_size
= INDEX4_SIZE_32_BIT
;
1784 restart_index
= 0xffffffff;
1786 case VK_INDEX_TYPE_UINT8_EXT
:
1787 index_size
= INDEX4_SIZE_8_BIT
;
1789 restart_index
= 0xff;
1792 unreachable("invalid VkIndexType");
1795 /* initialize/update the restart index */
1796 if (cmd
->state
.index_size
!= index_size
)
1797 tu_cs_emit_regs(&cmd
->draw_cs
, A6XX_PC_RESTART_INDEX(restart_index
));
1799 assert(buf
->size
>= offset
);
1801 cmd
->state
.index_va
= buf
->bo
->iova
+ buf
->bo_offset
+ offset
;
1802 cmd
->state
.max_index_count
= (buf
->size
- offset
) >> index_shift
;
1803 cmd
->state
.index_size
= index_size
;
1804 cmd
->state
.index_shift
= index_shift
;
1806 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_READ
);
1810 tu_CmdBindDescriptorSets(VkCommandBuffer commandBuffer
,
1811 VkPipelineBindPoint pipelineBindPoint
,
1812 VkPipelineLayout _layout
,
1814 uint32_t descriptorSetCount
,
1815 const VkDescriptorSet
*pDescriptorSets
,
1816 uint32_t dynamicOffsetCount
,
1817 const uint32_t *pDynamicOffsets
)
1819 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1820 TU_FROM_HANDLE(tu_pipeline_layout
, layout
, _layout
);
1821 unsigned dyn_idx
= 0;
1823 struct tu_descriptor_state
*descriptors_state
=
1824 tu_get_descriptors_state(cmd
, pipelineBindPoint
);
1826 for (unsigned i
= 0; i
< descriptorSetCount
; ++i
) {
1827 unsigned idx
= i
+ firstSet
;
1828 TU_FROM_HANDLE(tu_descriptor_set
, set
, pDescriptorSets
[i
]);
1830 descriptors_state
->sets
[idx
] = set
;
1832 for(unsigned j
= 0; j
< set
->layout
->dynamic_offset_count
; ++j
, ++dyn_idx
) {
1833 /* update the contents of the dynamic descriptor set */
1834 unsigned src_idx
= j
;
1835 unsigned dst_idx
= j
+ layout
->set
[idx
].dynamic_offset_start
;
1836 assert(dyn_idx
< dynamicOffsetCount
);
1839 &descriptors_state
->dynamic_descriptors
[dst_idx
* A6XX_TEX_CONST_DWORDS
];
1841 &set
->dynamic_descriptors
[src_idx
* A6XX_TEX_CONST_DWORDS
];
1842 uint32_t offset
= pDynamicOffsets
[dyn_idx
];
1844 /* Patch the storage/uniform descriptors right away. */
1845 if (layout
->set
[idx
].layout
->dynamic_ubo
& (1 << j
)) {
1846 /* Note: we can assume here that the addition won't roll over and
1847 * change the SIZE field.
1849 uint64_t va
= src
[0] | ((uint64_t)src
[1] << 32);
1854 memcpy(dst
, src
, A6XX_TEX_CONST_DWORDS
* 4);
1855 /* Note: A6XX_IBO_5_DEPTH is always 0 */
1856 uint64_t va
= dst
[4] | ((uint64_t)dst
[5] << 32);
1863 for (unsigned j
= 0; j
< set
->layout
->buffer_count
; ++j
) {
1864 if (set
->buffers
[j
]) {
1865 tu_bo_list_add(&cmd
->bo_list
, set
->buffers
[j
],
1866 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
1870 if (set
->size
> 0) {
1871 tu_bo_list_add(&cmd
->bo_list
, &set
->pool
->bo
,
1872 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
1875 assert(dyn_idx
== dynamicOffsetCount
);
1877 uint32_t sp_bindless_base_reg
, hlsq_bindless_base_reg
, hlsq_update_value
;
1878 uint64_t addr
[MAX_SETS
+ 1] = {};
1881 for (uint32_t i
= 0; i
< MAX_SETS
; i
++) {
1882 struct tu_descriptor_set
*set
= descriptors_state
->sets
[i
];
1884 addr
[i
] = set
->va
| 3;
1887 if (layout
->dynamic_offset_count
) {
1888 /* allocate and fill out dynamic descriptor set */
1889 struct tu_cs_memory dynamic_desc_set
;
1890 VkResult result
= tu_cs_alloc(&cmd
->sub_cs
, layout
->dynamic_offset_count
,
1891 A6XX_TEX_CONST_DWORDS
, &dynamic_desc_set
);
1892 assert(result
== VK_SUCCESS
);
1894 memcpy(dynamic_desc_set
.map
, descriptors_state
->dynamic_descriptors
,
1895 layout
->dynamic_offset_count
* A6XX_TEX_CONST_DWORDS
* 4);
1896 addr
[MAX_SETS
] = dynamic_desc_set
.iova
| 3;
1899 if (pipelineBindPoint
== VK_PIPELINE_BIND_POINT_GRAPHICS
) {
1900 sp_bindless_base_reg
= REG_A6XX_SP_BINDLESS_BASE(0);
1901 hlsq_bindless_base_reg
= REG_A6XX_HLSQ_BINDLESS_BASE(0);
1902 hlsq_update_value
= 0x7c000;
1904 cmd
->state
.dirty
|= TU_CMD_DIRTY_DESCRIPTOR_SETS
| TU_CMD_DIRTY_SHADER_CONSTS
;
1906 assert(pipelineBindPoint
== VK_PIPELINE_BIND_POINT_COMPUTE
);
1908 sp_bindless_base_reg
= REG_A6XX_SP_CS_BINDLESS_BASE(0);
1909 hlsq_bindless_base_reg
= REG_A6XX_HLSQ_CS_BINDLESS_BASE(0);
1910 hlsq_update_value
= 0x3e00;
1912 cmd
->state
.dirty
|= TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
;
1915 tu_cs_begin_sub_stream(&cmd
->sub_cs
, 24, &cs
);
1917 tu_cs_emit_pkt4(&cs
, sp_bindless_base_reg
, 10);
1918 tu_cs_emit_array(&cs
, (const uint32_t*) addr
, 10);
1919 tu_cs_emit_pkt4(&cs
, hlsq_bindless_base_reg
, 10);
1920 tu_cs_emit_array(&cs
, (const uint32_t*) addr
, 10);
1921 tu_cs_emit_regs(&cs
, A6XX_HLSQ_UPDATE_CNTL(.dword
= hlsq_update_value
));
1923 struct tu_cs_entry ib
= tu_cs_end_sub_stream(&cmd
->sub_cs
, &cs
);
1924 if (pipelineBindPoint
== VK_PIPELINE_BIND_POINT_GRAPHICS
) {
1925 tu_cs_emit_pkt7(&cmd
->draw_cs
, CP_SET_DRAW_STATE
, 3);
1926 tu_cs_emit_sds_ib(&cmd
->draw_cs
, TU_DRAW_STATE_DESC_SETS
, ib
);
1927 cmd
->state
.desc_sets_ib
= ib
;
1929 /* note: for compute we could emit directly, instead of a CP_INDIRECT
1930 * however, the blob uses draw states for compute
1932 tu_cs_emit_ib(&cmd
->cs
, &ib
);
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 struct tu_cs
*cs
= &cmd
->draw_cs
;
1946 /* using COND_REG_EXEC for xfb commands matches the blob behavior
1947 * presumably there isn't any benefit using a draw state when the
1948 * condition is (SYSMEM | BINNING)
1950 tu_cond_exec_start(cs
, CP_COND_REG_EXEC_0_MODE(RENDER_MODE
) |
1951 CP_COND_REG_EXEC_0_SYSMEM
|
1952 CP_COND_REG_EXEC_0_BINNING
);
1954 for (uint32_t i
= 0; i
< bindingCount
; i
++) {
1955 TU_FROM_HANDLE(tu_buffer
, buf
, pBuffers
[i
]);
1956 uint64_t iova
= buf
->bo
->iova
+ pOffsets
[i
];
1957 uint32_t size
= buf
->bo
->size
- pOffsets
[i
];
1958 uint32_t idx
= i
+ firstBinding
;
1960 if (pSizes
&& pSizes
[i
] != VK_WHOLE_SIZE
)
1963 /* BUFFER_BASE is 32-byte aligned, add remaining offset to BUFFER_OFFSET */
1964 uint32_t offset
= iova
& 0x1f;
1965 iova
&= ~(uint64_t) 0x1f;
1967 tu_cs_emit_pkt4(cs
, REG_A6XX_VPC_SO_BUFFER_BASE(idx
), 3);
1968 tu_cs_emit_qw(cs
, iova
);
1969 tu_cs_emit(cs
, size
+ offset
);
1971 cmd
->state
.streamout_offset
[idx
] = offset
;
1973 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_WRITE
);
1976 tu_cond_exec_end(cs
);
1980 tu_CmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer
,
1981 uint32_t firstCounterBuffer
,
1982 uint32_t counterBufferCount
,
1983 const VkBuffer
*pCounterBuffers
,
1984 const VkDeviceSize
*pCounterBufferOffsets
)
1986 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1987 struct tu_cs
*cs
= &cmd
->draw_cs
;
1989 tu_cond_exec_start(cs
, CP_COND_REG_EXEC_0_MODE(RENDER_MODE
) |
1990 CP_COND_REG_EXEC_0_SYSMEM
|
1991 CP_COND_REG_EXEC_0_BINNING
);
1993 /* TODO: only update offset for active buffers */
1994 for (uint32_t i
= 0; i
< IR3_MAX_SO_BUFFERS
; i
++)
1995 tu_cs_emit_regs(cs
, A6XX_VPC_SO_BUFFER_OFFSET(i
, cmd
->state
.streamout_offset
[i
]));
1997 for (uint32_t i
= 0; i
< counterBufferCount
; i
++) {
1998 uint32_t idx
= firstCounterBuffer
+ i
;
1999 uint32_t offset
= cmd
->state
.streamout_offset
[idx
];
2001 if (!pCounterBuffers
[i
])
2004 TU_FROM_HANDLE(tu_buffer
, buf
, pCounterBuffers
[i
]);
2006 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_READ
);
2008 tu_cs_emit_pkt7(cs
, CP_MEM_TO_REG
, 3);
2009 tu_cs_emit(cs
, CP_MEM_TO_REG_0_REG(REG_A6XX_VPC_SO_BUFFER_OFFSET(idx
)) |
2010 CP_MEM_TO_REG_0_UNK31
|
2011 CP_MEM_TO_REG_0_CNT(1));
2012 tu_cs_emit_qw(cs
, buf
->bo
->iova
+ pCounterBufferOffsets
[i
]);
2015 tu_cs_emit_pkt7(cs
, CP_REG_RMW
, 3);
2016 tu_cs_emit(cs
, CP_REG_RMW_0_DST_REG(REG_A6XX_VPC_SO_BUFFER_OFFSET(idx
)) |
2017 CP_REG_RMW_0_SRC1_ADD
);
2018 tu_cs_emit_qw(cs
, 0xffffffff);
2019 tu_cs_emit_qw(cs
, offset
);
2023 tu_cond_exec_end(cs
);
2026 void tu_CmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer
,
2027 uint32_t firstCounterBuffer
,
2028 uint32_t counterBufferCount
,
2029 const VkBuffer
*pCounterBuffers
,
2030 const VkDeviceSize
*pCounterBufferOffsets
)
2032 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2033 struct tu_cs
*cs
= &cmd
->draw_cs
;
2035 tu_cond_exec_start(cs
, CP_COND_REG_EXEC_0_MODE(RENDER_MODE
) |
2036 CP_COND_REG_EXEC_0_SYSMEM
|
2037 CP_COND_REG_EXEC_0_BINNING
);
2039 /* TODO: only flush buffers that need to be flushed */
2040 for (uint32_t i
= 0; i
< IR3_MAX_SO_BUFFERS
; i
++) {
2041 /* note: FLUSH_BASE is always the same, so it could go in init_hw()? */
2042 tu_cs_emit_pkt4(cs
, REG_A6XX_VPC_SO_FLUSH_BASE(i
), 2);
2043 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(flush_base
[i
]));
2044 tu6_emit_event_write(cmd
, cs
, FLUSH_SO_0
+ i
);
2047 for (uint32_t i
= 0; i
< counterBufferCount
; i
++) {
2048 uint32_t idx
= firstCounterBuffer
+ i
;
2049 uint32_t offset
= cmd
->state
.streamout_offset
[idx
];
2051 if (!pCounterBuffers
[i
])
2054 TU_FROM_HANDLE(tu_buffer
, buf
, pCounterBuffers
[i
]);
2056 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_WRITE
);
2058 /* VPC_SO_FLUSH_BASE has dwords counter, but counter should be in bytes */
2059 tu_cs_emit_pkt7(cs
, CP_MEM_TO_REG
, 3);
2060 tu_cs_emit(cs
, CP_MEM_TO_REG_0_REG(REG_A6XX_CP_SCRATCH_REG(0)) |
2061 CP_MEM_TO_REG_0_SHIFT_BY_2
|
2063 CP_MEM_TO_REG_0_UNK31
|
2064 CP_MEM_TO_REG_0_CNT(1));
2065 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(flush_base
[idx
]));
2068 tu_cs_emit_pkt7(cs
, CP_REG_RMW
, 3);
2069 tu_cs_emit(cs
, CP_REG_RMW_0_DST_REG(REG_A6XX_CP_SCRATCH_REG(0)) |
2070 CP_REG_RMW_0_SRC1_ADD
);
2071 tu_cs_emit_qw(cs
, 0xffffffff);
2072 tu_cs_emit_qw(cs
, -offset
);
2075 tu_cs_emit_pkt7(cs
, CP_REG_TO_MEM
, 3);
2076 tu_cs_emit(cs
, CP_REG_TO_MEM_0_REG(REG_A6XX_CP_SCRATCH_REG(0)) |
2077 CP_REG_TO_MEM_0_CNT(1));
2078 tu_cs_emit_qw(cs
, buf
->bo
->iova
+ pCounterBufferOffsets
[i
]);
2081 tu_cond_exec_end(cs
);
2083 cmd
->state
.xfb_used
= true;
2087 tu_CmdPushConstants(VkCommandBuffer commandBuffer
,
2088 VkPipelineLayout layout
,
2089 VkShaderStageFlags stageFlags
,
2092 const void *pValues
)
2094 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2095 memcpy((void*) cmd
->push_constants
+ offset
, pValues
, size
);
2096 cmd
->state
.dirty
|= TU_CMD_DIRTY_SHADER_CONSTS
;
2099 /* Flush everything which has been made available but we haven't actually
2103 tu_flush_all_pending(struct tu_cache_state
*cache
)
2105 cache
->flush_bits
|= cache
->pending_flush_bits
& TU_CMD_FLAG_ALL_FLUSH
;
2106 cache
->pending_flush_bits
&= ~TU_CMD_FLAG_ALL_FLUSH
;
2110 tu_EndCommandBuffer(VkCommandBuffer commandBuffer
)
2112 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
2114 /* We currently flush CCU at the end of the command buffer, like
2115 * what the blob does. There's implicit synchronization around every
2116 * vkQueueSubmit, but the kernel only flushes the UCHE, and we don't
2117 * know yet if this command buffer will be the last in the submit so we
2118 * have to defensively flush everything else.
2120 * TODO: We could definitely do better than this, since these flushes
2121 * aren't required by Vulkan, but we'd need kernel support to do that.
2122 * Ideally, we'd like the kernel to flush everything afterwards, so that we
2123 * wouldn't have to do any flushes here, and when submitting multiple
2124 * command buffers there wouldn't be any unnecessary flushes in between.
2126 if (cmd_buffer
->state
.pass
) {
2127 tu_flush_all_pending(&cmd_buffer
->state
.renderpass_cache
);
2128 tu_emit_cache_flush_renderpass(cmd_buffer
, &cmd_buffer
->draw_cs
);
2130 tu_flush_all_pending(&cmd_buffer
->state
.cache
);
2131 cmd_buffer
->state
.cache
.flush_bits
|=
2132 TU_CMD_FLAG_CCU_FLUSH_COLOR
|
2133 TU_CMD_FLAG_CCU_FLUSH_DEPTH
;
2134 tu_emit_cache_flush(cmd_buffer
, &cmd_buffer
->cs
);
2137 tu_bo_list_add(&cmd_buffer
->bo_list
, &cmd_buffer
->scratch_bo
,
2138 MSM_SUBMIT_BO_WRITE
);
2140 if (cmd_buffer
->use_vsc_data
) {
2141 tu_bo_list_add(&cmd_buffer
->bo_list
, &cmd_buffer
->vsc_draw_strm
,
2142 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
2143 tu_bo_list_add(&cmd_buffer
->bo_list
, &cmd_buffer
->vsc_prim_strm
,
2144 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
2147 tu_bo_list_add(&cmd_buffer
->bo_list
, &cmd_buffer
->device
->border_color
,
2148 MSM_SUBMIT_BO_READ
);
2150 for (uint32_t i
= 0; i
< cmd_buffer
->draw_cs
.bo_count
; i
++) {
2151 tu_bo_list_add(&cmd_buffer
->bo_list
, cmd_buffer
->draw_cs
.bos
[i
],
2152 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
2155 for (uint32_t i
= 0; i
< cmd_buffer
->draw_epilogue_cs
.bo_count
; i
++) {
2156 tu_bo_list_add(&cmd_buffer
->bo_list
, cmd_buffer
->draw_epilogue_cs
.bos
[i
],
2157 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
2160 for (uint32_t i
= 0; i
< cmd_buffer
->sub_cs
.bo_count
; i
++) {
2161 tu_bo_list_add(&cmd_buffer
->bo_list
, cmd_buffer
->sub_cs
.bos
[i
],
2162 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
2165 tu_cs_end(&cmd_buffer
->cs
);
2166 tu_cs_end(&cmd_buffer
->draw_cs
);
2167 tu_cs_end(&cmd_buffer
->draw_epilogue_cs
);
2169 cmd_buffer
->status
= TU_CMD_BUFFER_STATUS_EXECUTABLE
;
2171 return cmd_buffer
->record_result
;
2175 tu_cmd_dynamic_state(struct tu_cmd_buffer
*cmd
, uint32_t id
, uint32_t size
)
2177 struct tu_cs_memory memory
;
2180 /* TODO: share this logic with tu_pipeline_static_state */
2181 tu_cs_alloc(&cmd
->sub_cs
, size
, 1, &memory
);
2182 tu_cs_init_external(&cs
, memory
.map
, memory
.map
+ size
);
2184 tu_cs_reserve_space(&cs
, size
);
2186 assert(id
< ARRAY_SIZE(cmd
->state
.dynamic_state
));
2187 cmd
->state
.dynamic_state
[id
].iova
= memory
.iova
;
2188 cmd
->state
.dynamic_state
[id
].size
= size
;
2190 tu_cs_emit_pkt7(&cmd
->draw_cs
, CP_SET_DRAW_STATE
, 3);
2191 tu_cs_emit_draw_state(&cmd
->draw_cs
, TU_DRAW_STATE_DYNAMIC
+ id
, cmd
->state
.dynamic_state
[id
]);
2197 tu_CmdBindPipeline(VkCommandBuffer commandBuffer
,
2198 VkPipelineBindPoint pipelineBindPoint
,
2199 VkPipeline _pipeline
)
2201 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2202 TU_FROM_HANDLE(tu_pipeline
, pipeline
, _pipeline
);
2204 for (uint32_t i
= 0; i
< pipeline
->cs
.bo_count
; i
++) {
2205 tu_bo_list_add(&cmd
->bo_list
, pipeline
->cs
.bos
[i
],
2206 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
2209 if (pipelineBindPoint
== VK_PIPELINE_BIND_POINT_COMPUTE
) {
2210 cmd
->state
.compute_pipeline
= pipeline
;
2211 cmd
->state
.dirty
|= TU_CMD_DIRTY_COMPUTE_PIPELINE
;
2215 assert(pipelineBindPoint
== VK_PIPELINE_BIND_POINT_GRAPHICS
);
2217 cmd
->state
.pipeline
= pipeline
;
2218 cmd
->state
.dirty
|= TU_CMD_DIRTY_SHADER_CONSTS
;
2220 struct tu_cs
*cs
= &cmd
->draw_cs
;
2221 uint32_t mask
= ~pipeline
->dynamic_state_mask
& BITFIELD_MASK(TU_DYNAMIC_STATE_COUNT
);
2224 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 3 * (7 + util_bitcount(mask
)));
2225 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_PROGRAM
, pipeline
->program
.state_ib
);
2226 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_PROGRAM_BINNING
, pipeline
->program
.binning_state_ib
);
2227 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_VI
, pipeline
->vi
.state_ib
);
2228 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_VI_BINNING
, pipeline
->vi
.binning_state_ib
);
2229 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_RAST
, pipeline
->rast
.state_ib
);
2230 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_DS
, pipeline
->ds
.state_ib
);
2231 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_BLEND
, pipeline
->blend
.state_ib
);
2233 for_each_bit(i
, mask
)
2234 tu_cs_emit_draw_state(cs
, TU_DRAW_STATE_DYNAMIC
+ i
, pipeline
->dynamic_state
[i
]);
2236 /* If the new pipeline requires more VBs than we had previously set up, we
2237 * need to re-emit them in SDS. If it requires the same set or fewer, we
2238 * can just re-use the old SDS.
2240 if (pipeline
->vi
.bindings_used
& ~cmd
->vertex_bindings_set
)
2241 cmd
->state
.dirty
|= TU_CMD_DIRTY_VERTEX_BUFFERS
;
2243 /* If the pipeline needs a dynamic descriptor, re-emit descriptor sets */
2244 if (pipeline
->layout
->dynamic_offset_count
)
2245 cmd
->state
.dirty
|= TU_CMD_DIRTY_DESCRIPTOR_SETS
;
2247 /* dynamic linewidth state depends pipeline state's gras_su_cntl
2248 * so the dynamic state ib must be updated when pipeline changes
2250 if (pipeline
->dynamic_state_mask
& BIT(VK_DYNAMIC_STATE_LINE_WIDTH
)) {
2251 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_LINE_WIDTH
, 2);
2253 cmd
->state
.dynamic_gras_su_cntl
&= A6XX_GRAS_SU_CNTL_LINEHALFWIDTH__MASK
;
2254 cmd
->state
.dynamic_gras_su_cntl
|= pipeline
->gras_su_cntl
;
2256 tu_cs_emit_regs(&cs
, A6XX_GRAS_SU_CNTL(.dword
= cmd
->state
.dynamic_gras_su_cntl
));
2261 tu_CmdSetViewport(VkCommandBuffer commandBuffer
,
2262 uint32_t firstViewport
,
2263 uint32_t viewportCount
,
2264 const VkViewport
*pViewports
)
2266 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2267 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_VIEWPORT
, 18);
2269 assert(firstViewport
== 0 && viewportCount
== 1);
2271 tu6_emit_viewport(&cs
, pViewports
);
2275 tu_CmdSetScissor(VkCommandBuffer commandBuffer
,
2276 uint32_t firstScissor
,
2277 uint32_t scissorCount
,
2278 const VkRect2D
*pScissors
)
2280 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2281 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_SCISSOR
, 3);
2283 assert(firstScissor
== 0 && scissorCount
== 1);
2285 tu6_emit_scissor(&cs
, pScissors
);
2289 tu_CmdSetLineWidth(VkCommandBuffer commandBuffer
, float lineWidth
)
2291 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2292 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_LINE_WIDTH
, 2);
2294 cmd
->state
.dynamic_gras_su_cntl
&= ~A6XX_GRAS_SU_CNTL_LINEHALFWIDTH__MASK
;
2295 cmd
->state
.dynamic_gras_su_cntl
|= A6XX_GRAS_SU_CNTL_LINEHALFWIDTH(lineWidth
/ 2.0f
);
2297 tu_cs_emit_regs(&cs
, A6XX_GRAS_SU_CNTL(.dword
= cmd
->state
.dynamic_gras_su_cntl
));
2301 tu_CmdSetDepthBias(VkCommandBuffer commandBuffer
,
2302 float depthBiasConstantFactor
,
2303 float depthBiasClamp
,
2304 float depthBiasSlopeFactor
)
2306 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2307 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_DEPTH_BIAS
, 4);
2309 tu6_emit_depth_bias(&cs
, depthBiasConstantFactor
, depthBiasClamp
, depthBiasSlopeFactor
);
2313 tu_CmdSetBlendConstants(VkCommandBuffer commandBuffer
,
2314 const float blendConstants
[4])
2316 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2317 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_BLEND_CONSTANTS
, 5);
2319 tu_cs_emit_pkt4(&cs
, REG_A6XX_RB_BLEND_RED_F32
, 4);
2320 tu_cs_emit_array(&cs
, (const uint32_t *) blendConstants
, 4);
2324 tu_CmdSetDepthBounds(VkCommandBuffer commandBuffer
,
2325 float minDepthBounds
,
2326 float maxDepthBounds
)
2328 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2329 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_DEPTH_BOUNDS
, 3);
2331 tu_cs_emit_regs(&cs
,
2332 A6XX_RB_Z_BOUNDS_MIN(minDepthBounds
),
2333 A6XX_RB_Z_BOUNDS_MAX(maxDepthBounds
));
2337 update_stencil_mask(uint32_t *value
, VkStencilFaceFlags face
, uint32_t mask
)
2339 if (face
& VK_STENCIL_FACE_FRONT_BIT
)
2340 *value
= (*value
& 0xff00) | (mask
& 0xff);
2341 if (face
& VK_STENCIL_FACE_BACK_BIT
)
2342 *value
= (*value
& 0xff) | (mask
& 0xff) << 8;
2346 tu_CmdSetStencilCompareMask(VkCommandBuffer commandBuffer
,
2347 VkStencilFaceFlags faceMask
,
2348 uint32_t compareMask
)
2350 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2351 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
, 2);
2353 update_stencil_mask(&cmd
->state
.dynamic_stencil_mask
, faceMask
, compareMask
);
2355 tu_cs_emit_regs(&cs
, A6XX_RB_STENCILMASK(.dword
= cmd
->state
.dynamic_stencil_mask
));
2359 tu_CmdSetStencilWriteMask(VkCommandBuffer commandBuffer
,
2360 VkStencilFaceFlags faceMask
,
2363 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2364 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_STENCIL_WRITE_MASK
, 2);
2366 update_stencil_mask(&cmd
->state
.dynamic_stencil_wrmask
, faceMask
, writeMask
);
2368 tu_cs_emit_regs(&cs
, A6XX_RB_STENCILWRMASK(.dword
= cmd
->state
.dynamic_stencil_wrmask
));
2372 tu_CmdSetStencilReference(VkCommandBuffer commandBuffer
,
2373 VkStencilFaceFlags faceMask
,
2376 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2377 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_STENCIL_REFERENCE
, 2);
2379 update_stencil_mask(&cmd
->state
.dynamic_stencil_ref
, faceMask
, reference
);
2381 tu_cs_emit_regs(&cs
, A6XX_RB_STENCILREF(.dword
= cmd
->state
.dynamic_stencil_ref
));
2385 tu_CmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer
,
2386 const VkSampleLocationsInfoEXT
* pSampleLocationsInfo
)
2388 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2389 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, TU_DYNAMIC_STATE_SAMPLE_LOCATIONS
, 9);
2391 assert(pSampleLocationsInfo
);
2393 tu6_emit_sample_locations(&cs
, pSampleLocationsInfo
);
2397 tu_flush_for_access(struct tu_cache_state
*cache
,
2398 enum tu_cmd_access_mask src_mask
,
2399 enum tu_cmd_access_mask dst_mask
)
2401 enum tu_cmd_flush_bits flush_bits
= 0;
2403 if (src_mask
& TU_ACCESS_SYSMEM_WRITE
) {
2404 cache
->pending_flush_bits
|= TU_CMD_FLAG_ALL_INVALIDATE
;
2407 #define SRC_FLUSH(domain, flush, invalidate) \
2408 if (src_mask & TU_ACCESS_##domain##_WRITE) { \
2409 cache->pending_flush_bits |= TU_CMD_FLAG_##flush | \
2410 (TU_CMD_FLAG_ALL_INVALIDATE & ~TU_CMD_FLAG_##invalidate); \
2413 SRC_FLUSH(UCHE
, CACHE_FLUSH
, CACHE_INVALIDATE
)
2414 SRC_FLUSH(CCU_COLOR
, CCU_FLUSH_COLOR
, CCU_INVALIDATE_COLOR
)
2415 SRC_FLUSH(CCU_DEPTH
, CCU_FLUSH_DEPTH
, CCU_INVALIDATE_DEPTH
)
2419 #define SRC_INCOHERENT_FLUSH(domain, flush, invalidate) \
2420 if (src_mask & TU_ACCESS_##domain##_INCOHERENT_WRITE) { \
2421 flush_bits |= TU_CMD_FLAG_##flush; \
2422 cache->pending_flush_bits |= \
2423 (TU_CMD_FLAG_ALL_INVALIDATE & ~TU_CMD_FLAG_##invalidate); \
2426 SRC_INCOHERENT_FLUSH(CCU_COLOR
, CCU_FLUSH_COLOR
, CCU_INVALIDATE_COLOR
)
2427 SRC_INCOHERENT_FLUSH(CCU_DEPTH
, CCU_FLUSH_DEPTH
, CCU_INVALIDATE_DEPTH
)
2429 #undef SRC_INCOHERENT_FLUSH
2431 if (dst_mask
& (TU_ACCESS_SYSMEM_READ
| TU_ACCESS_SYSMEM_WRITE
)) {
2432 flush_bits
|= cache
->pending_flush_bits
& TU_CMD_FLAG_ALL_FLUSH
;
2435 #define DST_FLUSH(domain, flush, invalidate) \
2436 if (dst_mask & (TU_ACCESS_##domain##_READ | \
2437 TU_ACCESS_##domain##_WRITE)) { \
2438 flush_bits |= cache->pending_flush_bits & \
2439 (TU_CMD_FLAG_##invalidate | \
2440 (TU_CMD_FLAG_ALL_FLUSH & ~TU_CMD_FLAG_##flush)); \
2443 DST_FLUSH(UCHE
, CACHE_FLUSH
, CACHE_INVALIDATE
)
2444 DST_FLUSH(CCU_COLOR
, CCU_FLUSH_COLOR
, CCU_INVALIDATE_COLOR
)
2445 DST_FLUSH(CCU_DEPTH
, CCU_FLUSH_DEPTH
, CCU_INVALIDATE_DEPTH
)
2449 #define DST_INCOHERENT_FLUSH(domain, flush, invalidate) \
2450 if (dst_mask & (TU_ACCESS_##domain##_READ | \
2451 TU_ACCESS_##domain##_WRITE)) { \
2452 flush_bits |= TU_CMD_FLAG_##invalidate | \
2453 (cache->pending_flush_bits & \
2454 (TU_CMD_FLAG_ALL_FLUSH & ~TU_CMD_FLAG_##flush)); \
2457 DST_INCOHERENT_FLUSH(CCU_COLOR
, CCU_FLUSH_COLOR
, CCU_INVALIDATE_COLOR
)
2458 DST_INCOHERENT_FLUSH(CCU_DEPTH
, CCU_FLUSH_DEPTH
, CCU_INVALIDATE_DEPTH
)
2460 #undef DST_INCOHERENT_FLUSH
2462 if (dst_mask
& TU_ACCESS_WFI_READ
) {
2463 flush_bits
|= TU_CMD_FLAG_WFI
;
2466 cache
->flush_bits
|= flush_bits
;
2467 cache
->pending_flush_bits
&= ~flush_bits
;
2470 static enum tu_cmd_access_mask
2471 vk2tu_access(VkAccessFlags flags
, bool gmem
)
2473 enum tu_cmd_access_mask mask
= 0;
2475 /* If the GPU writes a buffer that is then read by an indirect draw
2476 * command, we theoretically need a WFI + WAIT_FOR_ME combination to
2477 * wait for the writes to complete. The WAIT_FOR_ME is performed as part
2478 * of the draw by the firmware, so we just need to execute a WFI.
2481 (VK_ACCESS_INDIRECT_COMMAND_READ_BIT
|
2482 VK_ACCESS_MEMORY_READ_BIT
)) {
2483 mask
|= TU_ACCESS_WFI_READ
;
2487 (VK_ACCESS_INDIRECT_COMMAND_READ_BIT
| /* Read performed by CP */
2488 VK_ACCESS_TRANSFORM_FEEDBACK_COUNTER_READ_BIT_EXT
| /* Read performed by CP, I think */
2489 VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT
| /* Read performed by CP */
2490 VK_ACCESS_HOST_READ_BIT
| /* sysmem by definition */
2491 VK_ACCESS_MEMORY_READ_BIT
)) {
2492 mask
|= TU_ACCESS_SYSMEM_READ
;
2496 (VK_ACCESS_HOST_WRITE_BIT
|
2497 VK_ACCESS_TRANSFORM_FEEDBACK_COUNTER_WRITE_BIT_EXT
| /* Write performed by CP, I think */
2498 VK_ACCESS_MEMORY_WRITE_BIT
)) {
2499 mask
|= TU_ACCESS_SYSMEM_WRITE
;
2503 (VK_ACCESS_INDEX_READ_BIT
| /* Read performed by PC, I think */
2504 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT
| /* Read performed by VFD */
2505 VK_ACCESS_UNIFORM_READ_BIT
| /* Read performed by SP */
2506 /* TODO: Is there a no-cache bit for textures so that we can ignore
2509 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT
| /* Read performed by TP */
2510 VK_ACCESS_SHADER_READ_BIT
| /* Read perfomed by SP/TP */
2511 VK_ACCESS_MEMORY_READ_BIT
)) {
2512 mask
|= TU_ACCESS_UCHE_READ
;
2516 (VK_ACCESS_SHADER_WRITE_BIT
| /* Write performed by SP */
2517 VK_ACCESS_TRANSFORM_FEEDBACK_WRITE_BIT_EXT
| /* Write performed by VPC */
2518 VK_ACCESS_MEMORY_WRITE_BIT
)) {
2519 mask
|= TU_ACCESS_UCHE_WRITE
;
2522 /* When using GMEM, the CCU is always flushed automatically to GMEM, and
2523 * then GMEM is flushed to sysmem. Furthermore, we already had to flush any
2524 * previous writes in sysmem mode when transitioning to GMEM. Therefore we
2525 * can ignore CCU and pretend that color attachments and transfers use
2530 (VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
|
2531 VK_ACCESS_COLOR_ATTACHMENT_READ_NONCOHERENT_BIT_EXT
|
2532 VK_ACCESS_MEMORY_READ_BIT
)) {
2534 mask
|= TU_ACCESS_SYSMEM_READ
;
2536 mask
|= TU_ACCESS_CCU_COLOR_INCOHERENT_READ
;
2540 (VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT
|
2541 VK_ACCESS_MEMORY_READ_BIT
)) {
2543 mask
|= TU_ACCESS_SYSMEM_READ
;
2545 mask
|= TU_ACCESS_CCU_DEPTH_INCOHERENT_READ
;
2549 (VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
|
2550 VK_ACCESS_MEMORY_WRITE_BIT
)) {
2552 mask
|= TU_ACCESS_SYSMEM_WRITE
;
2554 mask
|= TU_ACCESS_CCU_COLOR_INCOHERENT_WRITE
;
2559 (VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
|
2560 VK_ACCESS_MEMORY_WRITE_BIT
)) {
2562 mask
|= TU_ACCESS_SYSMEM_WRITE
;
2564 mask
|= TU_ACCESS_CCU_DEPTH_INCOHERENT_WRITE
;
2568 /* When the dst access is a transfer read/write, it seems we sometimes need
2569 * to insert a WFI after any flushes, to guarantee that the flushes finish
2570 * before the 2D engine starts. However the opposite (i.e. a WFI after
2571 * CP_BLIT and before any subsequent flush) does not seem to be needed, and
2572 * the blob doesn't emit such a WFI.
2576 (VK_ACCESS_TRANSFER_WRITE_BIT
|
2577 VK_ACCESS_MEMORY_WRITE_BIT
)) {
2579 mask
|= TU_ACCESS_SYSMEM_WRITE
;
2581 mask
|= TU_ACCESS_CCU_COLOR_WRITE
;
2583 mask
|= TU_ACCESS_WFI_READ
;
2587 (VK_ACCESS_TRANSFER_READ_BIT
| /* Access performed by TP */
2588 VK_ACCESS_MEMORY_READ_BIT
)) {
2589 mask
|= TU_ACCESS_UCHE_READ
| TU_ACCESS_WFI_READ
;
2597 tu_CmdExecuteCommands(VkCommandBuffer commandBuffer
,
2598 uint32_t commandBufferCount
,
2599 const VkCommandBuffer
*pCmdBuffers
)
2601 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2604 assert(commandBufferCount
> 0);
2606 /* Emit any pending flushes. */
2607 if (cmd
->state
.pass
) {
2608 tu_flush_all_pending(&cmd
->state
.renderpass_cache
);
2609 tu_emit_cache_flush_renderpass(cmd
, &cmd
->draw_cs
);
2611 tu_flush_all_pending(&cmd
->state
.cache
);
2612 tu_emit_cache_flush(cmd
, &cmd
->cs
);
2615 for (uint32_t i
= 0; i
< commandBufferCount
; i
++) {
2616 TU_FROM_HANDLE(tu_cmd_buffer
, secondary
, pCmdBuffers
[i
]);
2618 result
= tu_bo_list_merge(&cmd
->bo_list
, &secondary
->bo_list
);
2619 if (result
!= VK_SUCCESS
) {
2620 cmd
->record_result
= result
;
2624 if (secondary
->usage_flags
&
2625 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
) {
2626 assert(tu_cs_is_empty(&secondary
->cs
));
2628 result
= tu_cs_add_entries(&cmd
->draw_cs
, &secondary
->draw_cs
);
2629 if (result
!= VK_SUCCESS
) {
2630 cmd
->record_result
= result
;
2634 result
= tu_cs_add_entries(&cmd
->draw_epilogue_cs
,
2635 &secondary
->draw_epilogue_cs
);
2636 if (result
!= VK_SUCCESS
) {
2637 cmd
->record_result
= result
;
2641 if (secondary
->has_tess
)
2642 cmd
->has_tess
= true;
2644 assert(tu_cs_is_empty(&secondary
->draw_cs
));
2645 assert(tu_cs_is_empty(&secondary
->draw_epilogue_cs
));
2647 for (uint32_t j
= 0; j
< secondary
->cs
.bo_count
; j
++) {
2648 tu_bo_list_add(&cmd
->bo_list
, secondary
->cs
.bos
[j
],
2649 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
2652 tu_cs_add_entries(&cmd
->cs
, &secondary
->cs
);
2655 cmd
->state
.index_size
= secondary
->state
.index_size
; /* for restart index update */
2657 cmd
->state
.dirty
= ~0u; /* TODO: set dirty only what needs to be */
2659 /* After executing secondary command buffers, there may have been arbitrary
2660 * flushes executed, so when we encounter a pipeline barrier with a
2661 * srcMask, we have to assume that we need to invalidate. Therefore we need
2662 * to re-initialize the cache with all pending invalidate bits set.
2664 if (cmd
->state
.pass
) {
2665 tu_cache_init(&cmd
->state
.renderpass_cache
);
2667 tu_cache_init(&cmd
->state
.cache
);
2672 tu_CreateCommandPool(VkDevice _device
,
2673 const VkCommandPoolCreateInfo
*pCreateInfo
,
2674 const VkAllocationCallbacks
*pAllocator
,
2675 VkCommandPool
*pCmdPool
)
2677 TU_FROM_HANDLE(tu_device
, device
, _device
);
2678 struct tu_cmd_pool
*pool
;
2680 pool
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*pool
), 8,
2681 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2683 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2686 pool
->alloc
= *pAllocator
;
2688 pool
->alloc
= device
->alloc
;
2690 list_inithead(&pool
->cmd_buffers
);
2691 list_inithead(&pool
->free_cmd_buffers
);
2693 pool
->queue_family_index
= pCreateInfo
->queueFamilyIndex
;
2695 *pCmdPool
= tu_cmd_pool_to_handle(pool
);
2701 tu_DestroyCommandPool(VkDevice _device
,
2702 VkCommandPool commandPool
,
2703 const VkAllocationCallbacks
*pAllocator
)
2705 TU_FROM_HANDLE(tu_device
, device
, _device
);
2706 TU_FROM_HANDLE(tu_cmd_pool
, pool
, commandPool
);
2711 list_for_each_entry_safe(struct tu_cmd_buffer
, cmd_buffer
,
2712 &pool
->cmd_buffers
, pool_link
)
2714 tu_cmd_buffer_destroy(cmd_buffer
);
2717 list_for_each_entry_safe(struct tu_cmd_buffer
, cmd_buffer
,
2718 &pool
->free_cmd_buffers
, pool_link
)
2720 tu_cmd_buffer_destroy(cmd_buffer
);
2723 vk_free2(&device
->alloc
, pAllocator
, pool
);
2727 tu_ResetCommandPool(VkDevice device
,
2728 VkCommandPool commandPool
,
2729 VkCommandPoolResetFlags flags
)
2731 TU_FROM_HANDLE(tu_cmd_pool
, pool
, commandPool
);
2734 list_for_each_entry(struct tu_cmd_buffer
, cmd_buffer
, &pool
->cmd_buffers
,
2737 result
= tu_reset_cmd_buffer(cmd_buffer
);
2738 if (result
!= VK_SUCCESS
)
2746 tu_TrimCommandPool(VkDevice device
,
2747 VkCommandPool commandPool
,
2748 VkCommandPoolTrimFlags flags
)
2750 TU_FROM_HANDLE(tu_cmd_pool
, pool
, commandPool
);
2755 list_for_each_entry_safe(struct tu_cmd_buffer
, cmd_buffer
,
2756 &pool
->free_cmd_buffers
, pool_link
)
2758 tu_cmd_buffer_destroy(cmd_buffer
);
2763 tu_subpass_barrier(struct tu_cmd_buffer
*cmd_buffer
,
2764 const struct tu_subpass_barrier
*barrier
,
2767 /* Note: we don't know until the end of the subpass whether we'll use
2768 * sysmem, so assume sysmem here to be safe.
2770 struct tu_cache_state
*cache
=
2771 external
? &cmd_buffer
->state
.cache
: &cmd_buffer
->state
.renderpass_cache
;
2772 enum tu_cmd_access_mask src_flags
=
2773 vk2tu_access(barrier
->src_access_mask
, false);
2774 enum tu_cmd_access_mask dst_flags
=
2775 vk2tu_access(barrier
->dst_access_mask
, false);
2777 if (barrier
->incoherent_ccu_color
)
2778 src_flags
|= TU_ACCESS_CCU_COLOR_INCOHERENT_WRITE
;
2779 if (barrier
->incoherent_ccu_depth
)
2780 src_flags
|= TU_ACCESS_CCU_DEPTH_INCOHERENT_WRITE
;
2782 tu_flush_for_access(cache
, src_flags
, dst_flags
);
2786 tu_CmdBeginRenderPass(VkCommandBuffer commandBuffer
,
2787 const VkRenderPassBeginInfo
*pRenderPassBegin
,
2788 VkSubpassContents contents
)
2790 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2791 TU_FROM_HANDLE(tu_render_pass
, pass
, pRenderPassBegin
->renderPass
);
2792 TU_FROM_HANDLE(tu_framebuffer
, fb
, pRenderPassBegin
->framebuffer
);
2794 cmd
->state
.pass
= pass
;
2795 cmd
->state
.subpass
= pass
->subpasses
;
2796 cmd
->state
.framebuffer
= fb
;
2798 tu_cmd_update_tiling_config(cmd
, &pRenderPassBegin
->renderArea
);
2799 tu_cmd_prepare_tile_store_ib(cmd
);
2801 /* Note: because this is external, any flushes will happen before draw_cs
2802 * gets called. However deferred flushes could have to happen later as part
2805 tu_subpass_barrier(cmd
, &pass
->subpasses
[0].start_barrier
, true);
2806 cmd
->state
.renderpass_cache
.pending_flush_bits
=
2807 cmd
->state
.cache
.pending_flush_bits
;
2808 cmd
->state
.renderpass_cache
.flush_bits
= 0;
2810 tu_emit_renderpass_begin(cmd
, pRenderPassBegin
);
2812 tu6_emit_zs(cmd
, cmd
->state
.subpass
, &cmd
->draw_cs
);
2813 tu6_emit_mrt(cmd
, cmd
->state
.subpass
, &cmd
->draw_cs
);
2814 tu6_emit_msaa(&cmd
->draw_cs
, cmd
->state
.subpass
->samples
);
2815 tu6_emit_render_cntl(cmd
, cmd
->state
.subpass
, &cmd
->draw_cs
, false);
2817 tu_set_input_attachments(cmd
, cmd
->state
.subpass
);
2819 for (uint32_t i
= 0; i
< fb
->attachment_count
; ++i
) {
2820 const struct tu_image_view
*iview
= fb
->attachments
[i
].attachment
;
2821 tu_bo_list_add(&cmd
->bo_list
, iview
->image
->bo
,
2822 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
2825 cmd
->state
.dirty
|= TU_CMD_DIRTY_DRAW_STATE
;
2829 tu_CmdBeginRenderPass2(VkCommandBuffer commandBuffer
,
2830 const VkRenderPassBeginInfo
*pRenderPassBeginInfo
,
2831 const VkSubpassBeginInfoKHR
*pSubpassBeginInfo
)
2833 tu_CmdBeginRenderPass(commandBuffer
, pRenderPassBeginInfo
,
2834 pSubpassBeginInfo
->contents
);
2838 tu_CmdNextSubpass(VkCommandBuffer commandBuffer
, VkSubpassContents contents
)
2840 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2841 const struct tu_render_pass
*pass
= cmd
->state
.pass
;
2842 struct tu_cs
*cs
= &cmd
->draw_cs
;
2844 const struct tu_subpass
*subpass
= cmd
->state
.subpass
++;
2846 tu_cond_exec_start(cs
, CP_COND_EXEC_0_RENDER_MODE_GMEM
);
2848 if (subpass
->resolve_attachments
) {
2849 tu6_emit_blit_scissor(cmd
, cs
, true);
2851 for (unsigned i
= 0; i
< subpass
->color_count
; i
++) {
2852 uint32_t a
= subpass
->resolve_attachments
[i
].attachment
;
2853 if (a
== VK_ATTACHMENT_UNUSED
)
2856 tu_store_gmem_attachment(cmd
, cs
, a
,
2857 subpass
->color_attachments
[i
].attachment
);
2859 if (pass
->attachments
[a
].gmem_offset
< 0)
2863 * check if the resolved attachment is needed by later subpasses,
2864 * if it is, should be doing a GMEM->GMEM resolve instead of GMEM->MEM->GMEM..
2866 tu_finishme("missing GMEM->GMEM resolve path\n");
2867 tu_load_gmem_attachment(cmd
, cs
, a
, true);
2871 tu_cond_exec_end(cs
);
2873 tu_cond_exec_start(cs
, CP_COND_EXEC_0_RENDER_MODE_SYSMEM
);
2875 tu6_emit_sysmem_resolves(cmd
, cs
, subpass
);
2877 tu_cond_exec_end(cs
);
2879 /* Handle dependencies for the next subpass */
2880 tu_subpass_barrier(cmd
, &cmd
->state
.subpass
->start_barrier
, false);
2882 /* emit mrt/zs/msaa/ubwc state for the subpass that is starting */
2883 tu6_emit_zs(cmd
, cmd
->state
.subpass
, cs
);
2884 tu6_emit_mrt(cmd
, cmd
->state
.subpass
, cs
);
2885 tu6_emit_msaa(cs
, cmd
->state
.subpass
->samples
);
2886 tu6_emit_render_cntl(cmd
, cmd
->state
.subpass
, cs
, false);
2888 tu_set_input_attachments(cmd
, cmd
->state
.subpass
);
2892 tu_CmdNextSubpass2(VkCommandBuffer commandBuffer
,
2893 const VkSubpassBeginInfoKHR
*pSubpassBeginInfo
,
2894 const VkSubpassEndInfoKHR
*pSubpassEndInfo
)
2896 tu_CmdNextSubpass(commandBuffer
, pSubpassBeginInfo
->contents
);
2900 tu6_emit_user_consts(struct tu_cs
*cs
, const struct tu_pipeline
*pipeline
,
2901 struct tu_descriptor_state
*descriptors_state
,
2902 gl_shader_stage type
,
2903 uint32_t *push_constants
)
2905 const struct tu_program_descriptor_linkage
*link
=
2906 &pipeline
->program
.link
[type
];
2907 const struct ir3_ubo_analysis_state
*state
= &link
->const_state
.ubo_state
;
2909 if (link
->push_consts
.count
> 0) {
2910 unsigned num_units
= link
->push_consts
.count
;
2911 unsigned offset
= link
->push_consts
.lo
;
2912 tu_cs_emit_pkt7(cs
, tu6_stage2opcode(type
), 3 + num_units
* 4);
2913 tu_cs_emit(cs
, CP_LOAD_STATE6_0_DST_OFF(offset
) |
2914 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
2915 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
2916 CP_LOAD_STATE6_0_STATE_BLOCK(tu6_stage2shadersb(type
)) |
2917 CP_LOAD_STATE6_0_NUM_UNIT(num_units
));
2920 for (unsigned i
= 0; i
< num_units
* 4; i
++)
2921 tu_cs_emit(cs
, push_constants
[i
+ offset
* 4]);
2924 for (uint32_t i
= 0; i
< state
->num_enabled
; i
++) {
2925 uint32_t size
= state
->range
[i
].end
- state
->range
[i
].start
;
2926 uint32_t offset
= state
->range
[i
].start
;
2928 /* and even if the start of the const buffer is before
2929 * first_immediate, the end may not be:
2931 size
= MIN2(size
, (16 * link
->constlen
) - state
->range
[i
].offset
);
2936 /* things should be aligned to vec4: */
2937 debug_assert((state
->range
[i
].offset
% 16) == 0);
2938 debug_assert((size
% 16) == 0);
2939 debug_assert((offset
% 16) == 0);
2941 /* Dig out the descriptor from the descriptor state and read the VA from
2944 assert(state
->range
[i
].ubo
.bindless
);
2945 uint32_t *base
= state
->range
[i
].ubo
.bindless_base
== MAX_SETS
?
2946 descriptors_state
->dynamic_descriptors
:
2947 descriptors_state
->sets
[state
->range
[i
].ubo
.bindless_base
]->mapped_ptr
;
2948 unsigned block
= state
->range
[i
].ubo
.block
;
2949 uint32_t *desc
= base
+ block
* A6XX_TEX_CONST_DWORDS
;
2950 uint64_t va
= desc
[0] | ((uint64_t)(desc
[1] & A6XX_UBO_1_BASE_HI__MASK
) << 32);
2953 tu_cs_emit_pkt7(cs
, tu6_stage2opcode(type
), 3);
2954 tu_cs_emit(cs
, CP_LOAD_STATE6_0_DST_OFF(state
->range
[i
].offset
/ 16) |
2955 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
2956 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
2957 CP_LOAD_STATE6_0_STATE_BLOCK(tu6_stage2shadersb(type
)) |
2958 CP_LOAD_STATE6_0_NUM_UNIT(size
/ 16));
2959 tu_cs_emit_qw(cs
, va
+ offset
);
2963 static struct tu_cs_entry
2964 tu6_emit_consts(struct tu_cmd_buffer
*cmd
,
2965 const struct tu_pipeline
*pipeline
,
2966 struct tu_descriptor_state
*descriptors_state
,
2967 gl_shader_stage type
)
2970 tu_cs_begin_sub_stream(&cmd
->sub_cs
, 512, &cs
); /* TODO: maximum size? */
2972 tu6_emit_user_consts(&cs
, pipeline
, descriptors_state
, type
, cmd
->push_constants
);
2974 return tu_cs_end_sub_stream(&cmd
->sub_cs
, &cs
);
2977 static struct tu_cs_entry
2978 tu6_emit_vertex_buffers(struct tu_cmd_buffer
*cmd
,
2979 const struct tu_pipeline
*pipeline
)
2982 tu_cs_begin_sub_stream(&cmd
->sub_cs
, 4 * MAX_VBS
, &cs
);
2985 for_each_bit(binding
, pipeline
->vi
.bindings_used
) {
2986 const struct tu_buffer
*buf
= cmd
->state
.vb
.buffers
[binding
];
2987 const VkDeviceSize offset
= buf
->bo_offset
+
2988 cmd
->state
.vb
.offsets
[binding
];
2990 tu_cs_emit_regs(&cs
,
2991 A6XX_VFD_FETCH_BASE(binding
, .bo
= buf
->bo
, .bo_offset
= offset
),
2992 A6XX_VFD_FETCH_SIZE(binding
, buf
->size
- offset
));
2996 cmd
->vertex_bindings_set
= pipeline
->vi
.bindings_used
;
2998 return tu_cs_end_sub_stream(&cmd
->sub_cs
, &cs
);
3002 get_tess_param_bo_size(const struct tu_pipeline
*pipeline
,
3003 uint32_t draw_count
)
3005 /* TODO: For indirect draws, we can't compute the BO size ahead of time.
3006 * Still not sure what to do here, so just allocate a reasonably large
3007 * BO and hope for the best for now.
3008 * (maxTessellationControlPerVertexOutputComponents * 2048 vertices +
3009 * maxTessellationControlPerPatchOutputComponents * 512 patches) */
3011 return ((128 * 2048) + (128 * 512)) * 4;
3014 /* For each patch, adreno lays out the tess param BO in memory as:
3015 * (v_input[0][0])...(v_input[i][j])(p_input[0])...(p_input[k]).
3016 * where i = # vertices per patch, j = # per-vertex outputs, and
3017 * k = # per-patch outputs.*/
3018 uint32_t verts_per_patch
= pipeline
->ia
.primtype
- DI_PT_PATCHES0
;
3019 uint32_t num_patches
= draw_count
/ verts_per_patch
;
3020 return draw_count
* pipeline
->tess
.per_vertex_output_size
+
3021 pipeline
->tess
.per_patch_output_size
* num_patches
;
3025 get_tess_factor_bo_size(const struct tu_pipeline
*pipeline
,
3026 uint32_t draw_count
)
3028 /* TODO: For indirect draws, we can't compute the BO size ahead of time.
3029 * Still not sure what to do here, so just allocate a reasonably large
3030 * BO and hope for the best for now.
3031 * (quad factor stride * 512 patches) */
3033 return (28 * 512) * 4;
3036 /* Each distinct patch gets its own tess factor output. */
3037 uint32_t verts_per_patch
= pipeline
->ia
.primtype
- DI_PT_PATCHES0
;
3038 uint32_t num_patches
= draw_count
/ verts_per_patch
;
3039 uint32_t factor_stride
;
3040 switch (pipeline
->tess
.patch_type
) {
3041 case IR3_TESS_ISOLINES
:
3044 case IR3_TESS_TRIANGLES
:
3047 case IR3_TESS_QUADS
:
3051 unreachable("bad tessmode");
3053 return factor_stride
* num_patches
;
3057 tu6_emit_tess_consts(struct tu_cmd_buffer
*cmd
,
3058 uint32_t draw_count
,
3059 const struct tu_pipeline
*pipeline
,
3060 struct tu_cs_entry
*entry
)
3063 VkResult result
= tu_cs_begin_sub_stream(&cmd
->sub_cs
, 20, &cs
);
3064 if (result
!= VK_SUCCESS
)
3067 uint64_t tess_factor_size
= get_tess_factor_bo_size(pipeline
, draw_count
);
3068 uint64_t tess_param_size
= get_tess_param_bo_size(pipeline
, draw_count
);
3069 uint64_t tess_bo_size
= tess_factor_size
+ tess_param_size
;
3070 if (tess_bo_size
> 0) {
3071 struct tu_bo
*tess_bo
;
3072 result
= tu_get_scratch_bo(cmd
->device
, tess_bo_size
, &tess_bo
);
3073 if (result
!= VK_SUCCESS
)
3076 tu_bo_list_add(&cmd
->bo_list
, tess_bo
,
3077 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
3078 uint64_t tess_factor_iova
= tess_bo
->iova
;
3079 uint64_t tess_param_iova
= tess_factor_iova
+ tess_factor_size
;
3081 tu_cs_emit_pkt7(&cs
, CP_LOAD_STATE6_GEOM
, 3 + 4);
3082 tu_cs_emit(&cs
, CP_LOAD_STATE6_0_DST_OFF(pipeline
->tess
.hs_bo_regid
) |
3083 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
3084 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
3085 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_HS_SHADER
) |
3086 CP_LOAD_STATE6_0_NUM_UNIT(1));
3087 tu_cs_emit(&cs
, CP_LOAD_STATE6_1_EXT_SRC_ADDR(0));
3088 tu_cs_emit(&cs
, CP_LOAD_STATE6_2_EXT_SRC_ADDR_HI(0));
3089 tu_cs_emit_qw(&cs
, tess_param_iova
);
3090 tu_cs_emit_qw(&cs
, tess_factor_iova
);
3092 tu_cs_emit_pkt7(&cs
, CP_LOAD_STATE6_GEOM
, 3 + 4);
3093 tu_cs_emit(&cs
, CP_LOAD_STATE6_0_DST_OFF(pipeline
->tess
.ds_bo_regid
) |
3094 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
3095 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
3096 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_DS_SHADER
) |
3097 CP_LOAD_STATE6_0_NUM_UNIT(1));
3098 tu_cs_emit(&cs
, CP_LOAD_STATE6_1_EXT_SRC_ADDR(0));
3099 tu_cs_emit(&cs
, CP_LOAD_STATE6_2_EXT_SRC_ADDR_HI(0));
3100 tu_cs_emit_qw(&cs
, tess_param_iova
);
3101 tu_cs_emit_qw(&cs
, tess_factor_iova
);
3103 tu_cs_emit_pkt4(&cs
, REG_A6XX_PC_TESSFACTOR_ADDR_LO
, 2);
3104 tu_cs_emit_qw(&cs
, tess_factor_iova
);
3106 /* TODO: Without this WFI here, the hardware seems unable to read these
3107 * addresses we just emitted. Freedreno emits these consts as part of
3108 * IB1 instead of in a draw state which might make this WFI unnecessary,
3109 * but it requires a bit more indirection (SS6_INDIRECT for consts). */
3110 tu_cs_emit_wfi(&cs
);
3112 *entry
= tu_cs_end_sub_stream(&cmd
->sub_cs
, &cs
);
3117 tu6_draw_common(struct tu_cmd_buffer
*cmd
,
3120 /* note: draw_count is 0 for indirect */
3121 uint32_t draw_count
)
3123 const struct tu_pipeline
*pipeline
= cmd
->state
.pipeline
;
3126 struct tu_descriptor_state
*descriptors_state
=
3127 &cmd
->descriptors
[VK_PIPELINE_BIND_POINT_GRAPHICS
];
3129 tu_emit_cache_flush_renderpass(cmd
, cs
);
3133 tu_cs_emit_regs(cs
, A6XX_PC_PRIMITIVE_CNTL_0(
3134 .primitive_restart
=
3135 pipeline
->ia
.primitive_restart
&& indexed
,
3136 .tess_upper_left_domain_origin
=
3137 pipeline
->tess
.upper_left_domain_origin
));
3139 if (cmd
->state
.dirty
& TU_CMD_DIRTY_SHADER_CONSTS
) {
3140 cmd
->state
.shader_const_ib
[MESA_SHADER_VERTEX
] =
3141 tu6_emit_consts(cmd
, pipeline
, descriptors_state
, MESA_SHADER_VERTEX
);
3142 cmd
->state
.shader_const_ib
[MESA_SHADER_TESS_CTRL
] =
3143 tu6_emit_consts(cmd
, pipeline
, descriptors_state
, MESA_SHADER_TESS_CTRL
);
3144 cmd
->state
.shader_const_ib
[MESA_SHADER_TESS_EVAL
] =
3145 tu6_emit_consts(cmd
, pipeline
, descriptors_state
, MESA_SHADER_TESS_EVAL
);
3146 cmd
->state
.shader_const_ib
[MESA_SHADER_GEOMETRY
] =
3147 tu6_emit_consts(cmd
, pipeline
, descriptors_state
, MESA_SHADER_GEOMETRY
);
3148 cmd
->state
.shader_const_ib
[MESA_SHADER_FRAGMENT
] =
3149 tu6_emit_consts(cmd
, pipeline
, descriptors_state
, MESA_SHADER_FRAGMENT
);
3152 if (cmd
->state
.dirty
& TU_CMD_DIRTY_DESCRIPTOR_SETS
) {
3153 /* We need to reload the descriptors every time the descriptor sets
3154 * change. However, the commands we send only depend on the pipeline
3155 * because the whole point is to cache descriptors which are used by the
3156 * pipeline. There's a problem here, in that the firmware has an
3157 * "optimization" which skips executing groups that are set to the same
3158 * value as the last draw. This means that if the descriptor sets change
3159 * but not the pipeline, we'd try to re-execute the same buffer which
3160 * the firmware would ignore and we wouldn't pre-load the new
3161 * descriptors. The blob seems to re-emit the LOAD_STATE group whenever
3162 * the descriptor sets change, which we emulate here by copying the
3163 * pre-prepared buffer.
3165 const struct tu_cs_entry
*load_entry
= &pipeline
->load_state
.state_ib
;
3166 if (load_entry
->size
> 0) {
3167 struct tu_cs load_cs
;
3168 result
= tu_cs_begin_sub_stream(&cmd
->sub_cs
, load_entry
->size
, &load_cs
);
3169 if (result
!= VK_SUCCESS
)
3171 tu_cs_emit_array(&load_cs
,
3172 (uint32_t *)((char *)load_entry
->bo
->map
+ load_entry
->offset
),
3173 load_entry
->size
/ 4);
3174 cmd
->state
.desc_sets_load_ib
= tu_cs_end_sub_stream(&cmd
->sub_cs
, &load_cs
);
3176 cmd
->state
.desc_sets_load_ib
.size
= 0;
3180 if (cmd
->state
.dirty
& TU_CMD_DIRTY_VERTEX_BUFFERS
)
3181 cmd
->state
.vertex_buffers_ib
= tu6_emit_vertex_buffers(cmd
, pipeline
);
3184 pipeline
->active_stages
& VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT
;
3185 struct tu_cs_entry tess_consts
= {};
3187 cmd
->has_tess
= true;
3188 result
= tu6_emit_tess_consts(cmd
, draw_count
, pipeline
, &tess_consts
);
3189 if (result
!= VK_SUCCESS
)
3193 /* for the first draw in a renderpass, re-emit all the draw states
3195 * and if a draw-state disabling path (CmdClearAttachments 3D fallback) was
3196 * used, then draw states must be re-emitted. note however this only happens
3197 * in the sysmem path, so this can be skipped this for the gmem path (TODO)
3199 * the two input attachment states are excluded because secondary command
3200 * buffer doesn't have a state ib to restore it, and not re-emitting them
3201 * is OK since CmdClearAttachments won't disable/overwrite them
3203 if (cmd
->state
.dirty
& TU_CMD_DIRTY_DRAW_STATE
) {
3204 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 3 * (TU_DRAW_STATE_COUNT
- 2));
3206 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_PROGRAM
, pipeline
->program
.state_ib
);
3207 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_PROGRAM_BINNING
, pipeline
->program
.binning_state_ib
);
3208 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_TESS
, tess_consts
);
3209 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_VI
, pipeline
->vi
.state_ib
);
3210 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_VI_BINNING
, pipeline
->vi
.binning_state_ib
);
3211 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_RAST
, pipeline
->rast
.state_ib
);
3212 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_DS
, pipeline
->ds
.state_ib
);
3213 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_BLEND
, pipeline
->blend
.state_ib
);
3214 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_VS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_VERTEX
]);
3215 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_HS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_TESS_CTRL
]);
3216 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_DS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_TESS_EVAL
]);
3217 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_GS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_GEOMETRY
]);
3218 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_FS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_FRAGMENT
]);
3219 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_DESC_SETS
, cmd
->state
.desc_sets_ib
);
3220 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_DESC_SETS_LOAD
, cmd
->state
.desc_sets_load_ib
);
3221 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_VB
, cmd
->state
.vertex_buffers_ib
);
3222 tu_cs_emit_draw_state(cs
, TU_DRAW_STATE_VS_PARAMS
, cmd
->state
.vs_params
);
3224 for (uint32_t i
= 0; i
< ARRAY_SIZE(cmd
->state
.dynamic_state
); i
++) {
3225 tu_cs_emit_draw_state(cs
, TU_DRAW_STATE_DYNAMIC
+ i
,
3226 ((pipeline
->dynamic_state_mask
& BIT(i
)) ?
3227 cmd
->state
.dynamic_state
[i
] :
3228 pipeline
->dynamic_state
[i
]));
3232 /* emit draw states that were just updated
3233 * note we eventually don't want to have to emit anything here
3235 uint32_t draw_state_count
=
3237 ((cmd
->state
.dirty
& TU_CMD_DIRTY_SHADER_CONSTS
) ? 5 : 0) +
3238 ((cmd
->state
.dirty
& TU_CMD_DIRTY_DESCRIPTOR_SETS
) ? 1 : 0) +
3239 ((cmd
->state
.dirty
& TU_CMD_DIRTY_VERTEX_BUFFERS
) ? 1 : 0) +
3242 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 3 * draw_state_count
);
3244 /* We may need to re-emit tess consts if the current draw call is
3245 * sufficiently larger than the last draw call. */
3247 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_TESS
, tess_consts
);
3248 if (cmd
->state
.dirty
& TU_CMD_DIRTY_SHADER_CONSTS
) {
3249 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_VS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_VERTEX
]);
3250 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_HS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_TESS_CTRL
]);
3251 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_DS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_TESS_EVAL
]);
3252 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_GS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_GEOMETRY
]);
3253 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_FS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_FRAGMENT
]);
3255 if (cmd
->state
.dirty
& TU_CMD_DIRTY_DESCRIPTOR_SETS
)
3256 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_DESC_SETS_LOAD
, cmd
->state
.desc_sets_load_ib
);
3257 if (cmd
->state
.dirty
& TU_CMD_DIRTY_VERTEX_BUFFERS
)
3258 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_VB
, cmd
->state
.vertex_buffers_ib
);
3259 tu_cs_emit_draw_state(cs
, TU_DRAW_STATE_VS_PARAMS
, cmd
->state
.vs_params
);
3262 tu_cs_sanity_check(cs
);
3264 /* There are too many graphics dirty bits to list here, so just list the
3265 * bits to preserve instead. The only things not emitted here are
3266 * compute-related state.
3268 cmd
->state
.dirty
&= (TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
| TU_CMD_DIRTY_COMPUTE_PIPELINE
);
3273 tu_draw_initiator(struct tu_cmd_buffer
*cmd
, enum pc_di_src_sel src_sel
)
3275 const struct tu_pipeline
*pipeline
= cmd
->state
.pipeline
;
3276 uint32_t initiator
=
3277 CP_DRAW_INDX_OFFSET_0_PRIM_TYPE(pipeline
->ia
.primtype
) |
3278 CP_DRAW_INDX_OFFSET_0_SOURCE_SELECT(src_sel
) |
3279 CP_DRAW_INDX_OFFSET_0_INDEX_SIZE(cmd
->state
.index_size
) |
3280 CP_DRAW_INDX_OFFSET_0_VIS_CULL(USE_VISIBILITY
);
3282 if (pipeline
->active_stages
& VK_SHADER_STAGE_GEOMETRY_BIT
)
3283 initiator
|= CP_DRAW_INDX_OFFSET_0_GS_ENABLE
;
3285 switch (pipeline
->tess
.patch_type
) {
3286 case IR3_TESS_TRIANGLES
:
3287 initiator
|= CP_DRAW_INDX_OFFSET_0_PATCH_TYPE(TESS_TRIANGLES
) |
3288 CP_DRAW_INDX_OFFSET_0_TESS_ENABLE
;
3290 case IR3_TESS_ISOLINES
:
3291 initiator
|= CP_DRAW_INDX_OFFSET_0_PATCH_TYPE(TESS_ISOLINES
) |
3292 CP_DRAW_INDX_OFFSET_0_TESS_ENABLE
;
3295 initiator
|= CP_DRAW_INDX_OFFSET_0_PATCH_TYPE(TESS_QUADS
);
3297 case IR3_TESS_QUADS
:
3298 initiator
|= CP_DRAW_INDX_OFFSET_0_PATCH_TYPE(TESS_QUADS
) |
3299 CP_DRAW_INDX_OFFSET_0_TESS_ENABLE
;
3307 vs_params_offset(struct tu_cmd_buffer
*cmd
)
3309 const struct tu_program_descriptor_linkage
*link
=
3310 &cmd
->state
.pipeline
->program
.link
[MESA_SHADER_VERTEX
];
3311 const struct ir3_const_state
*const_state
= &link
->const_state
;
3313 if (const_state
->offsets
.driver_param
>= link
->constlen
)
3316 /* this layout is required by CP_DRAW_INDIRECT_MULTI */
3317 STATIC_ASSERT(IR3_DP_DRAWID
== 0);
3318 STATIC_ASSERT(IR3_DP_VTXID_BASE
== 1);
3319 STATIC_ASSERT(IR3_DP_INSTID_BASE
== 2);
3321 /* 0 means disabled for CP_DRAW_INDIRECT_MULTI */
3322 assert(const_state
->offsets
.driver_param
!= 0);
3324 return const_state
->offsets
.driver_param
;
3327 static struct tu_draw_state
3328 tu6_emit_vs_params(struct tu_cmd_buffer
*cmd
,
3329 uint32_t vertex_offset
,
3330 uint32_t first_instance
)
3332 uint32_t offset
= vs_params_offset(cmd
);
3335 VkResult result
= tu_cs_begin_sub_stream(&cmd
->sub_cs
, 3 + (offset
? 8 : 0), &cs
);
3336 if (result
!= VK_SUCCESS
) {
3337 cmd
->record_result
= result
;
3338 return (struct tu_draw_state
) {};
3341 /* TODO: don't make a new draw state when it doesn't change */
3343 tu_cs_emit_regs(&cs
,
3344 A6XX_VFD_INDEX_OFFSET(vertex_offset
),
3345 A6XX_VFD_INSTANCE_START_OFFSET(first_instance
));
3348 tu_cs_emit_pkt7(&cs
, CP_LOAD_STATE6_GEOM
, 3 + 4);
3349 tu_cs_emit(&cs
, CP_LOAD_STATE6_0_DST_OFF(offset
) |
3350 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
3351 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
3352 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_VS_SHADER
) |
3353 CP_LOAD_STATE6_0_NUM_UNIT(1));
3358 tu_cs_emit(&cs
, vertex_offset
);
3359 tu_cs_emit(&cs
, first_instance
);
3363 struct tu_cs_entry entry
= tu_cs_end_sub_stream(&cmd
->sub_cs
, &cs
);
3364 return (struct tu_draw_state
) {entry
.bo
->iova
+ entry
.offset
, entry
.size
/ 4};
3368 tu_CmdDraw(VkCommandBuffer commandBuffer
,
3369 uint32_t vertexCount
,
3370 uint32_t instanceCount
,
3371 uint32_t firstVertex
,
3372 uint32_t firstInstance
)
3374 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3375 struct tu_cs
*cs
= &cmd
->draw_cs
;
3377 cmd
->state
.vs_params
= tu6_emit_vs_params(cmd
, firstVertex
, firstInstance
);
3379 tu6_draw_common(cmd
, cs
, false, vertexCount
);
3381 tu_cs_emit_pkt7(cs
, CP_DRAW_INDX_OFFSET
, 3);
3382 tu_cs_emit(cs
, tu_draw_initiator(cmd
, DI_SRC_SEL_AUTO_INDEX
));
3383 tu_cs_emit(cs
, instanceCount
);
3384 tu_cs_emit(cs
, vertexCount
);
3388 tu_CmdDrawIndexed(VkCommandBuffer commandBuffer
,
3389 uint32_t indexCount
,
3390 uint32_t instanceCount
,
3391 uint32_t firstIndex
,
3392 int32_t vertexOffset
,
3393 uint32_t firstInstance
)
3395 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3396 struct tu_cs
*cs
= &cmd
->draw_cs
;
3398 cmd
->state
.vs_params
= tu6_emit_vs_params(cmd
, vertexOffset
, firstInstance
);
3400 tu6_draw_common(cmd
, cs
, true, indexCount
);
3402 tu_cs_emit_pkt7(cs
, CP_DRAW_INDX_OFFSET
, 7);
3403 tu_cs_emit(cs
, tu_draw_initiator(cmd
, DI_SRC_SEL_DMA
));
3404 tu_cs_emit(cs
, instanceCount
);
3405 tu_cs_emit(cs
, indexCount
);
3406 tu_cs_emit(cs
, 0x0); /* XXX */
3407 tu_cs_emit_qw(cs
, cmd
->state
.index_va
+ (firstIndex
<< cmd
->state
.index_shift
));
3408 tu_cs_emit(cs
, indexCount
<< cmd
->state
.index_shift
);
3412 tu_CmdDrawIndirect(VkCommandBuffer commandBuffer
,
3414 VkDeviceSize offset
,
3418 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3419 TU_FROM_HANDLE(tu_buffer
, buf
, _buffer
);
3420 struct tu_cs
*cs
= &cmd
->draw_cs
;
3422 cmd
->state
.vs_params
= (struct tu_draw_state
) {};
3424 tu6_draw_common(cmd
, cs
, false, 0);
3426 /* workaround for a firmware bug with CP_DRAW_INDIRECT_MULTI, where it
3427 * doesn't wait for WFIs to be completed and leads to GPU fault/hang
3428 * TODO: this could be worked around in a more performant way,
3429 * or there may exist newer firmware that has been fixed
3431 if (cmd
->device
->physical_device
->gpu_id
!= 650)
3432 tu_cs_emit_pkt7(cs
, CP_WAIT_FOR_ME
, 0);
3434 tu_cs_emit_pkt7(cs
, CP_DRAW_INDIRECT_MULTI
, 6);
3435 tu_cs_emit(cs
, tu_draw_initiator(cmd
, DI_SRC_SEL_AUTO_INDEX
));
3436 tu_cs_emit(cs
, A6XX_CP_DRAW_INDIRECT_MULTI_1_OPCODE(INDIRECT_OP_NORMAL
) |
3437 A6XX_CP_DRAW_INDIRECT_MULTI_1_DST_OFF(vs_params_offset(cmd
)));
3438 tu_cs_emit(cs
, drawCount
);
3439 tu_cs_emit_qw(cs
, buf
->bo
->iova
+ buf
->bo_offset
+ offset
);
3440 tu_cs_emit(cs
, stride
);
3442 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_READ
);
3446 tu_CmdDrawIndexedIndirect(VkCommandBuffer commandBuffer
,
3448 VkDeviceSize offset
,
3452 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3453 TU_FROM_HANDLE(tu_buffer
, buf
, _buffer
);
3454 struct tu_cs
*cs
= &cmd
->draw_cs
;
3456 cmd
->state
.vs_params
= (struct tu_draw_state
) {};
3458 tu6_draw_common(cmd
, cs
, true, 0);
3460 /* workaround for a firmware bug with CP_DRAW_INDIRECT_MULTI, where it
3461 * doesn't wait for WFIs to be completed and leads to GPU fault/hang
3462 * TODO: this could be worked around in a more performant way,
3463 * or there may exist newer firmware that has been fixed
3465 if (cmd
->device
->physical_device
->gpu_id
!= 650)
3466 tu_cs_emit_pkt7(cs
, CP_WAIT_FOR_ME
, 0);
3468 tu_cs_emit_pkt7(cs
, CP_DRAW_INDIRECT_MULTI
, 9);
3469 tu_cs_emit(cs
, tu_draw_initiator(cmd
, DI_SRC_SEL_DMA
));
3470 tu_cs_emit(cs
, A6XX_CP_DRAW_INDIRECT_MULTI_1_OPCODE(INDIRECT_OP_INDEXED
) |
3471 A6XX_CP_DRAW_INDIRECT_MULTI_1_DST_OFF(vs_params_offset(cmd
)));
3472 tu_cs_emit(cs
, drawCount
);
3473 tu_cs_emit_qw(cs
, cmd
->state
.index_va
);
3474 tu_cs_emit(cs
, cmd
->state
.max_index_count
);
3475 tu_cs_emit_qw(cs
, buf
->bo
->iova
+ buf
->bo_offset
+ offset
);
3476 tu_cs_emit(cs
, stride
);
3478 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_READ
);
3481 void tu_CmdDrawIndirectByteCountEXT(VkCommandBuffer commandBuffer
,
3482 uint32_t instanceCount
,
3483 uint32_t firstInstance
,
3484 VkBuffer _counterBuffer
,
3485 VkDeviceSize counterBufferOffset
,
3486 uint32_t counterOffset
,
3487 uint32_t vertexStride
)
3489 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3490 TU_FROM_HANDLE(tu_buffer
, buf
, _counterBuffer
);
3491 struct tu_cs
*cs
= &cmd
->draw_cs
;
3493 cmd
->state
.vs_params
= tu6_emit_vs_params(cmd
, 0, firstInstance
);
3495 tu6_draw_common(cmd
, cs
, false, 0);
3497 tu_cs_emit_pkt7(cs
, CP_DRAW_AUTO
, 6);
3498 tu_cs_emit(cs
, tu_draw_initiator(cmd
, DI_SRC_SEL_AUTO_XFB
));
3499 tu_cs_emit(cs
, instanceCount
);
3500 tu_cs_emit_qw(cs
, buf
->bo
->iova
+ buf
->bo_offset
+ counterBufferOffset
);
3501 tu_cs_emit(cs
, counterOffset
);
3502 tu_cs_emit(cs
, vertexStride
);
3504 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_READ
);
3507 struct tu_dispatch_info
3510 * Determine the layout of the grid (in block units) to be used.
3515 * A starting offset for the grid. If unaligned is set, the offset
3516 * must still be aligned.
3518 uint32_t offsets
[3];
3520 * Whether it's an unaligned compute dispatch.
3525 * Indirect compute parameters resource.
3527 struct tu_buffer
*indirect
;
3528 uint64_t indirect_offset
;
3532 tu_emit_compute_driver_params(struct tu_cs
*cs
, struct tu_pipeline
*pipeline
,
3533 const struct tu_dispatch_info
*info
)
3535 gl_shader_stage type
= MESA_SHADER_COMPUTE
;
3536 const struct tu_program_descriptor_linkage
*link
=
3537 &pipeline
->program
.link
[type
];
3538 const struct ir3_const_state
*const_state
= &link
->const_state
;
3539 uint32_t offset
= const_state
->offsets
.driver_param
;
3541 if (link
->constlen
<= offset
)
3544 if (!info
->indirect
) {
3545 uint32_t driver_params
[IR3_DP_CS_COUNT
] = {
3546 [IR3_DP_NUM_WORK_GROUPS_X
] = info
->blocks
[0],
3547 [IR3_DP_NUM_WORK_GROUPS_Y
] = info
->blocks
[1],
3548 [IR3_DP_NUM_WORK_GROUPS_Z
] = info
->blocks
[2],
3549 [IR3_DP_LOCAL_GROUP_SIZE_X
] = pipeline
->compute
.local_size
[0],
3550 [IR3_DP_LOCAL_GROUP_SIZE_Y
] = pipeline
->compute
.local_size
[1],
3551 [IR3_DP_LOCAL_GROUP_SIZE_Z
] = pipeline
->compute
.local_size
[2],
3554 uint32_t num_consts
= MIN2(const_state
->num_driver_params
,
3555 (link
->constlen
- offset
) * 4);
3556 /* push constants */
3557 tu_cs_emit_pkt7(cs
, tu6_stage2opcode(type
), 3 + num_consts
);
3558 tu_cs_emit(cs
, CP_LOAD_STATE6_0_DST_OFF(offset
) |
3559 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
3560 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
3561 CP_LOAD_STATE6_0_STATE_BLOCK(tu6_stage2shadersb(type
)) |
3562 CP_LOAD_STATE6_0_NUM_UNIT(num_consts
/ 4));
3566 for (i
= 0; i
< num_consts
; i
++)
3567 tu_cs_emit(cs
, driver_params
[i
]);
3569 tu_finishme("Indirect driver params");
3574 tu_dispatch(struct tu_cmd_buffer
*cmd
,
3575 const struct tu_dispatch_info
*info
)
3577 struct tu_cs
*cs
= &cmd
->cs
;
3578 struct tu_pipeline
*pipeline
= cmd
->state
.compute_pipeline
;
3579 struct tu_descriptor_state
*descriptors_state
=
3580 &cmd
->descriptors
[VK_PIPELINE_BIND_POINT_COMPUTE
];
3582 /* TODO: We could probably flush less if we add a compute_flush_bits
3585 tu_emit_cache_flush(cmd
, cs
);
3587 if (cmd
->state
.dirty
& TU_CMD_DIRTY_COMPUTE_PIPELINE
)
3588 tu_cs_emit_ib(cs
, &pipeline
->program
.state_ib
);
3590 struct tu_cs_entry ib
;
3592 ib
= tu6_emit_consts(cmd
, pipeline
, descriptors_state
, MESA_SHADER_COMPUTE
);
3594 tu_cs_emit_ib(cs
, &ib
);
3596 tu_emit_compute_driver_params(cs
, pipeline
, info
);
3598 if ((cmd
->state
.dirty
& TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
) &&
3599 pipeline
->load_state
.state_ib
.size
> 0) {
3600 tu_cs_emit_ib(cs
, &pipeline
->load_state
.state_ib
);
3604 ~(TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
| TU_CMD_DIRTY_COMPUTE_PIPELINE
);
3606 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
3607 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_COMPUTE
));
3609 const uint32_t *local_size
= pipeline
->compute
.local_size
;
3610 const uint32_t *num_groups
= info
->blocks
;
3612 A6XX_HLSQ_CS_NDRANGE_0(.kerneldim
= 3,
3613 .localsizex
= local_size
[0] - 1,
3614 .localsizey
= local_size
[1] - 1,
3615 .localsizez
= local_size
[2] - 1),
3616 A6XX_HLSQ_CS_NDRANGE_1(.globalsize_x
= local_size
[0] * num_groups
[0]),
3617 A6XX_HLSQ_CS_NDRANGE_2(.globaloff_x
= 0),
3618 A6XX_HLSQ_CS_NDRANGE_3(.globalsize_y
= local_size
[1] * num_groups
[1]),
3619 A6XX_HLSQ_CS_NDRANGE_4(.globaloff_y
= 0),
3620 A6XX_HLSQ_CS_NDRANGE_5(.globalsize_z
= local_size
[2] * num_groups
[2]),
3621 A6XX_HLSQ_CS_NDRANGE_6(.globaloff_z
= 0));
3624 A6XX_HLSQ_CS_KERNEL_GROUP_X(1),
3625 A6XX_HLSQ_CS_KERNEL_GROUP_Y(1),
3626 A6XX_HLSQ_CS_KERNEL_GROUP_Z(1));
3628 if (info
->indirect
) {
3629 uint64_t iova
= tu_buffer_iova(info
->indirect
) + info
->indirect_offset
;
3631 tu_bo_list_add(&cmd
->bo_list
, info
->indirect
->bo
,
3632 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
3634 tu_cs_emit_pkt7(cs
, CP_EXEC_CS_INDIRECT
, 4);
3635 tu_cs_emit(cs
, 0x00000000);
3636 tu_cs_emit_qw(cs
, iova
);
3638 A5XX_CP_EXEC_CS_INDIRECT_3_LOCALSIZEX(local_size
[0] - 1) |
3639 A5XX_CP_EXEC_CS_INDIRECT_3_LOCALSIZEY(local_size
[1] - 1) |
3640 A5XX_CP_EXEC_CS_INDIRECT_3_LOCALSIZEZ(local_size
[2] - 1));
3642 tu_cs_emit_pkt7(cs
, CP_EXEC_CS
, 4);
3643 tu_cs_emit(cs
, 0x00000000);
3644 tu_cs_emit(cs
, CP_EXEC_CS_1_NGROUPS_X(info
->blocks
[0]));
3645 tu_cs_emit(cs
, CP_EXEC_CS_2_NGROUPS_Y(info
->blocks
[1]));
3646 tu_cs_emit(cs
, CP_EXEC_CS_3_NGROUPS_Z(info
->blocks
[2]));
3653 tu_CmdDispatchBase(VkCommandBuffer commandBuffer
,
3661 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3662 struct tu_dispatch_info info
= {};
3668 info
.offsets
[0] = base_x
;
3669 info
.offsets
[1] = base_y
;
3670 info
.offsets
[2] = base_z
;
3671 tu_dispatch(cmd_buffer
, &info
);
3675 tu_CmdDispatch(VkCommandBuffer commandBuffer
,
3680 tu_CmdDispatchBase(commandBuffer
, 0, 0, 0, x
, y
, z
);
3684 tu_CmdDispatchIndirect(VkCommandBuffer commandBuffer
,
3686 VkDeviceSize offset
)
3688 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3689 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
3690 struct tu_dispatch_info info
= {};
3692 info
.indirect
= buffer
;
3693 info
.indirect_offset
= offset
;
3695 tu_dispatch(cmd_buffer
, &info
);
3699 tu_CmdEndRenderPass(VkCommandBuffer commandBuffer
)
3701 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3703 tu_cs_end(&cmd_buffer
->draw_cs
);
3704 tu_cs_end(&cmd_buffer
->draw_epilogue_cs
);
3706 if (use_sysmem_rendering(cmd_buffer
))
3707 tu_cmd_render_sysmem(cmd_buffer
);
3709 tu_cmd_render_tiles(cmd_buffer
);
3711 /* discard draw_cs and draw_epilogue_cs entries now that the tiles are
3713 tu_cs_discard_entries(&cmd_buffer
->draw_cs
);
3714 tu_cs_begin(&cmd_buffer
->draw_cs
);
3715 tu_cs_discard_entries(&cmd_buffer
->draw_epilogue_cs
);
3716 tu_cs_begin(&cmd_buffer
->draw_epilogue_cs
);
3718 cmd_buffer
->state
.cache
.pending_flush_bits
|=
3719 cmd_buffer
->state
.renderpass_cache
.pending_flush_bits
;
3720 tu_subpass_barrier(cmd_buffer
, &cmd_buffer
->state
.pass
->end_barrier
, true);
3722 cmd_buffer
->state
.pass
= NULL
;
3723 cmd_buffer
->state
.subpass
= NULL
;
3724 cmd_buffer
->state
.framebuffer
= NULL
;
3728 tu_CmdEndRenderPass2(VkCommandBuffer commandBuffer
,
3729 const VkSubpassEndInfoKHR
*pSubpassEndInfo
)
3731 tu_CmdEndRenderPass(commandBuffer
);
3734 struct tu_barrier_info
3736 uint32_t eventCount
;
3737 const VkEvent
*pEvents
;
3738 VkPipelineStageFlags srcStageMask
;
3742 tu_barrier(struct tu_cmd_buffer
*cmd
,
3743 uint32_t memoryBarrierCount
,
3744 const VkMemoryBarrier
*pMemoryBarriers
,
3745 uint32_t bufferMemoryBarrierCount
,
3746 const VkBufferMemoryBarrier
*pBufferMemoryBarriers
,
3747 uint32_t imageMemoryBarrierCount
,
3748 const VkImageMemoryBarrier
*pImageMemoryBarriers
,
3749 const struct tu_barrier_info
*info
)
3751 struct tu_cs
*cs
= cmd
->state
.pass
? &cmd
->draw_cs
: &cmd
->cs
;
3752 VkAccessFlags srcAccessMask
= 0;
3753 VkAccessFlags dstAccessMask
= 0;
3755 for (uint32_t i
= 0; i
< memoryBarrierCount
; i
++) {
3756 srcAccessMask
|= pMemoryBarriers
[i
].srcAccessMask
;
3757 dstAccessMask
|= pMemoryBarriers
[i
].dstAccessMask
;
3760 for (uint32_t i
= 0; i
< bufferMemoryBarrierCount
; i
++) {
3761 srcAccessMask
|= pBufferMemoryBarriers
[i
].srcAccessMask
;
3762 dstAccessMask
|= pBufferMemoryBarriers
[i
].dstAccessMask
;
3765 enum tu_cmd_access_mask src_flags
= 0;
3766 enum tu_cmd_access_mask dst_flags
= 0;
3768 for (uint32_t i
= 0; i
< imageMemoryBarrierCount
; i
++) {
3769 TU_FROM_HANDLE(tu_image
, image
, pImageMemoryBarriers
[i
].image
);
3770 VkImageLayout old_layout
= pImageMemoryBarriers
[i
].oldLayout
;
3771 /* For non-linear images, PREINITIALIZED is the same as UNDEFINED */
3772 if (old_layout
== VK_IMAGE_LAYOUT_UNDEFINED
||
3773 (image
->tiling
!= VK_IMAGE_TILING_LINEAR
&&
3774 old_layout
== VK_IMAGE_LAYOUT_PREINITIALIZED
)) {
3775 /* The underlying memory for this image may have been used earlier
3776 * within the same queue submission for a different image, which
3777 * means that there may be old, stale cache entries which are in the
3778 * "wrong" location, which could cause problems later after writing
3779 * to the image. We don't want these entries being flushed later and
3780 * overwriting the actual image, so we need to flush the CCU.
3782 src_flags
|= TU_ACCESS_CCU_COLOR_INCOHERENT_WRITE
;
3784 srcAccessMask
|= pImageMemoryBarriers
[i
].srcAccessMask
;
3785 dstAccessMask
|= pImageMemoryBarriers
[i
].dstAccessMask
;
3788 /* Inside a renderpass, we don't know yet whether we'll be using sysmem
3789 * so we have to use the sysmem flushes.
3791 bool gmem
= cmd
->state
.ccu_state
== TU_CMD_CCU_GMEM
&&
3793 src_flags
|= vk2tu_access(srcAccessMask
, gmem
);
3794 dst_flags
|= vk2tu_access(dstAccessMask
, gmem
);
3796 struct tu_cache_state
*cache
=
3797 cmd
->state
.pass
? &cmd
->state
.renderpass_cache
: &cmd
->state
.cache
;
3798 tu_flush_for_access(cache
, src_flags
, dst_flags
);
3800 for (uint32_t i
= 0; i
< info
->eventCount
; i
++) {
3801 TU_FROM_HANDLE(tu_event
, event
, info
->pEvents
[i
]);
3803 tu_bo_list_add(&cmd
->bo_list
, &event
->bo
, MSM_SUBMIT_BO_READ
);
3805 tu_cs_emit_pkt7(cs
, CP_WAIT_REG_MEM
, 6);
3806 tu_cs_emit(cs
, CP_WAIT_REG_MEM_0_FUNCTION(WRITE_EQ
) |
3807 CP_WAIT_REG_MEM_0_POLL_MEMORY
);
3808 tu_cs_emit_qw(cs
, event
->bo
.iova
); /* POLL_ADDR_LO/HI */
3809 tu_cs_emit(cs
, CP_WAIT_REG_MEM_3_REF(1));
3810 tu_cs_emit(cs
, CP_WAIT_REG_MEM_4_MASK(~0u));
3811 tu_cs_emit(cs
, CP_WAIT_REG_MEM_5_DELAY_LOOP_CYCLES(20));
3816 tu_CmdPipelineBarrier(VkCommandBuffer commandBuffer
,
3817 VkPipelineStageFlags srcStageMask
,
3818 VkPipelineStageFlags dstStageMask
,
3819 VkDependencyFlags dependencyFlags
,
3820 uint32_t memoryBarrierCount
,
3821 const VkMemoryBarrier
*pMemoryBarriers
,
3822 uint32_t bufferMemoryBarrierCount
,
3823 const VkBufferMemoryBarrier
*pBufferMemoryBarriers
,
3824 uint32_t imageMemoryBarrierCount
,
3825 const VkImageMemoryBarrier
*pImageMemoryBarriers
)
3827 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3828 struct tu_barrier_info info
;
3830 info
.eventCount
= 0;
3831 info
.pEvents
= NULL
;
3832 info
.srcStageMask
= srcStageMask
;
3834 tu_barrier(cmd_buffer
, memoryBarrierCount
, pMemoryBarriers
,
3835 bufferMemoryBarrierCount
, pBufferMemoryBarriers
,
3836 imageMemoryBarrierCount
, pImageMemoryBarriers
, &info
);
3840 write_event(struct tu_cmd_buffer
*cmd
, struct tu_event
*event
,
3841 VkPipelineStageFlags stageMask
, unsigned value
)
3843 struct tu_cs
*cs
= &cmd
->cs
;
3845 /* vkCmdSetEvent/vkCmdResetEvent cannot be called inside a render pass */
3846 assert(!cmd
->state
.pass
);
3848 tu_emit_cache_flush(cmd
, cs
);
3850 tu_bo_list_add(&cmd
->bo_list
, &event
->bo
, MSM_SUBMIT_BO_WRITE
);
3852 /* Flags that only require a top-of-pipe event. DrawIndirect parameters are
3853 * read by the CP, so the draw indirect stage counts as top-of-pipe too.
3855 VkPipelineStageFlags top_of_pipe_flags
=
3856 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT
|
3857 VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT
;
3859 if (!(stageMask
& ~top_of_pipe_flags
)) {
3860 tu_cs_emit_pkt7(cs
, CP_MEM_WRITE
, 3);
3861 tu_cs_emit_qw(cs
, event
->bo
.iova
); /* ADDR_LO/HI */
3862 tu_cs_emit(cs
, value
);
3864 /* Use a RB_DONE_TS event to wait for everything to complete. */
3865 tu_cs_emit_pkt7(cs
, CP_EVENT_WRITE
, 4);
3866 tu_cs_emit(cs
, CP_EVENT_WRITE_0_EVENT(RB_DONE_TS
));
3867 tu_cs_emit_qw(cs
, event
->bo
.iova
);
3868 tu_cs_emit(cs
, value
);
3873 tu_CmdSetEvent(VkCommandBuffer commandBuffer
,
3875 VkPipelineStageFlags stageMask
)
3877 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3878 TU_FROM_HANDLE(tu_event
, event
, _event
);
3880 write_event(cmd
, event
, stageMask
, 1);
3884 tu_CmdResetEvent(VkCommandBuffer commandBuffer
,
3886 VkPipelineStageFlags stageMask
)
3888 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3889 TU_FROM_HANDLE(tu_event
, event
, _event
);
3891 write_event(cmd
, event
, stageMask
, 0);
3895 tu_CmdWaitEvents(VkCommandBuffer commandBuffer
,
3896 uint32_t eventCount
,
3897 const VkEvent
*pEvents
,
3898 VkPipelineStageFlags srcStageMask
,
3899 VkPipelineStageFlags dstStageMask
,
3900 uint32_t memoryBarrierCount
,
3901 const VkMemoryBarrier
*pMemoryBarriers
,
3902 uint32_t bufferMemoryBarrierCount
,
3903 const VkBufferMemoryBarrier
*pBufferMemoryBarriers
,
3904 uint32_t imageMemoryBarrierCount
,
3905 const VkImageMemoryBarrier
*pImageMemoryBarriers
)
3907 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3908 struct tu_barrier_info info
;
3910 info
.eventCount
= eventCount
;
3911 info
.pEvents
= pEvents
;
3912 info
.srcStageMask
= 0;
3914 tu_barrier(cmd
, memoryBarrierCount
, pMemoryBarriers
,
3915 bufferMemoryBarrierCount
, pBufferMemoryBarriers
,
3916 imageMemoryBarrierCount
, pImageMemoryBarriers
, &info
);
3920 tu_CmdSetDeviceMask(VkCommandBuffer commandBuffer
, uint32_t deviceMask
)