2 * Copyright (C) 2016 Rob Clark <robclark@freedesktop.org>
3 * Copyright © 2018 Google, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Rob Clark <robclark@freedesktop.org>
30 #include "pipe/p_state.h"
31 #include "util/u_string.h"
32 #include "util/u_memory.h"
33 #include "util/u_inlines.h"
34 #include "util/format/u_format.h"
36 #include "freedreno_draw.h"
37 #include "freedreno_state.h"
38 #include "freedreno_resource.h"
40 #include "fd6_blitter.h"
42 #include "fd6_context.h"
45 #include "fd6_program.h"
46 #include "fd6_format.h"
47 #include "fd6_resource.h"
52 * Emits the flags registers, suitable for RB_MRT_FLAG_BUFFER,
53 * RB_DEPTH_FLAG_BUFFER, SP_PS_2D_SRC_FLAGS, and RB_BLIT_FLAG_DST.
56 fd6_emit_flag_reference(struct fd_ringbuffer
*ring
, struct fd_resource
*rsc
,
59 if (fd_resource_ubwc_enabled(rsc
, level
)) {
60 OUT_RELOCW(ring
, rsc
->bo
, fd_resource_ubwc_offset(rsc
, level
, layer
), 0, 0);
62 A6XX_RB_MRT_FLAG_BUFFER_PITCH_PITCH(rsc
->layout
.ubwc_slices
[level
].pitch
) |
63 A6XX_RB_MRT_FLAG_BUFFER_PITCH_ARRAY_PITCH(rsc
->layout
.ubwc_size
));
65 OUT_RING(ring
, 0x00000000); /* RB_MRT_FLAG_BUFFER[i].ADDR_LO */
66 OUT_RING(ring
, 0x00000000); /* RB_MRT_FLAG_BUFFER[i].ADDR_HI */
67 OUT_RING(ring
, 0x00000000);
72 emit_mrt(struct fd_ringbuffer
*ring
, struct pipe_framebuffer_state
*pfb
,
73 struct fd_gmem_stateobj
*gmem
)
75 unsigned char mrt_comp
[A6XX_MAX_RENDER_TARGETS
] = {0};
76 unsigned srgb_cntl
= 0;
82 for (i
= 0; i
< pfb
->nr_cbufs
; i
++) {
83 enum a6xx_color_fmt format
= 0;
84 enum a3xx_color_swap swap
= WZYX
;
85 bool sint
= false, uint
= false;
86 struct fd_resource
*rsc
= NULL
;
87 struct fdl_slice
*slice
= NULL
;
97 struct pipe_surface
*psurf
= pfb
->cbufs
[i
];
98 enum pipe_format pformat
= psurf
->format
;
99 rsc
= fd_resource(psurf
->texture
);
103 uint32_t base
= gmem
? gmem
->cbuf_base
[i
] : 0;
104 slice
= fd_resource_slice(rsc
, psurf
->u
.tex
.level
);
105 format
= fd6_pipe2color(pformat
);
106 sint
= util_format_is_pure_sint(pformat
);
107 uint
= util_format_is_pure_uint(pformat
);
109 if (util_format_is_srgb(pformat
))
110 srgb_cntl
|= (1 << i
);
112 offset
= fd_resource_offset(rsc
, psurf
->u
.tex
.level
,
113 psurf
->u
.tex
.first_layer
);
115 stride
= slice
->pitch
* rsc
->layout
.cpp
* pfb
->samples
;
116 swap
= rsc
->layout
.tile_mode
? WZYX
: fd6_pipe2swap(pformat
);
118 tile_mode
= fd_resource_tile_mode(psurf
->texture
, psurf
->u
.tex
.level
);
120 if (psurf
->u
.tex
.first_layer
< psurf
->u
.tex
.last_layer
) {
122 if (psurf
->texture
->target
== PIPE_TEXTURE_2D_ARRAY
&& psurf
->texture
->nr_samples
> 0)
123 type
= LAYER_MULTISAMPLE_ARRAY
;
124 else if (psurf
->texture
->target
== PIPE_TEXTURE_2D_ARRAY
)
125 type
= LAYER_2D_ARRAY
;
126 else if (psurf
->texture
->target
== PIPE_TEXTURE_CUBE
)
127 type
= LAYER_CUBEMAP
;
128 else if (psurf
->texture
->target
== PIPE_TEXTURE_3D
)
131 stride
/= pfb
->samples
;
134 debug_assert((offset
+ slice
->size0
) <= fd_bo_size(rsc
->bo
));
137 A6XX_RB_MRT_BUF_INFO(i
,
138 .color_format
= format
,
139 .color_tile_mode
= tile_mode
,
141 A6XX_RB_MRT_PITCH(i
, .a6xx_rb_mrt_pitch
= stride
),
142 A6XX_RB_MRT_ARRAY_PITCH(i
, .a6xx_rb_mrt_array_pitch
= slice
->size0
),
143 A6XX_RB_MRT_BASE(i
, .bo
= rsc
->bo
, .bo_offset
= offset
),
144 A6XX_RB_MRT_BASE_GMEM(i
, .unknown
= base
));
147 A6XX_SP_FS_MRT_REG(i
, .color_format
= format
,
148 .color_sint
= sint
, .color_uint
= uint
));
150 OUT_PKT4(ring
, REG_A6XX_RB_MRT_FLAG_BUFFER(i
), 3);
151 fd6_emit_flag_reference(ring
, rsc
,
152 psurf
->u
.tex
.level
, psurf
->u
.tex
.first_layer
);
155 OUT_REG(ring
, A6XX_RB_SRGB_CNTL(.dword
= srgb_cntl
));
156 OUT_REG(ring
, A6XX_SP_SRGB_CNTL(.dword
= srgb_cntl
));
158 OUT_REG(ring
, A6XX_RB_RENDER_COMPONENTS(
166 .rt7
= mrt_comp
[7]));
168 OUT_REG(ring
, A6XX_SP_FS_RENDER_COMPONENTS(
176 .rt7
= mrt_comp
[7]));
178 OUT_REG(ring
, A6XX_GRAS_LAYER_CNTL(.layered
= layered
, .type
= type
));
182 emit_zs(struct fd_ringbuffer
*ring
, struct pipe_surface
*zsbuf
,
183 struct fd_gmem_stateobj
*gmem
)
186 struct fd_resource
*rsc
= fd_resource(zsbuf
->texture
);
187 enum a6xx_depth_format fmt
= fd6_pipe2depth(zsbuf
->format
);
188 struct fdl_slice
*slice
= fd_resource_slice(rsc
, 0);
189 uint32_t stride
= slice
->pitch
* rsc
->layout
.cpp
;
190 uint32_t size
= slice
->size0
;
191 uint32_t base
= gmem
? gmem
->zsbuf_base
[0] : 0;
192 uint32_t offset
= fd_resource_offset(rsc
, zsbuf
->u
.tex
.level
,
193 zsbuf
->u
.tex
.first_layer
);
196 A6XX_RB_DEPTH_BUFFER_INFO(.depth_format
= fmt
),
197 A6XX_RB_DEPTH_BUFFER_PITCH(.a6xx_rb_depth_buffer_pitch
= stride
),
198 A6XX_RB_DEPTH_BUFFER_ARRAY_PITCH(.a6xx_rb_depth_buffer_array_pitch
= size
),
199 A6XX_RB_DEPTH_BUFFER_BASE(.bo
= rsc
->bo
, .bo_offset
= offset
),
200 A6XX_RB_DEPTH_BUFFER_BASE_GMEM(.dword
= base
));
202 OUT_REG(ring
, A6XX_GRAS_SU_DEPTH_BUFFER_INFO(.depth_format
= fmt
));
204 OUT_PKT4(ring
, REG_A6XX_RB_DEPTH_FLAG_BUFFER_BASE_LO
, 3);
205 fd6_emit_flag_reference(ring
, rsc
,
206 zsbuf
->u
.tex
.level
, zsbuf
->u
.tex
.first_layer
);
210 A6XX_GRAS_LRZ_BUFFER_BASE(.bo
= rsc
->lrz
),
211 A6XX_GRAS_LRZ_BUFFER_PITCH(.pitch
= rsc
->lrz_pitch
),
212 // XXX a6xx seems to use a different buffer here.. not sure what for..
213 A6XX_GRAS_LRZ_FAST_CLEAR_BUFFER_BASE_LO(0),
214 A6XX_GRAS_LRZ_FAST_CLEAR_BUFFER_BASE_HI(0));
216 OUT_PKT4(ring
, REG_A6XX_GRAS_LRZ_BUFFER_BASE_LO
, 5);
217 OUT_RING(ring
, 0x00000000);
218 OUT_RING(ring
, 0x00000000);
219 OUT_RING(ring
, 0x00000000); /* GRAS_LRZ_BUFFER_PITCH */
220 OUT_RING(ring
, 0x00000000); /* GRAS_LRZ_FAST_CLEAR_BUFFER_BASE_LO */
221 OUT_RING(ring
, 0x00000000);
224 /* NOTE: blob emits GRAS_LRZ_CNTL plus GRAZ_LRZ_BUFFER_BASE
225 * plus this CP_EVENT_WRITE at the end in it's own IB..
227 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
228 OUT_RING(ring
, CP_EVENT_WRITE_0_EVENT(UNK_25
));
231 struct fdl_slice
*slice
= fd_resource_slice(rsc
->stencil
, 0);
232 stride
= slice
->pitch
* rsc
->stencil
->layout
.cpp
;
234 uint32_t base
= gmem
? gmem
->zsbuf_base
[1] : 0;
237 A6XX_RB_STENCIL_INFO(.separate_stencil
= true),
238 A6XX_RB_STENCIL_BUFFER_PITCH(.a6xx_rb_stencil_buffer_pitch
= stride
),
239 A6XX_RB_STENCIL_BUFFER_ARRAY_PITCH(.a6xx_rb_stencil_buffer_array_pitch
= size
),
240 A6XX_RB_STENCIL_BUFFER_BASE(.bo
= rsc
->stencil
->bo
),
241 A6XX_RB_STENCIL_BUFFER_BASE_GMEM(.dword
= base
));
243 OUT_REG(ring
, A6XX_RB_STENCIL_INFO(0));
246 OUT_PKT4(ring
, REG_A6XX_RB_DEPTH_BUFFER_INFO
, 6);
247 OUT_RING(ring
, A6XX_RB_DEPTH_BUFFER_INFO_DEPTH_FORMAT(DEPTH6_NONE
));
248 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_BUFFER_PITCH */
249 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_BUFFER_ARRAY_PITCH */
250 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_BUFFER_BASE_LO */
251 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_BUFFER_BASE_HI */
252 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_BUFFER_BASE_GMEM */
254 OUT_REG(ring
, A6XX_GRAS_SU_DEPTH_BUFFER_INFO(.depth_format
= DEPTH6_NONE
));
256 OUT_PKT4(ring
, REG_A6XX_GRAS_LRZ_BUFFER_BASE_LO
, 5);
257 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_FLAG_BUFFER_BASE_LO */
258 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_FLAG_BUFFER_BASE_HI */
259 OUT_RING(ring
, 0x00000000); /* GRAS_LRZ_BUFFER_PITCH */
260 OUT_RING(ring
, 0x00000000); /* GRAS_LRZ_FAST_CLEAR_BUFFER_BASE_LO */
261 OUT_RING(ring
, 0x00000000); /* GRAS_LRZ_FAST_CLEAR_BUFFER_BASE_HI */
263 OUT_REG(ring
, A6XX_RB_STENCIL_INFO(0));
268 use_hw_binning(struct fd_batch
*batch
)
270 struct fd_gmem_stateobj
*gmem
= &batch
->ctx
->gmem
;
272 // TODO figure out hw limits for binning
274 return fd_binning_enabled
&& ((gmem
->nbins_x
* gmem
->nbins_y
) >= 2) &&
275 (batch
->num_draws
> 0);
279 patch_fb_read(struct fd_batch
*batch
)
281 struct fd_gmem_stateobj
*gmem
= &batch
->ctx
->gmem
;
283 for (unsigned i
= 0; i
< fd_patch_num_elements(&batch
->fb_read_patches
); i
++) {
284 struct fd_cs_patch
*patch
= fd_patch_element(&batch
->fb_read_patches
, i
);
285 *patch
->cs
= patch
->val
| A6XX_TEX_CONST_2_PITCH(gmem
->bin_w
* gmem
->cbuf_cpp
[0]);
287 util_dynarray_clear(&batch
->fb_read_patches
);
291 update_render_cntl(struct fd_batch
*batch
, struct pipe_framebuffer_state
*pfb
, bool binning
)
293 struct fd_ringbuffer
*ring
= batch
->gmem
;
295 bool depth_ubwc_enable
= false;
296 uint32_t mrts_ubwc_enable
= 0;
300 struct fd_resource
*rsc
= fd_resource(pfb
->zsbuf
->texture
);
301 depth_ubwc_enable
= fd_resource_ubwc_enabled(rsc
, pfb
->zsbuf
->u
.tex
.level
);
304 for (i
= 0; i
< pfb
->nr_cbufs
; i
++) {
308 struct pipe_surface
*psurf
= pfb
->cbufs
[i
];
309 struct fd_resource
*rsc
= fd_resource(psurf
->texture
);
313 if (fd_resource_ubwc_enabled(rsc
, psurf
->u
.tex
.level
))
314 mrts_ubwc_enable
|= 1 << i
;
317 cntl
|= A6XX_RB_RENDER_CNTL_UNK4
;
319 cntl
|= A6XX_RB_RENDER_CNTL_BINNING
;
321 OUT_PKT7(ring
, CP_REG_WRITE
, 3);
323 OUT_RING(ring
, REG_A6XX_RB_RENDER_CNTL
);
324 OUT_RING(ring
, cntl
|
325 COND(depth_ubwc_enable
, A6XX_RB_RENDER_CNTL_FLAG_DEPTH
) |
326 A6XX_RB_RENDER_CNTL_FLAG_MRTS(mrts_ubwc_enable
));
329 #define VSC_DATA_SIZE(pitch) ((pitch) * 32 + 0x100) /* extra size to store VSC_SIZE */
330 #define VSC_DATA2_SIZE(pitch) ((pitch) * 32)
333 update_vsc_pipe(struct fd_batch
*batch
)
335 struct fd_context
*ctx
= batch
->ctx
;
336 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
337 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
338 struct fd_ringbuffer
*ring
= batch
->gmem
;
342 if (!fd6_ctx
->vsc_data
) {
343 fd6_ctx
->vsc_data
= fd_bo_new(ctx
->screen
->dev
,
344 VSC_DATA_SIZE(fd6_ctx
->vsc_data_pitch
),
345 DRM_FREEDRENO_GEM_TYPE_KMEM
, "vsc_data");
348 if (!fd6_ctx
->vsc_data2
) {
349 fd6_ctx
->vsc_data2
= fd_bo_new(ctx
->screen
->dev
,
350 VSC_DATA2_SIZE(fd6_ctx
->vsc_data2_pitch
),
351 DRM_FREEDRENO_GEM_TYPE_KMEM
, "vsc_data2");
355 A6XX_VSC_BIN_SIZE(.width
= gmem
->bin_w
, .height
= gmem
->bin_h
),
356 A6XX_VSC_SIZE_ADDRESS(.bo
= fd6_ctx
->vsc_data
, .bo_offset
= 32 * fd6_ctx
->vsc_data_pitch
));
358 OUT_REG(ring
, A6XX_VSC_BIN_COUNT(.nx
= gmem
->nbins_x
,
359 .ny
= gmem
->nbins_y
));
361 OUT_PKT4(ring
, REG_A6XX_VSC_PIPE_CONFIG_REG(0), 32);
362 for (i
= 0; i
< 32; i
++) {
363 struct fd_vsc_pipe
*pipe
= &ctx
->vsc_pipe
[i
];
364 OUT_RING(ring
, A6XX_VSC_PIPE_CONFIG_REG_X(pipe
->x
) |
365 A6XX_VSC_PIPE_CONFIG_REG_Y(pipe
->y
) |
366 A6XX_VSC_PIPE_CONFIG_REG_W(pipe
->w
) |
367 A6XX_VSC_PIPE_CONFIG_REG_H(pipe
->h
));
371 A6XX_VSC_PIPE_DATA2_ADDRESS(.bo
= fd6_ctx
->vsc_data2
),
372 A6XX_VSC_PIPE_DATA2_PITCH(.dword
= fd6_ctx
->vsc_data2_pitch
),
373 A6XX_VSC_PIPE_DATA2_ARRAY_PITCH(.dword
= fd_bo_size(fd6_ctx
->vsc_data2
)));
376 A6XX_VSC_PIPE_DATA_ADDRESS(.bo
= fd6_ctx
->vsc_data
),
377 A6XX_VSC_PIPE_DATA_PITCH(.dword
= fd6_ctx
->vsc_data_pitch
),
378 A6XX_VSC_PIPE_DATA_ARRAY_PITCH(.dword
= fd_bo_size(fd6_ctx
->vsc_data
)));
381 /* TODO we probably have more than 8 scratch regs.. although the first
382 * 8 is what kernel dumps, and it is kinda useful to be able to see
383 * the value in kernel traces
385 #define OVERFLOW_FLAG_REG REG_A6XX_CP_SCRATCH_REG(0)
388 * If overflow is detected, either 0x1 (VSC_DATA overflow) or 0x3
389 * (VSC_DATA2 overflow) plus the size of the overflowed buffer is
390 * written to control->vsc_overflow. This allows the CPU to
391 * detect which buffer overflowed (and, since the current size is
392 * encoded as well, this protects against already-submitted but
393 * not executed batches from fooling the CPU into increasing the
394 * size again unnecessarily).
396 * To conditionally use VSC data in draw pass only if there is no
397 * overflow, we use a scratch reg (OVERFLOW_FLAG_REG) to hold 1
398 * if no overflow, or 0 in case of overflow. The value is inverted
399 * to make the CP_COND_REG_EXEC stuff easier.
402 emit_vsc_overflow_test(struct fd_batch
*batch
)
404 struct fd_ringbuffer
*ring
= batch
->gmem
;
405 struct fd_gmem_stateobj
*gmem
= &batch
->ctx
->gmem
;
406 struct fd6_context
*fd6_ctx
= fd6_context(batch
->ctx
);
408 debug_assert((fd6_ctx
->vsc_data_pitch
& 0x3) == 0);
409 debug_assert((fd6_ctx
->vsc_data2_pitch
& 0x3) == 0);
411 /* Clear vsc_scratch: */
412 OUT_PKT7(ring
, CP_MEM_WRITE
, 3);
413 OUT_RELOCW(ring
, control_ptr(fd6_ctx
, vsc_scratch
));
416 /* Check for overflow, write vsc_scratch if detected: */
417 for (int i
= 0; i
< gmem
->num_vsc_pipes
; i
++) {
418 OUT_PKT7(ring
, CP_COND_WRITE5
, 8);
419 OUT_RING(ring
, CP_COND_WRITE5_0_FUNCTION(WRITE_GE
) |
420 CP_COND_WRITE5_0_WRITE_MEMORY
);
421 OUT_RING(ring
, CP_COND_WRITE5_1_POLL_ADDR_LO(REG_A6XX_VSC_SIZE_REG(i
)));
422 OUT_RING(ring
, CP_COND_WRITE5_2_POLL_ADDR_HI(0));
423 OUT_RING(ring
, CP_COND_WRITE5_3_REF(fd6_ctx
->vsc_data_pitch
));
424 OUT_RING(ring
, CP_COND_WRITE5_4_MASK(~0));
425 OUT_RELOCW(ring
, control_ptr(fd6_ctx
, vsc_scratch
)); /* WRITE_ADDR_LO/HI */
426 OUT_RING(ring
, CP_COND_WRITE5_7_WRITE_DATA(1 + fd6_ctx
->vsc_data_pitch
));
428 OUT_PKT7(ring
, CP_COND_WRITE5
, 8);
429 OUT_RING(ring
, CP_COND_WRITE5_0_FUNCTION(WRITE_GE
) |
430 CP_COND_WRITE5_0_WRITE_MEMORY
);
431 OUT_RING(ring
, CP_COND_WRITE5_1_POLL_ADDR_LO(REG_A6XX_VSC_SIZE2_REG(i
)));
432 OUT_RING(ring
, CP_COND_WRITE5_2_POLL_ADDR_HI(0));
433 OUT_RING(ring
, CP_COND_WRITE5_3_REF(fd6_ctx
->vsc_data2_pitch
));
434 OUT_RING(ring
, CP_COND_WRITE5_4_MASK(~0));
435 OUT_RELOCW(ring
, control_ptr(fd6_ctx
, vsc_scratch
)); /* WRITE_ADDR_LO/HI */
436 OUT_RING(ring
, CP_COND_WRITE5_7_WRITE_DATA(3 + fd6_ctx
->vsc_data2_pitch
));
439 OUT_PKT7(ring
, CP_WAIT_MEM_WRITES
, 0);
441 OUT_PKT7(ring
, CP_WAIT_FOR_ME
, 0);
443 OUT_PKT7(ring
, CP_MEM_TO_REG
, 3);
444 OUT_RING(ring
, CP_MEM_TO_REG_0_REG(OVERFLOW_FLAG_REG
) |
445 CP_MEM_TO_REG_0_CNT(0));
446 OUT_RELOC(ring
, control_ptr(fd6_ctx
, vsc_scratch
)); /* SRC_LO/HI */
449 * This is a bit awkward, we really want a way to invert the
450 * CP_REG_TEST/CP_COND_REG_EXEC logic, so that we can conditionally
451 * execute cmds to use hwbinning when a bit is *not* set. This
452 * dance is to invert OVERFLOW_FLAG_REG
454 * A CP_NOP packet is used to skip executing the 'else' clause
458 BEGIN_RING(ring
, 10); /* ensure if/else doesn't get split */
460 /* b0 will be set if VSC_DATA or VSC_DATA2 overflow: */
461 OUT_PKT7(ring
, CP_REG_TEST
, 1);
462 OUT_RING(ring
, A6XX_CP_REG_TEST_0_REG(OVERFLOW_FLAG_REG
) |
463 A6XX_CP_REG_TEST_0_BIT(0) |
464 A6XX_CP_REG_TEST_0_WAIT_FOR_ME
);
466 OUT_PKT7(ring
, CP_COND_REG_EXEC
, 2);
467 OUT_RING(ring
, 0x10000000);
468 OUT_RING(ring
, 7); /* conditionally execute next 7 dwords */
472 * On overflow, mirror the value to control->vsc_overflow
473 * which CPU is checking to detect overflow (see
474 * check_vsc_overflow())
476 OUT_PKT7(ring
, CP_REG_TO_MEM
, 3);
477 OUT_RING(ring
, CP_REG_TO_MEM_0_REG(OVERFLOW_FLAG_REG
) |
478 CP_REG_TO_MEM_0_CNT(1 - 1));
479 OUT_RELOCW(ring
, control_ptr(fd6_ctx
, vsc_overflow
));
481 OUT_PKT4(ring
, OVERFLOW_FLAG_REG
, 1);
484 OUT_PKT7(ring
, CP_NOP
, 2); /* skip 'else' when 'if' is taken */
486 OUT_PKT4(ring
, OVERFLOW_FLAG_REG
, 1);
492 check_vsc_overflow(struct fd_context
*ctx
)
494 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
495 struct fd6_control
*control
= fd_bo_map(fd6_ctx
->control_mem
);
496 uint32_t vsc_overflow
= control
->vsc_overflow
;
501 /* clear overflow flag: */
502 control
->vsc_overflow
= 0;
504 unsigned buffer
= vsc_overflow
& 0x3;
505 unsigned size
= vsc_overflow
& ~0x3;
508 /* VSC_PIPE_DATA overflow: */
510 if (size
< fd6_ctx
->vsc_data_pitch
) {
511 /* we've already increased the size, this overflow is
512 * from a batch submitted before resize, but executed
518 fd_bo_del(fd6_ctx
->vsc_data
);
519 fd6_ctx
->vsc_data
= NULL
;
520 fd6_ctx
->vsc_data_pitch
*= 2;
522 debug_printf("resized VSC_DATA_PITCH to: 0x%x\n", fd6_ctx
->vsc_data_pitch
);
524 } else if (buffer
== 0x3) {
525 /* VSC_PIPE_DATA2 overflow: */
527 if (size
< fd6_ctx
->vsc_data2_pitch
) {
528 /* we've already increased the size */
532 fd_bo_del(fd6_ctx
->vsc_data2
);
533 fd6_ctx
->vsc_data2
= NULL
;
534 fd6_ctx
->vsc_data2_pitch
*= 2;
536 debug_printf("resized VSC_DATA2_PITCH to: 0x%x\n", fd6_ctx
->vsc_data2_pitch
);
539 /* NOTE: it's possible, for example, for overflow to corrupt the
540 * control page. I mostly just see this hit if I set initial VSC
541 * buffer size extremely small. Things still seem to recover,
542 * but maybe we should pre-emptively realloc vsc_data/vsc_data2
543 * and hope for different memory placement?
545 DBG("invalid vsc_overflow value: 0x%08x", vsc_overflow
);
550 * Emit conditional CP_INDIRECT_BRANCH based on VSC_STATE[p], ie. the IB
551 * is skipped for tiles that have no visible geometry.
554 emit_conditional_ib(struct fd_batch
*batch
, struct fd_tile
*tile
,
555 struct fd_ringbuffer
*target
)
557 struct fd_ringbuffer
*ring
= batch
->gmem
;
559 if (target
->cur
== target
->start
)
562 emit_marker6(ring
, 6);
564 unsigned count
= fd_ringbuffer_cmd_count(target
);
566 BEGIN_RING(ring
, 5 + 4 * count
); /* ensure conditional doesn't get split */
568 OUT_PKT7(ring
, CP_REG_TEST
, 1);
569 OUT_RING(ring
, A6XX_CP_REG_TEST_0_REG(REG_A6XX_VSC_STATE_REG(tile
->p
)) |
570 A6XX_CP_REG_TEST_0_BIT(tile
->n
) |
571 A6XX_CP_REG_TEST_0_WAIT_FOR_ME
);
573 OUT_PKT7(ring
, CP_COND_REG_EXEC
, 2);
574 OUT_RING(ring
, 0x10000000);
575 OUT_RING(ring
, 4 * count
); /* conditionally execute next 4*count dwords */
577 for (unsigned i
= 0; i
< count
; i
++) {
579 OUT_PKT7(ring
, CP_INDIRECT_BUFFER
, 3);
580 dwords
= fd_ringbuffer_emit_reloc_ring_full(ring
, target
, i
) / 4;
582 OUT_RING(ring
, dwords
);
585 emit_marker6(ring
, 6);
589 set_scissor(struct fd_ringbuffer
*ring
, uint32_t x1
, uint32_t y1
, uint32_t x2
, uint32_t y2
)
592 A6XX_GRAS_SC_WINDOW_SCISSOR_TL(.x
= x1
, .y
= y1
),
593 A6XX_GRAS_SC_WINDOW_SCISSOR_BR(.x
= x2
, .y
= y2
));
596 A6XX_GRAS_RESOLVE_CNTL_1(.x
= x1
, .y
= y1
),
597 A6XX_GRAS_RESOLVE_CNTL_2(.x
= x2
, .y
= y2
));
601 set_bin_size(struct fd_ringbuffer
*ring
, uint32_t w
, uint32_t h
, uint32_t flag
)
603 OUT_REG(ring
, A6XX_GRAS_BIN_CONTROL(.binw
= w
, .binh
= h
, .dword
= flag
));
604 OUT_REG(ring
, A6XX_RB_BIN_CONTROL(.binw
= w
, .binh
= h
, .dword
= flag
));
605 /* no flag for RB_BIN_CONTROL2... */
606 OUT_REG(ring
, A6XX_RB_BIN_CONTROL2(.binw
= w
, .binh
= h
));
610 emit_binning_pass(struct fd_batch
*batch
)
612 struct fd_ringbuffer
*ring
= batch
->gmem
;
613 struct fd_gmem_stateobj
*gmem
= &batch
->ctx
->gmem
;
614 struct fd6_context
*fd6_ctx
= fd6_context(batch
->ctx
);
616 uint32_t x1
= gmem
->minx
;
617 uint32_t y1
= gmem
->miny
;
618 uint32_t x2
= gmem
->minx
+ gmem
->width
- 1;
619 uint32_t y2
= gmem
->miny
+ gmem
->height
- 1;
621 debug_assert(!batch
->tessellation
);
623 set_scissor(ring
, x1
, y1
, x2
, y2
);
625 emit_marker6(ring
, 7);
626 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
627 OUT_RING(ring
, A6XX_CP_SET_MARKER_0_MODE(RM6_BINNING
));
628 emit_marker6(ring
, 7);
630 OUT_PKT7(ring
, CP_SET_VISIBILITY_OVERRIDE
, 1);
633 OUT_PKT7(ring
, CP_SET_MODE
, 1);
638 OUT_REG(ring
, A6XX_VFD_MODE_CNTL(.binning_pass
= true));
640 update_vsc_pipe(batch
);
642 OUT_PKT4(ring
, REG_A6XX_PC_UNKNOWN_9805
, 1);
643 OUT_RING(ring
, fd6_ctx
->magic
.PC_UNKNOWN_9805
);
645 OUT_PKT4(ring
, REG_A6XX_SP_UNKNOWN_A0F8
, 1);
646 OUT_RING(ring
, fd6_ctx
->magic
.SP_UNKNOWN_A0F8
);
648 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
649 OUT_RING(ring
, UNK_2C
);
651 OUT_PKT4(ring
, REG_A6XX_RB_WINDOW_OFFSET
, 1);
652 OUT_RING(ring
, A6XX_RB_WINDOW_OFFSET_X(0) |
653 A6XX_RB_WINDOW_OFFSET_Y(0));
655 OUT_PKT4(ring
, REG_A6XX_SP_TP_WINDOW_OFFSET
, 1);
656 OUT_RING(ring
, A6XX_SP_TP_WINDOW_OFFSET_X(0) |
657 A6XX_SP_TP_WINDOW_OFFSET_Y(0));
659 /* emit IB to binning drawcmds: */
660 fd6_emit_ib(ring
, batch
->draw
);
664 OUT_PKT7(ring
, CP_SET_DRAW_STATE
, 3);
665 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(0) |
666 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
667 CP_SET_DRAW_STATE__0_GROUP_ID(0));
668 OUT_RING(ring
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
669 OUT_RING(ring
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
671 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
672 OUT_RING(ring
, UNK_2D
);
674 fd6_cache_inv(batch
, ring
);
675 fd6_cache_flush(batch
, ring
);
678 OUT_PKT7(ring
, CP_WAIT_FOR_ME
, 0);
680 emit_vsc_overflow_test(batch
);
682 OUT_PKT7(ring
, CP_SET_VISIBILITY_OVERRIDE
, 1);
685 OUT_PKT7(ring
, CP_SET_MODE
, 1);
690 OUT_PKT4(ring
, REG_A6XX_RB_CCU_CNTL
, 1);
691 OUT_RING(ring
, fd6_ctx
->magic
.RB_CCU_CNTL_gmem
);
695 emit_msaa(struct fd_ringbuffer
*ring
, unsigned nr
)
697 enum a3xx_msaa_samples samples
= fd_msaa_samples(nr
);
699 OUT_PKT4(ring
, REG_A6XX_SP_TP_RAS_MSAA_CNTL
, 2);
700 OUT_RING(ring
, A6XX_SP_TP_RAS_MSAA_CNTL_SAMPLES(samples
));
701 OUT_RING(ring
, A6XX_SP_TP_DEST_MSAA_CNTL_SAMPLES(samples
) |
702 COND(samples
== MSAA_ONE
, A6XX_SP_TP_DEST_MSAA_CNTL_MSAA_DISABLE
));
704 OUT_PKT4(ring
, REG_A6XX_GRAS_RAS_MSAA_CNTL
, 2);
705 OUT_RING(ring
, A6XX_GRAS_RAS_MSAA_CNTL_SAMPLES(samples
));
706 OUT_RING(ring
, A6XX_GRAS_DEST_MSAA_CNTL_SAMPLES(samples
) |
707 COND(samples
== MSAA_ONE
, A6XX_GRAS_DEST_MSAA_CNTL_MSAA_DISABLE
));
709 OUT_PKT4(ring
, REG_A6XX_RB_RAS_MSAA_CNTL
, 2);
710 OUT_RING(ring
, A6XX_RB_RAS_MSAA_CNTL_SAMPLES(samples
));
711 OUT_RING(ring
, A6XX_RB_DEST_MSAA_CNTL_SAMPLES(samples
) |
712 COND(samples
== MSAA_ONE
, A6XX_RB_DEST_MSAA_CNTL_MSAA_DISABLE
));
714 OUT_PKT4(ring
, REG_A6XX_RB_MSAA_CNTL
, 1);
715 OUT_RING(ring
, A6XX_RB_MSAA_CNTL_SAMPLES(samples
));
718 static void prepare_tile_setup_ib(struct fd_batch
*batch
);
719 static void prepare_tile_fini_ib(struct fd_batch
*batch
);
721 /* before first tile */
723 fd6_emit_tile_init(struct fd_batch
*batch
)
725 struct fd_context
*ctx
= batch
->ctx
;
726 struct fd_ringbuffer
*ring
= batch
->gmem
;
727 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
728 struct fd_gmem_stateobj
*gmem
= &batch
->ctx
->gmem
;
730 fd6_emit_restore(batch
, ring
);
732 fd6_emit_lrz_flush(ring
);
734 if (batch
->lrz_clear
)
735 fd6_emit_ib(ring
, batch
->lrz_clear
);
737 fd6_cache_inv(batch
, ring
);
739 prepare_tile_setup_ib(batch
);
740 prepare_tile_fini_ib(batch
);
742 OUT_PKT7(ring
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
746 OUT_PKT4(ring
, REG_A6XX_RB_CCU_CNTL
, 1);
747 OUT_RING(ring
, fd6_context(ctx
)->magic
.RB_CCU_CNTL_gmem
);
749 emit_zs(ring
, pfb
->zsbuf
, &ctx
->gmem
);
750 emit_mrt(ring
, pfb
, &ctx
->gmem
);
751 emit_msaa(ring
, pfb
->samples
);
752 patch_fb_read(batch
);
754 if (use_hw_binning(batch
)) {
755 /* enable stream-out during binning pass: */
756 OUT_PKT4(ring
, REG_A6XX_VPC_SO_OVERRIDE
, 1);
759 set_bin_size(ring
, gmem
->bin_w
, gmem
->bin_h
,
760 A6XX_RB_BIN_CONTROL_BINNING_PASS
| 0x6000000);
761 update_render_cntl(batch
, pfb
, true);
762 emit_binning_pass(batch
);
764 /* and disable stream-out for draw pass: */
765 OUT_PKT4(ring
, REG_A6XX_VPC_SO_OVERRIDE
, 1);
766 OUT_RING(ring
, A6XX_VPC_SO_OVERRIDE_SO_DISABLE
);
769 * NOTE: even if we detect VSC overflow and disable use of
770 * visibility stream in draw pass, it is still safe to execute
771 * the reset of these cmds:
774 // NOTE a618 not setting .USE_VIZ .. from a quick check on a630, it
775 // does not appear that this bit changes much (ie. it isn't actually
776 // .USE_VIZ like previous gens)
777 set_bin_size(ring
, gmem
->bin_w
, gmem
->bin_h
,
778 A6XX_RB_BIN_CONTROL_USE_VIZ
| 0x6000000);
780 OUT_PKT4(ring
, REG_A6XX_VFD_MODE_CNTL
, 1);
783 OUT_PKT4(ring
, REG_A6XX_PC_UNKNOWN_9805
, 1);
784 OUT_RING(ring
, fd6_context(ctx
)->magic
.PC_UNKNOWN_9805
);
786 OUT_PKT4(ring
, REG_A6XX_SP_UNKNOWN_A0F8
, 1);
787 OUT_RING(ring
, fd6_context(ctx
)->magic
.SP_UNKNOWN_A0F8
);
789 OUT_PKT7(ring
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
792 /* no binning pass, so enable stream-out for draw pass:: */
793 OUT_PKT4(ring
, REG_A6XX_VPC_SO_OVERRIDE
, 1);
796 set_bin_size(ring
, gmem
->bin_w
, gmem
->bin_h
, 0x6000000);
799 update_render_cntl(batch
, pfb
, false);
803 set_window_offset(struct fd_ringbuffer
*ring
, uint32_t x1
, uint32_t y1
)
805 OUT_PKT4(ring
, REG_A6XX_RB_WINDOW_OFFSET
, 1);
806 OUT_RING(ring
, A6XX_RB_WINDOW_OFFSET_X(x1
) |
807 A6XX_RB_WINDOW_OFFSET_Y(y1
));
809 OUT_PKT4(ring
, REG_A6XX_RB_WINDOW_OFFSET2
, 1);
810 OUT_RING(ring
, A6XX_RB_WINDOW_OFFSET2_X(x1
) |
811 A6XX_RB_WINDOW_OFFSET2_Y(y1
));
813 OUT_PKT4(ring
, REG_A6XX_SP_WINDOW_OFFSET
, 1);
814 OUT_RING(ring
, A6XX_SP_WINDOW_OFFSET_X(x1
) |
815 A6XX_SP_WINDOW_OFFSET_Y(y1
));
817 OUT_PKT4(ring
, REG_A6XX_SP_TP_WINDOW_OFFSET
, 1);
818 OUT_RING(ring
, A6XX_SP_TP_WINDOW_OFFSET_X(x1
) |
819 A6XX_SP_TP_WINDOW_OFFSET_Y(y1
));
822 /* before mem2gmem */
824 fd6_emit_tile_prep(struct fd_batch
*batch
, struct fd_tile
*tile
)
826 struct fd_context
*ctx
= batch
->ctx
;
827 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
828 struct fd_ringbuffer
*ring
= batch
->gmem
;
830 emit_marker6(ring
, 7);
831 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
832 OUT_RING(ring
, A6XX_CP_SET_MARKER_0_MODE(RM6_GMEM
) | 0x10);
833 emit_marker6(ring
, 7);
835 uint32_t x1
= tile
->xoff
;
836 uint32_t y1
= tile
->yoff
;
837 uint32_t x2
= tile
->xoff
+ tile
->bin_w
- 1;
838 uint32_t y2
= tile
->yoff
+ tile
->bin_h
- 1;
840 set_scissor(ring
, x1
, y1
, x2
, y2
);
842 if (use_hw_binning(batch
)) {
843 struct fd_vsc_pipe
*pipe
= &ctx
->vsc_pipe
[tile
->p
];
845 OUT_PKT7(ring
, CP_WAIT_FOR_ME
, 0);
847 OUT_PKT7(ring
, CP_SET_MODE
, 1);
851 * Conditionally execute if no VSC overflow:
854 BEGIN_RING(ring
, 18); /* ensure if/else doesn't get split */
856 OUT_PKT7(ring
, CP_REG_TEST
, 1);
857 OUT_RING(ring
, A6XX_CP_REG_TEST_0_REG(OVERFLOW_FLAG_REG
) |
858 A6XX_CP_REG_TEST_0_BIT(0) |
859 A6XX_CP_REG_TEST_0_WAIT_FOR_ME
);
861 OUT_PKT7(ring
, CP_COND_REG_EXEC
, 2);
862 OUT_RING(ring
, 0x10000000);
863 OUT_RING(ring
, 11); /* conditionally execute next 11 dwords */
865 /* if (no overflow) */ {
866 OUT_PKT7(ring
, CP_SET_BIN_DATA5
, 7);
867 OUT_RING(ring
, CP_SET_BIN_DATA5_0_VSC_SIZE(pipe
->w
* pipe
->h
) |
868 CP_SET_BIN_DATA5_0_VSC_N(tile
->n
));
869 OUT_RELOC(ring
, fd6_ctx
->vsc_data
, /* VSC_PIPE[p].DATA_ADDRESS */
870 (tile
->p
* fd6_ctx
->vsc_data_pitch
), 0, 0);
871 OUT_RELOC(ring
, fd6_ctx
->vsc_data
, /* VSC_SIZE_ADDRESS + (p * 4) */
872 (tile
->p
* 4) + (32 * fd6_ctx
->vsc_data_pitch
), 0, 0);
873 OUT_RELOC(ring
, fd6_ctx
->vsc_data2
,
874 (tile
->p
* fd6_ctx
->vsc_data2_pitch
), 0, 0);
876 OUT_PKT7(ring
, CP_SET_VISIBILITY_OVERRIDE
, 1);
879 /* use a NOP packet to skip over the 'else' side: */
880 OUT_PKT7(ring
, CP_NOP
, 2);
882 OUT_PKT7(ring
, CP_SET_VISIBILITY_OVERRIDE
, 1);
886 set_window_offset(ring
, x1
, y1
);
888 struct fd_gmem_stateobj
*gmem
= &batch
->ctx
->gmem
;
889 set_bin_size(ring
, gmem
->bin_w
, gmem
->bin_h
, 0x6000000);
891 OUT_PKT7(ring
, CP_SET_MODE
, 1);
894 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8804
, 1);
897 OUT_PKT4(ring
, REG_A6XX_SP_TP_UNKNOWN_B304
, 1);
900 OUT_PKT4(ring
, REG_A6XX_GRAS_UNKNOWN_80A4
, 1);
903 set_window_offset(ring
, x1
, y1
);
905 OUT_PKT7(ring
, CP_SET_VISIBILITY_OVERRIDE
, 1);
908 OUT_PKT7(ring
, CP_SET_MODE
, 1);
914 set_blit_scissor(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
)
916 struct pipe_scissor_state blit_scissor
;
917 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
919 blit_scissor
.minx
= 0;
920 blit_scissor
.miny
= 0;
921 blit_scissor
.maxx
= align(pfb
->width
, batch
->ctx
->screen
->gmem_alignw
);
922 blit_scissor
.maxy
= align(pfb
->height
, batch
->ctx
->screen
->gmem_alignh
);
924 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_SCISSOR_TL
, 2);
926 A6XX_RB_BLIT_SCISSOR_TL_X(blit_scissor
.minx
) |
927 A6XX_RB_BLIT_SCISSOR_TL_Y(blit_scissor
.miny
));
929 A6XX_RB_BLIT_SCISSOR_BR_X(blit_scissor
.maxx
- 1) |
930 A6XX_RB_BLIT_SCISSOR_BR_Y(blit_scissor
.maxy
- 1));
934 emit_blit(struct fd_batch
*batch
,
935 struct fd_ringbuffer
*ring
,
937 struct pipe_surface
*psurf
,
940 struct fdl_slice
*slice
;
941 struct fd_resource
*rsc
= fd_resource(psurf
->texture
);
942 enum pipe_format pfmt
= psurf
->format
;
946 debug_assert(psurf
->u
.tex
.first_layer
== psurf
->u
.tex
.last_layer
);
948 /* separate stencil case: */
951 pfmt
= rsc
->base
.format
;
954 slice
= fd_resource_slice(rsc
, psurf
->u
.tex
.level
);
955 offset
= fd_resource_offset(rsc
, psurf
->u
.tex
.level
,
956 psurf
->u
.tex
.first_layer
);
957 ubwc_enabled
= fd_resource_ubwc_enabled(rsc
, psurf
->u
.tex
.level
);
959 debug_assert(psurf
->u
.tex
.first_layer
== psurf
->u
.tex
.last_layer
);
961 enum a6xx_color_fmt format
= fd6_pipe2color(pfmt
);
962 uint32_t stride
= slice
->pitch
* rsc
->layout
.cpp
;
963 uint32_t size
= slice
->size0
;
964 enum a3xx_color_swap swap
= rsc
->layout
.tile_mode
? WZYX
: fd6_pipe2swap(pfmt
);
965 enum a3xx_msaa_samples samples
=
966 fd_msaa_samples(rsc
->base
.nr_samples
);
967 uint32_t tile_mode
= fd_resource_tile_mode(&rsc
->base
, psurf
->u
.tex
.level
);
970 A6XX_RB_BLIT_DST_INFO(.tile_mode
= tile_mode
, .samples
= samples
,
971 .color_format
= format
, .color_swap
= swap
, .flags
= ubwc_enabled
),
972 A6XX_RB_BLIT_DST(.bo
= rsc
->bo
, .bo_offset
= offset
),
973 A6XX_RB_BLIT_DST_PITCH(.a6xx_rb_blit_dst_pitch
= stride
),
974 A6XX_RB_BLIT_DST_ARRAY_PITCH(.a6xx_rb_blit_dst_array_pitch
= size
));
976 OUT_REG(ring
, A6XX_RB_BLIT_BASE_GMEM(.dword
= base
));
979 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_FLAG_DST_LO
, 3);
980 fd6_emit_flag_reference(ring
, rsc
,
981 psurf
->u
.tex
.level
, psurf
->u
.tex
.first_layer
);
984 fd6_emit_blit(batch
, ring
);
988 emit_restore_blit(struct fd_batch
*batch
,
989 struct fd_ringbuffer
*ring
,
991 struct pipe_surface
*psurf
,
994 bool stencil
= (buffer
== FD_BUFFER_STENCIL
);
996 OUT_REG(ring
, A6XX_RB_BLIT_INFO(
997 .gmem
= true, .unk0
= true,
998 .depth
= (buffer
== FD_BUFFER_DEPTH
),
999 .integer
= util_format_is_pure_integer(psurf
->format
)));
1001 emit_blit(batch
, ring
, base
, psurf
, stencil
);
1005 emit_clears(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
)
1007 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
1008 struct fd_gmem_stateobj
*gmem
= &batch
->ctx
->gmem
;
1009 enum a3xx_msaa_samples samples
= fd_msaa_samples(pfb
->samples
);
1011 uint32_t buffers
= batch
->fast_cleared
;
1013 if (buffers
& PIPE_CLEAR_COLOR
) {
1015 for (int i
= 0; i
< pfb
->nr_cbufs
; i
++) {
1016 union pipe_color_union
*color
= &batch
->clear_color
[i
];
1017 union util_color uc
= {0};
1022 if (!(buffers
& (PIPE_CLEAR_COLOR0
<< i
)))
1025 enum pipe_format pfmt
= pfb
->cbufs
[i
]->format
;
1027 // XXX I think RB_CLEAR_COLOR_DWn wants to take into account SWAP??
1028 union pipe_color_union swapped
;
1029 switch (fd6_pipe2swap(pfmt
)) {
1031 swapped
.ui
[0] = color
->ui
[0];
1032 swapped
.ui
[1] = color
->ui
[1];
1033 swapped
.ui
[2] = color
->ui
[2];
1034 swapped
.ui
[3] = color
->ui
[3];
1037 swapped
.ui
[2] = color
->ui
[0];
1038 swapped
.ui
[1] = color
->ui
[1];
1039 swapped
.ui
[0] = color
->ui
[2];
1040 swapped
.ui
[3] = color
->ui
[3];
1043 swapped
.ui
[3] = color
->ui
[0];
1044 swapped
.ui
[0] = color
->ui
[1];
1045 swapped
.ui
[1] = color
->ui
[2];
1046 swapped
.ui
[2] = color
->ui
[3];
1049 swapped
.ui
[3] = color
->ui
[0];
1050 swapped
.ui
[2] = color
->ui
[1];
1051 swapped
.ui
[1] = color
->ui
[2];
1052 swapped
.ui
[0] = color
->ui
[3];
1056 if (util_format_is_pure_uint(pfmt
)) {
1057 util_format_write_4ui(pfmt
, swapped
.ui
, 0, &uc
, 0, 0, 0, 1, 1);
1058 } else if (util_format_is_pure_sint(pfmt
)) {
1059 util_format_write_4i(pfmt
, swapped
.i
, 0, &uc
, 0, 0, 0, 1, 1);
1061 util_pack_color(swapped
.f
, pfmt
, &uc
);
1064 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_DST_INFO
, 1);
1065 OUT_RING(ring
, A6XX_RB_BLIT_DST_INFO_TILE_MODE(TILE6_LINEAR
) |
1066 A6XX_RB_BLIT_DST_INFO_SAMPLES(samples
) |
1067 A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(fd6_pipe2color(pfmt
)));
1069 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_INFO
, 1);
1070 OUT_RING(ring
, A6XX_RB_BLIT_INFO_GMEM
|
1071 A6XX_RB_BLIT_INFO_CLEAR_MASK(0xf));
1073 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_BASE_GMEM
, 1);
1074 OUT_RING(ring
, gmem
->cbuf_base
[i
]);
1076 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_88D0
, 1);
1079 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_CLEAR_COLOR_DW0
, 4);
1080 OUT_RING(ring
, uc
.ui
[0]);
1081 OUT_RING(ring
, uc
.ui
[1]);
1082 OUT_RING(ring
, uc
.ui
[2]);
1083 OUT_RING(ring
, uc
.ui
[3]);
1085 fd6_emit_blit(batch
, ring
);
1089 const bool has_depth
= pfb
->zsbuf
;
1090 const bool has_separate_stencil
=
1091 has_depth
&& fd_resource(pfb
->zsbuf
->texture
)->stencil
;
1093 /* First clear depth or combined depth/stencil. */
1094 if ((has_depth
&& (buffers
& PIPE_CLEAR_DEPTH
)) ||
1095 (!has_separate_stencil
&& (buffers
& PIPE_CLEAR_STENCIL
))) {
1096 enum pipe_format pfmt
= pfb
->zsbuf
->format
;
1097 uint32_t clear_value
;
1100 if (has_separate_stencil
) {
1101 pfmt
= util_format_get_depth_only(pfb
->zsbuf
->format
);
1102 clear_value
= util_pack_z(pfmt
, batch
->clear_depth
);
1104 pfmt
= pfb
->zsbuf
->format
;
1105 clear_value
= util_pack_z_stencil(pfmt
, batch
->clear_depth
,
1106 batch
->clear_stencil
);
1109 if (buffers
& PIPE_CLEAR_DEPTH
)
1112 if (!has_separate_stencil
&& (buffers
& PIPE_CLEAR_STENCIL
))
1115 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_DST_INFO
, 1);
1116 OUT_RING(ring
, A6XX_RB_BLIT_DST_INFO_TILE_MODE(TILE6_LINEAR
) |
1117 A6XX_RB_BLIT_DST_INFO_SAMPLES(samples
) |
1118 A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(fd6_pipe2color(pfmt
)));
1120 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_INFO
, 1);
1121 OUT_RING(ring
, A6XX_RB_BLIT_INFO_GMEM
|
1122 // XXX UNK0 for separate stencil ??
1123 A6XX_RB_BLIT_INFO_DEPTH
|
1124 A6XX_RB_BLIT_INFO_CLEAR_MASK(mask
));
1126 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_BASE_GMEM
, 1);
1127 OUT_RING(ring
, gmem
->zsbuf_base
[0]);
1129 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_88D0
, 1);
1132 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_CLEAR_COLOR_DW0
, 1);
1133 OUT_RING(ring
, clear_value
);
1135 fd6_emit_blit(batch
, ring
);
1138 /* Then clear the separate stencil buffer in case of 32 bit depth
1139 * formats with separate stencil. */
1140 if (has_separate_stencil
&& (buffers
& PIPE_CLEAR_STENCIL
)) {
1141 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_DST_INFO
, 1);
1142 OUT_RING(ring
, A6XX_RB_BLIT_DST_INFO_TILE_MODE(TILE6_LINEAR
) |
1143 A6XX_RB_BLIT_DST_INFO_SAMPLES(samples
) |
1144 A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(RB6_R8_UINT
));
1146 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_INFO
, 1);
1147 OUT_RING(ring
, A6XX_RB_BLIT_INFO_GMEM
|
1148 //A6XX_RB_BLIT_INFO_UNK0 |
1149 A6XX_RB_BLIT_INFO_DEPTH
|
1150 A6XX_RB_BLIT_INFO_CLEAR_MASK(0x1));
1152 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_BASE_GMEM
, 1);
1153 OUT_RING(ring
, gmem
->zsbuf_base
[1]);
1155 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_88D0
, 1);
1158 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_CLEAR_COLOR_DW0
, 1);
1159 OUT_RING(ring
, batch
->clear_stencil
& 0xff);
1161 fd6_emit_blit(batch
, ring
);
1166 * transfer from system memory to gmem
1169 emit_restore_blits(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
)
1171 struct fd_context
*ctx
= batch
->ctx
;
1172 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
1173 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
1175 if (batch
->restore
& FD_BUFFER_COLOR
) {
1177 for (i
= 0; i
< pfb
->nr_cbufs
; i
++) {
1180 if (!(batch
->restore
& (PIPE_CLEAR_COLOR0
<< i
)))
1182 emit_restore_blit(batch
, ring
, gmem
->cbuf_base
[i
], pfb
->cbufs
[i
],
1187 if (batch
->restore
& (FD_BUFFER_DEPTH
| FD_BUFFER_STENCIL
)) {
1188 struct fd_resource
*rsc
= fd_resource(pfb
->zsbuf
->texture
);
1190 if (!rsc
->stencil
|| (batch
->restore
& FD_BUFFER_DEPTH
)) {
1191 emit_restore_blit(batch
, ring
, gmem
->zsbuf_base
[0], pfb
->zsbuf
,
1194 if (rsc
->stencil
&& (batch
->restore
& FD_BUFFER_STENCIL
)) {
1195 emit_restore_blit(batch
, ring
, gmem
->zsbuf_base
[1], pfb
->zsbuf
,
1202 prepare_tile_setup_ib(struct fd_batch
*batch
)
1204 batch
->tile_setup
= fd_submit_new_ringbuffer(batch
->submit
, 0x1000,
1205 FD_RINGBUFFER_STREAMING
);
1207 set_blit_scissor(batch
, batch
->tile_setup
);
1209 emit_restore_blits(batch
, batch
->tile_setup
);
1210 emit_clears(batch
, batch
->tile_setup
);
1214 * transfer from system memory to gmem
1217 fd6_emit_tile_mem2gmem(struct fd_batch
*batch
, struct fd_tile
*tile
)
1221 /* before IB to rendering cmds: */
1223 fd6_emit_tile_renderprep(struct fd_batch
*batch
, struct fd_tile
*tile
)
1225 if (batch
->fast_cleared
|| !use_hw_binning(batch
)) {
1226 fd6_emit_ib(batch
->gmem
, batch
->tile_setup
);
1228 emit_conditional_ib(batch
, tile
, batch
->tile_setup
);
1233 emit_resolve_blit(struct fd_batch
*batch
,
1234 struct fd_ringbuffer
*ring
,
1236 struct pipe_surface
*psurf
,
1240 bool stencil
= false;
1242 if (!fd_resource(psurf
->texture
)->valid
)
1246 case FD_BUFFER_COLOR
:
1248 case FD_BUFFER_STENCIL
:
1249 info
|= A6XX_RB_BLIT_INFO_UNK0
;
1252 case FD_BUFFER_DEPTH
:
1253 info
|= A6XX_RB_BLIT_INFO_DEPTH
;
1257 if (util_format_is_pure_integer(psurf
->format
))
1258 info
|= A6XX_RB_BLIT_INFO_INTEGER
;
1260 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_INFO
, 1);
1261 OUT_RING(ring
, info
);
1263 emit_blit(batch
, ring
, base
, psurf
, stencil
);
1267 * transfer from gmem to system memory (ie. normal RAM)
1271 prepare_tile_fini_ib(struct fd_batch
*batch
)
1273 struct fd_context
*ctx
= batch
->ctx
;
1274 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
1275 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
1276 struct fd_ringbuffer
*ring
;
1278 batch
->tile_fini
= fd_submit_new_ringbuffer(batch
->submit
, 0x1000,
1279 FD_RINGBUFFER_STREAMING
);
1280 ring
= batch
->tile_fini
;
1282 set_blit_scissor(batch
, ring
);
1284 if (batch
->resolve
& (FD_BUFFER_DEPTH
| FD_BUFFER_STENCIL
)) {
1285 struct fd_resource
*rsc
= fd_resource(pfb
->zsbuf
->texture
);
1287 if (!rsc
->stencil
|| (batch
->resolve
& FD_BUFFER_DEPTH
)) {
1288 emit_resolve_blit(batch
, ring
,
1289 gmem
->zsbuf_base
[0], pfb
->zsbuf
,
1292 if (rsc
->stencil
&& (batch
->resolve
& FD_BUFFER_STENCIL
)) {
1293 emit_resolve_blit(batch
, ring
,
1294 gmem
->zsbuf_base
[1], pfb
->zsbuf
,
1299 if (batch
->resolve
& FD_BUFFER_COLOR
) {
1301 for (i
= 0; i
< pfb
->nr_cbufs
; i
++) {
1304 if (!(batch
->resolve
& (PIPE_CLEAR_COLOR0
<< i
)))
1306 emit_resolve_blit(batch
, ring
, gmem
->cbuf_base
[i
], pfb
->cbufs
[i
],
1313 fd6_emit_tile(struct fd_batch
*batch
, struct fd_tile
*tile
)
1315 if (!use_hw_binning(batch
)) {
1316 fd6_emit_ib(batch
->gmem
, batch
->draw
);
1318 emit_conditional_ib(batch
, tile
, batch
->draw
);
1323 fd6_emit_tile_gmem2mem(struct fd_batch
*batch
, struct fd_tile
*tile
)
1325 struct fd_ringbuffer
*ring
= batch
->gmem
;
1327 if (use_hw_binning(batch
)) {
1328 /* Conditionally execute if no VSC overflow: */
1330 BEGIN_RING(ring
, 7); /* ensure if/else doesn't get split */
1332 OUT_PKT7(ring
, CP_REG_TEST
, 1);
1333 OUT_RING(ring
, A6XX_CP_REG_TEST_0_REG(OVERFLOW_FLAG_REG
) |
1334 A6XX_CP_REG_TEST_0_BIT(0) |
1335 A6XX_CP_REG_TEST_0_WAIT_FOR_ME
);
1337 OUT_PKT7(ring
, CP_COND_REG_EXEC
, 2);
1338 OUT_RING(ring
, 0x10000000);
1339 OUT_RING(ring
, 2); /* conditionally execute next 2 dwords */
1341 /* if (no overflow) */ {
1342 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
1343 OUT_RING(ring
, A6XX_CP_SET_MARKER_0_MODE(0x5) | 0x10);
1347 OUT_PKT7(ring
, CP_SET_DRAW_STATE
, 3);
1348 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(0) |
1349 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
1350 CP_SET_DRAW_STATE__0_GROUP_ID(0));
1351 OUT_RING(ring
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
1352 OUT_RING(ring
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
1354 OUT_PKT7(ring
, CP_SKIP_IB2_ENABLE_LOCAL
, 1);
1355 OUT_RING(ring
, 0x0);
1357 emit_marker6(ring
, 7);
1358 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
1359 OUT_RING(ring
, A6XX_CP_SET_MARKER_0_MODE(RM6_RESOLVE
) | 0x10);
1360 emit_marker6(ring
, 7);
1362 if (batch
->fast_cleared
|| !use_hw_binning(batch
)) {
1363 fd6_emit_ib(batch
->gmem
, batch
->tile_fini
);
1365 emit_conditional_ib(batch
, tile
, batch
->tile_fini
);
1368 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
1369 OUT_RING(ring
, A6XX_CP_SET_MARKER_0_MODE(0x7));
1373 fd6_emit_tile_fini(struct fd_batch
*batch
)
1375 struct fd_ringbuffer
*ring
= batch
->gmem
;
1377 OUT_PKT4(ring
, REG_A6XX_GRAS_LRZ_CNTL
, 1);
1378 OUT_RING(ring
, A6XX_GRAS_LRZ_CNTL_ENABLE
| A6XX_GRAS_LRZ_CNTL_UNK3
);
1380 fd6_emit_lrz_flush(ring
);
1382 fd6_event_write(batch
, ring
, CACHE_FLUSH_TS
, true);
1384 if (use_hw_binning(batch
)) {
1385 check_vsc_overflow(batch
->ctx
);
1390 emit_sysmem_clears(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
)
1392 struct fd_context
*ctx
= batch
->ctx
;
1393 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
1395 uint32_t buffers
= batch
->fast_cleared
;
1397 if (buffers
& PIPE_CLEAR_COLOR
) {
1398 for (int i
= 0; i
< pfb
->nr_cbufs
; i
++) {
1399 union pipe_color_union
*color
= &batch
->clear_color
[i
];
1404 if (!(buffers
& (PIPE_CLEAR_COLOR0
<< i
)))
1407 fd6_clear_surface(ctx
, ring
,
1408 pfb
->cbufs
[i
], pfb
->width
, pfb
->height
, color
);
1411 if (buffers
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) {
1412 union pipe_color_union value
= {};
1414 const bool has_depth
= pfb
->zsbuf
;
1415 struct pipe_resource
*separate_stencil
=
1416 has_depth
&& fd_resource(pfb
->zsbuf
->texture
)->stencil
?
1417 &fd_resource(pfb
->zsbuf
->texture
)->stencil
->base
: NULL
;
1419 if ((has_depth
&& (buffers
& PIPE_CLEAR_DEPTH
)) ||
1420 (!separate_stencil
&& (buffers
& PIPE_CLEAR_STENCIL
))) {
1421 value
.f
[0] = batch
->clear_depth
;
1422 value
.ui
[1] = batch
->clear_stencil
;
1423 fd6_clear_surface(ctx
, ring
,
1424 pfb
->zsbuf
, pfb
->width
, pfb
->height
, &value
);
1427 if (separate_stencil
&& (buffers
& PIPE_CLEAR_STENCIL
)) {
1428 value
.ui
[0] = batch
->clear_stencil
;
1430 struct pipe_surface stencil_surf
= *pfb
->zsbuf
;
1431 stencil_surf
.texture
= separate_stencil
;
1433 fd6_clear_surface(ctx
, ring
,
1434 &stencil_surf
, pfb
->width
, pfb
->height
, &value
);
1438 fd6_event_write(batch
, ring
, 0x1d, true);
1442 setup_tess_buffers(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
)
1444 struct fd_context
*ctx
= batch
->ctx
;
1446 batch
->tessfactor_bo
= fd_bo_new(ctx
->screen
->dev
,
1447 batch
->tessfactor_size
,
1448 DRM_FREEDRENO_GEM_TYPE_KMEM
, "tessfactor");
1450 batch
->tessparam_bo
= fd_bo_new(ctx
->screen
->dev
,
1451 batch
->tessparam_size
,
1452 DRM_FREEDRENO_GEM_TYPE_KMEM
, "tessparam");
1454 OUT_PKT4(ring
, REG_A6XX_PC_TESSFACTOR_ADDR_LO
, 2);
1455 OUT_RELOCW(ring
, batch
->tessfactor_bo
, 0, 0, 0);
1457 batch
->tess_addrs_constobj
->cur
= batch
->tess_addrs_constobj
->start
;
1458 OUT_RELOCW(batch
->tess_addrs_constobj
, batch
->tessparam_bo
, 0, 0, 0);
1459 OUT_RELOCW(batch
->tess_addrs_constobj
, batch
->tessfactor_bo
, 0, 0, 0);
1463 fd6_emit_sysmem_prep(struct fd_batch
*batch
)
1465 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
1466 struct fd_ringbuffer
*ring
= batch
->gmem
;
1468 fd6_emit_restore(batch
, ring
);
1470 if (pfb
->width
> 0 && pfb
->height
> 0)
1471 set_scissor(ring
, 0, 0, pfb
->width
- 1, pfb
->height
- 1);
1473 set_scissor(ring
, 0, 0, 0, 0);
1475 set_window_offset(ring
, 0, 0);
1477 set_bin_size(ring
, 0, 0, 0xc00000); /* 0xc00000 = BYPASS? */
1479 emit_sysmem_clears(batch
, ring
);
1481 fd6_emit_lrz_flush(ring
);
1483 emit_marker6(ring
, 7);
1484 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
1485 OUT_RING(ring
, A6XX_CP_SET_MARKER_0_MODE(RM6_BYPASS
) | 0x10); /* | 0x10 ? */
1486 emit_marker6(ring
, 7);
1488 if (batch
->tessellation
)
1489 setup_tess_buffers(batch
, ring
);
1491 OUT_PKT7(ring
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1492 OUT_RING(ring
, 0x0);
1494 fd6_event_write(batch
, ring
, PC_CCU_INVALIDATE_COLOR
, false);
1495 fd6_cache_inv(batch
, ring
);
1497 fd_wfi(batch
, ring
);
1498 OUT_PKT4(ring
, REG_A6XX_RB_CCU_CNTL
, 1);
1499 OUT_RING(ring
, fd6_context(batch
->ctx
)->magic
.RB_CCU_CNTL_bypass
);
1501 /* enable stream-out, with sysmem there is only one pass: */
1502 OUT_PKT4(ring
, REG_A6XX_VPC_SO_OVERRIDE
, 1);
1505 OUT_PKT7(ring
, CP_SET_VISIBILITY_OVERRIDE
, 1);
1506 OUT_RING(ring
, 0x1);
1508 emit_zs(ring
, pfb
->zsbuf
, NULL
);
1509 emit_mrt(ring
, pfb
, NULL
);
1510 emit_msaa(ring
, pfb
->samples
);
1512 update_render_cntl(batch
, pfb
, false);
1516 fd6_emit_sysmem_fini(struct fd_batch
*batch
)
1518 struct fd_ringbuffer
*ring
= batch
->gmem
;
1520 OUT_PKT7(ring
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1521 OUT_RING(ring
, 0x0);
1523 fd6_emit_lrz_flush(ring
);
1525 fd6_event_write(batch
, ring
, UNK_1D
, true);
1529 fd6_gmem_init(struct pipe_context
*pctx
)
1531 struct fd_context
*ctx
= fd_context(pctx
);
1533 ctx
->emit_tile_init
= fd6_emit_tile_init
;
1534 ctx
->emit_tile_prep
= fd6_emit_tile_prep
;
1535 ctx
->emit_tile_mem2gmem
= fd6_emit_tile_mem2gmem
;
1536 ctx
->emit_tile_renderprep
= fd6_emit_tile_renderprep
;
1537 ctx
->emit_tile
= fd6_emit_tile
;
1538 ctx
->emit_tile_gmem2mem
= fd6_emit_tile_gmem2mem
;
1539 ctx
->emit_tile_fini
= fd6_emit_tile_fini
;
1540 ctx
->emit_sysmem_prep
= fd6_emit_sysmem_prep
;
1541 ctx
->emit_sysmem_fini
= fd6_emit_sysmem_fini
;