2 * Copyright (C) 2016 Rob Clark <robclark@freedesktop.org>
3 * Copyright © 2018 Google, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Rob Clark <robclark@freedesktop.org>
28 #include "pipe/p_state.h"
29 #include "util/u_string.h"
30 #include "util/u_memory.h"
31 #include "util/u_helpers.h"
32 #include "util/format/u_format.h"
33 #include "util/u_viewport.h"
35 #include "freedreno_log.h"
36 #include "freedreno_resource.h"
37 #include "freedreno_query_hw.h"
40 #include "fd6_blend.h"
41 #include "fd6_const.h"
42 #include "fd6_context.h"
43 #include "fd6_image.h"
45 #include "fd6_program.h"
46 #include "fd6_rasterizer.h"
47 #include "fd6_texture.h"
48 #include "fd6_format.h"
51 /* Border color layout is diff from a4xx/a5xx.. if it turns out to be
52 * the same as a6xx then move this somewhere common ;-)
54 * Entry layout looks like (total size, 0x60 bytes):
57 struct PACKED bcolor_entry
{
69 uint32_t z24
; /* also s8? */
70 uint16_t srgb
[4]; /* appears to duplicate fp16[], but clamped, used for srgb */
74 #define FD6_BORDER_COLOR_SIZE sizeof(struct bcolor_entry)
75 #define FD6_BORDER_COLOR_UPLOAD_SIZE (2 * PIPE_MAX_SAMPLERS * FD6_BORDER_COLOR_SIZE)
78 setup_border_colors(struct fd_texture_stateobj
*tex
, struct bcolor_entry
*entries
)
81 STATIC_ASSERT(sizeof(struct bcolor_entry
) == FD6_BORDER_COLOR_SIZE
);
83 for (i
= 0; i
< tex
->num_samplers
; i
++) {
84 struct bcolor_entry
*e
= &entries
[i
];
85 struct pipe_sampler_state
*sampler
= tex
->samplers
[i
];
86 union pipe_color_union
*bc
;
91 bc
= &sampler
->border_color
;
96 * The border colors need to be swizzled in a particular
97 * format-dependent order. Even though samplers don't know about
98 * formats, we can assume that with a GL state tracker, there's a
99 * 1:1 correspondence between sampler and texture. Take advantage
102 if ((i
>= tex
->num_textures
) || !tex
->textures
[i
])
105 struct pipe_sampler_view
*view
= tex
->textures
[i
];
106 enum pipe_format format
= view
->format
;
107 const struct util_format_description
*desc
=
108 util_format_description(format
);
116 unsigned char swiz
[4];
118 fd6_tex_swiz(format
, swiz
,
119 view
->swizzle_r
, view
->swizzle_g
,
120 view
->swizzle_b
, view
->swizzle_a
);
122 for (j
= 0; j
< 4; j
++) {
127 * HACK: for PIPE_FORMAT_X24S8_UINT we end up w/ the
128 * stencil border color value in bc->ui[0] but according
129 * to desc->swizzle and desc->channel, the .x/.w component
130 * is NONE and the stencil value is in the y component.
131 * Meanwhile the hardware wants this in the .w component
132 * for x24s8 and the .x component for x32_s8x24.
134 if ((format
== PIPE_FORMAT_X24S8_UINT
) ||
135 (format
== PIPE_FORMAT_X32_S8X24_UINT
)) {
138 cd
= (format
== PIPE_FORMAT_X32_S8X24_UINT
) ? 0 : 3;
147 if (desc
->channel
[c
].pure_integer
) {
149 switch (desc
->channel
[c
].size
) {
151 assert(desc
->channel
[c
].type
== UTIL_FORMAT_TYPE_UNSIGNED
);
152 clamped
= CLAMP(bc
->ui
[j
], 0, 0x3);
155 if (desc
->channel
[c
].type
== UTIL_FORMAT_TYPE_SIGNED
)
156 clamped
= CLAMP(bc
->i
[j
], -128, 127);
158 clamped
= CLAMP(bc
->ui
[j
], 0, 255);
161 assert(desc
->channel
[c
].type
== UTIL_FORMAT_TYPE_UNSIGNED
);
162 clamped
= CLAMP(bc
->ui
[j
], 0, 0x3ff);
165 if (desc
->channel
[c
].type
== UTIL_FORMAT_TYPE_SIGNED
)
166 clamped
= CLAMP(bc
->i
[j
], -32768, 32767);
168 clamped
= CLAMP(bc
->ui
[j
], 0, 65535);
171 assert(!"Unexpected bit size");
176 e
->fp32
[cd
] = bc
->ui
[j
];
177 e
->fp16
[cd
] = clamped
;
180 float f_u
= CLAMP(f
, 0, 1);
181 float f_s
= CLAMP(f
, -1, 1);
184 e
->fp16
[c
] = util_float_to_half(f
);
185 e
->srgb
[c
] = util_float_to_half(f_u
);
186 e
->ui16
[c
] = f_u
* 0xffff;
187 e
->si16
[c
] = f_s
* 0x7fff;
188 e
->ui8
[c
] = f_u
* 0xff;
189 e
->si8
[c
] = f_s
* 0x7f;
191 e
->rgb565
|= (int)(f_u
* 0x3f) << 5;
193 e
->rgb565
|= (int)(f_u
* 0x1f) << (c
? 11 : 0);
195 e
->rgb5a1
|= (f_u
> 0.5) ? 0x8000 : 0;
197 e
->rgb5a1
|= (int)(f_u
* 0x1f) << (c
* 5);
199 e
->rgb10a2
|= (int)(f_u
* 0x3) << 30;
201 e
->rgb10a2
|= (int)(f_u
* 0x3ff) << (c
* 10);
202 e
->rgba4
|= (int)(f_u
* 0xf) << (c
* 4);
204 e
->z24
= f_u
* 0xffffff;
209 memset(&e
->__pad0
, 0, sizeof(e
->__pad0
));
210 memset(&e
->__pad1
, 0, sizeof(e
->__pad1
));
216 emit_border_color(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
)
218 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
219 struct bcolor_entry
*entries
;
223 STATIC_ASSERT(sizeof(struct bcolor_entry
) == FD6_BORDER_COLOR_SIZE
);
225 u_upload_alloc(fd6_ctx
->border_color_uploader
,
226 0, FD6_BORDER_COLOR_UPLOAD_SIZE
,
227 FD6_BORDER_COLOR_UPLOAD_SIZE
, &off
,
228 &fd6_ctx
->border_color_buf
,
233 setup_border_colors(&ctx
->tex
[PIPE_SHADER_VERTEX
], &entries
[0]);
234 setup_border_colors(&ctx
->tex
[PIPE_SHADER_FRAGMENT
],
235 &entries
[ctx
->tex
[PIPE_SHADER_VERTEX
].num_samplers
]);
237 OUT_PKT4(ring
, REG_A6XX_SP_TP_BORDER_COLOR_BASE_ADDR_LO
, 2);
238 OUT_RELOC(ring
, fd_resource(fd6_ctx
->border_color_buf
)->bo
, off
, 0, 0);
240 u_upload_unmap(fd6_ctx
->border_color_uploader
);
244 fd6_emit_fb_tex(struct fd_ringbuffer
*state
, struct fd_context
*ctx
)
246 struct pipe_framebuffer_state
*pfb
= &ctx
->batch
->framebuffer
;
247 struct pipe_surface
*psurf
= pfb
->cbufs
[0];
248 struct fd_resource
*rsc
= fd_resource(psurf
->texture
);
250 uint32_t texconst0
= fd6_tex_const_0(psurf
->texture
, psurf
->u
.tex
.level
,
251 psurf
->format
, PIPE_SWIZZLE_X
, PIPE_SWIZZLE_Y
,
252 PIPE_SWIZZLE_Z
, PIPE_SWIZZLE_W
);
254 /* always TILE6_2 mode in GMEM.. which also means no swap: */
255 texconst0
&= ~(A6XX_TEX_CONST_0_SWAP__MASK
| A6XX_TEX_CONST_0_TILE_MODE__MASK
);
256 texconst0
|= A6XX_TEX_CONST_0_TILE_MODE(TILE6_2
);
258 OUT_RING(state
, texconst0
);
259 OUT_RING(state
, A6XX_TEX_CONST_1_WIDTH(pfb
->width
) |
260 A6XX_TEX_CONST_1_HEIGHT(pfb
->height
));
261 OUT_RINGP(state
, A6XX_TEX_CONST_2_TYPE(A6XX_TEX_2D
) |
262 A6XX_TEX_CONST_2_FETCHSIZE(TFETCH6_2_BYTE
),
263 &ctx
->batch
->fb_read_patches
);
264 OUT_RING(state
, A6XX_TEX_CONST_3_ARRAY_PITCH(rsc
->layout
.layer_size
));
266 OUT_RING(state
, A6XX_TEX_CONST_4_BASE_LO(ctx
->screen
->gmem_base
));
267 OUT_RING(state
, A6XX_TEX_CONST_5_BASE_HI(ctx
->screen
->gmem_base
>> 32) |
268 A6XX_TEX_CONST_5_DEPTH(1));
269 OUT_RING(state
, 0); /* texconst6 */
270 OUT_RING(state
, 0); /* texconst7 */
271 OUT_RING(state
, 0); /* texconst8 */
272 OUT_RING(state
, 0); /* texconst9 */
273 OUT_RING(state
, 0); /* texconst10 */
274 OUT_RING(state
, 0); /* texconst11 */
282 fd6_emit_textures(struct fd_pipe
*pipe
, struct fd_ringbuffer
*ring
,
283 enum pipe_shader_type type
, struct fd_texture_stateobj
*tex
,
284 unsigned bcolor_offset
,
285 /* can be NULL if no image/SSBO/fb state to merge in: */
286 const struct ir3_shader_variant
*v
, struct fd_context
*ctx
)
288 bool needs_border
= false;
289 unsigned opcode
, tex_samp_reg
, tex_const_reg
, tex_count_reg
;
290 enum a6xx_state_block sb
;
293 case PIPE_SHADER_VERTEX
:
295 opcode
= CP_LOAD_STATE6_GEOM
;
296 tex_samp_reg
= REG_A6XX_SP_VS_TEX_SAMP_LO
;
297 tex_const_reg
= REG_A6XX_SP_VS_TEX_CONST_LO
;
298 tex_count_reg
= REG_A6XX_SP_VS_TEX_COUNT
;
300 case PIPE_SHADER_TESS_CTRL
:
302 opcode
= CP_LOAD_STATE6_GEOM
;
303 tex_samp_reg
= REG_A6XX_SP_HS_TEX_SAMP_LO
;
304 tex_const_reg
= REG_A6XX_SP_HS_TEX_CONST_LO
;
305 tex_count_reg
= REG_A6XX_SP_HS_TEX_COUNT
;
307 case PIPE_SHADER_TESS_EVAL
:
309 opcode
= CP_LOAD_STATE6_GEOM
;
310 tex_samp_reg
= REG_A6XX_SP_DS_TEX_SAMP_LO
;
311 tex_const_reg
= REG_A6XX_SP_DS_TEX_CONST_LO
;
312 tex_count_reg
= REG_A6XX_SP_DS_TEX_COUNT
;
314 case PIPE_SHADER_GEOMETRY
:
316 opcode
= CP_LOAD_STATE6_GEOM
;
317 tex_samp_reg
= REG_A6XX_SP_GS_TEX_SAMP_LO
;
318 tex_const_reg
= REG_A6XX_SP_GS_TEX_CONST_LO
;
319 tex_count_reg
= REG_A6XX_SP_GS_TEX_COUNT
;
321 case PIPE_SHADER_FRAGMENT
:
323 opcode
= CP_LOAD_STATE6_FRAG
;
324 tex_samp_reg
= REG_A6XX_SP_FS_TEX_SAMP_LO
;
325 tex_const_reg
= REG_A6XX_SP_FS_TEX_CONST_LO
;
326 tex_count_reg
= REG_A6XX_SP_FS_TEX_COUNT
;
328 case PIPE_SHADER_COMPUTE
:
330 opcode
= CP_LOAD_STATE6_FRAG
;
331 tex_samp_reg
= REG_A6XX_SP_CS_TEX_SAMP_LO
;
332 tex_const_reg
= REG_A6XX_SP_CS_TEX_CONST_LO
;
333 tex_count_reg
= REG_A6XX_SP_CS_TEX_COUNT
;
336 unreachable("bad state block");
339 if (tex
->num_samplers
> 0) {
340 struct fd_ringbuffer
*state
=
341 fd_ringbuffer_new_object(pipe
, tex
->num_samplers
* 4 * 4);
342 for (unsigned i
= 0; i
< tex
->num_samplers
; i
++) {
343 static const struct fd6_sampler_stateobj dummy_sampler
= {};
344 const struct fd6_sampler_stateobj
*sampler
= tex
->samplers
[i
] ?
345 fd6_sampler_stateobj(tex
->samplers
[i
]) : &dummy_sampler
;
346 OUT_RING(state
, sampler
->texsamp0
);
347 OUT_RING(state
, sampler
->texsamp1
);
348 OUT_RING(state
, sampler
->texsamp2
|
349 A6XX_TEX_SAMP_2_BCOLOR_OFFSET((i
+ bcolor_offset
) * sizeof(struct bcolor_entry
)));
350 OUT_RING(state
, sampler
->texsamp3
);
351 needs_border
|= sampler
->needs_border
;
354 /* output sampler state: */
355 OUT_PKT7(ring
, opcode
, 3);
356 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(0) |
357 CP_LOAD_STATE6_0_STATE_TYPE(ST6_SHADER
) |
358 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
359 CP_LOAD_STATE6_0_STATE_BLOCK(sb
) |
360 CP_LOAD_STATE6_0_NUM_UNIT(tex
->num_samplers
));
361 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
363 OUT_PKT4(ring
, tex_samp_reg
, 2);
364 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
366 fd_ringbuffer_del(state
);
369 unsigned num_merged_textures
= tex
->num_textures
;
370 unsigned num_textures
= tex
->num_textures
;
372 num_merged_textures
+= v
->image_mapping
.num_tex
;
375 num_merged_textures
++;
377 /* There could be more bound textures than what the shader uses.
378 * Which isn't known at shader compile time. So in the case we
379 * are merging tex state, only emit the textures that the shader
380 * uses (since the image/SSBO related tex state comes immediately
383 num_textures
= v
->image_mapping
.tex_base
;
386 if (num_merged_textures
> 0) {
387 struct fd_ringbuffer
*state
=
388 fd_ringbuffer_new_object(pipe
, num_merged_textures
* 16 * 4);
389 for (unsigned i
= 0; i
< num_textures
; i
++) {
390 static const struct fd6_pipe_sampler_view dummy_view
= {};
391 const struct fd6_pipe_sampler_view
*view
= tex
->textures
[i
] ?
392 fd6_pipe_sampler_view(tex
->textures
[i
]) : &dummy_view
;
393 struct fd_resource
*rsc
= NULL
;
395 if (view
->base
.texture
)
396 rsc
= fd_resource(view
->base
.texture
);
398 OUT_RING(state
, view
->texconst0
);
399 OUT_RING(state
, view
->texconst1
);
400 OUT_RING(state
, view
->texconst2
);
401 OUT_RING(state
, view
->texconst3
);
404 if (view
->base
.format
== PIPE_FORMAT_X32_S8X24_UINT
)
406 OUT_RELOC(state
, rsc
->bo
, view
->offset
,
407 (uint64_t)view
->texconst5
<< 32, 0);
409 OUT_RING(state
, 0x00000000);
410 OUT_RING(state
, view
->texconst5
);
413 OUT_RING(state
, view
->texconst6
);
415 if (rsc
&& view
->ubwc_enabled
) {
416 OUT_RELOC(state
, rsc
->bo
, view
->ubwc_offset
, 0, 0);
422 OUT_RING(state
, view
->texconst9
);
423 OUT_RING(state
, view
->texconst10
);
424 OUT_RING(state
, view
->texconst11
);
432 const struct ir3_ibo_mapping
*mapping
= &v
->image_mapping
;
433 struct fd_shaderbuf_stateobj
*buf
= &ctx
->shaderbuf
[type
];
434 struct fd_shaderimg_stateobj
*img
= &ctx
->shaderimg
[type
];
436 for (unsigned i
= 0; i
< mapping
->num_tex
; i
++) {
437 unsigned idx
= mapping
->tex_to_image
[i
];
438 if (idx
& IBO_SSBO
) {
439 fd6_emit_ssbo_tex(state
, &buf
->sb
[idx
& ~IBO_SSBO
]);
441 fd6_emit_image_tex(state
, &img
->si
[idx
]);
446 fd6_emit_fb_tex(state
, ctx
);
450 /* emit texture state: */
451 OUT_PKT7(ring
, opcode
, 3);
452 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(0) |
453 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
454 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
455 CP_LOAD_STATE6_0_STATE_BLOCK(sb
) |
456 CP_LOAD_STATE6_0_NUM_UNIT(num_merged_textures
));
457 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
459 OUT_PKT4(ring
, tex_const_reg
, 2);
460 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
462 fd_ringbuffer_del(state
);
465 OUT_PKT4(ring
, tex_count_reg
, 1);
466 OUT_RING(ring
, num_merged_textures
);
471 /* Emits combined texture state, which also includes any Image/SSBO
472 * related texture state merged in (because we must have all texture
473 * state for a given stage in a single buffer). In the fast-path, if
474 * we don't need to merge in any image/ssbo related texture state, we
475 * just use cached texture stateobj. Otherwise we generate a single-
478 * TODO Is there some sane way we can still use cached texture stateobj
479 * with image/ssbo in use?
481 * returns whether border_color is required:
484 fd6_emit_combined_textures(struct fd_ringbuffer
*ring
, struct fd6_emit
*emit
,
485 enum pipe_shader_type type
, const struct ir3_shader_variant
*v
)
487 struct fd_context
*ctx
= emit
->ctx
;
488 bool needs_border
= false;
490 static const struct {
491 enum fd6_state_id state_id
;
492 unsigned enable_mask
;
493 } s
[PIPE_SHADER_TYPES
] = {
494 [PIPE_SHADER_VERTEX
] = { FD6_GROUP_VS_TEX
, ENABLE_ALL
},
495 [PIPE_SHADER_TESS_CTRL
] = { FD6_GROUP_HS_TEX
, ENABLE_ALL
},
496 [PIPE_SHADER_TESS_EVAL
] = { FD6_GROUP_DS_TEX
, ENABLE_ALL
},
497 [PIPE_SHADER_GEOMETRY
] = { FD6_GROUP_GS_TEX
, ENABLE_ALL
},
498 [PIPE_SHADER_FRAGMENT
] = { FD6_GROUP_FS_TEX
, ENABLE_DRAW
},
501 debug_assert(s
[type
].state_id
);
503 if (!v
->image_mapping
.num_tex
&& !v
->fb_read
) {
504 /* in the fast-path, when we don't have to mix in any image/SSBO
505 * related texture state, we can just lookup the stateobj and
508 * Also, framebuffer-read is a slow-path because an extra
509 * texture needs to be inserted.
511 * TODO we can probably simmplify things if we also treated
512 * border_color as a slow-path.. this way the tex state key
513 * wouldn't depend on bcolor_offset.. but fb_read might rather
514 * be *somehow* a fast-path if we eventually used it for PLS.
515 * I suppose there would be no harm in just *always* inserting
516 * an fb_read texture?
518 if ((ctx
->dirty_shader
[type
] & FD_DIRTY_SHADER_TEX
) &&
519 ctx
->tex
[type
].num_textures
> 0) {
520 struct fd6_texture_state
*tex
= fd6_texture_state(ctx
,
521 type
, &ctx
->tex
[type
]);
523 needs_border
|= tex
->needs_border
;
525 fd6_emit_add_group(emit
, tex
->stateobj
, s
[type
].state_id
,
526 s
[type
].enable_mask
);
529 /* In the slow-path, create a one-shot texture state object
530 * if either TEX|PROG|SSBO|IMAGE state is dirty:
532 if ((ctx
->dirty_shader
[type
] &
533 (FD_DIRTY_SHADER_TEX
| FD_DIRTY_SHADER_PROG
|
534 FD_DIRTY_SHADER_IMAGE
| FD_DIRTY_SHADER_SSBO
)) ||
536 struct fd_texture_stateobj
*tex
= &ctx
->tex
[type
];
537 struct fd_ringbuffer
*stateobj
=
538 fd_submit_new_ringbuffer(ctx
->batch
->submit
,
539 0x1000, FD_RINGBUFFER_STREAMING
);
540 unsigned bcolor_offset
=
541 fd6_border_color_offset(ctx
, type
, tex
);
543 needs_border
|= fd6_emit_textures(ctx
->pipe
, stateobj
, type
, tex
,
544 bcolor_offset
, v
, ctx
);
546 fd6_emit_take_group(emit
, stateobj
, s
[type
].state_id
,
547 s
[type
].enable_mask
);
554 static struct fd_ringbuffer
*
555 build_vbo_state(struct fd6_emit
*emit
, const struct ir3_shader_variant
*vp
)
557 const struct fd_vertex_state
*vtx
= emit
->vtx
;
559 /* Determine which inputs need VFD state */
562 for (int32_t i
= 0; i
<= vp
->inputs_count
; i
++) {
563 if (vp
->inputs
[i
].sysval
)
565 if (vp
->inputs
[i
].compmask
) {
570 struct fd_ringbuffer
*ring
= fd_submit_new_ringbuffer(emit
->ctx
->batch
->submit
,
571 4 * (5 + cnt
* 7), FD_RINGBUFFER_STREAMING
);
573 OUT_PKT4(ring
, REG_A6XX_VFD_CONTROL_0
, 1);
574 OUT_RING(ring
, A6XX_VFD_CONTROL_0_FETCH_CNT(cnt
) |
575 A6XX_VFD_CONTROL_0_DECODE_CNT(cnt
));
577 OUT_PKT4(ring
, REG_A6XX_VFD_FETCH(0), 4 * cnt
);
578 for (int32_t j
= 0; j
< cnt
; j
++) {
580 struct pipe_vertex_element
*elem
= &vtx
->vtx
->pipe
[i
];
581 const struct pipe_vertex_buffer
*vb
=
582 &vtx
->vertexbuf
.vb
[elem
->vertex_buffer_index
];
583 struct fd_resource
*rsc
= fd_resource(vb
->buffer
.resource
);
584 uint32_t off
= vb
->buffer_offset
;
585 uint32_t size
= fd_bo_size(rsc
->bo
) - off
;
588 /* see dEQP-GLES31.stress.vertex_attribute_binding.buffer_bounds.bind_vertex_buffer_offset_near_wrap_10
590 if (off
> fd_bo_size(rsc
->bo
)) {
599 OUT_RELOC(ring
, rsc
->bo
, off
, 0, 0);
600 OUT_RING(ring
, size
); /* VFD_FETCH[j].SIZE */
601 OUT_RING(ring
, vb
->stride
); /* VFD_FETCH[j].STRIDE */
604 OUT_PKT4(ring
, REG_A6XX_VFD_DECODE(0), 2 * cnt
);
605 for (int32_t j
= 0; j
< cnt
; j
++) {
607 struct pipe_vertex_element
*elem
= &vtx
->vtx
->pipe
[i
];
608 enum pipe_format pfmt
= elem
->src_format
;
609 enum a6xx_format fmt
= fd6_pipe2vtx(pfmt
);
610 bool isint
= util_format_is_pure_integer(pfmt
);
611 debug_assert(fmt
!= FMT6_NONE
);
613 OUT_RING(ring
, A6XX_VFD_DECODE_INSTR_IDX(j
) |
614 A6XX_VFD_DECODE_INSTR_OFFSET(elem
->src_offset
) |
615 A6XX_VFD_DECODE_INSTR_FORMAT(fmt
) |
616 COND(elem
->instance_divisor
, A6XX_VFD_DECODE_INSTR_INSTANCED
) |
617 A6XX_VFD_DECODE_INSTR_SWAP(fd6_pipe2swap(pfmt
)) |
618 A6XX_VFD_DECODE_INSTR_UNK30
|
619 COND(!isint
, A6XX_VFD_DECODE_INSTR_FLOAT
));
620 OUT_RING(ring
, MAX2(1, elem
->instance_divisor
)); /* VFD_DECODE[j].STEP_RATE */
623 OUT_PKT4(ring
, REG_A6XX_VFD_DEST_CNTL(0), cnt
);
624 for (int32_t j
= 0; j
< cnt
; j
++) {
627 OUT_RING(ring
, A6XX_VFD_DEST_CNTL_INSTR_WRITEMASK(vp
->inputs
[i
].compmask
) |
628 A6XX_VFD_DEST_CNTL_INSTR_REGID(vp
->inputs
[i
].regid
));
634 static struct fd_ringbuffer
*
635 build_lrz(struct fd6_emit
*emit
, bool binning_pass
)
637 struct fd_context
*ctx
= emit
->ctx
;
638 struct fd6_blend_stateobj
*blend
= fd6_blend_stateobj(ctx
->blend
);
639 struct fd6_zsa_stateobj
*zsa
= fd6_zsa_stateobj(ctx
->zsa
);
640 struct pipe_framebuffer_state
*pfb
= &ctx
->batch
->framebuffer
;
641 struct fd_resource
*rsc
= fd_resource(pfb
->zsbuf
->texture
);
642 uint32_t gras_lrz_cntl
= zsa
->gras_lrz_cntl
;
643 uint32_t rb_lrz_cntl
= zsa
->rb_lrz_cntl
;
645 if (zsa
->invalidate_lrz
) {
646 rsc
->lrz_valid
= false;
649 } else if (emit
->no_lrz_write
|| !rsc
->lrz
|| !rsc
->lrz_valid
) {
652 } else if (binning_pass
&& blend
->lrz_write
&& zsa
->lrz_write
) {
653 gras_lrz_cntl
|= A6XX_GRAS_LRZ_CNTL_LRZ_WRITE
;
656 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
657 if ((fd6_ctx
->last
.lrz
[binning_pass
].gras_lrz_cntl
== gras_lrz_cntl
) &&
658 (fd6_ctx
->last
.lrz
[binning_pass
].rb_lrz_cntl
== rb_lrz_cntl
) &&
662 fd6_ctx
->last
.lrz
[binning_pass
].gras_lrz_cntl
= gras_lrz_cntl
;
663 fd6_ctx
->last
.lrz
[binning_pass
].rb_lrz_cntl
= rb_lrz_cntl
;
665 struct fd_ringbuffer
*ring
= fd_submit_new_ringbuffer(ctx
->batch
->submit
,
666 16, FD_RINGBUFFER_STREAMING
);
668 OUT_PKT4(ring
, REG_A6XX_GRAS_LRZ_CNTL
, 1);
669 OUT_RING(ring
, gras_lrz_cntl
);
671 OUT_PKT4(ring
, REG_A6XX_RB_LRZ_CNTL
, 1);
672 OUT_RING(ring
, rb_lrz_cntl
);
678 fd6_emit_streamout(struct fd_ringbuffer
*ring
, struct fd6_emit
*emit
, struct ir3_stream_output_info
*info
)
680 struct fd_context
*ctx
= emit
->ctx
;
681 const struct fd6_program_state
*prog
= fd6_emit_get_prog(emit
);
682 struct fd_streamout_stateobj
*so
= &ctx
->streamout
;
684 emit
->streamout_mask
= 0;
686 for (unsigned i
= 0; i
< so
->num_targets
; i
++) {
687 struct pipe_stream_output_target
*target
= so
->targets
[i
];
692 OUT_PKT4(ring
, REG_A6XX_VPC_SO_BUFFER_BASE_LO(i
), 3);
693 /* VPC_SO[i].BUFFER_BASE_LO: */
694 OUT_RELOC(ring
, fd_resource(target
->buffer
)->bo
, target
->buffer_offset
, 0, 0);
695 OUT_RING(ring
, target
->buffer_size
- target
->buffer_offset
);
697 if (so
->reset
& (1 << i
)) {
698 unsigned offset
= (so
->offsets
[i
] * info
->stride
[i
] * 4);
699 OUT_PKT4(ring
, REG_A6XX_VPC_SO_BUFFER_OFFSET(i
), 1);
700 OUT_RING(ring
, offset
);
702 OUT_PKT7(ring
, CP_MEM_TO_REG
, 3);
703 OUT_RING(ring
, CP_MEM_TO_REG_0_REG(REG_A6XX_VPC_SO_BUFFER_OFFSET(i
)) |
704 CP_MEM_TO_REG_0_SHIFT_BY_2
| CP_MEM_TO_REG_0_UNK31
|
705 CP_MEM_TO_REG_0_CNT(0));
706 OUT_RELOC(ring
, control_ptr(fd6_context(ctx
), flush_base
[i
].offset
));
709 OUT_PKT4(ring
, REG_A6XX_VPC_SO_FLUSH_BASE_LO(i
), 2);
710 OUT_RELOC(ring
, control_ptr(fd6_context(ctx
), flush_base
[i
]));
712 so
->reset
&= ~(1 << i
);
714 emit
->streamout_mask
|= (1 << i
);
717 if (emit
->streamout_mask
) {
718 fd6_emit_add_group(emit
, prog
->streamout_stateobj
, FD6_GROUP_SO
, ENABLE_ALL
);
720 /* If we transition from a draw with streamout to one without, turn
723 if (ctx
->last
.streamout_mask
!= 0) {
724 struct fd_ringbuffer
*obj
= fd_submit_new_ringbuffer(emit
->ctx
->batch
->submit
,
725 5 * 4, FD_RINGBUFFER_STREAMING
);
727 OUT_PKT7(obj
, CP_CONTEXT_REG_BUNCH
, 4);
728 OUT_RING(obj
, REG_A6XX_VPC_SO_CNTL
);
730 OUT_RING(obj
, REG_A6XX_VPC_SO_BUF_CNTL
);
733 fd6_emit_take_group(emit
, obj
, FD6_GROUP_SO
, ENABLE_ALL
);
737 ctx
->last
.streamout_mask
= emit
->streamout_mask
;
741 fd6_emit_state(struct fd_ringbuffer
*ring
, struct fd6_emit
*emit
)
743 struct fd_context
*ctx
= emit
->ctx
;
744 struct pipe_framebuffer_state
*pfb
= &ctx
->batch
->framebuffer
;
745 const struct fd6_program_state
*prog
= fd6_emit_get_prog(emit
);
746 const struct ir3_shader_variant
*vs
= emit
->vs
;
747 const struct ir3_shader_variant
*hs
= emit
->hs
;
748 const struct ir3_shader_variant
*ds
= emit
->ds
;
749 const struct ir3_shader_variant
*gs
= emit
->gs
;
750 const struct ir3_shader_variant
*fs
= emit
->fs
;
751 const enum fd_dirty_3d_state dirty
= emit
->dirty
;
752 bool needs_border
= false;
754 emit_marker6(ring
, 5);
756 /* NOTE: we track fb_read differently than _BLEND_ENABLED since
757 * we might at some point decide to do sysmem in some cases when
761 ctx
->batch
->gmem_reason
|= FD_GMEM_FB_READ
;
763 if (emit
->dirty
& (FD_DIRTY_VTXBUF
| FD_DIRTY_VTXSTATE
)) {
764 struct fd_ringbuffer
*state
;
766 state
= build_vbo_state(emit
, emit
->vs
);
767 fd6_emit_take_group(emit
, state
, FD6_GROUP_VBO
, ENABLE_ALL
);
770 if (dirty
& FD_DIRTY_ZSA
) {
771 struct fd6_zsa_stateobj
*zsa
= fd6_zsa_stateobj(ctx
->zsa
);
773 if (util_format_is_pure_integer(pipe_surface_format(pfb
->cbufs
[0])))
774 fd6_emit_add_group(emit
, zsa
->stateobj_no_alpha
, FD6_GROUP_ZSA
, ENABLE_ALL
);
776 fd6_emit_add_group(emit
, zsa
->stateobj
, FD6_GROUP_ZSA
, ENABLE_ALL
);
779 if ((dirty
& (FD_DIRTY_ZSA
| FD_DIRTY_BLEND
| FD_DIRTY_PROG
)) && pfb
->zsbuf
) {
780 struct fd_ringbuffer
*state
;
782 state
= build_lrz(emit
, false);
784 fd6_emit_take_group(emit
, state
, FD6_GROUP_LRZ
, ENABLE_DRAW
);
787 state
= build_lrz(emit
, true);
789 fd6_emit_take_group(emit
, state
,
790 FD6_GROUP_LRZ_BINNING
, CP_SET_DRAW_STATE__0_BINNING
);
794 if (dirty
& FD_DIRTY_STENCIL_REF
) {
795 struct pipe_stencil_ref
*sr
= &ctx
->stencil_ref
;
797 OUT_PKT4(ring
, REG_A6XX_RB_STENCILREF
, 1);
798 OUT_RING(ring
, A6XX_RB_STENCILREF_REF(sr
->ref_value
[0]) |
799 A6XX_RB_STENCILREF_BFREF(sr
->ref_value
[1]));
802 /* NOTE: scissor enabled bit is part of rasterizer state, but
803 * fd_rasterizer_state_bind() will mark scissor dirty if needed:
805 if (dirty
& FD_DIRTY_SCISSOR
) {
806 struct fd_ringbuffer
*ring
= fd_submit_new_ringbuffer(
807 emit
->ctx
->batch
->submit
, 3*4, FD_RINGBUFFER_STREAMING
);
808 struct pipe_scissor_state
*scissor
= fd_context_get_scissor(ctx
);
811 A6XX_GRAS_SC_SCREEN_SCISSOR_TL_0(
815 A6XX_GRAS_SC_SCREEN_SCISSOR_BR_0(
816 .x
= MAX2(scissor
->maxx
, 1) - 1,
817 .y
= MAX2(scissor
->maxy
, 1) - 1
821 fd6_emit_take_group(emit
, ring
, FD6_GROUP_SCISSOR
, ENABLE_ALL
);
823 ctx
->batch
->max_scissor
.minx
= MIN2(ctx
->batch
->max_scissor
.minx
, scissor
->minx
);
824 ctx
->batch
->max_scissor
.miny
= MIN2(ctx
->batch
->max_scissor
.miny
, scissor
->miny
);
825 ctx
->batch
->max_scissor
.maxx
= MAX2(ctx
->batch
->max_scissor
.maxx
, scissor
->maxx
);
826 ctx
->batch
->max_scissor
.maxy
= MAX2(ctx
->batch
->max_scissor
.maxy
, scissor
->maxy
);
829 if (dirty
& FD_DIRTY_VIEWPORT
) {
830 struct pipe_scissor_state
*scissor
= &ctx
->viewport_scissor
;
833 A6XX_GRAS_CL_VPORT_XOFFSET_0(ctx
->viewport
.translate
[0]),
834 A6XX_GRAS_CL_VPORT_XSCALE_0(ctx
->viewport
.scale
[0]),
835 A6XX_GRAS_CL_VPORT_YOFFSET_0(ctx
->viewport
.translate
[1]),
836 A6XX_GRAS_CL_VPORT_YSCALE_0(ctx
->viewport
.scale
[1]),
837 A6XX_GRAS_CL_VPORT_ZOFFSET_0(ctx
->viewport
.translate
[2]),
838 A6XX_GRAS_CL_VPORT_ZSCALE_0(ctx
->viewport
.scale
[2])
842 A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0(
846 A6XX_GRAS_SC_VIEWPORT_SCISSOR_BR_0(
847 .x
= MAX2(scissor
->maxx
, 1) - 1,
848 .y
= MAX2(scissor
->maxy
, 1) - 1
852 unsigned guardband_x
= fd_calc_guardband(scissor
->maxx
- scissor
->minx
);
853 unsigned guardband_y
= fd_calc_guardband(scissor
->maxy
- scissor
->miny
);
855 OUT_REG(ring
, A6XX_GRAS_CL_GUARDBAND_CLIP_ADJ(
862 if (dirty
& FD_DIRTY_PROG
) {
863 fd6_emit_add_group(emit
, prog
->config_stateobj
, FD6_GROUP_PROG_CONFIG
, ENABLE_ALL
);
864 fd6_emit_add_group(emit
, prog
->stateobj
, FD6_GROUP_PROG
, ENABLE_DRAW
);
865 fd6_emit_add_group(emit
, prog
->binning_stateobj
,
866 FD6_GROUP_PROG_BINNING
, CP_SET_DRAW_STATE__0_BINNING
);
868 /* emit remaining streaming program state, ie. what depends on
869 * other emit state, so cannot be pre-baked.
871 struct fd_ringbuffer
*streaming
= fd6_program_interp_state(emit
);
873 fd6_emit_take_group(emit
, streaming
, FD6_GROUP_PROG_INTERP
, ENABLE_DRAW
);
876 if (dirty
& FD_DIRTY_RASTERIZER
) {
877 struct fd_ringbuffer
*stateobj
=
878 fd6_rasterizer_state(ctx
, emit
->primitive_restart
);
879 fd6_emit_add_group(emit
, stateobj
,
880 FD6_GROUP_RASTERIZER
, ENABLE_ALL
);
883 if (dirty
& (FD_DIRTY_FRAMEBUFFER
| FD_DIRTY_RASTERIZER_DISCARD
| FD_DIRTY_PROG
)) {
884 struct fd_ringbuffer
*ring
= fd_submit_new_ringbuffer(
885 emit
->ctx
->batch
->submit
, 5 * 4, FD_RINGBUFFER_STREAMING
);
887 unsigned nr
= pfb
->nr_cbufs
;
889 if (ctx
->rasterizer
->rasterizer_discard
)
892 OUT_PKT4(ring
, REG_A6XX_RB_FS_OUTPUT_CNTL0
, 2);
893 OUT_RING(ring
, COND(fs
->writes_pos
, A6XX_RB_FS_OUTPUT_CNTL0_FRAG_WRITES_Z
) |
894 COND(fs
->writes_smask
&& pfb
->samples
> 1,
895 A6XX_RB_FS_OUTPUT_CNTL0_FRAG_WRITES_SAMPMASK
));
896 OUT_RING(ring
, A6XX_RB_FS_OUTPUT_CNTL1_MRT(nr
));
898 OUT_PKT4(ring
, REG_A6XX_SP_FS_OUTPUT_CNTL1
, 1);
899 OUT_RING(ring
, A6XX_SP_FS_OUTPUT_CNTL1_MRT(nr
));
901 fd6_emit_take_group(emit
, ring
, FD6_GROUP_PROG_FB_RAST
, ENABLE_DRAW
);
904 fd6_emit_consts(emit
);
906 struct ir3_stream_output_info
*info
= &fd6_last_shader(prog
)->shader
->stream_output
;
907 if (info
->num_outputs
)
908 fd6_emit_streamout(ring
, emit
, info
);
910 if (dirty
& (FD_DIRTY_BLEND
| FD_DIRTY_SAMPLE_MASK
)) {
911 struct fd6_blend_variant
*blend
= fd6_blend_variant(ctx
->blend
,
912 pfb
->samples
, ctx
->sample_mask
);
913 fd6_emit_add_group(emit
, blend
->stateobj
, FD6_GROUP_BLEND
, ENABLE_DRAW
);
916 if (dirty
& FD_DIRTY_BLEND_COLOR
) {
917 struct pipe_blend_color
*bcolor
= &ctx
->blend_color
;
918 struct fd_ringbuffer
*ring
= fd_submit_new_ringbuffer(
919 emit
->ctx
->batch
->submit
, 5*4, FD_RINGBUFFER_STREAMING
);
922 A6XX_RB_BLEND_RED_F32(bcolor
->color
[0]),
923 A6XX_RB_BLEND_GREEN_F32(bcolor
->color
[1]),
924 A6XX_RB_BLEND_BLUE_F32(bcolor
->color
[2]),
925 A6XX_RB_BLEND_ALPHA_F32(bcolor
->color
[3])
928 fd6_emit_take_group(emit
, ring
, FD6_GROUP_BLEND_COLOR
, ENABLE_DRAW
);
931 needs_border
|= fd6_emit_combined_textures(ring
, emit
, PIPE_SHADER_VERTEX
, vs
);
933 needs_border
|= fd6_emit_combined_textures(ring
, emit
, PIPE_SHADER_TESS_CTRL
, hs
);
934 needs_border
|= fd6_emit_combined_textures(ring
, emit
, PIPE_SHADER_TESS_EVAL
, ds
);
937 needs_border
|= fd6_emit_combined_textures(ring
, emit
, PIPE_SHADER_GEOMETRY
, gs
);
939 needs_border
|= fd6_emit_combined_textures(ring
, emit
, PIPE_SHADER_FRAGMENT
, fs
);
942 emit_border_color(ctx
, ring
);
945 debug_assert(ir3_shader_nibo(hs
) == 0);
946 debug_assert(ir3_shader_nibo(ds
) == 0);
949 debug_assert(ir3_shader_nibo(gs
) == 0);
952 #define DIRTY_IBO (FD_DIRTY_SHADER_SSBO | FD_DIRTY_SHADER_IMAGE | \
953 FD_DIRTY_SHADER_PROG)
954 if (ctx
->dirty_shader
[PIPE_SHADER_FRAGMENT
] & DIRTY_IBO
) {
955 struct fd_ringbuffer
*state
=
956 fd6_build_ibo_state(ctx
, fs
, PIPE_SHADER_FRAGMENT
);
957 struct fd_ringbuffer
*obj
= fd_submit_new_ringbuffer(
958 ctx
->batch
->submit
, 0x100, FD_RINGBUFFER_STREAMING
);
960 OUT_PKT7(obj
, CP_LOAD_STATE6
, 3);
961 OUT_RING(obj
, CP_LOAD_STATE6_0_DST_OFF(0) |
962 CP_LOAD_STATE6_0_STATE_TYPE(ST6_SHADER
) |
963 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
964 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_IBO
) |
965 CP_LOAD_STATE6_0_NUM_UNIT(ir3_shader_nibo(fs
)));
968 OUT_PKT4(obj
, REG_A6XX_SP_IBO_LO
, 2);
971 /* TODO if we used CP_SET_DRAW_STATE for compute shaders, we could
972 * de-duplicate this from program->config_stateobj
974 OUT_PKT4(obj
, REG_A6XX_SP_IBO_COUNT
, 1);
975 OUT_RING(obj
, ir3_shader_nibo(fs
));
977 fd6_emit_ibo_consts(emit
, fs
, PIPE_SHADER_FRAGMENT
, ring
);
979 fd6_emit_take_group(emit
, obj
, FD6_GROUP_IBO
, ENABLE_DRAW
);
980 fd_ringbuffer_del(state
);
983 if (emit
->num_groups
> 0) {
984 OUT_PKT7(ring
, CP_SET_DRAW_STATE
, 3 * emit
->num_groups
);
985 for (unsigned i
= 0; i
< emit
->num_groups
; i
++) {
986 struct fd6_state_group
*g
= &emit
->groups
[i
];
987 unsigned n
= g
->stateobj
?
988 fd_ringbuffer_size(g
->stateobj
) / 4 : 0;
990 debug_assert((g
->enable_mask
& ~ENABLE_ALL
) == 0);
993 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(0) |
994 CP_SET_DRAW_STATE__0_DISABLE
|
996 CP_SET_DRAW_STATE__0_GROUP_ID(g
->group_id
));
997 OUT_RING(ring
, 0x00000000);
998 OUT_RING(ring
, 0x00000000);
1000 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(n
) |
1002 CP_SET_DRAW_STATE__0_GROUP_ID(g
->group_id
));
1003 OUT_RB(ring
, g
->stateobj
);
1007 fd_ringbuffer_del(g
->stateobj
);
1009 emit
->num_groups
= 0;
1014 fd6_emit_cs_state(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
,
1015 struct ir3_shader_variant
*cp
)
1017 enum fd_dirty_shader_state dirty
= ctx
->dirty_shader
[PIPE_SHADER_COMPUTE
];
1019 if (dirty
& (FD_DIRTY_SHADER_TEX
| FD_DIRTY_SHADER_PROG
|
1020 FD_DIRTY_SHADER_IMAGE
| FD_DIRTY_SHADER_SSBO
)) {
1021 struct fd_texture_stateobj
*tex
= &ctx
->tex
[PIPE_SHADER_COMPUTE
];
1022 unsigned bcolor_offset
= fd6_border_color_offset(ctx
, PIPE_SHADER_COMPUTE
, tex
);
1024 bool needs_border
= fd6_emit_textures(ctx
->pipe
, ring
, PIPE_SHADER_COMPUTE
, tex
,
1025 bcolor_offset
, cp
, ctx
);
1028 emit_border_color(ctx
, ring
);
1030 OUT_PKT4(ring
, REG_A6XX_SP_VS_TEX_COUNT
, 1);
1033 OUT_PKT4(ring
, REG_A6XX_SP_HS_TEX_COUNT
, 1);
1036 OUT_PKT4(ring
, REG_A6XX_SP_DS_TEX_COUNT
, 1);
1039 OUT_PKT4(ring
, REG_A6XX_SP_GS_TEX_COUNT
, 1);
1042 OUT_PKT4(ring
, REG_A6XX_SP_FS_TEX_COUNT
, 1);
1046 if (dirty
& (FD_DIRTY_SHADER_SSBO
| FD_DIRTY_SHADER_IMAGE
)) {
1047 struct fd_ringbuffer
*state
=
1048 fd6_build_ibo_state(ctx
, cp
, PIPE_SHADER_COMPUTE
);
1050 OUT_PKT7(ring
, CP_LOAD_STATE6_FRAG
, 3);
1051 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(0) |
1052 CP_LOAD_STATE6_0_STATE_TYPE(ST6_IBO
) |
1053 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
1054 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_CS_SHADER
) |
1055 CP_LOAD_STATE6_0_NUM_UNIT(ir3_shader_nibo(cp
)));
1056 OUT_RB(ring
, state
);
1058 OUT_PKT4(ring
, REG_A6XX_SP_CS_IBO_LO
, 2);
1059 OUT_RB(ring
, state
);
1061 OUT_PKT4(ring
, REG_A6XX_SP_CS_IBO_COUNT
, 1);
1062 OUT_RING(ring
, ir3_shader_nibo(cp
));
1064 fd_ringbuffer_del(state
);
1069 /* emit setup at begin of new cmdstream buffer (don't rely on previous
1070 * state, there could have been a context switch between ioctls):
1073 fd6_emit_restore(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
)
1075 //struct fd_context *ctx = batch->ctx;
1077 fd_log(batch
, "START RESTORE");
1079 fd6_cache_inv(batch
, ring
);
1081 OUT_PKT4(ring
, REG_A6XX_HLSQ_UPDATE_CNTL
, 1);
1082 OUT_RING(ring
, 0xfffff);
1086 WRITE(REG_A6XX_RB_UNKNOWN_8E04
, 0x0);
1087 WRITE(REG_A6XX_SP_UNKNOWN_AE04
, 0x8);
1088 WRITE(REG_A6XX_SP_UNKNOWN_AE00
, 0);
1089 WRITE(REG_A6XX_SP_UNKNOWN_AE0F
, 0x3f);
1090 WRITE(REG_A6XX_SP_UNKNOWN_B605
, 0x44);
1091 WRITE(REG_A6XX_SP_UNKNOWN_B600
, 0x100000);
1092 WRITE(REG_A6XX_HLSQ_UNKNOWN_BE00
, 0x80);
1093 WRITE(REG_A6XX_HLSQ_UNKNOWN_BE01
, 0);
1095 WRITE(REG_A6XX_VPC_UNKNOWN_9600
, 0);
1096 WRITE(REG_A6XX_GRAS_UNKNOWN_8600
, 0x880);
1097 WRITE(REG_A6XX_HLSQ_UNKNOWN_BE04
, 0x80000);
1098 WRITE(REG_A6XX_SP_UNKNOWN_AE03
, 0x1430);
1099 WRITE(REG_A6XX_SP_IBO_COUNT
, 0);
1100 WRITE(REG_A6XX_SP_UNKNOWN_B182
, 0);
1101 WRITE(REG_A6XX_HLSQ_UNKNOWN_BB11
, 0);
1102 WRITE(REG_A6XX_UCHE_UNKNOWN_0E12
, 0x3200000);
1103 WRITE(REG_A6XX_UCHE_CLIENT_PF
, 4);
1104 WRITE(REG_A6XX_RB_UNKNOWN_8E01
, 0x1);
1105 WRITE(REG_A6XX_SP_UNKNOWN_AB00
, 0x5);
1106 WRITE(REG_A6XX_VFD_ADD_OFFSET
, A6XX_VFD_ADD_OFFSET_VERTEX
);
1107 WRITE(REG_A6XX_RB_UNKNOWN_8811
, 0x00000010);
1108 WRITE(REG_A6XX_PC_MODE_CNTL
, 0x1f);
1110 OUT_PKT4(ring
, REG_A6XX_RB_SRGB_CNTL
, 1);
1113 WRITE(REG_A6XX_GRAS_UNKNOWN_8101
, 0);
1114 WRITE(REG_A6XX_GRAS_SAMPLE_CNTL
, 0);
1115 WRITE(REG_A6XX_GRAS_UNKNOWN_8110
, 0x2);
1117 WRITE(REG_A6XX_RB_UNKNOWN_8818
, 0);
1118 WRITE(REG_A6XX_RB_UNKNOWN_8819
, 0);
1119 WRITE(REG_A6XX_RB_UNKNOWN_881A
, 0);
1120 WRITE(REG_A6XX_RB_UNKNOWN_881B
, 0);
1121 WRITE(REG_A6XX_RB_UNKNOWN_881C
, 0);
1122 WRITE(REG_A6XX_RB_UNKNOWN_881D
, 0);
1123 WRITE(REG_A6XX_RB_UNKNOWN_881E
, 0);
1124 WRITE(REG_A6XX_RB_UNKNOWN_88F0
, 0);
1126 WRITE(REG_A6XX_VPC_UNKNOWN_9236
,
1127 A6XX_VPC_UNKNOWN_9236_POINT_COORD_INVERT(0));
1128 WRITE(REG_A6XX_VPC_UNKNOWN_9300
, 0);
1130 WRITE(REG_A6XX_VPC_SO_OVERRIDE
, A6XX_VPC_SO_OVERRIDE_SO_DISABLE
);
1132 WRITE(REG_A6XX_PC_UNKNOWN_9990
, 0);
1133 WRITE(REG_A6XX_PC_UNKNOWN_9980
, 0);
1135 WRITE(REG_A6XX_PC_UNKNOWN_9B07
, 0);
1137 WRITE(REG_A6XX_SP_UNKNOWN_A81B
, 0);
1139 WRITE(REG_A6XX_SP_UNKNOWN_B183
, 0);
1141 WRITE(REG_A6XX_GRAS_UNKNOWN_8099
, 0);
1142 WRITE(REG_A6XX_GRAS_UNKNOWN_809B
, 0);
1143 WRITE(REG_A6XX_GRAS_UNKNOWN_80A0
, 2);
1144 WRITE(REG_A6XX_GRAS_UNKNOWN_80AF
, 0);
1145 WRITE(REG_A6XX_VPC_UNKNOWN_9210
, 0);
1146 WRITE(REG_A6XX_VPC_UNKNOWN_9211
, 0);
1147 WRITE(REG_A6XX_VPC_UNKNOWN_9602
, 0);
1148 WRITE(REG_A6XX_PC_UNKNOWN_9981
, 0x3);
1149 WRITE(REG_A6XX_PC_UNKNOWN_9E72
, 0);
1150 WRITE(REG_A6XX_VPC_UNKNOWN_9108
, 0x3);
1151 WRITE(REG_A6XX_SP_TP_SAMPLE_CONFIG
, 0);
1152 /* NOTE blob seems to (mostly?) use 0xb2 for SP_TP_UNKNOWN_B309
1153 * but this seems to kill texture gather offsets.
1155 WRITE(REG_A6XX_SP_TP_UNKNOWN_B309
, 0xa2);
1156 WRITE(REG_A6XX_RB_SAMPLE_CONFIG
, 0);
1157 WRITE(REG_A6XX_GRAS_SAMPLE_CONFIG
, 0);
1158 WRITE(REG_A6XX_RB_UNKNOWN_8878
, 0);
1159 WRITE(REG_A6XX_RB_UNKNOWN_8879
, 0);
1160 WRITE(REG_A6XX_HLSQ_CONTROL_5_REG
, 0xfc);
1162 emit_marker6(ring
, 7);
1164 OUT_PKT4(ring
, REG_A6XX_VFD_MODE_CNTL
, 1);
1165 OUT_RING(ring
, 0x00000000); /* VFD_MODE_CNTL */
1167 WRITE(REG_A6XX_VFD_UNKNOWN_A008
, 0);
1169 OUT_PKT4(ring
, REG_A6XX_PC_MODE_CNTL
, 1);
1170 OUT_RING(ring
, 0x0000001f); /* PC_MODE_CNTL */
1172 /* we don't use this yet.. probably best to disable.. */
1173 OUT_PKT7(ring
, CP_SET_DRAW_STATE
, 3);
1174 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(0) |
1175 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
1176 CP_SET_DRAW_STATE__0_GROUP_ID(0));
1177 OUT_RING(ring
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
1178 OUT_RING(ring
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
1180 OUT_PKT4(ring
, REG_A6XX_VPC_SO_BUF_CNTL
, 1);
1181 OUT_RING(ring
, 0x00000000); /* VPC_SO_BUF_CNTL */
1183 OUT_PKT4(ring
, REG_A6XX_GRAS_LRZ_CNTL
, 1);
1184 OUT_RING(ring
, 0x00000000);
1186 OUT_PKT4(ring
, REG_A6XX_RB_LRZ_CNTL
, 1);
1187 OUT_RING(ring
, 0x00000000);
1189 fd_log(batch
, "END RESTORE");
1193 fd6_mem_to_mem(struct fd_ringbuffer
*ring
, struct pipe_resource
*dst
,
1194 unsigned dst_off
, struct pipe_resource
*src
, unsigned src_off
,
1195 unsigned sizedwords
)
1197 struct fd_bo
*src_bo
= fd_resource(src
)->bo
;
1198 struct fd_bo
*dst_bo
= fd_resource(dst
)->bo
;
1201 for (i
= 0; i
< sizedwords
; i
++) {
1202 OUT_PKT7(ring
, CP_MEM_TO_MEM
, 5);
1203 OUT_RING(ring
, 0x00000000);
1204 OUT_RELOC(ring
, dst_bo
, dst_off
, 0, 0);
1205 OUT_RELOC(ring
, src_bo
, src_off
, 0, 0);
1212 /* this is *almost* the same as fd6_cache_flush().. which I guess
1213 * could be re-worked to be something a bit more generic w/ param
1214 * indicating what needs to be flushed.. although that would mean
1215 * figuring out which events trigger what state to flush..
1218 fd6_framebuffer_barrier(struct fd_context
*ctx
)
1220 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
1221 struct fd_batch
*batch
= ctx
->batch
;
1222 struct fd_ringbuffer
*ring
= batch
->draw
;
1225 seqno
= fd6_event_write(batch
, ring
, RB_DONE_TS
, true);
1227 OUT_PKT7(ring
, CP_WAIT_REG_MEM
, 6);
1228 OUT_RING(ring
, CP_WAIT_REG_MEM_0_FUNCTION(WRITE_EQ
) |
1229 CP_WAIT_REG_MEM_0_POLL_MEMORY
);
1230 OUT_RELOC(ring
, control_ptr(fd6_ctx
, seqno
));
1231 OUT_RING(ring
, CP_WAIT_REG_MEM_3_REF(seqno
));
1232 OUT_RING(ring
, CP_WAIT_REG_MEM_4_MASK(~0));
1233 OUT_RING(ring
, CP_WAIT_REG_MEM_5_DELAY_LOOP_CYCLES(16));
1235 fd6_event_write(batch
, ring
, PC_CCU_FLUSH_COLOR_TS
, true);
1236 fd6_event_write(batch
, ring
, PC_CCU_FLUSH_DEPTH_TS
, true);
1238 seqno
= fd6_event_write(batch
, ring
, CACHE_FLUSH_TS
, true);
1240 fd6_event_write(batch
, ring
, 0x31, false);
1242 OUT_PKT7(ring
, CP_WAIT_MEM_GTE
, 4);
1243 OUT_RING(ring
, CP_WAIT_MEM_GTE_0_RESERVED(0));
1244 OUT_RELOC(ring
, control_ptr(fd6_ctx
, seqno
));
1245 OUT_RING(ring
, CP_WAIT_MEM_GTE_3_REF(seqno
));
1249 fd6_emit_init_screen(struct pipe_screen
*pscreen
)
1251 struct fd_screen
*screen
= fd_screen(pscreen
);
1252 screen
->emit_ib
= fd6_emit_ib
;
1253 screen
->mem_to_mem
= fd6_mem_to_mem
;
1257 fd6_emit_init(struct pipe_context
*pctx
)
1259 struct fd_context
*ctx
= fd_context(pctx
);
1260 ctx
->framebuffer_barrier
= fd6_framebuffer_barrier
;