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)
38 load_general(struct vc5_cl
*cl
, struct pipe_surface
*psurf
, int buffer
)
40 struct vc5_surface
*surf
= vc5_surface(psurf
);
41 bool separate_stencil
= surf
->separate_stencil
&& buffer
== STENCIL
;
42 if (separate_stencil
) {
43 psurf
= surf
->separate_stencil
;
44 surf
= vc5_surface(psurf
);
47 struct vc5_resource
*rsc
= vc5_resource(psurf
->texture
);
49 cl_emit(cl
, LOAD_TILE_BUFFER_GENERAL
, load
) {
50 load
.buffer_to_load
= buffer
;
51 load
.address
= cl_address(rsc
->bo
, surf
->offset
);
54 load
.memory_format
= surf
->tiling
;
56 load
.input_image_format
= V3D_OUTPUT_IMAGE_FORMAT_S8
;
58 load
.input_image_format
= surf
->format
;
60 if (surf
->tiling
== VC5_TILING_UIF_NO_XOR
||
61 surf
->tiling
== VC5_TILING_UIF_XOR
) {
62 load
.height_in_ub_or_stride
=
63 surf
->padded_height_of_output_image_in_uif_blocks
;
64 } else if (surf
->tiling
== VC5_TILING_RASTER
) {
65 struct vc5_resource_slice
*slice
=
66 &rsc
->slices
[psurf
->u
.tex
.level
];
67 load
.height_in_ub_or_stride
= slice
->stride
;
71 #else /* V3D_VERSION < 40 */
72 /* Can't do raw ZSTENCIL loads -- need to load/store them to
73 * separate buffers for Z and stencil.
75 assert(buffer
!= ZSTENCIL
);
77 load
.padded_height_of_output_image_in_uif_blocks
=
78 surf
->padded_height_of_output_image_in_uif_blocks
;
79 #endif /* V3D_VERSION < 40 */
84 store_general(struct vc5_job
*job
,
85 struct vc5_cl
*cl
, struct pipe_surface
*psurf
, int buffer
,
86 int pipe_bit
, bool last_store
, bool general_color_clear
)
88 struct vc5_surface
*surf
= vc5_surface(psurf
);
89 bool separate_stencil
= surf
->separate_stencil
&& buffer
== STENCIL
;
90 if (separate_stencil
) {
91 psurf
= surf
->separate_stencil
;
92 surf
= vc5_surface(psurf
);
95 struct vc5_resource
*rsc
= vc5_resource(psurf
->texture
);
99 cl_emit(cl
, STORE_TILE_BUFFER_GENERAL
, store
) {
100 store
.buffer_to_store
= buffer
;
101 store
.address
= cl_address(rsc
->bo
, surf
->offset
);
103 #if V3D_VERSION >= 40
104 store
.clear_buffer_being_stored
=
105 ((job
->cleared
& pipe_bit
) &&
106 (general_color_clear
||
107 !(pipe_bit
& PIPE_CLEAR_COLOR_BUFFERS
)));
109 if (separate_stencil
)
110 store
.output_image_format
= V3D_OUTPUT_IMAGE_FORMAT_S8
;
112 store
.output_image_format
= surf
->format
;
114 store
.memory_format
= surf
->tiling
;
116 if (surf
->tiling
== VC5_TILING_UIF_NO_XOR
||
117 surf
->tiling
== VC5_TILING_UIF_XOR
) {
118 store
.height_in_ub_or_stride
=
119 surf
->padded_height_of_output_image_in_uif_blocks
;
120 } else if (surf
->tiling
== VC5_TILING_RASTER
) {
121 struct vc5_resource_slice
*slice
=
122 &rsc
->slices
[psurf
->u
.tex
.level
];
123 store
.height_in_ub_or_stride
= slice
->stride
;
125 #else /* V3D_VERSION < 40 */
126 /* Can't do raw ZSTENCIL stores -- need to load/store them to
127 * separate buffers for Z and stencil.
129 assert(buffer
!= ZSTENCIL
);
130 store
.raw_mode
= true;
132 store
.disable_colour_buffers_clear_on_write
= true;
133 store
.disable_z_buffer_clear_on_write
= true;
134 store
.disable_stencil_buffer_clear_on_write
= true;
136 store
.disable_colour_buffers_clear_on_write
=
137 !(((pipe_bit
& PIPE_CLEAR_COLOR_BUFFERS
) &&
138 general_color_clear
&&
139 (job
->cleared
& pipe_bit
)));
140 store
.disable_z_buffer_clear_on_write
=
141 !(job
->cleared
& PIPE_CLEAR_DEPTH
);
142 store
.disable_stencil_buffer_clear_on_write
=
143 !(job
->cleared
& PIPE_CLEAR_STENCIL
);
145 store
.padded_height_of_output_image_in_uif_blocks
=
146 surf
->padded_height_of_output_image_in_uif_blocks
;
147 #endif /* V3D_VERSION < 40 */
152 zs_buffer_from_pipe_bits(int pipe_clear_bits
)
154 switch (pipe_clear_bits
& PIPE_CLEAR_DEPTHSTENCIL
) {
155 case PIPE_CLEAR_DEPTHSTENCIL
:
157 case PIPE_CLEAR_DEPTH
:
159 case PIPE_CLEAR_STENCIL
:
166 /* The HW queues up the load until the tile coordinates show up, but can only
167 * track one at a time. If we need to do more than one load, then we need to
168 * flush out the previous load by emitting the tile coordinates and doing a
172 flush_last_load(struct vc5_cl
*cl
)
174 if (V3D_VERSION
>= 40)
177 cl_emit(cl
, TILE_COORDINATES_IMPLICIT
, coords
);
178 cl_emit(cl
, STORE_TILE_BUFFER_GENERAL
, store
) {
179 store
.buffer_to_store
= NONE
;
184 vc5_rcl_emit_loads(struct vc5_job
*job
, struct vc5_cl
*cl
)
186 uint32_t read_but_not_cleared
= job
->resolve
& ~job
->cleared
;
188 for (int i
= 0; i
< VC5_MAX_DRAW_BUFFERS
; i
++) {
189 uint32_t bit
= PIPE_CLEAR_COLOR0
<< i
;
190 if (!(read_but_not_cleared
& bit
))
193 struct pipe_surface
*psurf
= job
->cbufs
[i
];
194 if (!psurf
|| (V3D_VERSION
< 40 &&
195 psurf
->texture
->nr_samples
<= 1)) {
199 load_general(cl
, psurf
, RENDER_TARGET_0
+ i
);
200 read_but_not_cleared
&= ~bit
;
202 if (read_but_not_cleared
)
206 if (read_but_not_cleared
& PIPE_CLEAR_DEPTHSTENCIL
&&
207 (V3D_VERSION
>= 40 ||
208 (job
->zsbuf
&& job
->zsbuf
->texture
->nr_samples
> 1))) {
209 load_general(cl
, job
->zsbuf
,
210 zs_buffer_from_pipe_bits(read_but_not_cleared
));
211 read_but_not_cleared
&= ~PIPE_CLEAR_DEPTHSTENCIL
;
212 if (read_but_not_cleared
)
213 cl_emit(cl
, TILE_COORDINATES_IMPLICIT
, coords
);
217 /* The initial reload will be queued until we get the
220 if (read_but_not_cleared
) {
221 cl_emit(cl
, RELOAD_TILE_COLOUR_BUFFER
, load
) {
222 load
.disable_colour_buffer_load
=
223 (~read_but_not_cleared
&
224 PIPE_CLEAR_COLOR_BUFFERS
) >>
225 PIPE_FIRST_COLOR_BUFFER_BIT
;
227 read_but_not_cleared
& PIPE_CLEAR_DEPTH
;
228 load
.enable_stencil_load
=
229 read_but_not_cleared
& PIPE_CLEAR_STENCIL
;
232 #else /* V3D_VERSION >= 40 */
233 assert(!read_but_not_cleared
);
234 cl_emit(cl
, END_OF_LOADS
, end
);
239 vc5_rcl_emit_stores(struct vc5_job
*job
, struct vc5_cl
*cl
)
241 MAYBE_UNUSED
bool needs_color_clear
= job
->cleared
& PIPE_CLEAR_COLOR_BUFFERS
;
242 MAYBE_UNUSED
bool needs_z_clear
= job
->cleared
& PIPE_CLEAR_DEPTH
;
243 MAYBE_UNUSED
bool needs_s_clear
= job
->cleared
& PIPE_CLEAR_STENCIL
;
245 /* For clearing color in a TLB general on V3D 3.3:
247 * - NONE buffer store clears all TLB color buffers.
248 * - color buffer store clears just the TLB color buffer being stored.
249 * - Z/S buffers store may not clear the TLB color buffer.
251 * And on V3D 4.1, we only have one flag for "clear the buffer being
252 * stored" in the general packet, and a separate packet to clear all
255 * As a result, we only bother flagging TLB color clears in a general
256 * packet when we don't have to emit a separate packet to clear all
259 bool general_color_clear
= (needs_color_clear
&&
260 (job
->cleared
& PIPE_CLEAR_COLOR_BUFFERS
) ==
261 (job
->resolve
& PIPE_CLEAR_COLOR_BUFFERS
));
263 uint32_t stores_pending
= job
->resolve
;
265 /* For V3D 4.1, use general stores for all TLB stores.
267 * For V3D 3.3, we only use general stores to do raw stores for any
268 * MSAA surfaces. These output UIF tiled images where each 4x MSAA
269 * pixel is a 2x2 quad, and the format will be that of the
270 * internal_type/internal_bpp, rather than the format from GL's
271 * perspective. Non-MSAA surfaces will use
272 * STORE_MULTI_SAMPLE_RESOLVED_TILE_COLOR_BUFFER_EXTENDED.
274 for (int i
= 0; i
< VC5_MAX_DRAW_BUFFERS
; i
++) {
275 uint32_t bit
= PIPE_CLEAR_COLOR0
<< i
;
276 if (!(job
->resolve
& bit
))
279 struct pipe_surface
*psurf
= job
->cbufs
[i
];
281 (V3D_VERSION
< 40 && psurf
->texture
->nr_samples
<= 1)) {
285 stores_pending
&= ~bit
;
286 store_general(job
, cl
, psurf
, RENDER_TARGET_0
+ i
, bit
,
287 !stores_pending
, general_color_clear
);
288 if (V3D_VERSION
< 40 && stores_pending
)
289 cl_emit(cl
, TILE_COORDINATES_IMPLICIT
, coords
);
292 if (job
->resolve
& PIPE_CLEAR_DEPTHSTENCIL
&& job
->zsbuf
&&
293 !(V3D_VERSION
< 40 && job
->zsbuf
->texture
->nr_samples
<= 1)) {
294 struct vc5_resource
*rsc
= vc5_resource(job
->zsbuf
->texture
);
295 if (rsc
->separate_stencil
) {
296 if (job
->resolve
& PIPE_CLEAR_DEPTH
) {
297 stores_pending
&= ~PIPE_CLEAR_DEPTH
;
298 store_general(job
, cl
, job
->zsbuf
, Z
,
301 general_color_clear
);
302 if (V3D_VERSION
< 40 && stores_pending
) {
303 cl_emit(cl
, TILE_COORDINATES_IMPLICIT
,
308 if (job
->resolve
& PIPE_CLEAR_STENCIL
) {
309 stores_pending
&= ~PIPE_CLEAR_STENCIL
;
310 store_general(job
, cl
, job
->zsbuf
, STENCIL
,
313 general_color_clear
);
314 if (V3D_VERSION
< 40 && stores_pending
) {
315 cl_emit(cl
, TILE_COORDINATES_IMPLICIT
,
320 stores_pending
&= ~PIPE_CLEAR_DEPTHSTENCIL
;
321 store_general(job
, cl
, job
->zsbuf
,
322 zs_buffer_from_pipe_bits(job
->resolve
),
323 job
->resolve
& PIPE_CLEAR_DEPTHSTENCIL
,
324 !stores_pending
, general_color_clear
);
325 if (V3D_VERSION
< 40 && stores_pending
) {
326 cl_emit(cl
, TILE_COORDINATES_IMPLICIT
,
332 if (stores_pending
) {
334 cl_emit(cl
, STORE_MULTI_SAMPLE_RESOLVED_TILE_COLOR_BUFFER_EXTENDED
, store
) {
336 store
.disable_color_buffer_write
=
338 PIPE_FIRST_COLOR_BUFFER_BIT
) & 0xf;
339 store
.enable_z_write
= stores_pending
& PIPE_CLEAR_DEPTH
;
340 store
.enable_stencil_write
= stores_pending
& PIPE_CLEAR_STENCIL
;
342 /* Note that when set this will clear all of the color
345 store
.disable_colour_buffers_clear_on_write
=
347 store
.disable_z_buffer_clear_on_write
=
349 store
.disable_stencil_buffer_clear_on_write
=
352 #else /* V3D_VERSION >= 40 */
353 unreachable("All color buffers should have been stored.");
354 #endif /* V3D_VERSION >= 40 */
355 } else if (needs_color_clear
&& !general_color_clear
) {
356 /* If we didn't do our color clears in the general packet,
357 * then emit a packet to clear all the TLB color buffers now.
360 cl_emit(cl
, STORE_TILE_BUFFER_GENERAL
, store
) {
361 store
.buffer_to_store
= NONE
;
363 #else /* V3D_VERSION >= 40 */
364 cl_emit(cl
, CLEAR_TILE_BUFFERS
, clear
) {
365 clear
.clear_all_render_targets
= true;
367 #endif /* V3D_VERSION >= 40 */
372 vc5_rcl_emit_generic_per_tile_list(struct vc5_job
*job
, int last_cbuf
)
374 /* Emit the generic list in our indirect state -- the rcl will just
375 * have pointers into it.
377 struct vc5_cl
*cl
= &job
->indirect
;
378 vc5_cl_ensure_space(cl
, 200, 1);
379 struct vc5_cl_reloc tile_list_start
= cl_get_address(cl
);
381 if (V3D_VERSION
>= 40) {
382 /* V3D 4.x only requires a single tile coordinates, and
383 * END_OF_LOADS switches us between loading and rendering.
385 cl_emit(cl
, TILE_COORDINATES_IMPLICIT
, coords
);
388 vc5_rcl_emit_loads(job
, cl
);
390 if (V3D_VERSION
< 40) {
391 /* Tile Coordinates triggers the last reload and sets where
392 * the stores go. There must be one per store packet.
394 cl_emit(cl
, TILE_COORDINATES_IMPLICIT
, coords
);
397 /* The binner starts out writing tiles assuming that the initial mode
398 * is triangles, so make sure that's the case.
400 cl_emit(cl
, PRIMITIVE_LIST_FORMAT
, fmt
) {
401 fmt
.data_type
= LIST_INDEXED
;
402 fmt
.primitive_type
= LIST_TRIANGLES
;
405 cl_emit(cl
, BRANCH_TO_IMPLICIT_TILE_LIST
, branch
);
407 vc5_rcl_emit_stores(job
, cl
);
409 #if V3D_VERSION >= 40
410 cl_emit(cl
, END_OF_TILE_MARKER
, end
);
413 cl_emit(cl
, RETURN_FROM_SUB_LIST
, ret
);
415 cl_emit(&job
->rcl
, START_ADDRESS_OF_GENERIC_TILE_LIST
, branch
) {
416 branch
.start
= tile_list_start
;
417 branch
.end
= cl_get_address(cl
);
421 #if V3D_VERSION >= 40
423 v3d_setup_render_target(struct vc5_job
*job
, int cbuf
,
424 uint32_t *rt_bpp
, uint32_t *rt_type
, uint32_t *rt_clamp
)
426 if (!job
->cbufs
[cbuf
])
429 struct vc5_surface
*surf
= vc5_surface(job
->cbufs
[cbuf
]);
430 *rt_bpp
= surf
->internal_bpp
;
431 *rt_type
= surf
->internal_type
;
432 *rt_clamp
= V3D_RENDER_TARGET_CLAMP_NONE
;
435 #else /* V3D_VERSION < 40 */
438 v3d_emit_z_stencil_config(struct vc5_job
*job
, struct vc5_surface
*surf
,
439 struct vc5_resource
*rsc
, bool is_separate_stencil
)
441 cl_emit(&job
->rcl
, TILE_RENDERING_MODE_CONFIGURATION_Z_STENCIL_CONFIG
, zs
) {
442 zs
.address
= cl_address(rsc
->bo
, surf
->offset
);
444 if (!is_separate_stencil
) {
445 zs
.internal_type
= surf
->internal_type
;
446 zs
.output_image_format
= surf
->format
;
448 zs
.z_stencil_id
= 1; /* Separate stencil */
451 zs
.padded_height_of_output_image_in_uif_blocks
=
452 surf
->padded_height_of_output_image_in_uif_blocks
;
454 assert(surf
->tiling
!= VC5_TILING_RASTER
);
455 zs
.memory_format
= surf
->tiling
;
458 if (job
->resolve
& (is_separate_stencil
?
460 PIPE_CLEAR_DEPTHSTENCIL
)) {
464 #endif /* V3D_VERSION < 40 */
466 #define div_round_up(a, b) (((a) + (b) - 1) / b)
469 v3dX(emit_rcl
)(struct vc5_job
*job
)
471 /* The RCL list should be empty. */
472 assert(!job
->rcl
.bo
);
474 vc5_cl_ensure_space_with_branch(&job
->rcl
, 200 + 256 *
475 cl_packet_length(SUPERTILE_COORDINATES
));
476 job
->submit
.rcl_start
= job
->rcl
.bo
->offset
;
477 vc5_job_add_bo(job
, job
->rcl
.bo
);
480 for (int i
= 0; i
< VC5_MAX_DRAW_BUFFERS
; i
++) {
485 /* Comon config must be the first TILE_RENDERING_MODE_CONFIGURATION
486 * and Z_STENCIL_CLEAR_VALUES must be last. The ones in between are
487 * optional updates to the previous HW state.
489 cl_emit(&job
->rcl
, TILE_RENDERING_MODE_CONFIGURATION_COMMON_CONFIGURATION
,
492 config
.enable_z_store
= job
->resolve
& PIPE_CLEAR_DEPTH
;
493 config
.enable_stencil_store
= job
->resolve
& PIPE_CLEAR_STENCIL
;
494 #else /* V3D_VERSION >= 40 */
496 struct vc5_surface
*surf
= vc5_surface(job
->zsbuf
);
497 config
.internal_depth_type
= surf
->internal_type
;
499 #endif /* V3D_VERSION >= 40 */
501 /* XXX: Early D/S clear */
503 switch (job
->first_ez_state
) {
504 case VC5_EZ_UNDECIDED
:
506 config
.early_z_disable
= false;
507 config
.early_z_test_and_update_direction
=
508 EARLY_Z_DIRECTION_LT_LE
;
511 config
.early_z_disable
= false;
512 config
.early_z_test_and_update_direction
=
513 EARLY_Z_DIRECTION_GT_GE
;
515 case VC5_EZ_DISABLED
:
516 config
.early_z_disable
= true;
519 config
.image_width_pixels
= job
->draw_width
;
520 config
.image_height_pixels
= job
->draw_height
;
522 config
.number_of_render_targets_minus_1
=
523 MAX2(nr_cbufs
, 1) - 1;
525 config
.multisample_mode_4x
= job
->msaa
;
527 config
.maximum_bpp_of_all_render_targets
= job
->internal_bpp
;
530 for (int i
= 0; i
< nr_cbufs
; i
++) {
531 struct pipe_surface
*psurf
= job
->cbufs
[i
];
534 struct vc5_surface
*surf
= vc5_surface(psurf
);
535 struct vc5_resource
*rsc
= vc5_resource(psurf
->texture
);
537 MAYBE_UNUSED
uint32_t config_pad
= 0;
538 uint32_t clear_pad
= 0;
540 /* XXX: Set the pad for raster. */
541 if (surf
->tiling
== VC5_TILING_UIF_NO_XOR
||
542 surf
->tiling
== VC5_TILING_UIF_XOR
) {
543 int uif_block_height
= vc5_utile_height(rsc
->cpp
) * 2;
544 uint32_t implicit_padded_height
= (align(job
->draw_height
, uif_block_height
) /
546 if (surf
->padded_height_of_output_image_in_uif_blocks
-
547 implicit_padded_height
< 15) {
548 config_pad
= (surf
->padded_height_of_output_image_in_uif_blocks
-
549 implicit_padded_height
);
552 clear_pad
= surf
->padded_height_of_output_image_in_uif_blocks
;
557 cl_emit(&job
->rcl
, TILE_RENDERING_MODE_CONFIGURATION_RENDER_TARGET_CONFIG
, rt
) {
558 rt
.address
= cl_address(rsc
->bo
, surf
->offset
);
559 rt
.internal_type
= surf
->internal_type
;
560 rt
.output_image_format
= surf
->format
;
561 rt
.memory_format
= surf
->tiling
;
562 rt
.internal_bpp
= surf
->internal_bpp
;
563 rt
.render_target_number
= i
;
566 if (job
->resolve
& PIPE_CLEAR_COLOR0
<< i
)
569 #endif /* V3D_VERSION < 40 */
571 cl_emit(&job
->rcl
, TILE_RENDERING_MODE_CONFIGURATION_CLEAR_COLORS_PART1
,
573 clear
.clear_color_low_32_bits
= job
->clear_color
[i
][0];
574 clear
.clear_color_next_24_bits
= job
->clear_color
[i
][1] & 0xffffff;
575 clear
.render_target_number
= i
;
578 if (surf
->internal_bpp
>= V3D_INTERNAL_BPP_64
) {
579 cl_emit(&job
->rcl
, TILE_RENDERING_MODE_CONFIGURATION_CLEAR_COLORS_PART2
,
581 clear
.clear_color_mid_low_32_bits
=
582 ((job
->clear_color
[i
][1] >> 24) |
583 (job
->clear_color
[i
][2] << 8));
584 clear
.clear_color_mid_high_24_bits
=
585 ((job
->clear_color
[i
][2] >> 24) |
586 ((job
->clear_color
[i
][3] & 0xffff) << 8));
587 clear
.render_target_number
= i
;
591 if (surf
->internal_bpp
>= V3D_INTERNAL_BPP_128
|| clear_pad
) {
592 cl_emit(&job
->rcl
, TILE_RENDERING_MODE_CONFIGURATION_CLEAR_COLORS_PART3
,
594 clear
.uif_padded_height_in_uif_blocks
= clear_pad
;
595 clear
.clear_color_high_16_bits
= job
->clear_color
[i
][3] >> 16;
596 clear
.render_target_number
= i
;
601 #if V3D_VERSION >= 40
602 cl_emit(&job
->rcl
, TILE_RENDERING_MODE_CONFIGURATION_RENDER_TARGET_CONFIG
, rt
) {
603 v3d_setup_render_target(job
, 0,
604 &rt
.render_target_0_internal_bpp
,
605 &rt
.render_target_0_internal_type
,
606 &rt
.render_target_0_clamp
);
607 v3d_setup_render_target(job
, 1,
608 &rt
.render_target_1_internal_bpp
,
609 &rt
.render_target_1_internal_type
,
610 &rt
.render_target_1_clamp
);
611 v3d_setup_render_target(job
, 2,
612 &rt
.render_target_2_internal_bpp
,
613 &rt
.render_target_2_internal_type
,
614 &rt
.render_target_2_clamp
);
615 v3d_setup_render_target(job
, 3,
616 &rt
.render_target_3_internal_bpp
,
617 &rt
.render_target_3_internal_type
,
618 &rt
.render_target_3_clamp
);
623 /* TODO: Don't bother emitting if we don't load/clear Z/S. */
625 struct pipe_surface
*psurf
= job
->zsbuf
;
626 struct vc5_surface
*surf
= vc5_surface(psurf
);
627 struct vc5_resource
*rsc
= vc5_resource(psurf
->texture
);
629 v3d_emit_z_stencil_config(job
, surf
, rsc
, false);
631 /* Emit the separate stencil packet if we have a resource for
632 * it. The HW will only load/store this buffer if the
633 * Z/Stencil config doesn't have stencil in its format.
635 if (surf
->separate_stencil
) {
636 v3d_emit_z_stencil_config(job
,
637 vc5_surface(surf
->separate_stencil
),
638 rsc
->separate_stencil
, true);
641 #endif /* V3D_VERSION < 40 */
643 /* Ends rendering mode config. */
644 cl_emit(&job
->rcl
, TILE_RENDERING_MODE_CONFIGURATION_Z_STENCIL_CLEAR_VALUES
,
646 clear
.z_clear_value
= job
->clear_z
;
647 clear
.stencil_vg_mask_clear_value
= job
->clear_s
;
650 /* Always set initial block size before the first branch, which needs
651 * to match the value from binning mode config.
653 cl_emit(&job
->rcl
, TILE_LIST_INITIAL_BLOCK_SIZE
, init
) {
654 init
.use_auto_chained_tile_lists
= true;
655 init
.size_of_first_block_in_chained_tile_lists
=
656 TILE_ALLOCATION_BLOCK_SIZE_64B
;
659 uint32_t supertile_w
= 1, supertile_h
= 1;
661 /* If doing multicore binning, we would need to initialize each core's
664 cl_emit(&job
->rcl
, MULTICORE_RENDERING_TILE_LIST_SET_BASE
, list
) {
665 list
.address
= cl_address(job
->tile_alloc
, 0);
668 cl_emit(&job
->rcl
, MULTICORE_RENDERING_SUPERTILE_CONFIGURATION
, config
) {
669 uint32_t frame_w_in_supertiles
, frame_h_in_supertiles
;
670 const uint32_t max_supertiles
= 256;
672 /* Size up our supertiles until we get under the limit. */
674 frame_w_in_supertiles
= div_round_up(job
->draw_tiles_x
,
676 frame_h_in_supertiles
= div_round_up(job
->draw_tiles_y
,
678 if (frame_w_in_supertiles
* frame_h_in_supertiles
<
683 if (supertile_w
< supertile_h
)
689 config
.total_frame_width_in_tiles
= job
->draw_tiles_x
;
690 config
.total_frame_height_in_tiles
= job
->draw_tiles_y
;
692 config
.supertile_width_in_tiles_minus_1
= supertile_w
- 1;
693 config
.supertile_height_in_tiles_minus_1
= supertile_h
- 1;
695 config
.total_frame_width_in_supertiles
= frame_w_in_supertiles
;
696 config
.total_frame_height_in_supertiles
= frame_h_in_supertiles
;
699 /* Start by clearing the tile buffer. */
700 cl_emit(&job
->rcl
, TILE_COORDINATES
, coords
) {
701 coords
.tile_column_number
= 0;
702 coords
.tile_row_number
= 0;
706 cl_emit(&job
->rcl
, STORE_TILE_BUFFER_GENERAL
, store
) {
707 store
.buffer_to_store
= NONE
;
710 cl_emit(&job
->rcl
, END_OF_LOADS
, end
);
711 cl_emit(&job
->rcl
, STORE_TILE_BUFFER_GENERAL
, store
) {
712 store
.buffer_to_store
= NONE
;
714 cl_emit(&job
->rcl
, CLEAR_TILE_BUFFERS
, clear
) {
715 clear
.clear_z_stencil_buffer
= true;
716 clear
.clear_all_render_targets
= true;
718 cl_emit(&job
->rcl
, END_OF_TILE_MARKER
, end
);
721 cl_emit(&job
->rcl
, FLUSH_VCD_CACHE
, flush
);
723 vc5_rcl_emit_generic_per_tile_list(job
, nr_cbufs
- 1);
725 cl_emit(&job
->rcl
, WAIT_ON_SEMAPHORE
, sem
);
727 /* XXX: Use Morton order */
728 uint32_t supertile_w_in_pixels
= job
->tile_width
* supertile_w
;
729 uint32_t supertile_h_in_pixels
= job
->tile_height
* supertile_h
;
730 uint32_t min_x_supertile
= job
->draw_min_x
/ supertile_w_in_pixels
;
731 uint32_t min_y_supertile
= job
->draw_min_y
/ supertile_h_in_pixels
;
733 uint32_t max_x_supertile
= 0;
734 uint32_t max_y_supertile
= 0;
735 if (job
->draw_max_x
!= 0 && job
->draw_max_y
!= 0) {
736 max_x_supertile
= (job
->draw_max_x
- 1) / supertile_w_in_pixels
;
737 max_y_supertile
= (job
->draw_max_y
- 1) / supertile_h_in_pixels
;
740 for (int y
= min_y_supertile
; y
<= max_y_supertile
; y
++) {
741 for (int x
= min_x_supertile
; x
<= max_x_supertile
; x
++) {
742 cl_emit(&job
->rcl
, SUPERTILE_COORDINATES
, coords
) {
743 coords
.column_number_in_supertiles
= x
;
744 coords
.row_number_in_supertiles
= y
;
749 cl_emit(&job
->rcl
, END_OF_RENDERING
, end
);