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/u_format.h"
33 #include "util/u_viewport.h"
35 #include "freedreno_resource.h"
36 #include "freedreno_query_hw.h"
39 #include "fd6_blend.h"
40 #include "fd6_context.h"
41 #include "fd6_image.h"
42 #include "fd6_program.h"
43 #include "fd6_rasterizer.h"
44 #include "fd6_texture.h"
45 #include "fd6_format.h"
48 /* regid: base const register
49 * prsc or dwords: buffer containing constant values
50 * sizedwords: size of const value buffer
53 fd6_emit_const(struct fd_ringbuffer
*ring
, gl_shader_stage type
,
54 uint32_t regid
, uint32_t offset
, uint32_t sizedwords
,
55 const uint32_t *dwords
, struct pipe_resource
*prsc
)
57 uint32_t i
, sz
, align_sz
;
58 enum a6xx_state_src src
;
60 debug_assert((regid
% 4) == 0);
70 align_sz
= align(sz
, 4);
72 OUT_PKT7(ring
, fd6_stage2opcode(type
), 3 + align_sz
);
73 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(regid
/4) |
74 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
75 CP_LOAD_STATE6_0_STATE_SRC(src
) |
76 CP_LOAD_STATE6_0_STATE_BLOCK(fd6_stage2shadersb(type
)) |
77 CP_LOAD_STATE6_0_NUM_UNIT(DIV_ROUND_UP(sizedwords
, 4)));
79 struct fd_bo
*bo
= fd_resource(prsc
)->bo
;
80 OUT_RELOC(ring
, bo
, offset
, 0, 0);
82 OUT_RING(ring
, CP_LOAD_STATE6_1_EXT_SRC_ADDR(0));
83 OUT_RING(ring
, CP_LOAD_STATE6_2_EXT_SRC_ADDR_HI(0));
84 dwords
= (uint32_t *)&((uint8_t *)dwords
)[offset
];
87 for (i
= 0; i
< sz
; i
++) {
88 OUT_RING(ring
, dwords
[i
]);
91 /* Zero-pad to multiple of 4 dwords */
92 for (i
= sz
; i
< align_sz
; i
++) {
98 fd6_emit_const_bo(struct fd_ringbuffer
*ring
, gl_shader_stage type
, boolean write
,
99 uint32_t regid
, uint32_t num
, struct pipe_resource
**prscs
, uint32_t *offsets
)
101 uint32_t anum
= align(num
, 2);
104 debug_assert((regid
% 4) == 0);
106 OUT_PKT7(ring
, fd6_stage2opcode(type
), 3 + (2 * anum
));
107 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(regid
/4) |
108 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
)|
109 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
110 CP_LOAD_STATE6_0_STATE_BLOCK(fd6_stage2shadersb(type
)) |
111 CP_LOAD_STATE6_0_NUM_UNIT(anum
/2));
112 OUT_RING(ring
, CP_LOAD_STATE6_1_EXT_SRC_ADDR(0));
113 OUT_RING(ring
, CP_LOAD_STATE6_2_EXT_SRC_ADDR_HI(0));
115 for (i
= 0; i
< num
; i
++) {
118 OUT_RELOCW(ring
, fd_resource(prscs
[i
])->bo
, offsets
[i
], 0, 0);
120 OUT_RELOC(ring
, fd_resource(prscs
[i
])->bo
, offsets
[i
], 0, 0);
123 OUT_RING(ring
, 0xbad00000 | (i
<< 16));
124 OUT_RING(ring
, 0xbad00000 | (i
<< 16));
128 for (; i
< anum
; i
++) {
129 OUT_RING(ring
, 0xffffffff);
130 OUT_RING(ring
, 0xffffffff);
134 /* Border color layout is diff from a4xx/a5xx.. if it turns out to be
135 * the same as a6xx then move this somewhere common ;-)
137 * Entry layout looks like (total size, 0x60 bytes):
140 struct PACKED bcolor_entry
{
152 uint32_t z24
; /* also s8? */
153 uint16_t srgb
[4]; /* appears to duplicate fp16[], but clamped, used for srgb */
157 #define FD6_BORDER_COLOR_SIZE sizeof(struct bcolor_entry)
158 #define FD6_BORDER_COLOR_UPLOAD_SIZE (2 * PIPE_MAX_SAMPLERS * FD6_BORDER_COLOR_SIZE)
161 setup_border_colors(struct fd_texture_stateobj
*tex
, struct bcolor_entry
*entries
)
164 STATIC_ASSERT(sizeof(struct bcolor_entry
) == FD6_BORDER_COLOR_SIZE
);
166 for (i
= 0; i
< tex
->num_samplers
; i
++) {
167 struct bcolor_entry
*e
= &entries
[i
];
168 struct pipe_sampler_state
*sampler
= tex
->samplers
[i
];
169 union pipe_color_union
*bc
;
174 bc
= &sampler
->border_color
;
179 * The border colors need to be swizzled in a particular
180 * format-dependent order. Even though samplers don't know about
181 * formats, we can assume that with a GL state tracker, there's a
182 * 1:1 correspondence between sampler and texture. Take advantage
185 if ((i
>= tex
->num_textures
) || !tex
->textures
[i
])
188 struct pipe_sampler_view
*view
= tex
->textures
[i
];
189 enum pipe_format format
= view
->format
;
190 const struct util_format_description
*desc
=
191 util_format_description(format
);
199 unsigned char swiz
[4];
201 fd6_tex_swiz(format
, swiz
,
202 view
->swizzle_r
, view
->swizzle_g
,
203 view
->swizzle_b
, view
->swizzle_a
);
205 for (j
= 0; j
< 4; j
++) {
210 * HACK: for PIPE_FORMAT_X24S8_UINT we end up w/ the
211 * stencil border color value in bc->ui[0] but according
212 * to desc->swizzle and desc->channel, the .x/.w component
213 * is NONE and the stencil value is in the y component.
214 * Meanwhile the hardware wants this in the .w component
215 * for x24s8 and the .x component for x32_s8x24.
217 if ((format
== PIPE_FORMAT_X24S8_UINT
) ||
218 (format
== PIPE_FORMAT_X32_S8X24_UINT
)) {
221 cd
= (format
== PIPE_FORMAT_X32_S8X24_UINT
) ? 0 : 3;
230 if (desc
->channel
[c
].pure_integer
) {
232 switch (desc
->channel
[c
].size
) {
234 assert(desc
->channel
[c
].type
== UTIL_FORMAT_TYPE_UNSIGNED
);
235 clamped
= CLAMP(bc
->ui
[j
], 0, 0x3);
238 if (desc
->channel
[c
].type
== UTIL_FORMAT_TYPE_SIGNED
)
239 clamped
= CLAMP(bc
->i
[j
], -128, 127);
241 clamped
= CLAMP(bc
->ui
[j
], 0, 255);
244 assert(desc
->channel
[c
].type
== UTIL_FORMAT_TYPE_UNSIGNED
);
245 clamped
= CLAMP(bc
->ui
[j
], 0, 0x3ff);
248 if (desc
->channel
[c
].type
== UTIL_FORMAT_TYPE_SIGNED
)
249 clamped
= CLAMP(bc
->i
[j
], -32768, 32767);
251 clamped
= CLAMP(bc
->ui
[j
], 0, 65535);
254 assert(!"Unexpected bit size");
259 e
->fp32
[cd
] = bc
->ui
[j
];
260 e
->fp16
[cd
] = clamped
;
263 float f_u
= CLAMP(f
, 0, 1);
264 float f_s
= CLAMP(f
, -1, 1);
267 e
->fp16
[c
] = util_float_to_half(f
);
268 e
->srgb
[c
] = util_float_to_half(f_u
);
269 e
->ui16
[c
] = f_u
* 0xffff;
270 e
->si16
[c
] = f_s
* 0x7fff;
271 e
->ui8
[c
] = f_u
* 0xff;
272 e
->si8
[c
] = f_s
* 0x7f;
274 e
->rgb565
|= (int)(f_u
* 0x3f) << 5;
276 e
->rgb565
|= (int)(f_u
* 0x1f) << (c
? 11 : 0);
278 e
->rgb5a1
|= (f_u
> 0.5) ? 0x8000 : 0;
280 e
->rgb5a1
|= (int)(f_u
* 0x1f) << (c
* 5);
282 e
->rgb10a2
|= (int)(f_u
* 0x3) << 30;
284 e
->rgb10a2
|= (int)(f_u
* 0x3ff) << (c
* 10);
285 e
->rgba4
|= (int)(f_u
* 0xf) << (c
* 4);
287 e
->z24
= f_u
* 0xffffff;
292 memset(&e
->__pad0
, 0, sizeof(e
->__pad0
));
293 memset(&e
->__pad1
, 0, sizeof(e
->__pad1
));
299 emit_border_color(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
)
301 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
302 struct bcolor_entry
*entries
;
306 STATIC_ASSERT(sizeof(struct bcolor_entry
) == FD6_BORDER_COLOR_SIZE
);
308 u_upload_alloc(fd6_ctx
->border_color_uploader
,
309 0, FD6_BORDER_COLOR_UPLOAD_SIZE
,
310 FD6_BORDER_COLOR_UPLOAD_SIZE
, &off
,
311 &fd6_ctx
->border_color_buf
,
316 setup_border_colors(&ctx
->tex
[PIPE_SHADER_VERTEX
], &entries
[0]);
317 setup_border_colors(&ctx
->tex
[PIPE_SHADER_FRAGMENT
],
318 &entries
[ctx
->tex
[PIPE_SHADER_VERTEX
].num_samplers
]);
320 OUT_PKT4(ring
, REG_A6XX_SP_TP_BORDER_COLOR_BASE_ADDR_LO
, 2);
321 OUT_RELOC(ring
, fd_resource(fd6_ctx
->border_color_buf
)->bo
, off
, 0, 0);
323 u_upload_unmap(fd6_ctx
->border_color_uploader
);
327 fd6_emit_fb_tex(struct fd_ringbuffer
*state
, struct fd_context
*ctx
)
329 struct pipe_framebuffer_state
*pfb
= &ctx
->batch
->framebuffer
;
330 struct pipe_surface
*psurf
= pfb
->cbufs
[0];
331 struct fd_resource
*rsc
= fd_resource(psurf
->texture
);
333 uint32_t texconst0
= fd6_tex_const_0(psurf
->texture
, psurf
->u
.tex
.level
,
334 psurf
->format
, PIPE_SWIZZLE_X
, PIPE_SWIZZLE_Y
,
335 PIPE_SWIZZLE_Z
, PIPE_SWIZZLE_W
);
337 /* always TILE6_2 mode in GMEM.. which also means no swap: */
338 texconst0
&= ~(A6XX_TEX_CONST_0_SWAP__MASK
| A6XX_TEX_CONST_0_TILE_MODE__MASK
);
339 texconst0
|= A6XX_TEX_CONST_0_TILE_MODE(TILE6_2
);
341 OUT_RING(state
, texconst0
);
342 OUT_RING(state
, A6XX_TEX_CONST_1_WIDTH(pfb
->width
) |
343 A6XX_TEX_CONST_1_HEIGHT(pfb
->height
));
344 OUT_RINGP(state
, A6XX_TEX_CONST_2_TYPE(A6XX_TEX_2D
) |
345 A6XX_TEX_CONST_2_FETCHSIZE(TFETCH6_2_BYTE
),
346 &ctx
->batch
->fb_read_patches
);
347 OUT_RING(state
, A6XX_TEX_CONST_3_ARRAY_PITCH(rsc
->layer_size
));
349 OUT_RING(state
, A6XX_TEX_CONST_4_BASE_LO(ctx
->screen
->gmem_base
));
350 OUT_RING(state
, A6XX_TEX_CONST_5_BASE_HI(ctx
->screen
->gmem_base
>> 32) |
351 A6XX_TEX_CONST_5_DEPTH(1));
352 OUT_RING(state
, 0); /* texconst6 */
353 OUT_RING(state
, 0); /* texconst7 */
354 OUT_RING(state
, 0); /* texconst8 */
355 OUT_RING(state
, 0); /* texconst9 */
356 OUT_RING(state
, 0); /* texconst10 */
357 OUT_RING(state
, 0); /* texconst11 */
365 fd6_emit_textures(struct fd_pipe
*pipe
, struct fd_ringbuffer
*ring
,
366 enum pipe_shader_type type
, struct fd_texture_stateobj
*tex
,
367 unsigned bcolor_offset
,
368 /* can be NULL if no image/SSBO/fb state to merge in: */
369 const struct ir3_shader_variant
*v
, struct fd_context
*ctx
)
371 bool needs_border
= false;
372 unsigned opcode
, tex_samp_reg
, tex_const_reg
, tex_count_reg
;
373 enum a6xx_state_block sb
;
376 case PIPE_SHADER_VERTEX
:
378 opcode
= CP_LOAD_STATE6_GEOM
;
379 tex_samp_reg
= REG_A6XX_SP_VS_TEX_SAMP_LO
;
380 tex_const_reg
= REG_A6XX_SP_VS_TEX_CONST_LO
;
381 tex_count_reg
= REG_A6XX_SP_VS_TEX_COUNT
;
383 case PIPE_SHADER_FRAGMENT
:
385 opcode
= CP_LOAD_STATE6_FRAG
;
386 tex_samp_reg
= REG_A6XX_SP_FS_TEX_SAMP_LO
;
387 tex_const_reg
= REG_A6XX_SP_FS_TEX_CONST_LO
;
388 tex_count_reg
= REG_A6XX_SP_FS_TEX_COUNT
;
390 case PIPE_SHADER_COMPUTE
:
392 opcode
= CP_LOAD_STATE6_FRAG
;
393 tex_samp_reg
= REG_A6XX_SP_CS_TEX_SAMP_LO
;
394 tex_const_reg
= REG_A6XX_SP_CS_TEX_CONST_LO
;
395 tex_count_reg
= REG_A6XX_SP_CS_TEX_COUNT
;
398 unreachable("bad state block");
401 if (tex
->num_samplers
> 0) {
402 struct fd_ringbuffer
*state
=
403 fd_ringbuffer_new_object(pipe
, tex
->num_samplers
* 4 * 4);
404 for (unsigned i
= 0; i
< tex
->num_samplers
; i
++) {
405 static const struct fd6_sampler_stateobj dummy_sampler
= {};
406 const struct fd6_sampler_stateobj
*sampler
= tex
->samplers
[i
] ?
407 fd6_sampler_stateobj(tex
->samplers
[i
]) : &dummy_sampler
;
408 OUT_RING(state
, sampler
->texsamp0
);
409 OUT_RING(state
, sampler
->texsamp1
);
410 OUT_RING(state
, sampler
->texsamp2
|
411 A6XX_TEX_SAMP_2_BCOLOR_OFFSET((i
+ bcolor_offset
) * sizeof(struct bcolor_entry
)));
412 OUT_RING(state
, sampler
->texsamp3
);
413 needs_border
|= sampler
->needs_border
;
416 /* output sampler state: */
417 OUT_PKT7(ring
, opcode
, 3);
418 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(0) |
419 CP_LOAD_STATE6_0_STATE_TYPE(ST6_SHADER
) |
420 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
421 CP_LOAD_STATE6_0_STATE_BLOCK(sb
) |
422 CP_LOAD_STATE6_0_NUM_UNIT(tex
->num_samplers
));
423 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
425 OUT_PKT4(ring
, tex_samp_reg
, 2);
426 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
428 fd_ringbuffer_del(state
);
431 unsigned num_merged_textures
= tex
->num_textures
;
432 unsigned num_textures
= tex
->num_textures
;
434 num_merged_textures
+= v
->image_mapping
.num_tex
;
437 num_merged_textures
++;
439 /* There could be more bound textures than what the shader uses.
440 * Which isn't known at shader compile time. So in the case we
441 * are merging tex state, only emit the textures that the shader
442 * uses (since the image/SSBO related tex state comes immediately
445 num_textures
= v
->image_mapping
.tex_base
;
448 if (num_merged_textures
> 0) {
449 struct fd_ringbuffer
*state
=
450 fd_ringbuffer_new_object(pipe
, num_merged_textures
* 16 * 4);
451 for (unsigned i
= 0; i
< num_textures
; i
++) {
452 static const struct fd6_pipe_sampler_view dummy_view
= {};
453 const struct fd6_pipe_sampler_view
*view
= tex
->textures
[i
] ?
454 fd6_pipe_sampler_view(tex
->textures
[i
]) : &dummy_view
;
455 struct fd_resource
*rsc
= NULL
;
457 if (view
->base
.texture
)
458 rsc
= fd_resource(view
->base
.texture
);
460 OUT_RING(state
, view
->texconst0
);
461 OUT_RING(state
, view
->texconst1
);
462 OUT_RING(state
, view
->texconst2
);
463 OUT_RING(state
, view
->texconst3
);
466 if (view
->base
.format
== PIPE_FORMAT_X32_S8X24_UINT
)
468 OUT_RELOC(state
, rsc
->bo
, view
->offset
,
469 (uint64_t)view
->texconst5
<< 32, 0);
471 OUT_RING(state
, 0x00000000);
472 OUT_RING(state
, view
->texconst5
);
475 OUT_RING(state
, view
->texconst6
);
477 if (rsc
&& view
->ubwc_enabled
) {
478 OUT_RELOC(state
, rsc
->bo
, view
->ubwc_offset
, 0, 0);
484 OUT_RING(state
, view
->texconst9
);
485 OUT_RING(state
, view
->texconst10
);
486 OUT_RING(state
, view
->texconst11
);
494 const struct ir3_ibo_mapping
*mapping
= &v
->image_mapping
;
495 struct fd_shaderbuf_stateobj
*buf
= &ctx
->shaderbuf
[type
];
496 struct fd_shaderimg_stateobj
*img
= &ctx
->shaderimg
[type
];
498 for (unsigned i
= 0; i
< mapping
->num_tex
; i
++) {
499 unsigned idx
= mapping
->tex_to_image
[i
];
500 if (idx
& IBO_SSBO
) {
501 fd6_emit_ssbo_tex(state
, &buf
->sb
[idx
& ~IBO_SSBO
]);
503 fd6_emit_image_tex(state
, &img
->si
[idx
]);
508 fd6_emit_fb_tex(state
, ctx
);
512 /* emit texture state: */
513 OUT_PKT7(ring
, opcode
, 3);
514 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(0) |
515 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
516 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
517 CP_LOAD_STATE6_0_STATE_BLOCK(sb
) |
518 CP_LOAD_STATE6_0_NUM_UNIT(num_merged_textures
));
519 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
521 OUT_PKT4(ring
, tex_const_reg
, 2);
522 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
524 fd_ringbuffer_del(state
);
527 OUT_PKT4(ring
, tex_count_reg
, 1);
528 OUT_RING(ring
, num_merged_textures
);
533 /* Emits combined texture state, which also includes any Image/SSBO
534 * related texture state merged in (because we must have all texture
535 * state for a given stage in a single buffer). In the fast-path, if
536 * we don't need to merge in any image/ssbo related texture state, we
537 * just use cached texture stateobj. Otherwise we generate a single-
540 * TODO Is there some sane way we can still use cached texture stateobj
541 * with image/ssbo in use?
543 * returns whether border_color is required:
546 fd6_emit_combined_textures(struct fd_ringbuffer
*ring
, struct fd6_emit
*emit
,
547 enum pipe_shader_type type
, const struct ir3_shader_variant
*v
)
549 struct fd_context
*ctx
= emit
->ctx
;
550 bool needs_border
= false;
552 static const struct {
553 enum fd6_state_id state_id
;
554 unsigned enable_mask
;
555 } s
[PIPE_SHADER_TYPES
] = {
556 [PIPE_SHADER_VERTEX
] = { FD6_GROUP_VS_TEX
, 0x7 },
557 [PIPE_SHADER_FRAGMENT
] = { FD6_GROUP_FS_TEX
, 0x6 },
560 debug_assert(s
[type
].state_id
);
562 if (!v
->image_mapping
.num_tex
&& !v
->fb_read
) {
563 /* in the fast-path, when we don't have to mix in any image/SSBO
564 * related texture state, we can just lookup the stateobj and
567 * Also, framebuffer-read is a slow-path because an extra
568 * texture needs to be inserted.
570 * TODO we can probably simmplify things if we also treated
571 * border_color as a slow-path.. this way the tex state key
572 * wouldn't depend on bcolor_offset.. but fb_read might rather
573 * be *somehow* a fast-path if we eventually used it for PLS.
574 * I suppose there would be no harm in just *always* inserting
575 * an fb_read texture?
577 if ((ctx
->dirty_shader
[type
] & FD_DIRTY_SHADER_TEX
) &&
578 ctx
->tex
[type
].num_textures
> 0) {
579 struct fd6_texture_state
*tex
= fd6_texture_state(ctx
,
580 type
, &ctx
->tex
[type
]);
582 needs_border
|= tex
->needs_border
;
584 fd6_emit_add_group(emit
, tex
->stateobj
, s
[type
].state_id
,
585 s
[type
].enable_mask
);
588 /* In the slow-path, create a one-shot texture state object
589 * if either TEX|PROG|SSBO|IMAGE state is dirty:
591 if ((ctx
->dirty_shader
[type
] &
592 (FD_DIRTY_SHADER_TEX
| FD_DIRTY_SHADER_PROG
|
593 FD_DIRTY_SHADER_IMAGE
| FD_DIRTY_SHADER_SSBO
)) ||
595 struct fd_texture_stateobj
*tex
= &ctx
->tex
[type
];
596 struct fd_ringbuffer
*stateobj
=
597 fd_submit_new_ringbuffer(ctx
->batch
->submit
,
598 0x1000, FD_RINGBUFFER_STREAMING
);
599 unsigned bcolor_offset
=
600 fd6_border_color_offset(ctx
, type
, tex
);
602 needs_border
|= fd6_emit_textures(ctx
->pipe
, stateobj
, type
, tex
,
603 bcolor_offset
, v
, ctx
);
605 fd6_emit_add_group(emit
, stateobj
, s
[type
].state_id
,
606 s
[type
].enable_mask
);
608 fd_ringbuffer_del(stateobj
);
615 static struct fd_ringbuffer
*
616 build_vbo_state(struct fd6_emit
*emit
, const struct ir3_shader_variant
*vp
)
618 const struct fd_vertex_state
*vtx
= emit
->vtx
;
621 struct fd_ringbuffer
*ring
= fd_submit_new_ringbuffer(emit
->ctx
->batch
->submit
,
622 4 * (10 * vp
->inputs_count
+ 2), FD_RINGBUFFER_STREAMING
);
624 for (i
= 0, j
= 0; i
<= vp
->inputs_count
; i
++) {
625 if (vp
->inputs
[i
].sysval
)
627 if (vp
->inputs
[i
].compmask
) {
628 struct pipe_vertex_element
*elem
= &vtx
->vtx
->pipe
[i
];
629 const struct pipe_vertex_buffer
*vb
=
630 &vtx
->vertexbuf
.vb
[elem
->vertex_buffer_index
];
631 struct fd_resource
*rsc
= fd_resource(vb
->buffer
.resource
);
632 enum pipe_format pfmt
= elem
->src_format
;
633 enum a6xx_vtx_fmt fmt
= fd6_pipe2vtx(pfmt
);
634 bool isint
= util_format_is_pure_integer(pfmt
);
635 uint32_t off
= vb
->buffer_offset
+ elem
->src_offset
;
636 uint32_t size
= fd_bo_size(rsc
->bo
) - off
;
637 debug_assert(fmt
!= ~0);
640 /* see dEQP-GLES31.stress.vertex_attribute_binding.buffer_bounds.bind_vertex_buffer_offset_near_wrap_10
642 if (off
> fd_bo_size(rsc
->bo
))
646 OUT_PKT4(ring
, REG_A6XX_VFD_FETCH(j
), 4);
647 OUT_RELOC(ring
, rsc
->bo
, off
, 0, 0);
648 OUT_RING(ring
, size
); /* VFD_FETCH[j].SIZE */
649 OUT_RING(ring
, vb
->stride
); /* VFD_FETCH[j].STRIDE */
651 OUT_PKT4(ring
, REG_A6XX_VFD_DECODE(j
), 2);
652 OUT_RING(ring
, A6XX_VFD_DECODE_INSTR_IDX(j
) |
653 A6XX_VFD_DECODE_INSTR_FORMAT(fmt
) |
654 COND(elem
->instance_divisor
, A6XX_VFD_DECODE_INSTR_INSTANCED
) |
655 A6XX_VFD_DECODE_INSTR_SWAP(fd6_pipe2swap(pfmt
)) |
656 A6XX_VFD_DECODE_INSTR_UNK30
|
657 COND(!isint
, A6XX_VFD_DECODE_INSTR_FLOAT
));
658 OUT_RING(ring
, MAX2(1, elem
->instance_divisor
)); /* VFD_DECODE[j].STEP_RATE */
660 OUT_PKT4(ring
, REG_A6XX_VFD_DEST_CNTL(j
), 1);
661 OUT_RING(ring
, A6XX_VFD_DEST_CNTL_INSTR_WRITEMASK(vp
->inputs
[i
].compmask
) |
662 A6XX_VFD_DEST_CNTL_INSTR_REGID(vp
->inputs
[i
].regid
));
668 OUT_PKT4(ring
, REG_A6XX_VFD_CONTROL_0
, 1);
669 OUT_RING(ring
, A6XX_VFD_CONTROL_0_VTXCNT(j
) | (j
<< 8));
674 static struct fd_ringbuffer
*
675 build_lrz(struct fd6_emit
*emit
, bool binning_pass
)
677 struct fd6_zsa_stateobj
*zsa
= fd6_zsa_stateobj(emit
->ctx
->zsa
);
678 struct pipe_framebuffer_state
*pfb
= &emit
->ctx
->batch
->framebuffer
;
679 struct fd_resource
*rsc
= fd_resource(pfb
->zsbuf
->texture
);
680 uint32_t gras_lrz_cntl
= zsa
->gras_lrz_cntl
;
681 uint32_t rb_lrz_cntl
= zsa
->rb_lrz_cntl
;
683 struct fd_ringbuffer
*ring
= fd_submit_new_ringbuffer(emit
->ctx
->batch
->submit
,
684 16, FD_RINGBUFFER_STREAMING
);
686 if (emit
->no_lrz_write
|| !rsc
->lrz
|| !rsc
->lrz_valid
) {
689 } else if (binning_pass
&& zsa
->lrz_write
) {
690 gras_lrz_cntl
|= A6XX_GRAS_LRZ_CNTL_LRZ_WRITE
;
693 OUT_PKT4(ring
, REG_A6XX_GRAS_LRZ_CNTL
, 1);
694 OUT_RING(ring
, gras_lrz_cntl
);
696 OUT_PKT4(ring
, REG_A6XX_RB_LRZ_CNTL
, 1);
697 OUT_RING(ring
, rb_lrz_cntl
);
703 fd6_emit_streamout(struct fd_ringbuffer
*ring
, struct fd6_emit
*emit
, struct ir3_stream_output_info
*info
)
705 struct fd_context
*ctx
= emit
->ctx
;
706 const struct fd6_program_state
*prog
= fd6_emit_get_prog(emit
);
707 struct fd_streamout_stateobj
*so
= &ctx
->streamout
;
709 emit
->streamout_mask
= 0;
711 for (unsigned i
= 0; i
< so
->num_targets
; i
++) {
712 struct pipe_stream_output_target
*target
= so
->targets
[i
];
717 unsigned offset
= (so
->offsets
[i
] * info
->stride
[i
] * 4) +
718 target
->buffer_offset
;
720 OUT_PKT4(ring
, REG_A6XX_VPC_SO_BUFFER_BASE_LO(i
), 3);
721 /* VPC_SO[i].BUFFER_BASE_LO: */
722 OUT_RELOCW(ring
, fd_resource(target
->buffer
)->bo
, 0, 0, 0);
723 OUT_RING(ring
, target
->buffer_size
+ offset
);
725 OUT_PKT4(ring
, REG_A6XX_VPC_SO_BUFFER_OFFSET(i
), 3);
726 OUT_RING(ring
, offset
);
727 /* VPC_SO[i].FLUSH_BASE_LO/HI: */
728 // TODO just give hw a dummy addr for now.. we should
729 // be using this an then CP_MEM_TO_REG to set the
730 // VPC_SO[i].BUFFER_OFFSET for the next draw..
731 OUT_RELOCW(ring
, fd6_context(ctx
)->blit_mem
, 0x100, 0, 0);
733 emit
->streamout_mask
|= (1 << i
);
736 if (emit
->streamout_mask
) {
737 const struct fd6_streamout_state
*tf
= &prog
->tf
;
739 OUT_PKT7(ring
, CP_CONTEXT_REG_BUNCH
, 12 + (2 * tf
->prog_count
));
740 OUT_RING(ring
, REG_A6XX_VPC_SO_BUF_CNTL
);
741 OUT_RING(ring
, tf
->vpc_so_buf_cntl
);
742 OUT_RING(ring
, REG_A6XX_VPC_SO_NCOMP(0));
743 OUT_RING(ring
, tf
->ncomp
[0]);
744 OUT_RING(ring
, REG_A6XX_VPC_SO_NCOMP(1));
745 OUT_RING(ring
, tf
->ncomp
[1]);
746 OUT_RING(ring
, REG_A6XX_VPC_SO_NCOMP(2));
747 OUT_RING(ring
, tf
->ncomp
[2]);
748 OUT_RING(ring
, REG_A6XX_VPC_SO_NCOMP(3));
749 OUT_RING(ring
, tf
->ncomp
[3]);
750 OUT_RING(ring
, REG_A6XX_VPC_SO_CNTL
);
751 OUT_RING(ring
, A6XX_VPC_SO_CNTL_ENABLE
);
752 for (unsigned i
= 0; i
< tf
->prog_count
; i
++) {
753 OUT_RING(ring
, REG_A6XX_VPC_SO_PROG
);
754 OUT_RING(ring
, tf
->prog
[i
]);
757 OUT_PKT4(ring
, REG_A6XX_VPC_SO_OVERRIDE
, 1);
760 OUT_PKT7(ring
, CP_CONTEXT_REG_BUNCH
, 4);
761 OUT_RING(ring
, REG_A6XX_VPC_SO_CNTL
);
763 OUT_RING(ring
, REG_A6XX_VPC_SO_BUF_CNTL
);
766 OUT_PKT4(ring
, REG_A6XX_VPC_SO_OVERRIDE
, 1);
767 OUT_RING(ring
, A6XX_VPC_SO_OVERRIDE_SO_DISABLE
);
773 fd6_emit_state(struct fd_ringbuffer
*ring
, struct fd6_emit
*emit
)
775 struct fd_context
*ctx
= emit
->ctx
;
776 struct pipe_framebuffer_state
*pfb
= &ctx
->batch
->framebuffer
;
777 const struct fd6_program_state
*prog
= fd6_emit_get_prog(emit
);
778 const struct ir3_shader_variant
*vp
= emit
->vs
;
779 const struct ir3_shader_variant
*fp
= emit
->fs
;
780 const enum fd_dirty_3d_state dirty
= emit
->dirty
;
781 bool needs_border
= false;
783 emit_marker6(ring
, 5);
785 /* NOTE: we track fb_read differently than _BLEND_ENABLED since
786 * we might at some point decide to do sysmem in some cases when
790 ctx
->batch
->gmem_reason
|= FD_GMEM_FB_READ
;
792 if (emit
->dirty
& (FD_DIRTY_VTXBUF
| FD_DIRTY_VTXSTATE
)) {
793 struct fd_ringbuffer
*state
;
795 state
= build_vbo_state(emit
, emit
->vs
);
796 fd6_emit_add_group(emit
, state
, FD6_GROUP_VBO
, 0x6);
797 fd_ringbuffer_del(state
);
799 state
= build_vbo_state(emit
, emit
->bs
);
800 fd6_emit_add_group(emit
, state
, FD6_GROUP_VBO_BINNING
, 0x1);
801 fd_ringbuffer_del(state
);
804 if (dirty
& FD_DIRTY_ZSA
) {
805 struct fd6_zsa_stateobj
*zsa
= fd6_zsa_stateobj(ctx
->zsa
);
807 if (util_format_is_pure_integer(pipe_surface_format(pfb
->cbufs
[0])))
808 fd6_emit_add_group(emit
, zsa
->stateobj_no_alpha
, FD6_GROUP_ZSA
, 0x7);
810 fd6_emit_add_group(emit
, zsa
->stateobj
, FD6_GROUP_ZSA
, 0x7);
813 if ((dirty
& (FD_DIRTY_ZSA
| FD_DIRTY_PROG
)) && pfb
->zsbuf
) {
814 struct fd_ringbuffer
*state
;
816 state
= build_lrz(emit
, false);
817 fd6_emit_add_group(emit
, state
, FD6_GROUP_LRZ
, 0x6);
818 fd_ringbuffer_del(state
);
820 state
= build_lrz(emit
, true);
821 fd6_emit_add_group(emit
, state
, FD6_GROUP_LRZ_BINNING
, 0x1);
822 fd_ringbuffer_del(state
);
825 if (dirty
& FD_DIRTY_STENCIL_REF
) {
826 struct pipe_stencil_ref
*sr
= &ctx
->stencil_ref
;
828 OUT_PKT4(ring
, REG_A6XX_RB_STENCILREF
, 1);
829 OUT_RING(ring
, A6XX_RB_STENCILREF_REF(sr
->ref_value
[0]) |
830 A6XX_RB_STENCILREF_BFREF(sr
->ref_value
[1]));
833 /* NOTE: scissor enabled bit is part of rasterizer state: */
834 if (dirty
& (FD_DIRTY_SCISSOR
| FD_DIRTY_RASTERIZER
)) {
835 struct pipe_scissor_state
*scissor
= fd_context_get_scissor(ctx
);
837 OUT_PKT4(ring
, REG_A6XX_GRAS_SC_SCREEN_SCISSOR_TL_0
, 2);
838 OUT_RING(ring
, A6XX_GRAS_SC_SCREEN_SCISSOR_TL_0_X(scissor
->minx
) |
839 A6XX_GRAS_SC_SCREEN_SCISSOR_TL_0_Y(scissor
->miny
));
840 OUT_RING(ring
, A6XX_GRAS_SC_SCREEN_SCISSOR_TL_0_X(scissor
->maxx
- 1) |
841 A6XX_GRAS_SC_SCREEN_SCISSOR_TL_0_Y(scissor
->maxy
- 1));
843 ctx
->batch
->max_scissor
.minx
= MIN2(ctx
->batch
->max_scissor
.minx
, scissor
->minx
);
844 ctx
->batch
->max_scissor
.miny
= MIN2(ctx
->batch
->max_scissor
.miny
, scissor
->miny
);
845 ctx
->batch
->max_scissor
.maxx
= MAX2(ctx
->batch
->max_scissor
.maxx
, scissor
->maxx
);
846 ctx
->batch
->max_scissor
.maxy
= MAX2(ctx
->batch
->max_scissor
.maxy
, scissor
->maxy
);
849 if (dirty
& FD_DIRTY_VIEWPORT
) {
850 struct pipe_scissor_state
*scissor
= &ctx
->viewport_scissor
;
852 OUT_PKT4(ring
, REG_A6XX_GRAS_CL_VPORT_XOFFSET_0
, 6);
853 OUT_RING(ring
, A6XX_GRAS_CL_VPORT_XOFFSET_0(ctx
->viewport
.translate
[0]));
854 OUT_RING(ring
, A6XX_GRAS_CL_VPORT_XSCALE_0(ctx
->viewport
.scale
[0]));
855 OUT_RING(ring
, A6XX_GRAS_CL_VPORT_YOFFSET_0(ctx
->viewport
.translate
[1]));
856 OUT_RING(ring
, A6XX_GRAS_CL_VPORT_YSCALE_0(ctx
->viewport
.scale
[1]));
857 OUT_RING(ring
, A6XX_GRAS_CL_VPORT_ZOFFSET_0(ctx
->viewport
.translate
[2]));
858 OUT_RING(ring
, A6XX_GRAS_CL_VPORT_ZSCALE_0(ctx
->viewport
.scale
[2]));
860 OUT_PKT4(ring
, REG_A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0
, 2);
861 OUT_RING(ring
, A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0_X(scissor
->minx
) |
862 A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0_Y(scissor
->miny
));
863 OUT_RING(ring
, A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0_X(scissor
->maxx
- 1) |
864 A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0_Y(scissor
->maxy
- 1));
866 unsigned guardband_x
= fd_calc_guardband(scissor
->maxx
- scissor
->minx
);
867 unsigned guardband_y
= fd_calc_guardband(scissor
->maxy
- scissor
->miny
);
869 OUT_PKT4(ring
, REG_A6XX_GRAS_CL_GUARDBAND_CLIP_ADJ
, 1);
870 OUT_RING(ring
, A6XX_GRAS_CL_GUARDBAND_CLIP_ADJ_HORZ(guardband_x
) |
871 A6XX_GRAS_CL_GUARDBAND_CLIP_ADJ_VERT(guardband_y
));
874 if (dirty
& FD_DIRTY_PROG
) {
875 fd6_emit_add_group(emit
, prog
->config_stateobj
, FD6_GROUP_PROG_CONFIG
, 0x7);
876 fd6_emit_add_group(emit
, prog
->stateobj
, FD6_GROUP_PROG
, 0x6);
877 fd6_emit_add_group(emit
, prog
->binning_stateobj
,
878 FD6_GROUP_PROG_BINNING
, 0x1);
880 /* emit remaining non-stateobj program state, ie. what depends
881 * on other emit state, so cannot be pre-baked. This could
882 * be moved to a separate stateobj which is dynamically
885 fd6_program_emit(ring
, emit
);
888 if (dirty
& FD_DIRTY_RASTERIZER
) {
889 struct fd6_rasterizer_stateobj
*rasterizer
=
890 fd6_rasterizer_stateobj(ctx
->rasterizer
);
891 fd6_emit_add_group(emit
, rasterizer
->stateobj
,
892 FD6_GROUP_RASTERIZER
, 0x7);
895 /* Since the primitive restart state is not part of a tracked object, we
896 * re-emit this register every time.
898 if (emit
->info
&& ctx
->rasterizer
) {
899 struct fd6_rasterizer_stateobj
*rasterizer
=
900 fd6_rasterizer_stateobj(ctx
->rasterizer
);
901 OUT_PKT4(ring
, REG_A6XX_PC_UNKNOWN_9806
, 1);
903 OUT_PKT4(ring
, REG_A6XX_PC_UNKNOWN_9990
, 1);
905 OUT_PKT4(ring
, REG_A6XX_VFD_UNKNOWN_A008
, 1);
908 OUT_PKT4(ring
, REG_A6XX_PC_PRIMITIVE_CNTL_0
, 1);
909 OUT_RING(ring
, rasterizer
->pc_primitive_cntl
|
910 COND(emit
->info
->primitive_restart
&& emit
->info
->index_size
,
911 A6XX_PC_PRIMITIVE_CNTL_0_PRIMITIVE_RESTART
));
914 if (dirty
& (FD_DIRTY_FRAMEBUFFER
| FD_DIRTY_RASTERIZER
| FD_DIRTY_PROG
)) {
915 unsigned nr
= pfb
->nr_cbufs
;
917 if (ctx
->rasterizer
->rasterizer_discard
)
920 OUT_PKT4(ring
, REG_A6XX_RB_FS_OUTPUT_CNTL0
, 2);
921 OUT_RING(ring
, COND(fp
->writes_pos
, A6XX_RB_FS_OUTPUT_CNTL0_FRAG_WRITES_Z
) |
922 COND(fp
->writes_smask
&& pfb
->samples
> 1,
923 A6XX_RB_FS_OUTPUT_CNTL0_FRAG_WRITES_SAMPMASK
));
924 OUT_RING(ring
, A6XX_RB_FS_OUTPUT_CNTL1_MRT(nr
));
926 OUT_PKT4(ring
, REG_A6XX_SP_FS_OUTPUT_CNTL1
, 1);
927 OUT_RING(ring
, A6XX_SP_FS_OUTPUT_CNTL1_MRT(nr
));
930 #define DIRTY_CONST (FD_DIRTY_SHADER_PROG | FD_DIRTY_SHADER_CONST | \
931 FD_DIRTY_SHADER_SSBO | FD_DIRTY_SHADER_IMAGE)
933 if (ctx
->dirty_shader
[PIPE_SHADER_VERTEX
] & DIRTY_CONST
) {
934 struct fd_ringbuffer
*vsconstobj
= fd_submit_new_ringbuffer(
935 ctx
->batch
->submit
, 0x1000, FD_RINGBUFFER_STREAMING
);
937 ir3_emit_vs_consts(vp
, vsconstobj
, ctx
, emit
->info
);
938 fd6_emit_add_group(emit
, vsconstobj
, FD6_GROUP_VS_CONST
, 0x7);
939 fd_ringbuffer_del(vsconstobj
);
942 if (ctx
->dirty_shader
[PIPE_SHADER_FRAGMENT
] & DIRTY_CONST
) {
943 struct fd_ringbuffer
*fsconstobj
= fd_submit_new_ringbuffer(
944 ctx
->batch
->submit
, 0x1000, FD_RINGBUFFER_STREAMING
);
946 ir3_emit_fs_consts(fp
, fsconstobj
, ctx
);
947 fd6_emit_add_group(emit
, fsconstobj
, FD6_GROUP_FS_CONST
, 0x6);
948 fd_ringbuffer_del(fsconstobj
);
951 struct ir3_stream_output_info
*info
= &vp
->shader
->stream_output
;
952 if (info
->num_outputs
)
953 fd6_emit_streamout(ring
, emit
, info
);
955 if (dirty
& FD_DIRTY_BLEND
) {
956 struct fd6_blend_stateobj
*blend
= fd6_blend_stateobj(ctx
->blend
);
959 for (i
= 0; i
< pfb
->nr_cbufs
; i
++) {
960 enum pipe_format format
= pipe_surface_format(pfb
->cbufs
[i
]);
961 bool is_int
= util_format_is_pure_integer(format
);
962 bool has_alpha
= util_format_has_alpha(format
);
963 uint32_t control
= blend
->rb_mrt
[i
].control
;
964 uint32_t blend_control
= blend
->rb_mrt
[i
].blend_control_alpha
;
967 control
&= A6XX_RB_MRT_CONTROL_COMPONENT_ENABLE__MASK
;
968 control
|= A6XX_RB_MRT_CONTROL_ROP_CODE(ROP_COPY
);
972 blend_control
|= blend
->rb_mrt
[i
].blend_control_rgb
;
974 blend_control
|= blend
->rb_mrt
[i
].blend_control_no_alpha_rgb
;
975 control
&= ~A6XX_RB_MRT_CONTROL_BLEND2
;
978 OUT_PKT4(ring
, REG_A6XX_RB_MRT_CONTROL(i
), 1);
979 OUT_RING(ring
, control
);
981 OUT_PKT4(ring
, REG_A6XX_RB_MRT_BLEND_CONTROL(i
), 1);
982 OUT_RING(ring
, blend_control
);
985 OUT_PKT4(ring
, REG_A6XX_RB_DITHER_CNTL
, 1);
986 OUT_RING(ring
, blend
->rb_dither_cntl
);
988 OUT_PKT4(ring
, REG_A6XX_SP_BLEND_CNTL
, 1);
989 OUT_RING(ring
, blend
->sp_blend_cntl
);
992 if (dirty
& (FD_DIRTY_BLEND
| FD_DIRTY_SAMPLE_MASK
)) {
993 struct fd6_blend_stateobj
*blend
= fd6_blend_stateobj(ctx
->blend
);
995 OUT_PKT4(ring
, REG_A6XX_RB_BLEND_CNTL
, 1);
996 OUT_RING(ring
, blend
->rb_blend_cntl
|
997 A6XX_RB_BLEND_CNTL_SAMPLE_MASK(ctx
->sample_mask
));
1000 if (dirty
& FD_DIRTY_BLEND_COLOR
) {
1001 struct pipe_blend_color
*bcolor
= &ctx
->blend_color
;
1003 OUT_PKT4(ring
, REG_A6XX_RB_BLEND_RED_F32
, 4);
1004 OUT_RING(ring
, A6XX_RB_BLEND_RED_F32(bcolor
->color
[0]));
1005 OUT_RING(ring
, A6XX_RB_BLEND_GREEN_F32(bcolor
->color
[1]));
1006 OUT_RING(ring
, A6XX_RB_BLEND_BLUE_F32(bcolor
->color
[2]));
1007 OUT_RING(ring
, A6XX_RB_BLEND_ALPHA_F32(bcolor
->color
[3]));
1010 needs_border
|= fd6_emit_combined_textures(ring
, emit
, PIPE_SHADER_VERTEX
, vp
);
1011 needs_border
|= fd6_emit_combined_textures(ring
, emit
, PIPE_SHADER_FRAGMENT
, fp
);
1014 emit_border_color(ctx
, ring
);
1016 if (ctx
->dirty_shader
[PIPE_SHADER_FRAGMENT
] &
1017 (FD_DIRTY_SHADER_SSBO
| FD_DIRTY_SHADER_IMAGE
)) {
1018 struct fd_ringbuffer
*state
=
1019 fd6_build_ibo_state(ctx
, fp
, PIPE_SHADER_FRAGMENT
);
1020 struct fd_ringbuffer
*obj
= fd_submit_new_ringbuffer(
1021 ctx
->batch
->submit
, 9 * 4, FD_RINGBUFFER_STREAMING
);
1022 const struct ir3_ibo_mapping
*mapping
= &fp
->image_mapping
;
1024 OUT_PKT7(obj
, CP_LOAD_STATE6
, 3);
1025 OUT_RING(obj
, CP_LOAD_STATE6_0_DST_OFF(0) |
1026 CP_LOAD_STATE6_0_STATE_TYPE(ST6_SHADER
) |
1027 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
1028 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_IBO
) |
1029 CP_LOAD_STATE6_0_NUM_UNIT(mapping
->num_ibo
));
1032 OUT_PKT4(obj
, REG_A6XX_SP_IBO_LO
, 2);
1035 /* TODO if we used CP_SET_DRAW_STATE for compute shaders, we could
1036 * de-duplicate this from program->config_stateobj
1038 OUT_PKT4(obj
, REG_A6XX_SP_IBO_COUNT
, 1);
1039 OUT_RING(obj
, mapping
->num_ibo
);
1041 fd6_emit_add_group(emit
, obj
, FD6_GROUP_IBO
, 0x6);
1042 fd_ringbuffer_del(obj
);
1043 fd_ringbuffer_del(state
);
1046 if (emit
->num_groups
> 0) {
1047 OUT_PKT7(ring
, CP_SET_DRAW_STATE
, 3 * emit
->num_groups
);
1048 for (unsigned i
= 0; i
< emit
->num_groups
; i
++) {
1049 struct fd6_state_group
*g
= &emit
->groups
[i
];
1050 unsigned n
= fd_ringbuffer_size(g
->stateobj
) / 4;
1053 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(0) |
1054 CP_SET_DRAW_STATE__0_DISABLE
|
1055 CP_SET_DRAW_STATE__0_ENABLE_MASK(g
->enable_mask
) |
1056 CP_SET_DRAW_STATE__0_GROUP_ID(g
->group_id
));
1057 OUT_RING(ring
, 0x00000000);
1058 OUT_RING(ring
, 0x00000000);
1060 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(n
) |
1061 CP_SET_DRAW_STATE__0_ENABLE_MASK(g
->enable_mask
) |
1062 CP_SET_DRAW_STATE__0_GROUP_ID(g
->group_id
));
1063 OUT_RB(ring
, g
->stateobj
);
1066 fd_ringbuffer_del(g
->stateobj
);
1068 emit
->num_groups
= 0;
1073 fd6_emit_cs_state(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
,
1074 struct ir3_shader_variant
*cp
)
1076 enum fd_dirty_shader_state dirty
= ctx
->dirty_shader
[PIPE_SHADER_COMPUTE
];
1078 if (dirty
& (FD_DIRTY_SHADER_TEX
| FD_DIRTY_SHADER_PROG
|
1079 FD_DIRTY_SHADER_IMAGE
| FD_DIRTY_SHADER_SSBO
)) {
1080 struct fd_texture_stateobj
*tex
= &ctx
->tex
[PIPE_SHADER_COMPUTE
];
1081 unsigned bcolor_offset
= fd6_border_color_offset(ctx
, PIPE_SHADER_COMPUTE
, tex
);
1083 bool needs_border
= fd6_emit_textures(ctx
->pipe
, ring
, PIPE_SHADER_COMPUTE
, tex
,
1084 bcolor_offset
, cp
, ctx
);
1087 emit_border_color(ctx
, ring
);
1089 OUT_PKT4(ring
, REG_A6XX_SP_VS_TEX_COUNT
, 1);
1092 OUT_PKT4(ring
, REG_A6XX_SP_HS_TEX_COUNT
, 1);
1095 OUT_PKT4(ring
, REG_A6XX_SP_DS_TEX_COUNT
, 1);
1098 OUT_PKT4(ring
, REG_A6XX_SP_GS_TEX_COUNT
, 1);
1101 OUT_PKT4(ring
, REG_A6XX_SP_FS_TEX_COUNT
, 1);
1105 if (dirty
& (FD_DIRTY_SHADER_SSBO
| FD_DIRTY_SHADER_IMAGE
)) {
1106 struct fd_ringbuffer
*state
=
1107 fd6_build_ibo_state(ctx
, cp
, PIPE_SHADER_COMPUTE
);
1108 const struct ir3_ibo_mapping
*mapping
= &cp
->image_mapping
;
1110 OUT_PKT7(ring
, CP_LOAD_STATE6_FRAG
, 3);
1111 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(0) |
1112 CP_LOAD_STATE6_0_STATE_TYPE(ST6_IBO
) |
1113 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
1114 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_CS_SHADER
) |
1115 CP_LOAD_STATE6_0_NUM_UNIT(mapping
->num_ibo
));
1116 OUT_RB(ring
, state
);
1118 OUT_PKT4(ring
, REG_A6XX_SP_CS_IBO_LO
, 2);
1119 OUT_RB(ring
, state
);
1121 OUT_PKT4(ring
, REG_A6XX_SP_CS_IBO_COUNT
, 1);
1122 OUT_RING(ring
, mapping
->num_ibo
);
1124 fd_ringbuffer_del(state
);
1129 /* emit setup at begin of new cmdstream buffer (don't rely on previous
1130 * state, there could have been a context switch between ioctls):
1133 fd6_emit_restore(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
)
1135 //struct fd_context *ctx = batch->ctx;
1137 fd6_cache_inv(batch
, ring
);
1139 OUT_PKT4(ring
, REG_A6XX_HLSQ_UPDATE_CNTL
, 1);
1140 OUT_RING(ring
, 0xfffff);
1143 t7 opcode: CP_PERFCOUNTER_ACTION (50) (4 dwords)
1144 0000000500024048: 70d08003 00000000 001c5000 00000005
1145 t7 opcode: CP_PERFCOUNTER_ACTION (50) (4 dwords)
1146 0000000500024058: 70d08003 00000010 001c7000 00000005
1148 t7 opcode: CP_WAIT_FOR_IDLE (26) (1 dwords)
1149 0000000500024068: 70268000
1154 WRITE(REG_A6XX_RB_CCU_CNTL
, 0x7c400004);
1155 WRITE(REG_A6XX_RB_UNKNOWN_8E04
, 0x00100000);
1156 WRITE(REG_A6XX_SP_UNKNOWN_AE04
, 0x8);
1157 WRITE(REG_A6XX_SP_UNKNOWN_AE00
, 0);
1158 WRITE(REG_A6XX_SP_UNKNOWN_AE0F
, 0x3f);
1159 WRITE(REG_A6XX_SP_UNKNOWN_B605
, 0x44);
1160 WRITE(REG_A6XX_SP_UNKNOWN_B600
, 0x100000);
1161 WRITE(REG_A6XX_HLSQ_UNKNOWN_BE00
, 0x80);
1162 WRITE(REG_A6XX_HLSQ_UNKNOWN_BE01
, 0);
1164 WRITE(REG_A6XX_VPC_UNKNOWN_9600
, 0);
1165 WRITE(REG_A6XX_GRAS_UNKNOWN_8600
, 0x880);
1166 WRITE(REG_A6XX_HLSQ_UNKNOWN_BE04
, 0x80000);
1167 WRITE(REG_A6XX_SP_UNKNOWN_AE03
, 0x1430);
1168 WRITE(REG_A6XX_SP_IBO_COUNT
, 0);
1169 WRITE(REG_A6XX_SP_UNKNOWN_B182
, 0);
1170 WRITE(REG_A6XX_HLSQ_UNKNOWN_BB11
, 0);
1171 WRITE(REG_A6XX_UCHE_UNKNOWN_0E12
, 0x3200000);
1172 WRITE(REG_A6XX_UCHE_CLIENT_PF
, 4);
1173 WRITE(REG_A6XX_RB_UNKNOWN_8E01
, 0x1);
1174 WRITE(REG_A6XX_SP_UNKNOWN_AB00
, 0x5);
1175 WRITE(REG_A6XX_VFD_UNKNOWN_A009
, 0x00000001);
1176 WRITE(REG_A6XX_RB_UNKNOWN_8811
, 0x00000010);
1177 WRITE(REG_A6XX_PC_MODE_CNTL
, 0x1f);
1179 OUT_PKT4(ring
, REG_A6XX_RB_SRGB_CNTL
, 1);
1182 WRITE(REG_A6XX_GRAS_UNKNOWN_8101
, 0);
1183 WRITE(REG_A6XX_GRAS_SAMPLE_CNTL
, 0);
1184 WRITE(REG_A6XX_GRAS_UNKNOWN_8110
, 0x2);
1186 WRITE(REG_A6XX_RB_RENDER_CONTROL0
, 0x401);
1187 WRITE(REG_A6XX_RB_RENDER_CONTROL1
, 0);
1188 WRITE(REG_A6XX_RB_FS_OUTPUT_CNTL0
, 0);
1189 WRITE(REG_A6XX_RB_SAMPLE_CNTL
, 0);
1190 WRITE(REG_A6XX_RB_UNKNOWN_8818
, 0);
1191 WRITE(REG_A6XX_RB_UNKNOWN_8819
, 0);
1192 WRITE(REG_A6XX_RB_UNKNOWN_881A
, 0);
1193 WRITE(REG_A6XX_RB_UNKNOWN_881B
, 0);
1194 WRITE(REG_A6XX_RB_UNKNOWN_881C
, 0);
1195 WRITE(REG_A6XX_RB_UNKNOWN_881D
, 0);
1196 WRITE(REG_A6XX_RB_UNKNOWN_881E
, 0);
1197 WRITE(REG_A6XX_RB_UNKNOWN_88F0
, 0);
1199 WRITE(REG_A6XX_VPC_UNKNOWN_9101
, 0xffff00);
1200 WRITE(REG_A6XX_VPC_UNKNOWN_9107
, 0);
1202 WRITE(REG_A6XX_VPC_UNKNOWN_9236
,
1203 A6XX_VPC_UNKNOWN_9236_POINT_COORD_INVERT(0));
1204 WRITE(REG_A6XX_VPC_UNKNOWN_9300
, 0);
1206 WRITE(REG_A6XX_VPC_SO_OVERRIDE
, A6XX_VPC_SO_OVERRIDE_SO_DISABLE
);
1208 WRITE(REG_A6XX_PC_UNKNOWN_9801
, 0);
1209 WRITE(REG_A6XX_PC_UNKNOWN_9806
, 0);
1210 WRITE(REG_A6XX_PC_UNKNOWN_9980
, 0);
1212 WRITE(REG_A6XX_PC_UNKNOWN_9B06
, 0);
1213 WRITE(REG_A6XX_PC_UNKNOWN_9B06
, 0);
1215 WRITE(REG_A6XX_SP_UNKNOWN_A81B
, 0);
1217 WRITE(REG_A6XX_SP_UNKNOWN_B183
, 0);
1219 WRITE(REG_A6XX_GRAS_UNKNOWN_8099
, 0);
1220 WRITE(REG_A6XX_GRAS_UNKNOWN_809B
, 0);
1221 WRITE(REG_A6XX_GRAS_UNKNOWN_80A0
, 2);
1222 WRITE(REG_A6XX_GRAS_UNKNOWN_80AF
, 0);
1223 WRITE(REG_A6XX_VPC_UNKNOWN_9210
, 0);
1224 WRITE(REG_A6XX_VPC_UNKNOWN_9211
, 0);
1225 WRITE(REG_A6XX_VPC_UNKNOWN_9602
, 0);
1226 WRITE(REG_A6XX_PC_UNKNOWN_9981
, 0x3);
1227 WRITE(REG_A6XX_PC_UNKNOWN_9E72
, 0);
1228 WRITE(REG_A6XX_VPC_UNKNOWN_9108
, 0x3);
1229 WRITE(REG_A6XX_SP_TP_UNKNOWN_B304
, 0);
1230 /* NOTE blob seems to (mostly?) use 0xb2 for SP_TP_UNKNOWN_B309
1231 * but this seems to kill texture gather offsets.
1233 WRITE(REG_A6XX_SP_TP_UNKNOWN_B309
, 0xa2);
1234 WRITE(REG_A6XX_RB_UNKNOWN_8804
, 0);
1235 WRITE(REG_A6XX_GRAS_UNKNOWN_80A4
, 0);
1236 WRITE(REG_A6XX_GRAS_UNKNOWN_80A5
, 0);
1237 WRITE(REG_A6XX_GRAS_UNKNOWN_80A6
, 0);
1238 WRITE(REG_A6XX_RB_UNKNOWN_8805
, 0);
1239 WRITE(REG_A6XX_RB_UNKNOWN_8806
, 0);
1240 WRITE(REG_A6XX_RB_UNKNOWN_8878
, 0);
1241 WRITE(REG_A6XX_RB_UNKNOWN_8879
, 0);
1242 WRITE(REG_A6XX_HLSQ_CONTROL_5_REG
, 0xfc);
1244 emit_marker6(ring
, 7);
1246 OUT_PKT4(ring
, REG_A6XX_VFD_MODE_CNTL
, 1);
1247 OUT_RING(ring
, 0x00000000); /* VFD_MODE_CNTL */
1249 WRITE(REG_A6XX_VFD_UNKNOWN_A008
, 0);
1251 OUT_PKT4(ring
, REG_A6XX_PC_MODE_CNTL
, 1);
1252 OUT_RING(ring
, 0x0000001f); /* PC_MODE_CNTL */
1254 /* we don't use this yet.. probably best to disable.. */
1255 OUT_PKT7(ring
, CP_SET_DRAW_STATE
, 3);
1256 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(0) |
1257 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
1258 CP_SET_DRAW_STATE__0_GROUP_ID(0));
1259 OUT_RING(ring
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
1260 OUT_RING(ring
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
1262 OUT_PKT4(ring
, REG_A6XX_VPC_SO_BUF_CNTL
, 1);
1263 OUT_RING(ring
, 0x00000000); /* VPC_SO_BUF_CNTL */
1265 OUT_PKT4(ring
, REG_A6XX_SP_HS_CTRL_REG0
, 1);
1266 OUT_RING(ring
, 0x00000000);
1268 OUT_PKT4(ring
, REG_A6XX_SP_GS_CTRL_REG0
, 1);
1269 OUT_RING(ring
, 0x00000000);
1271 OUT_PKT4(ring
, REG_A6XX_GRAS_LRZ_CNTL
, 1);
1272 OUT_RING(ring
, 0x00000000);
1274 OUT_PKT4(ring
, REG_A6XX_RB_LRZ_CNTL
, 1);
1275 OUT_RING(ring
, 0x00000000);
1279 fd6_mem_to_mem(struct fd_ringbuffer
*ring
, struct pipe_resource
*dst
,
1280 unsigned dst_off
, struct pipe_resource
*src
, unsigned src_off
,
1281 unsigned sizedwords
)
1283 struct fd_bo
*src_bo
= fd_resource(src
)->bo
;
1284 struct fd_bo
*dst_bo
= fd_resource(dst
)->bo
;
1287 for (i
= 0; i
< sizedwords
; i
++) {
1288 OUT_PKT7(ring
, CP_MEM_TO_MEM
, 5);
1289 OUT_RING(ring
, 0x00000000);
1290 OUT_RELOCW(ring
, dst_bo
, dst_off
, 0, 0);
1291 OUT_RELOC (ring
, src_bo
, src_off
, 0, 0);
1298 /* this is *almost* the same as fd6_cache_flush().. which I guess
1299 * could be re-worked to be something a bit more generic w/ param
1300 * indicating what needs to be flushed.. although that would mean
1301 * figuring out which events trigger what state to flush..
1304 fd6_framebuffer_barrier(struct fd_context
*ctx
)
1306 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
1307 struct fd_batch
*batch
= ctx
->batch
;
1308 struct fd_ringbuffer
*ring
= batch
->draw
;
1311 seqno
= fd6_event_write(batch
, ring
, CACHE_FLUSH_AND_INV_EVENT
, true);
1313 OUT_PKT7(ring
, CP_WAIT_REG_MEM
, 6);
1314 OUT_RING(ring
, 0x00000013);
1315 OUT_RELOC(ring
, fd6_ctx
->blit_mem
, 0, 0, 0);
1316 OUT_RING(ring
, seqno
);
1317 OUT_RING(ring
, 0xffffffff);
1318 OUT_RING(ring
, 0x00000010);
1320 fd6_event_write(batch
, ring
, UNK_1D
, true);
1321 fd6_event_write(batch
, ring
, UNK_1C
, true);
1323 seqno
= fd6_event_write(batch
, ring
, CACHE_FLUSH_TS
, true);
1325 fd6_event_write(batch
, ring
, 0x31, false);
1327 OUT_PKT7(ring
, CP_UNK_A6XX_14
, 4);
1328 OUT_RING(ring
, 0x00000000);
1329 OUT_RELOC(ring
, fd6_ctx
->blit_mem
, 0, 0, 0);
1330 OUT_RING(ring
, seqno
);
1334 fd6_emit_init(struct pipe_context
*pctx
)
1336 struct fd_context
*ctx
= fd_context(pctx
);
1337 ctx
->emit_const
= fd6_emit_const
;
1338 ctx
->emit_const_bo
= fd6_emit_const_bo
;
1339 ctx
->emit_ib
= fd6_emit_ib
;
1340 ctx
->mem_to_mem
= fd6_mem_to_mem
;
1341 ctx
->framebuffer_barrier
= fd6_framebuffer_barrier
;