2 * Copyright © 2017 Broadcom
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include "util/u_format.h"
25 #include "vc5_context.h"
26 #include "vc5_tiling.h"
27 #include "broadcom/common/v3d_macros.h"
28 #include "broadcom/cle/v3dx_pack.h"
30 #define PIPE_CLEAR_COLOR_BUFFERS (PIPE_CLEAR_COLOR0 | \
35 #define PIPE_FIRST_COLOR_BUFFER_BIT (ffs(PIPE_CLEAR_COLOR0) - 1)
37 /* The HW queues up the load until the tile coordinates show up, but can only
38 * track one at a time. If we need to do more than one load, then we need to
39 * flush out the previous load by emitting the tile coordinates and doing a
43 flush_last_load(struct vc5_cl
*cl
)
45 if (V3D_VERSION
>= 40)
48 cl_emit(cl
, TILE_COORDINATES_IMPLICIT
, coords
);
49 cl_emit(cl
, STORE_TILE_BUFFER_GENERAL
, store
) {
50 store
.buffer_to_store
= NONE
;
55 load_general(struct vc5_cl
*cl
, struct pipe_surface
*psurf
, int buffer
,
56 uint32_t pipe_bit
, uint32_t *loads_pending
)
58 struct vc5_surface
*surf
= vc5_surface(psurf
);
59 bool separate_stencil
= surf
->separate_stencil
&& buffer
== STENCIL
;
60 if (separate_stencil
) {
61 psurf
= surf
->separate_stencil
;
62 surf
= vc5_surface(psurf
);
65 struct vc5_resource
*rsc
= vc5_resource(psurf
->texture
);
67 cl_emit(cl
, LOAD_TILE_BUFFER_GENERAL
, load
) {
68 load
.buffer_to_load
= buffer
;
69 load
.address
= cl_address(rsc
->bo
, surf
->offset
);
72 load
.memory_format
= surf
->tiling
;
74 load
.input_image_format
= V3D_OUTPUT_IMAGE_FORMAT_S8
;
76 load
.input_image_format
= surf
->format
;
78 if (surf
->tiling
== VC5_TILING_UIF_NO_XOR
||
79 surf
->tiling
== VC5_TILING_UIF_XOR
) {
80 load
.height_in_ub_or_stride
=
81 surf
->padded_height_of_output_image_in_uif_blocks
;
82 } else if (surf
->tiling
== VC5_TILING_RASTER
) {
83 struct vc5_resource_slice
*slice
=
84 &rsc
->slices
[psurf
->u
.tex
.level
];
85 load
.height_in_ub_or_stride
= slice
->stride
;
89 #else /* V3D_VERSION < 40 */
90 /* Can't do raw ZSTENCIL loads -- need to load/store them to
91 * separate buffers for Z and stencil.
93 assert(buffer
!= ZSTENCIL
);
95 load
.padded_height_of_output_image_in_uif_blocks
=
96 surf
->padded_height_of_output_image_in_uif_blocks
;
97 #endif /* V3D_VERSION < 40 */
100 *loads_pending
&= ~pipe_bit
;
106 store_general(struct vc5_job
*job
,
107 struct vc5_cl
*cl
, struct pipe_surface
*psurf
, int buffer
,
108 int pipe_bit
, uint32_t *stores_pending
, bool general_color_clear
)
110 struct vc5_surface
*surf
= vc5_surface(psurf
);
111 bool separate_stencil
= surf
->separate_stencil
&& buffer
== STENCIL
;
112 if (separate_stencil
) {
113 psurf
= surf
->separate_stencil
;
114 surf
= vc5_surface(psurf
);
117 *stores_pending
&= ~pipe_bit
;
118 bool last_store
= !(*stores_pending
);
120 struct vc5_resource
*rsc
= vc5_resource(psurf
->texture
);
124 cl_emit(cl
, STORE_TILE_BUFFER_GENERAL
, store
) {
125 store
.buffer_to_store
= buffer
;
126 store
.address
= cl_address(rsc
->bo
, surf
->offset
);
128 #if V3D_VERSION >= 40
129 store
.clear_buffer_being_stored
=
130 ((job
->cleared
& pipe_bit
) &&
131 (general_color_clear
||
132 !(pipe_bit
& PIPE_CLEAR_COLOR_BUFFERS
)));
134 if (separate_stencil
)
135 store
.output_image_format
= V3D_OUTPUT_IMAGE_FORMAT_S8
;
137 store
.output_image_format
= surf
->format
;
139 store
.memory_format
= surf
->tiling
;
141 if (surf
->tiling
== VC5_TILING_UIF_NO_XOR
||
142 surf
->tiling
== VC5_TILING_UIF_XOR
) {
143 store
.height_in_ub_or_stride
=
144 surf
->padded_height_of_output_image_in_uif_blocks
;
145 } else if (surf
->tiling
== VC5_TILING_RASTER
) {
146 struct vc5_resource_slice
*slice
=
147 &rsc
->slices
[psurf
->u
.tex
.level
];
148 store
.height_in_ub_or_stride
= slice
->stride
;
150 #else /* V3D_VERSION < 40 */
151 /* Can't do raw ZSTENCIL stores -- need to load/store them to
152 * separate buffers for Z and stencil.
154 assert(buffer
!= ZSTENCIL
);
155 store
.raw_mode
= true;
157 store
.disable_colour_buffers_clear_on_write
= true;
158 store
.disable_z_buffer_clear_on_write
= true;
159 store
.disable_stencil_buffer_clear_on_write
= true;
161 store
.disable_colour_buffers_clear_on_write
=
162 !(((pipe_bit
& PIPE_CLEAR_COLOR_BUFFERS
) &&
163 general_color_clear
&&
164 (job
->cleared
& pipe_bit
)));
165 store
.disable_z_buffer_clear_on_write
=
166 !(job
->cleared
& PIPE_CLEAR_DEPTH
);
167 store
.disable_stencil_buffer_clear_on_write
=
168 !(job
->cleared
& PIPE_CLEAR_STENCIL
);
170 store
.padded_height_of_output_image_in_uif_blocks
=
171 surf
->padded_height_of_output_image_in_uif_blocks
;
172 #endif /* V3D_VERSION < 40 */
175 /* There must be a TILE_COORDINATES_IMPLICIT between each store. */
176 if (V3D_VERSION
< 40 && !last_store
) {
177 cl_emit(cl
, TILE_COORDINATES_IMPLICIT
, coords
);
182 zs_buffer_from_pipe_bits(int pipe_clear_bits
)
184 switch (pipe_clear_bits
& PIPE_CLEAR_DEPTHSTENCIL
) {
185 case PIPE_CLEAR_DEPTHSTENCIL
:
187 case PIPE_CLEAR_DEPTH
:
189 case PIPE_CLEAR_STENCIL
:
197 vc5_rcl_emit_loads(struct vc5_job
*job
, struct vc5_cl
*cl
)
199 uint32_t loads_pending
= job
->resolve
& ~job
->cleared
;
201 for (int i
= 0; i
< VC5_MAX_DRAW_BUFFERS
; i
++) {
202 uint32_t bit
= PIPE_CLEAR_COLOR0
<< i
;
203 if (!(loads_pending
& bit
))
206 struct pipe_surface
*psurf
= job
->cbufs
[i
];
207 if (!psurf
|| (V3D_VERSION
< 40 &&
208 psurf
->texture
->nr_samples
<= 1)) {
212 load_general(cl
, psurf
, RENDER_TARGET_0
+ i
,
213 bit
, &loads_pending
);
216 if ((loads_pending
& PIPE_CLEAR_DEPTHSTENCIL
) &&
217 (V3D_VERSION
>= 40 ||
218 (job
->zsbuf
&& job
->zsbuf
->texture
->nr_samples
> 1))) {
219 load_general(cl
, job
->zsbuf
,
220 zs_buffer_from_pipe_bits(loads_pending
),
221 PIPE_CLEAR_DEPTHSTENCIL
,
226 /* The initial reload will be queued until we get the
230 cl_emit(cl
, RELOAD_TILE_COLOUR_BUFFER
, load
) {
231 load
.disable_colour_buffer_load
=
233 PIPE_CLEAR_COLOR_BUFFERS
) >>
234 PIPE_FIRST_COLOR_BUFFER_BIT
;
236 loads_pending
& PIPE_CLEAR_DEPTH
;
237 load
.enable_stencil_load
=
238 loads_pending
& PIPE_CLEAR_STENCIL
;
241 #else /* V3D_VERSION >= 40 */
242 assert(!loads_pending
);
243 cl_emit(cl
, END_OF_LOADS
, end
);
248 vc5_rcl_emit_stores(struct vc5_job
*job
, struct vc5_cl
*cl
)
250 MAYBE_UNUSED
bool needs_color_clear
= job
->cleared
& PIPE_CLEAR_COLOR_BUFFERS
;
251 MAYBE_UNUSED
bool needs_z_clear
= job
->cleared
& PIPE_CLEAR_DEPTH
;
252 MAYBE_UNUSED
bool needs_s_clear
= job
->cleared
& PIPE_CLEAR_STENCIL
;
254 /* For clearing color in a TLB general on V3D 3.3:
256 * - NONE buffer store clears all TLB color buffers.
257 * - color buffer store clears just the TLB color buffer being stored.
258 * - Z/S buffers store may not clear the TLB color buffer.
260 * And on V3D 4.1, we only have one flag for "clear the buffer being
261 * stored" in the general packet, and a separate packet to clear all
264 * As a result, we only bother flagging TLB color clears in a general
265 * packet when we don't have to emit a separate packet to clear all
268 bool general_color_clear
= (needs_color_clear
&&
269 (job
->cleared
& PIPE_CLEAR_COLOR_BUFFERS
) ==
270 (job
->resolve
& PIPE_CLEAR_COLOR_BUFFERS
));
272 uint32_t stores_pending
= job
->resolve
;
274 /* For V3D 4.1, use general stores for all TLB stores.
276 * For V3D 3.3, we only use general stores to do raw stores for any
277 * MSAA surfaces. These output UIF tiled images where each 4x MSAA
278 * pixel is a 2x2 quad, and the format will be that of the
279 * internal_type/internal_bpp, rather than the format from GL's
280 * perspective. Non-MSAA surfaces will use
281 * STORE_MULTI_SAMPLE_RESOLVED_TILE_COLOR_BUFFER_EXTENDED.
283 for (int i
= 0; i
< VC5_MAX_DRAW_BUFFERS
; i
++) {
284 uint32_t bit
= PIPE_CLEAR_COLOR0
<< i
;
285 if (!(job
->resolve
& bit
))
288 struct pipe_surface
*psurf
= job
->cbufs
[i
];
290 (V3D_VERSION
< 40 && psurf
->texture
->nr_samples
<= 1)) {
294 store_general(job
, cl
, psurf
, RENDER_TARGET_0
+ i
, bit
,
295 &stores_pending
, general_color_clear
);
298 if (job
->resolve
& PIPE_CLEAR_DEPTHSTENCIL
&& job
->zsbuf
&&
299 !(V3D_VERSION
< 40 && job
->zsbuf
->texture
->nr_samples
<= 1)) {
300 struct vc5_resource
*rsc
= vc5_resource(job
->zsbuf
->texture
);
301 if (rsc
->separate_stencil
) {
302 if (job
->resolve
& PIPE_CLEAR_DEPTH
) {
303 store_general(job
, cl
, job
->zsbuf
, Z
,
306 general_color_clear
);
309 if (job
->resolve
& PIPE_CLEAR_STENCIL
) {
310 store_general(job
, cl
, job
->zsbuf
, STENCIL
,
313 general_color_clear
);
316 store_general(job
, cl
, job
->zsbuf
,
317 zs_buffer_from_pipe_bits(job
->resolve
),
318 job
->resolve
& PIPE_CLEAR_DEPTHSTENCIL
,
319 &stores_pending
, general_color_clear
);
323 if (stores_pending
) {
325 cl_emit(cl
, STORE_MULTI_SAMPLE_RESOLVED_TILE_COLOR_BUFFER_EXTENDED
, store
) {
327 store
.disable_color_buffer_write
=
329 PIPE_FIRST_COLOR_BUFFER_BIT
) & 0xf;
330 store
.enable_z_write
= stores_pending
& PIPE_CLEAR_DEPTH
;
331 store
.enable_stencil_write
= stores_pending
& PIPE_CLEAR_STENCIL
;
333 /* Note that when set this will clear all of the color
336 store
.disable_colour_buffers_clear_on_write
=
338 store
.disable_z_buffer_clear_on_write
=
340 store
.disable_stencil_buffer_clear_on_write
=
343 #else /* V3D_VERSION >= 40 */
344 unreachable("All color buffers should have been stored.");
345 #endif /* V3D_VERSION >= 40 */
346 } else if (needs_color_clear
&& !general_color_clear
) {
347 /* If we didn't do our color clears in the general packet,
348 * then emit a packet to clear all the TLB color buffers now.
351 cl_emit(cl
, STORE_TILE_BUFFER_GENERAL
, store
) {
352 store
.buffer_to_store
= NONE
;
354 #else /* V3D_VERSION >= 40 */
355 cl_emit(cl
, CLEAR_TILE_BUFFERS
, clear
) {
356 clear
.clear_all_render_targets
= true;
358 #endif /* V3D_VERSION >= 40 */
363 vc5_rcl_emit_generic_per_tile_list(struct vc5_job
*job
, int last_cbuf
)
365 /* Emit the generic list in our indirect state -- the rcl will just
366 * have pointers into it.
368 struct vc5_cl
*cl
= &job
->indirect
;
369 vc5_cl_ensure_space(cl
, 200, 1);
370 struct vc5_cl_reloc tile_list_start
= cl_get_address(cl
);
372 if (V3D_VERSION
>= 40) {
373 /* V3D 4.x only requires a single tile coordinates, and
374 * END_OF_LOADS switches us between loading and rendering.
376 cl_emit(cl
, TILE_COORDINATES_IMPLICIT
, coords
);
379 vc5_rcl_emit_loads(job
, cl
);
381 if (V3D_VERSION
< 40) {
382 /* Tile Coordinates triggers the last reload and sets where
383 * the stores go. There must be one per store packet.
385 cl_emit(cl
, TILE_COORDINATES_IMPLICIT
, coords
);
388 /* The binner starts out writing tiles assuming that the initial mode
389 * is triangles, so make sure that's the case.
391 cl_emit(cl
, PRIMITIVE_LIST_FORMAT
, fmt
) {
392 fmt
.data_type
= LIST_INDEXED
;
393 fmt
.primitive_type
= LIST_TRIANGLES
;
396 cl_emit(cl
, BRANCH_TO_IMPLICIT_TILE_LIST
, branch
);
398 vc5_rcl_emit_stores(job
, cl
);
400 #if V3D_VERSION >= 40
401 cl_emit(cl
, END_OF_TILE_MARKER
, end
);
404 cl_emit(cl
, RETURN_FROM_SUB_LIST
, ret
);
406 cl_emit(&job
->rcl
, START_ADDRESS_OF_GENERIC_TILE_LIST
, branch
) {
407 branch
.start
= tile_list_start
;
408 branch
.end
= cl_get_address(cl
);
412 #if V3D_VERSION >= 40
414 v3d_setup_render_target(struct vc5_job
*job
, int cbuf
,
415 uint32_t *rt_bpp
, uint32_t *rt_type
, uint32_t *rt_clamp
)
417 if (!job
->cbufs
[cbuf
])
420 struct vc5_surface
*surf
= vc5_surface(job
->cbufs
[cbuf
]);
421 *rt_bpp
= surf
->internal_bpp
;
422 *rt_type
= surf
->internal_type
;
423 *rt_clamp
= V3D_RENDER_TARGET_CLAMP_NONE
;
426 #else /* V3D_VERSION < 40 */
429 v3d_emit_z_stencil_config(struct vc5_job
*job
, struct vc5_surface
*surf
,
430 struct vc5_resource
*rsc
, bool is_separate_stencil
)
432 cl_emit(&job
->rcl
, TILE_RENDERING_MODE_CONFIGURATION_Z_STENCIL_CONFIG
, zs
) {
433 zs
.address
= cl_address(rsc
->bo
, surf
->offset
);
435 if (!is_separate_stencil
) {
436 zs
.internal_type
= surf
->internal_type
;
437 zs
.output_image_format
= surf
->format
;
439 zs
.z_stencil_id
= 1; /* Separate stencil */
442 zs
.padded_height_of_output_image_in_uif_blocks
=
443 surf
->padded_height_of_output_image_in_uif_blocks
;
445 assert(surf
->tiling
!= VC5_TILING_RASTER
);
446 zs
.memory_format
= surf
->tiling
;
449 if (job
->resolve
& (is_separate_stencil
?
451 PIPE_CLEAR_DEPTHSTENCIL
)) {
455 #endif /* V3D_VERSION < 40 */
457 #define div_round_up(a, b) (((a) + (b) - 1) / b)
460 v3dX(emit_rcl
)(struct vc5_job
*job
)
462 /* The RCL list should be empty. */
463 assert(!job
->rcl
.bo
);
465 vc5_cl_ensure_space_with_branch(&job
->rcl
, 200 + 256 *
466 cl_packet_length(SUPERTILE_COORDINATES
));
467 job
->submit
.rcl_start
= job
->rcl
.bo
->offset
;
468 vc5_job_add_bo(job
, job
->rcl
.bo
);
471 for (int i
= 0; i
< VC5_MAX_DRAW_BUFFERS
; i
++) {
476 /* Comon config must be the first TILE_RENDERING_MODE_CONFIGURATION
477 * and Z_STENCIL_CLEAR_VALUES must be last. The ones in between are
478 * optional updates to the previous HW state.
480 cl_emit(&job
->rcl
, TILE_RENDERING_MODE_CONFIGURATION_COMMON_CONFIGURATION
,
483 config
.enable_z_store
= job
->resolve
& PIPE_CLEAR_DEPTH
;
484 config
.enable_stencil_store
= job
->resolve
& PIPE_CLEAR_STENCIL
;
485 #else /* V3D_VERSION >= 40 */
487 struct vc5_surface
*surf
= vc5_surface(job
->zsbuf
);
488 config
.internal_depth_type
= surf
->internal_type
;
490 #endif /* V3D_VERSION >= 40 */
492 /* XXX: Early D/S clear */
494 switch (job
->first_ez_state
) {
495 case VC5_EZ_UNDECIDED
:
497 config
.early_z_disable
= false;
498 config
.early_z_test_and_update_direction
=
499 EARLY_Z_DIRECTION_LT_LE
;
502 config
.early_z_disable
= false;
503 config
.early_z_test_and_update_direction
=
504 EARLY_Z_DIRECTION_GT_GE
;
506 case VC5_EZ_DISABLED
:
507 config
.early_z_disable
= true;
510 config
.image_width_pixels
= job
->draw_width
;
511 config
.image_height_pixels
= job
->draw_height
;
513 config
.number_of_render_targets_minus_1
=
514 MAX2(nr_cbufs
, 1) - 1;
516 config
.multisample_mode_4x
= job
->msaa
;
518 config
.maximum_bpp_of_all_render_targets
= job
->internal_bpp
;
521 for (int i
= 0; i
< nr_cbufs
; i
++) {
522 struct pipe_surface
*psurf
= job
->cbufs
[i
];
525 struct vc5_surface
*surf
= vc5_surface(psurf
);
526 struct vc5_resource
*rsc
= vc5_resource(psurf
->texture
);
528 MAYBE_UNUSED
uint32_t config_pad
= 0;
529 uint32_t clear_pad
= 0;
531 /* XXX: Set the pad for raster. */
532 if (surf
->tiling
== VC5_TILING_UIF_NO_XOR
||
533 surf
->tiling
== VC5_TILING_UIF_XOR
) {
534 int uif_block_height
= vc5_utile_height(rsc
->cpp
) * 2;
535 uint32_t implicit_padded_height
= (align(job
->draw_height
, uif_block_height
) /
537 if (surf
->padded_height_of_output_image_in_uif_blocks
-
538 implicit_padded_height
< 15) {
539 config_pad
= (surf
->padded_height_of_output_image_in_uif_blocks
-
540 implicit_padded_height
);
543 clear_pad
= surf
->padded_height_of_output_image_in_uif_blocks
;
548 cl_emit(&job
->rcl
, TILE_RENDERING_MODE_CONFIGURATION_RENDER_TARGET_CONFIG
, rt
) {
549 rt
.address
= cl_address(rsc
->bo
, surf
->offset
);
550 rt
.internal_type
= surf
->internal_type
;
551 rt
.output_image_format
= surf
->format
;
552 rt
.memory_format
= surf
->tiling
;
553 rt
.internal_bpp
= surf
->internal_bpp
;
554 rt
.render_target_number
= i
;
557 if (job
->resolve
& PIPE_CLEAR_COLOR0
<< i
)
560 #endif /* V3D_VERSION < 40 */
562 cl_emit(&job
->rcl
, TILE_RENDERING_MODE_CONFIGURATION_CLEAR_COLORS_PART1
,
564 clear
.clear_color_low_32_bits
= job
->clear_color
[i
][0];
565 clear
.clear_color_next_24_bits
= job
->clear_color
[i
][1] & 0xffffff;
566 clear
.render_target_number
= i
;
569 if (surf
->internal_bpp
>= V3D_INTERNAL_BPP_64
) {
570 cl_emit(&job
->rcl
, TILE_RENDERING_MODE_CONFIGURATION_CLEAR_COLORS_PART2
,
572 clear
.clear_color_mid_low_32_bits
=
573 ((job
->clear_color
[i
][1] >> 24) |
574 (job
->clear_color
[i
][2] << 8));
575 clear
.clear_color_mid_high_24_bits
=
576 ((job
->clear_color
[i
][2] >> 24) |
577 ((job
->clear_color
[i
][3] & 0xffff) << 8));
578 clear
.render_target_number
= i
;
582 if (surf
->internal_bpp
>= V3D_INTERNAL_BPP_128
|| clear_pad
) {
583 cl_emit(&job
->rcl
, TILE_RENDERING_MODE_CONFIGURATION_CLEAR_COLORS_PART3
,
585 clear
.uif_padded_height_in_uif_blocks
= clear_pad
;
586 clear
.clear_color_high_16_bits
= job
->clear_color
[i
][3] >> 16;
587 clear
.render_target_number
= i
;
592 #if V3D_VERSION >= 40
593 cl_emit(&job
->rcl
, TILE_RENDERING_MODE_CONFIGURATION_RENDER_TARGET_CONFIG
, rt
) {
594 v3d_setup_render_target(job
, 0,
595 &rt
.render_target_0_internal_bpp
,
596 &rt
.render_target_0_internal_type
,
597 &rt
.render_target_0_clamp
);
598 v3d_setup_render_target(job
, 1,
599 &rt
.render_target_1_internal_bpp
,
600 &rt
.render_target_1_internal_type
,
601 &rt
.render_target_1_clamp
);
602 v3d_setup_render_target(job
, 2,
603 &rt
.render_target_2_internal_bpp
,
604 &rt
.render_target_2_internal_type
,
605 &rt
.render_target_2_clamp
);
606 v3d_setup_render_target(job
, 3,
607 &rt
.render_target_3_internal_bpp
,
608 &rt
.render_target_3_internal_type
,
609 &rt
.render_target_3_clamp
);
614 /* TODO: Don't bother emitting if we don't load/clear Z/S. */
616 struct pipe_surface
*psurf
= job
->zsbuf
;
617 struct vc5_surface
*surf
= vc5_surface(psurf
);
618 struct vc5_resource
*rsc
= vc5_resource(psurf
->texture
);
620 v3d_emit_z_stencil_config(job
, surf
, rsc
, false);
622 /* Emit the separate stencil packet if we have a resource for
623 * it. The HW will only load/store this buffer if the
624 * Z/Stencil config doesn't have stencil in its format.
626 if (surf
->separate_stencil
) {
627 v3d_emit_z_stencil_config(job
,
628 vc5_surface(surf
->separate_stencil
),
629 rsc
->separate_stencil
, true);
632 #endif /* V3D_VERSION < 40 */
634 /* Ends rendering mode config. */
635 cl_emit(&job
->rcl
, TILE_RENDERING_MODE_CONFIGURATION_Z_STENCIL_CLEAR_VALUES
,
637 clear
.z_clear_value
= job
->clear_z
;
638 clear
.stencil_vg_mask_clear_value
= job
->clear_s
;
641 /* Always set initial block size before the first branch, which needs
642 * to match the value from binning mode config.
644 cl_emit(&job
->rcl
, TILE_LIST_INITIAL_BLOCK_SIZE
, init
) {
645 init
.use_auto_chained_tile_lists
= true;
646 init
.size_of_first_block_in_chained_tile_lists
=
647 TILE_ALLOCATION_BLOCK_SIZE_64B
;
650 uint32_t supertile_w
= 1, supertile_h
= 1;
652 /* If doing multicore binning, we would need to initialize each core's
655 cl_emit(&job
->rcl
, MULTICORE_RENDERING_TILE_LIST_SET_BASE
, list
) {
656 list
.address
= cl_address(job
->tile_alloc
, 0);
659 cl_emit(&job
->rcl
, MULTICORE_RENDERING_SUPERTILE_CONFIGURATION
, config
) {
660 uint32_t frame_w_in_supertiles
, frame_h_in_supertiles
;
661 const uint32_t max_supertiles
= 256;
663 /* Size up our supertiles until we get under the limit. */
665 frame_w_in_supertiles
= div_round_up(job
->draw_tiles_x
,
667 frame_h_in_supertiles
= div_round_up(job
->draw_tiles_y
,
669 if (frame_w_in_supertiles
* frame_h_in_supertiles
<
674 if (supertile_w
< supertile_h
)
680 config
.total_frame_width_in_tiles
= job
->draw_tiles_x
;
681 config
.total_frame_height_in_tiles
= job
->draw_tiles_y
;
683 config
.supertile_width_in_tiles_minus_1
= supertile_w
- 1;
684 config
.supertile_height_in_tiles_minus_1
= supertile_h
- 1;
686 config
.total_frame_width_in_supertiles
= frame_w_in_supertiles
;
687 config
.total_frame_height_in_supertiles
= frame_h_in_supertiles
;
690 /* Start by clearing the tile buffer. */
691 cl_emit(&job
->rcl
, TILE_COORDINATES
, coords
) {
692 coords
.tile_column_number
= 0;
693 coords
.tile_row_number
= 0;
697 cl_emit(&job
->rcl
, STORE_TILE_BUFFER_GENERAL
, store
) {
698 store
.buffer_to_store
= NONE
;
701 cl_emit(&job
->rcl
, END_OF_LOADS
, end
);
702 cl_emit(&job
->rcl
, STORE_TILE_BUFFER_GENERAL
, store
) {
703 store
.buffer_to_store
= NONE
;
705 cl_emit(&job
->rcl
, CLEAR_TILE_BUFFERS
, clear
) {
706 clear
.clear_z_stencil_buffer
= true;
707 clear
.clear_all_render_targets
= true;
709 cl_emit(&job
->rcl
, END_OF_TILE_MARKER
, end
);
712 cl_emit(&job
->rcl
, FLUSH_VCD_CACHE
, flush
);
714 vc5_rcl_emit_generic_per_tile_list(job
, nr_cbufs
- 1);
716 cl_emit(&job
->rcl
, WAIT_ON_SEMAPHORE
, sem
);
718 /* XXX: Use Morton order */
719 uint32_t supertile_w_in_pixels
= job
->tile_width
* supertile_w
;
720 uint32_t supertile_h_in_pixels
= job
->tile_height
* supertile_h
;
721 uint32_t min_x_supertile
= job
->draw_min_x
/ supertile_w_in_pixels
;
722 uint32_t min_y_supertile
= job
->draw_min_y
/ supertile_h_in_pixels
;
724 uint32_t max_x_supertile
= 0;
725 uint32_t max_y_supertile
= 0;
726 if (job
->draw_max_x
!= 0 && job
->draw_max_y
!= 0) {
727 max_x_supertile
= (job
->draw_max_x
- 1) / supertile_w_in_pixels
;
728 max_y_supertile
= (job
->draw_max_y
- 1) / supertile_h_in_pixels
;
731 for (int y
= min_y_supertile
; y
<= max_y_supertile
; y
++) {
732 for (int x
= min_x_supertile
; x
<= max_x_supertile
; x
++) {
733 cl_emit(&job
->rcl
, SUPERTILE_COORDINATES
, coords
) {
734 coords
.column_number_in_supertiles
= x
;
735 coords
.row_number_in_supertiles
= y
;
740 cl_emit(&job
->rcl
, END_OF_RENDERING
, end
);