1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
4 * Copyright (C) 2013 Rob Clark <robclark@freedesktop.org>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * Rob Clark <robclark@freedesktop.org>
29 #include "pipe/p_state.h"
30 #include "util/u_string.h"
31 #include "util/u_memory.h"
32 #include "util/u_inlines.h"
33 #include "util/u_format.h"
35 #include "freedreno_draw.h"
36 #include "freedreno_state.h"
37 #include "freedreno_resource.h"
40 #include "fd3_context.h"
42 #include "fd3_program.h"
43 #include "fd3_format.h"
47 emit_mrt(struct fd_ringbuffer
*ring
, unsigned nr_bufs
,
48 struct pipe_surface
**bufs
, uint32_t *bases
, uint32_t bin_w
,
51 enum a3xx_tile_mode tile_mode
;
55 tile_mode
= TILE_32X32
;
60 for (i
= 0; i
< A3XX_MAX_RENDER_TARGETS
; i
++) {
61 enum pipe_format pformat
= 0;
62 enum a3xx_color_fmt format
= 0;
63 enum a3xx_color_swap swap
= WZYX
;
65 struct fd_resource
*rsc
= NULL
;
66 struct fd_resource_slice
*slice
= NULL
;
71 if ((i
< nr_bufs
) && bufs
[i
]) {
72 struct pipe_surface
*psurf
= bufs
[i
];
74 rsc
= fd_resource(psurf
->texture
);
75 pformat
= psurf
->format
;
76 /* In case we're drawing to Z32F_S8, the "color" actually goes to
81 pformat
= rsc
->base
.b
.format
;
84 slice
= fd_resource_slice(rsc
, psurf
->u
.tex
.level
);
85 format
= fd3_pipe2color(pformat
);
86 swap
= fd3_pipe2swap(pformat
);
88 srgb
= util_format_is_srgb(pformat
);
90 pformat
= util_format_linear(pformat
);
92 debug_assert(psurf
->u
.tex
.first_layer
== psurf
->u
.tex
.last_layer
);
94 offset
= fd_resource_offset(rsc
, psurf
->u
.tex
.level
,
95 psurf
->u
.tex
.first_layer
);
98 stride
= bin_w
* rsc
->cpp
;
104 stride
= slice
->pitch
* rsc
->cpp
;
106 } else if (i
< nr_bufs
&& bases
) {
110 OUT_PKT0(ring
, REG_A3XX_RB_MRT_BUF_INFO(i
), 2);
111 OUT_RING(ring
, A3XX_RB_MRT_BUF_INFO_COLOR_FORMAT(format
) |
112 A3XX_RB_MRT_BUF_INFO_COLOR_TILE_MODE(tile_mode
) |
113 A3XX_RB_MRT_BUF_INFO_COLOR_BUF_PITCH(stride
) |
114 A3XX_RB_MRT_BUF_INFO_COLOR_SWAP(swap
) |
115 COND(srgb
, A3XX_RB_MRT_BUF_INFO_COLOR_SRGB
));
116 if (bin_w
|| (i
>= nr_bufs
) || !bufs
[i
]) {
117 OUT_RING(ring
, A3XX_RB_MRT_BUF_BASE_COLOR_BUF_BASE(base
));
119 OUT_RELOCW(ring
, rsc
->bo
, offset
, 0, -1);
122 OUT_PKT0(ring
, REG_A3XX_SP_FS_IMAGE_OUTPUT_REG(i
), 1);
123 OUT_RING(ring
, COND((i
< nr_bufs
) && bufs
[i
],
124 A3XX_SP_FS_IMAGE_OUTPUT_REG_MRTFORMAT(
125 fd3_fs_output_format(pformat
))));
130 use_hw_binning(struct fd_context
*ctx
)
132 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
134 /* workaround: combining scissor optimization and hw binning
135 * seems problematic. Seems like we end up with a mismatch
136 * between binning pass and rendering pass, wrt. where the hw
137 * thinks the vertices belong. And the blob driver doesn't
138 * seem to implement anything like scissor optimization, so
139 * not entirely sure what I might be missing.
141 * But scissor optimization is mainly for window managers,
142 * which don't have many vertices (and therefore doesn't
143 * benefit much from binning pass).
145 * So for now just disable binning if scissor optimization is
148 if (gmem
->minx
|| gmem
->miny
)
151 return fd_binning_enabled
&& ((gmem
->nbins_x
* gmem
->nbins_y
) > 2);
154 /* workaround for (hlsq?) lockup with hw binning on a3xx patchlevel 0 */
155 static void update_vsc_pipe(struct fd_context
*ctx
);
157 emit_binning_workaround(struct fd_context
*ctx
)
159 struct fd3_context
*fd3_ctx
= fd3_context(ctx
);
160 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
161 struct fd_ringbuffer
*ring
= ctx
->ring
;
162 struct fd3_emit emit
= {
163 .vtx
= &fd3_ctx
->solid_vbuf_state
,
164 .prog
= &ctx
->solid_prog
,
166 .half_precision
= true,
170 OUT_PKT0(ring
, REG_A3XX_RB_MODE_CONTROL
, 2);
171 OUT_RING(ring
, A3XX_RB_MODE_CONTROL_RENDER_MODE(RB_RESOLVE_PASS
) |
172 A3XX_RB_MODE_CONTROL_MARB_CACHE_SPLIT_MODE
|
173 A3XX_RB_MODE_CONTROL_MRT(0));
174 OUT_RING(ring
, A3XX_RB_RENDER_CONTROL_BIN_WIDTH(32) |
175 A3XX_RB_RENDER_CONTROL_DISABLE_COLOR_PIPE
|
176 A3XX_RB_RENDER_CONTROL_ALPHA_TEST_FUNC(FUNC_NEVER
));
178 OUT_PKT0(ring
, REG_A3XX_RB_COPY_CONTROL
, 4);
179 OUT_RING(ring
, A3XX_RB_COPY_CONTROL_MSAA_RESOLVE(MSAA_ONE
) |
180 A3XX_RB_COPY_CONTROL_MODE(0) |
181 A3XX_RB_COPY_CONTROL_GMEM_BASE(0));
182 OUT_RELOCW(ring
, fd_resource(fd3_ctx
->solid_vbuf
)->bo
, 0x20, 0, -1); /* RB_COPY_DEST_BASE */
183 OUT_RING(ring
, A3XX_RB_COPY_DEST_PITCH_PITCH(128));
184 OUT_RING(ring
, A3XX_RB_COPY_DEST_INFO_TILE(LINEAR
) |
185 A3XX_RB_COPY_DEST_INFO_FORMAT(RB_R8G8B8A8_UNORM
) |
186 A3XX_RB_COPY_DEST_INFO_SWAP(WZYX
) |
187 A3XX_RB_COPY_DEST_INFO_COMPONENT_ENABLE(0xf) |
188 A3XX_RB_COPY_DEST_INFO_ENDIAN(ENDIAN_NONE
));
190 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_CONTROL
, 1);
191 OUT_RING(ring
, A3XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RESOLVE_PASS
) |
192 A3XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
193 A3XX_GRAS_SC_CONTROL_RASTER_MODE(1));
195 fd3_program_emit(ring
, &emit
, 0, NULL
);
196 fd3_emit_vertex_bufs(ring
, &emit
);
198 OUT_PKT0(ring
, REG_A3XX_HLSQ_CONTROL_0_REG
, 4);
199 OUT_RING(ring
, A3XX_HLSQ_CONTROL_0_REG_FSTHREADSIZE(FOUR_QUADS
) |
200 A3XX_HLSQ_CONTROL_0_REG_FSSUPERTHREADENABLE
|
201 A3XX_HLSQ_CONTROL_0_REG_RESERVED2
|
202 A3XX_HLSQ_CONTROL_0_REG_SPCONSTFULLUPDATE
);
203 OUT_RING(ring
, A3XX_HLSQ_CONTROL_1_REG_VSTHREADSIZE(TWO_QUADS
) |
204 A3XX_HLSQ_CONTROL_1_REG_VSSUPERTHREADENABLE
);
205 OUT_RING(ring
, A3XX_HLSQ_CONTROL_2_REG_PRIMALLOCTHRESHOLD(31));
206 OUT_RING(ring
, 0); /* HLSQ_CONTROL_3_REG */
208 OUT_PKT0(ring
, REG_A3XX_HLSQ_CONST_FSPRESV_RANGE_REG
, 1);
209 OUT_RING(ring
, A3XX_HLSQ_CONST_FSPRESV_RANGE_REG_STARTENTRY(0x20) |
210 A3XX_HLSQ_CONST_FSPRESV_RANGE_REG_ENDENTRY(0x20));
212 OUT_PKT0(ring
, REG_A3XX_RB_MSAA_CONTROL
, 1);
213 OUT_RING(ring
, A3XX_RB_MSAA_CONTROL_DISABLE
|
214 A3XX_RB_MSAA_CONTROL_SAMPLES(MSAA_ONE
) |
215 A3XX_RB_MSAA_CONTROL_SAMPLE_MASK(0xffff));
217 OUT_PKT0(ring
, REG_A3XX_RB_DEPTH_CONTROL
, 1);
218 OUT_RING(ring
, A3XX_RB_DEPTH_CONTROL_ZFUNC(FUNC_NEVER
));
220 OUT_PKT0(ring
, REG_A3XX_RB_STENCIL_CONTROL
, 1);
221 OUT_RING(ring
, A3XX_RB_STENCIL_CONTROL_FUNC(FUNC_NEVER
) |
222 A3XX_RB_STENCIL_CONTROL_FAIL(STENCIL_KEEP
) |
223 A3XX_RB_STENCIL_CONTROL_ZPASS(STENCIL_KEEP
) |
224 A3XX_RB_STENCIL_CONTROL_ZFAIL(STENCIL_KEEP
) |
225 A3XX_RB_STENCIL_CONTROL_FUNC_BF(FUNC_NEVER
) |
226 A3XX_RB_STENCIL_CONTROL_FAIL_BF(STENCIL_KEEP
) |
227 A3XX_RB_STENCIL_CONTROL_ZPASS_BF(STENCIL_KEEP
) |
228 A3XX_RB_STENCIL_CONTROL_ZFAIL_BF(STENCIL_KEEP
));
230 OUT_PKT0(ring
, REG_A3XX_GRAS_SU_MODE_CONTROL
, 1);
231 OUT_RING(ring
, A3XX_GRAS_SU_MODE_CONTROL_LINEHALFWIDTH(0.0));
233 OUT_PKT0(ring
, REG_A3XX_VFD_INDEX_MIN
, 4);
234 OUT_RING(ring
, 0); /* VFD_INDEX_MIN */
235 OUT_RING(ring
, 2); /* VFD_INDEX_MAX */
236 OUT_RING(ring
, 0); /* VFD_INSTANCEID_OFFSET */
237 OUT_RING(ring
, 0); /* VFD_INDEX_OFFSET */
239 OUT_PKT0(ring
, REG_A3XX_PC_PRIM_VTX_CNTL
, 1);
240 OUT_RING(ring
, A3XX_PC_PRIM_VTX_CNTL_STRIDE_IN_VPC(0) |
241 A3XX_PC_PRIM_VTX_CNTL_POLYMODE_FRONT_PTYPE(PC_DRAW_TRIANGLES
) |
242 A3XX_PC_PRIM_VTX_CNTL_POLYMODE_BACK_PTYPE(PC_DRAW_TRIANGLES
) |
243 A3XX_PC_PRIM_VTX_CNTL_PROVOKING_VTX_LAST
);
245 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_WINDOW_SCISSOR_TL
, 2);
246 OUT_RING(ring
, A3XX_GRAS_SC_WINDOW_SCISSOR_TL_X(0) |
247 A3XX_GRAS_SC_WINDOW_SCISSOR_TL_Y(1));
248 OUT_RING(ring
, A3XX_GRAS_SC_WINDOW_SCISSOR_BR_X(0) |
249 A3XX_GRAS_SC_WINDOW_SCISSOR_BR_Y(1));
251 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_SCREEN_SCISSOR_TL
, 2);
252 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_TL_X(0) |
253 A3XX_GRAS_SC_SCREEN_SCISSOR_TL_Y(0));
254 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_BR_X(31) |
255 A3XX_GRAS_SC_SCREEN_SCISSOR_BR_Y(0));
258 OUT_PKT0(ring
, REG_A3XX_GRAS_CL_VPORT_XOFFSET
, 6);
259 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_XOFFSET(0.0));
260 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_XSCALE(1.0));
261 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_YOFFSET(0.0));
262 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_YSCALE(1.0));
263 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_ZOFFSET(0.0));
264 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_ZSCALE(1.0));
266 OUT_PKT0(ring
, REG_A3XX_GRAS_CL_CLIP_CNTL
, 1);
267 OUT_RING(ring
, A3XX_GRAS_CL_CLIP_CNTL_CLIP_DISABLE
|
268 A3XX_GRAS_CL_CLIP_CNTL_ZFAR_CLIP_DISABLE
|
269 A3XX_GRAS_CL_CLIP_CNTL_VP_CLIP_CODE_IGNORE
|
270 A3XX_GRAS_CL_CLIP_CNTL_VP_XFORM_DISABLE
|
271 A3XX_GRAS_CL_CLIP_CNTL_PERSP_DIVISION_DISABLE
);
273 OUT_PKT0(ring
, REG_A3XX_GRAS_CL_GB_CLIP_ADJ
, 1);
274 OUT_RING(ring
, A3XX_GRAS_CL_GB_CLIP_ADJ_HORZ(0) |
275 A3XX_GRAS_CL_GB_CLIP_ADJ_VERT(0));
277 OUT_PKT3(ring
, CP_DRAW_INDX_2
, 5);
278 OUT_RING(ring
, 0x00000000); /* viz query info. */
279 OUT_RING(ring
, DRAW(DI_PT_RECTLIST
, DI_SRC_SEL_IMMEDIATE
,
280 INDEX_SIZE_32_BIT
, IGNORE_VISIBILITY
, 0));
281 OUT_RING(ring
, 2); /* NumIndices */
286 OUT_PKT0(ring
, REG_A3XX_HLSQ_CONTROL_0_REG
, 1);
287 OUT_RING(ring
, A3XX_HLSQ_CONTROL_0_REG_FSTHREADSIZE(TWO_QUADS
));
289 OUT_PKT0(ring
, REG_A3XX_VFD_PERFCOUNTER0_SELECT
, 1);
290 OUT_RING(ring
, 0x00000000);
293 OUT_PKT0(ring
, REG_A3XX_VSC_BIN_SIZE
, 1);
294 OUT_RING(ring
, A3XX_VSC_BIN_SIZE_WIDTH(gmem
->bin_w
) |
295 A3XX_VSC_BIN_SIZE_HEIGHT(gmem
->bin_h
));
297 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_CONTROL
, 1);
298 OUT_RING(ring
, A3XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
299 A3XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
300 A3XX_GRAS_SC_CONTROL_RASTER_MODE(0));
302 OUT_PKT0(ring
, REG_A3XX_GRAS_CL_CLIP_CNTL
, 1);
303 OUT_RING(ring
, 0x00000000);
306 /* transfer from gmem to system memory (ie. normal RAM) */
309 emit_gmem2mem_surf(struct fd_context
*ctx
,
310 enum adreno_rb_copy_control_mode mode
,
312 uint32_t base
, struct pipe_surface
*psurf
)
314 struct fd_ringbuffer
*ring
= ctx
->ring
;
315 struct fd_resource
*rsc
= fd_resource(psurf
->texture
);
316 enum pipe_format format
= psurf
->format
;
319 format
= rsc
->base
.b
.format
;
321 struct fd_resource_slice
*slice
= fd_resource_slice(rsc
, psurf
->u
.tex
.level
);
322 uint32_t offset
= fd_resource_offset(rsc
, psurf
->u
.tex
.level
,
323 psurf
->u
.tex
.first_layer
);
325 debug_assert(psurf
->u
.tex
.first_layer
== psurf
->u
.tex
.last_layer
);
327 OUT_PKT0(ring
, REG_A3XX_RB_COPY_CONTROL
, 4);
328 OUT_RING(ring
, A3XX_RB_COPY_CONTROL_MSAA_RESOLVE(MSAA_ONE
) |
329 A3XX_RB_COPY_CONTROL_MODE(mode
) |
330 A3XX_RB_COPY_CONTROL_GMEM_BASE(base
) |
331 COND(format
== PIPE_FORMAT_Z32_FLOAT
||
332 format
== PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
,
333 A3XX_RB_COPY_CONTROL_UNK12
));
335 OUT_RELOCW(ring
, rsc
->bo
, offset
, 0, -1); /* RB_COPY_DEST_BASE */
336 OUT_RING(ring
, A3XX_RB_COPY_DEST_PITCH_PITCH(slice
->pitch
* rsc
->cpp
));
337 OUT_RING(ring
, A3XX_RB_COPY_DEST_INFO_TILE(LINEAR
) |
338 A3XX_RB_COPY_DEST_INFO_FORMAT(fd3_pipe2color(format
)) |
339 A3XX_RB_COPY_DEST_INFO_COMPONENT_ENABLE(0xf) |
340 A3XX_RB_COPY_DEST_INFO_ENDIAN(ENDIAN_NONE
) |
341 A3XX_RB_COPY_DEST_INFO_SWAP(fd3_pipe2swap(format
)));
343 fd_draw(ctx
, ring
, DI_PT_RECTLIST
, IGNORE_VISIBILITY
,
344 DI_SRC_SEL_AUTO_INDEX
, 2, 0, INDEX_SIZE_IGN
, 0, 0, NULL
);
348 fd3_emit_tile_gmem2mem(struct fd_context
*ctx
, struct fd_tile
*tile
)
350 struct fd3_context
*fd3_ctx
= fd3_context(ctx
);
351 struct fd_ringbuffer
*ring
= ctx
->ring
;
352 struct pipe_framebuffer_state
*pfb
= &ctx
->framebuffer
;
353 struct fd3_emit emit
= {
354 .vtx
= &fd3_ctx
->solid_vbuf_state
,
355 .prog
= &ctx
->solid_prog
,
357 .half_precision
= true,
362 OUT_PKT0(ring
, REG_A3XX_RB_DEPTH_CONTROL
, 1);
363 OUT_RING(ring
, A3XX_RB_DEPTH_CONTROL_ZFUNC(FUNC_NEVER
));
365 OUT_PKT0(ring
, REG_A3XX_RB_STENCIL_CONTROL
, 1);
366 OUT_RING(ring
, A3XX_RB_STENCIL_CONTROL_FUNC(FUNC_NEVER
) |
367 A3XX_RB_STENCIL_CONTROL_FAIL(STENCIL_KEEP
) |
368 A3XX_RB_STENCIL_CONTROL_ZPASS(STENCIL_KEEP
) |
369 A3XX_RB_STENCIL_CONTROL_ZFAIL(STENCIL_KEEP
) |
370 A3XX_RB_STENCIL_CONTROL_FUNC_BF(FUNC_NEVER
) |
371 A3XX_RB_STENCIL_CONTROL_FAIL_BF(STENCIL_KEEP
) |
372 A3XX_RB_STENCIL_CONTROL_ZPASS_BF(STENCIL_KEEP
) |
373 A3XX_RB_STENCIL_CONTROL_ZFAIL_BF(STENCIL_KEEP
));
375 OUT_PKT0(ring
, REG_A3XX_RB_STENCILREFMASK
, 2);
376 OUT_RING(ring
, 0xff000000 |
377 A3XX_RB_STENCILREFMASK_STENCILREF(0) |
378 A3XX_RB_STENCILREFMASK_STENCILMASK(0) |
379 A3XX_RB_STENCILREFMASK_STENCILWRITEMASK(0xff));
380 OUT_RING(ring
, 0xff000000 |
381 A3XX_RB_STENCILREFMASK_STENCILREF(0) |
382 A3XX_RB_STENCILREFMASK_STENCILMASK(0) |
383 A3XX_RB_STENCILREFMASK_STENCILWRITEMASK(0xff));
385 OUT_PKT0(ring
, REG_A3XX_GRAS_SU_MODE_CONTROL
, 1);
386 OUT_RING(ring
, A3XX_GRAS_SU_MODE_CONTROL_LINEHALFWIDTH(0));
388 OUT_PKT0(ring
, REG_A3XX_GRAS_CL_CLIP_CNTL
, 1);
389 OUT_RING(ring
, 0x00000000); /* GRAS_CL_CLIP_CNTL */
392 OUT_PKT0(ring
, REG_A3XX_GRAS_CL_VPORT_XOFFSET
, 6);
393 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_XOFFSET((float)pfb
->width
/2.0 - 0.5));
394 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_XSCALE((float)pfb
->width
/2.0));
395 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_YOFFSET((float)pfb
->height
/2.0 - 0.5));
396 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_YSCALE(-(float)pfb
->height
/2.0));
397 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_ZOFFSET(0.0));
398 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_ZSCALE(1.0));
400 OUT_PKT0(ring
, REG_A3XX_RB_MODE_CONTROL
, 1);
401 OUT_RING(ring
, A3XX_RB_MODE_CONTROL_RENDER_MODE(RB_RESOLVE_PASS
) |
402 A3XX_RB_MODE_CONTROL_MARB_CACHE_SPLIT_MODE
|
403 A3XX_RB_MODE_CONTROL_MRT(0));
405 OUT_PKT0(ring
, REG_A3XX_RB_RENDER_CONTROL
, 1);
406 OUT_RING(ring
, A3XX_RB_RENDER_CONTROL_DISABLE_COLOR_PIPE
|
407 A3XX_RB_RENDER_CONTROL_ENABLE_GMEM
|
408 A3XX_RB_RENDER_CONTROL_ALPHA_TEST_FUNC(FUNC_NEVER
) |
409 A3XX_RB_RENDER_CONTROL_BIN_WIDTH(ctx
->gmem
.bin_w
));
411 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_CONTROL
, 1);
412 OUT_RING(ring
, A3XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RESOLVE_PASS
) |
413 A3XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
414 A3XX_GRAS_SC_CONTROL_RASTER_MODE(1));
416 OUT_PKT0(ring
, REG_A3XX_PC_PRIM_VTX_CNTL
, 1);
417 OUT_RING(ring
, A3XX_PC_PRIM_VTX_CNTL_STRIDE_IN_VPC(0) |
418 A3XX_PC_PRIM_VTX_CNTL_POLYMODE_FRONT_PTYPE(PC_DRAW_TRIANGLES
) |
419 A3XX_PC_PRIM_VTX_CNTL_POLYMODE_BACK_PTYPE(PC_DRAW_TRIANGLES
) |
420 A3XX_PC_PRIM_VTX_CNTL_PROVOKING_VTX_LAST
);
422 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_WINDOW_SCISSOR_TL
, 2);
423 OUT_RING(ring
, A3XX_GRAS_SC_WINDOW_SCISSOR_TL_X(0) |
424 A3XX_GRAS_SC_WINDOW_SCISSOR_TL_Y(0));
425 OUT_RING(ring
, A3XX_GRAS_SC_WINDOW_SCISSOR_BR_X(pfb
->width
- 1) |
426 A3XX_GRAS_SC_WINDOW_SCISSOR_BR_Y(pfb
->height
- 1));
428 OUT_PKT0(ring
, REG_A3XX_VFD_INDEX_MIN
, 4);
429 OUT_RING(ring
, 0); /* VFD_INDEX_MIN */
430 OUT_RING(ring
, 2); /* VFD_INDEX_MAX */
431 OUT_RING(ring
, 0); /* VFD_INSTANCEID_OFFSET */
432 OUT_RING(ring
, 0); /* VFD_INDEX_OFFSET */
434 fd3_program_emit(ring
, &emit
, 0, NULL
);
435 fd3_emit_vertex_bufs(ring
, &emit
);
437 if (ctx
->resolve
& (FD_BUFFER_DEPTH
| FD_BUFFER_STENCIL
)) {
438 struct fd_resource
*rsc
= fd_resource(pfb
->zsbuf
->texture
);
439 if (!rsc
->stencil
|| ctx
->resolve
& FD_BUFFER_DEPTH
)
440 emit_gmem2mem_surf(ctx
, RB_COPY_DEPTH_STENCIL
, false,
441 ctx
->gmem
.zsbuf_base
[0], pfb
->zsbuf
);
442 if (rsc
->stencil
&& ctx
->resolve
& FD_BUFFER_STENCIL
)
443 emit_gmem2mem_surf(ctx
, RB_COPY_DEPTH_STENCIL
, true,
444 ctx
->gmem
.zsbuf_base
[1], pfb
->zsbuf
);
447 if (ctx
->resolve
& FD_BUFFER_COLOR
) {
448 for (i
= 0; i
< pfb
->nr_cbufs
; i
++) {
451 if (!(ctx
->resolve
& (PIPE_CLEAR_COLOR0
<< i
)))
453 emit_gmem2mem_surf(ctx
, RB_COPY_RESOLVE
, false,
454 ctx
->gmem
.cbuf_base
[i
], pfb
->cbufs
[i
]);
458 OUT_PKT0(ring
, REG_A3XX_RB_MODE_CONTROL
, 1);
459 OUT_RING(ring
, A3XX_RB_MODE_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
460 A3XX_RB_MODE_CONTROL_MARB_CACHE_SPLIT_MODE
|
461 A3XX_RB_MODE_CONTROL_MRT(MAX2(1, pfb
->nr_cbufs
) - 1));
463 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_CONTROL
, 1);
464 OUT_RING(ring
, A3XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
465 A3XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
466 A3XX_GRAS_SC_CONTROL_RASTER_MODE(0));
469 /* transfer from system memory to gmem */
472 emit_mem2gmem_surf(struct fd_context
*ctx
, uint32_t bases
[],
473 struct pipe_surface
**psurf
, uint32_t bufs
, uint32_t bin_w
)
475 struct fd_ringbuffer
*ring
= ctx
->ring
;
476 struct pipe_surface
*zsbufs
[2];
480 OUT_PKT0(ring
, REG_A3XX_RB_MODE_CONTROL
, 1);
481 OUT_RING(ring
, A3XX_RB_MODE_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
482 A3XX_RB_MODE_CONTROL_MARB_CACHE_SPLIT_MODE
|
483 A3XX_RB_MODE_CONTROL_MRT(bufs
- 1));
485 emit_mrt(ring
, bufs
, psurf
, bases
, bin_w
, false);
487 if (psurf
[0] && (psurf
[0]->format
== PIPE_FORMAT_Z32_FLOAT
||
488 psurf
[0]->format
== PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
)) {
489 /* Depth is stored as unorm in gmem, so we have to write it in using a
490 * special blit shader which writes depth.
492 OUT_PKT0(ring
, REG_A3XX_RB_DEPTH_CONTROL
, 1);
493 OUT_RING(ring
, (A3XX_RB_DEPTH_CONTROL_FRAG_WRITES_Z
|
494 A3XX_RB_DEPTH_CONTROL_Z_WRITE_ENABLE
|
495 A3XX_RB_DEPTH_CONTROL_Z_ENABLE
|
496 A3XX_RB_DEPTH_CONTROL_EARLY_Z_DISABLE
|
497 A3XX_RB_DEPTH_CONTROL_ZFUNC(FUNC_ALWAYS
)));
499 OUT_PKT0(ring
, REG_A3XX_RB_DEPTH_INFO
, 2);
500 OUT_RING(ring
, A3XX_RB_DEPTH_INFO_DEPTH_BASE(bases
[0]) |
501 A3XX_RB_DEPTH_INFO_DEPTH_FORMAT(DEPTHX_32
));
502 OUT_RING(ring
, A3XX_RB_DEPTH_PITCH(4 * ctx
->gmem
.bin_w
));
504 if (psurf
[0]->format
== PIPE_FORMAT_Z32_FLOAT
) {
505 OUT_PKT0(ring
, REG_A3XX_RB_MRT_CONTROL(0), 1);
508 /* The gmem_restore_tex logic will put the first buffer's stencil
509 * as color. Supply it with the proper information to make that
512 zsbufs
[0] = zsbufs
[1] = psurf
[0];
517 OUT_PKT0(ring
, REG_A3XX_SP_FS_OUTPUT_REG
, 1);
518 OUT_RING(ring
, A3XX_SP_FS_OUTPUT_REG_MRT(bufs
- 1));
521 fd3_emit_gmem_restore_tex(ring
, psurf
, bufs
);
523 fd_draw(ctx
, ring
, DI_PT_RECTLIST
, IGNORE_VISIBILITY
,
524 DI_SRC_SEL_AUTO_INDEX
, 2, 0, INDEX_SIZE_IGN
, 0, 0, NULL
);
528 fd3_emit_tile_mem2gmem(struct fd_context
*ctx
, struct fd_tile
*tile
)
530 struct fd3_context
*fd3_ctx
= fd3_context(ctx
);
531 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
532 struct fd_ringbuffer
*ring
= ctx
->ring
;
533 struct pipe_framebuffer_state
*pfb
= &ctx
->framebuffer
;
534 struct fd3_emit emit
= {
535 .vtx
= &fd3_ctx
->blit_vbuf_state
,
536 .sprite_coord_enable
= 1,
537 /* NOTE: They all use the same VP, this is for vtx bufs. */
538 .prog
= &ctx
->blit_prog
[0],
540 .half_precision
= fd_half_precision(pfb
),
543 float x0
, y0
, x1
, y1
;
544 unsigned bin_w
= tile
->bin_w
;
545 unsigned bin_h
= tile
->bin_h
;
548 /* write texture coordinates to vertexbuf: */
549 x0
= ((float)tile
->xoff
) / ((float)pfb
->width
);
550 x1
= ((float)tile
->xoff
+ bin_w
) / ((float)pfb
->width
);
551 y0
= ((float)tile
->yoff
) / ((float)pfb
->height
);
552 y1
= ((float)tile
->yoff
+ bin_h
) / ((float)pfb
->height
);
554 OUT_PKT3(ring
, CP_MEM_WRITE
, 5);
555 OUT_RELOCW(ring
, fd_resource(fd3_ctx
->blit_texcoord_vbuf
)->bo
, 0, 0, 0);
556 OUT_RING(ring
, fui(x0
));
557 OUT_RING(ring
, fui(y0
));
558 OUT_RING(ring
, fui(x1
));
559 OUT_RING(ring
, fui(y1
));
561 for (i
= 0; i
< 4; i
++) {
562 OUT_PKT0(ring
, REG_A3XX_RB_MRT_CONTROL(i
), 1);
563 OUT_RING(ring
, A3XX_RB_MRT_CONTROL_ROP_CODE(ROP_COPY
) |
564 A3XX_RB_MRT_CONTROL_DITHER_MODE(DITHER_DISABLE
) |
565 A3XX_RB_MRT_CONTROL_COMPONENT_ENABLE(0xf));
567 OUT_PKT0(ring
, REG_A3XX_RB_MRT_BLEND_CONTROL(i
), 1);
568 OUT_RING(ring
, A3XX_RB_MRT_BLEND_CONTROL_RGB_SRC_FACTOR(FACTOR_ONE
) |
569 A3XX_RB_MRT_BLEND_CONTROL_RGB_BLEND_OPCODE(BLEND_DST_PLUS_SRC
) |
570 A3XX_RB_MRT_BLEND_CONTROL_RGB_DEST_FACTOR(FACTOR_ZERO
) |
571 A3XX_RB_MRT_BLEND_CONTROL_ALPHA_SRC_FACTOR(FACTOR_ONE
) |
572 A3XX_RB_MRT_BLEND_CONTROL_ALPHA_BLEND_OPCODE(BLEND_DST_PLUS_SRC
) |
573 A3XX_RB_MRT_BLEND_CONTROL_ALPHA_DEST_FACTOR(FACTOR_ZERO
));
576 OUT_PKT0(ring
, REG_A3XX_RB_RENDER_CONTROL
, 1);
577 OUT_RING(ring
, A3XX_RB_RENDER_CONTROL_ALPHA_TEST_FUNC(FUNC_ALWAYS
) |
578 A3XX_RB_RENDER_CONTROL_BIN_WIDTH(gmem
->bin_w
));
581 OUT_PKT0(ring
, REG_A3XX_RB_DEPTH_CONTROL
, 1);
582 OUT_RING(ring
, A3XX_RB_DEPTH_CONTROL_ZFUNC(FUNC_LESS
));
584 OUT_PKT0(ring
, REG_A3XX_RB_DEPTH_INFO
, 2);
588 OUT_PKT0(ring
, REG_A3XX_GRAS_CL_CLIP_CNTL
, 1);
589 OUT_RING(ring
, A3XX_GRAS_CL_CLIP_CNTL_IJ_PERSP_CENTER
); /* GRAS_CL_CLIP_CNTL */
592 OUT_PKT0(ring
, REG_A3XX_GRAS_CL_VPORT_XOFFSET
, 6);
593 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_XOFFSET((float)bin_w
/2.0 - 0.5));
594 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_XSCALE((float)bin_w
/2.0));
595 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_YOFFSET((float)bin_h
/2.0 - 0.5));
596 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_YSCALE(-(float)bin_h
/2.0));
597 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_ZOFFSET(0.0));
598 OUT_RING(ring
, A3XX_GRAS_CL_VPORT_ZSCALE(1.0));
600 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_WINDOW_SCISSOR_TL
, 2);
601 OUT_RING(ring
, A3XX_GRAS_SC_WINDOW_SCISSOR_TL_X(0) |
602 A3XX_GRAS_SC_WINDOW_SCISSOR_TL_Y(0));
603 OUT_RING(ring
, A3XX_GRAS_SC_WINDOW_SCISSOR_BR_X(bin_w
- 1) |
604 A3XX_GRAS_SC_WINDOW_SCISSOR_BR_Y(bin_h
- 1));
606 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_SCREEN_SCISSOR_TL
, 2);
607 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_TL_X(0) |
608 A3XX_GRAS_SC_SCREEN_SCISSOR_TL_Y(0));
609 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_BR_X(bin_w
- 1) |
610 A3XX_GRAS_SC_SCREEN_SCISSOR_BR_Y(bin_h
- 1));
612 OUT_PKT0(ring
, REG_A3XX_RB_STENCIL_CONTROL
, 1);
614 A3XX_RB_STENCIL_CONTROL_FUNC(FUNC_ALWAYS
) |
615 A3XX_RB_STENCIL_CONTROL_FAIL(STENCIL_KEEP
) |
616 A3XX_RB_STENCIL_CONTROL_ZPASS(STENCIL_KEEP
) |
617 A3XX_RB_STENCIL_CONTROL_ZFAIL(STENCIL_KEEP
) |
618 A3XX_RB_STENCIL_CONTROL_FUNC_BF(FUNC_ALWAYS
) |
619 A3XX_RB_STENCIL_CONTROL_FAIL_BF(STENCIL_KEEP
) |
620 A3XX_RB_STENCIL_CONTROL_ZPASS_BF(STENCIL_KEEP
) |
621 A3XX_RB_STENCIL_CONTROL_ZFAIL_BF(STENCIL_KEEP
));
623 OUT_PKT0(ring
, REG_A3XX_RB_STENCIL_INFO
, 2);
624 OUT_RING(ring
, 0); /* RB_STENCIL_INFO */
625 OUT_RING(ring
, 0); /* RB_STENCIL_PITCH */
627 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_CONTROL
, 1);
628 OUT_RING(ring
, A3XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
629 A3XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
630 A3XX_GRAS_SC_CONTROL_RASTER_MODE(1));
632 OUT_PKT0(ring
, REG_A3XX_PC_PRIM_VTX_CNTL
, 1);
633 OUT_RING(ring
, A3XX_PC_PRIM_VTX_CNTL_STRIDE_IN_VPC(2) |
634 A3XX_PC_PRIM_VTX_CNTL_POLYMODE_FRONT_PTYPE(PC_DRAW_TRIANGLES
) |
635 A3XX_PC_PRIM_VTX_CNTL_POLYMODE_BACK_PTYPE(PC_DRAW_TRIANGLES
) |
636 A3XX_PC_PRIM_VTX_CNTL_PROVOKING_VTX_LAST
);
638 OUT_PKT0(ring
, REG_A3XX_VFD_INDEX_MIN
, 4);
639 OUT_RING(ring
, 0); /* VFD_INDEX_MIN */
640 OUT_RING(ring
, 2); /* VFD_INDEX_MAX */
641 OUT_RING(ring
, 0); /* VFD_INSTANCEID_OFFSET */
642 OUT_RING(ring
, 0); /* VFD_INDEX_OFFSET */
644 fd3_emit_vertex_bufs(ring
, &emit
);
646 /* for gmem pitch/base calculations, we need to use the non-
647 * truncated tile sizes:
652 if (fd_gmem_needs_restore(ctx
, tile
, FD_BUFFER_COLOR
)) {
653 emit
.prog
= &ctx
->blit_prog
[pfb
->nr_cbufs
- 1];
654 fd3_program_emit(ring
, &emit
, pfb
->nr_cbufs
, pfb
->cbufs
);
655 emit_mem2gmem_surf(ctx
, gmem
->cbuf_base
, pfb
->cbufs
, pfb
->nr_cbufs
, bin_w
);
658 if (fd_gmem_needs_restore(ctx
, tile
, FD_BUFFER_DEPTH
| FD_BUFFER_STENCIL
)) {
659 if (pfb
->zsbuf
->format
!= PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
&&
660 pfb
->zsbuf
->format
!= PIPE_FORMAT_Z32_FLOAT
) {
661 /* Non-float can use a regular color write. It's split over 8-bit
662 * components, so half precision is always sufficient.
664 emit
.prog
= &ctx
->blit_prog
[0];
665 emit
.key
.half_precision
= true;
667 /* Float depth needs special blit shader that writes depth */
668 if (pfb
->zsbuf
->format
== PIPE_FORMAT_Z32_FLOAT
)
669 emit
.prog
= &ctx
->blit_z
;
671 emit
.prog
= &ctx
->blit_zs
;
672 emit
.key
.half_precision
= false;
674 fd3_program_emit(ring
, &emit
, 1, &pfb
->zsbuf
);
675 emit_mem2gmem_surf(ctx
, gmem
->zsbuf_base
, &pfb
->zsbuf
, 1, bin_w
);
678 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_CONTROL
, 1);
679 OUT_RING(ring
, A3XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
680 A3XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
681 A3XX_GRAS_SC_CONTROL_RASTER_MODE(0));
683 OUT_PKT0(ring
, REG_A3XX_RB_MODE_CONTROL
, 1);
684 OUT_RING(ring
, A3XX_RB_MODE_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
685 A3XX_RB_MODE_CONTROL_MARB_CACHE_SPLIT_MODE
|
686 A3XX_RB_MODE_CONTROL_MRT(MAX2(1, pfb
->nr_cbufs
) - 1));
690 patch_draws(struct fd_context
*ctx
, enum pc_di_vis_cull_mode vismode
)
693 for (i
= 0; i
< fd_patch_num_elements(&ctx
->draw_patches
); i
++) {
694 struct fd_cs_patch
*patch
= fd_patch_element(&ctx
->draw_patches
, i
);
695 *patch
->cs
= patch
->val
| DRAW(0, 0, 0, vismode
, 0);
697 util_dynarray_resize(&ctx
->draw_patches
, 0);
701 patch_rbrc(struct fd_context
*ctx
, uint32_t val
)
703 struct fd3_context
*fd3_ctx
= fd3_context(ctx
);
705 for (i
= 0; i
< fd_patch_num_elements(&fd3_ctx
->rbrc_patches
); i
++) {
706 struct fd_cs_patch
*patch
= fd_patch_element(&fd3_ctx
->rbrc_patches
, i
);
707 *patch
->cs
= patch
->val
| val
;
709 util_dynarray_resize(&fd3_ctx
->rbrc_patches
, 0);
712 /* for rendering directly to system memory: */
714 fd3_emit_sysmem_prep(struct fd_context
*ctx
)
716 struct pipe_framebuffer_state
*pfb
= &ctx
->framebuffer
;
717 struct fd_ringbuffer
*ring
= ctx
->ring
;
718 uint32_t i
, pitch
= 0;
720 for (i
= 0; i
< pfb
->nr_cbufs
; i
++) {
721 struct pipe_surface
*psurf
= pfb
->cbufs
[i
];
724 pitch
= fd_resource(psurf
->texture
)->slices
[psurf
->u
.tex
.level
].pitch
;
727 fd3_emit_restore(ctx
);
729 OUT_PKT0(ring
, REG_A3XX_RB_FRAME_BUFFER_DIMENSION
, 1);
730 OUT_RING(ring
, A3XX_RB_FRAME_BUFFER_DIMENSION_WIDTH(pfb
->width
) |
731 A3XX_RB_FRAME_BUFFER_DIMENSION_HEIGHT(pfb
->height
));
733 emit_mrt(ring
, pfb
->nr_cbufs
, pfb
->cbufs
, NULL
, 0, true);
735 /* setup scissor/offset for current tile: */
736 OUT_PKT0(ring
, REG_A3XX_RB_WINDOW_OFFSET
, 1);
737 OUT_RING(ring
, A3XX_RB_WINDOW_OFFSET_X(0) |
738 A3XX_RB_WINDOW_OFFSET_Y(0));
740 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_SCREEN_SCISSOR_TL
, 2);
741 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_TL_X(0) |
742 A3XX_GRAS_SC_SCREEN_SCISSOR_TL_Y(0));
743 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_BR_X(pfb
->width
- 1) |
744 A3XX_GRAS_SC_SCREEN_SCISSOR_BR_Y(pfb
->height
- 1));
746 OUT_PKT0(ring
, REG_A3XX_RB_MODE_CONTROL
, 1);
747 OUT_RING(ring
, A3XX_RB_MODE_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
748 A3XX_RB_MODE_CONTROL_GMEM_BYPASS
|
749 A3XX_RB_MODE_CONTROL_MARB_CACHE_SPLIT_MODE
|
750 A3XX_RB_MODE_CONTROL_MRT(MAX2(1, pfb
->nr_cbufs
) - 1));
752 patch_draws(ctx
, IGNORE_VISIBILITY
);
753 patch_rbrc(ctx
, A3XX_RB_RENDER_CONTROL_BIN_WIDTH(pitch
));
757 update_vsc_pipe(struct fd_context
*ctx
)
759 struct fd3_context
*fd3_ctx
= fd3_context(ctx
);
760 struct fd_ringbuffer
*ring
= ctx
->ring
;
763 OUT_PKT0(ring
, REG_A3XX_VSC_SIZE_ADDRESS
, 1);
764 OUT_RELOCW(ring
, fd3_ctx
->vsc_size_mem
, 0, 0, 0); /* VSC_SIZE_ADDRESS */
766 for (i
= 0; i
< 8; i
++) {
767 struct fd_vsc_pipe
*pipe
= &ctx
->pipe
[i
];
770 pipe
->bo
= fd_bo_new(ctx
->dev
, 0x40000,
771 DRM_FREEDRENO_GEM_TYPE_KMEM
);
774 OUT_PKT0(ring
, REG_A3XX_VSC_PIPE(i
), 3);
775 OUT_RING(ring
, A3XX_VSC_PIPE_CONFIG_X(pipe
->x
) |
776 A3XX_VSC_PIPE_CONFIG_Y(pipe
->y
) |
777 A3XX_VSC_PIPE_CONFIG_W(pipe
->w
) |
778 A3XX_VSC_PIPE_CONFIG_H(pipe
->h
));
779 OUT_RELOCW(ring
, pipe
->bo
, 0, 0, 0); /* VSC_PIPE[i].DATA_ADDRESS */
780 OUT_RING(ring
, fd_bo_size(pipe
->bo
) - 32); /* VSC_PIPE[i].DATA_LENGTH */
785 emit_binning_pass(struct fd_context
*ctx
)
787 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
788 struct pipe_framebuffer_state
*pfb
= &ctx
->framebuffer
;
789 struct fd_ringbuffer
*ring
= ctx
->ring
;
792 uint32_t x1
= gmem
->minx
;
793 uint32_t y1
= gmem
->miny
;
794 uint32_t x2
= gmem
->minx
+ gmem
->width
- 1;
795 uint32_t y2
= gmem
->miny
+ gmem
->height
- 1;
797 if (ctx
->screen
->gpu_id
== 320) {
798 emit_binning_workaround(ctx
);
800 OUT_PKT3(ring
, CP_INVALIDATE_STATE
, 1);
801 OUT_RING(ring
, 0x00007fff);
804 OUT_PKT0(ring
, REG_A3XX_VSC_BIN_CONTROL
, 1);
805 OUT_RING(ring
, A3XX_VSC_BIN_CONTROL_BINNING_ENABLE
);
807 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_CONTROL
, 1);
808 OUT_RING(ring
, A3XX_GRAS_SC_CONTROL_RENDER_MODE(RB_TILING_PASS
) |
809 A3XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
810 A3XX_GRAS_SC_CONTROL_RASTER_MODE(0));
812 OUT_PKT0(ring
, REG_A3XX_RB_FRAME_BUFFER_DIMENSION
, 1);
813 OUT_RING(ring
, A3XX_RB_FRAME_BUFFER_DIMENSION_WIDTH(pfb
->width
) |
814 A3XX_RB_FRAME_BUFFER_DIMENSION_HEIGHT(pfb
->height
));
816 OUT_PKT0(ring
, REG_A3XX_RB_RENDER_CONTROL
, 1);
817 OUT_RING(ring
, A3XX_RB_RENDER_CONTROL_ALPHA_TEST_FUNC(FUNC_NEVER
) |
818 A3XX_RB_RENDER_CONTROL_DISABLE_COLOR_PIPE
|
819 A3XX_RB_RENDER_CONTROL_BIN_WIDTH(gmem
->bin_w
));
821 /* setup scissor/offset for whole screen: */
822 OUT_PKT0(ring
, REG_A3XX_RB_WINDOW_OFFSET
, 1);
823 OUT_RING(ring
, A3XX_RB_WINDOW_OFFSET_X(x1
) |
824 A3XX_RB_WINDOW_OFFSET_Y(y1
));
826 OUT_PKT0(ring
, REG_A3XX_RB_LRZ_VSC_CONTROL
, 1);
827 OUT_RING(ring
, A3XX_RB_LRZ_VSC_CONTROL_BINNING_ENABLE
);
829 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_SCREEN_SCISSOR_TL
, 2);
830 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_TL_X(x1
) |
831 A3XX_GRAS_SC_SCREEN_SCISSOR_TL_Y(y1
));
832 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_BR_X(x2
) |
833 A3XX_GRAS_SC_SCREEN_SCISSOR_BR_Y(y2
));
835 OUT_PKT0(ring
, REG_A3XX_RB_MODE_CONTROL
, 1);
836 OUT_RING(ring
, A3XX_RB_MODE_CONTROL_RENDER_MODE(RB_TILING_PASS
) |
837 A3XX_RB_MODE_CONTROL_MARB_CACHE_SPLIT_MODE
|
838 A3XX_RB_MODE_CONTROL_MRT(0));
840 for (i
= 0; i
< 4; i
++) {
841 OUT_PKT0(ring
, REG_A3XX_RB_MRT_CONTROL(i
), 1);
842 OUT_RING(ring
, A3XX_RB_MRT_CONTROL_ROP_CODE(ROP_CLEAR
) |
843 A3XX_RB_MRT_CONTROL_DITHER_MODE(DITHER_DISABLE
) |
844 A3XX_RB_MRT_CONTROL_COMPONENT_ENABLE(0));
847 OUT_PKT0(ring
, REG_A3XX_PC_VSTREAM_CONTROL
, 1);
848 OUT_RING(ring
, A3XX_PC_VSTREAM_CONTROL_SIZE(1) |
849 A3XX_PC_VSTREAM_CONTROL_N(0));
851 /* emit IB to binning drawcmds: */
852 OUT_IB(ring
, ctx
->binning_start
, ctx
->binning_end
);
857 /* and then put stuff back the way it was: */
859 OUT_PKT0(ring
, REG_A3XX_VSC_BIN_CONTROL
, 1);
860 OUT_RING(ring
, 0x00000000);
862 OUT_PKT0(ring
, REG_A3XX_SP_SP_CTRL_REG
, 1);
863 OUT_RING(ring
, A3XX_SP_SP_CTRL_REG_RESOLVE
|
864 A3XX_SP_SP_CTRL_REG_CONSTMODE(1) |
865 A3XX_SP_SP_CTRL_REG_SLEEPMODE(1) |
866 A3XX_SP_SP_CTRL_REG_L0MODE(0));
868 OUT_PKT0(ring
, REG_A3XX_RB_LRZ_VSC_CONTROL
, 1);
869 OUT_RING(ring
, 0x00000000);
871 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_CONTROL
, 1);
872 OUT_RING(ring
, A3XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
873 A3XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
874 A3XX_GRAS_SC_CONTROL_RASTER_MODE(0));
876 OUT_PKT0(ring
, REG_A3XX_RB_MODE_CONTROL
, 2);
877 OUT_RING(ring
, A3XX_RB_MODE_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
878 A3XX_RB_MODE_CONTROL_MARB_CACHE_SPLIT_MODE
|
879 A3XX_RB_MODE_CONTROL_MRT(pfb
->nr_cbufs
- 1));
880 OUT_RING(ring
, A3XX_RB_RENDER_CONTROL_ENABLE_GMEM
|
881 A3XX_RB_RENDER_CONTROL_ALPHA_TEST_FUNC(FUNC_NEVER
) |
882 A3XX_RB_RENDER_CONTROL_BIN_WIDTH(gmem
->bin_w
));
884 fd_event_write(ctx
, ring
, CACHE_FLUSH
);
887 if (ctx
->screen
->gpu_id
== 320) {
888 /* dummy-draw workaround: */
889 OUT_PKT3(ring
, CP_DRAW_INDX
, 3);
890 OUT_RING(ring
, 0x00000000);
891 OUT_RING(ring
, DRAW(1, DI_SRC_SEL_AUTO_INDEX
,
892 INDEX_SIZE_IGN
, IGNORE_VISIBILITY
, 0));
893 OUT_RING(ring
, 0); /* NumIndices */
897 OUT_PKT3(ring
, CP_NOP
, 4);
898 OUT_RING(ring
, 0x00000000);
899 OUT_RING(ring
, 0x00000000);
900 OUT_RING(ring
, 0x00000000);
901 OUT_RING(ring
, 0x00000000);
905 if (ctx
->screen
->gpu_id
== 320) {
906 emit_binning_workaround(ctx
);
910 /* before first tile */
912 fd3_emit_tile_init(struct fd_context
*ctx
)
914 struct fd_ringbuffer
*ring
= ctx
->ring
;
915 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
916 uint32_t rb_render_control
;
918 fd3_emit_restore(ctx
);
920 /* note: use gmem->bin_w/h, the bin_w/h parameters may be truncated
921 * at the right and bottom edge tiles
923 OUT_PKT0(ring
, REG_A3XX_VSC_BIN_SIZE
, 1);
924 OUT_RING(ring
, A3XX_VSC_BIN_SIZE_WIDTH(gmem
->bin_w
) |
925 A3XX_VSC_BIN_SIZE_HEIGHT(gmem
->bin_h
));
927 update_vsc_pipe(ctx
);
929 if (use_hw_binning(ctx
)) {
930 /* mark the end of the binning cmds: */
931 fd_ringmarker_mark(ctx
->binning_end
);
933 /* emit hw binning pass: */
934 emit_binning_pass(ctx
);
936 patch_draws(ctx
, USE_VISIBILITY
);
938 patch_draws(ctx
, IGNORE_VISIBILITY
);
941 rb_render_control
= A3XX_RB_RENDER_CONTROL_ENABLE_GMEM
|
942 A3XX_RB_RENDER_CONTROL_BIN_WIDTH(gmem
->bin_w
);
944 patch_rbrc(ctx
, rb_render_control
);
947 /* before mem2gmem */
949 fd3_emit_tile_prep(struct fd_context
*ctx
, struct fd_tile
*tile
)
951 struct fd_ringbuffer
*ring
= ctx
->ring
;
952 struct pipe_framebuffer_state
*pfb
= &ctx
->framebuffer
;
954 if (ctx
->needs_rb_fbd
) {
956 OUT_PKT0(ring
, REG_A3XX_RB_FRAME_BUFFER_DIMENSION
, 1);
957 OUT_RING(ring
, A3XX_RB_FRAME_BUFFER_DIMENSION_WIDTH(pfb
->width
) |
958 A3XX_RB_FRAME_BUFFER_DIMENSION_HEIGHT(pfb
->height
));
959 ctx
->needs_rb_fbd
= false;
962 OUT_PKT0(ring
, REG_A3XX_RB_MODE_CONTROL
, 1);
963 OUT_RING(ring
, A3XX_RB_MODE_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
964 A3XX_RB_MODE_CONTROL_MARB_CACHE_SPLIT_MODE
|
965 A3XX_RB_MODE_CONTROL_MRT(MAX2(1, pfb
->nr_cbufs
) - 1));
968 /* before IB to rendering cmds: */
970 fd3_emit_tile_renderprep(struct fd_context
*ctx
, struct fd_tile
*tile
)
972 struct fd3_context
*fd3_ctx
= fd3_context(ctx
);
973 struct fd_ringbuffer
*ring
= ctx
->ring
;
974 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
975 struct pipe_framebuffer_state
*pfb
= &ctx
->framebuffer
;
977 uint32_t x1
= tile
->xoff
;
978 uint32_t y1
= tile
->yoff
;
979 uint32_t x2
= tile
->xoff
+ tile
->bin_w
- 1;
980 uint32_t y2
= tile
->yoff
+ tile
->bin_h
- 1;
984 OUT_PKT0(ring
, REG_A3XX_RB_DEPTH_INFO
, 2);
985 reg
= A3XX_RB_DEPTH_INFO_DEPTH_BASE(gmem
->zsbuf_base
[0]);
987 reg
|= A3XX_RB_DEPTH_INFO_DEPTH_FORMAT(fd_pipe2depth(pfb
->zsbuf
->format
));
991 struct fd_resource
*rsc
= fd_resource(pfb
->zsbuf
->texture
);
992 OUT_RING(ring
, A3XX_RB_DEPTH_PITCH(rsc
->cpp
* gmem
->bin_w
));
994 OUT_PKT0(ring
, REG_A3XX_RB_STENCIL_INFO
, 2);
995 OUT_RING(ring
, A3XX_RB_STENCIL_INFO_STENCIL_BASE(gmem
->zsbuf_base
[1]));
996 OUT_RING(ring
, A3XX_RB_STENCIL_PITCH(rsc
->stencil
->cpp
* gmem
->bin_w
));
999 OUT_RING(ring
, 0x00000000);
1002 if (use_hw_binning(ctx
)) {
1003 struct fd_vsc_pipe
*pipe
= &ctx
->pipe
[tile
->p
];
1005 assert(pipe
->w
* pipe
->h
);
1007 fd_event_write(ctx
, ring
, HLSQ_FLUSH
);
1010 OUT_PKT0(ring
, REG_A3XX_PC_VSTREAM_CONTROL
, 1);
1011 OUT_RING(ring
, A3XX_PC_VSTREAM_CONTROL_SIZE(pipe
->w
* pipe
->h
) |
1012 A3XX_PC_VSTREAM_CONTROL_N(tile
->n
));
1015 OUT_PKT3(ring
, CP_SET_BIN_DATA
, 2);
1016 OUT_RELOC(ring
, pipe
->bo
, 0, 0, 0); /* BIN_DATA_ADDR <- VSC_PIPE[p].DATA_ADDRESS */
1017 OUT_RELOC(ring
, fd3_ctx
->vsc_size_mem
, /* BIN_SIZE_ADDR <- VSC_SIZE_ADDRESS + (p * 4) */
1018 (tile
->p
* 4), 0, 0);
1020 OUT_PKT0(ring
, REG_A3XX_PC_VSTREAM_CONTROL
, 1);
1021 OUT_RING(ring
, 0x00000000);
1024 OUT_PKT3(ring
, CP_SET_BIN
, 3);
1025 OUT_RING(ring
, 0x00000000);
1026 OUT_RING(ring
, CP_SET_BIN_1_X1(x1
) | CP_SET_BIN_1_Y1(y1
));
1027 OUT_RING(ring
, CP_SET_BIN_2_X2(x2
) | CP_SET_BIN_2_Y2(y2
));
1029 emit_mrt(ring
, pfb
->nr_cbufs
, pfb
->cbufs
, gmem
->cbuf_base
, gmem
->bin_w
, true);
1031 /* setup scissor/offset for current tile: */
1032 OUT_PKT0(ring
, REG_A3XX_RB_WINDOW_OFFSET
, 1);
1033 OUT_RING(ring
, A3XX_RB_WINDOW_OFFSET_X(tile
->xoff
) |
1034 A3XX_RB_WINDOW_OFFSET_Y(tile
->yoff
));
1036 OUT_PKT0(ring
, REG_A3XX_GRAS_SC_SCREEN_SCISSOR_TL
, 2);
1037 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_TL_X(x1
) |
1038 A3XX_GRAS_SC_SCREEN_SCISSOR_TL_Y(y1
));
1039 OUT_RING(ring
, A3XX_GRAS_SC_SCREEN_SCISSOR_BR_X(x2
) |
1040 A3XX_GRAS_SC_SCREEN_SCISSOR_BR_Y(y2
));
1044 fd3_gmem_init(struct pipe_context
*pctx
)
1046 struct fd_context
*ctx
= fd_context(pctx
);
1048 ctx
->emit_sysmem_prep
= fd3_emit_sysmem_prep
;
1049 ctx
->emit_tile_init
= fd3_emit_tile_init
;
1050 ctx
->emit_tile_prep
= fd3_emit_tile_prep
;
1051 ctx
->emit_tile_mem2gmem
= fd3_emit_tile_mem2gmem
;
1052 ctx
->emit_tile_renderprep
= fd3_emit_tile_renderprep
;
1053 ctx
->emit_tile_gmem2mem
= fd3_emit_tile_gmem2mem
;