2 * Copyright (C) 2013 Rob Clark <robclark@freedesktop.org>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Rob Clark <robclark@freedesktop.org>
27 #include "pipe/p_state.h"
28 #include "util/u_string.h"
29 #include "util/u_memory.h"
30 #include "util/u_inlines.h"
31 #include "util/u_format.h"
33 #include "freedreno_draw.h"
34 #include "freedreno_state.h"
35 #include "freedreno_resource.h"
38 #include "fd3_context.h"
40 #include "fd3_program.h"
41 #include "fd3_format.h"
45 emit_mrt(struct fd_ringbuffer
*ring
, unsigned nr_bufs
,
46 struct pipe_surface
**bufs
, uint32_t *bases
, uint32_t bin_w
,
49 enum a3xx_tile_mode tile_mode
;
53 tile_mode
= TILE_32X32
;
58 for (i
= 0; i
< A3XX_MAX_RENDER_TARGETS
; i
++) {
59 enum pipe_format pformat
= 0;
60 enum a3xx_color_fmt format
= 0;
61 enum a3xx_color_swap swap
= WZYX
;
63 struct fd_resource
*rsc
= NULL
;
64 struct fd_resource_slice
*slice
= NULL
;
69 if ((i
< nr_bufs
) && bufs
[i
]) {
70 struct pipe_surface
*psurf
= bufs
[i
];
72 rsc
= fd_resource(psurf
->texture
);
73 pformat
= psurf
->format
;
74 /* In case we're drawing to Z32F_S8, the "color" actually goes to
79 pformat
= rsc
->base
.format
;
83 slice
= fd_resource_slice(rsc
, psurf
->u
.tex
.level
);
84 format
= fd3_pipe2color(pformat
);
85 swap
= fd3_pipe2swap(pformat
);
87 srgb
= util_format_is_srgb(pformat
);
89 pformat
= util_format_linear(pformat
);
91 debug_assert(psurf
->u
.tex
.first_layer
== psurf
->u
.tex
.last_layer
);
93 offset
= fd_resource_offset(rsc
, psurf
->u
.tex
.level
,
94 psurf
->u
.tex
.first_layer
);
97 stride
= bin_w
* rsc
->cpp
;
103 stride
= slice
->pitch
* rsc
->cpp
;
105 } else if (i
< nr_bufs
&& bases
) {
109 OUT_PKT0(ring
, REG_A3XX_RB_MRT_BUF_INFO(i
), 2);
110 OUT_RING(ring
, A3XX_RB_MRT_BUF_INFO_COLOR_FORMAT(format
) |
111 A3XX_RB_MRT_BUF_INFO_COLOR_TILE_MODE(tile_mode
) |
112 A3XX_RB_MRT_BUF_INFO_COLOR_BUF_PITCH(stride
) |
113 A3XX_RB_MRT_BUF_INFO_COLOR_SWAP(swap
) |
114 COND(srgb
, A3XX_RB_MRT_BUF_INFO_COLOR_SRGB
));
115 if (bin_w
|| (i
>= nr_bufs
) || !bufs
[i
]) {
116 OUT_RING(ring
, A3XX_RB_MRT_BUF_BASE_COLOR_BUF_BASE(base
));
118 OUT_RELOCW(ring
, rsc
->bo
, offset
, 0, -1);
121 OUT_PKT0(ring
, REG_A3XX_SP_FS_IMAGE_OUTPUT_REG(i
), 1);
122 OUT_RING(ring
, COND((i
< nr_bufs
) && bufs
[i
],
123 A3XX_SP_FS_IMAGE_OUTPUT_REG_MRTFORMAT(
124 fd3_fs_output_format(pformat
))));
129 use_hw_binning(struct fd_batch
*batch
)
131 struct fd_gmem_stateobj
*gmem
= &batch
->ctx
->gmem
;
133 /* workaround: combining scissor optimization and hw binning
134 * seems problematic. Seems like we end up with a mismatch
135 * between binning pass and rendering pass, wrt. where the hw
136 * thinks the vertices belong. And the blob driver doesn't
137 * seem to implement anything like scissor optimization, so
138 * not entirely sure what I might be missing.
140 * But scissor optimization is mainly for window managers,
141 * which don't have many vertices (and therefore doesn't
142 * benefit much from binning pass).
144 * So for now just disable binning if scissor optimization is
147 if (gmem
->minx
|| gmem
->miny
)
150 if ((gmem
->maxpw
* gmem
->maxph
) > 32)
153 if ((gmem
->maxpw
> 15) || (gmem
->maxph
> 15))
156 return fd_binning_enabled
&& ((gmem
->nbins_x
* gmem
->nbins_y
) > 2);
159 /* workaround for (hlsq?) lockup with hw binning on a3xx patchlevel 0 */
160 static void update_vsc_pipe(struct fd_batch
*batch
);
162 emit_binning_workaround(struct fd_batch
*batch
)
164 struct fd_context
*ctx
= batch
->ctx
;
165 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
166 struct fd_ringbuffer
*ring
= batch
->gmem
;
167 struct fd3_emit emit
= {
168 .debug
= &ctx
->debug
,
169 .vtx
= &ctx
->solid_vbuf_state
,
170 .prog
= &ctx
->solid_prog
,
172 .half_precision
= true,
176 OUT_PKT0(ring
, REG_A3XX_RB_MODE_CONTROL
, 2);
177 OUT_RING(ring
, A3XX_RB_MODE_CONTROL_RENDER_MODE(RB_RESOLVE_PASS
) |
178 A3XX_RB_MODE_CONTROL_MARB_CACHE_SPLIT_MODE
|
179 A3XX_RB_MODE_CONTROL_MRT(0));
180 OUT_RING(ring
, A3XX_RB_RENDER_CONTROL_BIN_WIDTH(32) |
181 A3XX_RB_RENDER_CONTROL_DISABLE_COLOR_PIPE
|
182 A3XX_RB_RENDER_CONTROL_ALPHA_TEST_FUNC(FUNC_NEVER
));
184 OUT_PKT0(ring
, REG_A3XX_RB_COPY_CONTROL
, 4);
185 OUT_RING(ring
, A3XX_RB_COPY_CONTROL_MSAA_RESOLVE(MSAA_ONE
) |
186 A3XX_RB_COPY_CONTROL_MODE(0) |
187 A3XX_RB_COPY_CONTROL_GMEM_BASE(0));
188 OUT_RELOCW(ring
, fd_resource(ctx
->solid_vbuf
)->bo
, 0x20, 0, -1); /* RB_COPY_DEST_BASE */
189 OUT_RING(ring
, A3XX_RB_COPY_DEST_PITCH_PITCH(128));
190 OUT_RING(ring
, A3XX_RB_COPY_DEST_INFO_TILE(LINEAR
) |
191 A3XX_RB_COPY_DEST_INFO_FORMAT(RB_R8G8B8A8_UNORM
) |
192 A3XX_RB_COPY_DEST_INFO_SWAP(WZYX
) |
193 A3XX_RB_COPY_DEST_INFO_COMPONENT_ENABLE(0xf) |
194 A3XX_RB_COPY_DEST_INFO_ENDIAN(ENDIAN_NONE
));
196 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_CONTROL
, 1);
197 OUT_RING(ring
, A3XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RESOLVE_PASS
) |
198 A3XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
199 A3XX_GRAS_SC_CONTROL_RASTER_MODE(1));
201 fd3_program_emit(ring
, &emit
, 0, NULL
);
202 fd3_emit_vertex_bufs(ring
, &emit
);
204 OUT_PKT0(ring
, REG_A3XX_HLSQ_CONTROL_0_REG
, 4);
205 OUT_RING(ring
, A3XX_HLSQ_CONTROL_0_REG_FSTHREADSIZE(FOUR_QUADS
) |
206 A3XX_HLSQ_CONTROL_0_REG_FSSUPERTHREADENABLE
|
207 A3XX_HLSQ_CONTROL_0_REG_RESERVED2
|
208 A3XX_HLSQ_CONTROL_0_REG_SPCONSTFULLUPDATE
);
209 OUT_RING(ring
, A3XX_HLSQ_CONTROL_1_REG_VSTHREADSIZE(TWO_QUADS
) |
210 A3XX_HLSQ_CONTROL_1_REG_VSSUPERTHREADENABLE
);
211 OUT_RING(ring
, A3XX_HLSQ_CONTROL_2_REG_PRIMALLOCTHRESHOLD(31));
212 OUT_RING(ring
, 0); /* HLSQ_CONTROL_3_REG */
214 OUT_PKT0(ring
, REG_A3XX_HLSQ_CONST_FSPRESV_RANGE_REG
, 1);
215 OUT_RING(ring
, A3XX_HLSQ_CONST_FSPRESV_RANGE_REG_STARTENTRY(0x20) |
216 A3XX_HLSQ_CONST_FSPRESV_RANGE_REG_ENDENTRY(0x20));
218 OUT_PKT0(ring
, REG_A3XX_RB_MSAA_CONTROL
, 1);
219 OUT_RING(ring
, A3XX_RB_MSAA_CONTROL_DISABLE
|
220 A3XX_RB_MSAA_CONTROL_SAMPLES(MSAA_ONE
) |
221 A3XX_RB_MSAA_CONTROL_SAMPLE_MASK(0xffff));
223 OUT_PKT0(ring
, REG_A3XX_RB_DEPTH_CONTROL
, 1);
224 OUT_RING(ring
, A3XX_RB_DEPTH_CONTROL_ZFUNC(FUNC_NEVER
));
226 OUT_PKT0(ring
, REG_A3XX_RB_STENCIL_CONTROL
, 1);
227 OUT_RING(ring
, A3XX_RB_STENCIL_CONTROL_FUNC(FUNC_NEVER
) |
228 A3XX_RB_STENCIL_CONTROL_FAIL(STENCIL_KEEP
) |
229 A3XX_RB_STENCIL_CONTROL_ZPASS(STENCIL_KEEP
) |
230 A3XX_RB_STENCIL_CONTROL_ZFAIL(STENCIL_KEEP
) |
231 A3XX_RB_STENCIL_CONTROL_FUNC_BF(FUNC_NEVER
) |
232 A3XX_RB_STENCIL_CONTROL_FAIL_BF(STENCIL_KEEP
) |
233 A3XX_RB_STENCIL_CONTROL_ZPASS_BF(STENCIL_KEEP
) |
234 A3XX_RB_STENCIL_CONTROL_ZFAIL_BF(STENCIL_KEEP
));
236 OUT_PKT0(ring
, REG_A3XX_GRAS_SU_MODE_CONTROL
, 1);
237 OUT_RING(ring
, A3XX_GRAS_SU_MODE_CONTROL_LINEHALFWIDTH(0.0));
239 OUT_PKT0(ring
, REG_A3XX_VFD_INDEX_MIN
, 4);
240 OUT_RING(ring
, 0); /* VFD_INDEX_MIN */
241 OUT_RING(ring
, 2); /* VFD_INDEX_MAX */
242 OUT_RING(ring
, 0); /* VFD_INSTANCEID_OFFSET */
243 OUT_RING(ring
, 0); /* VFD_INDEX_OFFSET */
245 OUT_PKT0(ring
, REG_A3XX_PC_PRIM_VTX_CNTL
, 1);
246 OUT_RING(ring
, A3XX_PC_PRIM_VTX_CNTL_STRIDE_IN_VPC(0) |
247 A3XX_PC_PRIM_VTX_CNTL_POLYMODE_FRONT_PTYPE(PC_DRAW_TRIANGLES
) |
248 A3XX_PC_PRIM_VTX_CNTL_POLYMODE_BACK_PTYPE(PC_DRAW_TRIANGLES
) |
249 A3XX_PC_PRIM_VTX_CNTL_PROVOKING_VTX_LAST
);
251 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_WINDOW_SCISSOR_TL
, 2);
252 OUT_RING(ring
, A3XX_GRAS_SC_WINDOW_SCISSOR_TL_X(0) |
253 A3XX_GRAS_SC_WINDOW_SCISSOR_TL_Y(1));
254 OUT_RING(ring
, A3XX_GRAS_SC_WINDOW_SCISSOR_BR_X(0) |
255 A3XX_GRAS_SC_WINDOW_SCISSOR_BR_Y(1));
257 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_SCREEN_SCISSOR_TL
, 2);
258 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_TL_X(0) |
259 A3XX_GRAS_SC_SCREEN_SCISSOR_TL_Y(0));
260 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_BR_X(31) |
261 A3XX_GRAS_SC_SCREEN_SCISSOR_BR_Y(0));
264 OUT_PKT0(ring
, REG_A3XX_GRAS_CL_VPORT_XOFFSET
, 6);
265 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_XOFFSET(0.0));
266 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_XSCALE(1.0));
267 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_YOFFSET(0.0));
268 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_YSCALE(1.0));
269 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_ZOFFSET(0.0));
270 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_ZSCALE(1.0));
272 OUT_PKT0(ring
, REG_A3XX_GRAS_CL_CLIP_CNTL
, 1);
273 OUT_RING(ring
, A3XX_GRAS_CL_CLIP_CNTL_CLIP_DISABLE
|
274 A3XX_GRAS_CL_CLIP_CNTL_ZFAR_CLIP_DISABLE
|
275 A3XX_GRAS_CL_CLIP_CNTL_VP_CLIP_CODE_IGNORE
|
276 A3XX_GRAS_CL_CLIP_CNTL_VP_XFORM_DISABLE
|
277 A3XX_GRAS_CL_CLIP_CNTL_PERSP_DIVISION_DISABLE
);
279 OUT_PKT0(ring
, REG_A3XX_GRAS_CL_GB_CLIP_ADJ
, 1);
280 OUT_RING(ring
, A3XX_GRAS_CL_GB_CLIP_ADJ_HORZ(0) |
281 A3XX_GRAS_CL_GB_CLIP_ADJ_VERT(0));
283 OUT_PKT3(ring
, CP_DRAW_INDX_2
, 5);
284 OUT_RING(ring
, 0x00000000); /* viz query info. */
285 OUT_RING(ring
, DRAW(DI_PT_RECTLIST
, DI_SRC_SEL_IMMEDIATE
,
286 INDEX_SIZE_32_BIT
, IGNORE_VISIBILITY
, 0));
287 OUT_RING(ring
, 2); /* NumIndices */
292 OUT_PKT0(ring
, REG_A3XX_HLSQ_CONTROL_0_REG
, 1);
293 OUT_RING(ring
, A3XX_HLSQ_CONTROL_0_REG_FSTHREADSIZE(TWO_QUADS
));
295 OUT_PKT0(ring
, REG_A3XX_VFD_PERFCOUNTER0_SELECT
, 1);
296 OUT_RING(ring
, 0x00000000);
299 OUT_PKT0(ring
, REG_A3XX_VSC_BIN_SIZE
, 1);
300 OUT_RING(ring
, A3XX_VSC_BIN_SIZE_WIDTH(gmem
->bin_w
) |
301 A3XX_VSC_BIN_SIZE_HEIGHT(gmem
->bin_h
));
303 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_CONTROL
, 1);
304 OUT_RING(ring
, A3XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
305 A3XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
306 A3XX_GRAS_SC_CONTROL_RASTER_MODE(0));
308 OUT_PKT0(ring
, REG_A3XX_GRAS_CL_CLIP_CNTL
, 1);
309 OUT_RING(ring
, 0x00000000);
312 /* transfer from gmem to system memory (ie. normal RAM) */
315 emit_gmem2mem_surf(struct fd_batch
*batch
,
316 enum adreno_rb_copy_control_mode mode
,
318 uint32_t base
, struct pipe_surface
*psurf
)
320 struct fd_ringbuffer
*ring
= batch
->gmem
;
321 struct fd_resource
*rsc
= fd_resource(psurf
->texture
);
322 enum pipe_format format
= psurf
->format
;
329 format
= rsc
->base
.format
;
332 struct fd_resource_slice
*slice
= fd_resource_slice(rsc
, psurf
->u
.tex
.level
);
333 uint32_t offset
= fd_resource_offset(rsc
, psurf
->u
.tex
.level
,
334 psurf
->u
.tex
.first_layer
);
336 debug_assert(psurf
->u
.tex
.first_layer
== psurf
->u
.tex
.last_layer
);
338 OUT_PKT0(ring
, REG_A3XX_RB_COPY_CONTROL
, 4);
339 OUT_RING(ring
, A3XX_RB_COPY_CONTROL_MSAA_RESOLVE(MSAA_ONE
) |
340 A3XX_RB_COPY_CONTROL_MODE(mode
) |
341 A3XX_RB_COPY_CONTROL_GMEM_BASE(base
) |
342 COND(format
== PIPE_FORMAT_Z32_FLOAT
||
343 format
== PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
,
344 A3XX_RB_COPY_CONTROL_DEPTH32_RESOLVE
));
346 OUT_RELOCW(ring
, rsc
->bo
, offset
, 0, -1); /* RB_COPY_DEST_BASE */
347 OUT_RING(ring
, A3XX_RB_COPY_DEST_PITCH_PITCH(slice
->pitch
* rsc
->cpp
));
348 OUT_RING(ring
, A3XX_RB_COPY_DEST_INFO_TILE(LINEAR
) |
349 A3XX_RB_COPY_DEST_INFO_FORMAT(fd3_pipe2color(format
)) |
350 A3XX_RB_COPY_DEST_INFO_COMPONENT_ENABLE(0xf) |
351 A3XX_RB_COPY_DEST_INFO_ENDIAN(ENDIAN_NONE
) |
352 A3XX_RB_COPY_DEST_INFO_SWAP(fd3_pipe2swap(format
)));
354 fd_draw(batch
, ring
, DI_PT_RECTLIST
, IGNORE_VISIBILITY
,
355 DI_SRC_SEL_AUTO_INDEX
, 2, 0, INDEX_SIZE_IGN
, 0, 0, NULL
);
359 fd3_emit_tile_gmem2mem(struct fd_batch
*batch
, struct fd_tile
*tile
)
361 struct fd_context
*ctx
= batch
->ctx
;
362 struct fd_ringbuffer
*ring
= batch
->gmem
;
363 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
364 struct fd3_emit emit
= {
365 .debug
= &ctx
->debug
,
366 .vtx
= &ctx
->solid_vbuf_state
,
367 .prog
= &ctx
->solid_prog
,
369 .half_precision
= true,
374 OUT_PKT0(ring
, REG_A3XX_RB_DEPTH_CONTROL
, 1);
375 OUT_RING(ring
, A3XX_RB_DEPTH_CONTROL_ZFUNC(FUNC_NEVER
));
377 OUT_PKT0(ring
, REG_A3XX_RB_STENCIL_CONTROL
, 1);
378 OUT_RING(ring
, A3XX_RB_STENCIL_CONTROL_FUNC(FUNC_NEVER
) |
379 A3XX_RB_STENCIL_CONTROL_FAIL(STENCIL_KEEP
) |
380 A3XX_RB_STENCIL_CONTROL_ZPASS(STENCIL_KEEP
) |
381 A3XX_RB_STENCIL_CONTROL_ZFAIL(STENCIL_KEEP
) |
382 A3XX_RB_STENCIL_CONTROL_FUNC_BF(FUNC_NEVER
) |
383 A3XX_RB_STENCIL_CONTROL_FAIL_BF(STENCIL_KEEP
) |
384 A3XX_RB_STENCIL_CONTROL_ZPASS_BF(STENCIL_KEEP
) |
385 A3XX_RB_STENCIL_CONTROL_ZFAIL_BF(STENCIL_KEEP
));
387 OUT_PKT0(ring
, REG_A3XX_RB_STENCILREFMASK
, 2);
388 OUT_RING(ring
, 0xff000000 |
389 A3XX_RB_STENCILREFMASK_STENCILREF(0) |
390 A3XX_RB_STENCILREFMASK_STENCILMASK(0) |
391 A3XX_RB_STENCILREFMASK_STENCILWRITEMASK(0xff));
392 OUT_RING(ring
, 0xff000000 |
393 A3XX_RB_STENCILREFMASK_STENCILREF(0) |
394 A3XX_RB_STENCILREFMASK_STENCILMASK(0) |
395 A3XX_RB_STENCILREFMASK_STENCILWRITEMASK(0xff));
397 OUT_PKT0(ring
, REG_A3XX_GRAS_SU_MODE_CONTROL
, 1);
398 OUT_RING(ring
, A3XX_GRAS_SU_MODE_CONTROL_LINEHALFWIDTH(0));
400 OUT_PKT0(ring
, REG_A3XX_GRAS_CL_CLIP_CNTL
, 1);
401 OUT_RING(ring
, 0x00000000); /* GRAS_CL_CLIP_CNTL */
404 OUT_PKT0(ring
, REG_A3XX_GRAS_CL_VPORT_XOFFSET
, 6);
405 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_XOFFSET((float)pfb
->width
/2.0 - 0.5));
406 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_XSCALE((float)pfb
->width
/2.0));
407 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_YOFFSET((float)pfb
->height
/2.0 - 0.5));
408 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_YSCALE(-(float)pfb
->height
/2.0));
409 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_ZOFFSET(0.0));
410 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_ZSCALE(1.0));
412 OUT_PKT0(ring
, REG_A3XX_RB_MODE_CONTROL
, 1);
413 OUT_RING(ring
, A3XX_RB_MODE_CONTROL_RENDER_MODE(RB_RESOLVE_PASS
) |
414 A3XX_RB_MODE_CONTROL_MARB_CACHE_SPLIT_MODE
|
415 A3XX_RB_MODE_CONTROL_MRT(0));
417 OUT_PKT0(ring
, REG_A3XX_RB_RENDER_CONTROL
, 1);
418 OUT_RING(ring
, A3XX_RB_RENDER_CONTROL_DISABLE_COLOR_PIPE
|
419 A3XX_RB_RENDER_CONTROL_ENABLE_GMEM
|
420 A3XX_RB_RENDER_CONTROL_ALPHA_TEST_FUNC(FUNC_NEVER
) |
421 A3XX_RB_RENDER_CONTROL_BIN_WIDTH(ctx
->gmem
.bin_w
));
423 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_CONTROL
, 1);
424 OUT_RING(ring
, A3XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RESOLVE_PASS
) |
425 A3XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
426 A3XX_GRAS_SC_CONTROL_RASTER_MODE(1));
428 OUT_PKT0(ring
, REG_A3XX_PC_PRIM_VTX_CNTL
, 1);
429 OUT_RING(ring
, A3XX_PC_PRIM_VTX_CNTL_STRIDE_IN_VPC(0) |
430 A3XX_PC_PRIM_VTX_CNTL_POLYMODE_FRONT_PTYPE(PC_DRAW_TRIANGLES
) |
431 A3XX_PC_PRIM_VTX_CNTL_POLYMODE_BACK_PTYPE(PC_DRAW_TRIANGLES
) |
432 A3XX_PC_PRIM_VTX_CNTL_PROVOKING_VTX_LAST
);
434 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_WINDOW_SCISSOR_TL
, 2);
435 OUT_RING(ring
, A3XX_GRAS_SC_WINDOW_SCISSOR_TL_X(0) |
436 A3XX_GRAS_SC_WINDOW_SCISSOR_TL_Y(0));
437 OUT_RING(ring
, A3XX_GRAS_SC_WINDOW_SCISSOR_BR_X(pfb
->width
- 1) |
438 A3XX_GRAS_SC_WINDOW_SCISSOR_BR_Y(pfb
->height
- 1));
440 OUT_PKT0(ring
, REG_A3XX_VFD_INDEX_MIN
, 4);
441 OUT_RING(ring
, 0); /* VFD_INDEX_MIN */
442 OUT_RING(ring
, 2); /* VFD_INDEX_MAX */
443 OUT_RING(ring
, 0); /* VFD_INSTANCEID_OFFSET */
444 OUT_RING(ring
, 0); /* VFD_INDEX_OFFSET */
446 fd3_program_emit(ring
, &emit
, 0, NULL
);
447 fd3_emit_vertex_bufs(ring
, &emit
);
449 if (batch
->resolve
& (FD_BUFFER_DEPTH
| FD_BUFFER_STENCIL
)) {
450 struct fd_resource
*rsc
= fd_resource(pfb
->zsbuf
->texture
);
451 if (!rsc
->stencil
|| batch
->resolve
& FD_BUFFER_DEPTH
)
452 emit_gmem2mem_surf(batch
, RB_COPY_DEPTH_STENCIL
, false,
453 ctx
->gmem
.zsbuf_base
[0], pfb
->zsbuf
);
454 if (rsc
->stencil
&& batch
->resolve
& FD_BUFFER_STENCIL
)
455 emit_gmem2mem_surf(batch
, RB_COPY_DEPTH_STENCIL
, true,
456 ctx
->gmem
.zsbuf_base
[1], pfb
->zsbuf
);
459 if (batch
->resolve
& FD_BUFFER_COLOR
) {
460 for (i
= 0; i
< pfb
->nr_cbufs
; i
++) {
463 if (!(batch
->resolve
& (PIPE_CLEAR_COLOR0
<< i
)))
465 emit_gmem2mem_surf(batch
, RB_COPY_RESOLVE
, false,
466 ctx
->gmem
.cbuf_base
[i
], pfb
->cbufs
[i
]);
470 OUT_PKT0(ring
, REG_A3XX_RB_MODE_CONTROL
, 1);
471 OUT_RING(ring
, A3XX_RB_MODE_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
472 A3XX_RB_MODE_CONTROL_MARB_CACHE_SPLIT_MODE
|
473 A3XX_RB_MODE_CONTROL_MRT(MAX2(1, pfb
->nr_cbufs
) - 1));
475 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_CONTROL
, 1);
476 OUT_RING(ring
, A3XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
477 A3XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
478 A3XX_GRAS_SC_CONTROL_RASTER_MODE(0));
481 /* transfer from system memory to gmem */
484 emit_mem2gmem_surf(struct fd_batch
*batch
, uint32_t bases
[],
485 struct pipe_surface
**psurf
, uint32_t bufs
, uint32_t bin_w
)
487 struct fd_ringbuffer
*ring
= batch
->gmem
;
488 struct pipe_surface
*zsbufs
[2];
492 OUT_PKT0(ring
, REG_A3XX_RB_MODE_CONTROL
, 1);
493 OUT_RING(ring
, A3XX_RB_MODE_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
494 A3XX_RB_MODE_CONTROL_MARB_CACHE_SPLIT_MODE
|
495 A3XX_RB_MODE_CONTROL_MRT(bufs
- 1));
497 emit_mrt(ring
, bufs
, psurf
, bases
, bin_w
, false);
499 if (psurf
[0] && (psurf
[0]->format
== PIPE_FORMAT_Z32_FLOAT
||
500 psurf
[0]->format
== PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
)) {
501 /* Depth is stored as unorm in gmem, so we have to write it in using a
502 * special blit shader which writes depth.
504 OUT_PKT0(ring
, REG_A3XX_RB_DEPTH_CONTROL
, 1);
505 OUT_RING(ring
, (A3XX_RB_DEPTH_CONTROL_FRAG_WRITES_Z
|
506 A3XX_RB_DEPTH_CONTROL_Z_WRITE_ENABLE
|
507 A3XX_RB_DEPTH_CONTROL_Z_ENABLE
|
508 A3XX_RB_DEPTH_CONTROL_EARLY_Z_DISABLE
|
509 A3XX_RB_DEPTH_CONTROL_ZFUNC(FUNC_ALWAYS
)));
511 OUT_PKT0(ring
, REG_A3XX_RB_DEPTH_INFO
, 2);
512 OUT_RING(ring
, A3XX_RB_DEPTH_INFO_DEPTH_BASE(bases
[0]) |
513 A3XX_RB_DEPTH_INFO_DEPTH_FORMAT(DEPTHX_32
));
514 OUT_RING(ring
, A3XX_RB_DEPTH_PITCH(4 * batch
->ctx
->gmem
.bin_w
));
516 if (psurf
[0]->format
== PIPE_FORMAT_Z32_FLOAT
) {
517 OUT_PKT0(ring
, REG_A3XX_RB_MRT_CONTROL(0), 1);
520 /* The gmem_restore_tex logic will put the first buffer's stencil
521 * as color. Supply it with the proper information to make that
524 zsbufs
[0] = zsbufs
[1] = psurf
[0];
529 OUT_PKT0(ring
, REG_A3XX_SP_FS_OUTPUT_REG
, 1);
530 OUT_RING(ring
, A3XX_SP_FS_OUTPUT_REG_MRT(bufs
- 1));
533 fd3_emit_gmem_restore_tex(ring
, psurf
, bufs
);
535 fd_draw(batch
, ring
, DI_PT_RECTLIST
, IGNORE_VISIBILITY
,
536 DI_SRC_SEL_AUTO_INDEX
, 2, 0, INDEX_SIZE_IGN
, 0, 0, NULL
);
540 fd3_emit_tile_mem2gmem(struct fd_batch
*batch
, struct fd_tile
*tile
)
542 struct fd_context
*ctx
= batch
->ctx
;
543 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
544 struct fd_ringbuffer
*ring
= batch
->gmem
;
545 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
546 struct fd3_emit emit
= {
547 .debug
= &ctx
->debug
,
548 .vtx
= &ctx
->blit_vbuf_state
,
549 .sprite_coord_enable
= 1,
550 /* NOTE: They all use the same VP, this is for vtx bufs. */
551 .prog
= &ctx
->blit_prog
[0],
553 .half_precision
= fd_half_precision(pfb
),
556 float x0
, y0
, x1
, y1
;
557 unsigned bin_w
= tile
->bin_w
;
558 unsigned bin_h
= tile
->bin_h
;
561 /* write texture coordinates to vertexbuf: */
562 x0
= ((float)tile
->xoff
) / ((float)pfb
->width
);
563 x1
= ((float)tile
->xoff
+ bin_w
) / ((float)pfb
->width
);
564 y0
= ((float)tile
->yoff
) / ((float)pfb
->height
);
565 y1
= ((float)tile
->yoff
+ bin_h
) / ((float)pfb
->height
);
567 OUT_PKT3(ring
, CP_MEM_WRITE
, 5);
568 OUT_RELOCW(ring
, fd_resource(ctx
->blit_texcoord_vbuf
)->bo
, 0, 0, 0);
569 OUT_RING(ring
, fui(x0
));
570 OUT_RING(ring
, fui(y0
));
571 OUT_RING(ring
, fui(x1
));
572 OUT_RING(ring
, fui(y1
));
574 fd3_emit_cache_flush(batch
, ring
);
576 for (i
= 0; i
< 4; i
++) {
577 OUT_PKT0(ring
, REG_A3XX_RB_MRT_CONTROL(i
), 1);
578 OUT_RING(ring
, A3XX_RB_MRT_CONTROL_ROP_CODE(ROP_COPY
) |
579 A3XX_RB_MRT_CONTROL_DITHER_MODE(DITHER_DISABLE
) |
580 A3XX_RB_MRT_CONTROL_COMPONENT_ENABLE(0xf));
582 OUT_PKT0(ring
, REG_A3XX_RB_MRT_BLEND_CONTROL(i
), 1);
583 OUT_RING(ring
, A3XX_RB_MRT_BLEND_CONTROL_RGB_SRC_FACTOR(FACTOR_ONE
) |
584 A3XX_RB_MRT_BLEND_CONTROL_RGB_BLEND_OPCODE(BLEND_DST_PLUS_SRC
) |
585 A3XX_RB_MRT_BLEND_CONTROL_RGB_DEST_FACTOR(FACTOR_ZERO
) |
586 A3XX_RB_MRT_BLEND_CONTROL_ALPHA_SRC_FACTOR(FACTOR_ONE
) |
587 A3XX_RB_MRT_BLEND_CONTROL_ALPHA_BLEND_OPCODE(BLEND_DST_PLUS_SRC
) |
588 A3XX_RB_MRT_BLEND_CONTROL_ALPHA_DEST_FACTOR(FACTOR_ZERO
));
591 OUT_PKT0(ring
, REG_A3XX_RB_RENDER_CONTROL
, 1);
592 OUT_RING(ring
, A3XX_RB_RENDER_CONTROL_ALPHA_TEST_FUNC(FUNC_ALWAYS
) |
593 A3XX_RB_RENDER_CONTROL_BIN_WIDTH(gmem
->bin_w
));
596 OUT_PKT0(ring
, REG_A3XX_RB_DEPTH_CONTROL
, 1);
597 OUT_RING(ring
, A3XX_RB_DEPTH_CONTROL_ZFUNC(FUNC_LESS
));
599 OUT_PKT0(ring
, REG_A3XX_RB_DEPTH_INFO
, 2);
603 OUT_PKT0(ring
, REG_A3XX_GRAS_CL_CLIP_CNTL
, 1);
604 OUT_RING(ring
, A3XX_GRAS_CL_CLIP_CNTL_IJ_PERSP_CENTER
); /* GRAS_CL_CLIP_CNTL */
607 OUT_PKT0(ring
, REG_A3XX_GRAS_CL_VPORT_XOFFSET
, 6);
608 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_XOFFSET((float)bin_w
/2.0 - 0.5));
609 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_XSCALE((float)bin_w
/2.0));
610 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_YOFFSET((float)bin_h
/2.0 - 0.5));
611 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_YSCALE(-(float)bin_h
/2.0));
612 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_ZOFFSET(0.0));
613 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_ZSCALE(1.0));
615 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_WINDOW_SCISSOR_TL
, 2);
616 OUT_RING(ring
, A3XX_GRAS_SC_WINDOW_SCISSOR_TL_X(0) |
617 A3XX_GRAS_SC_WINDOW_SCISSOR_TL_Y(0));
618 OUT_RING(ring
, A3XX_GRAS_SC_WINDOW_SCISSOR_BR_X(bin_w
- 1) |
619 A3XX_GRAS_SC_WINDOW_SCISSOR_BR_Y(bin_h
- 1));
621 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_SCREEN_SCISSOR_TL
, 2);
622 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_TL_X(0) |
623 A3XX_GRAS_SC_SCREEN_SCISSOR_TL_Y(0));
624 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_BR_X(bin_w
- 1) |
625 A3XX_GRAS_SC_SCREEN_SCISSOR_BR_Y(bin_h
- 1));
627 OUT_PKT0(ring
, REG_A3XX_RB_STENCIL_CONTROL
, 1);
629 A3XX_RB_STENCIL_CONTROL_FUNC(FUNC_ALWAYS
) |
630 A3XX_RB_STENCIL_CONTROL_FAIL(STENCIL_KEEP
) |
631 A3XX_RB_STENCIL_CONTROL_ZPASS(STENCIL_KEEP
) |
632 A3XX_RB_STENCIL_CONTROL_ZFAIL(STENCIL_KEEP
) |
633 A3XX_RB_STENCIL_CONTROL_FUNC_BF(FUNC_ALWAYS
) |
634 A3XX_RB_STENCIL_CONTROL_FAIL_BF(STENCIL_KEEP
) |
635 A3XX_RB_STENCIL_CONTROL_ZPASS_BF(STENCIL_KEEP
) |
636 A3XX_RB_STENCIL_CONTROL_ZFAIL_BF(STENCIL_KEEP
));
638 OUT_PKT0(ring
, REG_A3XX_RB_STENCIL_INFO
, 2);
639 OUT_RING(ring
, 0); /* RB_STENCIL_INFO */
640 OUT_RING(ring
, 0); /* RB_STENCIL_PITCH */
642 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_CONTROL
, 1);
643 OUT_RING(ring
, A3XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
644 A3XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
645 A3XX_GRAS_SC_CONTROL_RASTER_MODE(1));
647 OUT_PKT0(ring
, REG_A3XX_PC_PRIM_VTX_CNTL
, 1);
648 OUT_RING(ring
, A3XX_PC_PRIM_VTX_CNTL_STRIDE_IN_VPC(2) |
649 A3XX_PC_PRIM_VTX_CNTL_POLYMODE_FRONT_PTYPE(PC_DRAW_TRIANGLES
) |
650 A3XX_PC_PRIM_VTX_CNTL_POLYMODE_BACK_PTYPE(PC_DRAW_TRIANGLES
) |
651 A3XX_PC_PRIM_VTX_CNTL_PROVOKING_VTX_LAST
);
653 OUT_PKT0(ring
, REG_A3XX_VFD_INDEX_MIN
, 4);
654 OUT_RING(ring
, 0); /* VFD_INDEX_MIN */
655 OUT_RING(ring
, 2); /* VFD_INDEX_MAX */
656 OUT_RING(ring
, 0); /* VFD_INSTANCEID_OFFSET */
657 OUT_RING(ring
, 0); /* VFD_INDEX_OFFSET */
659 fd3_emit_vertex_bufs(ring
, &emit
);
661 /* for gmem pitch/base calculations, we need to use the non-
662 * truncated tile sizes:
667 if (fd_gmem_needs_restore(batch
, tile
, FD_BUFFER_COLOR
)) {
668 emit
.prog
= &ctx
->blit_prog
[pfb
->nr_cbufs
- 1];
669 emit
.fp
= NULL
; /* frag shader changed so clear cache */
670 fd3_program_emit(ring
, &emit
, pfb
->nr_cbufs
, pfb
->cbufs
);
671 emit_mem2gmem_surf(batch
, gmem
->cbuf_base
, pfb
->cbufs
, pfb
->nr_cbufs
, bin_w
);
674 if (fd_gmem_needs_restore(batch
, tile
, FD_BUFFER_DEPTH
| FD_BUFFER_STENCIL
)) {
675 if (pfb
->zsbuf
->format
!= PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
&&
676 pfb
->zsbuf
->format
!= PIPE_FORMAT_Z32_FLOAT
) {
677 /* Non-float can use a regular color write. It's split over 8-bit
678 * components, so half precision is always sufficient.
680 emit
.prog
= &ctx
->blit_prog
[0];
681 emit
.key
.half_precision
= true;
683 /* Float depth needs special blit shader that writes depth */
684 if (pfb
->zsbuf
->format
== PIPE_FORMAT_Z32_FLOAT
)
685 emit
.prog
= &ctx
->blit_z
;
687 emit
.prog
= &ctx
->blit_zs
;
688 emit
.key
.half_precision
= false;
690 emit
.fp
= NULL
; /* frag shader changed so clear cache */
691 fd3_program_emit(ring
, &emit
, 1, &pfb
->zsbuf
);
692 emit_mem2gmem_surf(batch
, gmem
->zsbuf_base
, &pfb
->zsbuf
, 1, bin_w
);
695 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_CONTROL
, 1);
696 OUT_RING(ring
, A3XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
697 A3XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
698 A3XX_GRAS_SC_CONTROL_RASTER_MODE(0));
700 OUT_PKT0(ring
, REG_A3XX_RB_MODE_CONTROL
, 1);
701 OUT_RING(ring
, A3XX_RB_MODE_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
702 A3XX_RB_MODE_CONTROL_MARB_CACHE_SPLIT_MODE
|
703 A3XX_RB_MODE_CONTROL_MRT(MAX2(1, pfb
->nr_cbufs
) - 1));
707 patch_draws(struct fd_batch
*batch
, enum pc_di_vis_cull_mode vismode
)
710 for (i
= 0; i
< fd_patch_num_elements(&batch
->draw_patches
); i
++) {
711 struct fd_cs_patch
*patch
= fd_patch_element(&batch
->draw_patches
, i
);
712 *patch
->cs
= patch
->val
| DRAW(0, 0, 0, vismode
, 0);
714 util_dynarray_resize(&batch
->draw_patches
, 0);
718 patch_rbrc(struct fd_batch
*batch
, uint32_t val
)
721 for (i
= 0; i
< fd_patch_num_elements(&batch
->rbrc_patches
); i
++) {
722 struct fd_cs_patch
*patch
= fd_patch_element(&batch
->rbrc_patches
, i
);
723 *patch
->cs
= patch
->val
| val
;
725 util_dynarray_resize(&batch
->rbrc_patches
, 0);
728 /* for rendering directly to system memory: */
730 fd3_emit_sysmem_prep(struct fd_batch
*batch
)
732 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
733 struct fd_ringbuffer
*ring
= batch
->gmem
;
734 uint32_t i
, pitch
= 0;
736 for (i
= 0; i
< pfb
->nr_cbufs
; i
++) {
737 struct pipe_surface
*psurf
= pfb
->cbufs
[i
];
740 pitch
= fd_resource(psurf
->texture
)->slices
[psurf
->u
.tex
.level
].pitch
;
743 fd3_emit_restore(batch
, ring
);
745 OUT_PKT0(ring
, REG_A3XX_RB_FRAME_BUFFER_DIMENSION
, 1);
746 OUT_RING(ring
, A3XX_RB_FRAME_BUFFER_DIMENSION_WIDTH(pfb
->width
) |
747 A3XX_RB_FRAME_BUFFER_DIMENSION_HEIGHT(pfb
->height
));
749 emit_mrt(ring
, pfb
->nr_cbufs
, pfb
->cbufs
, NULL
, 0, true);
751 /* setup scissor/offset for current tile: */
752 OUT_PKT0(ring
, REG_A3XX_RB_WINDOW_OFFSET
, 1);
753 OUT_RING(ring
, A3XX_RB_WINDOW_OFFSET_X(0) |
754 A3XX_RB_WINDOW_OFFSET_Y(0));
756 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_SCREEN_SCISSOR_TL
, 2);
757 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_TL_X(0) |
758 A3XX_GRAS_SC_SCREEN_SCISSOR_TL_Y(0));
759 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_BR_X(pfb
->width
- 1) |
760 A3XX_GRAS_SC_SCREEN_SCISSOR_BR_Y(pfb
->height
- 1));
762 OUT_PKT0(ring
, REG_A3XX_RB_MODE_CONTROL
, 1);
763 OUT_RING(ring
, A3XX_RB_MODE_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
764 A3XX_RB_MODE_CONTROL_GMEM_BYPASS
|
765 A3XX_RB_MODE_CONTROL_MARB_CACHE_SPLIT_MODE
|
766 A3XX_RB_MODE_CONTROL_MRT(MAX2(1, pfb
->nr_cbufs
) - 1));
768 patch_draws(batch
, IGNORE_VISIBILITY
);
769 patch_rbrc(batch
, A3XX_RB_RENDER_CONTROL_BIN_WIDTH(pitch
));
773 update_vsc_pipe(struct fd_batch
*batch
)
775 struct fd_context
*ctx
= batch
->ctx
;
776 struct fd3_context
*fd3_ctx
= fd3_context(ctx
);
777 struct fd_ringbuffer
*ring
= batch
->gmem
;
780 OUT_PKT0(ring
, REG_A3XX_VSC_SIZE_ADDRESS
, 1);
781 OUT_RELOCW(ring
, fd3_ctx
->vsc_size_mem
, 0, 0, 0); /* VSC_SIZE_ADDRESS */
783 for (i
= 0; i
< 8; i
++) {
784 struct fd_vsc_pipe
*pipe
= &ctx
->vsc_pipe
[i
];
787 pipe
->bo
= fd_bo_new(ctx
->dev
, 0x40000,
788 DRM_FREEDRENO_GEM_TYPE_KMEM
);
791 OUT_PKT0(ring
, REG_A3XX_VSC_PIPE(i
), 3);
792 OUT_RING(ring
, A3XX_VSC_PIPE_CONFIG_X(pipe
->x
) |
793 A3XX_VSC_PIPE_CONFIG_Y(pipe
->y
) |
794 A3XX_VSC_PIPE_CONFIG_W(pipe
->w
) |
795 A3XX_VSC_PIPE_CONFIG_H(pipe
->h
));
796 OUT_RELOCW(ring
, pipe
->bo
, 0, 0, 0); /* VSC_PIPE[i].DATA_ADDRESS */
797 OUT_RING(ring
, fd_bo_size(pipe
->bo
) - 32); /* VSC_PIPE[i].DATA_LENGTH */
802 emit_binning_pass(struct fd_batch
*batch
)
804 struct fd_context
*ctx
= batch
->ctx
;
805 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
806 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
807 struct fd_ringbuffer
*ring
= batch
->gmem
;
810 uint32_t x1
= gmem
->minx
;
811 uint32_t y1
= gmem
->miny
;
812 uint32_t x2
= gmem
->minx
+ gmem
->width
- 1;
813 uint32_t y2
= gmem
->miny
+ gmem
->height
- 1;
815 if (ctx
->screen
->gpu_id
== 320) {
816 emit_binning_workaround(batch
);
818 OUT_PKT3(ring
, CP_INVALIDATE_STATE
, 1);
819 OUT_RING(ring
, 0x00007fff);
822 OUT_PKT0(ring
, REG_A3XX_VSC_BIN_CONTROL
, 1);
823 OUT_RING(ring
, A3XX_VSC_BIN_CONTROL_BINNING_ENABLE
);
825 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_CONTROL
, 1);
826 OUT_RING(ring
, A3XX_GRAS_SC_CONTROL_RENDER_MODE(RB_TILING_PASS
) |
827 A3XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
828 A3XX_GRAS_SC_CONTROL_RASTER_MODE(0));
830 OUT_PKT0(ring
, REG_A3XX_RB_FRAME_BUFFER_DIMENSION
, 1);
831 OUT_RING(ring
, A3XX_RB_FRAME_BUFFER_DIMENSION_WIDTH(pfb
->width
) |
832 A3XX_RB_FRAME_BUFFER_DIMENSION_HEIGHT(pfb
->height
));
834 OUT_PKT0(ring
, REG_A3XX_RB_RENDER_CONTROL
, 1);
835 OUT_RING(ring
, A3XX_RB_RENDER_CONTROL_ALPHA_TEST_FUNC(FUNC_NEVER
) |
836 A3XX_RB_RENDER_CONTROL_DISABLE_COLOR_PIPE
|
837 A3XX_RB_RENDER_CONTROL_BIN_WIDTH(gmem
->bin_w
));
839 /* setup scissor/offset for whole screen: */
840 OUT_PKT0(ring
, REG_A3XX_RB_WINDOW_OFFSET
, 1);
841 OUT_RING(ring
, A3XX_RB_WINDOW_OFFSET_X(x1
) |
842 A3XX_RB_WINDOW_OFFSET_Y(y1
));
844 OUT_PKT0(ring
, REG_A3XX_RB_LRZ_VSC_CONTROL
, 1);
845 OUT_RING(ring
, A3XX_RB_LRZ_VSC_CONTROL_BINNING_ENABLE
);
847 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_SCREEN_SCISSOR_TL
, 2);
848 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_TL_X(x1
) |
849 A3XX_GRAS_SC_SCREEN_SCISSOR_TL_Y(y1
));
850 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_BR_X(x2
) |
851 A3XX_GRAS_SC_SCREEN_SCISSOR_BR_Y(y2
));
853 OUT_PKT0(ring
, REG_A3XX_RB_MODE_CONTROL
, 1);
854 OUT_RING(ring
, A3XX_RB_MODE_CONTROL_RENDER_MODE(RB_TILING_PASS
) |
855 A3XX_RB_MODE_CONTROL_MARB_CACHE_SPLIT_MODE
|
856 A3XX_RB_MODE_CONTROL_MRT(0));
858 for (i
= 0; i
< 4; i
++) {
859 OUT_PKT0(ring
, REG_A3XX_RB_MRT_CONTROL(i
), 1);
860 OUT_RING(ring
, A3XX_RB_MRT_CONTROL_ROP_CODE(ROP_CLEAR
) |
861 A3XX_RB_MRT_CONTROL_DITHER_MODE(DITHER_DISABLE
) |
862 A3XX_RB_MRT_CONTROL_COMPONENT_ENABLE(0));
865 OUT_PKT0(ring
, REG_A3XX_PC_VSTREAM_CONTROL
, 1);
866 OUT_RING(ring
, A3XX_PC_VSTREAM_CONTROL_SIZE(1) |
867 A3XX_PC_VSTREAM_CONTROL_N(0));
869 /* emit IB to binning drawcmds: */
870 ctx
->emit_ib(ring
, batch
->binning
);
875 /* and then put stuff back the way it was: */
877 OUT_PKT0(ring
, REG_A3XX_VSC_BIN_CONTROL
, 1);
878 OUT_RING(ring
, 0x00000000);
880 OUT_PKT0(ring
, REG_A3XX_SP_SP_CTRL_REG
, 1);
881 OUT_RING(ring
, A3XX_SP_SP_CTRL_REG_RESOLVE
|
882 A3XX_SP_SP_CTRL_REG_CONSTMODE(1) |
883 A3XX_SP_SP_CTRL_REG_SLEEPMODE(1) |
884 A3XX_SP_SP_CTRL_REG_L0MODE(0));
886 OUT_PKT0(ring
, REG_A3XX_RB_LRZ_VSC_CONTROL
, 1);
887 OUT_RING(ring
, 0x00000000);
889 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_CONTROL
, 1);
890 OUT_RING(ring
, A3XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
891 A3XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
892 A3XX_GRAS_SC_CONTROL_RASTER_MODE(0));
894 OUT_PKT0(ring
, REG_A3XX_RB_MODE_CONTROL
, 2);
895 OUT_RING(ring
, A3XX_RB_MODE_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
896 A3XX_RB_MODE_CONTROL_MARB_CACHE_SPLIT_MODE
|
897 A3XX_RB_MODE_CONTROL_MRT(pfb
->nr_cbufs
- 1));
898 OUT_RING(ring
, A3XX_RB_RENDER_CONTROL_ENABLE_GMEM
|
899 A3XX_RB_RENDER_CONTROL_ALPHA_TEST_FUNC(FUNC_NEVER
) |
900 A3XX_RB_RENDER_CONTROL_BIN_WIDTH(gmem
->bin_w
));
902 fd_event_write(batch
, ring
, CACHE_FLUSH
);
905 if (ctx
->screen
->gpu_id
== 320) {
906 /* dummy-draw workaround: */
907 OUT_PKT3(ring
, CP_DRAW_INDX
, 3);
908 OUT_RING(ring
, 0x00000000);
909 OUT_RING(ring
, DRAW(1, DI_SRC_SEL_AUTO_INDEX
,
910 INDEX_SIZE_IGN
, IGNORE_VISIBILITY
, 0));
911 OUT_RING(ring
, 0); /* NumIndices */
915 OUT_PKT3(ring
, CP_NOP
, 4);
916 OUT_RING(ring
, 0x00000000);
917 OUT_RING(ring
, 0x00000000);
918 OUT_RING(ring
, 0x00000000);
919 OUT_RING(ring
, 0x00000000);
923 if (ctx
->screen
->gpu_id
== 320) {
924 emit_binning_workaround(batch
);
928 /* before first tile */
930 fd3_emit_tile_init(struct fd_batch
*batch
)
932 struct fd_ringbuffer
*ring
= batch
->gmem
;
933 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
934 struct fd_gmem_stateobj
*gmem
= &batch
->ctx
->gmem
;
935 uint32_t rb_render_control
;
937 fd3_emit_restore(batch
, ring
);
939 /* note: use gmem->bin_w/h, the bin_w/h parameters may be truncated
940 * at the right and bottom edge tiles
942 OUT_PKT0(ring
, REG_A3XX_VSC_BIN_SIZE
, 1);
943 OUT_RING(ring
, A3XX_VSC_BIN_SIZE_WIDTH(gmem
->bin_w
) |
944 A3XX_VSC_BIN_SIZE_HEIGHT(gmem
->bin_h
));
946 update_vsc_pipe(batch
);
949 OUT_PKT0(ring
, REG_A3XX_RB_FRAME_BUFFER_DIMENSION
, 1);
950 OUT_RING(ring
, A3XX_RB_FRAME_BUFFER_DIMENSION_WIDTH(pfb
->width
) |
951 A3XX_RB_FRAME_BUFFER_DIMENSION_HEIGHT(pfb
->height
));
953 if (use_hw_binning(batch
)) {
954 /* emit hw binning pass: */
955 emit_binning_pass(batch
);
957 patch_draws(batch
, USE_VISIBILITY
);
959 patch_draws(batch
, IGNORE_VISIBILITY
);
962 rb_render_control
= A3XX_RB_RENDER_CONTROL_ENABLE_GMEM
|
963 A3XX_RB_RENDER_CONTROL_BIN_WIDTH(gmem
->bin_w
);
965 patch_rbrc(batch
, rb_render_control
);
968 /* before mem2gmem */
970 fd3_emit_tile_prep(struct fd_batch
*batch
, struct fd_tile
*tile
)
972 struct fd_ringbuffer
*ring
= batch
->gmem
;
973 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
975 OUT_PKT0(ring
, REG_A3XX_RB_MODE_CONTROL
, 1);
976 OUT_RING(ring
, A3XX_RB_MODE_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
977 A3XX_RB_MODE_CONTROL_MARB_CACHE_SPLIT_MODE
|
978 A3XX_RB_MODE_CONTROL_MRT(MAX2(1, pfb
->nr_cbufs
) - 1));
981 /* before IB to rendering cmds: */
983 fd3_emit_tile_renderprep(struct fd_batch
*batch
, struct fd_tile
*tile
)
985 struct fd_context
*ctx
= batch
->ctx
;
986 struct fd3_context
*fd3_ctx
= fd3_context(ctx
);
987 struct fd_ringbuffer
*ring
= batch
->gmem
;
988 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
989 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
991 uint32_t x1
= tile
->xoff
;
992 uint32_t y1
= tile
->yoff
;
993 uint32_t x2
= tile
->xoff
+ tile
->bin_w
- 1;
994 uint32_t y2
= tile
->yoff
+ tile
->bin_h
- 1;
998 OUT_PKT0(ring
, REG_A3XX_RB_DEPTH_INFO
, 2);
999 reg
= A3XX_RB_DEPTH_INFO_DEPTH_BASE(gmem
->zsbuf_base
[0]);
1001 reg
|= A3XX_RB_DEPTH_INFO_DEPTH_FORMAT(fd_pipe2depth(pfb
->zsbuf
->format
));
1003 OUT_RING(ring
, reg
);
1005 struct fd_resource
*rsc
= fd_resource(pfb
->zsbuf
->texture
);
1006 OUT_RING(ring
, A3XX_RB_DEPTH_PITCH(rsc
->cpp
* gmem
->bin_w
));
1008 OUT_PKT0(ring
, REG_A3XX_RB_STENCIL_INFO
, 2);
1009 OUT_RING(ring
, A3XX_RB_STENCIL_INFO_STENCIL_BASE(gmem
->zsbuf_base
[1]));
1010 OUT_RING(ring
, A3XX_RB_STENCIL_PITCH(rsc
->stencil
->cpp
* gmem
->bin_w
));
1013 OUT_RING(ring
, 0x00000000);
1016 if (use_hw_binning(batch
)) {
1017 struct fd_vsc_pipe
*pipe
= &ctx
->vsc_pipe
[tile
->p
];
1019 assert(pipe
->w
* pipe
->h
);
1021 fd_event_write(batch
, ring
, HLSQ_FLUSH
);
1022 fd_wfi(batch
, ring
);
1024 OUT_PKT0(ring
, REG_A3XX_PC_VSTREAM_CONTROL
, 1);
1025 OUT_RING(ring
, A3XX_PC_VSTREAM_CONTROL_SIZE(pipe
->w
* pipe
->h
) |
1026 A3XX_PC_VSTREAM_CONTROL_N(tile
->n
));
1029 OUT_PKT3(ring
, CP_SET_BIN_DATA
, 2);
1030 OUT_RELOCW(ring
, pipe
->bo
, 0, 0, 0); /* BIN_DATA_ADDR <- VSC_PIPE[p].DATA_ADDRESS */
1031 OUT_RELOCW(ring
, fd3_ctx
->vsc_size_mem
, /* BIN_SIZE_ADDR <- VSC_SIZE_ADDRESS + (p * 4) */
1032 (tile
->p
* 4), 0, 0);
1034 OUT_PKT0(ring
, REG_A3XX_PC_VSTREAM_CONTROL
, 1);
1035 OUT_RING(ring
, 0x00000000);
1038 OUT_PKT3(ring
, CP_SET_BIN
, 3);
1039 OUT_RING(ring
, 0x00000000);
1040 OUT_RING(ring
, CP_SET_BIN_1_X1(x1
) | CP_SET_BIN_1_Y1(y1
));
1041 OUT_RING(ring
, CP_SET_BIN_2_X2(x2
) | CP_SET_BIN_2_Y2(y2
));
1043 emit_mrt(ring
, pfb
->nr_cbufs
, pfb
->cbufs
, gmem
->cbuf_base
, gmem
->bin_w
, true);
1045 /* setup scissor/offset for current tile: */
1046 OUT_PKT0(ring
, REG_A3XX_RB_WINDOW_OFFSET
, 1);
1047 OUT_RING(ring
, A3XX_RB_WINDOW_OFFSET_X(tile
->xoff
) |
1048 A3XX_RB_WINDOW_OFFSET_Y(tile
->yoff
));
1050 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_SCREEN_SCISSOR_TL
, 2);
1051 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_TL_X(x1
) |
1052 A3XX_GRAS_SC_SCREEN_SCISSOR_TL_Y(y1
));
1053 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_BR_X(x2
) |
1054 A3XX_GRAS_SC_SCREEN_SCISSOR_BR_Y(y2
));
1058 fd3_gmem_init(struct pipe_context
*pctx
)
1060 struct fd_context
*ctx
= fd_context(pctx
);
1062 ctx
->emit_sysmem_prep
= fd3_emit_sysmem_prep
;
1063 ctx
->emit_tile_init
= fd3_emit_tile_init
;
1064 ctx
->emit_tile_prep
= fd3_emit_tile_prep
;
1065 ctx
->emit_tile_mem2gmem
= fd3_emit_tile_mem2gmem
;
1066 ctx
->emit_tile_renderprep
= fd3_emit_tile_renderprep
;
1067 ctx
->emit_tile_gmem2mem
= fd3_emit_tile_gmem2mem
;