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/u_format.h"
36 #include "freedreno_draw.h"
37 #include "freedreno_state.h"
38 #include "freedreno_resource.h"
41 #include "fd6_context.h"
44 #include "fd6_program.h"
45 #include "fd6_format.h"
48 /* some bits in common w/ a4xx: */
49 #include "a4xx/fd4_draw.h"
52 emit_mrt(struct fd_ringbuffer
*ring
, struct pipe_framebuffer_state
*pfb
,
53 struct fd_gmem_stateobj
*gmem
)
55 unsigned char mrt_comp
[A6XX_MAX_RENDER_TARGETS
] = {0};
56 unsigned srgb_cntl
= 0;
59 for (i
= 0; i
< pfb
->nr_cbufs
; i
++) {
60 enum a6xx_color_fmt format
= 0;
61 enum a3xx_color_swap swap
= WZYX
;
62 bool sint
= false, uint
= false;
63 struct fd_resource
*rsc
= NULL
;
64 struct fd_resource_slice
*slice
= NULL
;
73 struct pipe_surface
*psurf
= pfb
->cbufs
[i
];
74 enum pipe_format pformat
= psurf
->format
;
75 rsc
= fd_resource(psurf
->texture
);
79 uint32_t base
= gmem
? gmem
->cbuf_base
[i
] : 0;
80 slice
= fd_resource_slice(rsc
, psurf
->u
.tex
.level
);
81 format
= fd6_pipe2color(pformat
);
82 swap
= fd6_pipe2swap(pformat
);
83 sint
= util_format_is_pure_sint(pformat
);
84 uint
= util_format_is_pure_uint(pformat
);
86 if (util_format_is_srgb(pformat
))
87 srgb_cntl
|= (1 << i
);
89 offset
= fd_resource_offset(rsc
, psurf
->u
.tex
.level
,
90 psurf
->u
.tex
.first_layer
);
92 stride
= slice
->pitch
* rsc
->cpp
;
94 debug_assert(psurf
->u
.tex
.first_layer
== psurf
->u
.tex
.last_layer
);
95 debug_assert((offset
+ slice
->size0
) <= fd_bo_size(rsc
->bo
));
97 OUT_PKT4(ring
, REG_A6XX_RB_MRT_BUF_INFO(i
), 6);
98 OUT_RING(ring
, A6XX_RB_MRT_BUF_INFO_COLOR_FORMAT(format
) |
99 A6XX_RB_MRT_BUF_INFO_COLOR_TILE_MODE(rsc
->tile_mode
) |
100 A6XX_RB_MRT_BUF_INFO_COLOR_SWAP(swap
));
101 OUT_RING(ring
, A6XX_RB_MRT_PITCH(stride
));
102 OUT_RING(ring
, A6XX_RB_MRT_ARRAY_PITCH(slice
->size0
));
103 OUT_RELOCW(ring
, rsc
->bo
, offset
, 0, 0); /* BASE_LO/HI */
104 OUT_RING(ring
, base
); /* RB_MRT[i].BASE_GMEM */
105 OUT_PKT4(ring
, REG_A6XX_SP_FS_MRT_REG(i
), 1);
106 OUT_RING(ring
, A6XX_SP_FS_MRT_REG_COLOR_FORMAT(format
) |
107 COND(sint
, A6XX_SP_FS_MRT_REG_COLOR_SINT
) |
108 COND(uint
, A6XX_SP_FS_MRT_REG_COLOR_UINT
));
111 /* when we support UBWC, these would be the system memory
114 OUT_PKT4(ring
, REG_A6XX_RB_MRT_FLAG_BUFFER(i
), 4);
115 OUT_RING(ring
, 0x00000000); /* RB_MRT_FLAG_BUFFER[i].ADDR_LO */
116 OUT_RING(ring
, 0x00000000); /* RB_MRT_FLAG_BUFFER[i].ADDR_HI */
117 OUT_RING(ring
, A6XX_RB_MRT_FLAG_BUFFER_PITCH(0));
118 OUT_RING(ring
, A6XX_RB_MRT_FLAG_BUFFER_ARRAY_PITCH(0));
122 OUT_PKT4(ring
, REG_A6XX_RB_SRGB_CNTL
, 1);
123 OUT_RING(ring
, srgb_cntl
);
125 OUT_PKT4(ring
, REG_A6XX_SP_SRGB_CNTL
, 1);
126 OUT_RING(ring
, srgb_cntl
);
128 OUT_PKT4(ring
, REG_A6XX_RB_RENDER_COMPONENTS
, 1);
129 OUT_RING(ring
, A6XX_RB_RENDER_COMPONENTS_RT0(mrt_comp
[0]) |
130 A6XX_RB_RENDER_COMPONENTS_RT1(mrt_comp
[1]) |
131 A6XX_RB_RENDER_COMPONENTS_RT2(mrt_comp
[2]) |
132 A6XX_RB_RENDER_COMPONENTS_RT3(mrt_comp
[3]) |
133 A6XX_RB_RENDER_COMPONENTS_RT4(mrt_comp
[4]) |
134 A6XX_RB_RENDER_COMPONENTS_RT5(mrt_comp
[5]) |
135 A6XX_RB_RENDER_COMPONENTS_RT6(mrt_comp
[6]) |
136 A6XX_RB_RENDER_COMPONENTS_RT7(mrt_comp
[7]));
138 OUT_PKT4(ring
, REG_A6XX_SP_FS_RENDER_COMPONENTS
, 1);
140 A6XX_SP_FS_RENDER_COMPONENTS_RT0(mrt_comp
[0]) |
141 A6XX_SP_FS_RENDER_COMPONENTS_RT1(mrt_comp
[1]) |
142 A6XX_SP_FS_RENDER_COMPONENTS_RT2(mrt_comp
[2]) |
143 A6XX_SP_FS_RENDER_COMPONENTS_RT3(mrt_comp
[3]) |
144 A6XX_SP_FS_RENDER_COMPONENTS_RT4(mrt_comp
[4]) |
145 A6XX_SP_FS_RENDER_COMPONENTS_RT5(mrt_comp
[5]) |
146 A6XX_SP_FS_RENDER_COMPONENTS_RT6(mrt_comp
[6]) |
147 A6XX_SP_FS_RENDER_COMPONENTS_RT7(mrt_comp
[7]));
151 emit_zs(struct fd_ringbuffer
*ring
, struct pipe_surface
*zsbuf
,
152 struct fd_gmem_stateobj
*gmem
)
155 struct fd_resource
*rsc
= fd_resource(zsbuf
->texture
);
156 enum a6xx_depth_format fmt
= fd6_pipe2depth(zsbuf
->format
);
157 struct fd_resource_slice
*slice
= fd_resource_slice(rsc
, 0);
158 uint32_t stride
= slice
->pitch
* rsc
->cpp
;
159 uint32_t size
= slice
->size0
;
160 uint32_t base
= gmem
? gmem
->zsbuf_base
[0] : 0;
162 OUT_PKT4(ring
, REG_A6XX_RB_DEPTH_BUFFER_INFO
, 6);
163 OUT_RING(ring
, A6XX_RB_DEPTH_BUFFER_INFO_DEPTH_FORMAT(fmt
));
164 OUT_RING(ring
, A6XX_RB_DEPTH_BUFFER_PITCH(stride
));
165 OUT_RING(ring
, A6XX_RB_DEPTH_BUFFER_ARRAY_PITCH(size
));
166 OUT_RELOCW(ring
, rsc
->bo
, 0, 0, 0); /* RB_DEPTH_BUFFER_BASE_LO/HI */
167 OUT_RING(ring
, base
); /* RB_DEPTH_BUFFER_BASE_GMEM */
169 OUT_PKT4(ring
, REG_A6XX_GRAS_SU_DEPTH_BUFFER_INFO
, 1);
170 OUT_RING(ring
, A6XX_GRAS_SU_DEPTH_BUFFER_INFO_DEPTH_FORMAT(fmt
));
172 OUT_PKT4(ring
, REG_A6XX_RB_DEPTH_FLAG_BUFFER_BASE_LO
, 3);
173 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_FLAG_BUFFER_BASE_LO */
174 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_FLAG_BUFFER_BASE_HI */
175 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_FLAG_BUFFER_PITCH */
178 OUT_PKT4(ring
, REG_A6XX_GRAS_LRZ_BUFFER_BASE_LO
, 5);
179 OUT_RELOCW(ring
, rsc
->lrz
, 0, 0, 0);
180 OUT_RING(ring
, A6XX_GRAS_LRZ_BUFFER_PITCH_PITCH(rsc
->lrz_pitch
));
181 //OUT_RELOCW(ring, rsc->lrz, 0, 0, 0); /* GRAS_LRZ_FAST_CLEAR_BUFFER_BASE_LO/HI */
182 // XXX a6xx seems to use a different buffer here.. not sure what for..
183 OUT_RING(ring
, 0x00000000);
184 OUT_RING(ring
, 0x00000000);
186 OUT_PKT4(ring
, REG_A6XX_GRAS_LRZ_BUFFER_BASE_LO
, 5);
187 OUT_RING(ring
, 0x00000000);
188 OUT_RING(ring
, 0x00000000);
189 OUT_RING(ring
, 0x00000000); /* GRAS_LRZ_BUFFER_PITCH */
190 OUT_RING(ring
, 0x00000000); /* GRAS_LRZ_FAST_CLEAR_BUFFER_BASE_LO */
191 OUT_RING(ring
, 0x00000000);
195 struct fd_resource_slice
*slice
= fd_resource_slice(rsc
->stencil
, 0);
196 stride
= slice
->pitch
* rsc
->cpp
;
198 uint32_t base
= gmem
? gmem
->zsbuf_base
[1] : 0;
200 OUT_PKT4(ring
, REG_A6XX_RB_STENCIL_INFO
, 6);
201 OUT_RING(ring
, A6XX_RB_STENCIL_INFO_SEPARATE_STENCIL
);
202 OUT_RING(ring
, A6XX_RB_STENCIL_BUFFER_PITCH(stride
));
203 OUT_RING(ring
, A6XX_RB_STENCIL_BUFFER_ARRAY_PITCH(size
));
204 OUT_RELOCW(ring
, rsc
->stencil
->bo
, 0, 0, 0); /* RB_STENCIL_BASE_LO/HI */
205 OUT_RING(ring
, base
); /* RB_STENCIL_BASE_LO */
207 OUT_PKT4(ring
, REG_A6XX_RB_STENCIL_INFO
, 1);
208 OUT_RING(ring
, 0x00000000); /* RB_STENCIL_INFO */
211 OUT_PKT4(ring
, REG_A6XX_RB_DEPTH_BUFFER_INFO
, 6);
212 OUT_RING(ring
, A6XX_RB_DEPTH_BUFFER_INFO_DEPTH_FORMAT(DEPTH6_NONE
));
213 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_BUFFER_PITCH */
214 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_BUFFER_ARRAY_PITCH */
215 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_BUFFER_BASE_LO */
216 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_BUFFER_BASE_HI */
217 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_BUFFER_BASE_GMEM */
219 OUT_PKT4(ring
, REG_A6XX_GRAS_SU_DEPTH_BUFFER_INFO
, 1);
220 OUT_RING(ring
, A6XX_GRAS_SU_DEPTH_BUFFER_INFO_DEPTH_FORMAT(DEPTH6_NONE
));
222 OUT_PKT4(ring
, REG_A6XX_GRAS_LRZ_BUFFER_BASE_LO
, 5);
223 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_FLAG_BUFFER_BASE_LO */
224 OUT_RING(ring
, 0x00000000); /* RB_DEPTH_FLAG_BUFFER_BASE_HI */
225 OUT_RING(ring
, 0x00000000); /* GRAS_LRZ_BUFFER_PITCH */
226 OUT_RING(ring
, 0x00000000); /* GRAS_LRZ_FAST_CLEAR_BUFFER_BASE_LO */
227 OUT_RING(ring
, 0x00000000); /* GRAS_LRZ_FAST_CLEAR_BUFFER_BASE_HI */
229 OUT_PKT4(ring
, REG_A6XX_RB_STENCIL_INFO
, 1);
230 OUT_RING(ring
, 0x00000000); /* RB_STENCIL_INFO */
235 use_hw_binning(struct fd_batch
*batch
)
237 struct fd_gmem_stateobj
*gmem
= &batch
->ctx
->gmem
;
239 // TODO figure out hw limits for binning
241 return fd_binning_enabled
&& ((gmem
->nbins_x
* gmem
->nbins_y
) > 2) &&
242 (batch
->num_draws
> 0);
246 patch_draws(struct fd_batch
*batch
, enum pc_di_vis_cull_mode vismode
)
249 for (i
= 0; i
< fd_patch_num_elements(&batch
->draw_patches
); i
++) {
250 struct fd_cs_patch
*patch
= fd_patch_element(&batch
->draw_patches
, i
);
251 *patch
->cs
= patch
->val
| DRAW4(0, 0, 0, vismode
);
253 util_dynarray_resize(&batch
->draw_patches
, 0);
257 patch_gmem_bases(struct fd_batch
*batch
)
259 struct fd_gmem_stateobj
*gmem
= &batch
->ctx
->gmem
;
262 for (i
= 0; i
< fd_patch_num_elements(&batch
->gmem_patches
); i
++) {
263 struct fd_cs_patch
*patch
= fd_patch_element(&batch
->gmem_patches
, i
);
264 if (patch
->val
< MAX_RENDER_TARGETS
)
265 *patch
->cs
= gmem
->cbuf_base
[patch
->val
];
267 *patch
->cs
= gmem
->zsbuf_base
[patch
->val
- MAX_RENDER_TARGETS
];
269 util_dynarray_resize(&batch
->gmem_patches
, 0);
273 update_render_cntl(struct fd_batch
*batch
, bool binning
)
275 struct fd_ringbuffer
*ring
= batch
->gmem
;
278 cntl
|= A6XX_RB_RENDER_CNTL_UNK4
;
280 cntl
|= A6XX_RB_RENDER_CNTL_BINNING
;
282 OUT_PKT7(ring
, CP_REG_WRITE
, 3);
284 OUT_RING(ring
, REG_A6XX_RB_RENDER_CNTL
);
285 OUT_RING(ring
, cntl
);
289 update_vsc_pipe(struct fd_batch
*batch
)
291 struct fd_context
*ctx
= batch
->ctx
;
292 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
293 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
294 struct fd_ringbuffer
*ring
= batch
->gmem
;
297 OUT_PKT4(ring
, REG_A6XX_VSC_BIN_SIZE
, 3);
298 OUT_RING(ring
, A6XX_VSC_BIN_SIZE_WIDTH(gmem
->bin_w
) |
299 A6XX_VSC_BIN_SIZE_HEIGHT(gmem
->bin_h
));
300 OUT_RELOCW(ring
, fd6_ctx
->vsc_data
,
301 32 * A6XX_VSC_DATA_PITCH
, 0, 0); /* VSC_SIZE_ADDRESS_LO/HI */
303 OUT_PKT4(ring
, REG_A6XX_VSC_BIN_COUNT
, 1);
304 OUT_RING(ring
, A6XX_VSC_BIN_COUNT_NX(gmem
->nbins_x
) |
305 A6XX_VSC_BIN_COUNT_NY(gmem
->nbins_y
));
307 OUT_PKT4(ring
, REG_A6XX_VSC_PIPE_CONFIG_REG(0), 32);
308 for (i
= 0; i
< 32; i
++) {
309 struct fd_vsc_pipe
*pipe
= &ctx
->vsc_pipe
[i
];
310 OUT_RING(ring
, A6XX_VSC_PIPE_CONFIG_REG_X(pipe
->x
) |
311 A6XX_VSC_PIPE_CONFIG_REG_Y(pipe
->y
) |
312 A6XX_VSC_PIPE_CONFIG_REG_W(pipe
->w
) |
313 A6XX_VSC_PIPE_CONFIG_REG_H(pipe
->h
));
316 OUT_PKT4(ring
, REG_A6XX_VSC_PIPE_DATA2_ADDRESS_LO
, 4);
317 OUT_RELOCW(ring
, fd6_ctx
->vsc_data2
, 0, 0, 0);
318 OUT_RING(ring
, A6XX_VSC_DATA2_PITCH
);
319 OUT_RING(ring
, fd_bo_size(fd6_ctx
->vsc_data2
));
321 OUT_PKT4(ring
, REG_A6XX_VSC_PIPE_DATA_ADDRESS_LO
, 4);
322 OUT_RELOCW(ring
, fd6_ctx
->vsc_data
, 0, 0, 0);
323 OUT_RING(ring
, A6XX_VSC_DATA_PITCH
);
324 OUT_RING(ring
, fd_bo_size(fd6_ctx
->vsc_data
));
328 set_scissor(struct fd_ringbuffer
*ring
, uint32_t x1
, uint32_t y1
, uint32_t x2
, uint32_t y2
)
330 OUT_PKT4(ring
, REG_A6XX_GRAS_SC_WINDOW_SCISSOR_TL
, 2);
331 OUT_RING(ring
, A6XX_GRAS_SC_WINDOW_SCISSOR_TL_X(x1
) |
332 A6XX_GRAS_SC_WINDOW_SCISSOR_TL_Y(y1
));
333 OUT_RING(ring
, A6XX_GRAS_SC_WINDOW_SCISSOR_BR_X(x2
) |
334 A6XX_GRAS_SC_WINDOW_SCISSOR_BR_Y(y2
));
336 OUT_PKT4(ring
, REG_A6XX_GRAS_RESOLVE_CNTL_1
, 2);
337 OUT_RING(ring
, A6XX_GRAS_RESOLVE_CNTL_1_X(x1
) |
338 A6XX_GRAS_RESOLVE_CNTL_1_Y(y1
));
339 OUT_RING(ring
, A6XX_GRAS_RESOLVE_CNTL_2_X(x2
) |
340 A6XX_GRAS_RESOLVE_CNTL_2_Y(y2
));
344 set_bin_size(struct fd_ringbuffer
*ring
, uint32_t w
, uint32_t h
, uint32_t flag
)
346 OUT_PKT4(ring
, REG_A6XX_GRAS_BIN_CONTROL
, 1);
347 OUT_RING(ring
, A6XX_GRAS_BIN_CONTROL_BINW(w
) |
348 A6XX_GRAS_BIN_CONTROL_BINH(h
) | flag
);
350 OUT_PKT4(ring
, REG_A6XX_RB_BIN_CONTROL
, 1);
351 OUT_RING(ring
, A6XX_RB_BIN_CONTROL_BINW(w
) |
352 A6XX_RB_BIN_CONTROL_BINH(h
) | flag
);
354 /* no flag for RB_BIN_CONTROL2... */
355 OUT_PKT4(ring
, REG_A6XX_RB_BIN_CONTROL2
, 1);
356 OUT_RING(ring
, A6XX_RB_BIN_CONTROL2_BINW(w
) |
357 A6XX_RB_BIN_CONTROL2_BINH(h
));
361 emit_binning_pass(struct fd_batch
*batch
)
363 struct fd_context
*ctx
= batch
->ctx
;
364 struct fd_ringbuffer
*ring
= batch
->gmem
;
365 struct fd_gmem_stateobj
*gmem
= &batch
->ctx
->gmem
;
367 uint32_t x1
= gmem
->minx
;
368 uint32_t y1
= gmem
->miny
;
369 uint32_t x2
= gmem
->minx
+ gmem
->width
- 1;
370 uint32_t y2
= gmem
->miny
+ gmem
->height
- 1;
372 set_scissor(ring
, x1
, y1
, x2
, y2
);
374 emit_marker6(ring
, 7);
375 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
376 OUT_RING(ring
, A2XX_CP_SET_MARKER_0_MODE(RM6_BINNING
));
377 emit_marker6(ring
, 7);
379 OUT_PKT7(ring
, CP_SET_VISIBILITY_OVERRIDE
, 1);
382 OUT_PKT7(ring
, CP_SET_MODE
, 1);
387 OUT_PKT4(ring
, REG_A6XX_VFD_MODE_CNTL
, 1);
388 OUT_RING(ring
, A6XX_VFD_MODE_CNTL_BINNING_PASS
);
390 update_vsc_pipe(batch
);
392 OUT_PKT4(ring
, REG_A6XX_PC_UNKNOWN_9805
, 1);
395 OUT_PKT4(ring
, REG_A6XX_SP_UNKNOWN_A0F8
, 1);
398 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
399 OUT_RING(ring
, UNK_2C
);
401 OUT_PKT4(ring
, REG_A6XX_RB_WINDOW_OFFSET
, 1);
402 OUT_RING(ring
, A6XX_RB_WINDOW_OFFSET_X(0) |
403 A6XX_RB_WINDOW_OFFSET_Y(0));
405 OUT_PKT4(ring
, REG_A6XX_SP_TP_WINDOW_OFFSET
, 1);
406 OUT_RING(ring
, A6XX_SP_TP_WINDOW_OFFSET_X(0) |
407 A6XX_SP_TP_WINDOW_OFFSET_Y(0));
409 /* emit IB to binning drawcmds: */
410 fd6_emit_ib(ring
, batch
->draw
);
414 OUT_PKT7(ring
, CP_SET_DRAW_STATE
, 3);
415 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(0) |
416 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
417 CP_SET_DRAW_STATE__0_GROUP_ID(0));
418 OUT_RING(ring
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
419 OUT_RING(ring
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
421 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
422 OUT_RING(ring
, UNK_2D
);
424 OUT_PKT7(ring
, CP_EVENT_WRITE
, 4);
425 OUT_RING(ring
, CACHE_FLUSH_TS
);
426 OUT_RELOCW(ring
, fd6_context(ctx
)->blit_mem
, 0, 0, 0); /* ADDR_LO/HI */
427 OUT_RING(ring
, 0x00000000);
433 disable_msaa(struct fd_ringbuffer
*ring
)
436 OUT_PKT4(ring
, REG_A6XX_SP_TP_RAS_MSAA_CNTL
, 2);
437 OUT_RING(ring
, A6XX_SP_TP_RAS_MSAA_CNTL_SAMPLES(MSAA_ONE
));
438 OUT_RING(ring
, A6XX_SP_TP_DEST_MSAA_CNTL_SAMPLES(MSAA_ONE
) |
439 A6XX_SP_TP_DEST_MSAA_CNTL_MSAA_DISABLE
);
441 OUT_PKT4(ring
, REG_A6XX_GRAS_RAS_MSAA_CNTL
, 2);
442 OUT_RING(ring
, A6XX_GRAS_RAS_MSAA_CNTL_SAMPLES(MSAA_ONE
));
443 OUT_RING(ring
, A6XX_GRAS_DEST_MSAA_CNTL_SAMPLES(MSAA_ONE
) |
444 A6XX_GRAS_DEST_MSAA_CNTL_MSAA_DISABLE
);
446 OUT_PKT4(ring
, REG_A6XX_RB_RAS_MSAA_CNTL
, 2);
447 OUT_RING(ring
, A6XX_RB_RAS_MSAA_CNTL_SAMPLES(MSAA_ONE
));
448 OUT_RING(ring
, A6XX_RB_DEST_MSAA_CNTL_SAMPLES(MSAA_ONE
) |
449 A6XX_RB_DEST_MSAA_CNTL_MSAA_DISABLE
);
452 static void prepare_tile_setup_ib(struct fd_batch
*batch
);
453 static void prepare_tile_fini_ib(struct fd_batch
*batch
);
455 /* before first tile */
457 fd6_emit_tile_init(struct fd_batch
*batch
)
459 struct fd_context
*ctx
= batch
->ctx
;
460 struct fd_ringbuffer
*ring
= batch
->gmem
;
461 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
462 struct fd_gmem_stateobj
*gmem
= &batch
->ctx
->gmem
;
464 fd6_emit_restore(batch
, ring
);
466 fd6_emit_lrz_flush(ring
);
468 if (batch
->lrz_clear
)
469 fd6_emit_ib(ring
, batch
->lrz_clear
);
471 fd6_cache_flush(batch
, ring
);
473 prepare_tile_setup_ib(batch
);
474 prepare_tile_fini_ib(batch
);
476 OUT_PKT7(ring
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
479 /* 0x10000000 for BYPASS.. 0x7c13c080 for GMEM: */
481 OUT_PKT4(ring
, REG_A6XX_RB_CCU_CNTL
, 1);
482 OUT_RING(ring
, 0x7c400004); /* RB_CCU_CNTL */
484 emit_zs(ring
, pfb
->zsbuf
, &ctx
->gmem
);
485 emit_mrt(ring
, pfb
, &ctx
->gmem
);
487 patch_gmem_bases(batch
);
491 if (use_hw_binning(batch
)) {
492 set_bin_size(ring
, gmem
->bin_w
, gmem
->bin_h
,
493 A6XX_RB_BIN_CONTROL_BINNING_PASS
| 0x6000000);
494 update_render_cntl(batch
, true);
495 emit_binning_pass(batch
);
496 patch_draws(batch
, USE_VISIBILITY
);
498 set_bin_size(ring
, gmem
->bin_w
, gmem
->bin_h
,
499 A6XX_RB_BIN_CONTROL_USE_VIZ
| 0x6000000);
501 OUT_PKT4(ring
, REG_A6XX_VFD_MODE_CNTL
, 1);
504 set_bin_size(ring
, gmem
->bin_w
, gmem
->bin_h
, 0x6000000);
505 patch_draws(batch
, IGNORE_VISIBILITY
);
508 update_render_cntl(batch
, false);
512 set_window_offset(struct fd_ringbuffer
*ring
, uint32_t x1
, uint32_t y1
)
514 OUT_PKT4(ring
, REG_A6XX_RB_WINDOW_OFFSET
, 1);
515 OUT_RING(ring
, A6XX_RB_WINDOW_OFFSET_X(x1
) |
516 A6XX_RB_WINDOW_OFFSET_Y(y1
));
518 OUT_PKT4(ring
, REG_A6XX_RB_WINDOW_OFFSET2
, 1);
519 OUT_RING(ring
, A6XX_RB_WINDOW_OFFSET2_X(x1
) |
520 A6XX_RB_WINDOW_OFFSET2_Y(y1
));
522 OUT_PKT4(ring
, REG_A6XX_SP_WINDOW_OFFSET
, 1);
523 OUT_RING(ring
, A6XX_SP_WINDOW_OFFSET_X(x1
) |
524 A6XX_SP_WINDOW_OFFSET_Y(y1
));
526 OUT_PKT4(ring
, REG_A6XX_SP_TP_WINDOW_OFFSET
, 1);
527 OUT_RING(ring
, A6XX_SP_TP_WINDOW_OFFSET_X(x1
) |
528 A6XX_SP_TP_WINDOW_OFFSET_Y(y1
));
531 /* before mem2gmem */
533 fd6_emit_tile_prep(struct fd_batch
*batch
, struct fd_tile
*tile
)
535 struct fd_context
*ctx
= batch
->ctx
;
536 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
537 struct fd_ringbuffer
*ring
= batch
->gmem
;
539 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
540 OUT_RING(ring
, A2XX_CP_SET_MARKER_0_MODE(0x7));
542 emit_marker6(ring
, 7);
543 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
544 OUT_RING(ring
, A2XX_CP_SET_MARKER_0_MODE(RM6_GMEM
) | 0x10);
545 emit_marker6(ring
, 7);
547 uint32_t x1
= tile
->xoff
;
548 uint32_t y1
= tile
->yoff
;
549 uint32_t x2
= tile
->xoff
+ tile
->bin_w
- 1;
550 uint32_t y2
= tile
->yoff
+ tile
->bin_h
- 1;
552 set_scissor(ring
, x1
, y1
, x2
, y2
);
554 set_window_offset(ring
, x1
, y1
);
556 OUT_PKT4(ring
, REG_A6XX_VPC_SO_OVERRIDE
, 1);
557 OUT_RING(ring
, A6XX_VPC_SO_OVERRIDE_SO_DISABLE
);
559 if (use_hw_binning(batch
)) {
560 struct fd_vsc_pipe
*pipe
= &ctx
->vsc_pipe
[tile
->p
];
562 OUT_PKT7(ring
, CP_WAIT_FOR_ME
, 0);
564 OUT_PKT7(ring
, CP_SET_VISIBILITY_OVERRIDE
, 1);
567 OUT_PKT7(ring
, CP_SET_MODE
, 1);
570 OUT_PKT7(ring
, CP_SET_BIN_DATA5
, 7);
571 OUT_RING(ring
, CP_SET_BIN_DATA5_0_VSC_SIZE(pipe
->w
* pipe
->h
) |
572 CP_SET_BIN_DATA5_0_VSC_N(tile
->n
));
573 OUT_RELOC(ring
, fd6_ctx
->vsc_data
, /* VSC_PIPE[p].DATA_ADDRESS */
574 (tile
->p
* A6XX_VSC_DATA_PITCH
), 0, 0);
575 OUT_RELOC(ring
, fd6_ctx
->vsc_data
, /* VSC_SIZE_ADDRESS + (p * 4) */
576 (tile
->p
* 4) + (32 * A6XX_VSC_DATA_PITCH
), 0, 0);
577 OUT_RELOC(ring
, fd6_ctx
->vsc_data2
,
578 (tile
->p
* A6XX_VSC_DATA2_PITCH
), 0, 0);
580 OUT_PKT7(ring
, CP_SET_VISIBILITY_OVERRIDE
, 1);
583 OUT_PKT7(ring
, CP_SET_MODE
, 1);
589 set_blit_scissor(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
)
591 struct pipe_scissor_state blit_scissor
;
592 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
594 blit_scissor
.minx
= batch
->max_scissor
.minx
;
595 blit_scissor
.miny
= batch
->max_scissor
.miny
;
596 blit_scissor
.maxx
= MIN2(pfb
->width
, batch
->max_scissor
.maxx
);
597 blit_scissor
.maxy
= MIN2(pfb
->height
, batch
->max_scissor
.maxy
);
599 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_SCISSOR_TL
, 2);
601 A6XX_RB_BLIT_SCISSOR_TL_X(blit_scissor
.minx
) |
602 A6XX_RB_BLIT_SCISSOR_TL_Y(blit_scissor
.miny
));
604 A6XX_RB_BLIT_SCISSOR_BR_X(blit_scissor
.maxx
- 1) |
605 A6XX_RB_BLIT_SCISSOR_BR_Y(blit_scissor
.maxy
- 1));
609 emit_blit(struct fd_batch
*batch
,
610 struct fd_ringbuffer
*ring
,
612 struct pipe_surface
*psurf
,
613 struct fd_resource
*rsc
)
615 struct fd_resource_slice
*slice
;
618 slice
= fd_resource_slice(rsc
, psurf
->u
.tex
.level
);
619 offset
= fd_resource_offset(rsc
, psurf
->u
.tex
.level
,
620 psurf
->u
.tex
.first_layer
);
622 debug_assert(psurf
->u
.tex
.first_layer
== psurf
->u
.tex
.last_layer
);
624 enum pipe_format pfmt
= psurf
->format
;
625 enum a6xx_color_fmt format
= fd6_pipe2color(pfmt
);
626 uint32_t stride
= slice
->pitch
* rsc
->cpp
;
627 uint32_t size
= slice
->size0
;
628 enum a3xx_color_swap swap
= fd6_pipe2swap(pfmt
);
632 // tiled = rsc->tile_mode &&
633 // !fd_resource_level_linear(psurf->texture, psurf->u.tex.level);
635 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_DST_INFO
, 5);
637 A6XX_RB_BLIT_DST_INFO_TILE_MODE(TILE6_LINEAR
) |
638 A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(format
) |
639 A6XX_RB_BLIT_DST_INFO_COLOR_SWAP(swap
));
640 OUT_RELOCW(ring
, rsc
->bo
, offset
, 0, 0); /* RB_BLIT_DST_LO/HI */
641 OUT_RING(ring
, A6XX_RB_BLIT_DST_PITCH(stride
));
642 OUT_RING(ring
, A6XX_RB_BLIT_DST_ARRAY_PITCH(size
));
644 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_BASE_GMEM
, 1);
645 OUT_RING(ring
, base
);
647 fd6_emit_blit(batch
, ring
);
651 emit_restore_blit(struct fd_batch
*batch
,
652 struct fd_ringbuffer
*ring
,
654 struct pipe_surface
*psurf
,
655 struct fd_resource
*rsc
,
661 case FD_BUFFER_COLOR
:
662 info
|= A6XX_RB_BLIT_INFO_UNK0
;
664 case FD_BUFFER_STENCIL
:
665 info
|= A6XX_RB_BLIT_INFO_UNK0
;
667 case FD_BUFFER_DEPTH
:
668 info
|= A6XX_RB_BLIT_INFO_DEPTH
| A6XX_RB_BLIT_INFO_UNK0
;
672 if (util_format_is_pure_integer(psurf
->format
))
673 info
|= A6XX_RB_BLIT_INFO_INTEGER
;
675 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_INFO
, 1);
676 OUT_RING(ring
, info
| A6XX_RB_BLIT_INFO_GMEM
);
678 emit_blit(batch
, ring
, base
, psurf
, rsc
);
682 * transfer from system memory to gmem
685 emit_restore_blits(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
)
687 struct fd_context
*ctx
= batch
->ctx
;
688 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
689 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
691 if (batch
->restore
& FD_BUFFER_COLOR
) {
693 for (i
= 0; i
< pfb
->nr_cbufs
; i
++) {
696 if (!(batch
->restore
& (PIPE_CLEAR_COLOR0
<< i
)))
698 emit_restore_blit(batch
, ring
, gmem
->cbuf_base
[i
], pfb
->cbufs
[i
],
699 fd_resource(pfb
->cbufs
[i
]->texture
),
704 if (batch
->restore
& (FD_BUFFER_DEPTH
| FD_BUFFER_STENCIL
)) {
705 struct fd_resource
*rsc
= fd_resource(pfb
->zsbuf
->texture
);
707 if (!rsc
->stencil
|| (batch
->restore
& FD_BUFFER_DEPTH
)) {
708 emit_restore_blit(batch
, ring
, gmem
->zsbuf_base
[0], pfb
->zsbuf
, rsc
,
711 if (rsc
->stencil
&& (batch
->restore
& FD_BUFFER_STENCIL
)) {
712 emit_restore_blit(batch
, ring
, gmem
->zsbuf_base
[1], pfb
->zsbuf
, rsc
->stencil
,
719 prepare_tile_setup_ib(struct fd_batch
*batch
)
721 batch
->tile_setup
= fd_submit_new_ringbuffer(batch
->submit
, 0x1000,
722 FD_RINGBUFFER_STREAMING
);
724 set_blit_scissor(batch
, batch
->tile_setup
);
726 emit_restore_blits(batch
, batch
->tile_setup
);
730 * transfer from system memory to gmem
733 fd6_emit_tile_mem2gmem(struct fd_batch
*batch
, struct fd_tile
*tile
)
737 /* before IB to rendering cmds: */
739 fd6_emit_tile_renderprep(struct fd_batch
*batch
, struct fd_tile
*tile
)
741 fd6_emit_ib(batch
->gmem
, batch
->tile_setup
);
745 emit_resolve_blit(struct fd_batch
*batch
,
746 struct fd_ringbuffer
*ring
,
748 struct pipe_surface
*psurf
,
749 struct fd_resource
*rsc
,
758 case FD_BUFFER_COLOR
:
760 case FD_BUFFER_STENCIL
:
761 info
|= A6XX_RB_BLIT_INFO_UNK0
;
763 case FD_BUFFER_DEPTH
:
764 info
|= A6XX_RB_BLIT_INFO_DEPTH
;
768 if (util_format_is_pure_integer(psurf
->format
))
769 info
|= A6XX_RB_BLIT_INFO_INTEGER
;
771 OUT_PKT4(ring
, REG_A6XX_RB_BLIT_INFO
, 1);
772 OUT_RING(ring
, info
);
774 emit_blit(batch
, ring
, base
, psurf
, rsc
);
778 * transfer from gmem to system memory (ie. normal RAM)
782 prepare_tile_fini_ib(struct fd_batch
*batch
)
784 struct fd_context
*ctx
= batch
->ctx
;
785 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
786 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
787 struct fd_ringbuffer
*ring
;
789 batch
->tile_fini
= fd_submit_new_ringbuffer(batch
->submit
, 0x1000,
790 FD_RINGBUFFER_STREAMING
);
791 ring
= batch
->tile_fini
;
793 if (use_hw_binning(batch
)) {
794 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
795 OUT_RING(ring
, A2XX_CP_SET_MARKER_0_MODE(0x5) | 0x10);
798 OUT_PKT7(ring
, CP_SET_DRAW_STATE
, 3);
799 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(0) |
800 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
801 CP_SET_DRAW_STATE__0_GROUP_ID(0));
802 OUT_RING(ring
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
803 OUT_RING(ring
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
805 OUT_PKT7(ring
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
808 emit_marker6(ring
, 7);
809 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
810 OUT_RING(ring
, A2XX_CP_SET_MARKER_0_MODE(RM6_RESOLVE
) | 0x10);
811 emit_marker6(ring
, 7);
813 set_blit_scissor(batch
, ring
);
815 if (batch
->resolve
& (FD_BUFFER_DEPTH
| FD_BUFFER_STENCIL
)) {
816 struct fd_resource
*rsc
= fd_resource(pfb
->zsbuf
->texture
);
818 if (!rsc
->stencil
|| (batch
->resolve
& FD_BUFFER_DEPTH
)) {
819 emit_resolve_blit(batch
, ring
,
820 gmem
->zsbuf_base
[0], pfb
->zsbuf
, rsc
,
823 if (rsc
->stencil
&& (batch
->resolve
& FD_BUFFER_STENCIL
)) {
824 emit_resolve_blit(batch
, ring
,
825 gmem
->zsbuf_base
[1], pfb
->zsbuf
, rsc
->stencil
,
830 if (batch
->resolve
& FD_BUFFER_COLOR
) {
832 for (i
= 0; i
< pfb
->nr_cbufs
; i
++) {
835 if (!(batch
->resolve
& (PIPE_CLEAR_COLOR0
<< i
)))
837 emit_resolve_blit(batch
, ring
, gmem
->cbuf_base
[i
], pfb
->cbufs
[i
],
838 fd_resource(pfb
->cbufs
[i
]->texture
),
845 fd6_emit_tile_gmem2mem(struct fd_batch
*batch
, struct fd_tile
*tile
)
847 fd6_emit_ib(batch
->gmem
, batch
->tile_fini
);
851 fd6_emit_tile_fini(struct fd_batch
*batch
)
853 struct fd_ringbuffer
*ring
= batch
->gmem
;
855 OUT_PKT4(ring
, REG_A6XX_GRAS_LRZ_CNTL
, 1);
856 OUT_RING(ring
, A6XX_GRAS_LRZ_CNTL_ENABLE
| A6XX_GRAS_LRZ_CNTL_UNK3
);
858 fd6_emit_lrz_flush(ring
);
860 fd6_event_write(batch
, ring
, CACHE_FLUSH_TS
, true);
864 fd6_emit_sysmem_prep(struct fd_batch
*batch
)
866 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
867 struct fd_ringbuffer
*ring
= batch
->gmem
;
869 fd6_emit_restore(batch
, ring
);
871 fd6_emit_lrz_flush(ring
);
873 emit_marker6(ring
, 7);
874 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
875 OUT_RING(ring
, A2XX_CP_SET_MARKER_0_MODE(RM6_BYPASS
) | 0x10); /* | 0x10 ? */
876 emit_marker6(ring
, 7);
878 OUT_PKT7(ring
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
881 fd6_event_write(batch
, ring
, PC_CCU_INVALIDATE_COLOR
, false);
882 fd6_cache_flush(batch
, ring
);
885 OUT_PKT4(ring
, REG_A6XX_PC_POWER_CNTL
, 1);
886 OUT_RING(ring
, 0x00000003); /* PC_POWER_CNTL */
890 OUT_PKT4(ring
, REG_A6XX_VFD_POWER_CNTL
, 1);
891 OUT_RING(ring
, 0x00000003); /* VFD_POWER_CNTL */
894 /* 0x10000000 for BYPASS.. 0x7c13c080 for GMEM: */
896 OUT_PKT4(ring
, REG_A6XX_RB_CCU_CNTL
, 1);
897 OUT_RING(ring
, 0x10000000); /* RB_CCU_CNTL */
899 set_scissor(ring
, 0, 0, pfb
->width
- 1, pfb
->height
- 1);
901 set_window_offset(ring
, 0, 0);
903 set_bin_size(ring
, 0, 0, 0xc00000); /* 0xc00000 = BYPASS? */
905 OUT_PKT7(ring
, CP_SET_VISIBILITY_OVERRIDE
, 1);
908 patch_draws(batch
, IGNORE_VISIBILITY
);
910 emit_zs(ring
, pfb
->zsbuf
, NULL
);
911 emit_mrt(ring
, pfb
, NULL
);
917 fd6_emit_sysmem_fini(struct fd_batch
*batch
)
919 struct fd_ringbuffer
*ring
= batch
->gmem
;
921 OUT_PKT7(ring
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
924 fd6_emit_lrz_flush(ring
);
926 fd6_event_write(batch
, ring
, UNK_1D
, true);
930 fd6_gmem_init(struct pipe_context
*pctx
)
932 struct fd_context
*ctx
= fd_context(pctx
);
934 ctx
->emit_tile_init
= fd6_emit_tile_init
;
935 ctx
->emit_tile_prep
= fd6_emit_tile_prep
;
936 ctx
->emit_tile_mem2gmem
= fd6_emit_tile_mem2gmem
;
937 ctx
->emit_tile_renderprep
= fd6_emit_tile_renderprep
;
938 ctx
->emit_tile_gmem2mem
= fd6_emit_tile_gmem2mem
;
939 ctx
->emit_tile_fini
= fd6_emit_tile_fini
;
940 ctx
->emit_sysmem_prep
= fd6_emit_sysmem_prep
;
941 ctx
->emit_sysmem_fini
= fd6_emit_sysmem_fini
;