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_log.h"
38 #include "freedreno_state.h"
39 #include "freedreno_resource.h"
41 #include "fd6_blitter.h"
43 #include "fd6_context.h"
46 #include "fd6_program.h"
47 #include "fd6_format.h"
48 #include "fd6_resource.h"
53 * Emits the flags registers, suitable for RB_MRT_FLAG_BUFFER,
54 * RB_DEPTH_FLAG_BUFFER, SP_PS_2D_SRC_FLAGS, and RB_BLIT_FLAG_DST.
57 fd6_emit_flag_reference(struct fd_ringbuffer
*ring
, struct fd_resource
*rsc
,
60 if (fd_resource_ubwc_enabled(rsc
, level
)) {
61 OUT_RELOCW(ring
, rsc
->bo
, fd_resource_ubwc_offset(rsc
, level
, layer
), 0, 0);
63 A6XX_RB_MRT_FLAG_BUFFER_PITCH_PITCH(rsc
->layout
.ubwc_slices
[level
].pitch
) |
64 A6XX_RB_MRT_FLAG_BUFFER_PITCH_ARRAY_PITCH(rsc
->layout
.ubwc_layer_size
>> 2));
66 OUT_RING(ring
, 0x00000000); /* RB_MRT_FLAG_BUFFER[i].ADDR_LO */
67 OUT_RING(ring
, 0x00000000); /* RB_MRT_FLAG_BUFFER[i].ADDR_HI */
68 OUT_RING(ring
, 0x00000000);
73 emit_mrt(struct fd_ringbuffer
*ring
, struct pipe_framebuffer_state
*pfb
,
74 const struct fd_gmem_stateobj
*gmem
)
76 unsigned char mrt_comp
[A6XX_MAX_RENDER_TARGETS
] = {0};
77 unsigned srgb_cntl
= 0;
83 for (i
= 0; i
< pfb
->nr_cbufs
; i
++) {
84 enum a6xx_format format
= 0;
85 enum a3xx_color_swap swap
= WZYX
;
86 bool sint
= false, uint
= false;
87 struct fd_resource
*rsc
= NULL
;
88 struct fdl_slice
*slice
= NULL
;
98 struct pipe_surface
*psurf
= pfb
->cbufs
[i
];
99 enum pipe_format pformat
= psurf
->format
;
100 rsc
= fd_resource(psurf
->texture
);
104 uint32_t base
= gmem
? gmem
->cbuf_base
[i
] : 0;
105 slice
= fd_resource_slice(rsc
, psurf
->u
.tex
.level
);
106 format
= fd6_pipe2color(pformat
);
107 sint
= util_format_is_pure_sint(pformat
);
108 uint
= util_format_is_pure_uint(pformat
);
110 if (util_format_is_srgb(pformat
))
111 srgb_cntl
|= (1 << i
);
113 offset
= fd_resource_offset(rsc
, psurf
->u
.tex
.level
,
114 psurf
->u
.tex
.first_layer
);
116 stride
= slice
->pitch
* rsc
->layout
.cpp
;
117 swap
= fd6_resource_swap(rsc
, pformat
);
119 tile_mode
= fd_resource_tile_mode(psurf
->texture
, psurf
->u
.tex
.level
);
121 if (psurf
->u
.tex
.first_layer
< psurf
->u
.tex
.last_layer
) {
123 if (psurf
->texture
->target
== PIPE_TEXTURE_2D_ARRAY
&& psurf
->texture
->nr_samples
> 0)
124 type
= LAYER_MULTISAMPLE_ARRAY
;
125 else if (psurf
->texture
->target
== PIPE_TEXTURE_2D_ARRAY
)
126 type
= LAYER_2D_ARRAY
;
127 else if (psurf
->texture
->target
== PIPE_TEXTURE_CUBE
)
128 type
= LAYER_CUBEMAP
;
129 else if (psurf
->texture
->target
== PIPE_TEXTURE_3D
)
133 debug_assert((offset
+ slice
->size0
) <= fd_bo_size(rsc
->bo
));
136 A6XX_RB_MRT_BUF_INFO(i
,
137 .color_format
= format
,
138 .color_tile_mode
= tile_mode
,
140 A6XX_RB_MRT_PITCH(i
, .a6xx_rb_mrt_pitch
= stride
),
141 A6XX_RB_MRT_ARRAY_PITCH(i
, .a6xx_rb_mrt_array_pitch
= slice
->size0
),
142 A6XX_RB_MRT_BASE(i
, .bo
= rsc
->bo
, .bo_offset
= offset
),
143 A6XX_RB_MRT_BASE_GMEM(i
, .unknown
= base
));
146 A6XX_SP_FS_MRT_REG(i
, .color_format
= format
,
147 .color_sint
= sint
, .color_uint
= uint
));
149 OUT_PKT4(ring
, REG_A6XX_RB_MRT_FLAG_BUFFER(i
), 3);
150 fd6_emit_flag_reference(ring
, rsc
,
151 psurf
->u
.tex
.level
, psurf
->u
.tex
.first_layer
);
154 OUT_REG(ring
, A6XX_RB_SRGB_CNTL(.dword
= srgb_cntl
));
155 OUT_REG(ring
, A6XX_SP_SRGB_CNTL(.dword
= srgb_cntl
));
157 OUT_REG(ring
, A6XX_RB_RENDER_COMPONENTS(
165 .rt7
= mrt_comp
[7]));
167 OUT_REG(ring
, A6XX_SP_FS_RENDER_COMPONENTS(
175 .rt7
= mrt_comp
[7]));
177 OUT_REG(ring
, A6XX_GRAS_LAYER_CNTL(.layered
= layered
, .type
= type
));
181 emit_zs(struct fd_ringbuffer
*ring
, struct pipe_surface
*zsbuf
,
182 const struct fd_gmem_stateobj
*gmem
)
185 struct fd_resource
*rsc
= fd_resource(zsbuf
->texture
);
186 enum a6xx_depth_format fmt
= fd6_pipe2depth(zsbuf
->format
);
187 struct fdl_slice
*slice
= fd_resource_slice(rsc
, 0);
188 uint32_t stride
= slice
->pitch
* rsc
->layout
.cpp
;
189 uint32_t size
= slice
->size0
;
190 uint32_t base
= gmem
? gmem
->zsbuf_base
[0] : 0;
191 uint32_t offset
= fd_resource_offset(rsc
, zsbuf
->u
.tex
.level
,
192 zsbuf
->u
.tex
.first_layer
);
195 A6XX_RB_DEPTH_BUFFER_INFO(.depth_format
= fmt
),
196 A6XX_RB_DEPTH_BUFFER_PITCH(.a6xx_rb_depth_buffer_pitch
= stride
),
197 A6XX_RB_DEPTH_BUFFER_ARRAY_PITCH(.a6xx_rb_depth_buffer_array_pitch
= size
),
198 A6XX_RB_DEPTH_BUFFER_BASE(.bo
= rsc
->bo
, .bo_offset
= offset
),
199 A6XX_RB_DEPTH_BUFFER_BASE_GMEM(.dword
= base
));
201 OUT_REG(ring
, A6XX_GRAS_SU_DEPTH_BUFFER_INFO(.depth_format
= fmt
));
203 OUT_PKT4(ring
, REG_A6XX_RB_DEPTH_FLAG_BUFFER_BASE_LO
, 3);
204 fd6_emit_flag_reference(ring
, rsc
,
205 zsbuf
->u
.tex
.level
, zsbuf
->u
.tex
.first_layer
);
209 A6XX_GRAS_LRZ_BUFFER_BASE(.bo
= rsc
->lrz
),
210 A6XX_GRAS_LRZ_BUFFER_PITCH(.pitch
= rsc
->lrz_pitch
),
211 // XXX a6xx seems to use a different buffer here.. not sure what for..
212 A6XX_GRAS_LRZ_FAST_CLEAR_BUFFER_BASE_LO(0),
213 A6XX_GRAS_LRZ_FAST_CLEAR_BUFFER_BASE_HI(0));
215 OUT_PKT4(ring
, REG_A6XX_GRAS_LRZ_BUFFER_BASE_LO
, 5);
216 OUT_RING(ring
, 0x00000000);
217 OUT_RING(ring
, 0x00000000);
218 OUT_RING(ring
, 0x00000000); /* GRAS_LRZ_BUFFER_PITCH */
219 OUT_RING(ring
, 0x00000000); /* GRAS_LRZ_FAST_CLEAR_BUFFER_BASE_LO */
220 OUT_RING(ring
, 0x00000000);
223 /* NOTE: blob emits GRAS_LRZ_CNTL plus GRAZ_LRZ_BUFFER_BASE
224 * plus this CP_EVENT_WRITE at the end in it's own IB..
226 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
227 OUT_RING(ring
, CP_EVENT_WRITE_0_EVENT(UNK_25
));
230 struct fdl_slice
*slice
= fd_resource_slice(rsc
->stencil
, 0);
231 stride
= slice
->pitch
* rsc
->stencil
->layout
.cpp
;
233 uint32_t base
= gmem
? gmem
->zsbuf_base
[1] : 0;
236 A6XX_RB_STENCIL_INFO(.separate_stencil
= true),
237 A6XX_RB_STENCIL_BUFFER_PITCH(.a6xx_rb_stencil_buffer_pitch
= stride
),
238 A6XX_RB_STENCIL_BUFFER_ARRAY_PITCH(.a6xx_rb_stencil_buffer_array_pitch
= size
),
239 A6XX_RB_STENCIL_BUFFER_BASE(.bo
= rsc
->stencil
->bo
),
240 A6XX_RB_STENCIL_BUFFER_BASE_GMEM(.dword
= base
));
242 OUT_REG(ring
, A6XX_RB_STENCIL_INFO(0));
245 OUT_PKT4(ring
, REG_A6XX_RB_DEPTH_BUFFER_INFO
, 6);
246 OUT_RING(ring
, A6XX_RB_DEPTH_BUFFER_INFO_DEPTH_FORMAT(DEPTH6_NONE
));
247 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_BUFFER_PITCH */
248 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_BUFFER_ARRAY_PITCH */
249 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_BUFFER_BASE_LO */
250 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_BUFFER_BASE_HI */
251 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_BUFFER_BASE_GMEM */
253 OUT_REG(ring
, A6XX_GRAS_SU_DEPTH_BUFFER_INFO(.depth_format
= DEPTH6_NONE
));
255 OUT_PKT4(ring
, REG_A6XX_GRAS_LRZ_BUFFER_BASE_LO
, 5);
256 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_FLAG_BUFFER_BASE_LO */
257 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_FLAG_BUFFER_BASE_HI */
258 OUT_RING(ring
, 0x00000000); /* GRAS_LRZ_BUFFER_PITCH */
259 OUT_RING(ring
, 0x00000000); /* GRAS_LRZ_FAST_CLEAR_BUFFER_BASE_LO */
260 OUT_RING(ring
, 0x00000000); /* GRAS_LRZ_FAST_CLEAR_BUFFER_BASE_HI */
262 OUT_REG(ring
, A6XX_RB_STENCIL_INFO(0));
267 use_hw_binning(struct fd_batch
*batch
)
269 const struct fd_gmem_stateobj
*gmem
= batch
->gmem_state
;
271 // TODO figure out hw limits for binning
273 return fd_binning_enabled
&& ((gmem
->nbins_x
* gmem
->nbins_y
) >= 2) &&
274 (batch
->num_draws
> 0);
278 patch_fb_read(struct fd_batch
*batch
)
280 const struct fd_gmem_stateobj
*gmem
= batch
->gmem_state
;
282 for (unsigned i
= 0; i
< fd_patch_num_elements(&batch
->fb_read_patches
); i
++) {
283 struct fd_cs_patch
*patch
= fd_patch_element(&batch
->fb_read_patches
, i
);
284 *patch
->cs
= patch
->val
| A6XX_TEX_CONST_2_PITCH(gmem
->bin_w
* gmem
->cbuf_cpp
[0]);
286 util_dynarray_clear(&batch
->fb_read_patches
);
290 update_render_cntl(struct fd_batch
*batch
, struct pipe_framebuffer_state
*pfb
, bool binning
)
292 struct fd_ringbuffer
*ring
= batch
->gmem
;
294 bool depth_ubwc_enable
= false;
295 uint32_t mrts_ubwc_enable
= 0;
299 struct fd_resource
*rsc
= fd_resource(pfb
->zsbuf
->texture
);
300 depth_ubwc_enable
= fd_resource_ubwc_enabled(rsc
, pfb
->zsbuf
->u
.tex
.level
);
303 for (i
= 0; i
< pfb
->nr_cbufs
; i
++) {
307 struct pipe_surface
*psurf
= pfb
->cbufs
[i
];
308 struct fd_resource
*rsc
= fd_resource(psurf
->texture
);
312 if (fd_resource_ubwc_enabled(rsc
, psurf
->u
.tex
.level
))
313 mrts_ubwc_enable
|= 1 << i
;
316 cntl
|= A6XX_RB_RENDER_CNTL_UNK4
;
318 cntl
|= A6XX_RB_RENDER_CNTL_BINNING
;
320 OUT_PKT7(ring
, CP_REG_WRITE
, 3);
321 OUT_RING(ring
, CP_REG_WRITE_0_TRACKER(TRACK_RENDER_CNTL
));
322 OUT_RING(ring
, REG_A6XX_RB_RENDER_CNTL
);
323 OUT_RING(ring
, cntl
|
324 COND(depth_ubwc_enable
, A6XX_RB_RENDER_CNTL_FLAG_DEPTH
) |
325 A6XX_RB_RENDER_CNTL_FLAG_MRTS(mrts_ubwc_enable
));
328 #define VSC_DATA_SIZE(pitch) ((pitch) * 32 + 0x100) /* extra size to store VSC_SIZE */
329 #define VSC_DATA2_SIZE(pitch) ((pitch) * 32)
332 update_vsc_pipe(struct fd_batch
*batch
)
334 struct fd_context
*ctx
= batch
->ctx
;
335 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
336 const struct fd_gmem_stateobj
*gmem
= batch
->gmem_state
;
337 struct fd_ringbuffer
*ring
= batch
->gmem
;
341 if (!fd6_ctx
->vsc_data
) {
342 fd6_ctx
->vsc_data
= fd_bo_new(ctx
->screen
->dev
,
343 VSC_DATA_SIZE(fd6_ctx
->vsc_data_pitch
),
344 DRM_FREEDRENO_GEM_TYPE_KMEM
, "vsc_data");
347 if (!fd6_ctx
->vsc_data2
) {
348 fd6_ctx
->vsc_data2
= fd_bo_new(ctx
->screen
->dev
,
349 VSC_DATA2_SIZE(fd6_ctx
->vsc_data2_pitch
),
350 DRM_FREEDRENO_GEM_TYPE_KMEM
, "vsc_data2");
354 A6XX_VSC_BIN_SIZE(.width
= gmem
->bin_w
, .height
= gmem
->bin_h
),
355 A6XX_VSC_SIZE_ADDRESS(.bo
= fd6_ctx
->vsc_data
, .bo_offset
= 32 * fd6_ctx
->vsc_data_pitch
));
357 OUT_REG(ring
, A6XX_VSC_BIN_COUNT(.nx
= gmem
->nbins_x
,
358 .ny
= gmem
->nbins_y
));
360 OUT_PKT4(ring
, REG_A6XX_VSC_PIPE_CONFIG_REG(0), 32);
361 for (i
= 0; i
< 32; i
++) {
362 const struct fd_vsc_pipe
*pipe
= &gmem
->vsc_pipe
[i
];
363 OUT_RING(ring
, A6XX_VSC_PIPE_CONFIG_REG_X(pipe
->x
) |
364 A6XX_VSC_PIPE_CONFIG_REG_Y(pipe
->y
) |
365 A6XX_VSC_PIPE_CONFIG_REG_W(pipe
->w
) |
366 A6XX_VSC_PIPE_CONFIG_REG_H(pipe
->h
));
370 A6XX_VSC_PIPE_DATA2_ADDRESS(.bo
= fd6_ctx
->vsc_data2
),
371 A6XX_VSC_PIPE_DATA2_PITCH(.dword
= fd6_ctx
->vsc_data2_pitch
),
372 A6XX_VSC_PIPE_DATA2_ARRAY_PITCH(.dword
= fd_bo_size(fd6_ctx
->vsc_data2
)));
375 A6XX_VSC_PIPE_DATA_ADDRESS(.bo
= fd6_ctx
->vsc_data
),
376 A6XX_VSC_PIPE_DATA_PITCH(.dword
= fd6_ctx
->vsc_data_pitch
),
377 A6XX_VSC_PIPE_DATA_ARRAY_PITCH(.dword
= fd_bo_size(fd6_ctx
->vsc_data
)));
380 /* TODO we probably have more than 8 scratch regs.. although the first
381 * 8 is what kernel dumps, and it is kinda useful to be able to see
382 * the value in kernel traces
384 #define OVERFLOW_FLAG_REG REG_A6XX_CP_SCRATCH_REG(0)
387 * If overflow is detected, either 0x1 (VSC_DATA overflow) or 0x3
388 * (VSC_DATA2 overflow) plus the size of the overflowed buffer is
389 * written to control->vsc_overflow. This allows the CPU to
390 * detect which buffer overflowed (and, since the current size is
391 * encoded as well, this protects against already-submitted but
392 * not executed batches from fooling the CPU into increasing the
393 * size again unnecessarily).
395 * To conditionally use VSC data in draw pass only if there is no
396 * overflow, we use a scratch reg (OVERFLOW_FLAG_REG) to hold 1
397 * if no overflow, or 0 in case of overflow. The value is inverted
398 * to make the CP_COND_REG_EXEC stuff easier.
401 emit_vsc_overflow_test(struct fd_batch
*batch
)
403 struct fd_ringbuffer
*ring
= batch
->gmem
;
404 const struct fd_gmem_stateobj
*gmem
= batch
->gmem_state
;
405 struct fd6_context
*fd6_ctx
= fd6_context(batch
->ctx
);
407 debug_assert((fd6_ctx
->vsc_data_pitch
& 0x3) == 0);
408 debug_assert((fd6_ctx
->vsc_data2_pitch
& 0x3) == 0);
410 /* Clear vsc_scratch: */
411 OUT_PKT7(ring
, CP_MEM_WRITE
, 3);
412 OUT_RELOCW(ring
, control_ptr(fd6_ctx
, vsc_scratch
));
415 /* Check for overflow, write vsc_scratch if detected: */
416 for (int i
= 0; i
< gmem
->num_vsc_pipes
; i
++) {
417 OUT_PKT7(ring
, CP_COND_WRITE5
, 8);
418 OUT_RING(ring
, CP_COND_WRITE5_0_FUNCTION(WRITE_GE
) |
419 CP_COND_WRITE5_0_WRITE_MEMORY
);
420 OUT_RING(ring
, CP_COND_WRITE5_1_POLL_ADDR_LO(REG_A6XX_VSC_SIZE_REG(i
)));
421 OUT_RING(ring
, CP_COND_WRITE5_2_POLL_ADDR_HI(0));
422 OUT_RING(ring
, CP_COND_WRITE5_3_REF(fd6_ctx
->vsc_data_pitch
));
423 OUT_RING(ring
, CP_COND_WRITE5_4_MASK(~0));
424 OUT_RELOCW(ring
, control_ptr(fd6_ctx
, vsc_scratch
)); /* WRITE_ADDR_LO/HI */
425 OUT_RING(ring
, CP_COND_WRITE5_7_WRITE_DATA(1 + fd6_ctx
->vsc_data_pitch
));
427 OUT_PKT7(ring
, CP_COND_WRITE5
, 8);
428 OUT_RING(ring
, CP_COND_WRITE5_0_FUNCTION(WRITE_GE
) |
429 CP_COND_WRITE5_0_WRITE_MEMORY
);
430 OUT_RING(ring
, CP_COND_WRITE5_1_POLL_ADDR_LO(REG_A6XX_VSC_SIZE2_REG(i
)));
431 OUT_RING(ring
, CP_COND_WRITE5_2_POLL_ADDR_HI(0));
432 OUT_RING(ring
, CP_COND_WRITE5_3_REF(fd6_ctx
->vsc_data2_pitch
));
433 OUT_RING(ring
, CP_COND_WRITE5_4_MASK(~0));
434 OUT_RELOCW(ring
, control_ptr(fd6_ctx
, vsc_scratch
)); /* WRITE_ADDR_LO/HI */
435 OUT_RING(ring
, CP_COND_WRITE5_7_WRITE_DATA(3 + fd6_ctx
->vsc_data2_pitch
));
438 OUT_PKT7(ring
, CP_WAIT_MEM_WRITES
, 0);
440 OUT_PKT7(ring
, CP_WAIT_FOR_ME
, 0);
442 OUT_PKT7(ring
, CP_MEM_TO_REG
, 3);
443 OUT_RING(ring
, CP_MEM_TO_REG_0_REG(OVERFLOW_FLAG_REG
) |
444 CP_MEM_TO_REG_0_CNT(0));
445 OUT_RELOC(ring
, control_ptr(fd6_ctx
, vsc_scratch
)); /* SRC_LO/HI */
448 * This is a bit awkward, we really want a way to invert the
449 * CP_REG_TEST/CP_COND_REG_EXEC logic, so that we can conditionally
450 * execute cmds to use hwbinning when a bit is *not* set. This
451 * dance is to invert OVERFLOW_FLAG_REG
453 * A CP_NOP packet is used to skip executing the 'else' clause
457 BEGIN_RING(ring
, 10); /* ensure if/else doesn't get split */
459 /* b0 will be set if VSC_DATA or VSC_DATA2 overflow: */
460 OUT_PKT7(ring
, CP_REG_TEST
, 1);
461 OUT_RING(ring
, A6XX_CP_REG_TEST_0_REG(OVERFLOW_FLAG_REG
) |
462 A6XX_CP_REG_TEST_0_BIT(0) |
463 A6XX_CP_REG_TEST_0_WAIT_FOR_ME
);
465 OUT_PKT7(ring
, CP_COND_REG_EXEC
, 2);
466 OUT_RING(ring
, CP_COND_REG_EXEC_0_MODE(PRED_TEST
));
467 OUT_RING(ring
, CP_COND_REG_EXEC_1_DWORDS(7));
471 * On overflow, mirror the value to control->vsc_overflow
472 * which CPU is checking to detect overflow (see
473 * check_vsc_overflow())
475 OUT_PKT7(ring
, CP_REG_TO_MEM
, 3);
476 OUT_RING(ring
, CP_REG_TO_MEM_0_REG(OVERFLOW_FLAG_REG
) |
477 CP_REG_TO_MEM_0_CNT(1 - 1));
478 OUT_RELOCW(ring
, control_ptr(fd6_ctx
, vsc_overflow
));
480 OUT_PKT4(ring
, OVERFLOW_FLAG_REG
, 1);
483 OUT_PKT7(ring
, CP_NOP
, 2); /* skip 'else' when 'if' is taken */
485 OUT_PKT4(ring
, OVERFLOW_FLAG_REG
, 1);
491 check_vsc_overflow(struct fd_context
*ctx
)
493 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
494 struct fd6_control
*control
= fd_bo_map(fd6_ctx
->control_mem
);
495 uint32_t vsc_overflow
= control
->vsc_overflow
;
500 /* clear overflow flag: */
501 control
->vsc_overflow
= 0;
503 unsigned buffer
= vsc_overflow
& 0x3;
504 unsigned size
= vsc_overflow
& ~0x3;
507 /* VSC_PIPE_DATA overflow: */
509 if (size
< fd6_ctx
->vsc_data_pitch
) {
510 /* we've already increased the size, this overflow is
511 * from a batch submitted before resize, but executed
517 fd_bo_del(fd6_ctx
->vsc_data
);
518 fd6_ctx
->vsc_data
= NULL
;
519 fd6_ctx
->vsc_data_pitch
*= 2;
521 debug_printf("resized VSC_DATA_PITCH to: 0x%x\n", fd6_ctx
->vsc_data_pitch
);
523 } else if (buffer
== 0x3) {
524 /* VSC_PIPE_DATA2 overflow: */
526 if (size
< fd6_ctx
->vsc_data2_pitch
) {
527 /* we've already increased the size */
531 fd_bo_del(fd6_ctx
->vsc_data2
);
532 fd6_ctx
->vsc_data2
= NULL
;
533 fd6_ctx
->vsc_data2_pitch
*= 2;
535 debug_printf("resized VSC_DATA2_PITCH to: 0x%x\n", fd6_ctx
->vsc_data2_pitch
);
538 /* NOTE: it's possible, for example, for overflow to corrupt the
539 * control page. I mostly just see this hit if I set initial VSC
540 * buffer size extremely small. Things still seem to recover,
541 * but maybe we should pre-emptively realloc vsc_data/vsc_data2
542 * and hope for different memory placement?
544 DBG("invalid vsc_overflow value: 0x%08x", vsc_overflow
);
549 * Emit conditional CP_INDIRECT_BRANCH based on VSC_STATE[p], ie. the IB
550 * is skipped for tiles that have no visible geometry.
553 emit_conditional_ib(struct fd_batch
*batch
, const struct fd_tile
*tile
,
554 struct fd_ringbuffer
*target
)
556 struct fd_ringbuffer
*ring
= batch
->gmem
;
558 if (target
->cur
== target
->start
)
561 emit_marker6(ring
, 6);
563 unsigned count
= fd_ringbuffer_cmd_count(target
);
565 BEGIN_RING(ring
, 5 + 4 * count
); /* ensure conditional doesn't get split */
567 OUT_PKT7(ring
, CP_REG_TEST
, 1);
568 OUT_RING(ring
, A6XX_CP_REG_TEST_0_REG(REG_A6XX_VSC_STATE_REG(tile
->p
)) |
569 A6XX_CP_REG_TEST_0_BIT(tile
->n
) |
570 A6XX_CP_REG_TEST_0_WAIT_FOR_ME
);
572 OUT_PKT7(ring
, CP_COND_REG_EXEC
, 2);
573 OUT_RING(ring
, CP_COND_REG_EXEC_0_MODE(PRED_TEST
));
574 OUT_RING(ring
, CP_COND_REG_EXEC_1_DWORDS(4 * count
));
576 for (unsigned i
= 0; i
< count
; i
++) {
578 OUT_PKT7(ring
, CP_INDIRECT_BUFFER
, 3);
579 dwords
= fd_ringbuffer_emit_reloc_ring_full(ring
, target
, i
) / 4;
581 OUT_RING(ring
, dwords
);
584 emit_marker6(ring
, 6);
588 set_scissor(struct fd_ringbuffer
*ring
, uint32_t x1
, uint32_t y1
, uint32_t x2
, uint32_t y2
)
591 A6XX_GRAS_SC_WINDOW_SCISSOR_TL(.x
= x1
, .y
= y1
),
592 A6XX_GRAS_SC_WINDOW_SCISSOR_BR(.x
= x2
, .y
= y2
));
595 A6XX_GRAS_RESOLVE_CNTL_1(.x
= x1
, .y
= y1
),
596 A6XX_GRAS_RESOLVE_CNTL_2(.x
= x2
, .y
= y2
));
600 set_bin_size(struct fd_ringbuffer
*ring
, uint32_t w
, uint32_t h
, uint32_t flag
)
602 OUT_REG(ring
, A6XX_GRAS_BIN_CONTROL(.binw
= w
, .binh
= h
, .dword
= flag
));
603 OUT_REG(ring
, A6XX_RB_BIN_CONTROL(.binw
= w
, .binh
= h
, .dword
= flag
));
604 /* no flag for RB_BIN_CONTROL2... */
605 OUT_REG(ring
, A6XX_RB_BIN_CONTROL2(.binw
= w
, .binh
= h
));
609 emit_binning_pass(struct fd_batch
*batch
)
611 struct fd_ringbuffer
*ring
= batch
->gmem
;
612 const struct fd_gmem_stateobj
*gmem
= batch
->gmem_state
;
613 struct fd6_context
*fd6_ctx
= fd6_context(batch
->ctx
);
615 uint32_t x1
= gmem
->minx
;
616 uint32_t y1
= gmem
->miny
;
617 uint32_t x2
= gmem
->minx
+ gmem
->width
- 1;
618 uint32_t y2
= gmem
->miny
+ gmem
->height
- 1;
620 debug_assert(!batch
->tessellation
);
622 set_scissor(ring
, x1
, y1
, x2
, y2
);
624 emit_marker6(ring
, 7);
625 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
626 OUT_RING(ring
, A6XX_CP_SET_MARKER_0_MODE(RM6_BINNING
));
627 emit_marker6(ring
, 7);
629 OUT_PKT7(ring
, CP_SET_VISIBILITY_OVERRIDE
, 1);
632 OUT_PKT7(ring
, CP_SET_MODE
, 1);
637 OUT_REG(ring
, A6XX_VFD_MODE_CNTL(.binning_pass
= true));
639 update_vsc_pipe(batch
);
641 OUT_PKT4(ring
, REG_A6XX_PC_UNKNOWN_9805
, 1);
642 OUT_RING(ring
, fd6_ctx
->magic
.PC_UNKNOWN_9805
);
644 OUT_PKT4(ring
, REG_A6XX_SP_UNKNOWN_A0F8
, 1);
645 OUT_RING(ring
, fd6_ctx
->magic
.SP_UNKNOWN_A0F8
);
647 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
648 OUT_RING(ring
, UNK_2C
);
650 OUT_PKT4(ring
, REG_A6XX_RB_WINDOW_OFFSET
, 1);
651 OUT_RING(ring
, A6XX_RB_WINDOW_OFFSET_X(0) |
652 A6XX_RB_WINDOW_OFFSET_Y(0));
654 OUT_PKT4(ring
, REG_A6XX_SP_TP_WINDOW_OFFSET
, 1);
655 OUT_RING(ring
, A6XX_SP_TP_WINDOW_OFFSET_X(0) |
656 A6XX_SP_TP_WINDOW_OFFSET_Y(0));
658 /* emit IB to binning drawcmds: */
659 fd_log(batch
, "GMEM: START BINNING IB");
660 fd6_emit_ib(ring
, batch
->draw
);
661 fd_log(batch
, "GMEM: END BINNING IB");
665 OUT_PKT7(ring
, CP_SET_DRAW_STATE
, 3);
666 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(0) |
667 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
668 CP_SET_DRAW_STATE__0_GROUP_ID(0));
669 OUT_RING(ring
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
670 OUT_RING(ring
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
672 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
673 OUT_RING(ring
, UNK_2D
);
675 fd6_cache_inv(batch
, ring
);
676 fd6_cache_flush(batch
, ring
);
679 OUT_PKT7(ring
, CP_WAIT_FOR_ME
, 0);
681 fd_log(batch
, "START VSC OVERFLOW TEST");
682 emit_vsc_overflow_test(batch
);
683 fd_log(batch
, "END VSC OVERFLOW TEST");
685 OUT_PKT7(ring
, CP_SET_VISIBILITY_OVERRIDE
, 1);
688 OUT_PKT7(ring
, CP_SET_MODE
, 1);
693 OUT_PKT4(ring
, REG_A6XX_RB_CCU_CNTL
, 1);
694 OUT_RING(ring
, fd6_ctx
->magic
.RB_CCU_CNTL_gmem
);
698 emit_msaa(struct fd_ringbuffer
*ring
, unsigned nr
)
700 enum a3xx_msaa_samples samples
= fd_msaa_samples(nr
);
702 OUT_PKT4(ring
, REG_A6XX_SP_TP_RAS_MSAA_CNTL
, 2);
703 OUT_RING(ring
, A6XX_SP_TP_RAS_MSAA_CNTL_SAMPLES(samples
));
704 OUT_RING(ring
, A6XX_SP_TP_DEST_MSAA_CNTL_SAMPLES(samples
) |
705 COND(samples
== MSAA_ONE
, A6XX_SP_TP_DEST_MSAA_CNTL_MSAA_DISABLE
));
707 OUT_PKT4(ring
, REG_A6XX_GRAS_RAS_MSAA_CNTL
, 2);
708 OUT_RING(ring
, A6XX_GRAS_RAS_MSAA_CNTL_SAMPLES(samples
));
709 OUT_RING(ring
, A6XX_GRAS_DEST_MSAA_CNTL_SAMPLES(samples
) |
710 COND(samples
== MSAA_ONE
, A6XX_GRAS_DEST_MSAA_CNTL_MSAA_DISABLE
));
712 OUT_PKT4(ring
, REG_A6XX_RB_RAS_MSAA_CNTL
, 2);
713 OUT_RING(ring
, A6XX_RB_RAS_MSAA_CNTL_SAMPLES(samples
));
714 OUT_RING(ring
, A6XX_RB_DEST_MSAA_CNTL_SAMPLES(samples
) |
715 COND(samples
== MSAA_ONE
, A6XX_RB_DEST_MSAA_CNTL_MSAA_DISABLE
));
717 OUT_PKT4(ring
, REG_A6XX_RB_MSAA_CNTL
, 1);
718 OUT_RING(ring
, A6XX_RB_MSAA_CNTL_SAMPLES(samples
));
721 static void prepare_tile_setup_ib(struct fd_batch
*batch
);
722 static void prepare_tile_fini_ib(struct fd_batch
*batch
);
724 /* before first tile */
726 fd6_emit_tile_init(struct fd_batch
*batch
)
728 struct fd_context
*ctx
= batch
->ctx
;
729 struct fd_ringbuffer
*ring
= batch
->gmem
;
730 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
731 const struct fd_gmem_stateobj
*gmem
= batch
->gmem_state
;
733 fd6_emit_restore(batch
, ring
);
735 fd6_emit_lrz_flush(ring
);
737 if (batch
->lrz_clear
) {
738 fd_log(batch
, "START LRZ CLEAR");
739 fd6_emit_ib(ring
, batch
->lrz_clear
);
740 fd_log(batch
, "END LRZ CLEAR");
743 fd6_cache_inv(batch
, ring
);
745 prepare_tile_setup_ib(batch
);
746 prepare_tile_fini_ib(batch
);
748 OUT_PKT7(ring
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
751 /* blob controls "local" in IB2, but I think that is not required */
752 OUT_PKT7(ring
, CP_SKIP_IB2_ENABLE_LOCAL
, 1);
756 OUT_PKT4(ring
, REG_A6XX_RB_CCU_CNTL
, 1);
757 OUT_RING(ring
, fd6_context(ctx
)->magic
.RB_CCU_CNTL_gmem
);
759 emit_zs(ring
, pfb
->zsbuf
, batch
->gmem_state
);
760 emit_mrt(ring
, pfb
, batch
->gmem_state
);
761 emit_msaa(ring
, pfb
->samples
);
762 patch_fb_read(batch
);
764 if (use_hw_binning(batch
)) {
765 /* enable stream-out during binning pass: */
766 OUT_PKT4(ring
, REG_A6XX_VPC_SO_OVERRIDE
, 1);
769 set_bin_size(ring
, gmem
->bin_w
, gmem
->bin_h
,
770 A6XX_RB_BIN_CONTROL_BINNING_PASS
| 0x6000000);
771 update_render_cntl(batch
, pfb
, true);
772 emit_binning_pass(batch
);
774 /* and disable stream-out for draw pass: */
775 OUT_PKT4(ring
, REG_A6XX_VPC_SO_OVERRIDE
, 1);
776 OUT_RING(ring
, A6XX_VPC_SO_OVERRIDE_SO_DISABLE
);
779 * NOTE: even if we detect VSC overflow and disable use of
780 * visibility stream in draw pass, it is still safe to execute
781 * the reset of these cmds:
784 // NOTE a618 not setting .USE_VIZ .. from a quick check on a630, it
785 // does not appear that this bit changes much (ie. it isn't actually
786 // .USE_VIZ like previous gens)
787 set_bin_size(ring
, gmem
->bin_w
, gmem
->bin_h
,
788 A6XX_RB_BIN_CONTROL_USE_VIZ
| 0x6000000);
790 OUT_PKT4(ring
, REG_A6XX_VFD_MODE_CNTL
, 1);
793 OUT_PKT4(ring
, REG_A6XX_PC_UNKNOWN_9805
, 1);
794 OUT_RING(ring
, fd6_context(ctx
)->magic
.PC_UNKNOWN_9805
);
796 OUT_PKT4(ring
, REG_A6XX_SP_UNKNOWN_A0F8
, 1);
797 OUT_RING(ring
, fd6_context(ctx
)->magic
.SP_UNKNOWN_A0F8
);
799 OUT_PKT7(ring
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
802 /* no binning pass, so enable stream-out for draw pass:: */
803 OUT_PKT4(ring
, REG_A6XX_VPC_SO_OVERRIDE
, 1);
806 set_bin_size(ring
, gmem
->bin_w
, gmem
->bin_h
, 0x6000000);
809 update_render_cntl(batch
, pfb
, false);
813 set_window_offset(struct fd_ringbuffer
*ring
, uint32_t x1
, uint32_t y1
)
815 OUT_PKT4(ring
, REG_A6XX_RB_WINDOW_OFFSET
, 1);
816 OUT_RING(ring
, A6XX_RB_WINDOW_OFFSET_X(x1
) |
817 A6XX_RB_WINDOW_OFFSET_Y(y1
));
819 OUT_PKT4(ring
, REG_A6XX_RB_WINDOW_OFFSET2
, 1);
820 OUT_RING(ring
, A6XX_RB_WINDOW_OFFSET2_X(x1
) |
821 A6XX_RB_WINDOW_OFFSET2_Y(y1
));
823 OUT_PKT4(ring
, REG_A6XX_SP_WINDOW_OFFSET
, 1);
824 OUT_RING(ring
, A6XX_SP_WINDOW_OFFSET_X(x1
) |
825 A6XX_SP_WINDOW_OFFSET_Y(y1
));
827 OUT_PKT4(ring
, REG_A6XX_SP_TP_WINDOW_OFFSET
, 1);
828 OUT_RING(ring
, A6XX_SP_TP_WINDOW_OFFSET_X(x1
) |
829 A6XX_SP_TP_WINDOW_OFFSET_Y(y1
));
832 /* before mem2gmem */
834 fd6_emit_tile_prep(struct fd_batch
*batch
, const struct fd_tile
*tile
)
836 struct fd_context
*ctx
= batch
->ctx
;
837 const struct fd_gmem_stateobj
*gmem
= batch
->gmem_state
;
838 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
839 struct fd_ringbuffer
*ring
= batch
->gmem
;
841 emit_marker6(ring
, 7);
842 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
843 OUT_RING(ring
, A6XX_CP_SET_MARKER_0_MODE(RM6_GMEM
));
844 emit_marker6(ring
, 7);
846 uint32_t x1
= tile
->xoff
;
847 uint32_t y1
= tile
->yoff
;
848 uint32_t x2
= tile
->xoff
+ tile
->bin_w
- 1;
849 uint32_t y2
= tile
->yoff
+ tile
->bin_h
- 1;
851 set_scissor(ring
, x1
, y1
, x2
, y2
);
853 if (use_hw_binning(batch
)) {
854 const struct fd_vsc_pipe
*pipe
= &gmem
->vsc_pipe
[tile
->p
];
856 OUT_PKT7(ring
, CP_WAIT_FOR_ME
, 0);
858 OUT_PKT7(ring
, CP_SET_MODE
, 1);
862 * Conditionally execute if no VSC overflow:
865 BEGIN_RING(ring
, 18); /* ensure if/else doesn't get split */
867 OUT_PKT7(ring
, CP_REG_TEST
, 1);
868 OUT_RING(ring
, A6XX_CP_REG_TEST_0_REG(OVERFLOW_FLAG_REG
) |
869 A6XX_CP_REG_TEST_0_BIT(0) |
870 A6XX_CP_REG_TEST_0_WAIT_FOR_ME
);
872 OUT_PKT7(ring
, CP_COND_REG_EXEC
, 2);
873 OUT_RING(ring
, CP_COND_REG_EXEC_0_MODE(PRED_TEST
));
874 OUT_RING(ring
, CP_COND_REG_EXEC_1_DWORDS(11));
876 /* if (no overflow) */ {
877 OUT_PKT7(ring
, CP_SET_BIN_DATA5
, 7);
878 OUT_RING(ring
, CP_SET_BIN_DATA5_0_VSC_SIZE(pipe
->w
* pipe
->h
) |
879 CP_SET_BIN_DATA5_0_VSC_N(tile
->n
));
880 OUT_RELOC(ring
, fd6_ctx
->vsc_data
, /* VSC_PIPE[p].DATA_ADDRESS */
881 (tile
->p
* fd6_ctx
->vsc_data_pitch
), 0, 0);
882 OUT_RELOC(ring
, fd6_ctx
->vsc_data
, /* VSC_SIZE_ADDRESS + (p * 4) */
883 (tile
->p
* 4) + (32 * fd6_ctx
->vsc_data_pitch
), 0, 0);
884 OUT_RELOC(ring
, fd6_ctx
->vsc_data2
,
885 (tile
->p
* fd6_ctx
->vsc_data2_pitch
), 0, 0);
887 OUT_PKT7(ring
, CP_SET_VISIBILITY_OVERRIDE
, 1);
890 /* use a NOP packet to skip over the 'else' side: */
891 OUT_PKT7(ring
, CP_NOP
, 2);
893 OUT_PKT7(ring
, CP_SET_VISIBILITY_OVERRIDE
, 1);
897 set_window_offset(ring
, x1
, y1
);
899 const struct fd_gmem_stateobj
*gmem
= batch
->gmem_state
;
900 set_bin_size(ring
, gmem
->bin_w
, gmem
->bin_h
, 0x6000000);
902 OUT_PKT7(ring
, CP_SET_MODE
, 1);
905 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8804
, 1);
908 OUT_PKT4(ring
, REG_A6XX_SP_TP_UNKNOWN_B304
, 1);
911 OUT_PKT4(ring
, REG_A6XX_GRAS_UNKNOWN_80A4
, 1);
914 set_window_offset(ring
, x1
, y1
);
916 OUT_PKT7(ring
, CP_SET_VISIBILITY_OVERRIDE
, 1);
919 OUT_PKT7(ring
, CP_SET_MODE
, 1);
925 set_blit_scissor(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
)
927 struct pipe_scissor_state blit_scissor
;
928 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
930 blit_scissor
.minx
= 0;
931 blit_scissor
.miny
= 0;
932 blit_scissor
.maxx
= align(pfb
->width
, batch
->ctx
->screen
->gmem_alignw
);
933 blit_scissor
.maxy
= align(pfb
->height
, batch
->ctx
->screen
->gmem_alignh
);
935 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_SCISSOR_TL
, 2);
937 A6XX_RB_BLIT_SCISSOR_TL_X(blit_scissor
.minx
) |
938 A6XX_RB_BLIT_SCISSOR_TL_Y(blit_scissor
.miny
));
940 A6XX_RB_BLIT_SCISSOR_BR_X(blit_scissor
.maxx
- 1) |
941 A6XX_RB_BLIT_SCISSOR_BR_Y(blit_scissor
.maxy
- 1));
945 emit_blit(struct fd_batch
*batch
,
946 struct fd_ringbuffer
*ring
,
948 struct pipe_surface
*psurf
,
951 struct fdl_slice
*slice
;
952 struct fd_resource
*rsc
= fd_resource(psurf
->texture
);
953 enum pipe_format pfmt
= psurf
->format
;
957 debug_assert(psurf
->u
.tex
.first_layer
== psurf
->u
.tex
.last_layer
);
959 /* separate stencil case: */
962 pfmt
= rsc
->base
.format
;
965 slice
= fd_resource_slice(rsc
, psurf
->u
.tex
.level
);
966 offset
= fd_resource_offset(rsc
, psurf
->u
.tex
.level
,
967 psurf
->u
.tex
.first_layer
);
968 ubwc_enabled
= fd_resource_ubwc_enabled(rsc
, psurf
->u
.tex
.level
);
970 debug_assert(psurf
->u
.tex
.first_layer
== psurf
->u
.tex
.last_layer
);
972 enum a6xx_format format
= fd6_pipe2color(pfmt
);
973 uint32_t stride
= slice
->pitch
* rsc
->layout
.cpp
;
974 uint32_t size
= slice
->size0
;
975 enum a3xx_color_swap swap
= fd6_resource_swap(rsc
, pfmt
);
976 enum a3xx_msaa_samples samples
=
977 fd_msaa_samples(rsc
->base
.nr_samples
);
978 uint32_t tile_mode
= fd_resource_tile_mode(&rsc
->base
, psurf
->u
.tex
.level
);
981 A6XX_RB_BLIT_DST_INFO(.tile_mode
= tile_mode
, .samples
= samples
,
982 .color_format
= format
, .color_swap
= swap
, .flags
= ubwc_enabled
),
983 A6XX_RB_BLIT_DST(.bo
= rsc
->bo
, .bo_offset
= offset
),
984 A6XX_RB_BLIT_DST_PITCH(.a6xx_rb_blit_dst_pitch
= stride
),
985 A6XX_RB_BLIT_DST_ARRAY_PITCH(.a6xx_rb_blit_dst_array_pitch
= size
));
987 OUT_REG(ring
, A6XX_RB_BLIT_BASE_GMEM(.dword
= base
));
990 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_FLAG_DST_LO
, 3);
991 fd6_emit_flag_reference(ring
, rsc
,
992 psurf
->u
.tex
.level
, psurf
->u
.tex
.first_layer
);
995 fd6_emit_blit(batch
, ring
);
999 emit_restore_blit(struct fd_batch
*batch
,
1000 struct fd_ringbuffer
*ring
,
1002 struct pipe_surface
*psurf
,
1005 bool stencil
= (buffer
== FD_BUFFER_STENCIL
);
1007 OUT_REG(ring
, A6XX_RB_BLIT_INFO(
1008 .gmem
= true, .unk0
= true,
1009 .depth
= (buffer
== FD_BUFFER_DEPTH
),
1010 .integer
= util_format_is_pure_integer(psurf
->format
)));
1012 emit_blit(batch
, ring
, base
, psurf
, stencil
);
1016 emit_clears(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
)
1018 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
1019 const struct fd_gmem_stateobj
*gmem
= batch
->gmem_state
;
1020 enum a3xx_msaa_samples samples
= fd_msaa_samples(pfb
->samples
);
1022 uint32_t buffers
= batch
->fast_cleared
;
1024 if (buffers
& PIPE_CLEAR_COLOR
) {
1026 for (int i
= 0; i
< pfb
->nr_cbufs
; i
++) {
1027 union pipe_color_union
*color
= &batch
->clear_color
[i
];
1028 union util_color uc
= {0};
1033 if (!(buffers
& (PIPE_CLEAR_COLOR0
<< i
)))
1036 enum pipe_format pfmt
= pfb
->cbufs
[i
]->format
;
1038 // XXX I think RB_CLEAR_COLOR_DWn wants to take into account SWAP??
1039 union pipe_color_union swapped
;
1040 switch (fd6_pipe2swap(pfmt
)) {
1042 swapped
.ui
[0] = color
->ui
[0];
1043 swapped
.ui
[1] = color
->ui
[1];
1044 swapped
.ui
[2] = color
->ui
[2];
1045 swapped
.ui
[3] = color
->ui
[3];
1048 swapped
.ui
[2] = color
->ui
[0];
1049 swapped
.ui
[1] = color
->ui
[1];
1050 swapped
.ui
[0] = color
->ui
[2];
1051 swapped
.ui
[3] = color
->ui
[3];
1054 swapped
.ui
[3] = color
->ui
[0];
1055 swapped
.ui
[0] = color
->ui
[1];
1056 swapped
.ui
[1] = color
->ui
[2];
1057 swapped
.ui
[2] = color
->ui
[3];
1060 swapped
.ui
[3] = color
->ui
[0];
1061 swapped
.ui
[2] = color
->ui
[1];
1062 swapped
.ui
[1] = color
->ui
[2];
1063 swapped
.ui
[0] = color
->ui
[3];
1067 util_pack_color_union(pfmt
, &uc
, &swapped
);
1069 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_DST_INFO
, 1);
1070 OUT_RING(ring
, A6XX_RB_BLIT_DST_INFO_TILE_MODE(TILE6_LINEAR
) |
1071 A6XX_RB_BLIT_DST_INFO_SAMPLES(samples
) |
1072 A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(fd6_pipe2color(pfmt
)));
1074 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_INFO
, 1);
1075 OUT_RING(ring
, A6XX_RB_BLIT_INFO_GMEM
|
1076 A6XX_RB_BLIT_INFO_CLEAR_MASK(0xf));
1078 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_BASE_GMEM
, 1);
1079 OUT_RING(ring
, gmem
->cbuf_base
[i
]);
1081 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_88D0
, 1);
1084 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_CLEAR_COLOR_DW0
, 4);
1085 OUT_RING(ring
, uc
.ui
[0]);
1086 OUT_RING(ring
, uc
.ui
[1]);
1087 OUT_RING(ring
, uc
.ui
[2]);
1088 OUT_RING(ring
, uc
.ui
[3]);
1090 fd6_emit_blit(batch
, ring
);
1094 const bool has_depth
= pfb
->zsbuf
;
1095 const bool has_separate_stencil
=
1096 has_depth
&& fd_resource(pfb
->zsbuf
->texture
)->stencil
;
1098 /* First clear depth or combined depth/stencil. */
1099 if ((has_depth
&& (buffers
& PIPE_CLEAR_DEPTH
)) ||
1100 (!has_separate_stencil
&& (buffers
& PIPE_CLEAR_STENCIL
))) {
1101 enum pipe_format pfmt
= pfb
->zsbuf
->format
;
1102 uint32_t clear_value
;
1105 if (has_separate_stencil
) {
1106 pfmt
= util_format_get_depth_only(pfb
->zsbuf
->format
);
1107 clear_value
= util_pack_z(pfmt
, batch
->clear_depth
);
1109 pfmt
= pfb
->zsbuf
->format
;
1110 clear_value
= util_pack_z_stencil(pfmt
, batch
->clear_depth
,
1111 batch
->clear_stencil
);
1114 if (buffers
& PIPE_CLEAR_DEPTH
)
1117 if (!has_separate_stencil
&& (buffers
& PIPE_CLEAR_STENCIL
))
1120 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_DST_INFO
, 1);
1121 OUT_RING(ring
, A6XX_RB_BLIT_DST_INFO_TILE_MODE(TILE6_LINEAR
) |
1122 A6XX_RB_BLIT_DST_INFO_SAMPLES(samples
) |
1123 A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(fd6_pipe2color(pfmt
)));
1125 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_INFO
, 1);
1126 OUT_RING(ring
, A6XX_RB_BLIT_INFO_GMEM
|
1127 // XXX UNK0 for separate stencil ??
1128 A6XX_RB_BLIT_INFO_DEPTH
|
1129 A6XX_RB_BLIT_INFO_CLEAR_MASK(mask
));
1131 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_BASE_GMEM
, 1);
1132 OUT_RING(ring
, gmem
->zsbuf_base
[0]);
1134 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_88D0
, 1);
1137 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_CLEAR_COLOR_DW0
, 1);
1138 OUT_RING(ring
, clear_value
);
1140 fd6_emit_blit(batch
, ring
);
1143 /* Then clear the separate stencil buffer in case of 32 bit depth
1144 * formats with separate stencil. */
1145 if (has_separate_stencil
&& (buffers
& PIPE_CLEAR_STENCIL
)) {
1146 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_DST_INFO
, 1);
1147 OUT_RING(ring
, A6XX_RB_BLIT_DST_INFO_TILE_MODE(TILE6_LINEAR
) |
1148 A6XX_RB_BLIT_DST_INFO_SAMPLES(samples
) |
1149 A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(FMT6_8_UINT
));
1151 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_INFO
, 1);
1152 OUT_RING(ring
, A6XX_RB_BLIT_INFO_GMEM
|
1153 //A6XX_RB_BLIT_INFO_UNK0 |
1154 A6XX_RB_BLIT_INFO_DEPTH
|
1155 A6XX_RB_BLIT_INFO_CLEAR_MASK(0x1));
1157 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_BASE_GMEM
, 1);
1158 OUT_RING(ring
, gmem
->zsbuf_base
[1]);
1160 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_88D0
, 1);
1163 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_CLEAR_COLOR_DW0
, 1);
1164 OUT_RING(ring
, batch
->clear_stencil
& 0xff);
1166 fd6_emit_blit(batch
, ring
);
1171 * transfer from system memory to gmem
1174 emit_restore_blits(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
)
1176 const struct fd_gmem_stateobj
*gmem
= batch
->gmem_state
;
1177 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
1179 if (batch
->restore
& FD_BUFFER_COLOR
) {
1181 for (i
= 0; i
< pfb
->nr_cbufs
; i
++) {
1184 if (!(batch
->restore
& (PIPE_CLEAR_COLOR0
<< i
)))
1186 emit_restore_blit(batch
, ring
, gmem
->cbuf_base
[i
], pfb
->cbufs
[i
],
1191 if (batch
->restore
& (FD_BUFFER_DEPTH
| FD_BUFFER_STENCIL
)) {
1192 struct fd_resource
*rsc
= fd_resource(pfb
->zsbuf
->texture
);
1194 if (!rsc
->stencil
|| (batch
->restore
& FD_BUFFER_DEPTH
)) {
1195 emit_restore_blit(batch
, ring
, gmem
->zsbuf_base
[0], pfb
->zsbuf
,
1198 if (rsc
->stencil
&& (batch
->restore
& FD_BUFFER_STENCIL
)) {
1199 emit_restore_blit(batch
, ring
, gmem
->zsbuf_base
[1], pfb
->zsbuf
,
1206 prepare_tile_setup_ib(struct fd_batch
*batch
)
1208 batch
->tile_setup
= fd_submit_new_ringbuffer(batch
->submit
, 0x1000,
1209 FD_RINGBUFFER_STREAMING
);
1211 set_blit_scissor(batch
, batch
->tile_setup
);
1213 emit_restore_blits(batch
, batch
->tile_setup
);
1214 emit_clears(batch
, batch
->tile_setup
);
1218 * transfer from system memory to gmem
1221 fd6_emit_tile_mem2gmem(struct fd_batch
*batch
, const struct fd_tile
*tile
)
1225 /* before IB to rendering cmds: */
1227 fd6_emit_tile_renderprep(struct fd_batch
*batch
, const struct fd_tile
*tile
)
1229 fd_log(batch
, "TILE: START CLEAR/RESTORE");
1230 if (batch
->fast_cleared
|| !use_hw_binning(batch
)) {
1231 fd6_emit_ib(batch
->gmem
, batch
->tile_setup
);
1233 emit_conditional_ib(batch
, tile
, batch
->tile_setup
);
1235 fd_log(batch
, "TILE: END CLEAR/RESTORE");
1239 emit_resolve_blit(struct fd_batch
*batch
,
1240 struct fd_ringbuffer
*ring
,
1242 struct pipe_surface
*psurf
,
1246 bool stencil
= false;
1248 if (!fd_resource(psurf
->texture
)->valid
)
1252 case FD_BUFFER_COLOR
:
1254 case FD_BUFFER_STENCIL
:
1255 info
|= A6XX_RB_BLIT_INFO_UNK0
;
1258 case FD_BUFFER_DEPTH
:
1259 info
|= A6XX_RB_BLIT_INFO_DEPTH
;
1263 if (util_format_is_pure_integer(psurf
->format
))
1264 info
|= A6XX_RB_BLIT_INFO_INTEGER
;
1266 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_INFO
, 1);
1267 OUT_RING(ring
, info
);
1269 emit_blit(batch
, ring
, base
, psurf
, stencil
);
1273 * transfer from gmem to system memory (ie. normal RAM)
1277 prepare_tile_fini_ib(struct fd_batch
*batch
)
1279 const struct fd_gmem_stateobj
*gmem
= batch
->gmem_state
;
1280 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
1281 struct fd_ringbuffer
*ring
;
1283 batch
->tile_fini
= fd_submit_new_ringbuffer(batch
->submit
, 0x1000,
1284 FD_RINGBUFFER_STREAMING
);
1285 ring
= batch
->tile_fini
;
1287 set_blit_scissor(batch
, ring
);
1289 if (batch
->resolve
& (FD_BUFFER_DEPTH
| FD_BUFFER_STENCIL
)) {
1290 struct fd_resource
*rsc
= fd_resource(pfb
->zsbuf
->texture
);
1292 if (!rsc
->stencil
|| (batch
->resolve
& FD_BUFFER_DEPTH
)) {
1293 emit_resolve_blit(batch
, ring
,
1294 gmem
->zsbuf_base
[0], pfb
->zsbuf
,
1297 if (rsc
->stencil
&& (batch
->resolve
& FD_BUFFER_STENCIL
)) {
1298 emit_resolve_blit(batch
, ring
,
1299 gmem
->zsbuf_base
[1], pfb
->zsbuf
,
1304 if (batch
->resolve
& FD_BUFFER_COLOR
) {
1306 for (i
= 0; i
< pfb
->nr_cbufs
; i
++) {
1309 if (!(batch
->resolve
& (PIPE_CLEAR_COLOR0
<< i
)))
1311 emit_resolve_blit(batch
, ring
, gmem
->cbuf_base
[i
], pfb
->cbufs
[i
],
1318 fd6_emit_tile(struct fd_batch
*batch
, const struct fd_tile
*tile
)
1320 if (!use_hw_binning(batch
)) {
1321 fd6_emit_ib(batch
->gmem
, batch
->draw
);
1323 emit_conditional_ib(batch
, tile
, batch
->draw
);
1328 fd6_emit_tile_gmem2mem(struct fd_batch
*batch
, const struct fd_tile
*tile
)
1330 struct fd_ringbuffer
*ring
= batch
->gmem
;
1332 if (use_hw_binning(batch
)) {
1333 /* Conditionally execute if no VSC overflow: */
1335 BEGIN_RING(ring
, 7); /* ensure if/else doesn't get split */
1337 OUT_PKT7(ring
, CP_REG_TEST
, 1);
1338 OUT_RING(ring
, A6XX_CP_REG_TEST_0_REG(OVERFLOW_FLAG_REG
) |
1339 A6XX_CP_REG_TEST_0_BIT(0) |
1340 A6XX_CP_REG_TEST_0_WAIT_FOR_ME
);
1342 OUT_PKT7(ring
, CP_COND_REG_EXEC
, 2);
1343 OUT_RING(ring
, CP_COND_REG_EXEC_0_MODE(PRED_TEST
));
1344 OUT_RING(ring
, CP_COND_REG_EXEC_1_DWORDS(2));
1346 /* if (no overflow) */ {
1347 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
1348 OUT_RING(ring
, A6XX_CP_SET_MARKER_0_MODE(RM6_ENDVIS
));
1352 OUT_PKT7(ring
, CP_SET_DRAW_STATE
, 3);
1353 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(0) |
1354 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
1355 CP_SET_DRAW_STATE__0_GROUP_ID(0));
1356 OUT_RING(ring
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
1357 OUT_RING(ring
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
1359 OUT_PKT7(ring
, CP_SKIP_IB2_ENABLE_LOCAL
, 1);
1360 OUT_RING(ring
, 0x0);
1362 emit_marker6(ring
, 7);
1363 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
1364 OUT_RING(ring
, A6XX_CP_SET_MARKER_0_MODE(RM6_RESOLVE
));
1365 emit_marker6(ring
, 7);
1367 fd_log(batch
, "TILE: START RESOLVE");
1368 if (batch
->fast_cleared
|| !use_hw_binning(batch
)) {
1369 fd6_emit_ib(batch
->gmem
, batch
->tile_fini
);
1371 emit_conditional_ib(batch
, tile
, batch
->tile_fini
);
1373 fd_log(batch
, "TILE: END RESOLVE");
1377 fd6_emit_tile_fini(struct fd_batch
*batch
)
1379 struct fd_ringbuffer
*ring
= batch
->gmem
;
1381 OUT_PKT4(ring
, REG_A6XX_GRAS_LRZ_CNTL
, 1);
1382 OUT_RING(ring
, A6XX_GRAS_LRZ_CNTL_ENABLE
| A6XX_GRAS_LRZ_CNTL_UNK3
);
1384 fd6_emit_lrz_flush(ring
);
1386 fd6_event_write(batch
, ring
, CACHE_FLUSH_TS
, true);
1388 if (use_hw_binning(batch
)) {
1389 check_vsc_overflow(batch
->ctx
);
1394 emit_sysmem_clears(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
)
1396 struct fd_context
*ctx
= batch
->ctx
;
1397 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
1399 uint32_t buffers
= batch
->fast_cleared
;
1401 if (buffers
& PIPE_CLEAR_COLOR
) {
1402 for (int i
= 0; i
< pfb
->nr_cbufs
; i
++) {
1403 union pipe_color_union
*color
= &batch
->clear_color
[i
];
1408 if (!(buffers
& (PIPE_CLEAR_COLOR0
<< i
)))
1411 fd6_clear_surface(ctx
, ring
,
1412 pfb
->cbufs
[i
], pfb
->width
, pfb
->height
, color
);
1415 if (buffers
& (PIPE_CLEAR_DEPTH
| PIPE_CLEAR_STENCIL
)) {
1416 union pipe_color_union value
= {};
1418 const bool has_depth
= pfb
->zsbuf
;
1419 struct pipe_resource
*separate_stencil
=
1420 has_depth
&& fd_resource(pfb
->zsbuf
->texture
)->stencil
?
1421 &fd_resource(pfb
->zsbuf
->texture
)->stencil
->base
: NULL
;
1423 if ((has_depth
&& (buffers
& PIPE_CLEAR_DEPTH
)) ||
1424 (!separate_stencil
&& (buffers
& PIPE_CLEAR_STENCIL
))) {
1425 value
.f
[0] = batch
->clear_depth
;
1426 value
.ui
[1] = batch
->clear_stencil
;
1427 fd6_clear_surface(ctx
, ring
,
1428 pfb
->zsbuf
, pfb
->width
, pfb
->height
, &value
);
1431 if (separate_stencil
&& (buffers
& PIPE_CLEAR_STENCIL
)) {
1432 value
.ui
[0] = batch
->clear_stencil
;
1434 struct pipe_surface stencil_surf
= *pfb
->zsbuf
;
1435 stencil_surf
.texture
= separate_stencil
;
1437 fd6_clear_surface(ctx
, ring
,
1438 &stencil_surf
, pfb
->width
, pfb
->height
, &value
);
1442 fd6_event_write(batch
, ring
, PC_CCU_FLUSH_COLOR_TS
, true);
1446 setup_tess_buffers(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
)
1448 struct fd_context
*ctx
= batch
->ctx
;
1450 batch
->tessfactor_bo
= fd_bo_new(ctx
->screen
->dev
,
1451 batch
->tessfactor_size
,
1452 DRM_FREEDRENO_GEM_TYPE_KMEM
, "tessfactor");
1454 batch
->tessparam_bo
= fd_bo_new(ctx
->screen
->dev
,
1455 batch
->tessparam_size
,
1456 DRM_FREEDRENO_GEM_TYPE_KMEM
, "tessparam");
1458 OUT_PKT4(ring
, REG_A6XX_PC_TESSFACTOR_ADDR_LO
, 2);
1459 OUT_RELOCW(ring
, batch
->tessfactor_bo
, 0, 0, 0);
1461 batch
->tess_addrs_constobj
->cur
= batch
->tess_addrs_constobj
->start
;
1462 OUT_RELOCW(batch
->tess_addrs_constobj
, batch
->tessparam_bo
, 0, 0, 0);
1463 OUT_RELOCW(batch
->tess_addrs_constobj
, batch
->tessfactor_bo
, 0, 0, 0);
1467 fd6_emit_sysmem_prep(struct fd_batch
*batch
)
1469 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
1470 struct fd_ringbuffer
*ring
= batch
->gmem
;
1472 fd6_emit_restore(batch
, ring
);
1474 if (pfb
->width
> 0 && pfb
->height
> 0)
1475 set_scissor(ring
, 0, 0, pfb
->width
- 1, pfb
->height
- 1);
1477 set_scissor(ring
, 0, 0, 0, 0);
1479 set_window_offset(ring
, 0, 0);
1481 set_bin_size(ring
, 0, 0, 0xc00000); /* 0xc00000 = BYPASS? */
1483 emit_sysmem_clears(batch
, ring
);
1485 fd6_emit_lrz_flush(ring
);
1487 if (batch
->lrz_clear
)
1488 fd6_emit_ib(ring
, batch
->lrz_clear
);
1490 emit_marker6(ring
, 7);
1491 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
1492 OUT_RING(ring
, A6XX_CP_SET_MARKER_0_MODE(RM6_BYPASS
));
1493 emit_marker6(ring
, 7);
1495 if (batch
->tessellation
)
1496 setup_tess_buffers(batch
, ring
);
1498 OUT_PKT7(ring
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1499 OUT_RING(ring
, 0x0);
1501 /* blob controls "local" in IB2, but I think that is not required */
1502 OUT_PKT7(ring
, CP_SKIP_IB2_ENABLE_LOCAL
, 1);
1503 OUT_RING(ring
, 0x1);
1505 fd6_event_write(batch
, ring
, PC_CCU_INVALIDATE_COLOR
, false);
1506 fd6_cache_inv(batch
, ring
);
1508 fd_wfi(batch
, ring
);
1509 OUT_PKT4(ring
, REG_A6XX_RB_CCU_CNTL
, 1);
1510 OUT_RING(ring
, fd6_context(batch
->ctx
)->magic
.RB_CCU_CNTL_bypass
);
1512 /* enable stream-out, with sysmem there is only one pass: */
1513 OUT_PKT4(ring
, REG_A6XX_VPC_SO_OVERRIDE
, 1);
1516 OUT_PKT7(ring
, CP_SET_VISIBILITY_OVERRIDE
, 1);
1517 OUT_RING(ring
, 0x1);
1519 emit_zs(ring
, pfb
->zsbuf
, NULL
);
1520 emit_mrt(ring
, pfb
, NULL
);
1521 emit_msaa(ring
, pfb
->samples
);
1523 update_render_cntl(batch
, pfb
, false);
1527 fd6_emit_sysmem_fini(struct fd_batch
*batch
)
1529 struct fd_ringbuffer
*ring
= batch
->gmem
;
1531 OUT_PKT7(ring
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
1532 OUT_RING(ring
, 0x0);
1534 fd6_emit_lrz_flush(ring
);
1536 fd6_event_write(batch
, ring
, PC_CCU_FLUSH_COLOR_TS
, true);
1540 fd6_gmem_init(struct pipe_context
*pctx
)
1542 struct fd_context
*ctx
= fd_context(pctx
);
1544 ctx
->emit_tile_init
= fd6_emit_tile_init
;
1545 ctx
->emit_tile_prep
= fd6_emit_tile_prep
;
1546 ctx
->emit_tile_mem2gmem
= fd6_emit_tile_mem2gmem
;
1547 ctx
->emit_tile_renderprep
= fd6_emit_tile_renderprep
;
1548 ctx
->emit_tile
= fd6_emit_tile
;
1549 ctx
->emit_tile_gmem2mem
= fd6_emit_tile_gmem2mem
;
1550 ctx
->emit_tile_fini
= fd6_emit_tile_fini
;
1551 ctx
->emit_sysmem_prep
= fd6_emit_sysmem_prep
;
1552 ctx
->emit_sysmem_fini
= fd6_emit_sysmem_fini
;