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 &ctx
->batch
->fb_read_patches
);
263 OUT_RING(state
, A6XX_TEX_CONST_3_ARRAY_PITCH(rsc
->layout
.layer_size
));
265 OUT_RING(state
, A6XX_TEX_CONST_4_BASE_LO(ctx
->screen
->gmem_base
));
266 OUT_RING(state
, A6XX_TEX_CONST_5_BASE_HI(ctx
->screen
->gmem_base
>> 32) |
267 A6XX_TEX_CONST_5_DEPTH(1));
268 OUT_RING(state
, 0); /* texconst6 */
269 OUT_RING(state
, 0); /* texconst7 */
270 OUT_RING(state
, 0); /* texconst8 */
271 OUT_RING(state
, 0); /* texconst9 */
272 OUT_RING(state
, 0); /* texconst10 */
273 OUT_RING(state
, 0); /* texconst11 */
281 fd6_emit_textures(struct fd_pipe
*pipe
, struct fd_ringbuffer
*ring
,
282 enum pipe_shader_type type
, struct fd_texture_stateobj
*tex
,
283 unsigned bcolor_offset
,
284 /* can be NULL if no image/SSBO/fb state to merge in: */
285 const struct ir3_shader_variant
*v
, struct fd_context
*ctx
)
287 bool needs_border
= false;
288 unsigned opcode
, tex_samp_reg
, tex_const_reg
, tex_count_reg
;
289 enum a6xx_state_block sb
;
292 case PIPE_SHADER_VERTEX
:
294 opcode
= CP_LOAD_STATE6_GEOM
;
295 tex_samp_reg
= REG_A6XX_SP_VS_TEX_SAMP_LO
;
296 tex_const_reg
= REG_A6XX_SP_VS_TEX_CONST_LO
;
297 tex_count_reg
= REG_A6XX_SP_VS_TEX_COUNT
;
299 case PIPE_SHADER_TESS_CTRL
:
301 opcode
= CP_LOAD_STATE6_GEOM
;
302 tex_samp_reg
= REG_A6XX_SP_HS_TEX_SAMP_LO
;
303 tex_const_reg
= REG_A6XX_SP_HS_TEX_CONST_LO
;
304 tex_count_reg
= REG_A6XX_SP_HS_TEX_COUNT
;
306 case PIPE_SHADER_TESS_EVAL
:
308 opcode
= CP_LOAD_STATE6_GEOM
;
309 tex_samp_reg
= REG_A6XX_SP_DS_TEX_SAMP_LO
;
310 tex_const_reg
= REG_A6XX_SP_DS_TEX_CONST_LO
;
311 tex_count_reg
= REG_A6XX_SP_DS_TEX_COUNT
;
313 case PIPE_SHADER_GEOMETRY
:
315 opcode
= CP_LOAD_STATE6_GEOM
;
316 tex_samp_reg
= REG_A6XX_SP_GS_TEX_SAMP_LO
;
317 tex_const_reg
= REG_A6XX_SP_GS_TEX_CONST_LO
;
318 tex_count_reg
= REG_A6XX_SP_GS_TEX_COUNT
;
320 case PIPE_SHADER_FRAGMENT
:
322 opcode
= CP_LOAD_STATE6_FRAG
;
323 tex_samp_reg
= REG_A6XX_SP_FS_TEX_SAMP_LO
;
324 tex_const_reg
= REG_A6XX_SP_FS_TEX_CONST_LO
;
325 tex_count_reg
= REG_A6XX_SP_FS_TEX_COUNT
;
327 case PIPE_SHADER_COMPUTE
:
329 opcode
= CP_LOAD_STATE6_FRAG
;
330 tex_samp_reg
= REG_A6XX_SP_CS_TEX_SAMP_LO
;
331 tex_const_reg
= REG_A6XX_SP_CS_TEX_CONST_LO
;
332 tex_count_reg
= REG_A6XX_SP_CS_TEX_COUNT
;
335 unreachable("bad state block");
338 if (tex
->num_samplers
> 0) {
339 struct fd_ringbuffer
*state
=
340 fd_ringbuffer_new_object(pipe
, tex
->num_samplers
* 4 * 4);
341 for (unsigned i
= 0; i
< tex
->num_samplers
; i
++) {
342 static const struct fd6_sampler_stateobj dummy_sampler
= {};
343 const struct fd6_sampler_stateobj
*sampler
= tex
->samplers
[i
] ?
344 fd6_sampler_stateobj(tex
->samplers
[i
]) : &dummy_sampler
;
345 OUT_RING(state
, sampler
->texsamp0
);
346 OUT_RING(state
, sampler
->texsamp1
);
347 OUT_RING(state
, sampler
->texsamp2
|
348 A6XX_TEX_SAMP_2_BCOLOR_OFFSET((i
+ bcolor_offset
) * sizeof(struct bcolor_entry
)));
349 OUT_RING(state
, sampler
->texsamp3
);
350 needs_border
|= sampler
->needs_border
;
353 /* output sampler state: */
354 OUT_PKT7(ring
, opcode
, 3);
355 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(0) |
356 CP_LOAD_STATE6_0_STATE_TYPE(ST6_SHADER
) |
357 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
358 CP_LOAD_STATE6_0_STATE_BLOCK(sb
) |
359 CP_LOAD_STATE6_0_NUM_UNIT(tex
->num_samplers
));
360 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
362 OUT_PKT4(ring
, tex_samp_reg
, 2);
363 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
365 fd_ringbuffer_del(state
);
368 unsigned num_merged_textures
= tex
->num_textures
;
369 unsigned num_textures
= tex
->num_textures
;
371 num_merged_textures
+= v
->image_mapping
.num_tex
;
374 num_merged_textures
++;
376 /* There could be more bound textures than what the shader uses.
377 * Which isn't known at shader compile time. So in the case we
378 * are merging tex state, only emit the textures that the shader
379 * uses (since the image/SSBO related tex state comes immediately
382 num_textures
= v
->image_mapping
.tex_base
;
385 if (num_merged_textures
> 0) {
386 struct fd_ringbuffer
*state
=
387 fd_ringbuffer_new_object(pipe
, num_merged_textures
* 16 * 4);
388 for (unsigned i
= 0; i
< num_textures
; i
++) {
389 static const struct fd6_pipe_sampler_view dummy_view
= {};
390 const struct fd6_pipe_sampler_view
*view
= tex
->textures
[i
] ?
391 fd6_pipe_sampler_view(tex
->textures
[i
]) : &dummy_view
;
392 struct fd_resource
*rsc
= NULL
;
394 if (view
->base
.texture
)
395 rsc
= fd_resource(view
->base
.texture
);
397 OUT_RING(state
, view
->texconst0
);
398 OUT_RING(state
, view
->texconst1
);
399 OUT_RING(state
, view
->texconst2
);
400 OUT_RING(state
, view
->texconst3
);
403 if (view
->base
.format
== PIPE_FORMAT_X32_S8X24_UINT
)
405 OUT_RELOC(state
, rsc
->bo
, view
->offset
,
406 (uint64_t)view
->texconst5
<< 32, 0);
408 OUT_RING(state
, 0x00000000);
409 OUT_RING(state
, view
->texconst5
);
412 OUT_RING(state
, view
->texconst6
);
414 if (rsc
&& view
->ubwc_enabled
) {
415 OUT_RELOC(state
, rsc
->bo
, view
->ubwc_offset
, 0, 0);
421 OUT_RING(state
, view
->texconst9
);
422 OUT_RING(state
, view
->texconst10
);
423 OUT_RING(state
, view
->texconst11
);
431 const struct ir3_ibo_mapping
*mapping
= &v
->image_mapping
;
432 struct fd_shaderbuf_stateobj
*buf
= &ctx
->shaderbuf
[type
];
433 struct fd_shaderimg_stateobj
*img
= &ctx
->shaderimg
[type
];
435 for (unsigned i
= 0; i
< mapping
->num_tex
; i
++) {
436 unsigned idx
= mapping
->tex_to_image
[i
];
437 if (idx
& IBO_SSBO
) {
438 fd6_emit_ssbo_tex(state
, &buf
->sb
[idx
& ~IBO_SSBO
]);
440 fd6_emit_image_tex(state
, &img
->si
[idx
]);
445 fd6_emit_fb_tex(state
, ctx
);
449 /* emit texture state: */
450 OUT_PKT7(ring
, opcode
, 3);
451 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(0) |
452 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
453 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
454 CP_LOAD_STATE6_0_STATE_BLOCK(sb
) |
455 CP_LOAD_STATE6_0_NUM_UNIT(num_merged_textures
));
456 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
458 OUT_PKT4(ring
, tex_const_reg
, 2);
459 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
461 fd_ringbuffer_del(state
);
464 OUT_PKT4(ring
, tex_count_reg
, 1);
465 OUT_RING(ring
, num_merged_textures
);
470 /* Emits combined texture state, which also includes any Image/SSBO
471 * related texture state merged in (because we must have all texture
472 * state for a given stage in a single buffer). In the fast-path, if
473 * we don't need to merge in any image/ssbo related texture state, we
474 * just use cached texture stateobj. Otherwise we generate a single-
477 * TODO Is there some sane way we can still use cached texture stateobj
478 * with image/ssbo in use?
480 * returns whether border_color is required:
483 fd6_emit_combined_textures(struct fd_ringbuffer
*ring
, struct fd6_emit
*emit
,
484 enum pipe_shader_type type
, const struct ir3_shader_variant
*v
)
486 struct fd_context
*ctx
= emit
->ctx
;
487 bool needs_border
= false;
489 static const struct {
490 enum fd6_state_id state_id
;
491 unsigned enable_mask
;
492 } s
[PIPE_SHADER_TYPES
] = {
493 [PIPE_SHADER_VERTEX
] = { FD6_GROUP_VS_TEX
, ENABLE_ALL
},
494 [PIPE_SHADER_TESS_CTRL
] = { FD6_GROUP_HS_TEX
, ENABLE_ALL
},
495 [PIPE_SHADER_TESS_EVAL
] = { FD6_GROUP_DS_TEX
, ENABLE_ALL
},
496 [PIPE_SHADER_GEOMETRY
] = { FD6_GROUP_GS_TEX
, ENABLE_ALL
},
497 [PIPE_SHADER_FRAGMENT
] = { FD6_GROUP_FS_TEX
, ENABLE_DRAW
},
500 debug_assert(s
[type
].state_id
);
502 if (!v
->image_mapping
.num_tex
&& !v
->fb_read
) {
503 /* in the fast-path, when we don't have to mix in any image/SSBO
504 * related texture state, we can just lookup the stateobj and
507 * Also, framebuffer-read is a slow-path because an extra
508 * texture needs to be inserted.
510 * TODO we can probably simmplify things if we also treated
511 * border_color as a slow-path.. this way the tex state key
512 * wouldn't depend on bcolor_offset.. but fb_read might rather
513 * be *somehow* a fast-path if we eventually used it for PLS.
514 * I suppose there would be no harm in just *always* inserting
515 * an fb_read texture?
517 if ((ctx
->dirty_shader
[type
] & FD_DIRTY_SHADER_TEX
) &&
518 ctx
->tex
[type
].num_textures
> 0) {
519 struct fd6_texture_state
*tex
= fd6_texture_state(ctx
,
520 type
, &ctx
->tex
[type
]);
522 needs_border
|= tex
->needs_border
;
524 fd6_emit_add_group(emit
, tex
->stateobj
, s
[type
].state_id
,
525 s
[type
].enable_mask
);
528 /* In the slow-path, create a one-shot texture state object
529 * if either TEX|PROG|SSBO|IMAGE state is dirty:
531 if ((ctx
->dirty_shader
[type
] &
532 (FD_DIRTY_SHADER_TEX
| FD_DIRTY_SHADER_PROG
|
533 FD_DIRTY_SHADER_IMAGE
| FD_DIRTY_SHADER_SSBO
)) ||
535 struct fd_texture_stateobj
*tex
= &ctx
->tex
[type
];
536 struct fd_ringbuffer
*stateobj
=
537 fd_submit_new_ringbuffer(ctx
->batch
->submit
,
538 0x1000, FD_RINGBUFFER_STREAMING
);
539 unsigned bcolor_offset
=
540 fd6_border_color_offset(ctx
, type
, tex
);
542 needs_border
|= fd6_emit_textures(ctx
->pipe
, stateobj
, type
, tex
,
543 bcolor_offset
, v
, ctx
);
545 fd6_emit_take_group(emit
, stateobj
, s
[type
].state_id
,
546 s
[type
].enable_mask
);
553 static struct fd_ringbuffer
*
554 build_vbo_state(struct fd6_emit
*emit
)
556 const struct fd_vertex_state
*vtx
= emit
->vtx
;
558 struct fd_ringbuffer
*ring
= fd_submit_new_ringbuffer(emit
->ctx
->batch
->submit
,
559 4 * (1 + vtx
->vertexbuf
.count
* 4), FD_RINGBUFFER_STREAMING
);
561 OUT_PKT4(ring
, REG_A6XX_VFD_FETCH(0), 4 * vtx
->vertexbuf
.count
);
562 for (int32_t j
= 0; j
< vtx
->vertexbuf
.count
; j
++) {
563 const struct pipe_vertex_buffer
*vb
= &vtx
->vertexbuf
.vb
[j
];
564 struct fd_resource
*rsc
= fd_resource(vb
->buffer
.resource
);
571 uint32_t off
= vb
->buffer_offset
;
572 uint32_t size
= fd_bo_size(rsc
->bo
) - off
;
574 OUT_RELOC(ring
, rsc
->bo
, off
, 0, 0);
575 OUT_RING(ring
, size
); /* VFD_FETCH[j].SIZE */
576 OUT_RING(ring
, vb
->stride
); /* VFD_FETCH[j].STRIDE */
583 static enum a6xx_ztest_mode
584 compute_ztest_mode(struct fd6_emit
*emit
, bool lrz_valid
)
586 struct fd_context
*ctx
= emit
->ctx
;
587 struct pipe_framebuffer_state
*pfb
= &ctx
->batch
->framebuffer
;
588 struct fd6_zsa_stateobj
*zsa
= fd6_zsa_stateobj(ctx
->zsa
);
589 const struct ir3_shader_variant
*fs
= emit
->fs
;
591 if (fs
->no_earlyz
|| fs
->writes_pos
) {
593 } else if ((fs
->has_kill
|| zsa
->alpha_test
) &&
594 (zsa
->base
.depth
.writemask
|| !pfb
->zsbuf
)) {
595 /* Slightly odd, but seems like the hw wants us to select
596 * LATE_Z mode if there is no depth buffer + discard. Either
597 * that, or when occlusion query is enabled. See:
599 * dEQP-GLES31.functional.fbo.no_attachments.*
601 return lrz_valid
? A6XX_EARLY_LRZ_LATE_Z
: A6XX_LATE_Z
;
608 * Calculate normalized LRZ state based on zsa/prog/blend state, updating
609 * the zsbuf's lrz state as necessary to detect the cases where we need
612 static struct fd6_lrz_state
613 compute_lrz_state(struct fd6_emit
*emit
, bool binning_pass
)
615 struct fd_context
*ctx
= emit
->ctx
;
616 struct pipe_framebuffer_state
*pfb
= &ctx
->batch
->framebuffer
;
617 const struct ir3_shader_variant
*fs
= emit
->fs
;
618 struct fd6_lrz_state lrz
;
621 memset(&lrz
, 0, sizeof(lrz
));
623 lrz
.z_mode
= compute_ztest_mode(emit
, false);
628 struct fd6_blend_stateobj
*blend
= fd6_blend_stateobj(ctx
->blend
);
629 struct fd6_zsa_stateobj
*zsa
= fd6_zsa_stateobj(ctx
->zsa
);
630 struct fd_resource
*rsc
= fd_resource(pfb
->zsbuf
->texture
);
634 /* normalize lrz state: */
635 if (blend
->reads_dest
|| fs
->writes_pos
|| fs
->no_earlyz
|| fs
->has_kill
) {
641 /* if we change depthfunc direction, bail out on using LRZ. The
642 * LRZ buffer encodes a min/max depth value per block, but if
643 * we switch from GT/GE <-> LT/LE, those values cannot be
644 * interpreted properly.
646 if (zsa
->base
.depth
.enabled
&&
647 (rsc
->lrz_direction
!= FD_LRZ_UNKNOWN
) &&
648 (rsc
->lrz_direction
!= lrz
.direction
)) {
649 rsc
->lrz_valid
= false;
652 if (zsa
->invalidate_lrz
|| !rsc
->lrz_valid
) {
653 rsc
->lrz_valid
= false;
654 memset(&lrz
, 0, sizeof(lrz
));
657 if (fs
->no_earlyz
|| fs
->writes_pos
) {
664 lrz
.z_mode
= compute_ztest_mode(emit
, rsc
->lrz_valid
);
667 /* Once we start writing to the real depth buffer, we lock in the
668 * direction for LRZ.. if we have to skip a LRZ write for any
669 * reason, it is still safe to have LRZ until there is a direction
670 * reversal. Prior to the reversal, since we disabled LRZ writes
671 * in the "unsafe" cases, this just means that the LRZ test may
672 * not early-discard some things that end up not passing a later
673 * test (ie. be overly concervative). But once you have a reversal
674 * of direction, it is possible to increase/decrease the z value
675 * to the point where the overly-conservative test is incorrect.
677 if (zsa
->base
.depth
.writemask
) {
678 rsc
->lrz_direction
= lrz
.direction
;
684 static struct fd_ringbuffer
*
685 build_lrz(struct fd6_emit
*emit
, bool binning_pass
)
687 struct fd_context
*ctx
= emit
->ctx
;
688 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
689 struct fd6_lrz_state lrz
=
690 compute_lrz_state(emit
, binning_pass
);
692 /* If the LRZ state has not changed, we can skip the emit: */
693 if (!ctx
->last
.dirty
&&
694 !memcmp(&fd6_ctx
->last
.lrz
[binning_pass
], &lrz
, sizeof(lrz
)))
697 fd6_ctx
->last
.lrz
[binning_pass
] = lrz
;
699 struct fd_ringbuffer
*ring
= fd_submit_new_ringbuffer(ctx
->batch
->submit
,
700 8*4, FD_RINGBUFFER_STREAMING
);
702 OUT_REG(ring
, A6XX_GRAS_LRZ_CNTL(
703 .enable
= lrz
.enable
,
704 .lrz_write
= lrz
.write
,
705 .greater
= lrz
.direction
== FD_LRZ_GREATER
,
706 .z_test_enable
= lrz
.test
,
708 OUT_REG(ring
, A6XX_RB_LRZ_CNTL(
709 .enable
= lrz
.enable
,
712 OUT_REG(ring
, A6XX_RB_DEPTH_PLANE_CNTL(
713 .z_mode
= lrz
.z_mode
,
716 OUT_REG(ring
, A6XX_GRAS_SU_DEPTH_PLANE_CNTL(
717 .z_mode
= lrz
.z_mode
,
724 fd6_emit_streamout(struct fd_ringbuffer
*ring
, struct fd6_emit
*emit
, struct ir3_stream_output_info
*info
)
726 struct fd_context
*ctx
= emit
->ctx
;
727 const struct fd6_program_state
*prog
= fd6_emit_get_prog(emit
);
728 struct fd_streamout_stateobj
*so
= &ctx
->streamout
;
730 emit
->streamout_mask
= 0;
732 for (unsigned i
= 0; i
< so
->num_targets
; i
++) {
733 struct pipe_stream_output_target
*target
= so
->targets
[i
];
738 OUT_PKT4(ring
, REG_A6XX_VPC_SO_BUFFER_BASE_LO(i
), 3);
739 /* VPC_SO[i].BUFFER_BASE_LO: */
740 OUT_RELOC(ring
, fd_resource(target
->buffer
)->bo
, target
->buffer_offset
, 0, 0);
741 OUT_RING(ring
, target
->buffer_size
- target
->buffer_offset
);
743 if (so
->reset
& (1 << i
)) {
744 unsigned offset
= (so
->offsets
[i
] * info
->stride
[i
] * 4);
745 OUT_PKT4(ring
, REG_A6XX_VPC_SO_BUFFER_OFFSET(i
), 1);
746 OUT_RING(ring
, offset
);
748 OUT_PKT7(ring
, CP_MEM_TO_REG
, 3);
749 OUT_RING(ring
, CP_MEM_TO_REG_0_REG(REG_A6XX_VPC_SO_BUFFER_OFFSET(i
)) |
750 CP_MEM_TO_REG_0_SHIFT_BY_2
| CP_MEM_TO_REG_0_UNK31
|
751 CP_MEM_TO_REG_0_CNT(0));
752 OUT_RELOC(ring
, control_ptr(fd6_context(ctx
), flush_base
[i
].offset
));
755 OUT_PKT4(ring
, REG_A6XX_VPC_SO_FLUSH_BASE_LO(i
), 2);
756 OUT_RELOC(ring
, control_ptr(fd6_context(ctx
), flush_base
[i
]));
758 so
->reset
&= ~(1 << i
);
760 emit
->streamout_mask
|= (1 << i
);
763 if (emit
->streamout_mask
) {
764 fd6_emit_add_group(emit
, prog
->streamout_stateobj
, FD6_GROUP_SO
, ENABLE_ALL
);
766 /* If we transition from a draw with streamout to one without, turn
769 if (ctx
->last
.streamout_mask
!= 0) {
770 struct fd_ringbuffer
*obj
= fd_submit_new_ringbuffer(emit
->ctx
->batch
->submit
,
771 5 * 4, FD_RINGBUFFER_STREAMING
);
773 OUT_PKT7(obj
, CP_CONTEXT_REG_BUNCH
, 4);
774 OUT_RING(obj
, REG_A6XX_VPC_SO_CNTL
);
776 OUT_RING(obj
, REG_A6XX_VPC_SO_BUF_CNTL
);
779 fd6_emit_take_group(emit
, obj
, FD6_GROUP_SO
, ENABLE_ALL
);
783 ctx
->last
.streamout_mask
= emit
->streamout_mask
;
787 fd6_emit_state(struct fd_ringbuffer
*ring
, struct fd6_emit
*emit
)
789 struct fd_context
*ctx
= emit
->ctx
;
790 struct pipe_framebuffer_state
*pfb
= &ctx
->batch
->framebuffer
;
791 const struct fd6_program_state
*prog
= fd6_emit_get_prog(emit
);
792 const struct ir3_shader_variant
*vs
= emit
->vs
;
793 const struct ir3_shader_variant
*hs
= emit
->hs
;
794 const struct ir3_shader_variant
*ds
= emit
->ds
;
795 const struct ir3_shader_variant
*gs
= emit
->gs
;
796 const struct ir3_shader_variant
*fs
= emit
->fs
;
797 const enum fd_dirty_3d_state dirty
= emit
->dirty
;
798 bool needs_border
= false;
800 emit_marker6(ring
, 5);
802 /* NOTE: we track fb_read differently than _BLEND_ENABLED since
803 * we might at some point decide to do sysmem in some cases when
807 ctx
->batch
->gmem_reason
|= FD_GMEM_FB_READ
;
809 if (emit
->dirty
& FD_DIRTY_VTXSTATE
) {
810 struct fd6_vertex_stateobj
*vtx
= fd6_vertex_stateobj(ctx
->vtx
.vtx
);
812 fd6_emit_add_group(emit
, vtx
->stateobj
, FD6_GROUP_VTXSTATE
, ENABLE_ALL
);
815 if (emit
->dirty
& FD_DIRTY_VTXBUF
) {
816 struct fd_ringbuffer
*state
;
818 state
= build_vbo_state(emit
);
819 fd6_emit_take_group(emit
, state
, FD6_GROUP_VBO
, ENABLE_ALL
);
822 if (dirty
& FD_DIRTY_ZSA
) {
823 struct fd6_zsa_stateobj
*zsa
= fd6_zsa_stateobj(ctx
->zsa
);
825 if (util_format_is_pure_integer(pipe_surface_format(pfb
->cbufs
[0])))
826 fd6_emit_add_group(emit
, zsa
->stateobj_no_alpha
, FD6_GROUP_ZSA
, ENABLE_ALL
);
828 fd6_emit_add_group(emit
, zsa
->stateobj
, FD6_GROUP_ZSA
, ENABLE_ALL
);
831 if (dirty
& (FD_DIRTY_ZSA
| FD_DIRTY_BLEND
| FD_DIRTY_PROG
)) {
832 struct fd_ringbuffer
*state
;
834 state
= build_lrz(emit
, false);
836 fd6_emit_take_group(emit
, state
, FD6_GROUP_LRZ
, ENABLE_DRAW
);
839 state
= build_lrz(emit
, true);
841 fd6_emit_take_group(emit
, state
,
842 FD6_GROUP_LRZ_BINNING
, CP_SET_DRAW_STATE__0_BINNING
);
846 if (dirty
& FD_DIRTY_STENCIL_REF
) {
847 struct pipe_stencil_ref
*sr
= &ctx
->stencil_ref
;
849 OUT_PKT4(ring
, REG_A6XX_RB_STENCILREF
, 1);
850 OUT_RING(ring
, A6XX_RB_STENCILREF_REF(sr
->ref_value
[0]) |
851 A6XX_RB_STENCILREF_BFREF(sr
->ref_value
[1]));
854 /* NOTE: scissor enabled bit is part of rasterizer state, but
855 * fd_rasterizer_state_bind() will mark scissor dirty if needed:
857 if (dirty
& FD_DIRTY_SCISSOR
) {
858 struct fd_ringbuffer
*ring
= fd_submit_new_ringbuffer(
859 emit
->ctx
->batch
->submit
, 3*4, FD_RINGBUFFER_STREAMING
);
860 struct pipe_scissor_state
*scissor
= fd_context_get_scissor(ctx
);
863 A6XX_GRAS_SC_SCREEN_SCISSOR_TL(0,
867 A6XX_GRAS_SC_SCREEN_SCISSOR_BR(0,
868 .x
= MAX2(scissor
->maxx
, 1) - 1,
869 .y
= MAX2(scissor
->maxy
, 1) - 1
873 fd6_emit_take_group(emit
, ring
, FD6_GROUP_SCISSOR
, ENABLE_ALL
);
875 ctx
->batch
->max_scissor
.minx
= MIN2(ctx
->batch
->max_scissor
.minx
, scissor
->minx
);
876 ctx
->batch
->max_scissor
.miny
= MIN2(ctx
->batch
->max_scissor
.miny
, scissor
->miny
);
877 ctx
->batch
->max_scissor
.maxx
= MAX2(ctx
->batch
->max_scissor
.maxx
, scissor
->maxx
);
878 ctx
->batch
->max_scissor
.maxy
= MAX2(ctx
->batch
->max_scissor
.maxy
, scissor
->maxy
);
881 if (dirty
& FD_DIRTY_VIEWPORT
) {
882 struct pipe_scissor_state
*scissor
= &ctx
->viewport_scissor
;
885 A6XX_GRAS_CL_VPORT_XOFFSET(0, ctx
->viewport
.translate
[0]),
886 A6XX_GRAS_CL_VPORT_XSCALE(0, ctx
->viewport
.scale
[0]),
887 A6XX_GRAS_CL_VPORT_YOFFSET(0, ctx
->viewport
.translate
[1]),
888 A6XX_GRAS_CL_VPORT_YSCALE(0, ctx
->viewport
.scale
[1]),
889 A6XX_GRAS_CL_VPORT_ZOFFSET(0, ctx
->viewport
.translate
[2]),
890 A6XX_GRAS_CL_VPORT_ZSCALE(0, ctx
->viewport
.scale
[2])
894 A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL(0,
898 A6XX_GRAS_SC_VIEWPORT_SCISSOR_BR(0,
899 .x
= MAX2(scissor
->maxx
, 1) - 1,
900 .y
= MAX2(scissor
->maxy
, 1) - 1
904 unsigned guardband_x
= fd_calc_guardband(scissor
->maxx
- scissor
->minx
);
905 unsigned guardband_y
= fd_calc_guardband(scissor
->maxy
- scissor
->miny
);
907 OUT_REG(ring
, A6XX_GRAS_CL_GUARDBAND_CLIP_ADJ(
914 if (dirty
& FD_DIRTY_PROG
) {
915 fd6_emit_add_group(emit
, prog
->config_stateobj
, FD6_GROUP_PROG_CONFIG
, ENABLE_ALL
);
916 fd6_emit_add_group(emit
, prog
->stateobj
, FD6_GROUP_PROG
, ENABLE_DRAW
);
917 fd6_emit_add_group(emit
, prog
->binning_stateobj
,
918 FD6_GROUP_PROG_BINNING
, CP_SET_DRAW_STATE__0_BINNING
);
920 /* emit remaining streaming program state, ie. what depends on
921 * other emit state, so cannot be pre-baked.
923 struct fd_ringbuffer
*streaming
= fd6_program_interp_state(emit
);
925 fd6_emit_take_group(emit
, streaming
, FD6_GROUP_PROG_INTERP
, ENABLE_DRAW
);
928 if (dirty
& FD_DIRTY_RASTERIZER
) {
929 struct fd_ringbuffer
*stateobj
=
930 fd6_rasterizer_state(ctx
, emit
->primitive_restart
);
931 fd6_emit_add_group(emit
, stateobj
,
932 FD6_GROUP_RASTERIZER
, ENABLE_ALL
);
935 if (dirty
& (FD_DIRTY_FRAMEBUFFER
| FD_DIRTY_RASTERIZER_DISCARD
| FD_DIRTY_PROG
)) {
936 struct fd_ringbuffer
*ring
= fd_submit_new_ringbuffer(
937 emit
->ctx
->batch
->submit
, 5 * 4, FD_RINGBUFFER_STREAMING
);
939 unsigned nr
= pfb
->nr_cbufs
;
941 if (ctx
->rasterizer
->rasterizer_discard
)
944 OUT_PKT4(ring
, REG_A6XX_RB_FS_OUTPUT_CNTL0
, 2);
945 OUT_RING(ring
, COND(fs
->writes_pos
, A6XX_RB_FS_OUTPUT_CNTL0_FRAG_WRITES_Z
) |
946 COND(fs
->writes_smask
&& pfb
->samples
> 1,
947 A6XX_RB_FS_OUTPUT_CNTL0_FRAG_WRITES_SAMPMASK
));
948 OUT_RING(ring
, A6XX_RB_FS_OUTPUT_CNTL1_MRT(nr
));
950 OUT_PKT4(ring
, REG_A6XX_SP_FS_OUTPUT_CNTL1
, 1);
951 OUT_RING(ring
, A6XX_SP_FS_OUTPUT_CNTL1_MRT(nr
));
953 fd6_emit_take_group(emit
, ring
, FD6_GROUP_PROG_FB_RAST
, ENABLE_DRAW
);
956 fd6_emit_consts(emit
);
958 struct ir3_stream_output_info
*info
= &fd6_last_shader(prog
)->shader
->stream_output
;
959 if (info
->num_outputs
)
960 fd6_emit_streamout(ring
, emit
, info
);
962 if (dirty
& (FD_DIRTY_BLEND
| FD_DIRTY_SAMPLE_MASK
)) {
963 struct fd6_blend_variant
*blend
= fd6_blend_variant(ctx
->blend
,
964 pfb
->samples
, ctx
->sample_mask
);
965 fd6_emit_add_group(emit
, blend
->stateobj
, FD6_GROUP_BLEND
, ENABLE_DRAW
);
968 if (dirty
& FD_DIRTY_BLEND_COLOR
) {
969 struct pipe_blend_color
*bcolor
= &ctx
->blend_color
;
970 struct fd_ringbuffer
*ring
= fd_submit_new_ringbuffer(
971 emit
->ctx
->batch
->submit
, 5*4, FD_RINGBUFFER_STREAMING
);
974 A6XX_RB_BLEND_RED_F32(bcolor
->color
[0]),
975 A6XX_RB_BLEND_GREEN_F32(bcolor
->color
[1]),
976 A6XX_RB_BLEND_BLUE_F32(bcolor
->color
[2]),
977 A6XX_RB_BLEND_ALPHA_F32(bcolor
->color
[3])
980 fd6_emit_take_group(emit
, ring
, FD6_GROUP_BLEND_COLOR
, ENABLE_DRAW
);
983 needs_border
|= fd6_emit_combined_textures(ring
, emit
, PIPE_SHADER_VERTEX
, vs
);
985 needs_border
|= fd6_emit_combined_textures(ring
, emit
, PIPE_SHADER_TESS_CTRL
, hs
);
986 needs_border
|= fd6_emit_combined_textures(ring
, emit
, PIPE_SHADER_TESS_EVAL
, ds
);
989 needs_border
|= fd6_emit_combined_textures(ring
, emit
, PIPE_SHADER_GEOMETRY
, gs
);
991 needs_border
|= fd6_emit_combined_textures(ring
, emit
, PIPE_SHADER_FRAGMENT
, fs
);
994 emit_border_color(ctx
, ring
);
997 debug_assert(ir3_shader_nibo(hs
) == 0);
998 debug_assert(ir3_shader_nibo(ds
) == 0);
1001 debug_assert(ir3_shader_nibo(gs
) == 0);
1004 #define DIRTY_IBO (FD_DIRTY_SHADER_SSBO | FD_DIRTY_SHADER_IMAGE | \
1005 FD_DIRTY_SHADER_PROG)
1006 if (ctx
->dirty_shader
[PIPE_SHADER_FRAGMENT
] & DIRTY_IBO
) {
1007 struct fd_ringbuffer
*state
=
1008 fd6_build_ibo_state(ctx
, fs
, PIPE_SHADER_FRAGMENT
);
1009 struct fd_ringbuffer
*obj
= fd_submit_new_ringbuffer(
1010 ctx
->batch
->submit
, 0x100, FD_RINGBUFFER_STREAMING
);
1012 OUT_PKT7(obj
, CP_LOAD_STATE6
, 3);
1013 OUT_RING(obj
, CP_LOAD_STATE6_0_DST_OFF(0) |
1014 CP_LOAD_STATE6_0_STATE_TYPE(ST6_SHADER
) |
1015 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
1016 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_IBO
) |
1017 CP_LOAD_STATE6_0_NUM_UNIT(ir3_shader_nibo(fs
)));
1020 OUT_PKT4(obj
, REG_A6XX_SP_IBO_LO
, 2);
1023 /* TODO if we used CP_SET_DRAW_STATE for compute shaders, we could
1024 * de-duplicate this from program->config_stateobj
1026 OUT_PKT4(obj
, REG_A6XX_SP_IBO_COUNT
, 1);
1027 OUT_RING(obj
, ir3_shader_nibo(fs
));
1029 fd6_emit_ibo_consts(emit
, fs
, PIPE_SHADER_FRAGMENT
, ring
);
1031 fd6_emit_take_group(emit
, obj
, FD6_GROUP_IBO
, ENABLE_DRAW
);
1032 fd_ringbuffer_del(state
);
1035 if (emit
->num_groups
> 0) {
1036 OUT_PKT7(ring
, CP_SET_DRAW_STATE
, 3 * emit
->num_groups
);
1037 for (unsigned i
= 0; i
< emit
->num_groups
; i
++) {
1038 struct fd6_state_group
*g
= &emit
->groups
[i
];
1039 unsigned n
= g
->stateobj
?
1040 fd_ringbuffer_size(g
->stateobj
) / 4 : 0;
1042 debug_assert((g
->enable_mask
& ~ENABLE_ALL
) == 0);
1045 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(0) |
1046 CP_SET_DRAW_STATE__0_DISABLE
|
1048 CP_SET_DRAW_STATE__0_GROUP_ID(g
->group_id
));
1049 OUT_RING(ring
, 0x00000000);
1050 OUT_RING(ring
, 0x00000000);
1052 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(n
) |
1054 CP_SET_DRAW_STATE__0_GROUP_ID(g
->group_id
));
1055 OUT_RB(ring
, g
->stateobj
);
1059 fd_ringbuffer_del(g
->stateobj
);
1061 emit
->num_groups
= 0;
1066 fd6_emit_cs_state(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
,
1067 struct ir3_shader_variant
*cp
)
1069 enum fd_dirty_shader_state dirty
= ctx
->dirty_shader
[PIPE_SHADER_COMPUTE
];
1071 if (dirty
& (FD_DIRTY_SHADER_TEX
| FD_DIRTY_SHADER_PROG
|
1072 FD_DIRTY_SHADER_IMAGE
| FD_DIRTY_SHADER_SSBO
)) {
1073 struct fd_texture_stateobj
*tex
= &ctx
->tex
[PIPE_SHADER_COMPUTE
];
1074 unsigned bcolor_offset
= fd6_border_color_offset(ctx
, PIPE_SHADER_COMPUTE
, tex
);
1076 bool needs_border
= fd6_emit_textures(ctx
->pipe
, ring
, PIPE_SHADER_COMPUTE
, tex
,
1077 bcolor_offset
, cp
, ctx
);
1080 emit_border_color(ctx
, ring
);
1082 OUT_PKT4(ring
, REG_A6XX_SP_VS_TEX_COUNT
, 1);
1085 OUT_PKT4(ring
, REG_A6XX_SP_HS_TEX_COUNT
, 1);
1088 OUT_PKT4(ring
, REG_A6XX_SP_DS_TEX_COUNT
, 1);
1091 OUT_PKT4(ring
, REG_A6XX_SP_GS_TEX_COUNT
, 1);
1094 OUT_PKT4(ring
, REG_A6XX_SP_FS_TEX_COUNT
, 1);
1098 if (dirty
& (FD_DIRTY_SHADER_SSBO
| FD_DIRTY_SHADER_IMAGE
)) {
1099 struct fd_ringbuffer
*state
=
1100 fd6_build_ibo_state(ctx
, cp
, PIPE_SHADER_COMPUTE
);
1102 OUT_PKT7(ring
, CP_LOAD_STATE6_FRAG
, 3);
1103 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(0) |
1104 CP_LOAD_STATE6_0_STATE_TYPE(ST6_IBO
) |
1105 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
1106 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_CS_SHADER
) |
1107 CP_LOAD_STATE6_0_NUM_UNIT(ir3_shader_nibo(cp
)));
1108 OUT_RB(ring
, state
);
1110 OUT_PKT4(ring
, REG_A6XX_SP_CS_IBO_LO
, 2);
1111 OUT_RB(ring
, state
);
1113 OUT_PKT4(ring
, REG_A6XX_SP_CS_IBO_COUNT
, 1);
1114 OUT_RING(ring
, ir3_shader_nibo(cp
));
1116 fd_ringbuffer_del(state
);
1121 /* emit setup at begin of new cmdstream buffer (don't rely on previous
1122 * state, there could have been a context switch between ioctls):
1125 fd6_emit_restore(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
)
1127 //struct fd_context *ctx = batch->ctx;
1129 fd_log(batch
, "START RESTORE");
1131 fd6_cache_inv(batch
, ring
);
1133 OUT_REG(ring
, A6XX_HLSQ_INVALIDATE_CMD(
1142 .gfx_shared_const
= true,
1143 .cs_shared_const
= true,
1144 .gfx_bindless
= 0x1f,
1150 WRITE(REG_A6XX_RB_UNKNOWN_8E04
, 0x0);
1151 WRITE(REG_A6XX_SP_UNKNOWN_AE04
, 0x8);
1152 WRITE(REG_A6XX_SP_UNKNOWN_AE00
, 0);
1153 WRITE(REG_A6XX_SP_UNKNOWN_AE0F
, 0x3f);
1154 WRITE(REG_A6XX_SP_UNKNOWN_B605
, 0x44);
1155 WRITE(REG_A6XX_SP_UNKNOWN_B600
, 0x100000);
1156 WRITE(REG_A6XX_HLSQ_UNKNOWN_BE00
, 0x80);
1157 WRITE(REG_A6XX_HLSQ_UNKNOWN_BE01
, 0);
1159 WRITE(REG_A6XX_VPC_UNKNOWN_9600
, 0);
1160 WRITE(REG_A6XX_GRAS_UNKNOWN_8600
, 0x880);
1161 WRITE(REG_A6XX_HLSQ_UNKNOWN_BE04
, 0x80000);
1162 WRITE(REG_A6XX_SP_UNKNOWN_AE03
, 0x1430);
1163 WRITE(REG_A6XX_SP_IBO_COUNT
, 0);
1164 WRITE(REG_A6XX_SP_UNKNOWN_B182
, 0);
1165 WRITE(REG_A6XX_HLSQ_SHARED_CONSTS
, 0);
1166 WRITE(REG_A6XX_UCHE_UNKNOWN_0E12
, 0x3200000);
1167 WRITE(REG_A6XX_UCHE_CLIENT_PF
, 4);
1168 WRITE(REG_A6XX_RB_UNKNOWN_8E01
, 0x1);
1169 WRITE(REG_A6XX_SP_UNKNOWN_AB00
, 0x5);
1170 WRITE(REG_A6XX_VFD_ADD_OFFSET
, A6XX_VFD_ADD_OFFSET_VERTEX
);
1171 WRITE(REG_A6XX_RB_UNKNOWN_8811
, 0x00000010);
1172 WRITE(REG_A6XX_PC_MODE_CNTL
, 0x1f);
1174 WRITE(REG_A6XX_GRAS_UNKNOWN_8101
, 0);
1175 WRITE(REG_A6XX_GRAS_SAMPLE_CNTL
, 0);
1176 WRITE(REG_A6XX_GRAS_UNKNOWN_8110
, 0x2);
1178 WRITE(REG_A6XX_RB_UNKNOWN_8818
, 0);
1179 WRITE(REG_A6XX_RB_UNKNOWN_8819
, 0);
1180 WRITE(REG_A6XX_RB_UNKNOWN_881A
, 0);
1181 WRITE(REG_A6XX_RB_UNKNOWN_881B
, 0);
1182 WRITE(REG_A6XX_RB_UNKNOWN_881C
, 0);
1183 WRITE(REG_A6XX_RB_UNKNOWN_881D
, 0);
1184 WRITE(REG_A6XX_RB_UNKNOWN_881E
, 0);
1185 WRITE(REG_A6XX_RB_UNKNOWN_88F0
, 0);
1187 WRITE(REG_A6XX_VPC_POINT_COORD_INVERT
,
1188 A6XX_VPC_POINT_COORD_INVERT(0).value
);
1189 WRITE(REG_A6XX_VPC_UNKNOWN_9300
, 0);
1191 WRITE(REG_A6XX_VPC_SO_DISABLE
, A6XX_VPC_SO_DISABLE(true).value
);
1193 WRITE(REG_A6XX_PC_UNKNOWN_9990
, 0);
1194 WRITE(REG_A6XX_PC_UNKNOWN_9980
, 0);
1196 WRITE(REG_A6XX_PC_UNKNOWN_9B07
, 0);
1198 WRITE(REG_A6XX_SP_UNKNOWN_A81B
, 0);
1200 WRITE(REG_A6XX_SP_UNKNOWN_B183
, 0);
1202 WRITE(REG_A6XX_GRAS_UNKNOWN_8099
, 0);
1203 WRITE(REG_A6XX_GRAS_VS_LAYER_CNTL
, 0);
1204 WRITE(REG_A6XX_GRAS_UNKNOWN_80A0
, 2);
1205 WRITE(REG_A6XX_GRAS_UNKNOWN_80AF
, 0);
1206 WRITE(REG_A6XX_VPC_UNKNOWN_9210
, 0);
1207 WRITE(REG_A6XX_VPC_UNKNOWN_9211
, 0);
1208 WRITE(REG_A6XX_VPC_UNKNOWN_9602
, 0);
1209 WRITE(REG_A6XX_PC_UNKNOWN_9E72
, 0);
1210 WRITE(REG_A6XX_SP_TP_SAMPLE_CONFIG
, 0);
1211 /* NOTE blob seems to (mostly?) use 0xb2 for SP_TP_UNKNOWN_B309
1212 * but this seems to kill texture gather offsets.
1214 WRITE(REG_A6XX_SP_TP_UNKNOWN_B309
, 0xa2);
1215 WRITE(REG_A6XX_RB_SAMPLE_CONFIG
, 0);
1216 WRITE(REG_A6XX_GRAS_SAMPLE_CONFIG
, 0);
1217 WRITE(REG_A6XX_RB_Z_BOUNDS_MIN
, 0);
1218 WRITE(REG_A6XX_RB_Z_BOUNDS_MAX
, 0);
1219 WRITE(REG_A6XX_HLSQ_CONTROL_5_REG
, 0xfc);
1221 emit_marker6(ring
, 7);
1223 OUT_PKT4(ring
, REG_A6XX_VFD_MODE_CNTL
, 1);
1224 OUT_RING(ring
, 0x00000000); /* VFD_MODE_CNTL */
1226 WRITE(REG_A6XX_VFD_UNKNOWN_A008
, 0);
1228 OUT_PKT4(ring
, REG_A6XX_PC_MODE_CNTL
, 1);
1229 OUT_RING(ring
, 0x0000001f); /* PC_MODE_CNTL */
1231 /* we don't use this yet.. probably best to disable.. */
1232 OUT_PKT7(ring
, CP_SET_DRAW_STATE
, 3);
1233 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(0) |
1234 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
1235 CP_SET_DRAW_STATE__0_GROUP_ID(0));
1236 OUT_RING(ring
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
1237 OUT_RING(ring
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
1239 OUT_PKT4(ring
, REG_A6XX_VPC_SO_BUF_CNTL
, 1);
1240 OUT_RING(ring
, 0x00000000); /* VPC_SO_BUF_CNTL */
1242 OUT_PKT4(ring
, REG_A6XX_GRAS_LRZ_CNTL
, 1);
1243 OUT_RING(ring
, 0x00000000);
1245 OUT_PKT4(ring
, REG_A6XX_RB_LRZ_CNTL
, 1);
1246 OUT_RING(ring
, 0x00000000);
1248 fd_log(batch
, "END RESTORE");
1252 fd6_mem_to_mem(struct fd_ringbuffer
*ring
, struct pipe_resource
*dst
,
1253 unsigned dst_off
, struct pipe_resource
*src
, unsigned src_off
,
1254 unsigned sizedwords
)
1256 struct fd_bo
*src_bo
= fd_resource(src
)->bo
;
1257 struct fd_bo
*dst_bo
= fd_resource(dst
)->bo
;
1260 for (i
= 0; i
< sizedwords
; i
++) {
1261 OUT_PKT7(ring
, CP_MEM_TO_MEM
, 5);
1262 OUT_RING(ring
, 0x00000000);
1263 OUT_RELOC(ring
, dst_bo
, dst_off
, 0, 0);
1264 OUT_RELOC(ring
, src_bo
, src_off
, 0, 0);
1271 /* this is *almost* the same as fd6_cache_flush().. which I guess
1272 * could be re-worked to be something a bit more generic w/ param
1273 * indicating what needs to be flushed.. although that would mean
1274 * figuring out which events trigger what state to flush..
1277 fd6_framebuffer_barrier(struct fd_context
*ctx
)
1279 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
1280 struct fd_batch
*batch
= ctx
->batch
;
1281 struct fd_ringbuffer
*ring
= batch
->draw
;
1284 seqno
= fd6_event_write(batch
, ring
, RB_DONE_TS
, true);
1286 OUT_PKT7(ring
, CP_WAIT_REG_MEM
, 6);
1287 OUT_RING(ring
, CP_WAIT_REG_MEM_0_FUNCTION(WRITE_EQ
) |
1288 CP_WAIT_REG_MEM_0_POLL_MEMORY
);
1289 OUT_RELOC(ring
, control_ptr(fd6_ctx
, seqno
));
1290 OUT_RING(ring
, CP_WAIT_REG_MEM_3_REF(seqno
));
1291 OUT_RING(ring
, CP_WAIT_REG_MEM_4_MASK(~0));
1292 OUT_RING(ring
, CP_WAIT_REG_MEM_5_DELAY_LOOP_CYCLES(16));
1294 fd6_event_write(batch
, ring
, PC_CCU_FLUSH_COLOR_TS
, true);
1295 fd6_event_write(batch
, ring
, PC_CCU_FLUSH_DEPTH_TS
, true);
1297 seqno
= fd6_event_write(batch
, ring
, CACHE_FLUSH_TS
, true);
1299 fd6_event_write(batch
, ring
, 0x31, false);
1301 OUT_PKT7(ring
, CP_WAIT_MEM_GTE
, 4);
1302 OUT_RING(ring
, CP_WAIT_MEM_GTE_0_RESERVED(0));
1303 OUT_RELOC(ring
, control_ptr(fd6_ctx
, seqno
));
1304 OUT_RING(ring
, CP_WAIT_MEM_GTE_3_REF(seqno
));
1308 fd6_emit_init_screen(struct pipe_screen
*pscreen
)
1310 struct fd_screen
*screen
= fd_screen(pscreen
);
1311 screen
->emit_ib
= fd6_emit_ib
;
1312 screen
->mem_to_mem
= fd6_mem_to_mem
;
1316 fd6_emit_init(struct pipe_context
*pctx
)
1318 struct fd_context
*ctx
= fd_context(pctx
);
1319 ctx
->framebuffer_barrier
= fd6_framebuffer_barrier
;