1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
4 * Copyright (C) 2014 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 "fd4_context.h"
43 #include "fd4_program.h"
44 #include "fd4_format.h"
47 static const struct ir3_shader_key key
= {
48 // XXX should set this based on render target format! We don't
49 // want half_precision if float32 render target!!!
50 .half_precision
= true,
54 emit_mrt(struct fd_ringbuffer
*ring
, unsigned nr_bufs
,
55 struct pipe_surface
**bufs
, uint32_t *bases
, uint32_t bin_w
)
57 enum a4xx_tile_mode tile_mode
;
63 tile_mode
= TILE4_LINEAR
;
66 for (i
= 0; i
< 8; i
++) {
67 enum a4xx_color_fmt format
= 0;
68 enum a3xx_color_swap swap
= WZYX
;
69 struct fd_resource
*rsc
= NULL
;
70 struct fd_resource_slice
*slice
= NULL
;
75 if ((i
< nr_bufs
) && bufs
[i
]) {
76 struct pipe_surface
*psurf
= bufs
[i
];
78 rsc
= fd_resource(psurf
->texture
);
79 slice
= fd_resource_slice(rsc
, psurf
->u
.tex
.level
);
80 format
= fd4_pipe2color(psurf
->format
);
81 swap
= fd4_pipe2swap(psurf
->format
);
83 debug_assert(psurf
->u
.tex
.first_layer
== psurf
->u
.tex
.last_layer
);
85 offset
= fd_resource_offset(rsc
, psurf
->u
.tex
.level
,
86 psurf
->u
.tex
.first_layer
);
89 stride
= bin_w
* rsc
->cpp
;
95 stride
= slice
->pitch
* rsc
->cpp
;
99 OUT_PKT0(ring
, REG_A4XX_RB_MRT_BUF_INFO(i
), 3);
100 OUT_RING(ring
, A4XX_RB_MRT_BUF_INFO_COLOR_FORMAT(format
) |
101 A4XX_RB_MRT_BUF_INFO_COLOR_TILE_MODE(tile_mode
) |
102 A4XX_RB_MRT_BUF_INFO_COLOR_BUF_PITCH(stride
) |
103 A4XX_RB_MRT_BUF_INFO_COLOR_SWAP(swap
));
104 if (bin_w
|| (i
>= nr_bufs
)) {
105 OUT_RING(ring
, base
);
106 OUT_RING(ring
, A4XX_RB_MRT_CONTROL3_STRIDE(stride
));
108 OUT_RELOCW(ring
, rsc
->bo
, offset
, 0, 0);
109 /* RB_MRT[i].CONTROL3.STRIDE not emitted by c2d..
110 * not sure if we need to skip it for bypass or
113 OUT_RING(ring
, A4XX_RB_MRT_CONTROL3_STRIDE(0));
119 depth_base(struct fd_context
*ctx
)
121 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
122 struct pipe_framebuffer_state
*pfb
= &ctx
->framebuffer
;
125 struct fd_resource
*rsc
=
126 fd_resource(pfb
->cbufs
[0]->texture
);
129 return align(gmem
->bin_w
* gmem
->bin_h
* cpp
, 0x4000);
132 /* transfer from gmem to system memory (ie. normal RAM) */
135 emit_gmem2mem_surf(struct fd_context
*ctx
,
136 uint32_t base
, struct pipe_surface
*psurf
)
138 struct fd_ringbuffer
*ring
= ctx
->ring
;
139 struct fd_resource
*rsc
= fd_resource(psurf
->texture
);
140 struct fd_resource_slice
*slice
= &rsc
->slices
[psurf
->u
.tex
.level
];
141 uint32_t offset
= fd_resource_offset(rsc
, psurf
->u
.tex
.level
,
142 psurf
->u
.tex
.first_layer
);
144 debug_assert(psurf
->u
.tex
.first_layer
== psurf
->u
.tex
.last_layer
);
146 OUT_PKT0(ring
, REG_A4XX_RB_COPY_CONTROL
, 4);
147 OUT_RING(ring
, A4XX_RB_COPY_CONTROL_MSAA_RESOLVE(MSAA_ONE
) |
148 A4XX_RB_COPY_CONTROL_MODE(RB_COPY_RESOLVE
) |
149 A4XX_RB_COPY_CONTROL_GMEM_BASE(base
));
150 OUT_RELOCW(ring
, rsc
->bo
, offset
, 0, 0); /* RB_COPY_DEST_BASE */
151 OUT_RING(ring
, A4XX_RB_COPY_DEST_PITCH_PITCH(slice
->pitch
* rsc
->cpp
));
152 OUT_RING(ring
, A4XX_RB_COPY_DEST_INFO_TILE(TILE4_LINEAR
) |
153 A4XX_RB_COPY_DEST_INFO_FORMAT(fd4_pipe2color(psurf
->format
)) |
154 A4XX_RB_COPY_DEST_INFO_COMPONENT_ENABLE(0xf) |
155 A4XX_RB_COPY_DEST_INFO_ENDIAN(ENDIAN_NONE
) |
156 A4XX_RB_COPY_DEST_INFO_SWAP(fd4_pipe2swap(psurf
->format
)));
158 fd4_draw(ctx
, ring
, DI_PT_RECTLIST
, IGNORE_VISIBILITY
,
159 DI_SRC_SEL_AUTO_INDEX
, 2, INDEX_SIZE_IGN
, 0, 0, NULL
);
163 fd4_emit_tile_gmem2mem(struct fd_context
*ctx
, struct fd_tile
*tile
)
165 struct fd4_context
*fd4_ctx
= fd4_context(ctx
);
166 struct fd_ringbuffer
*ring
= ctx
->ring
;
167 struct pipe_framebuffer_state
*pfb
= &ctx
->framebuffer
;
168 struct fd4_emit emit
= {
169 .vtx
= &fd4_ctx
->solid_vbuf_state
,
170 .prog
= &ctx
->solid_prog
,
172 .format
= fd4_emit_format(pfb
->cbufs
[0]),
175 OUT_PKT0(ring
, REG_A4XX_RB_DEPTH_CONTROL
, 1);
176 OUT_RING(ring
, A4XX_RB_DEPTH_CONTROL_ZFUNC(FUNC_NEVER
));
178 OUT_PKT0(ring
, REG_A4XX_RB_STENCIL_CONTROL
, 2);
179 OUT_RING(ring
, A4XX_RB_STENCIL_CONTROL_FUNC(FUNC_NEVER
) |
180 A4XX_RB_STENCIL_CONTROL_FAIL(STENCIL_KEEP
) |
181 A4XX_RB_STENCIL_CONTROL_ZPASS(STENCIL_KEEP
) |
182 A4XX_RB_STENCIL_CONTROL_ZFAIL(STENCIL_KEEP
) |
183 A4XX_RB_STENCIL_CONTROL_FUNC_BF(FUNC_NEVER
) |
184 A4XX_RB_STENCIL_CONTROL_FAIL_BF(STENCIL_KEEP
) |
185 A4XX_RB_STENCIL_CONTROL_ZPASS_BF(STENCIL_KEEP
) |
186 A4XX_RB_STENCIL_CONTROL_ZFAIL_BF(STENCIL_KEEP
));
187 OUT_RING(ring
, 0x00000000); /* RB_STENCIL_CONTROL2 */
189 OUT_PKT0(ring
, REG_A4XX_RB_STENCILREFMASK
, 2);
190 OUT_RING(ring
, 0xff000000 |
191 A4XX_RB_STENCILREFMASK_STENCILREF(0) |
192 A4XX_RB_STENCILREFMASK_STENCILMASK(0) |
193 A4XX_RB_STENCILREFMASK_STENCILWRITEMASK(0xff));
194 OUT_RING(ring
, 0xff000000 |
195 A4XX_RB_STENCILREFMASK_BF_STENCILREF(0) |
196 A4XX_RB_STENCILREFMASK_BF_STENCILMASK(0) |
197 A4XX_RB_STENCILREFMASK_BF_STENCILWRITEMASK(0xff));
199 OUT_PKT0(ring
, REG_A4XX_GRAS_SU_MODE_CONTROL
, 1);
200 OUT_RING(ring
, A4XX_GRAS_SU_MODE_CONTROL_LINEHALFWIDTH(0));
204 OUT_PKT0(ring
, REG_A4XX_GRAS_CL_CLIP_CNTL
, 1);
205 OUT_RING(ring
, 0x80000); /* GRAS_CL_CLIP_CNTL */
207 OUT_PKT0(ring
, REG_A4XX_GRAS_CL_VPORT_XOFFSET_0
, 6);
208 OUT_RING(ring
, A4XX_GRAS_CL_VPORT_XOFFSET_0((float)pfb
->width
/2.0));
209 OUT_RING(ring
, A4XX_GRAS_CL_VPORT_XSCALE_0((float)pfb
->width
/2.0));
210 OUT_RING(ring
, A4XX_GRAS_CL_VPORT_YOFFSET_0((float)pfb
->height
/2.0));
211 OUT_RING(ring
, A4XX_GRAS_CL_VPORT_YSCALE_0(-(float)pfb
->height
/2.0));
212 OUT_RING(ring
, A4XX_GRAS_CL_VPORT_ZOFFSET_0(0.0));
213 OUT_RING(ring
, A4XX_GRAS_CL_VPORT_ZSCALE_0(1.0));
215 OUT_PKT0(ring
, REG_A4XX_RB_RENDER_CONTROL
, 1);
216 OUT_RING(ring
, A4XX_RB_RENDER_CONTROL_DISABLE_COLOR_PIPE
|
219 OUT_PKT0(ring
, REG_A4XX_GRAS_SC_CONTROL
, 1);
220 OUT_RING(ring
, A4XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RESOLVE_PASS
) |
221 A4XX_GRAS_SC_CONTROL_MSAA_DISABLE
|
222 A4XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
223 A4XX_GRAS_SC_CONTROL_RASTER_MODE(1));
225 OUT_PKT0(ring
, REG_A4XX_PC_PRIM_VTX_CNTL
, 1);
226 OUT_RING(ring
, A4XX_PC_PRIM_VTX_CNTL_PROVOKING_VTX_LAST
);
228 OUT_PKT0(ring
, REG_A4XX_GRAS_ALPHA_CONTROL
, 1);
229 OUT_RING(ring
, 0x00000002);
231 OUT_PKT0(ring
, REG_A4XX_GRAS_SC_WINDOW_SCISSOR_BR
, 2);
232 OUT_RING(ring
, A4XX_GRAS_SC_WINDOW_SCISSOR_BR_X(pfb
->width
- 1) |
233 A4XX_GRAS_SC_WINDOW_SCISSOR_BR_Y(pfb
->height
- 1));
234 OUT_RING(ring
, A4XX_GRAS_SC_WINDOW_SCISSOR_TL_X(0) |
235 A4XX_GRAS_SC_WINDOW_SCISSOR_TL_Y(0));
237 OUT_PKT0(ring
, REG_A4XX_VFD_INDEX_OFFSET
, 2);
238 OUT_RING(ring
, 0); /* VFD_INDEX_OFFSET */
239 OUT_RING(ring
, 0); /* ??? UNKNOWN_2209 */
241 fd4_program_emit(ring
, &emit
);
242 fd4_emit_vertex_bufs(ring
, &emit
);
244 if (ctx
->resolve
& (FD_BUFFER_DEPTH
| FD_BUFFER_STENCIL
)) {
245 uint32_t base
= depth_base(ctx
);
246 emit_gmem2mem_surf(ctx
, base
, pfb
->zsbuf
);
249 if (ctx
->resolve
& FD_BUFFER_COLOR
) {
250 emit_gmem2mem_surf(ctx
, 0, pfb
->cbufs
[0]);
253 OUT_PKT0(ring
, REG_A4XX_GRAS_SC_CONTROL
, 1);
254 OUT_RING(ring
, A4XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
255 A4XX_GRAS_SC_CONTROL_MSAA_DISABLE
|
256 A4XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
257 A4XX_GRAS_SC_CONTROL_RASTER_MODE(0));
260 /* transfer from system memory to gmem */
263 emit_mem2gmem_surf(struct fd_context
*ctx
, uint32_t base
,
264 struct pipe_surface
*psurf
, uint32_t bin_w
)
266 struct fd_ringbuffer
*ring
= ctx
->ring
;
268 emit_mrt(ring
, 1, &psurf
, &base
, bin_w
);
270 fd4_emit_gmem_restore_tex(ring
, psurf
);
272 fd4_draw(ctx
, ring
, DI_PT_RECTLIST
, IGNORE_VISIBILITY
,
273 DI_SRC_SEL_AUTO_INDEX
, 2, INDEX_SIZE_IGN
, 0, 0, NULL
);
277 fd4_emit_tile_mem2gmem(struct fd_context
*ctx
, struct fd_tile
*tile
)
279 struct fd4_context
*fd4_ctx
= fd4_context(ctx
);
280 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
281 struct fd_ringbuffer
*ring
= ctx
->ring
;
282 struct pipe_framebuffer_state
*pfb
= &ctx
->framebuffer
;
283 struct fd4_emit emit
= {
284 .vtx
= &fd4_ctx
->blit_vbuf_state
,
285 .prog
= &ctx
->blit_prog
,
287 .format
= fd4_emit_format(pfb
->cbufs
[0]),
289 float x0
, y0
, x1
, y1
;
290 unsigned bin_w
= tile
->bin_w
;
291 unsigned bin_h
= tile
->bin_h
;
294 /* write texture coordinates to vertexbuf: */
295 x0
= ((float)tile
->xoff
) / ((float)pfb
->width
);
296 x1
= ((float)tile
->xoff
+ bin_w
) / ((float)pfb
->width
);
297 y0
= ((float)tile
->yoff
) / ((float)pfb
->height
);
298 y1
= ((float)tile
->yoff
+ bin_h
) / ((float)pfb
->height
);
300 OUT_PKT3(ring
, CP_MEM_WRITE
, 5);
301 OUT_RELOCW(ring
, fd_resource(fd4_ctx
->blit_texcoord_vbuf
)->bo
, 0, 0, 0);
302 OUT_RING(ring
, fui(x0
));
303 OUT_RING(ring
, fui(y0
));
304 OUT_RING(ring
, fui(x1
));
305 OUT_RING(ring
, fui(y1
));
307 for (i
= 0; i
< 8; i
++) {
308 OUT_PKT0(ring
, REG_A4XX_RB_MRT_CONTROL(i
), 1);
309 OUT_RING(ring
, A4XX_RB_MRT_CONTROL_FASTCLEAR
|
310 A4XX_RB_MRT_CONTROL_B11
|
311 A4XX_RB_MRT_CONTROL_COMPONENT_ENABLE(0xf));
313 OUT_PKT0(ring
, REG_A4XX_RB_MRT_BLEND_CONTROL(i
), 1);
314 OUT_RING(ring
, A4XX_RB_MRT_BLEND_CONTROL_RGB_SRC_FACTOR(FACTOR_ONE
) |
315 A4XX_RB_MRT_BLEND_CONTROL_RGB_BLEND_OPCODE(BLEND_DST_PLUS_SRC
) |
316 A4XX_RB_MRT_BLEND_CONTROL_RGB_DEST_FACTOR(FACTOR_ZERO
) |
317 A4XX_RB_MRT_BLEND_CONTROL_ALPHA_SRC_FACTOR(FACTOR_ONE
) |
318 A4XX_RB_MRT_BLEND_CONTROL_ALPHA_BLEND_OPCODE(BLEND_DST_PLUS_SRC
) |
319 A4XX_RB_MRT_BLEND_CONTROL_ALPHA_DEST_FACTOR(FACTOR_ZERO
));
322 OUT_PKT0(ring
, REG_A4XX_RB_RENDER_CONTROL
, 1);
323 OUT_RING(ring
, 0x8); /* XXX RB_RENDER_CONTROL */
325 OUT_PKT0(ring
, REG_A4XX_RB_DEPTH_CONTROL
, 1);
326 OUT_RING(ring
, A4XX_RB_DEPTH_CONTROL_ZFUNC(FUNC_LESS
));
328 OUT_PKT0(ring
, REG_A4XX_GRAS_CL_CLIP_CNTL
, 1);
329 OUT_RING(ring
, 0x280000); /* XXX GRAS_CL_CLIP_CNTL */
331 OUT_PKT0(ring
, REG_A4XX_GRAS_SU_MODE_CONTROL
, 1);
332 OUT_RING(ring
, A4XX_GRAS_SU_MODE_CONTROL_LINEHALFWIDTH(0) |
333 A4XX_GRAS_SU_MODE_CONTROL_RENDERING_PASS
);
335 OUT_PKT0(ring
, REG_A4XX_GRAS_CL_VPORT_XOFFSET_0
, 6);
336 OUT_RING(ring
, A4XX_GRAS_CL_VPORT_XOFFSET_0((float)bin_w
/2.0));
337 OUT_RING(ring
, A4XX_GRAS_CL_VPORT_XSCALE_0((float)bin_w
/2.0));
338 OUT_RING(ring
, A4XX_GRAS_CL_VPORT_YOFFSET_0((float)bin_h
/2.0));
339 OUT_RING(ring
, A4XX_GRAS_CL_VPORT_YSCALE_0(-(float)bin_h
/2.0));
340 OUT_RING(ring
, A4XX_GRAS_CL_VPORT_ZOFFSET_0(0.0));
341 OUT_RING(ring
, A4XX_GRAS_CL_VPORT_ZSCALE_0(1.0));
343 OUT_PKT0(ring
, REG_A4XX_GRAS_SC_WINDOW_SCISSOR_BR
, 2);
344 OUT_RING(ring
, A4XX_GRAS_SC_WINDOW_SCISSOR_BR_X(bin_w
- 1) |
345 A4XX_GRAS_SC_WINDOW_SCISSOR_BR_Y(bin_h
- 1));
346 OUT_RING(ring
, A4XX_GRAS_SC_WINDOW_SCISSOR_TL_X(0) |
347 A4XX_GRAS_SC_WINDOW_SCISSOR_TL_Y(0));
349 OUT_PKT0(ring
, REG_A4XX_GRAS_SC_SCREEN_SCISSOR_TL
, 2);
350 OUT_RING(ring
, A4XX_GRAS_SC_SCREEN_SCISSOR_TL_X(0) |
351 A4XX_GRAS_SC_SCREEN_SCISSOR_TL_Y(0));
352 OUT_RING(ring
, A4XX_GRAS_SC_SCREEN_SCISSOR_BR_X(bin_w
- 1) |
353 A4XX_GRAS_SC_SCREEN_SCISSOR_BR_Y(bin_h
- 1));
355 OUT_PKT0(ring
, REG_A4XX_RB_MODE_CONTROL
, 1);
356 OUT_RING(ring
, A4XX_RB_MODE_CONTROL_WIDTH(gmem
->bin_w
) |
357 A4XX_RB_MODE_CONTROL_HEIGHT(gmem
->bin_h
));
359 OUT_PKT0(ring
, REG_A4XX_RB_STENCIL_CONTROL
, 2);
360 OUT_RING(ring
, A4XX_RB_STENCIL_CONTROL_FUNC(FUNC_ALWAYS
) |
361 A4XX_RB_STENCIL_CONTROL_FAIL(STENCIL_KEEP
) |
362 A4XX_RB_STENCIL_CONTROL_ZPASS(STENCIL_KEEP
) |
363 A4XX_RB_STENCIL_CONTROL_ZFAIL(STENCIL_KEEP
) |
364 A4XX_RB_STENCIL_CONTROL_FUNC_BF(FUNC_ALWAYS
) |
365 A4XX_RB_STENCIL_CONTROL_FAIL_BF(STENCIL_KEEP
) |
366 A4XX_RB_STENCIL_CONTROL_ZPASS_BF(STENCIL_KEEP
) |
367 A4XX_RB_STENCIL_CONTROL_ZFAIL_BF(STENCIL_KEEP
));
368 OUT_RING(ring
, 0x00000000); /* RB_STENCIL_CONTROL2 */
370 OUT_PKT0(ring
, REG_A4XX_GRAS_SC_CONTROL
, 1);
371 OUT_RING(ring
, A4XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
372 A4XX_GRAS_SC_CONTROL_MSAA_DISABLE
|
373 A4XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
374 A4XX_GRAS_SC_CONTROL_RASTER_MODE(1));
376 OUT_PKT0(ring
, REG_A4XX_PC_PRIM_VTX_CNTL
, 1);
377 OUT_RING(ring
, A4XX_PC_PRIM_VTX_CNTL_PROVOKING_VTX_LAST
|
378 A4XX_PC_PRIM_VTX_CNTL_VAROUT
);
380 OUT_PKT0(ring
, REG_A4XX_VFD_INDEX_OFFSET
, 2);
381 OUT_RING(ring
, 0); /* VFD_INDEX_OFFSET */
382 OUT_RING(ring
, 0); /* ??? UNKNOWN_2209 */
384 fd4_program_emit(ring
, &emit
);
385 fd4_emit_vertex_bufs(ring
, &emit
);
387 /* for gmem pitch/base calculations, we need to use the non-
388 * truncated tile sizes:
393 if (fd_gmem_needs_restore(ctx
, tile
, FD_BUFFER_DEPTH
| FD_BUFFER_STENCIL
))
394 emit_mem2gmem_surf(ctx
, depth_base(ctx
), pfb
->zsbuf
, bin_w
);
396 if (fd_gmem_needs_restore(ctx
, tile
, FD_BUFFER_COLOR
))
397 emit_mem2gmem_surf(ctx
, 0, pfb
->cbufs
[0], bin_w
);
399 OUT_PKT0(ring
, REG_A4XX_GRAS_SC_CONTROL
, 1);
400 OUT_RING(ring
, A4XX_GRAS_SC_CONTROL_RENDER_MODE(RB_RENDERING_PASS
) |
401 A4XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE
) |
402 A4XX_GRAS_SC_CONTROL_RASTER_MODE(0));
404 OUT_PKT0(ring
, REG_A4XX_RB_MODE_CONTROL
, 1);
405 OUT_RING(ring
, A4XX_RB_MODE_CONTROL_WIDTH(gmem
->bin_w
) |
406 A4XX_RB_MODE_CONTROL_HEIGHT(gmem
->bin_h
) |
407 0x00010000); /* XXX */
411 patch_draws(struct fd_context
*ctx
, enum pc_di_vis_cull_mode vismode
)
414 for (i
= 0; i
< fd_patch_num_elements(&ctx
->draw_patches
); i
++) {
415 struct fd_cs_patch
*patch
= fd_patch_element(&ctx
->draw_patches
, i
);
416 *patch
->cs
= patch
->val
| DRAW4(0, 0, 0, vismode
);
418 util_dynarray_resize(&ctx
->draw_patches
, 0);
422 patch_rbrc(struct fd_context
*ctx
, uint32_t val
)
424 struct fd4_context
*fd4_ctx
= fd4_context(ctx
);
426 for (i
= 0; i
< fd_patch_num_elements(&fd4_ctx
->rbrc_patches
); i
++) {
427 struct fd_cs_patch
*patch
= fd_patch_element(&fd4_ctx
->rbrc_patches
, i
);
428 *patch
->cs
= patch
->val
| val
;
430 util_dynarray_resize(&fd4_ctx
->rbrc_patches
, 0);
433 /* for rendering directly to system memory: */
435 fd4_emit_sysmem_prep(struct fd_context
*ctx
)
437 struct pipe_framebuffer_state
*pfb
= &ctx
->framebuffer
;
438 struct fd_ringbuffer
*ring
= ctx
->ring
;
442 struct pipe_surface
*psurf
= pfb
->cbufs
[0];
443 unsigned lvl
= psurf
->u
.tex
.level
;
444 pitch
= fd_resource(psurf
->texture
)->slices
[lvl
].pitch
;
447 fd4_emit_restore(ctx
);
449 OUT_PKT0(ring
, REG_A4XX_RB_FRAME_BUFFER_DIMENSION
, 1);
450 OUT_RING(ring
, A4XX_RB_FRAME_BUFFER_DIMENSION_WIDTH(pfb
->width
) |
451 A4XX_RB_FRAME_BUFFER_DIMENSION_HEIGHT(pfb
->height
));
453 emit_mrt(ring
, pfb
->nr_cbufs
, pfb
->cbufs
, NULL
, 0);
455 /* setup scissor/offset for current tile: */
456 OUT_PKT0(ring
, REG_A4XX_RB_BIN_OFFSET
, 1);
457 OUT_RING(ring
, A4XX_RB_BIN_OFFSET_X(0) |
458 A4XX_RB_BIN_OFFSET_Y(0));
460 OUT_PKT0(ring
, REG_A4XX_GRAS_SC_SCREEN_SCISSOR_TL
, 2);
461 OUT_RING(ring
, A4XX_GRAS_SC_SCREEN_SCISSOR_TL_X(0) |
462 A4XX_GRAS_SC_SCREEN_SCISSOR_TL_Y(0));
463 OUT_RING(ring
, A4XX_GRAS_SC_SCREEN_SCISSOR_BR_X(pfb
->width
- 1) |
464 A4XX_GRAS_SC_SCREEN_SCISSOR_BR_Y(pfb
->height
- 1));
466 OUT_PKT0(ring
, REG_A4XX_RB_MODE_CONTROL
, 1);
467 OUT_RING(ring
, A4XX_RB_MODE_CONTROL_WIDTH(0) |
468 A4XX_RB_MODE_CONTROL_HEIGHT(0) |
469 0x00c00000); /* XXX */
471 patch_draws(ctx
, IGNORE_VISIBILITY
);
472 patch_rbrc(ctx
, 0); // XXX
476 update_vsc_pipe(struct fd_context
*ctx
)
478 struct fd4_context
*fd4_ctx
= fd4_context(ctx
);
479 struct fd_ringbuffer
*ring
= ctx
->ring
;
482 OUT_PKT0(ring
, REG_A4XX_VSC_SIZE_ADDRESS
, 1);
483 OUT_RELOCW(ring
, fd4_ctx
->vsc_size_mem
, 0, 0, 0); /* VSC_SIZE_ADDRESS */
485 OUT_PKT0(ring
, REG_A4XX_VSC_PIPE_CONFIG_REG(0), 8);
486 for (i
= 0; i
< 8; i
++) {
487 struct fd_vsc_pipe
*pipe
= &ctx
->pipe
[i
];
488 OUT_RING(ring
, A4XX_VSC_PIPE_CONFIG_REG_X(pipe
->x
) |
489 A4XX_VSC_PIPE_CONFIG_REG_Y(pipe
->y
) |
490 A4XX_VSC_PIPE_CONFIG_REG_W(pipe
->w
) |
491 A4XX_VSC_PIPE_CONFIG_REG_H(pipe
->h
));
494 OUT_PKT0(ring
, REG_A4XX_VSC_PIPE_DATA_ADDRESS_REG(0), 8);
495 for (i
= 0; i
< 8; i
++) {
496 struct fd_vsc_pipe
*pipe
= &ctx
->pipe
[i
];
498 pipe
->bo
= fd_bo_new(ctx
->dev
, 0x40000,
499 DRM_FREEDRENO_GEM_TYPE_KMEM
);
501 OUT_RELOCW(ring
, pipe
->bo
, 0, 0, 0); /* VSC_PIPE_DATA_ADDRESS[i] */
504 OUT_PKT0(ring
, REG_A4XX_VSC_PIPE_DATA_LENGTH_REG(0), 8);
505 for (i
= 0; i
< 8; i
++) {
506 struct fd_vsc_pipe
*pipe
= &ctx
->pipe
[i
];
507 OUT_RING(ring
, fd_bo_size(pipe
->bo
) - 32); /* VSC_PIPE_DATA_LENGTH[i] */
511 /* before first tile */
513 fd4_emit_tile_init(struct fd_context
*ctx
)
515 struct fd_ringbuffer
*ring
= ctx
->ring
;
516 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
517 uint32_t rb_render_control
;
519 fd4_emit_restore(ctx
);
521 OUT_PKT0(ring
, REG_A4XX_VSC_BIN_SIZE
, 1);
522 OUT_RING(ring
, A4XX_VSC_BIN_SIZE_WIDTH(gmem
->bin_w
) |
523 A4XX_VSC_BIN_SIZE_HEIGHT(gmem
->bin_h
));
525 OUT_PKT0(ring
, REG_A4XX_RB_MODE_CONTROL
, 1);
526 OUT_RING(ring
, A4XX_RB_MODE_CONTROL_WIDTH(gmem
->bin_w
) |
527 A4XX_RB_MODE_CONTROL_HEIGHT(gmem
->bin_h
) |
528 0x00010000); /* XXX */
530 update_vsc_pipe(ctx
);
531 patch_draws(ctx
, IGNORE_VISIBILITY
);
533 rb_render_control
= 0; // XXX or BINNING_PASS.. but maybe we can emit only from gmem
534 patch_rbrc(ctx
, rb_render_control
);
537 /* before mem2gmem */
539 fd4_emit_tile_prep(struct fd_context
*ctx
, struct fd_tile
*tile
)
541 struct fd_ringbuffer
*ring
= ctx
->ring
;
542 struct pipe_framebuffer_state
*pfb
= &ctx
->framebuffer
;
543 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
546 OUT_PKT0(ring
, REG_A4XX_RB_DEPTH_INFO
, 3);
547 reg
= A4XX_RB_DEPTH_INFO_DEPTH_BASE(depth_base(ctx
));
549 reg
|= A4XX_RB_DEPTH_INFO_DEPTH_FORMAT(fd4_pipe2depth(pfb
->zsbuf
->format
));
553 uint32_t cpp
= util_format_get_blocksize(pfb
->zsbuf
->format
);
554 OUT_RING(ring
, A4XX_RB_DEPTH_PITCH(cpp
* gmem
->bin_w
));
555 OUT_RING(ring
, A4XX_RB_DEPTH_PITCH2(cpp
* gmem
->bin_w
));
557 OUT_RING(ring
, 0x00000000);
558 OUT_RING(ring
, 0x00000000);
561 OUT_PKT0(ring
, REG_A4XX_GRAS_DEPTH_CONTROL
, 1);
563 OUT_RING(ring
, A4XX_GRAS_DEPTH_CONTROL_FORMAT(
564 fd4_pipe2depth(pfb
->zsbuf
->format
)));
566 OUT_RING(ring
, A4XX_GRAS_DEPTH_CONTROL_FORMAT(DEPTH4_NONE
));
569 if (ctx
->needs_rb_fbd
) {
571 OUT_PKT0(ring
, REG_A4XX_RB_FRAME_BUFFER_DIMENSION
, 1);
572 OUT_RING(ring
, A4XX_RB_FRAME_BUFFER_DIMENSION_WIDTH(pfb
->width
) |
573 A4XX_RB_FRAME_BUFFER_DIMENSION_HEIGHT(pfb
->height
));
574 ctx
->needs_rb_fbd
= false;
578 /* before IB to rendering cmds: */
580 fd4_emit_tile_renderprep(struct fd_context
*ctx
, struct fd_tile
*tile
)
582 struct fd_ringbuffer
*ring
= ctx
->ring
;
583 struct fd_gmem_stateobj
*gmem
= &ctx
->gmem
;
584 struct pipe_framebuffer_state
*pfb
= &ctx
->framebuffer
;
586 uint32_t x1
= tile
->xoff
;
587 uint32_t y1
= tile
->yoff
;
588 uint32_t x2
= tile
->xoff
+ tile
->bin_w
- 1;
589 uint32_t y2
= tile
->yoff
+ tile
->bin_h
- 1;
591 OUT_PKT3(ring
, CP_SET_BIN
, 3);
592 OUT_RING(ring
, 0x00000000);
593 OUT_RING(ring
, CP_SET_BIN_1_X1(x1
) | CP_SET_BIN_1_Y1(y1
));
594 OUT_RING(ring
, CP_SET_BIN_2_X2(x2
) | CP_SET_BIN_2_Y2(y2
));
596 emit_mrt(ring
, pfb
->nr_cbufs
, pfb
->cbufs
, NULL
, gmem
->bin_w
);
598 /* setup scissor/offset for current tile: */
599 OUT_PKT0(ring
, REG_A4XX_RB_BIN_OFFSET
, 1);
600 OUT_RING(ring
, A4XX_RB_BIN_OFFSET_X(tile
->xoff
) |
601 A4XX_RB_BIN_OFFSET_Y(tile
->yoff
));
603 OUT_PKT0(ring
, REG_A4XX_GRAS_SC_SCREEN_SCISSOR_TL
, 2);
604 OUT_RING(ring
, A4XX_GRAS_SC_SCREEN_SCISSOR_TL_X(x1
) |
605 A4XX_GRAS_SC_SCREEN_SCISSOR_TL_Y(y1
));
606 OUT_RING(ring
, A4XX_GRAS_SC_SCREEN_SCISSOR_BR_X(x2
) |
607 A4XX_GRAS_SC_SCREEN_SCISSOR_BR_Y(y2
));
611 fd4_gmem_init(struct pipe_context
*pctx
)
613 struct fd_context
*ctx
= fd_context(pctx
);
615 ctx
->emit_sysmem_prep
= fd4_emit_sysmem_prep
;
616 ctx
->emit_tile_init
= fd4_emit_tile_init
;
617 ctx
->emit_tile_prep
= fd4_emit_tile_prep
;
618 ctx
->emit_tile_mem2gmem
= fd4_emit_tile_mem2gmem
;
619 ctx
->emit_tile_renderprep
= fd4_emit_tile_renderprep
;
620 ctx
->emit_tile_gmem2mem
= fd4_emit_tile_gmem2mem
;