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 tu_cs_emit_write_reg(cs
, REG_A6XX_VFD_ADD_OFFSET
, A6XX_VFD_ADD_OFFSET_VERTEX
);
923 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8811
, 0x00000010);
924 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_MODE_CNTL
, 0x1f);
926 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_SRGB_CNTL
, 0);
928 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_8110
, 0);
930 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_RENDER_CONTROL0
, 0x401);
931 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_RENDER_CONTROL1
, 0);
932 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_FS_OUTPUT_CNTL0
, 0);
933 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8818
, 0);
934 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_8819
, 0);
935 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881A
, 0);
936 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881B
, 0);
937 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881C
, 0);
938 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881D
, 0);
939 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_881E
, 0);
940 tu_cs_emit_write_reg(cs
, REG_A6XX_RB_UNKNOWN_88F0
, 0);
942 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9101
, 0xffff00);
943 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9107
, 0);
945 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9236
,
946 A6XX_VPC_UNKNOWN_9236_POINT_COORD_INVERT(0));
947 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9300
, 0);
949 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_SO_OVERRIDE
,
950 A6XX_VPC_SO_OVERRIDE_SO_DISABLE
);
952 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9801
, 0);
953 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9980
, 0);
954 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9990
, 0);
956 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_PRIMITIVE_CNTL_6
, 0);
957 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9B07
, 0);
959 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_A81B
, 0);
961 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_UNKNOWN_B183
, 0);
963 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_8099
, 0);
964 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_809B
, 0);
965 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_80A0
, 2);
966 tu_cs_emit_write_reg(cs
, REG_A6XX_GRAS_UNKNOWN_80AF
, 0);
967 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9210
, 0);
968 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9211
, 0);
969 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9602
, 0);
970 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9981
, 0x3);
971 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_UNKNOWN_9E72
, 0);
972 tu_cs_emit_write_reg(cs
, REG_A6XX_VPC_UNKNOWN_9108
, 0x3);
973 tu_cs_emit_write_reg(cs
, REG_A6XX_SP_TP_UNKNOWN_B309
, 0x000000a2);
974 tu_cs_emit_write_reg(cs
, REG_A6XX_HLSQ_CONTROL_5_REG
, 0xfc);
976 tu_cs_emit_write_reg(cs
, REG_A6XX_VFD_MODE_CNTL
, 0x00000000);
978 tu_cs_emit_write_reg(cs
, REG_A6XX_VFD_UNKNOWN_A008
, 0);
980 tu_cs_emit_write_reg(cs
, REG_A6XX_PC_MODE_CNTL
, 0x0000001f);
982 /* we don't use this yet.. probably best to disable.. */
983 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 3);
984 tu_cs_emit(cs
, CP_SET_DRAW_STATE__0_COUNT(0) |
985 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
986 CP_SET_DRAW_STATE__0_GROUP_ID(0));
987 tu_cs_emit(cs
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
988 tu_cs_emit(cs
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
991 A6XX_SP_HS_CTRL_REG0(0));
994 A6XX_SP_GS_CTRL_REG0(0));
997 A6XX_GRAS_LRZ_CNTL(0));
1000 A6XX_RB_LRZ_CNTL(0));
1003 A6XX_SP_TP_BORDER_COLOR_BASE_ADDR(.bo
= &cmd
->device
->border_color
));
1005 A6XX_SP_PS_TP_BORDER_COLOR_BASE_ADDR(.bo
= &cmd
->device
->border_color
));
1007 tu_cs_sanity_check(cs
);
1011 update_vsc_pipe(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1013 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1016 A6XX_VSC_BIN_SIZE(.width
= tiling
->tile0
.extent
.width
,
1017 .height
= tiling
->tile0
.extent
.height
),
1018 A6XX_VSC_DRAW_STRM_SIZE_ADDRESS(.bo
= &cmd
->vsc_draw_strm
,
1019 .bo_offset
= 32 * cmd
->vsc_draw_strm_pitch
));
1022 A6XX_VSC_BIN_COUNT(.nx
= tiling
->tile_count
.width
,
1023 .ny
= tiling
->tile_count
.height
));
1025 tu_cs_emit_pkt4(cs
, REG_A6XX_VSC_PIPE_CONFIG_REG(0), 32);
1026 for (unsigned i
= 0; i
< 32; i
++)
1027 tu_cs_emit(cs
, tiling
->pipe_config
[i
]);
1030 A6XX_VSC_PRIM_STRM_ADDRESS(.bo
= &cmd
->vsc_prim_strm
),
1031 A6XX_VSC_PRIM_STRM_PITCH(cmd
->vsc_prim_strm_pitch
),
1032 A6XX_VSC_PRIM_STRM_LIMIT(cmd
->vsc_prim_strm_pitch
- 64));
1035 A6XX_VSC_DRAW_STRM_ADDRESS(.bo
= &cmd
->vsc_draw_strm
),
1036 A6XX_VSC_DRAW_STRM_PITCH(cmd
->vsc_draw_strm_pitch
),
1037 A6XX_VSC_DRAW_STRM_LIMIT(cmd
->vsc_draw_strm_pitch
- 64));
1041 emit_vsc_overflow_test(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1043 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1044 const uint32_t used_pipe_count
=
1045 tiling
->pipe_count
.width
* tiling
->pipe_count
.height
;
1047 /* Clear vsc_scratch: */
1048 tu_cs_emit_pkt7(cs
, CP_MEM_WRITE
, 3);
1049 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(vsc_scratch
));
1050 tu_cs_emit(cs
, 0x0);
1052 /* Check for overflow, write vsc_scratch if detected: */
1053 for (int i
= 0; i
< used_pipe_count
; i
++) {
1054 tu_cs_emit_pkt7(cs
, CP_COND_WRITE5
, 8);
1055 tu_cs_emit(cs
, CP_COND_WRITE5_0_FUNCTION(WRITE_GE
) |
1056 CP_COND_WRITE5_0_WRITE_MEMORY
);
1057 tu_cs_emit(cs
, CP_COND_WRITE5_1_POLL_ADDR_LO(REG_A6XX_VSC_DRAW_STRM_SIZE_REG(i
)));
1058 tu_cs_emit(cs
, CP_COND_WRITE5_2_POLL_ADDR_HI(0));
1059 tu_cs_emit(cs
, CP_COND_WRITE5_3_REF(cmd
->vsc_draw_strm_pitch
- 64));
1060 tu_cs_emit(cs
, CP_COND_WRITE5_4_MASK(~0));
1061 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(vsc_scratch
));
1062 tu_cs_emit(cs
, CP_COND_WRITE5_7_WRITE_DATA(1 + cmd
->vsc_draw_strm_pitch
));
1064 tu_cs_emit_pkt7(cs
, CP_COND_WRITE5
, 8);
1065 tu_cs_emit(cs
, CP_COND_WRITE5_0_FUNCTION(WRITE_GE
) |
1066 CP_COND_WRITE5_0_WRITE_MEMORY
);
1067 tu_cs_emit(cs
, CP_COND_WRITE5_1_POLL_ADDR_LO(REG_A6XX_VSC_PRIM_STRM_SIZE_REG(i
)));
1068 tu_cs_emit(cs
, CP_COND_WRITE5_2_POLL_ADDR_HI(0));
1069 tu_cs_emit(cs
, CP_COND_WRITE5_3_REF(cmd
->vsc_prim_strm_pitch
- 64));
1070 tu_cs_emit(cs
, CP_COND_WRITE5_4_MASK(~0));
1071 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(vsc_scratch
));
1072 tu_cs_emit(cs
, CP_COND_WRITE5_7_WRITE_DATA(3 + cmd
->vsc_prim_strm_pitch
));
1075 tu_cs_emit_pkt7(cs
, CP_WAIT_MEM_WRITES
, 0);
1079 tu6_emit_binning_pass(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1081 struct tu_physical_device
*phys_dev
= cmd
->device
->physical_device
;
1082 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1084 uint32_t x1
= tiling
->tile0
.offset
.x
;
1085 uint32_t y1
= tiling
->tile0
.offset
.y
;
1086 uint32_t x2
= tiling
->render_area
.offset
.x
+ tiling
->render_area
.extent
.width
- 1;
1087 uint32_t y2
= tiling
->render_area
.offset
.y
+ tiling
->render_area
.extent
.height
- 1;
1089 tu6_emit_window_scissor(cs
, x1
, y1
, x2
, y2
);
1091 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
1092 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_BINNING
));
1094 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
1095 tu_cs_emit(cs
, 0x1);
1097 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
1098 tu_cs_emit(cs
, 0x1);
1103 A6XX_VFD_MODE_CNTL(.binning_pass
= true));
1105 update_vsc_pipe(cmd
, cs
);
1108 A6XX_PC_UNKNOWN_9805(.unknown
= phys_dev
->magic
.PC_UNKNOWN_9805
));
1111 A6XX_SP_UNKNOWN_A0F8(.unknown
= phys_dev
->magic
.SP_UNKNOWN_A0F8
));
1113 tu_cs_emit_pkt7(cs
, CP_EVENT_WRITE
, 1);
1114 tu_cs_emit(cs
, UNK_2C
);
1117 A6XX_RB_WINDOW_OFFSET(.x
= 0, .y
= 0));
1120 A6XX_SP_TP_WINDOW_OFFSET(.x
= 0, .y
= 0));
1122 /* emit IB to binning drawcmds: */
1123 tu_cs_emit_call(cs
, &cmd
->draw_cs
);
1125 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 3);
1126 tu_cs_emit(cs
, CP_SET_DRAW_STATE__0_COUNT(0) |
1127 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
1128 CP_SET_DRAW_STATE__0_GROUP_ID(0));
1129 tu_cs_emit(cs
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
1130 tu_cs_emit(cs
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
1132 tu_cs_emit_pkt7(cs
, CP_EVENT_WRITE
, 1);
1133 tu_cs_emit(cs
, UNK_2D
);
1135 /* This flush is probably required because the VSC, which produces the
1136 * visibility stream, is a client of UCHE, whereas the CP needs to read the
1137 * visibility stream (without caching) to do draw skipping. The
1138 * WFI+WAIT_FOR_ME combination guarantees that the binning commands
1139 * submitted are finished before reading the VSC regs (in
1140 * emit_vsc_overflow_test) or the VSC_DATA buffer directly (implicitly as
1143 tu6_emit_event_write(cmd
, cs
, CACHE_FLUSH_TS
);
1147 tu_cs_emit_pkt7(cs
, CP_WAIT_FOR_ME
, 0);
1149 emit_vsc_overflow_test(cmd
, cs
);
1151 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
1152 tu_cs_emit(cs
, 0x0);
1154 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
1155 tu_cs_emit(cs
, 0x0);
1159 tu_emit_input_attachments(struct tu_cmd_buffer
*cmd
,
1160 const struct tu_subpass
*subpass
,
1161 struct tu_cs_entry
*ib
,
1164 /* note: we can probably emit input attachments just once for the whole
1165 * renderpass, this would avoid emitting both sysmem/gmem versions
1167 * emit two texture descriptors for each input, as a workaround for
1168 * d24s8, which can be sampled as both float (depth) and integer (stencil)
1169 * tu_shader lowers uint input attachment loads to use the 2nd descriptor
1171 * TODO: a smarter workaround
1174 if (!subpass
->input_count
)
1177 struct tu_cs_memory texture
;
1178 VkResult result
= tu_cs_alloc(&cmd
->sub_cs
, subpass
->input_count
* 2,
1179 A6XX_TEX_CONST_DWORDS
, &texture
);
1180 assert(result
== VK_SUCCESS
);
1182 for (unsigned i
= 0; i
< subpass
->input_count
* 2; i
++) {
1183 uint32_t a
= subpass
->input_attachments
[i
/ 2].attachment
;
1184 if (a
== VK_ATTACHMENT_UNUSED
)
1187 struct tu_image_view
*iview
=
1188 cmd
->state
.framebuffer
->attachments
[a
].attachment
;
1189 const struct tu_render_pass_attachment
*att
=
1190 &cmd
->state
.pass
->attachments
[a
];
1191 uint32_t *dst
= &texture
.map
[A6XX_TEX_CONST_DWORDS
* i
];
1193 memcpy(dst
, iview
->descriptor
, A6XX_TEX_CONST_DWORDS
* 4);
1195 if (i
% 2 == 1 && att
->format
== VK_FORMAT_D24_UNORM_S8_UINT
) {
1196 /* note this works because spec says fb and input attachments
1197 * must use identity swizzle
1199 dst
[0] &= ~(A6XX_TEX_CONST_0_FMT__MASK
|
1200 A6XX_TEX_CONST_0_SWIZ_X__MASK
| A6XX_TEX_CONST_0_SWIZ_Y__MASK
|
1201 A6XX_TEX_CONST_0_SWIZ_Z__MASK
| A6XX_TEX_CONST_0_SWIZ_W__MASK
);
1202 dst
[0] |= A6XX_TEX_CONST_0_FMT(FMT6_S8Z24_UINT
) |
1203 A6XX_TEX_CONST_0_SWIZ_X(A6XX_TEX_Y
) |
1204 A6XX_TEX_CONST_0_SWIZ_Y(A6XX_TEX_ZERO
) |
1205 A6XX_TEX_CONST_0_SWIZ_Z(A6XX_TEX_ZERO
) |
1206 A6XX_TEX_CONST_0_SWIZ_W(A6XX_TEX_ONE
);
1212 /* patched for gmem */
1213 dst
[0] &= ~(A6XX_TEX_CONST_0_SWAP__MASK
| A6XX_TEX_CONST_0_TILE_MODE__MASK
);
1214 dst
[0] |= A6XX_TEX_CONST_0_TILE_MODE(TILE6_2
);
1216 A6XX_TEX_CONST_2_TYPE(A6XX_TEX_2D
) |
1217 A6XX_TEX_CONST_2_PITCH(cmd
->state
.tiling_config
.tile0
.extent
.width
* att
->cpp
);
1219 dst
[4] = cmd
->device
->physical_device
->gmem_base
+ att
->gmem_offset
;
1220 dst
[5] = A6XX_TEX_CONST_5_DEPTH(1);
1221 for (unsigned i
= 6; i
< A6XX_TEX_CONST_DWORDS
; i
++)
1226 tu_cs_begin_sub_stream(&cmd
->sub_cs
, 9, &cs
);
1228 tu_cs_emit_pkt7(&cs
, CP_LOAD_STATE6_FRAG
, 3);
1229 tu_cs_emit(&cs
, CP_LOAD_STATE6_0_DST_OFF(0) |
1230 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
1231 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
1232 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_FS_TEX
) |
1233 CP_LOAD_STATE6_0_NUM_UNIT(subpass
->input_count
* 2));
1234 tu_cs_emit_qw(&cs
, texture
.iova
);
1236 tu_cs_emit_pkt4(&cs
, REG_A6XX_SP_FS_TEX_CONST_LO
, 2);
1237 tu_cs_emit_qw(&cs
, texture
.iova
);
1239 tu_cs_emit_regs(&cs
, A6XX_SP_FS_TEX_COUNT(subpass
->input_count
* 2));
1241 *ib
= tu_cs_end_sub_stream(&cmd
->sub_cs
, &cs
);
1245 tu_set_input_attachments(struct tu_cmd_buffer
*cmd
, const struct tu_subpass
*subpass
)
1247 struct tu_cs
*cs
= &cmd
->draw_cs
;
1249 tu_emit_input_attachments(cmd
, subpass
, &cmd
->state
.ia_gmem_ib
, true);
1250 tu_emit_input_attachments(cmd
, subpass
, &cmd
->state
.ia_sysmem_ib
, false);
1252 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 6);
1253 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_INPUT_ATTACHMENTS_GMEM
, cmd
->state
.ia_gmem_ib
);
1254 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_INPUT_ATTACHMENTS_SYSMEM
, cmd
->state
.ia_sysmem_ib
);
1258 tu_emit_renderpass_begin(struct tu_cmd_buffer
*cmd
,
1259 const VkRenderPassBeginInfo
*info
)
1261 struct tu_cs
*cs
= &cmd
->draw_cs
;
1263 tu_cond_exec_start(cs
, CP_COND_EXEC_0_RENDER_MODE_GMEM
);
1265 tu6_emit_blit_scissor(cmd
, cs
, true);
1267 for (uint32_t i
= 0; i
< cmd
->state
.pass
->attachment_count
; ++i
)
1268 tu_load_gmem_attachment(cmd
, cs
, i
, false);
1270 tu6_emit_blit_scissor(cmd
, cs
, false);
1272 for (uint32_t i
= 0; i
< cmd
->state
.pass
->attachment_count
; ++i
)
1273 tu_clear_gmem_attachment(cmd
, cs
, i
, info
);
1275 tu_cond_exec_end(cs
);
1277 tu_cond_exec_start(cs
, CP_COND_EXEC_0_RENDER_MODE_SYSMEM
);
1279 for (uint32_t i
= 0; i
< cmd
->state
.pass
->attachment_count
; ++i
)
1280 tu_clear_sysmem_attachment(cmd
, cs
, i
, info
);
1282 tu_cond_exec_end(cs
);
1286 tu6_sysmem_render_begin(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
,
1287 const struct VkRect2D
*renderArea
)
1289 const struct tu_framebuffer
*fb
= cmd
->state
.framebuffer
;
1291 assert(fb
->width
> 0 && fb
->height
> 0);
1292 tu6_emit_window_scissor(cs
, 0, 0, fb
->width
- 1, fb
->height
- 1);
1293 tu6_emit_window_offset(cs
, 0, 0);
1295 tu6_emit_bin_size(cs
, 0, 0, 0xc00000); /* 0xc00000 = BYPASS? */
1297 tu6_emit_event_write(cmd
, cs
, LRZ_FLUSH
);
1299 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
1300 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_BYPASS
));
1302 tu_cs_emit_pkt7(cs
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1303 tu_cs_emit(cs
, 0x0);
1305 tu_emit_cache_flush_ccu(cmd
, cs
, TU_CMD_CCU_SYSMEM
);
1307 /* enable stream-out, with sysmem there is only one pass: */
1309 A6XX_VPC_SO_OVERRIDE(.so_disable
= false));
1311 tu_cs_emit_pkt7(cs
, CP_SET_VISIBILITY_OVERRIDE
, 1);
1312 tu_cs_emit(cs
, 0x1);
1314 tu_cs_emit_pkt7(cs
, CP_SET_MODE
, 1);
1315 tu_cs_emit(cs
, 0x0);
1317 tu_cs_sanity_check(cs
);
1321 tu6_sysmem_render_end(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1323 /* Do any resolves of the last subpass. These are handled in the
1324 * tile_store_ib in the gmem path.
1326 tu6_emit_sysmem_resolves(cmd
, cs
, cmd
->state
.subpass
);
1328 tu_cs_emit_call(cs
, &cmd
->draw_epilogue_cs
);
1330 tu_cs_emit_pkt7(cs
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1331 tu_cs_emit(cs
, 0x0);
1333 tu6_emit_event_write(cmd
, cs
, LRZ_FLUSH
);
1335 tu_cs_sanity_check(cs
);
1339 tu6_tile_render_begin(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1341 struct tu_physical_device
*phys_dev
= cmd
->device
->physical_device
;
1343 tu6_emit_event_write(cmd
, cs
, LRZ_FLUSH
);
1347 tu_cs_emit_pkt7(cs
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1348 tu_cs_emit(cs
, 0x0);
1350 tu_emit_cache_flush_ccu(cmd
, cs
, TU_CMD_CCU_GMEM
);
1352 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1353 if (use_hw_binning(cmd
)) {
1354 /* enable stream-out during binning pass: */
1355 tu_cs_emit_regs(cs
, A6XX_VPC_SO_OVERRIDE(.so_disable
=false));
1357 tu6_emit_bin_size(cs
,
1358 tiling
->tile0
.extent
.width
,
1359 tiling
->tile0
.extent
.height
,
1360 A6XX_RB_BIN_CONTROL_BINNING_PASS
| 0x6000000);
1362 tu6_emit_render_cntl(cmd
, cmd
->state
.subpass
, cs
, true);
1364 tu6_emit_binning_pass(cmd
, cs
);
1366 /* and disable stream-out for draw pass: */
1367 tu_cs_emit_regs(cs
, A6XX_VPC_SO_OVERRIDE(.so_disable
=true));
1369 tu6_emit_bin_size(cs
,
1370 tiling
->tile0
.extent
.width
,
1371 tiling
->tile0
.extent
.height
,
1372 A6XX_RB_BIN_CONTROL_USE_VIZ
| 0x6000000);
1375 A6XX_VFD_MODE_CNTL(0));
1377 tu_cs_emit_regs(cs
, A6XX_PC_UNKNOWN_9805(.unknown
= phys_dev
->magic
.PC_UNKNOWN_9805
));
1379 tu_cs_emit_regs(cs
, A6XX_SP_UNKNOWN_A0F8(.unknown
= phys_dev
->magic
.SP_UNKNOWN_A0F8
));
1381 tu_cs_emit_pkt7(cs
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1382 tu_cs_emit(cs
, 0x1);
1384 /* no binning pass, so enable stream-out for draw pass:: */
1385 tu_cs_emit_regs(cs
, A6XX_VPC_SO_OVERRIDE(.so_disable
=false));
1387 tu6_emit_bin_size(cs
,
1388 tiling
->tile0
.extent
.width
,
1389 tiling
->tile0
.extent
.height
,
1393 tu_cs_sanity_check(cs
);
1397 tu6_render_tile(struct tu_cmd_buffer
*cmd
,
1399 const struct tu_tile
*tile
)
1401 tu6_emit_tile_select(cmd
, cs
, tile
);
1403 tu_cs_emit_call(cs
, &cmd
->draw_cs
);
1405 if (use_hw_binning(cmd
)) {
1406 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
1407 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_ENDVIS
));
1410 tu_cs_emit_ib(cs
, &cmd
->state
.tile_store_ib
);
1412 tu_cs_sanity_check(cs
);
1416 tu6_tile_render_end(struct tu_cmd_buffer
*cmd
, struct tu_cs
*cs
)
1418 tu_cs_emit_call(cs
, &cmd
->draw_epilogue_cs
);
1421 A6XX_GRAS_LRZ_CNTL(0));
1423 tu6_emit_event_write(cmd
, cs
, LRZ_FLUSH
);
1425 tu6_emit_event_write(cmd
, cs
, PC_CCU_RESOLVE_TS
);
1427 tu_cs_sanity_check(cs
);
1431 tu_cmd_render_tiles(struct tu_cmd_buffer
*cmd
)
1433 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1435 if (use_hw_binning(cmd
))
1436 cmd
->use_vsc_data
= true;
1438 tu6_tile_render_begin(cmd
, &cmd
->cs
);
1440 for (uint32_t y
= 0; y
< tiling
->tile_count
.height
; y
++) {
1441 for (uint32_t x
= 0; x
< tiling
->tile_count
.width
; x
++) {
1442 struct tu_tile tile
;
1443 tu_tiling_config_get_tile(tiling
, cmd
->device
, x
, y
, &tile
);
1444 tu6_render_tile(cmd
, &cmd
->cs
, &tile
);
1448 tu6_tile_render_end(cmd
, &cmd
->cs
);
1452 tu_cmd_render_sysmem(struct tu_cmd_buffer
*cmd
)
1454 const struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1456 tu6_sysmem_render_begin(cmd
, &cmd
->cs
, &tiling
->render_area
);
1458 tu_cs_emit_call(&cmd
->cs
, &cmd
->draw_cs
);
1460 tu6_sysmem_render_end(cmd
, &cmd
->cs
);
1464 tu_cmd_prepare_tile_store_ib(struct tu_cmd_buffer
*cmd
)
1466 const uint32_t tile_store_space
= 11 + (35 * 2) * cmd
->state
.pass
->attachment_count
;
1467 struct tu_cs sub_cs
;
1470 tu_cs_begin_sub_stream(&cmd
->sub_cs
, tile_store_space
, &sub_cs
);
1471 if (result
!= VK_SUCCESS
) {
1472 cmd
->record_result
= result
;
1476 /* emit to tile-store sub_cs */
1477 tu6_emit_tile_store(cmd
, &sub_cs
);
1479 cmd
->state
.tile_store_ib
= tu_cs_end_sub_stream(&cmd
->sub_cs
, &sub_cs
);
1483 tu_cmd_update_tiling_config(struct tu_cmd_buffer
*cmd
,
1484 const VkRect2D
*render_area
)
1486 const struct tu_device
*dev
= cmd
->device
;
1487 struct tu_tiling_config
*tiling
= &cmd
->state
.tiling_config
;
1489 tiling
->render_area
= *render_area
;
1490 tiling
->force_sysmem
= false;
1492 tu_tiling_config_update_tile_layout(tiling
, dev
, cmd
->state
.pass
);
1493 tu_tiling_config_update_pipe_layout(tiling
, dev
);
1494 tu_tiling_config_update_pipes(tiling
, dev
);
1498 tu_create_cmd_buffer(struct tu_device
*device
,
1499 struct tu_cmd_pool
*pool
,
1500 VkCommandBufferLevel level
,
1501 VkCommandBuffer
*pCommandBuffer
)
1503 struct tu_cmd_buffer
*cmd_buffer
;
1504 cmd_buffer
= vk_zalloc(&pool
->alloc
, sizeof(*cmd_buffer
), 8,
1505 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1506 if (cmd_buffer
== NULL
)
1507 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1509 cmd_buffer
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1510 cmd_buffer
->device
= device
;
1511 cmd_buffer
->pool
= pool
;
1512 cmd_buffer
->level
= level
;
1515 list_addtail(&cmd_buffer
->pool_link
, &pool
->cmd_buffers
);
1516 cmd_buffer
->queue_family_index
= pool
->queue_family_index
;
1519 /* Init the pool_link so we can safely call list_del when we destroy
1520 * the command buffer
1522 list_inithead(&cmd_buffer
->pool_link
);
1523 cmd_buffer
->queue_family_index
= TU_QUEUE_GENERAL
;
1526 tu_bo_list_init(&cmd_buffer
->bo_list
);
1527 tu_cs_init(&cmd_buffer
->cs
, device
, TU_CS_MODE_GROW
, 4096);
1528 tu_cs_init(&cmd_buffer
->draw_cs
, device
, TU_CS_MODE_GROW
, 4096);
1529 tu_cs_init(&cmd_buffer
->draw_epilogue_cs
, device
, TU_CS_MODE_GROW
, 4096);
1530 tu_cs_init(&cmd_buffer
->sub_cs
, device
, TU_CS_MODE_SUB_STREAM
, 2048);
1532 *pCommandBuffer
= tu_cmd_buffer_to_handle(cmd_buffer
);
1534 list_inithead(&cmd_buffer
->upload
.list
);
1536 VkResult result
= tu_bo_init_new(device
, &cmd_buffer
->scratch_bo
, 0x1000);
1537 if (result
!= VK_SUCCESS
)
1538 goto fail_scratch_bo
;
1540 /* TODO: resize on overflow */
1541 cmd_buffer
->vsc_draw_strm_pitch
= device
->vsc_draw_strm_pitch
;
1542 cmd_buffer
->vsc_prim_strm_pitch
= device
->vsc_prim_strm_pitch
;
1543 cmd_buffer
->vsc_draw_strm
= device
->vsc_draw_strm
;
1544 cmd_buffer
->vsc_prim_strm
= device
->vsc_prim_strm
;
1549 list_del(&cmd_buffer
->pool_link
);
1554 tu_cmd_buffer_destroy(struct tu_cmd_buffer
*cmd_buffer
)
1556 tu_bo_finish(cmd_buffer
->device
, &cmd_buffer
->scratch_bo
);
1558 list_del(&cmd_buffer
->pool_link
);
1560 tu_cs_finish(&cmd_buffer
->cs
);
1561 tu_cs_finish(&cmd_buffer
->draw_cs
);
1562 tu_cs_finish(&cmd_buffer
->draw_epilogue_cs
);
1563 tu_cs_finish(&cmd_buffer
->sub_cs
);
1565 tu_bo_list_destroy(&cmd_buffer
->bo_list
);
1566 vk_free(&cmd_buffer
->pool
->alloc
, cmd_buffer
);
1570 tu_reset_cmd_buffer(struct tu_cmd_buffer
*cmd_buffer
)
1572 cmd_buffer
->record_result
= VK_SUCCESS
;
1574 tu_bo_list_reset(&cmd_buffer
->bo_list
);
1575 tu_cs_reset(&cmd_buffer
->cs
);
1576 tu_cs_reset(&cmd_buffer
->draw_cs
);
1577 tu_cs_reset(&cmd_buffer
->draw_epilogue_cs
);
1578 tu_cs_reset(&cmd_buffer
->sub_cs
);
1580 for (unsigned i
= 0; i
< MAX_BIND_POINTS
; i
++)
1581 memset(&cmd_buffer
->descriptors
[i
].sets
, 0, sizeof(cmd_buffer
->descriptors
[i
].sets
));
1583 cmd_buffer
->status
= TU_CMD_BUFFER_STATUS_INITIAL
;
1585 return cmd_buffer
->record_result
;
1589 tu_AllocateCommandBuffers(VkDevice _device
,
1590 const VkCommandBufferAllocateInfo
*pAllocateInfo
,
1591 VkCommandBuffer
*pCommandBuffers
)
1593 TU_FROM_HANDLE(tu_device
, device
, _device
);
1594 TU_FROM_HANDLE(tu_cmd_pool
, pool
, pAllocateInfo
->commandPool
);
1596 VkResult result
= VK_SUCCESS
;
1599 for (i
= 0; i
< pAllocateInfo
->commandBufferCount
; i
++) {
1601 if (!list_is_empty(&pool
->free_cmd_buffers
)) {
1602 struct tu_cmd_buffer
*cmd_buffer
= list_first_entry(
1603 &pool
->free_cmd_buffers
, struct tu_cmd_buffer
, pool_link
);
1605 list_del(&cmd_buffer
->pool_link
);
1606 list_addtail(&cmd_buffer
->pool_link
, &pool
->cmd_buffers
);
1608 result
= tu_reset_cmd_buffer(cmd_buffer
);
1609 cmd_buffer
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1610 cmd_buffer
->level
= pAllocateInfo
->level
;
1612 pCommandBuffers
[i
] = tu_cmd_buffer_to_handle(cmd_buffer
);
1614 result
= tu_create_cmd_buffer(device
, pool
, pAllocateInfo
->level
,
1615 &pCommandBuffers
[i
]);
1617 if (result
!= VK_SUCCESS
)
1621 if (result
!= VK_SUCCESS
) {
1622 tu_FreeCommandBuffers(_device
, pAllocateInfo
->commandPool
, i
,
1625 /* From the Vulkan 1.0.66 spec:
1627 * "vkAllocateCommandBuffers can be used to create multiple
1628 * command buffers. If the creation of any of those command
1629 * buffers fails, the implementation must destroy all
1630 * successfully created command buffer objects from this
1631 * command, set all entries of the pCommandBuffers array to
1632 * NULL and return the error."
1634 memset(pCommandBuffers
, 0,
1635 sizeof(*pCommandBuffers
) * pAllocateInfo
->commandBufferCount
);
1642 tu_FreeCommandBuffers(VkDevice device
,
1643 VkCommandPool commandPool
,
1644 uint32_t commandBufferCount
,
1645 const VkCommandBuffer
*pCommandBuffers
)
1647 for (uint32_t i
= 0; i
< commandBufferCount
; i
++) {
1648 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, pCommandBuffers
[i
]);
1651 if (cmd_buffer
->pool
) {
1652 list_del(&cmd_buffer
->pool_link
);
1653 list_addtail(&cmd_buffer
->pool_link
,
1654 &cmd_buffer
->pool
->free_cmd_buffers
);
1656 tu_cmd_buffer_destroy(cmd_buffer
);
1662 tu_ResetCommandBuffer(VkCommandBuffer commandBuffer
,
1663 VkCommandBufferResetFlags flags
)
1665 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
1666 return tu_reset_cmd_buffer(cmd_buffer
);
1669 /* Initialize the cache, assuming all necessary flushes have happened but *not*
1673 tu_cache_init(struct tu_cache_state
*cache
)
1675 cache
->flush_bits
= 0;
1676 cache
->pending_flush_bits
= TU_CMD_FLAG_ALL_INVALIDATE
;
1680 tu_BeginCommandBuffer(VkCommandBuffer commandBuffer
,
1681 const VkCommandBufferBeginInfo
*pBeginInfo
)
1683 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
1684 VkResult result
= VK_SUCCESS
;
1686 if (cmd_buffer
->status
!= TU_CMD_BUFFER_STATUS_INITIAL
) {
1687 /* If the command buffer has already been resetted with
1688 * vkResetCommandBuffer, no need to do it again.
1690 result
= tu_reset_cmd_buffer(cmd_buffer
);
1691 if (result
!= VK_SUCCESS
)
1695 memset(&cmd_buffer
->state
, 0, sizeof(cmd_buffer
->state
));
1696 cmd_buffer
->state
.index_size
= 0xff; /* dirty restart index */
1698 tu_cache_init(&cmd_buffer
->state
.cache
);
1699 tu_cache_init(&cmd_buffer
->state
.renderpass_cache
);
1700 cmd_buffer
->usage_flags
= pBeginInfo
->flags
;
1702 tu_cs_begin(&cmd_buffer
->cs
);
1703 tu_cs_begin(&cmd_buffer
->draw_cs
);
1704 tu_cs_begin(&cmd_buffer
->draw_epilogue_cs
);
1706 /* setup initial configuration into command buffer */
1707 if (cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
) {
1708 switch (cmd_buffer
->queue_family_index
) {
1709 case TU_QUEUE_GENERAL
:
1710 tu6_init_hw(cmd_buffer
, &cmd_buffer
->cs
);
1715 } else if (cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_SECONDARY
) {
1716 if (pBeginInfo
->flags
& VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
) {
1717 assert(pBeginInfo
->pInheritanceInfo
);
1718 cmd_buffer
->state
.pass
= tu_render_pass_from_handle(pBeginInfo
->pInheritanceInfo
->renderPass
);
1719 cmd_buffer
->state
.subpass
=
1720 &cmd_buffer
->state
.pass
->subpasses
[pBeginInfo
->pInheritanceInfo
->subpass
];
1722 /* When executing in the middle of another command buffer, the CCU
1725 cmd_buffer
->state
.ccu_state
= TU_CMD_CCU_UNKNOWN
;
1729 cmd_buffer
->status
= TU_CMD_BUFFER_STATUS_RECORDING
;
1734 /* Sets vertex buffers to HW binding points. We emit VBs in SDS (so that bin
1735 * rendering can skip over unused state), so we need to collect all the
1736 * bindings together into a single state emit at draw time.
1739 tu_CmdBindVertexBuffers(VkCommandBuffer commandBuffer
,
1740 uint32_t firstBinding
,
1741 uint32_t bindingCount
,
1742 const VkBuffer
*pBuffers
,
1743 const VkDeviceSize
*pOffsets
)
1745 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1747 assert(firstBinding
+ bindingCount
<= MAX_VBS
);
1749 for (uint32_t i
= 0; i
< bindingCount
; i
++) {
1750 struct tu_buffer
*buf
= tu_buffer_from_handle(pBuffers
[i
]);
1752 cmd
->state
.vb
.buffers
[firstBinding
+ i
] = buf
;
1753 cmd
->state
.vb
.offsets
[firstBinding
+ i
] = pOffsets
[i
];
1755 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_READ
);
1758 cmd
->state
.dirty
|= TU_CMD_DIRTY_VERTEX_BUFFERS
;
1762 tu_CmdBindIndexBuffer(VkCommandBuffer commandBuffer
,
1764 VkDeviceSize offset
,
1765 VkIndexType indexType
)
1767 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1768 TU_FROM_HANDLE(tu_buffer
, buf
, buffer
);
1772 uint32_t index_size
, index_shift
, restart_index
;
1774 switch (indexType
) {
1775 case VK_INDEX_TYPE_UINT16
:
1776 index_size
= INDEX4_SIZE_16_BIT
;
1778 restart_index
= 0xffff;
1780 case VK_INDEX_TYPE_UINT32
:
1781 index_size
= INDEX4_SIZE_32_BIT
;
1783 restart_index
= 0xffffffff;
1785 case VK_INDEX_TYPE_UINT8_EXT
:
1786 index_size
= INDEX4_SIZE_8_BIT
;
1788 restart_index
= 0xff;
1791 unreachable("invalid VkIndexType");
1794 /* initialize/update the restart index */
1795 if (cmd
->state
.index_size
!= index_size
)
1796 tu_cs_emit_regs(&cmd
->draw_cs
, A6XX_PC_RESTART_INDEX(restart_index
));
1798 assert(buf
->size
>= offset
);
1800 cmd
->state
.index_va
= buf
->bo
->iova
+ buf
->bo_offset
+ offset
;
1801 cmd
->state
.max_index_count
= (buf
->size
- offset
) >> index_shift
;
1802 cmd
->state
.index_size
= index_size
;
1803 cmd
->state
.index_shift
= index_shift
;
1805 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_READ
);
1809 tu_CmdBindDescriptorSets(VkCommandBuffer commandBuffer
,
1810 VkPipelineBindPoint pipelineBindPoint
,
1811 VkPipelineLayout _layout
,
1813 uint32_t descriptorSetCount
,
1814 const VkDescriptorSet
*pDescriptorSets
,
1815 uint32_t dynamicOffsetCount
,
1816 const uint32_t *pDynamicOffsets
)
1818 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1819 TU_FROM_HANDLE(tu_pipeline_layout
, layout
, _layout
);
1820 unsigned dyn_idx
= 0;
1822 struct tu_descriptor_state
*descriptors_state
=
1823 tu_get_descriptors_state(cmd
, pipelineBindPoint
);
1825 for (unsigned i
= 0; i
< descriptorSetCount
; ++i
) {
1826 unsigned idx
= i
+ firstSet
;
1827 TU_FROM_HANDLE(tu_descriptor_set
, set
, pDescriptorSets
[i
]);
1829 descriptors_state
->sets
[idx
] = set
;
1831 for(unsigned j
= 0; j
< set
->layout
->dynamic_offset_count
; ++j
, ++dyn_idx
) {
1832 /* update the contents of the dynamic descriptor set */
1833 unsigned src_idx
= j
;
1834 unsigned dst_idx
= j
+ layout
->set
[idx
].dynamic_offset_start
;
1835 assert(dyn_idx
< dynamicOffsetCount
);
1838 &descriptors_state
->dynamic_descriptors
[dst_idx
* A6XX_TEX_CONST_DWORDS
];
1840 &set
->dynamic_descriptors
[src_idx
* A6XX_TEX_CONST_DWORDS
];
1841 uint32_t offset
= pDynamicOffsets
[dyn_idx
];
1843 /* Patch the storage/uniform descriptors right away. */
1844 if (layout
->set
[idx
].layout
->dynamic_ubo
& (1 << j
)) {
1845 /* Note: we can assume here that the addition won't roll over and
1846 * change the SIZE field.
1848 uint64_t va
= src
[0] | ((uint64_t)src
[1] << 32);
1853 memcpy(dst
, src
, A6XX_TEX_CONST_DWORDS
* 4);
1854 /* Note: A6XX_IBO_5_DEPTH is always 0 */
1855 uint64_t va
= dst
[4] | ((uint64_t)dst
[5] << 32);
1862 for (unsigned j
= 0; j
< set
->layout
->buffer_count
; ++j
) {
1863 if (set
->buffers
[j
]) {
1864 tu_bo_list_add(&cmd
->bo_list
, set
->buffers
[j
],
1865 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
1869 if (set
->size
> 0) {
1870 tu_bo_list_add(&cmd
->bo_list
, &set
->pool
->bo
,
1871 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
1874 assert(dyn_idx
== dynamicOffsetCount
);
1876 uint32_t sp_bindless_base_reg
, hlsq_bindless_base_reg
, hlsq_update_value
;
1877 uint64_t addr
[MAX_SETS
+ 1] = {};
1880 for (uint32_t i
= 0; i
< MAX_SETS
; i
++) {
1881 struct tu_descriptor_set
*set
= descriptors_state
->sets
[i
];
1883 addr
[i
] = set
->va
| 3;
1886 if (layout
->dynamic_offset_count
) {
1887 /* allocate and fill out dynamic descriptor set */
1888 struct tu_cs_memory dynamic_desc_set
;
1889 VkResult result
= tu_cs_alloc(&cmd
->sub_cs
, layout
->dynamic_offset_count
,
1890 A6XX_TEX_CONST_DWORDS
, &dynamic_desc_set
);
1891 assert(result
== VK_SUCCESS
);
1893 memcpy(dynamic_desc_set
.map
, descriptors_state
->dynamic_descriptors
,
1894 layout
->dynamic_offset_count
* A6XX_TEX_CONST_DWORDS
* 4);
1895 addr
[MAX_SETS
] = dynamic_desc_set
.iova
| 3;
1898 if (pipelineBindPoint
== VK_PIPELINE_BIND_POINT_GRAPHICS
) {
1899 sp_bindless_base_reg
= REG_A6XX_SP_BINDLESS_BASE(0);
1900 hlsq_bindless_base_reg
= REG_A6XX_HLSQ_BINDLESS_BASE(0);
1901 hlsq_update_value
= 0x7c000;
1903 cmd
->state
.dirty
|= TU_CMD_DIRTY_DESCRIPTOR_SETS
| TU_CMD_DIRTY_SHADER_CONSTS
;
1905 assert(pipelineBindPoint
== VK_PIPELINE_BIND_POINT_COMPUTE
);
1907 sp_bindless_base_reg
= REG_A6XX_SP_CS_BINDLESS_BASE(0);
1908 hlsq_bindless_base_reg
= REG_A6XX_HLSQ_CS_BINDLESS_BASE(0);
1909 hlsq_update_value
= 0x3e00;
1911 cmd
->state
.dirty
|= TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
;
1914 tu_cs_begin_sub_stream(&cmd
->sub_cs
, 24, &cs
);
1916 tu_cs_emit_pkt4(&cs
, sp_bindless_base_reg
, 10);
1917 tu_cs_emit_array(&cs
, (const uint32_t*) addr
, 10);
1918 tu_cs_emit_pkt4(&cs
, hlsq_bindless_base_reg
, 10);
1919 tu_cs_emit_array(&cs
, (const uint32_t*) addr
, 10);
1920 tu_cs_emit_regs(&cs
, A6XX_HLSQ_UPDATE_CNTL(.dword
= hlsq_update_value
));
1922 struct tu_cs_entry ib
= tu_cs_end_sub_stream(&cmd
->sub_cs
, &cs
);
1923 if (pipelineBindPoint
== VK_PIPELINE_BIND_POINT_GRAPHICS
) {
1924 tu_cs_emit_pkt7(&cmd
->draw_cs
, CP_SET_DRAW_STATE
, 3);
1925 tu_cs_emit_sds_ib(&cmd
->draw_cs
, TU_DRAW_STATE_DESC_SETS
, ib
);
1926 cmd
->state
.desc_sets_ib
= ib
;
1928 /* note: for compute we could emit directly, instead of a CP_INDIRECT
1929 * however, the blob uses draw states for compute
1931 tu_cs_emit_ib(&cmd
->cs
, &ib
);
1935 void tu_CmdBindTransformFeedbackBuffersEXT(VkCommandBuffer commandBuffer
,
1936 uint32_t firstBinding
,
1937 uint32_t bindingCount
,
1938 const VkBuffer
*pBuffers
,
1939 const VkDeviceSize
*pOffsets
,
1940 const VkDeviceSize
*pSizes
)
1942 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1943 struct tu_cs
*cs
= &cmd
->draw_cs
;
1945 /* using COND_REG_EXEC for xfb commands matches the blob behavior
1946 * presumably there isn't any benefit using a draw state when the
1947 * condition is (SYSMEM | BINNING)
1949 tu_cond_exec_start(cs
, CP_COND_REG_EXEC_0_MODE(RENDER_MODE
) |
1950 CP_COND_REG_EXEC_0_SYSMEM
|
1951 CP_COND_REG_EXEC_0_BINNING
);
1953 for (uint32_t i
= 0; i
< bindingCount
; i
++) {
1954 TU_FROM_HANDLE(tu_buffer
, buf
, pBuffers
[i
]);
1955 uint64_t iova
= buf
->bo
->iova
+ pOffsets
[i
];
1956 uint32_t size
= buf
->bo
->size
- pOffsets
[i
];
1957 uint32_t idx
= i
+ firstBinding
;
1959 if (pSizes
&& pSizes
[i
] != VK_WHOLE_SIZE
)
1962 /* BUFFER_BASE is 32-byte aligned, add remaining offset to BUFFER_OFFSET */
1963 uint32_t offset
= iova
& 0x1f;
1964 iova
&= ~(uint64_t) 0x1f;
1966 tu_cs_emit_pkt4(cs
, REG_A6XX_VPC_SO_BUFFER_BASE(idx
), 3);
1967 tu_cs_emit_qw(cs
, iova
);
1968 tu_cs_emit(cs
, size
+ offset
);
1970 cmd
->state
.streamout_offset
[idx
] = offset
;
1972 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_WRITE
);
1975 tu_cond_exec_end(cs
);
1979 tu_CmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer
,
1980 uint32_t firstCounterBuffer
,
1981 uint32_t counterBufferCount
,
1982 const VkBuffer
*pCounterBuffers
,
1983 const VkDeviceSize
*pCounterBufferOffsets
)
1985 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
1986 struct tu_cs
*cs
= &cmd
->draw_cs
;
1988 tu_cond_exec_start(cs
, CP_COND_REG_EXEC_0_MODE(RENDER_MODE
) |
1989 CP_COND_REG_EXEC_0_SYSMEM
|
1990 CP_COND_REG_EXEC_0_BINNING
);
1992 /* TODO: only update offset for active buffers */
1993 for (uint32_t i
= 0; i
< IR3_MAX_SO_BUFFERS
; i
++)
1994 tu_cs_emit_regs(cs
, A6XX_VPC_SO_BUFFER_OFFSET(i
, cmd
->state
.streamout_offset
[i
]));
1996 for (uint32_t i
= 0; i
< counterBufferCount
; i
++) {
1997 uint32_t idx
= firstCounterBuffer
+ i
;
1998 uint32_t offset
= cmd
->state
.streamout_offset
[idx
];
2000 if (!pCounterBuffers
[i
])
2003 TU_FROM_HANDLE(tu_buffer
, buf
, pCounterBuffers
[i
]);
2005 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_READ
);
2007 tu_cs_emit_pkt7(cs
, CP_MEM_TO_REG
, 3);
2008 tu_cs_emit(cs
, CP_MEM_TO_REG_0_REG(REG_A6XX_VPC_SO_BUFFER_OFFSET(idx
)) |
2009 CP_MEM_TO_REG_0_UNK31
|
2010 CP_MEM_TO_REG_0_CNT(1));
2011 tu_cs_emit_qw(cs
, buf
->bo
->iova
+ pCounterBufferOffsets
[i
]);
2014 tu_cs_emit_pkt7(cs
, CP_REG_RMW
, 3);
2015 tu_cs_emit(cs
, CP_REG_RMW_0_DST_REG(REG_A6XX_VPC_SO_BUFFER_OFFSET(idx
)) |
2016 CP_REG_RMW_0_SRC1_ADD
);
2017 tu_cs_emit_qw(cs
, 0xffffffff);
2018 tu_cs_emit_qw(cs
, offset
);
2022 tu_cond_exec_end(cs
);
2025 void tu_CmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer
,
2026 uint32_t firstCounterBuffer
,
2027 uint32_t counterBufferCount
,
2028 const VkBuffer
*pCounterBuffers
,
2029 const VkDeviceSize
*pCounterBufferOffsets
)
2031 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2032 struct tu_cs
*cs
= &cmd
->draw_cs
;
2034 tu_cond_exec_start(cs
, CP_COND_REG_EXEC_0_MODE(RENDER_MODE
) |
2035 CP_COND_REG_EXEC_0_SYSMEM
|
2036 CP_COND_REG_EXEC_0_BINNING
);
2038 /* TODO: only flush buffers that need to be flushed */
2039 for (uint32_t i
= 0; i
< IR3_MAX_SO_BUFFERS
; i
++) {
2040 /* note: FLUSH_BASE is always the same, so it could go in init_hw()? */
2041 tu_cs_emit_pkt4(cs
, REG_A6XX_VPC_SO_FLUSH_BASE(i
), 2);
2042 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(flush_base
[i
]));
2043 tu6_emit_event_write(cmd
, cs
, FLUSH_SO_0
+ i
);
2046 for (uint32_t i
= 0; i
< counterBufferCount
; i
++) {
2047 uint32_t idx
= firstCounterBuffer
+ i
;
2048 uint32_t offset
= cmd
->state
.streamout_offset
[idx
];
2050 if (!pCounterBuffers
[i
])
2053 TU_FROM_HANDLE(tu_buffer
, buf
, pCounterBuffers
[i
]);
2055 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_WRITE
);
2057 /* VPC_SO_FLUSH_BASE has dwords counter, but counter should be in bytes */
2058 tu_cs_emit_pkt7(cs
, CP_MEM_TO_REG
, 3);
2059 tu_cs_emit(cs
, CP_MEM_TO_REG_0_REG(REG_A6XX_CP_SCRATCH_REG(0)) |
2060 CP_MEM_TO_REG_0_SHIFT_BY_2
|
2062 CP_MEM_TO_REG_0_UNK31
|
2063 CP_MEM_TO_REG_0_CNT(1));
2064 tu_cs_emit_qw(cs
, cmd
->scratch_bo
.iova
+ ctrl_offset(flush_base
[idx
]));
2067 tu_cs_emit_pkt7(cs
, CP_REG_RMW
, 3);
2068 tu_cs_emit(cs
, CP_REG_RMW_0_DST_REG(REG_A6XX_CP_SCRATCH_REG(0)) |
2069 CP_REG_RMW_0_SRC1_ADD
);
2070 tu_cs_emit_qw(cs
, 0xffffffff);
2071 tu_cs_emit_qw(cs
, -offset
);
2074 tu_cs_emit_pkt7(cs
, CP_REG_TO_MEM
, 3);
2075 tu_cs_emit(cs
, CP_REG_TO_MEM_0_REG(REG_A6XX_CP_SCRATCH_REG(0)) |
2076 CP_REG_TO_MEM_0_CNT(1));
2077 tu_cs_emit_qw(cs
, buf
->bo
->iova
+ pCounterBufferOffsets
[i
]);
2080 tu_cond_exec_end(cs
);
2082 cmd
->state
.xfb_used
= true;
2086 tu_CmdPushConstants(VkCommandBuffer commandBuffer
,
2087 VkPipelineLayout layout
,
2088 VkShaderStageFlags stageFlags
,
2091 const void *pValues
)
2093 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2094 memcpy((void*) cmd
->push_constants
+ offset
, pValues
, size
);
2095 cmd
->state
.dirty
|= TU_CMD_DIRTY_SHADER_CONSTS
;
2098 /* Flush everything which has been made available but we haven't actually
2102 tu_flush_all_pending(struct tu_cache_state
*cache
)
2104 cache
->flush_bits
|= cache
->pending_flush_bits
& TU_CMD_FLAG_ALL_FLUSH
;
2105 cache
->pending_flush_bits
&= ~TU_CMD_FLAG_ALL_FLUSH
;
2109 tu_EndCommandBuffer(VkCommandBuffer commandBuffer
)
2111 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
2113 /* We currently flush CCU at the end of the command buffer, like
2114 * what the blob does. There's implicit synchronization around every
2115 * vkQueueSubmit, but the kernel only flushes the UCHE, and we don't
2116 * know yet if this command buffer will be the last in the submit so we
2117 * have to defensively flush everything else.
2119 * TODO: We could definitely do better than this, since these flushes
2120 * aren't required by Vulkan, but we'd need kernel support to do that.
2121 * Ideally, we'd like the kernel to flush everything afterwards, so that we
2122 * wouldn't have to do any flushes here, and when submitting multiple
2123 * command buffers there wouldn't be any unnecessary flushes in between.
2125 if (cmd_buffer
->state
.pass
) {
2126 tu_flush_all_pending(&cmd_buffer
->state
.renderpass_cache
);
2127 tu_emit_cache_flush_renderpass(cmd_buffer
, &cmd_buffer
->draw_cs
);
2129 tu_flush_all_pending(&cmd_buffer
->state
.cache
);
2130 cmd_buffer
->state
.cache
.flush_bits
|=
2131 TU_CMD_FLAG_CCU_FLUSH_COLOR
|
2132 TU_CMD_FLAG_CCU_FLUSH_DEPTH
;
2133 tu_emit_cache_flush(cmd_buffer
, &cmd_buffer
->cs
);
2136 tu_bo_list_add(&cmd_buffer
->bo_list
, &cmd_buffer
->scratch_bo
,
2137 MSM_SUBMIT_BO_WRITE
);
2139 if (cmd_buffer
->use_vsc_data
) {
2140 tu_bo_list_add(&cmd_buffer
->bo_list
, &cmd_buffer
->vsc_draw_strm
,
2141 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
2142 tu_bo_list_add(&cmd_buffer
->bo_list
, &cmd_buffer
->vsc_prim_strm
,
2143 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
2146 tu_bo_list_add(&cmd_buffer
->bo_list
, &cmd_buffer
->device
->border_color
,
2147 MSM_SUBMIT_BO_READ
);
2149 for (uint32_t i
= 0; i
< cmd_buffer
->draw_cs
.bo_count
; i
++) {
2150 tu_bo_list_add(&cmd_buffer
->bo_list
, cmd_buffer
->draw_cs
.bos
[i
],
2151 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
2154 for (uint32_t i
= 0; i
< cmd_buffer
->draw_epilogue_cs
.bo_count
; i
++) {
2155 tu_bo_list_add(&cmd_buffer
->bo_list
, cmd_buffer
->draw_epilogue_cs
.bos
[i
],
2156 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
2159 for (uint32_t i
= 0; i
< cmd_buffer
->sub_cs
.bo_count
; i
++) {
2160 tu_bo_list_add(&cmd_buffer
->bo_list
, cmd_buffer
->sub_cs
.bos
[i
],
2161 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
2164 tu_cs_end(&cmd_buffer
->cs
);
2165 tu_cs_end(&cmd_buffer
->draw_cs
);
2166 tu_cs_end(&cmd_buffer
->draw_epilogue_cs
);
2168 cmd_buffer
->status
= TU_CMD_BUFFER_STATUS_EXECUTABLE
;
2170 return cmd_buffer
->record_result
;
2174 tu_cmd_dynamic_state(struct tu_cmd_buffer
*cmd
, uint32_t id
, uint32_t size
)
2176 struct tu_cs_memory memory
;
2179 /* TODO: share this logic with tu_pipeline_static_state */
2180 tu_cs_alloc(&cmd
->sub_cs
, size
, 1, &memory
);
2181 tu_cs_init_external(&cs
, memory
.map
, memory
.map
+ size
);
2183 tu_cs_reserve_space(&cs
, size
);
2185 assert(id
< ARRAY_SIZE(cmd
->state
.dynamic_state
));
2186 cmd
->state
.dynamic_state
[id
].iova
= memory
.iova
;
2187 cmd
->state
.dynamic_state
[id
].size
= size
;
2189 tu_cs_emit_pkt7(&cmd
->draw_cs
, CP_SET_DRAW_STATE
, 3);
2190 tu_cs_emit_draw_state(&cmd
->draw_cs
, TU_DRAW_STATE_DYNAMIC
+ id
, cmd
->state
.dynamic_state
[id
]);
2196 tu_CmdBindPipeline(VkCommandBuffer commandBuffer
,
2197 VkPipelineBindPoint pipelineBindPoint
,
2198 VkPipeline _pipeline
)
2200 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2201 TU_FROM_HANDLE(tu_pipeline
, pipeline
, _pipeline
);
2203 for (uint32_t i
= 0; i
< pipeline
->cs
.bo_count
; i
++) {
2204 tu_bo_list_add(&cmd
->bo_list
, pipeline
->cs
.bos
[i
],
2205 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
2208 if (pipelineBindPoint
== VK_PIPELINE_BIND_POINT_COMPUTE
) {
2209 cmd
->state
.compute_pipeline
= pipeline
;
2210 cmd
->state
.dirty
|= TU_CMD_DIRTY_COMPUTE_PIPELINE
;
2214 assert(pipelineBindPoint
== VK_PIPELINE_BIND_POINT_GRAPHICS
);
2216 cmd
->state
.pipeline
= pipeline
;
2217 cmd
->state
.dirty
|= TU_CMD_DIRTY_SHADER_CONSTS
;
2219 struct tu_cs
*cs
= &cmd
->draw_cs
;
2220 uint32_t mask
= ~pipeline
->dynamic_state_mask
& BITFIELD_MASK(TU_DYNAMIC_STATE_COUNT
);
2223 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 3 * (7 + util_bitcount(mask
)));
2224 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_PROGRAM
, pipeline
->program
.state_ib
);
2225 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_PROGRAM_BINNING
, pipeline
->program
.binning_state_ib
);
2226 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_VI
, pipeline
->vi
.state_ib
);
2227 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_VI_BINNING
, pipeline
->vi
.binning_state_ib
);
2228 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_RAST
, pipeline
->rast
.state_ib
);
2229 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_DS
, pipeline
->ds
.state_ib
);
2230 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_BLEND
, pipeline
->blend
.state_ib
);
2232 for_each_bit(i
, mask
)
2233 tu_cs_emit_draw_state(cs
, TU_DRAW_STATE_DYNAMIC
+ i
, pipeline
->dynamic_state
[i
]);
2235 /* If the new pipeline requires more VBs than we had previously set up, we
2236 * need to re-emit them in SDS. If it requires the same set or fewer, we
2237 * can just re-use the old SDS.
2239 if (pipeline
->vi
.bindings_used
& ~cmd
->vertex_bindings_set
)
2240 cmd
->state
.dirty
|= TU_CMD_DIRTY_VERTEX_BUFFERS
;
2242 /* If the pipeline needs a dynamic descriptor, re-emit descriptor sets */
2243 if (pipeline
->layout
->dynamic_offset_count
)
2244 cmd
->state
.dirty
|= TU_CMD_DIRTY_DESCRIPTOR_SETS
;
2246 /* dynamic linewidth state depends pipeline state's gras_su_cntl
2247 * so the dynamic state ib must be updated when pipeline changes
2249 if (pipeline
->dynamic_state_mask
& BIT(VK_DYNAMIC_STATE_LINE_WIDTH
)) {
2250 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_LINE_WIDTH
, 2);
2252 cmd
->state
.dynamic_gras_su_cntl
&= A6XX_GRAS_SU_CNTL_LINEHALFWIDTH__MASK
;
2253 cmd
->state
.dynamic_gras_su_cntl
|= pipeline
->gras_su_cntl
;
2255 tu_cs_emit_regs(&cs
, A6XX_GRAS_SU_CNTL(.dword
= cmd
->state
.dynamic_gras_su_cntl
));
2260 tu_CmdSetViewport(VkCommandBuffer commandBuffer
,
2261 uint32_t firstViewport
,
2262 uint32_t viewportCount
,
2263 const VkViewport
*pViewports
)
2265 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2266 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_VIEWPORT
, 18);
2268 assert(firstViewport
== 0 && viewportCount
== 1);
2270 tu6_emit_viewport(&cs
, pViewports
);
2274 tu_CmdSetScissor(VkCommandBuffer commandBuffer
,
2275 uint32_t firstScissor
,
2276 uint32_t scissorCount
,
2277 const VkRect2D
*pScissors
)
2279 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2280 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_SCISSOR
, 3);
2282 assert(firstScissor
== 0 && scissorCount
== 1);
2284 tu6_emit_scissor(&cs
, pScissors
);
2288 tu_CmdSetLineWidth(VkCommandBuffer commandBuffer
, float lineWidth
)
2290 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2291 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_LINE_WIDTH
, 2);
2293 cmd
->state
.dynamic_gras_su_cntl
&= ~A6XX_GRAS_SU_CNTL_LINEHALFWIDTH__MASK
;
2294 cmd
->state
.dynamic_gras_su_cntl
|= A6XX_GRAS_SU_CNTL_LINEHALFWIDTH(lineWidth
/ 2.0f
);
2296 tu_cs_emit_regs(&cs
, A6XX_GRAS_SU_CNTL(.dword
= cmd
->state
.dynamic_gras_su_cntl
));
2300 tu_CmdSetDepthBias(VkCommandBuffer commandBuffer
,
2301 float depthBiasConstantFactor
,
2302 float depthBiasClamp
,
2303 float depthBiasSlopeFactor
)
2305 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2306 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_DEPTH_BIAS
, 4);
2308 tu6_emit_depth_bias(&cs
, depthBiasConstantFactor
, depthBiasClamp
, depthBiasSlopeFactor
);
2312 tu_CmdSetBlendConstants(VkCommandBuffer commandBuffer
,
2313 const float blendConstants
[4])
2315 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2316 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_BLEND_CONSTANTS
, 5);
2318 tu_cs_emit_pkt4(&cs
, REG_A6XX_RB_BLEND_RED_F32
, 4);
2319 tu_cs_emit_array(&cs
, (const uint32_t *) blendConstants
, 4);
2323 tu_CmdSetDepthBounds(VkCommandBuffer commandBuffer
,
2324 float minDepthBounds
,
2325 float maxDepthBounds
)
2327 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2328 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_DEPTH_BOUNDS
, 3);
2330 tu_cs_emit_regs(&cs
,
2331 A6XX_RB_Z_BOUNDS_MIN(minDepthBounds
),
2332 A6XX_RB_Z_BOUNDS_MAX(maxDepthBounds
));
2336 update_stencil_mask(uint32_t *value
, VkStencilFaceFlags face
, uint32_t mask
)
2338 if (face
& VK_STENCIL_FACE_FRONT_BIT
)
2339 *value
|= A6XX_RB_STENCILMASK_MASK(mask
);
2340 if (face
& VK_STENCIL_FACE_BACK_BIT
)
2341 *value
|= A6XX_RB_STENCILMASK_BFMASK(mask
);
2345 tu_CmdSetStencilCompareMask(VkCommandBuffer commandBuffer
,
2346 VkStencilFaceFlags faceMask
,
2347 uint32_t compareMask
)
2349 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2350 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
, 2);
2352 update_stencil_mask(&cmd
->state
.dynamic_stencil_mask
, faceMask
, compareMask
);
2354 tu_cs_emit_regs(&cs
, A6XX_RB_STENCILMASK(.dword
= cmd
->state
.dynamic_stencil_mask
));
2358 tu_CmdSetStencilWriteMask(VkCommandBuffer commandBuffer
,
2359 VkStencilFaceFlags faceMask
,
2362 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2363 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_STENCIL_WRITE_MASK
, 2);
2365 update_stencil_mask(&cmd
->state
.dynamic_stencil_wrmask
, faceMask
, writeMask
);
2367 tu_cs_emit_regs(&cs
, A6XX_RB_STENCILWRMASK(.dword
= cmd
->state
.dynamic_stencil_wrmask
));
2371 tu_CmdSetStencilReference(VkCommandBuffer commandBuffer
,
2372 VkStencilFaceFlags faceMask
,
2375 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2376 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, VK_DYNAMIC_STATE_STENCIL_REFERENCE
, 2);
2378 update_stencil_mask(&cmd
->state
.dynamic_stencil_ref
, faceMask
, reference
);
2380 tu_cs_emit_regs(&cs
, A6XX_RB_STENCILREF(.dword
= cmd
->state
.dynamic_stencil_ref
));
2384 tu_CmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer
,
2385 const VkSampleLocationsInfoEXT
* pSampleLocationsInfo
)
2387 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2388 struct tu_cs cs
= tu_cmd_dynamic_state(cmd
, TU_DYNAMIC_STATE_SAMPLE_LOCATIONS
, 9);
2390 assert(pSampleLocationsInfo
);
2392 tu6_emit_sample_locations(&cs
, pSampleLocationsInfo
);
2396 tu_flush_for_access(struct tu_cache_state
*cache
,
2397 enum tu_cmd_access_mask src_mask
,
2398 enum tu_cmd_access_mask dst_mask
)
2400 enum tu_cmd_flush_bits flush_bits
= 0;
2402 if (src_mask
& TU_ACCESS_SYSMEM_WRITE
) {
2403 cache
->pending_flush_bits
|= TU_CMD_FLAG_ALL_INVALIDATE
;
2406 #define SRC_FLUSH(domain, flush, invalidate) \
2407 if (src_mask & TU_ACCESS_##domain##_WRITE) { \
2408 cache->pending_flush_bits |= TU_CMD_FLAG_##flush | \
2409 (TU_CMD_FLAG_ALL_INVALIDATE & ~TU_CMD_FLAG_##invalidate); \
2412 SRC_FLUSH(UCHE
, CACHE_FLUSH
, CACHE_INVALIDATE
)
2413 SRC_FLUSH(CCU_COLOR
, CCU_FLUSH_COLOR
, CCU_INVALIDATE_COLOR
)
2414 SRC_FLUSH(CCU_DEPTH
, CCU_FLUSH_DEPTH
, CCU_INVALIDATE_DEPTH
)
2418 #define SRC_INCOHERENT_FLUSH(domain, flush, invalidate) \
2419 if (src_mask & TU_ACCESS_##domain##_INCOHERENT_WRITE) { \
2420 flush_bits |= TU_CMD_FLAG_##flush; \
2421 cache->pending_flush_bits |= \
2422 (TU_CMD_FLAG_ALL_INVALIDATE & ~TU_CMD_FLAG_##invalidate); \
2425 SRC_INCOHERENT_FLUSH(CCU_COLOR
, CCU_FLUSH_COLOR
, CCU_INVALIDATE_COLOR
)
2426 SRC_INCOHERENT_FLUSH(CCU_DEPTH
, CCU_FLUSH_DEPTH
, CCU_INVALIDATE_DEPTH
)
2428 #undef SRC_INCOHERENT_FLUSH
2430 if (dst_mask
& (TU_ACCESS_SYSMEM_READ
| TU_ACCESS_SYSMEM_WRITE
)) {
2431 flush_bits
|= cache
->pending_flush_bits
& TU_CMD_FLAG_ALL_FLUSH
;
2434 #define DST_FLUSH(domain, flush, invalidate) \
2435 if (dst_mask & (TU_ACCESS_##domain##_READ | \
2436 TU_ACCESS_##domain##_WRITE)) { \
2437 flush_bits |= cache->pending_flush_bits & \
2438 (TU_CMD_FLAG_##invalidate | \
2439 (TU_CMD_FLAG_ALL_FLUSH & ~TU_CMD_FLAG_##flush)); \
2442 DST_FLUSH(UCHE
, CACHE_FLUSH
, CACHE_INVALIDATE
)
2443 DST_FLUSH(CCU_COLOR
, CCU_FLUSH_COLOR
, CCU_INVALIDATE_COLOR
)
2444 DST_FLUSH(CCU_DEPTH
, CCU_FLUSH_DEPTH
, CCU_INVALIDATE_DEPTH
)
2448 #define DST_INCOHERENT_FLUSH(domain, flush, invalidate) \
2449 if (dst_mask & (TU_ACCESS_##domain##_READ | \
2450 TU_ACCESS_##domain##_WRITE)) { \
2451 flush_bits |= TU_CMD_FLAG_##invalidate | \
2452 (cache->pending_flush_bits & \
2453 (TU_CMD_FLAG_ALL_FLUSH & ~TU_CMD_FLAG_##flush)); \
2456 DST_INCOHERENT_FLUSH(CCU_COLOR
, CCU_FLUSH_COLOR
, CCU_INVALIDATE_COLOR
)
2457 DST_INCOHERENT_FLUSH(CCU_DEPTH
, CCU_FLUSH_DEPTH
, CCU_INVALIDATE_DEPTH
)
2459 #undef DST_INCOHERENT_FLUSH
2461 if (dst_mask
& TU_ACCESS_WFI_READ
) {
2462 flush_bits
|= TU_CMD_FLAG_WFI
;
2465 cache
->flush_bits
|= flush_bits
;
2466 cache
->pending_flush_bits
&= ~flush_bits
;
2469 static enum tu_cmd_access_mask
2470 vk2tu_access(VkAccessFlags flags
, bool gmem
)
2472 enum tu_cmd_access_mask mask
= 0;
2474 /* If the GPU writes a buffer that is then read by an indirect draw
2475 * command, we theoretically need a WFI + WAIT_FOR_ME combination to
2476 * wait for the writes to complete. The WAIT_FOR_ME is performed as part
2477 * of the draw by the firmware, so we just need to execute a WFI.
2480 (VK_ACCESS_INDIRECT_COMMAND_READ_BIT
|
2481 VK_ACCESS_MEMORY_READ_BIT
)) {
2482 mask
|= TU_ACCESS_WFI_READ
;
2486 (VK_ACCESS_INDIRECT_COMMAND_READ_BIT
| /* Read performed by CP */
2487 VK_ACCESS_TRANSFORM_FEEDBACK_COUNTER_READ_BIT_EXT
| /* Read performed by CP, I think */
2488 VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT
| /* Read performed by CP */
2489 VK_ACCESS_HOST_READ_BIT
| /* sysmem by definition */
2490 VK_ACCESS_MEMORY_READ_BIT
)) {
2491 mask
|= TU_ACCESS_SYSMEM_READ
;
2495 (VK_ACCESS_HOST_WRITE_BIT
|
2496 VK_ACCESS_TRANSFORM_FEEDBACK_COUNTER_WRITE_BIT_EXT
| /* Write performed by CP, I think */
2497 VK_ACCESS_MEMORY_WRITE_BIT
)) {
2498 mask
|= TU_ACCESS_SYSMEM_WRITE
;
2502 (VK_ACCESS_INDEX_READ_BIT
| /* Read performed by PC, I think */
2503 VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT
| /* Read performed by VFD */
2504 VK_ACCESS_UNIFORM_READ_BIT
| /* Read performed by SP */
2505 /* TODO: Is there a no-cache bit for textures so that we can ignore
2508 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT
| /* Read performed by TP */
2509 VK_ACCESS_SHADER_READ_BIT
| /* Read perfomed by SP/TP */
2510 VK_ACCESS_MEMORY_READ_BIT
)) {
2511 mask
|= TU_ACCESS_UCHE_READ
;
2515 (VK_ACCESS_SHADER_WRITE_BIT
| /* Write performed by SP */
2516 VK_ACCESS_TRANSFORM_FEEDBACK_WRITE_BIT_EXT
| /* Write performed by VPC */
2517 VK_ACCESS_MEMORY_WRITE_BIT
)) {
2518 mask
|= TU_ACCESS_UCHE_WRITE
;
2521 /* When using GMEM, the CCU is always flushed automatically to GMEM, and
2522 * then GMEM is flushed to sysmem. Furthermore, we already had to flush any
2523 * previous writes in sysmem mode when transitioning to GMEM. Therefore we
2524 * can ignore CCU and pretend that color attachments and transfers use
2529 (VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
|
2530 VK_ACCESS_COLOR_ATTACHMENT_READ_NONCOHERENT_BIT_EXT
|
2531 VK_ACCESS_MEMORY_READ_BIT
)) {
2533 mask
|= TU_ACCESS_SYSMEM_READ
;
2535 mask
|= TU_ACCESS_CCU_COLOR_INCOHERENT_READ
;
2539 (VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT
|
2540 VK_ACCESS_MEMORY_READ_BIT
)) {
2542 mask
|= TU_ACCESS_SYSMEM_READ
;
2544 mask
|= TU_ACCESS_CCU_DEPTH_INCOHERENT_READ
;
2548 (VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
|
2549 VK_ACCESS_MEMORY_WRITE_BIT
)) {
2551 mask
|= TU_ACCESS_SYSMEM_WRITE
;
2553 mask
|= TU_ACCESS_CCU_COLOR_INCOHERENT_WRITE
;
2558 (VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
|
2559 VK_ACCESS_MEMORY_WRITE_BIT
)) {
2561 mask
|= TU_ACCESS_SYSMEM_WRITE
;
2563 mask
|= TU_ACCESS_CCU_DEPTH_INCOHERENT_WRITE
;
2567 /* When the dst access is a transfer read/write, it seems we sometimes need
2568 * to insert a WFI after any flushes, to guarantee that the flushes finish
2569 * before the 2D engine starts. However the opposite (i.e. a WFI after
2570 * CP_BLIT and before any subsequent flush) does not seem to be needed, and
2571 * the blob doesn't emit such a WFI.
2575 (VK_ACCESS_TRANSFER_WRITE_BIT
|
2576 VK_ACCESS_MEMORY_WRITE_BIT
)) {
2578 mask
|= TU_ACCESS_SYSMEM_WRITE
;
2580 mask
|= TU_ACCESS_CCU_COLOR_WRITE
;
2582 mask
|= TU_ACCESS_WFI_READ
;
2586 (VK_ACCESS_TRANSFER_READ_BIT
| /* Access performed by TP */
2587 VK_ACCESS_MEMORY_READ_BIT
)) {
2588 mask
|= TU_ACCESS_UCHE_READ
| TU_ACCESS_WFI_READ
;
2596 tu_CmdExecuteCommands(VkCommandBuffer commandBuffer
,
2597 uint32_t commandBufferCount
,
2598 const VkCommandBuffer
*pCmdBuffers
)
2600 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2603 assert(commandBufferCount
> 0);
2605 /* Emit any pending flushes. */
2606 if (cmd
->state
.pass
) {
2607 tu_flush_all_pending(&cmd
->state
.renderpass_cache
);
2608 tu_emit_cache_flush_renderpass(cmd
, &cmd
->draw_cs
);
2610 tu_flush_all_pending(&cmd
->state
.cache
);
2611 tu_emit_cache_flush(cmd
, &cmd
->cs
);
2614 for (uint32_t i
= 0; i
< commandBufferCount
; i
++) {
2615 TU_FROM_HANDLE(tu_cmd_buffer
, secondary
, pCmdBuffers
[i
]);
2617 result
= tu_bo_list_merge(&cmd
->bo_list
, &secondary
->bo_list
);
2618 if (result
!= VK_SUCCESS
) {
2619 cmd
->record_result
= result
;
2623 if (secondary
->usage_flags
&
2624 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
) {
2625 assert(tu_cs_is_empty(&secondary
->cs
));
2627 result
= tu_cs_add_entries(&cmd
->draw_cs
, &secondary
->draw_cs
);
2628 if (result
!= VK_SUCCESS
) {
2629 cmd
->record_result
= result
;
2633 result
= tu_cs_add_entries(&cmd
->draw_epilogue_cs
,
2634 &secondary
->draw_epilogue_cs
);
2635 if (result
!= VK_SUCCESS
) {
2636 cmd
->record_result
= result
;
2640 if (secondary
->has_tess
)
2641 cmd
->has_tess
= true;
2643 assert(tu_cs_is_empty(&secondary
->draw_cs
));
2644 assert(tu_cs_is_empty(&secondary
->draw_epilogue_cs
));
2646 for (uint32_t j
= 0; j
< secondary
->cs
.bo_count
; j
++) {
2647 tu_bo_list_add(&cmd
->bo_list
, secondary
->cs
.bos
[j
],
2648 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_DUMP
);
2651 tu_cs_add_entries(&cmd
->cs
, &secondary
->cs
);
2654 cmd
->state
.index_size
= secondary
->state
.index_size
; /* for restart index update */
2656 cmd
->state
.dirty
= ~0u; /* TODO: set dirty only what needs to be */
2658 /* After executing secondary command buffers, there may have been arbitrary
2659 * flushes executed, so when we encounter a pipeline barrier with a
2660 * srcMask, we have to assume that we need to invalidate. Therefore we need
2661 * to re-initialize the cache with all pending invalidate bits set.
2663 if (cmd
->state
.pass
) {
2664 tu_cache_init(&cmd
->state
.renderpass_cache
);
2666 tu_cache_init(&cmd
->state
.cache
);
2671 tu_CreateCommandPool(VkDevice _device
,
2672 const VkCommandPoolCreateInfo
*pCreateInfo
,
2673 const VkAllocationCallbacks
*pAllocator
,
2674 VkCommandPool
*pCmdPool
)
2676 TU_FROM_HANDLE(tu_device
, device
, _device
);
2677 struct tu_cmd_pool
*pool
;
2679 pool
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*pool
), 8,
2680 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2682 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2685 pool
->alloc
= *pAllocator
;
2687 pool
->alloc
= device
->alloc
;
2689 list_inithead(&pool
->cmd_buffers
);
2690 list_inithead(&pool
->free_cmd_buffers
);
2692 pool
->queue_family_index
= pCreateInfo
->queueFamilyIndex
;
2694 *pCmdPool
= tu_cmd_pool_to_handle(pool
);
2700 tu_DestroyCommandPool(VkDevice _device
,
2701 VkCommandPool commandPool
,
2702 const VkAllocationCallbacks
*pAllocator
)
2704 TU_FROM_HANDLE(tu_device
, device
, _device
);
2705 TU_FROM_HANDLE(tu_cmd_pool
, pool
, commandPool
);
2710 list_for_each_entry_safe(struct tu_cmd_buffer
, cmd_buffer
,
2711 &pool
->cmd_buffers
, pool_link
)
2713 tu_cmd_buffer_destroy(cmd_buffer
);
2716 list_for_each_entry_safe(struct tu_cmd_buffer
, cmd_buffer
,
2717 &pool
->free_cmd_buffers
, pool_link
)
2719 tu_cmd_buffer_destroy(cmd_buffer
);
2722 vk_free2(&device
->alloc
, pAllocator
, pool
);
2726 tu_ResetCommandPool(VkDevice device
,
2727 VkCommandPool commandPool
,
2728 VkCommandPoolResetFlags flags
)
2730 TU_FROM_HANDLE(tu_cmd_pool
, pool
, commandPool
);
2733 list_for_each_entry(struct tu_cmd_buffer
, cmd_buffer
, &pool
->cmd_buffers
,
2736 result
= tu_reset_cmd_buffer(cmd_buffer
);
2737 if (result
!= VK_SUCCESS
)
2745 tu_TrimCommandPool(VkDevice device
,
2746 VkCommandPool commandPool
,
2747 VkCommandPoolTrimFlags flags
)
2749 TU_FROM_HANDLE(tu_cmd_pool
, pool
, commandPool
);
2754 list_for_each_entry_safe(struct tu_cmd_buffer
, cmd_buffer
,
2755 &pool
->free_cmd_buffers
, pool_link
)
2757 tu_cmd_buffer_destroy(cmd_buffer
);
2762 tu_subpass_barrier(struct tu_cmd_buffer
*cmd_buffer
,
2763 const struct tu_subpass_barrier
*barrier
,
2766 /* Note: we don't know until the end of the subpass whether we'll use
2767 * sysmem, so assume sysmem here to be safe.
2769 struct tu_cache_state
*cache
=
2770 external
? &cmd_buffer
->state
.cache
: &cmd_buffer
->state
.renderpass_cache
;
2771 enum tu_cmd_access_mask src_flags
=
2772 vk2tu_access(barrier
->src_access_mask
, false);
2773 enum tu_cmd_access_mask dst_flags
=
2774 vk2tu_access(barrier
->dst_access_mask
, false);
2776 if (barrier
->incoherent_ccu_color
)
2777 src_flags
|= TU_ACCESS_CCU_COLOR_INCOHERENT_WRITE
;
2778 if (barrier
->incoherent_ccu_depth
)
2779 src_flags
|= TU_ACCESS_CCU_DEPTH_INCOHERENT_WRITE
;
2781 tu_flush_for_access(cache
, src_flags
, dst_flags
);
2785 tu_CmdBeginRenderPass(VkCommandBuffer commandBuffer
,
2786 const VkRenderPassBeginInfo
*pRenderPassBegin
,
2787 VkSubpassContents contents
)
2789 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2790 TU_FROM_HANDLE(tu_render_pass
, pass
, pRenderPassBegin
->renderPass
);
2791 TU_FROM_HANDLE(tu_framebuffer
, fb
, pRenderPassBegin
->framebuffer
);
2793 cmd
->state
.pass
= pass
;
2794 cmd
->state
.subpass
= pass
->subpasses
;
2795 cmd
->state
.framebuffer
= fb
;
2797 tu_cmd_update_tiling_config(cmd
, &pRenderPassBegin
->renderArea
);
2798 tu_cmd_prepare_tile_store_ib(cmd
);
2800 /* Note: because this is external, any flushes will happen before draw_cs
2801 * gets called. However deferred flushes could have to happen later as part
2804 tu_subpass_barrier(cmd
, &pass
->subpasses
[0].start_barrier
, true);
2805 cmd
->state
.renderpass_cache
.pending_flush_bits
=
2806 cmd
->state
.cache
.pending_flush_bits
;
2807 cmd
->state
.renderpass_cache
.flush_bits
= 0;
2809 tu_emit_renderpass_begin(cmd
, pRenderPassBegin
);
2811 tu6_emit_zs(cmd
, cmd
->state
.subpass
, &cmd
->draw_cs
);
2812 tu6_emit_mrt(cmd
, cmd
->state
.subpass
, &cmd
->draw_cs
);
2813 tu6_emit_msaa(&cmd
->draw_cs
, cmd
->state
.subpass
->samples
);
2814 tu6_emit_render_cntl(cmd
, cmd
->state
.subpass
, &cmd
->draw_cs
, false);
2816 tu_set_input_attachments(cmd
, cmd
->state
.subpass
);
2818 for (uint32_t i
= 0; i
< fb
->attachment_count
; ++i
) {
2819 const struct tu_image_view
*iview
= fb
->attachments
[i
].attachment
;
2820 tu_bo_list_add(&cmd
->bo_list
, iview
->image
->bo
,
2821 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
2824 cmd
->state
.dirty
|= TU_CMD_DIRTY_DRAW_STATE
;
2828 tu_CmdBeginRenderPass2(VkCommandBuffer commandBuffer
,
2829 const VkRenderPassBeginInfo
*pRenderPassBeginInfo
,
2830 const VkSubpassBeginInfoKHR
*pSubpassBeginInfo
)
2832 tu_CmdBeginRenderPass(commandBuffer
, pRenderPassBeginInfo
,
2833 pSubpassBeginInfo
->contents
);
2837 tu_CmdNextSubpass(VkCommandBuffer commandBuffer
, VkSubpassContents contents
)
2839 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
2840 const struct tu_render_pass
*pass
= cmd
->state
.pass
;
2841 struct tu_cs
*cs
= &cmd
->draw_cs
;
2843 const struct tu_subpass
*subpass
= cmd
->state
.subpass
++;
2845 tu_cond_exec_start(cs
, CP_COND_EXEC_0_RENDER_MODE_GMEM
);
2847 if (subpass
->resolve_attachments
) {
2848 tu6_emit_blit_scissor(cmd
, cs
, true);
2850 for (unsigned i
= 0; i
< subpass
->color_count
; i
++) {
2851 uint32_t a
= subpass
->resolve_attachments
[i
].attachment
;
2852 if (a
== VK_ATTACHMENT_UNUSED
)
2855 tu_store_gmem_attachment(cmd
, cs
, a
,
2856 subpass
->color_attachments
[i
].attachment
);
2858 if (pass
->attachments
[a
].gmem_offset
< 0)
2862 * check if the resolved attachment is needed by later subpasses,
2863 * if it is, should be doing a GMEM->GMEM resolve instead of GMEM->MEM->GMEM..
2865 tu_finishme("missing GMEM->GMEM resolve path\n");
2866 tu_load_gmem_attachment(cmd
, cs
, a
, true);
2870 tu_cond_exec_end(cs
);
2872 tu_cond_exec_start(cs
, CP_COND_EXEC_0_RENDER_MODE_SYSMEM
);
2874 tu6_emit_sysmem_resolves(cmd
, cs
, subpass
);
2876 tu_cond_exec_end(cs
);
2878 /* Handle dependencies for the next subpass */
2879 tu_subpass_barrier(cmd
, &cmd
->state
.subpass
->start_barrier
, false);
2881 /* emit mrt/zs/msaa/ubwc state for the subpass that is starting */
2882 tu6_emit_zs(cmd
, cmd
->state
.subpass
, cs
);
2883 tu6_emit_mrt(cmd
, cmd
->state
.subpass
, cs
);
2884 tu6_emit_msaa(cs
, cmd
->state
.subpass
->samples
);
2885 tu6_emit_render_cntl(cmd
, cmd
->state
.subpass
, cs
, false);
2887 tu_set_input_attachments(cmd
, cmd
->state
.subpass
);
2891 tu_CmdNextSubpass2(VkCommandBuffer commandBuffer
,
2892 const VkSubpassBeginInfoKHR
*pSubpassBeginInfo
,
2893 const VkSubpassEndInfoKHR
*pSubpassEndInfo
)
2895 tu_CmdNextSubpass(commandBuffer
, pSubpassBeginInfo
->contents
);
2899 tu6_emit_user_consts(struct tu_cs
*cs
, const struct tu_pipeline
*pipeline
,
2900 struct tu_descriptor_state
*descriptors_state
,
2901 gl_shader_stage type
,
2902 uint32_t *push_constants
)
2904 const struct tu_program_descriptor_linkage
*link
=
2905 &pipeline
->program
.link
[type
];
2906 const struct ir3_ubo_analysis_state
*state
= &link
->const_state
.ubo_state
;
2908 if (link
->push_consts
.count
> 0) {
2909 unsigned num_units
= link
->push_consts
.count
;
2910 unsigned offset
= link
->push_consts
.lo
;
2911 tu_cs_emit_pkt7(cs
, tu6_stage2opcode(type
), 3 + num_units
* 4);
2912 tu_cs_emit(cs
, CP_LOAD_STATE6_0_DST_OFF(offset
) |
2913 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
2914 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
2915 CP_LOAD_STATE6_0_STATE_BLOCK(tu6_stage2shadersb(type
)) |
2916 CP_LOAD_STATE6_0_NUM_UNIT(num_units
));
2919 for (unsigned i
= 0; i
< num_units
* 4; i
++)
2920 tu_cs_emit(cs
, push_constants
[i
+ offset
* 4]);
2923 for (uint32_t i
= 0; i
< state
->num_enabled
; i
++) {
2924 uint32_t size
= state
->range
[i
].end
- state
->range
[i
].start
;
2925 uint32_t offset
= state
->range
[i
].start
;
2927 /* and even if the start of the const buffer is before
2928 * first_immediate, the end may not be:
2930 size
= MIN2(size
, (16 * link
->constlen
) - state
->range
[i
].offset
);
2935 /* things should be aligned to vec4: */
2936 debug_assert((state
->range
[i
].offset
% 16) == 0);
2937 debug_assert((size
% 16) == 0);
2938 debug_assert((offset
% 16) == 0);
2940 /* Dig out the descriptor from the descriptor state and read the VA from
2943 assert(state
->range
[i
].ubo
.bindless
);
2944 uint32_t *base
= state
->range
[i
].ubo
.bindless_base
== MAX_SETS
?
2945 descriptors_state
->dynamic_descriptors
:
2946 descriptors_state
->sets
[state
->range
[i
].ubo
.bindless_base
]->mapped_ptr
;
2947 unsigned block
= state
->range
[i
].ubo
.block
;
2948 uint32_t *desc
= base
+ block
* A6XX_TEX_CONST_DWORDS
;
2949 uint64_t va
= desc
[0] | ((uint64_t)(desc
[1] & A6XX_UBO_1_BASE_HI__MASK
) << 32);
2952 tu_cs_emit_pkt7(cs
, tu6_stage2opcode(type
), 3);
2953 tu_cs_emit(cs
, CP_LOAD_STATE6_0_DST_OFF(state
->range
[i
].offset
/ 16) |
2954 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
2955 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
2956 CP_LOAD_STATE6_0_STATE_BLOCK(tu6_stage2shadersb(type
)) |
2957 CP_LOAD_STATE6_0_NUM_UNIT(size
/ 16));
2958 tu_cs_emit_qw(cs
, va
+ offset
);
2962 static struct tu_cs_entry
2963 tu6_emit_consts(struct tu_cmd_buffer
*cmd
,
2964 const struct tu_pipeline
*pipeline
,
2965 struct tu_descriptor_state
*descriptors_state
,
2966 gl_shader_stage type
)
2969 tu_cs_begin_sub_stream(&cmd
->sub_cs
, 512, &cs
); /* TODO: maximum size? */
2971 tu6_emit_user_consts(&cs
, pipeline
, descriptors_state
, type
, cmd
->push_constants
);
2973 return tu_cs_end_sub_stream(&cmd
->sub_cs
, &cs
);
2977 tu6_emit_vs_params(struct tu_cmd_buffer
*cmd
,
2978 uint32_t first_instance
,
2979 struct tu_cs_entry
*entry
)
2981 /* TODO: fill out more than just base instance */
2982 const struct tu_program_descriptor_linkage
*link
=
2983 &cmd
->state
.pipeline
->program
.link
[MESA_SHADER_VERTEX
];
2984 const struct ir3_const_state
*const_state
= &link
->const_state
;
2987 if (const_state
->offsets
.driver_param
>= link
->constlen
) {
2988 *entry
= (struct tu_cs_entry
) {};
2992 VkResult result
= tu_cs_begin_sub_stream(&cmd
->sub_cs
, 8, &cs
);
2993 if (result
!= VK_SUCCESS
)
2996 tu_cs_emit_pkt7(&cs
, CP_LOAD_STATE6_GEOM
, 3 + 4);
2997 tu_cs_emit(&cs
, CP_LOAD_STATE6_0_DST_OFF(const_state
->offsets
.driver_param
) |
2998 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
2999 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
3000 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_VS_SHADER
) |
3001 CP_LOAD_STATE6_0_NUM_UNIT(1));
3005 STATIC_ASSERT(IR3_DP_INSTID_BASE
== 2);
3009 tu_cs_emit(&cs
, first_instance
);
3012 *entry
= tu_cs_end_sub_stream(&cmd
->sub_cs
, &cs
);
3016 static struct tu_cs_entry
3017 tu6_emit_vertex_buffers(struct tu_cmd_buffer
*cmd
,
3018 const struct tu_pipeline
*pipeline
)
3021 tu_cs_begin_sub_stream(&cmd
->sub_cs
, 4 * MAX_VBS
, &cs
);
3024 for_each_bit(binding
, pipeline
->vi
.bindings_used
) {
3025 const struct tu_buffer
*buf
= cmd
->state
.vb
.buffers
[binding
];
3026 const VkDeviceSize offset
= buf
->bo_offset
+
3027 cmd
->state
.vb
.offsets
[binding
];
3029 tu_cs_emit_regs(&cs
,
3030 A6XX_VFD_FETCH_BASE(binding
, .bo
= buf
->bo
, .bo_offset
= offset
),
3031 A6XX_VFD_FETCH_SIZE(binding
, buf
->size
- offset
));
3035 cmd
->vertex_bindings_set
= pipeline
->vi
.bindings_used
;
3037 return tu_cs_end_sub_stream(&cmd
->sub_cs
, &cs
);
3041 get_tess_param_bo_size(const struct tu_pipeline
*pipeline
,
3042 uint32_t draw_count
)
3044 /* TODO: For indirect draws, we can't compute the BO size ahead of time.
3045 * Still not sure what to do here, so just allocate a reasonably large
3046 * BO and hope for the best for now.
3047 * (maxTessellationControlPerVertexOutputComponents * 2048 vertices +
3048 * maxTessellationControlPerPatchOutputComponents * 512 patches) */
3050 return ((128 * 2048) + (128 * 512)) * 4;
3053 /* For each patch, adreno lays out the tess param BO in memory as:
3054 * (v_input[0][0])...(v_input[i][j])(p_input[0])...(p_input[k]).
3055 * where i = # vertices per patch, j = # per-vertex outputs, and
3056 * k = # per-patch outputs.*/
3057 uint32_t verts_per_patch
= pipeline
->ia
.primtype
- DI_PT_PATCHES0
;
3058 uint32_t num_patches
= draw_count
/ verts_per_patch
;
3059 return draw_count
* pipeline
->tess
.per_vertex_output_size
+
3060 pipeline
->tess
.per_patch_output_size
* num_patches
;
3064 get_tess_factor_bo_size(const struct tu_pipeline
*pipeline
,
3065 uint32_t draw_count
)
3067 /* TODO: For indirect draws, we can't compute the BO size ahead of time.
3068 * Still not sure what to do here, so just allocate a reasonably large
3069 * BO and hope for the best for now.
3070 * (quad factor stride * 512 patches) */
3072 return (28 * 512) * 4;
3075 /* Each distinct patch gets its own tess factor output. */
3076 uint32_t verts_per_patch
= pipeline
->ia
.primtype
- DI_PT_PATCHES0
;
3077 uint32_t num_patches
= draw_count
/ verts_per_patch
;
3078 uint32_t factor_stride
;
3079 switch (pipeline
->tess
.patch_type
) {
3080 case IR3_TESS_ISOLINES
:
3083 case IR3_TESS_TRIANGLES
:
3086 case IR3_TESS_QUADS
:
3090 unreachable("bad tessmode");
3092 return factor_stride
* num_patches
;
3096 tu6_emit_tess_consts(struct tu_cmd_buffer
*cmd
,
3097 uint32_t draw_count
,
3098 const struct tu_pipeline
*pipeline
,
3099 struct tu_cs_entry
*entry
)
3102 VkResult result
= tu_cs_begin_sub_stream(&cmd
->sub_cs
, 20, &cs
);
3103 if (result
!= VK_SUCCESS
)
3106 uint64_t tess_factor_size
= get_tess_factor_bo_size(pipeline
, draw_count
);
3107 uint64_t tess_param_size
= get_tess_param_bo_size(pipeline
, draw_count
);
3108 uint64_t tess_bo_size
= tess_factor_size
+ tess_param_size
;
3109 if (tess_bo_size
> 0) {
3110 struct tu_bo
*tess_bo
;
3111 result
= tu_get_scratch_bo(cmd
->device
, tess_bo_size
, &tess_bo
);
3112 if (result
!= VK_SUCCESS
)
3115 tu_bo_list_add(&cmd
->bo_list
, tess_bo
,
3116 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
3117 uint64_t tess_factor_iova
= tess_bo
->iova
;
3118 uint64_t tess_param_iova
= tess_factor_iova
+ tess_factor_size
;
3120 tu_cs_emit_pkt7(&cs
, CP_LOAD_STATE6_GEOM
, 3 + 4);
3121 tu_cs_emit(&cs
, CP_LOAD_STATE6_0_DST_OFF(pipeline
->tess
.hs_bo_regid
) |
3122 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
3123 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
3124 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_HS_SHADER
) |
3125 CP_LOAD_STATE6_0_NUM_UNIT(1));
3126 tu_cs_emit(&cs
, CP_LOAD_STATE6_1_EXT_SRC_ADDR(0));
3127 tu_cs_emit(&cs
, CP_LOAD_STATE6_2_EXT_SRC_ADDR_HI(0));
3128 tu_cs_emit_qw(&cs
, tess_param_iova
);
3129 tu_cs_emit_qw(&cs
, tess_factor_iova
);
3131 tu_cs_emit_pkt7(&cs
, CP_LOAD_STATE6_GEOM
, 3 + 4);
3132 tu_cs_emit(&cs
, CP_LOAD_STATE6_0_DST_OFF(pipeline
->tess
.ds_bo_regid
) |
3133 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
3134 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
3135 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_DS_SHADER
) |
3136 CP_LOAD_STATE6_0_NUM_UNIT(1));
3137 tu_cs_emit(&cs
, CP_LOAD_STATE6_1_EXT_SRC_ADDR(0));
3138 tu_cs_emit(&cs
, CP_LOAD_STATE6_2_EXT_SRC_ADDR_HI(0));
3139 tu_cs_emit_qw(&cs
, tess_param_iova
);
3140 tu_cs_emit_qw(&cs
, tess_factor_iova
);
3142 tu_cs_emit_pkt4(&cs
, REG_A6XX_PC_TESSFACTOR_ADDR_LO
, 2);
3143 tu_cs_emit_qw(&cs
, tess_factor_iova
);
3145 /* TODO: Without this WFI here, the hardware seems unable to read these
3146 * addresses we just emitted. Freedreno emits these consts as part of
3147 * IB1 instead of in a draw state which might make this WFI unnecessary,
3148 * but it requires a bit more indirection (SS6_INDIRECT for consts). */
3149 tu_cs_emit_wfi(&cs
);
3151 *entry
= tu_cs_end_sub_stream(&cmd
->sub_cs
, &cs
);
3156 tu6_draw_common(struct tu_cmd_buffer
*cmd
,
3159 uint32_t vertex_offset
,
3160 uint32_t first_instance
,
3161 /* note: draw_count count is 0 for indirect */
3162 uint32_t draw_count
)
3164 const struct tu_pipeline
*pipeline
= cmd
->state
.pipeline
;
3167 struct tu_descriptor_state
*descriptors_state
=
3168 &cmd
->descriptors
[VK_PIPELINE_BIND_POINT_GRAPHICS
];
3170 tu_emit_cache_flush_renderpass(cmd
, cs
);
3175 A6XX_VFD_INDEX_OFFSET(vertex_offset
),
3176 A6XX_VFD_INSTANCE_START_OFFSET(first_instance
));
3178 tu_cs_emit_regs(cs
, A6XX_PC_PRIMITIVE_CNTL_0(
3179 .primitive_restart
=
3180 pipeline
->ia
.primitive_restart
&& indexed
,
3181 .tess_upper_left_domain_origin
=
3182 pipeline
->tess
.upper_left_domain_origin
));
3184 if (cmd
->state
.dirty
& TU_CMD_DIRTY_SHADER_CONSTS
) {
3185 cmd
->state
.shader_const_ib
[MESA_SHADER_VERTEX
] =
3186 tu6_emit_consts(cmd
, pipeline
, descriptors_state
, MESA_SHADER_VERTEX
);
3187 cmd
->state
.shader_const_ib
[MESA_SHADER_TESS_CTRL
] =
3188 tu6_emit_consts(cmd
, pipeline
, descriptors_state
, MESA_SHADER_TESS_CTRL
);
3189 cmd
->state
.shader_const_ib
[MESA_SHADER_TESS_EVAL
] =
3190 tu6_emit_consts(cmd
, pipeline
, descriptors_state
, MESA_SHADER_TESS_EVAL
);
3191 cmd
->state
.shader_const_ib
[MESA_SHADER_GEOMETRY
] =
3192 tu6_emit_consts(cmd
, pipeline
, descriptors_state
, MESA_SHADER_GEOMETRY
);
3193 cmd
->state
.shader_const_ib
[MESA_SHADER_FRAGMENT
] =
3194 tu6_emit_consts(cmd
, pipeline
, descriptors_state
, MESA_SHADER_FRAGMENT
);
3197 if (cmd
->state
.dirty
& TU_CMD_DIRTY_DESCRIPTOR_SETS
) {
3198 /* We need to reload the descriptors every time the descriptor sets
3199 * change. However, the commands we send only depend on the pipeline
3200 * because the whole point is to cache descriptors which are used by the
3201 * pipeline. There's a problem here, in that the firmware has an
3202 * "optimization" which skips executing groups that are set to the same
3203 * value as the last draw. This means that if the descriptor sets change
3204 * but not the pipeline, we'd try to re-execute the same buffer which
3205 * the firmware would ignore and we wouldn't pre-load the new
3206 * descriptors. The blob seems to re-emit the LOAD_STATE group whenever
3207 * the descriptor sets change, which we emulate here by copying the
3208 * pre-prepared buffer.
3210 const struct tu_cs_entry
*load_entry
= &pipeline
->load_state
.state_ib
;
3211 if (load_entry
->size
> 0) {
3212 struct tu_cs load_cs
;
3213 result
= tu_cs_begin_sub_stream(&cmd
->sub_cs
, load_entry
->size
, &load_cs
);
3214 if (result
!= VK_SUCCESS
)
3216 tu_cs_emit_array(&load_cs
,
3217 (uint32_t *)((char *)load_entry
->bo
->map
+ load_entry
->offset
),
3218 load_entry
->size
/ 4);
3219 cmd
->state
.desc_sets_load_ib
= tu_cs_end_sub_stream(&cmd
->sub_cs
, &load_cs
);
3221 cmd
->state
.desc_sets_load_ib
.size
= 0;
3225 if (cmd
->state
.dirty
& TU_CMD_DIRTY_VERTEX_BUFFERS
)
3226 cmd
->state
.vertex_buffers_ib
= tu6_emit_vertex_buffers(cmd
, pipeline
);
3228 struct tu_cs_entry vs_params
;
3229 result
= tu6_emit_vs_params(cmd
, first_instance
, &vs_params
);
3230 if (result
!= VK_SUCCESS
)
3234 pipeline
->active_stages
& VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT
;
3235 struct tu_cs_entry tess_consts
= {};
3237 cmd
->has_tess
= true;
3238 result
= tu6_emit_tess_consts(cmd
, draw_count
, pipeline
, &tess_consts
);
3239 if (result
!= VK_SUCCESS
)
3243 /* for the first draw in a renderpass, re-emit all the draw states
3245 * and if a draw-state disabling path (CmdClearAttachments 3D fallback) was
3246 * used, then draw states must be re-emitted. note however this only happens
3247 * in the sysmem path, so this can be skipped this for the gmem path (TODO)
3249 * the two input attachment states are excluded because secondary command
3250 * buffer doesn't have a state ib to restore it, and not re-emitting them
3251 * is OK since CmdClearAttachments won't disable/overwrite them
3253 if (cmd
->state
.dirty
& TU_CMD_DIRTY_DRAW_STATE
) {
3254 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 3 * (TU_DRAW_STATE_COUNT
- 2));
3256 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_PROGRAM
, pipeline
->program
.state_ib
);
3257 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_PROGRAM_BINNING
, pipeline
->program
.binning_state_ib
);
3258 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_TESS
, tess_consts
);
3259 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_VI
, pipeline
->vi
.state_ib
);
3260 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_VI_BINNING
, pipeline
->vi
.binning_state_ib
);
3261 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_RAST
, pipeline
->rast
.state_ib
);
3262 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_DS
, pipeline
->ds
.state_ib
);
3263 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_BLEND
, pipeline
->blend
.state_ib
);
3264 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_VS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_VERTEX
]);
3265 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_HS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_TESS_CTRL
]);
3266 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_DS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_TESS_EVAL
]);
3267 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_GS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_GEOMETRY
]);
3268 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_FS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_FRAGMENT
]);
3269 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_DESC_SETS
, cmd
->state
.desc_sets_ib
);
3270 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_DESC_SETS_LOAD
, cmd
->state
.desc_sets_load_ib
);
3271 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_VB
, cmd
->state
.vertex_buffers_ib
);
3272 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_VS_PARAMS
, vs_params
);
3274 for (uint32_t i
= 0; i
< ARRAY_SIZE(cmd
->state
.dynamic_state
); i
++) {
3275 tu_cs_emit_draw_state(cs
, TU_DRAW_STATE_DYNAMIC
+ i
,
3276 ((pipeline
->dynamic_state_mask
& BIT(i
)) ?
3277 cmd
->state
.dynamic_state
[i
] :
3278 pipeline
->dynamic_state
[i
]));
3282 /* emit draw states that were just updated
3283 * note we eventually don't want to have to emit anything here
3285 uint32_t draw_state_count
=
3287 ((cmd
->state
.dirty
& TU_CMD_DIRTY_SHADER_CONSTS
) ? 5 : 0) +
3288 ((cmd
->state
.dirty
& TU_CMD_DIRTY_DESCRIPTOR_SETS
) ? 1 : 0) +
3289 ((cmd
->state
.dirty
& TU_CMD_DIRTY_VERTEX_BUFFERS
) ? 1 : 0) +
3292 tu_cs_emit_pkt7(cs
, CP_SET_DRAW_STATE
, 3 * draw_state_count
);
3294 /* We may need to re-emit tess consts if the current draw call is
3295 * sufficiently larger than the last draw call. */
3297 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_TESS
, tess_consts
);
3298 if (cmd
->state
.dirty
& TU_CMD_DIRTY_SHADER_CONSTS
) {
3299 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_VS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_VERTEX
]);
3300 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_HS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_TESS_CTRL
]);
3301 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_DS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_TESS_EVAL
]);
3302 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_GS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_GEOMETRY
]);
3303 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_FS_CONST
, cmd
->state
.shader_const_ib
[MESA_SHADER_FRAGMENT
]);
3305 if (cmd
->state
.dirty
& TU_CMD_DIRTY_DESCRIPTOR_SETS
)
3306 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_DESC_SETS_LOAD
, cmd
->state
.desc_sets_load_ib
);
3307 if (cmd
->state
.dirty
& TU_CMD_DIRTY_VERTEX_BUFFERS
)
3308 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_VB
, cmd
->state
.vertex_buffers_ib
);
3309 tu_cs_emit_sds_ib(cs
, TU_DRAW_STATE_VS_PARAMS
, vs_params
);
3312 tu_cs_sanity_check(cs
);
3314 /* There are too many graphics dirty bits to list here, so just list the
3315 * bits to preserve instead. The only things not emitted here are
3316 * compute-related state.
3318 cmd
->state
.dirty
&= (TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
| TU_CMD_DIRTY_COMPUTE_PIPELINE
);
3323 tu_draw_initiator(struct tu_cmd_buffer
*cmd
, enum pc_di_src_sel src_sel
)
3325 const struct tu_pipeline
*pipeline
= cmd
->state
.pipeline
;
3326 uint32_t initiator
=
3327 CP_DRAW_INDX_OFFSET_0_PRIM_TYPE(pipeline
->ia
.primtype
) |
3328 CP_DRAW_INDX_OFFSET_0_SOURCE_SELECT(src_sel
) |
3329 CP_DRAW_INDX_OFFSET_0_INDEX_SIZE(cmd
->state
.index_size
) |
3330 CP_DRAW_INDX_OFFSET_0_VIS_CULL(USE_VISIBILITY
);
3332 if (pipeline
->active_stages
& VK_SHADER_STAGE_GEOMETRY_BIT
)
3333 initiator
|= CP_DRAW_INDX_OFFSET_0_GS_ENABLE
;
3335 switch (pipeline
->tess
.patch_type
) {
3336 case IR3_TESS_TRIANGLES
:
3337 initiator
|= CP_DRAW_INDX_OFFSET_0_PATCH_TYPE(TESS_TRIANGLES
) |
3338 CP_DRAW_INDX_OFFSET_0_TESS_ENABLE
;
3340 case IR3_TESS_ISOLINES
:
3341 initiator
|= CP_DRAW_INDX_OFFSET_0_PATCH_TYPE(TESS_ISOLINES
) |
3342 CP_DRAW_INDX_OFFSET_0_TESS_ENABLE
;
3345 initiator
|= CP_DRAW_INDX_OFFSET_0_PATCH_TYPE(TESS_QUADS
);
3347 case IR3_TESS_QUADS
:
3348 initiator
|= CP_DRAW_INDX_OFFSET_0_PATCH_TYPE(TESS_QUADS
) |
3349 CP_DRAW_INDX_OFFSET_0_TESS_ENABLE
;
3356 tu_CmdDraw(VkCommandBuffer commandBuffer
,
3357 uint32_t vertexCount
,
3358 uint32_t instanceCount
,
3359 uint32_t firstVertex
,
3360 uint32_t firstInstance
)
3362 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3363 struct tu_cs
*cs
= &cmd
->draw_cs
;
3365 tu6_draw_common(cmd
, cs
, false, firstVertex
, firstInstance
, vertexCount
);
3367 tu_cs_emit_pkt7(cs
, CP_DRAW_INDX_OFFSET
, 3);
3368 tu_cs_emit(cs
, tu_draw_initiator(cmd
, DI_SRC_SEL_AUTO_INDEX
));
3369 tu_cs_emit(cs
, instanceCount
);
3370 tu_cs_emit(cs
, vertexCount
);
3374 tu_CmdDrawIndexed(VkCommandBuffer commandBuffer
,
3375 uint32_t indexCount
,
3376 uint32_t instanceCount
,
3377 uint32_t firstIndex
,
3378 int32_t vertexOffset
,
3379 uint32_t firstInstance
)
3381 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3382 struct tu_cs
*cs
= &cmd
->draw_cs
;
3384 tu6_draw_common(cmd
, cs
, true, vertexOffset
, firstInstance
, indexCount
);
3386 tu_cs_emit_pkt7(cs
, CP_DRAW_INDX_OFFSET
, 7);
3387 tu_cs_emit(cs
, tu_draw_initiator(cmd
, DI_SRC_SEL_DMA
));
3388 tu_cs_emit(cs
, instanceCount
);
3389 tu_cs_emit(cs
, indexCount
);
3390 tu_cs_emit(cs
, 0x0); /* XXX */
3391 tu_cs_emit_qw(cs
, cmd
->state
.index_va
+ (firstIndex
<< cmd
->state
.index_shift
));
3392 tu_cs_emit(cs
, indexCount
<< cmd
->state
.index_shift
);
3396 tu_CmdDrawIndirect(VkCommandBuffer commandBuffer
,
3398 VkDeviceSize offset
,
3402 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3403 TU_FROM_HANDLE(tu_buffer
, buf
, _buffer
);
3404 struct tu_cs
*cs
= &cmd
->draw_cs
;
3406 tu6_draw_common(cmd
, cs
, false, 0, 0, 0);
3408 for (uint32_t i
= 0; i
< drawCount
; i
++) {
3409 tu_cs_emit_pkt7(cs
, CP_DRAW_INDIRECT
, 3);
3410 tu_cs_emit(cs
, tu_draw_initiator(cmd
, DI_SRC_SEL_AUTO_INDEX
));
3411 tu_cs_emit_qw(cs
, buf
->bo
->iova
+ buf
->bo_offset
+ offset
+ stride
* i
);
3414 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_READ
);
3418 tu_CmdDrawIndexedIndirect(VkCommandBuffer commandBuffer
,
3420 VkDeviceSize offset
,
3424 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3425 TU_FROM_HANDLE(tu_buffer
, buf
, _buffer
);
3426 struct tu_cs
*cs
= &cmd
->draw_cs
;
3428 tu6_draw_common(cmd
, cs
, true, 0, 0, 0);
3430 for (uint32_t i
= 0; i
< drawCount
; i
++) {
3431 tu_cs_emit_pkt7(cs
, CP_DRAW_INDX_INDIRECT
, 6);
3432 tu_cs_emit(cs
, tu_draw_initiator(cmd
, DI_SRC_SEL_DMA
));
3433 tu_cs_emit_qw(cs
, cmd
->state
.index_va
);
3434 tu_cs_emit(cs
, A5XX_CP_DRAW_INDX_INDIRECT_3_MAX_INDICES(cmd
->state
.max_index_count
));
3435 tu_cs_emit_qw(cs
, buf
->bo
->iova
+ buf
->bo_offset
+ offset
+ stride
* i
);
3438 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_READ
);
3441 void tu_CmdDrawIndirectByteCountEXT(VkCommandBuffer commandBuffer
,
3442 uint32_t instanceCount
,
3443 uint32_t firstInstance
,
3444 VkBuffer _counterBuffer
,
3445 VkDeviceSize counterBufferOffset
,
3446 uint32_t counterOffset
,
3447 uint32_t vertexStride
)
3449 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3450 TU_FROM_HANDLE(tu_buffer
, buf
, _counterBuffer
);
3451 struct tu_cs
*cs
= &cmd
->draw_cs
;
3453 tu6_draw_common(cmd
, cs
, false, 0, firstInstance
, 0);
3455 tu_cs_emit_pkt7(cs
, CP_DRAW_AUTO
, 6);
3456 tu_cs_emit(cs
, tu_draw_initiator(cmd
, DI_SRC_SEL_AUTO_XFB
));
3457 tu_cs_emit(cs
, instanceCount
);
3458 tu_cs_emit_qw(cs
, buf
->bo
->iova
+ buf
->bo_offset
+ counterBufferOffset
);
3459 tu_cs_emit(cs
, counterOffset
);
3460 tu_cs_emit(cs
, vertexStride
);
3462 tu_bo_list_add(&cmd
->bo_list
, buf
->bo
, MSM_SUBMIT_BO_READ
);
3465 struct tu_dispatch_info
3468 * Determine the layout of the grid (in block units) to be used.
3473 * A starting offset for the grid. If unaligned is set, the offset
3474 * must still be aligned.
3476 uint32_t offsets
[3];
3478 * Whether it's an unaligned compute dispatch.
3483 * Indirect compute parameters resource.
3485 struct tu_buffer
*indirect
;
3486 uint64_t indirect_offset
;
3490 tu_emit_compute_driver_params(struct tu_cs
*cs
, struct tu_pipeline
*pipeline
,
3491 const struct tu_dispatch_info
*info
)
3493 gl_shader_stage type
= MESA_SHADER_COMPUTE
;
3494 const struct tu_program_descriptor_linkage
*link
=
3495 &pipeline
->program
.link
[type
];
3496 const struct ir3_const_state
*const_state
= &link
->const_state
;
3497 uint32_t offset
= const_state
->offsets
.driver_param
;
3499 if (link
->constlen
<= offset
)
3502 if (!info
->indirect
) {
3503 uint32_t driver_params
[IR3_DP_CS_COUNT
] = {
3504 [IR3_DP_NUM_WORK_GROUPS_X
] = info
->blocks
[0],
3505 [IR3_DP_NUM_WORK_GROUPS_Y
] = info
->blocks
[1],
3506 [IR3_DP_NUM_WORK_GROUPS_Z
] = info
->blocks
[2],
3507 [IR3_DP_LOCAL_GROUP_SIZE_X
] = pipeline
->compute
.local_size
[0],
3508 [IR3_DP_LOCAL_GROUP_SIZE_Y
] = pipeline
->compute
.local_size
[1],
3509 [IR3_DP_LOCAL_GROUP_SIZE_Z
] = pipeline
->compute
.local_size
[2],
3512 uint32_t num_consts
= MIN2(const_state
->num_driver_params
,
3513 (link
->constlen
- offset
) * 4);
3514 /* push constants */
3515 tu_cs_emit_pkt7(cs
, tu6_stage2opcode(type
), 3 + num_consts
);
3516 tu_cs_emit(cs
, CP_LOAD_STATE6_0_DST_OFF(offset
) |
3517 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
3518 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
3519 CP_LOAD_STATE6_0_STATE_BLOCK(tu6_stage2shadersb(type
)) |
3520 CP_LOAD_STATE6_0_NUM_UNIT(num_consts
/ 4));
3524 for (i
= 0; i
< num_consts
; i
++)
3525 tu_cs_emit(cs
, driver_params
[i
]);
3527 tu_finishme("Indirect driver params");
3532 tu_dispatch(struct tu_cmd_buffer
*cmd
,
3533 const struct tu_dispatch_info
*info
)
3535 struct tu_cs
*cs
= &cmd
->cs
;
3536 struct tu_pipeline
*pipeline
= cmd
->state
.compute_pipeline
;
3537 struct tu_descriptor_state
*descriptors_state
=
3538 &cmd
->descriptors
[VK_PIPELINE_BIND_POINT_COMPUTE
];
3540 /* TODO: We could probably flush less if we add a compute_flush_bits
3543 tu_emit_cache_flush(cmd
, cs
);
3545 if (cmd
->state
.dirty
& TU_CMD_DIRTY_COMPUTE_PIPELINE
)
3546 tu_cs_emit_ib(cs
, &pipeline
->program
.state_ib
);
3548 struct tu_cs_entry ib
;
3550 ib
= tu6_emit_consts(cmd
, pipeline
, descriptors_state
, MESA_SHADER_COMPUTE
);
3552 tu_cs_emit_ib(cs
, &ib
);
3554 tu_emit_compute_driver_params(cs
, pipeline
, info
);
3556 if ((cmd
->state
.dirty
& TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
) &&
3557 pipeline
->load_state
.state_ib
.size
> 0) {
3558 tu_cs_emit_ib(cs
, &pipeline
->load_state
.state_ib
);
3562 ~(TU_CMD_DIRTY_COMPUTE_DESCRIPTOR_SETS
| TU_CMD_DIRTY_COMPUTE_PIPELINE
);
3564 tu_cs_emit_pkt7(cs
, CP_SET_MARKER
, 1);
3565 tu_cs_emit(cs
, A6XX_CP_SET_MARKER_0_MODE(RM6_COMPUTE
));
3567 const uint32_t *local_size
= pipeline
->compute
.local_size
;
3568 const uint32_t *num_groups
= info
->blocks
;
3570 A6XX_HLSQ_CS_NDRANGE_0(.kerneldim
= 3,
3571 .localsizex
= local_size
[0] - 1,
3572 .localsizey
= local_size
[1] - 1,
3573 .localsizez
= local_size
[2] - 1),
3574 A6XX_HLSQ_CS_NDRANGE_1(.globalsize_x
= local_size
[0] * num_groups
[0]),
3575 A6XX_HLSQ_CS_NDRANGE_2(.globaloff_x
= 0),
3576 A6XX_HLSQ_CS_NDRANGE_3(.globalsize_y
= local_size
[1] * num_groups
[1]),
3577 A6XX_HLSQ_CS_NDRANGE_4(.globaloff_y
= 0),
3578 A6XX_HLSQ_CS_NDRANGE_5(.globalsize_z
= local_size
[2] * num_groups
[2]),
3579 A6XX_HLSQ_CS_NDRANGE_6(.globaloff_z
= 0));
3582 A6XX_HLSQ_CS_KERNEL_GROUP_X(1),
3583 A6XX_HLSQ_CS_KERNEL_GROUP_Y(1),
3584 A6XX_HLSQ_CS_KERNEL_GROUP_Z(1));
3586 if (info
->indirect
) {
3587 uint64_t iova
= tu_buffer_iova(info
->indirect
) + info
->indirect_offset
;
3589 tu_bo_list_add(&cmd
->bo_list
, info
->indirect
->bo
,
3590 MSM_SUBMIT_BO_READ
| MSM_SUBMIT_BO_WRITE
);
3592 tu_cs_emit_pkt7(cs
, CP_EXEC_CS_INDIRECT
, 4);
3593 tu_cs_emit(cs
, 0x00000000);
3594 tu_cs_emit_qw(cs
, iova
);
3596 A5XX_CP_EXEC_CS_INDIRECT_3_LOCALSIZEX(local_size
[0] - 1) |
3597 A5XX_CP_EXEC_CS_INDIRECT_3_LOCALSIZEY(local_size
[1] - 1) |
3598 A5XX_CP_EXEC_CS_INDIRECT_3_LOCALSIZEZ(local_size
[2] - 1));
3600 tu_cs_emit_pkt7(cs
, CP_EXEC_CS
, 4);
3601 tu_cs_emit(cs
, 0x00000000);
3602 tu_cs_emit(cs
, CP_EXEC_CS_1_NGROUPS_X(info
->blocks
[0]));
3603 tu_cs_emit(cs
, CP_EXEC_CS_2_NGROUPS_Y(info
->blocks
[1]));
3604 tu_cs_emit(cs
, CP_EXEC_CS_3_NGROUPS_Z(info
->blocks
[2]));
3611 tu_CmdDispatchBase(VkCommandBuffer commandBuffer
,
3619 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3620 struct tu_dispatch_info info
= {};
3626 info
.offsets
[0] = base_x
;
3627 info
.offsets
[1] = base_y
;
3628 info
.offsets
[2] = base_z
;
3629 tu_dispatch(cmd_buffer
, &info
);
3633 tu_CmdDispatch(VkCommandBuffer commandBuffer
,
3638 tu_CmdDispatchBase(commandBuffer
, 0, 0, 0, x
, y
, z
);
3642 tu_CmdDispatchIndirect(VkCommandBuffer commandBuffer
,
3644 VkDeviceSize offset
)
3646 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3647 TU_FROM_HANDLE(tu_buffer
, buffer
, _buffer
);
3648 struct tu_dispatch_info info
= {};
3650 info
.indirect
= buffer
;
3651 info
.indirect_offset
= offset
;
3653 tu_dispatch(cmd_buffer
, &info
);
3657 tu_CmdEndRenderPass(VkCommandBuffer commandBuffer
)
3659 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3661 tu_cs_end(&cmd_buffer
->draw_cs
);
3662 tu_cs_end(&cmd_buffer
->draw_epilogue_cs
);
3664 if (use_sysmem_rendering(cmd_buffer
))
3665 tu_cmd_render_sysmem(cmd_buffer
);
3667 tu_cmd_render_tiles(cmd_buffer
);
3669 /* discard draw_cs and draw_epilogue_cs entries now that the tiles are
3671 tu_cs_discard_entries(&cmd_buffer
->draw_cs
);
3672 tu_cs_begin(&cmd_buffer
->draw_cs
);
3673 tu_cs_discard_entries(&cmd_buffer
->draw_epilogue_cs
);
3674 tu_cs_begin(&cmd_buffer
->draw_epilogue_cs
);
3676 cmd_buffer
->state
.cache
.pending_flush_bits
|=
3677 cmd_buffer
->state
.renderpass_cache
.pending_flush_bits
;
3678 tu_subpass_barrier(cmd_buffer
, &cmd_buffer
->state
.pass
->end_barrier
, true);
3680 cmd_buffer
->state
.pass
= NULL
;
3681 cmd_buffer
->state
.subpass
= NULL
;
3682 cmd_buffer
->state
.framebuffer
= NULL
;
3686 tu_CmdEndRenderPass2(VkCommandBuffer commandBuffer
,
3687 const VkSubpassEndInfoKHR
*pSubpassEndInfo
)
3689 tu_CmdEndRenderPass(commandBuffer
);
3692 struct tu_barrier_info
3694 uint32_t eventCount
;
3695 const VkEvent
*pEvents
;
3696 VkPipelineStageFlags srcStageMask
;
3700 tu_barrier(struct tu_cmd_buffer
*cmd
,
3701 uint32_t memoryBarrierCount
,
3702 const VkMemoryBarrier
*pMemoryBarriers
,
3703 uint32_t bufferMemoryBarrierCount
,
3704 const VkBufferMemoryBarrier
*pBufferMemoryBarriers
,
3705 uint32_t imageMemoryBarrierCount
,
3706 const VkImageMemoryBarrier
*pImageMemoryBarriers
,
3707 const struct tu_barrier_info
*info
)
3709 struct tu_cs
*cs
= cmd
->state
.pass
? &cmd
->draw_cs
: &cmd
->cs
;
3710 VkAccessFlags srcAccessMask
= 0;
3711 VkAccessFlags dstAccessMask
= 0;
3713 for (uint32_t i
= 0; i
< memoryBarrierCount
; i
++) {
3714 srcAccessMask
|= pMemoryBarriers
[i
].srcAccessMask
;
3715 dstAccessMask
|= pMemoryBarriers
[i
].dstAccessMask
;
3718 for (uint32_t i
= 0; i
< bufferMemoryBarrierCount
; i
++) {
3719 srcAccessMask
|= pBufferMemoryBarriers
[i
].srcAccessMask
;
3720 dstAccessMask
|= pBufferMemoryBarriers
[i
].dstAccessMask
;
3723 enum tu_cmd_access_mask src_flags
= 0;
3724 enum tu_cmd_access_mask dst_flags
= 0;
3726 for (uint32_t i
= 0; i
< imageMemoryBarrierCount
; i
++) {
3727 TU_FROM_HANDLE(tu_image
, image
, pImageMemoryBarriers
[i
].image
);
3728 VkImageLayout old_layout
= pImageMemoryBarriers
[i
].oldLayout
;
3729 /* For non-linear images, PREINITIALIZED is the same as UNDEFINED */
3730 if (old_layout
== VK_IMAGE_LAYOUT_UNDEFINED
||
3731 (image
->tiling
!= VK_IMAGE_TILING_LINEAR
&&
3732 old_layout
== VK_IMAGE_LAYOUT_PREINITIALIZED
)) {
3733 /* The underlying memory for this image may have been used earlier
3734 * within the same queue submission for a different image, which
3735 * means that there may be old, stale cache entries which are in the
3736 * "wrong" location, which could cause problems later after writing
3737 * to the image. We don't want these entries being flushed later and
3738 * overwriting the actual image, so we need to flush the CCU.
3740 src_flags
|= TU_ACCESS_CCU_COLOR_INCOHERENT_WRITE
;
3742 srcAccessMask
|= pImageMemoryBarriers
[i
].srcAccessMask
;
3743 dstAccessMask
|= pImageMemoryBarriers
[i
].dstAccessMask
;
3746 /* Inside a renderpass, we don't know yet whether we'll be using sysmem
3747 * so we have to use the sysmem flushes.
3749 bool gmem
= cmd
->state
.ccu_state
== TU_CMD_CCU_GMEM
&&
3751 src_flags
|= vk2tu_access(srcAccessMask
, gmem
);
3752 dst_flags
|= vk2tu_access(dstAccessMask
, gmem
);
3754 struct tu_cache_state
*cache
=
3755 cmd
->state
.pass
? &cmd
->state
.renderpass_cache
: &cmd
->state
.cache
;
3756 tu_flush_for_access(cache
, src_flags
, dst_flags
);
3758 for (uint32_t i
= 0; i
< info
->eventCount
; i
++) {
3759 TU_FROM_HANDLE(tu_event
, event
, info
->pEvents
[i
]);
3761 tu_bo_list_add(&cmd
->bo_list
, &event
->bo
, MSM_SUBMIT_BO_READ
);
3763 tu_cs_emit_pkt7(cs
, CP_WAIT_REG_MEM
, 6);
3764 tu_cs_emit(cs
, CP_WAIT_REG_MEM_0_FUNCTION(WRITE_EQ
) |
3765 CP_WAIT_REG_MEM_0_POLL_MEMORY
);
3766 tu_cs_emit_qw(cs
, event
->bo
.iova
); /* POLL_ADDR_LO/HI */
3767 tu_cs_emit(cs
, CP_WAIT_REG_MEM_3_REF(1));
3768 tu_cs_emit(cs
, CP_WAIT_REG_MEM_4_MASK(~0u));
3769 tu_cs_emit(cs
, CP_WAIT_REG_MEM_5_DELAY_LOOP_CYCLES(20));
3774 tu_CmdPipelineBarrier(VkCommandBuffer commandBuffer
,
3775 VkPipelineStageFlags srcStageMask
,
3776 VkPipelineStageFlags dstStageMask
,
3777 VkDependencyFlags dependencyFlags
,
3778 uint32_t memoryBarrierCount
,
3779 const VkMemoryBarrier
*pMemoryBarriers
,
3780 uint32_t bufferMemoryBarrierCount
,
3781 const VkBufferMemoryBarrier
*pBufferMemoryBarriers
,
3782 uint32_t imageMemoryBarrierCount
,
3783 const VkImageMemoryBarrier
*pImageMemoryBarriers
)
3785 TU_FROM_HANDLE(tu_cmd_buffer
, cmd_buffer
, commandBuffer
);
3786 struct tu_barrier_info info
;
3788 info
.eventCount
= 0;
3789 info
.pEvents
= NULL
;
3790 info
.srcStageMask
= srcStageMask
;
3792 tu_barrier(cmd_buffer
, memoryBarrierCount
, pMemoryBarriers
,
3793 bufferMemoryBarrierCount
, pBufferMemoryBarriers
,
3794 imageMemoryBarrierCount
, pImageMemoryBarriers
, &info
);
3798 write_event(struct tu_cmd_buffer
*cmd
, struct tu_event
*event
,
3799 VkPipelineStageFlags stageMask
, unsigned value
)
3801 struct tu_cs
*cs
= &cmd
->cs
;
3803 /* vkCmdSetEvent/vkCmdResetEvent cannot be called inside a render pass */
3804 assert(!cmd
->state
.pass
);
3806 tu_emit_cache_flush(cmd
, cs
);
3808 tu_bo_list_add(&cmd
->bo_list
, &event
->bo
, MSM_SUBMIT_BO_WRITE
);
3810 /* Flags that only require a top-of-pipe event. DrawIndirect parameters are
3811 * read by the CP, so the draw indirect stage counts as top-of-pipe too.
3813 VkPipelineStageFlags top_of_pipe_flags
=
3814 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT
|
3815 VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT
;
3817 if (!(stageMask
& ~top_of_pipe_flags
)) {
3818 tu_cs_emit_pkt7(cs
, CP_MEM_WRITE
, 3);
3819 tu_cs_emit_qw(cs
, event
->bo
.iova
); /* ADDR_LO/HI */
3820 tu_cs_emit(cs
, value
);
3822 /* Use a RB_DONE_TS event to wait for everything to complete. */
3823 tu_cs_emit_pkt7(cs
, CP_EVENT_WRITE
, 4);
3824 tu_cs_emit(cs
, CP_EVENT_WRITE_0_EVENT(RB_DONE_TS
));
3825 tu_cs_emit_qw(cs
, event
->bo
.iova
);
3826 tu_cs_emit(cs
, value
);
3831 tu_CmdSetEvent(VkCommandBuffer commandBuffer
,
3833 VkPipelineStageFlags stageMask
)
3835 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3836 TU_FROM_HANDLE(tu_event
, event
, _event
);
3838 write_event(cmd
, event
, stageMask
, 1);
3842 tu_CmdResetEvent(VkCommandBuffer commandBuffer
,
3844 VkPipelineStageFlags stageMask
)
3846 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3847 TU_FROM_HANDLE(tu_event
, event
, _event
);
3849 write_event(cmd
, event
, stageMask
, 0);
3853 tu_CmdWaitEvents(VkCommandBuffer commandBuffer
,
3854 uint32_t eventCount
,
3855 const VkEvent
*pEvents
,
3856 VkPipelineStageFlags srcStageMask
,
3857 VkPipelineStageFlags dstStageMask
,
3858 uint32_t memoryBarrierCount
,
3859 const VkMemoryBarrier
*pMemoryBarriers
,
3860 uint32_t bufferMemoryBarrierCount
,
3861 const VkBufferMemoryBarrier
*pBufferMemoryBarriers
,
3862 uint32_t imageMemoryBarrierCount
,
3863 const VkImageMemoryBarrier
*pImageMemoryBarriers
)
3865 TU_FROM_HANDLE(tu_cmd_buffer
, cmd
, commandBuffer
);
3866 struct tu_barrier_info info
;
3868 info
.eventCount
= eventCount
;
3869 info
.pEvents
= pEvents
;
3870 info
.srcStageMask
= 0;
3872 tu_barrier(cmd
, memoryBarrierCount
, pMemoryBarriers
,
3873 bufferMemoryBarrierCount
, pBufferMemoryBarriers
,
3874 imageMemoryBarrierCount
, pImageMemoryBarriers
, &info
);
3878 tu_CmdSetDeviceMask(VkCommandBuffer commandBuffer
, uint32_t deviceMask
)