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_context.h"
42 #include "fd6_image.h"
43 #include "fd6_program.h"
44 #include "fd6_rasterizer.h"
45 #include "fd6_texture.h"
46 #include "fd6_format.h"
49 /* regid: base const register
50 * prsc or dwords: buffer containing constant values
51 * sizedwords: size of const value buffer
54 fd6_emit_const(struct fd_ringbuffer
*ring
, gl_shader_stage type
,
55 uint32_t regid
, uint32_t offset
, uint32_t sizedwords
,
56 const uint32_t *dwords
, struct pipe_resource
*prsc
)
58 uint32_t i
, sz
, align_sz
;
59 enum a6xx_state_src src
;
61 debug_assert((regid
% 4) == 0);
71 align_sz
= align(sz
, 4);
73 OUT_PKT7(ring
, fd6_stage2opcode(type
), 3 + align_sz
);
74 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(regid
/4) |
75 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
76 CP_LOAD_STATE6_0_STATE_SRC(src
) |
77 CP_LOAD_STATE6_0_STATE_BLOCK(fd6_stage2shadersb(type
)) |
78 CP_LOAD_STATE6_0_NUM_UNIT(DIV_ROUND_UP(sizedwords
, 4)));
80 struct fd_bo
*bo
= fd_resource(prsc
)->bo
;
81 OUT_RELOC(ring
, bo
, offset
, 0, 0);
83 OUT_RING(ring
, CP_LOAD_STATE6_1_EXT_SRC_ADDR(0));
84 OUT_RING(ring
, CP_LOAD_STATE6_2_EXT_SRC_ADDR_HI(0));
85 dwords
= (uint32_t *)&((uint8_t *)dwords
)[offset
];
88 for (i
= 0; i
< sz
; i
++) {
89 OUT_RING(ring
, dwords
[i
]);
92 /* Zero-pad to multiple of 4 dwords */
93 for (i
= sz
; i
< align_sz
; i
++) {
99 fd6_emit_const_bo(struct fd_ringbuffer
*ring
, gl_shader_stage type
, boolean write
,
100 uint32_t regid
, uint32_t num
, struct pipe_resource
**prscs
, uint32_t *offsets
)
102 uint32_t anum
= align(num
, 2);
105 debug_assert((regid
% 4) == 0);
107 OUT_PKT7(ring
, fd6_stage2opcode(type
), 3 + (2 * anum
));
108 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(regid
/4) |
109 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
)|
110 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
111 CP_LOAD_STATE6_0_STATE_BLOCK(fd6_stage2shadersb(type
)) |
112 CP_LOAD_STATE6_0_NUM_UNIT(anum
/2));
113 OUT_RING(ring
, CP_LOAD_STATE6_1_EXT_SRC_ADDR(0));
114 OUT_RING(ring
, CP_LOAD_STATE6_2_EXT_SRC_ADDR_HI(0));
116 for (i
= 0; i
< num
; i
++) {
119 OUT_RELOCW(ring
, fd_resource(prscs
[i
])->bo
, offsets
[i
], 0, 0);
121 OUT_RELOC(ring
, fd_resource(prscs
[i
])->bo
, offsets
[i
], 0, 0);
124 OUT_RING(ring
, 0xbad00000 | (i
<< 16));
125 OUT_RING(ring
, 0xbad00000 | (i
<< 16));
129 for (; i
< anum
; i
++) {
130 OUT_RING(ring
, 0xffffffff);
131 OUT_RING(ring
, 0xffffffff);
135 /* Border color layout is diff from a4xx/a5xx.. if it turns out to be
136 * the same as a6xx then move this somewhere common ;-)
138 * Entry layout looks like (total size, 0x60 bytes):
141 struct PACKED bcolor_entry
{
153 uint32_t z24
; /* also s8? */
154 uint16_t srgb
[4]; /* appears to duplicate fp16[], but clamped, used for srgb */
158 #define FD6_BORDER_COLOR_SIZE sizeof(struct bcolor_entry)
159 #define FD6_BORDER_COLOR_UPLOAD_SIZE (2 * PIPE_MAX_SAMPLERS * FD6_BORDER_COLOR_SIZE)
162 setup_border_colors(struct fd_texture_stateobj
*tex
, struct bcolor_entry
*entries
)
165 STATIC_ASSERT(sizeof(struct bcolor_entry
) == FD6_BORDER_COLOR_SIZE
);
167 for (i
= 0; i
< tex
->num_samplers
; i
++) {
168 struct bcolor_entry
*e
= &entries
[i
];
169 struct pipe_sampler_state
*sampler
= tex
->samplers
[i
];
170 union pipe_color_union
*bc
;
175 bc
= &sampler
->border_color
;
180 * The border colors need to be swizzled in a particular
181 * format-dependent order. Even though samplers don't know about
182 * formats, we can assume that with a GL state tracker, there's a
183 * 1:1 correspondence between sampler and texture. Take advantage
186 if ((i
>= tex
->num_textures
) || !tex
->textures
[i
])
189 struct pipe_sampler_view
*view
= tex
->textures
[i
];
190 enum pipe_format format
= view
->format
;
191 const struct util_format_description
*desc
=
192 util_format_description(format
);
200 unsigned char swiz
[4];
202 fd6_tex_swiz(format
, swiz
,
203 view
->swizzle_r
, view
->swizzle_g
,
204 view
->swizzle_b
, view
->swizzle_a
);
206 for (j
= 0; j
< 4; j
++) {
211 * HACK: for PIPE_FORMAT_X24S8_UINT we end up w/ the
212 * stencil border color value in bc->ui[0] but according
213 * to desc->swizzle and desc->channel, the .x/.w component
214 * is NONE and the stencil value is in the y component.
215 * Meanwhile the hardware wants this in the .w component
216 * for x24s8 and the .x component for x32_s8x24.
218 if ((format
== PIPE_FORMAT_X24S8_UINT
) ||
219 (format
== PIPE_FORMAT_X32_S8X24_UINT
)) {
222 cd
= (format
== PIPE_FORMAT_X32_S8X24_UINT
) ? 0 : 3;
231 if (desc
->channel
[c
].pure_integer
) {
233 switch (desc
->channel
[c
].size
) {
235 assert(desc
->channel
[c
].type
== UTIL_FORMAT_TYPE_UNSIGNED
);
236 clamped
= CLAMP(bc
->ui
[j
], 0, 0x3);
239 if (desc
->channel
[c
].type
== UTIL_FORMAT_TYPE_SIGNED
)
240 clamped
= CLAMP(bc
->i
[j
], -128, 127);
242 clamped
= CLAMP(bc
->ui
[j
], 0, 255);
245 assert(desc
->channel
[c
].type
== UTIL_FORMAT_TYPE_UNSIGNED
);
246 clamped
= CLAMP(bc
->ui
[j
], 0, 0x3ff);
249 if (desc
->channel
[c
].type
== UTIL_FORMAT_TYPE_SIGNED
)
250 clamped
= CLAMP(bc
->i
[j
], -32768, 32767);
252 clamped
= CLAMP(bc
->ui
[j
], 0, 65535);
255 assert(!"Unexpected bit size");
260 e
->fp32
[cd
] = bc
->ui
[j
];
261 e
->fp16
[cd
] = clamped
;
264 float f_u
= CLAMP(f
, 0, 1);
265 float f_s
= CLAMP(f
, -1, 1);
268 e
->fp16
[c
] = util_float_to_half(f
);
269 e
->srgb
[c
] = util_float_to_half(f_u
);
270 e
->ui16
[c
] = f_u
* 0xffff;
271 e
->si16
[c
] = f_s
* 0x7fff;
272 e
->ui8
[c
] = f_u
* 0xff;
273 e
->si8
[c
] = f_s
* 0x7f;
275 e
->rgb565
|= (int)(f_u
* 0x3f) << 5;
277 e
->rgb565
|= (int)(f_u
* 0x1f) << (c
? 11 : 0);
279 e
->rgb5a1
|= (f_u
> 0.5) ? 0x8000 : 0;
281 e
->rgb5a1
|= (int)(f_u
* 0x1f) << (c
* 5);
283 e
->rgb10a2
|= (int)(f_u
* 0x3) << 30;
285 e
->rgb10a2
|= (int)(f_u
* 0x3ff) << (c
* 10);
286 e
->rgba4
|= (int)(f_u
* 0xf) << (c
* 4);
288 e
->z24
= f_u
* 0xffffff;
293 memset(&e
->__pad0
, 0, sizeof(e
->__pad0
));
294 memset(&e
->__pad1
, 0, sizeof(e
->__pad1
));
300 emit_border_color(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
)
302 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
303 struct bcolor_entry
*entries
;
307 STATIC_ASSERT(sizeof(struct bcolor_entry
) == FD6_BORDER_COLOR_SIZE
);
309 u_upload_alloc(fd6_ctx
->border_color_uploader
,
310 0, FD6_BORDER_COLOR_UPLOAD_SIZE
,
311 FD6_BORDER_COLOR_UPLOAD_SIZE
, &off
,
312 &fd6_ctx
->border_color_buf
,
317 setup_border_colors(&ctx
->tex
[PIPE_SHADER_VERTEX
], &entries
[0]);
318 setup_border_colors(&ctx
->tex
[PIPE_SHADER_FRAGMENT
],
319 &entries
[ctx
->tex
[PIPE_SHADER_VERTEX
].num_samplers
]);
321 OUT_PKT4(ring
, REG_A6XX_SP_TP_BORDER_COLOR_BASE_ADDR_LO
, 2);
322 OUT_RELOC(ring
, fd_resource(fd6_ctx
->border_color_buf
)->bo
, off
, 0, 0);
324 u_upload_unmap(fd6_ctx
->border_color_uploader
);
328 fd6_emit_fb_tex(struct fd_ringbuffer
*state
, struct fd_context
*ctx
)
330 struct pipe_framebuffer_state
*pfb
= &ctx
->batch
->framebuffer
;
331 struct pipe_surface
*psurf
= pfb
->cbufs
[0];
332 struct fd_resource
*rsc
= fd_resource(psurf
->texture
);
334 uint32_t texconst0
= fd6_tex_const_0(psurf
->texture
, psurf
->u
.tex
.level
,
335 psurf
->format
, PIPE_SWIZZLE_X
, PIPE_SWIZZLE_Y
,
336 PIPE_SWIZZLE_Z
, PIPE_SWIZZLE_W
);
338 /* always TILE6_2 mode in GMEM.. which also means no swap: */
339 texconst0
&= ~(A6XX_TEX_CONST_0_SWAP__MASK
| A6XX_TEX_CONST_0_TILE_MODE__MASK
);
340 texconst0
|= A6XX_TEX_CONST_0_TILE_MODE(TILE6_2
);
342 OUT_RING(state
, texconst0
);
343 OUT_RING(state
, A6XX_TEX_CONST_1_WIDTH(pfb
->width
) |
344 A6XX_TEX_CONST_1_HEIGHT(pfb
->height
));
345 OUT_RINGP(state
, A6XX_TEX_CONST_2_TYPE(A6XX_TEX_2D
) |
346 A6XX_TEX_CONST_2_FETCHSIZE(TFETCH6_2_BYTE
),
347 &ctx
->batch
->fb_read_patches
);
348 OUT_RING(state
, A6XX_TEX_CONST_3_ARRAY_PITCH(rsc
->layout
.layer_size
));
350 OUT_RING(state
, A6XX_TEX_CONST_4_BASE_LO(ctx
->screen
->gmem_base
));
351 OUT_RING(state
, A6XX_TEX_CONST_5_BASE_HI(ctx
->screen
->gmem_base
>> 32) |
352 A6XX_TEX_CONST_5_DEPTH(1));
353 OUT_RING(state
, 0); /* texconst6 */
354 OUT_RING(state
, 0); /* texconst7 */
355 OUT_RING(state
, 0); /* texconst8 */
356 OUT_RING(state
, 0); /* texconst9 */
357 OUT_RING(state
, 0); /* texconst10 */
358 OUT_RING(state
, 0); /* texconst11 */
366 fd6_emit_textures(struct fd_pipe
*pipe
, struct fd_ringbuffer
*ring
,
367 enum pipe_shader_type type
, struct fd_texture_stateobj
*tex
,
368 unsigned bcolor_offset
,
369 /* can be NULL if no image/SSBO/fb state to merge in: */
370 const struct ir3_shader_variant
*v
, struct fd_context
*ctx
)
372 bool needs_border
= false;
373 unsigned opcode
, tex_samp_reg
, tex_const_reg
, tex_count_reg
;
374 enum a6xx_state_block sb
;
377 case PIPE_SHADER_VERTEX
:
379 opcode
= CP_LOAD_STATE6_GEOM
;
380 tex_samp_reg
= REG_A6XX_SP_VS_TEX_SAMP_LO
;
381 tex_const_reg
= REG_A6XX_SP_VS_TEX_CONST_LO
;
382 tex_count_reg
= REG_A6XX_SP_VS_TEX_COUNT
;
384 case PIPE_SHADER_TESS_CTRL
:
386 opcode
= CP_LOAD_STATE6_GEOM
;
387 tex_samp_reg
= REG_A6XX_SP_HS_TEX_SAMP_LO
;
388 tex_const_reg
= REG_A6XX_SP_HS_TEX_CONST_LO
;
389 tex_count_reg
= REG_A6XX_SP_HS_TEX_COUNT
;
391 case PIPE_SHADER_TESS_EVAL
:
393 opcode
= CP_LOAD_STATE6_GEOM
;
394 tex_samp_reg
= REG_A6XX_SP_DS_TEX_SAMP_LO
;
395 tex_const_reg
= REG_A6XX_SP_DS_TEX_CONST_LO
;
396 tex_count_reg
= REG_A6XX_SP_DS_TEX_COUNT
;
398 case PIPE_SHADER_GEOMETRY
:
400 opcode
= CP_LOAD_STATE6_GEOM
;
401 tex_samp_reg
= REG_A6XX_SP_GS_TEX_SAMP_LO
;
402 tex_const_reg
= REG_A6XX_SP_GS_TEX_CONST_LO
;
403 tex_count_reg
= REG_A6XX_SP_GS_TEX_COUNT
;
405 case PIPE_SHADER_FRAGMENT
:
407 opcode
= CP_LOAD_STATE6_FRAG
;
408 tex_samp_reg
= REG_A6XX_SP_FS_TEX_SAMP_LO
;
409 tex_const_reg
= REG_A6XX_SP_FS_TEX_CONST_LO
;
410 tex_count_reg
= REG_A6XX_SP_FS_TEX_COUNT
;
412 case PIPE_SHADER_COMPUTE
:
414 opcode
= CP_LOAD_STATE6_FRAG
;
415 tex_samp_reg
= REG_A6XX_SP_CS_TEX_SAMP_LO
;
416 tex_const_reg
= REG_A6XX_SP_CS_TEX_CONST_LO
;
417 tex_count_reg
= REG_A6XX_SP_CS_TEX_COUNT
;
420 unreachable("bad state block");
423 if (tex
->num_samplers
> 0) {
424 struct fd_ringbuffer
*state
=
425 fd_ringbuffer_new_object(pipe
, tex
->num_samplers
* 4 * 4);
426 for (unsigned i
= 0; i
< tex
->num_samplers
; i
++) {
427 static const struct fd6_sampler_stateobj dummy_sampler
= {};
428 const struct fd6_sampler_stateobj
*sampler
= tex
->samplers
[i
] ?
429 fd6_sampler_stateobj(tex
->samplers
[i
]) : &dummy_sampler
;
430 OUT_RING(state
, sampler
->texsamp0
);
431 OUT_RING(state
, sampler
->texsamp1
);
432 OUT_RING(state
, sampler
->texsamp2
|
433 A6XX_TEX_SAMP_2_BCOLOR_OFFSET((i
+ bcolor_offset
) * sizeof(struct bcolor_entry
)));
434 OUT_RING(state
, sampler
->texsamp3
);
435 needs_border
|= sampler
->needs_border
;
438 /* output sampler state: */
439 OUT_PKT7(ring
, opcode
, 3);
440 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(0) |
441 CP_LOAD_STATE6_0_STATE_TYPE(ST6_SHADER
) |
442 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
443 CP_LOAD_STATE6_0_STATE_BLOCK(sb
) |
444 CP_LOAD_STATE6_0_NUM_UNIT(tex
->num_samplers
));
445 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
447 OUT_PKT4(ring
, tex_samp_reg
, 2);
448 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
450 fd_ringbuffer_del(state
);
453 unsigned num_merged_textures
= tex
->num_textures
;
454 unsigned num_textures
= tex
->num_textures
;
456 num_merged_textures
+= v
->image_mapping
.num_tex
;
459 num_merged_textures
++;
461 /* There could be more bound textures than what the shader uses.
462 * Which isn't known at shader compile time. So in the case we
463 * are merging tex state, only emit the textures that the shader
464 * uses (since the image/SSBO related tex state comes immediately
467 num_textures
= v
->image_mapping
.tex_base
;
470 if (num_merged_textures
> 0) {
471 struct fd_ringbuffer
*state
=
472 fd_ringbuffer_new_object(pipe
, num_merged_textures
* 16 * 4);
473 for (unsigned i
= 0; i
< num_textures
; i
++) {
474 static const struct fd6_pipe_sampler_view dummy_view
= {};
475 const struct fd6_pipe_sampler_view
*view
= tex
->textures
[i
] ?
476 fd6_pipe_sampler_view(tex
->textures
[i
]) : &dummy_view
;
477 struct fd_resource
*rsc
= NULL
;
479 if (view
->base
.texture
)
480 rsc
= fd_resource(view
->base
.texture
);
482 OUT_RING(state
, view
->texconst0
);
483 OUT_RING(state
, view
->texconst1
);
484 OUT_RING(state
, view
->texconst2
);
485 OUT_RING(state
, view
->texconst3
);
488 if (view
->base
.format
== PIPE_FORMAT_X32_S8X24_UINT
)
490 OUT_RELOC(state
, rsc
->bo
, view
->offset
,
491 (uint64_t)view
->texconst5
<< 32, 0);
493 OUT_RING(state
, 0x00000000);
494 OUT_RING(state
, view
->texconst5
);
497 OUT_RING(state
, view
->texconst6
);
499 if (rsc
&& view
->ubwc_enabled
) {
500 OUT_RELOC(state
, rsc
->bo
, view
->ubwc_offset
, 0, 0);
506 OUT_RING(state
, view
->texconst9
);
507 OUT_RING(state
, view
->texconst10
);
508 OUT_RING(state
, view
->texconst11
);
516 const struct ir3_ibo_mapping
*mapping
= &v
->image_mapping
;
517 struct fd_shaderbuf_stateobj
*buf
= &ctx
->shaderbuf
[type
];
518 struct fd_shaderimg_stateobj
*img
= &ctx
->shaderimg
[type
];
520 for (unsigned i
= 0; i
< mapping
->num_tex
; i
++) {
521 unsigned idx
= mapping
->tex_to_image
[i
];
522 if (idx
& IBO_SSBO
) {
523 fd6_emit_ssbo_tex(state
, &buf
->sb
[idx
& ~IBO_SSBO
]);
525 fd6_emit_image_tex(state
, &img
->si
[idx
]);
530 fd6_emit_fb_tex(state
, ctx
);
534 /* emit texture state: */
535 OUT_PKT7(ring
, opcode
, 3);
536 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(0) |
537 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
538 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
539 CP_LOAD_STATE6_0_STATE_BLOCK(sb
) |
540 CP_LOAD_STATE6_0_NUM_UNIT(num_merged_textures
));
541 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
543 OUT_PKT4(ring
, tex_const_reg
, 2);
544 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
546 fd_ringbuffer_del(state
);
549 OUT_PKT4(ring
, tex_count_reg
, 1);
550 OUT_RING(ring
, num_merged_textures
);
555 /* Emits combined texture state, which also includes any Image/SSBO
556 * related texture state merged in (because we must have all texture
557 * state for a given stage in a single buffer). In the fast-path, if
558 * we don't need to merge in any image/ssbo related texture state, we
559 * just use cached texture stateobj. Otherwise we generate a single-
562 * TODO Is there some sane way we can still use cached texture stateobj
563 * with image/ssbo in use?
565 * returns whether border_color is required:
568 fd6_emit_combined_textures(struct fd_ringbuffer
*ring
, struct fd6_emit
*emit
,
569 enum pipe_shader_type type
, const struct ir3_shader_variant
*v
)
571 struct fd_context
*ctx
= emit
->ctx
;
572 bool needs_border
= false;
574 static const struct {
575 enum fd6_state_id state_id
;
576 unsigned enable_mask
;
577 } s
[PIPE_SHADER_TYPES
] = {
578 [PIPE_SHADER_VERTEX
] = { FD6_GROUP_VS_TEX
, ENABLE_ALL
},
579 [PIPE_SHADER_TESS_CTRL
] = { FD6_GROUP_HS_TEX
, ENABLE_ALL
},
580 [PIPE_SHADER_TESS_EVAL
] = { FD6_GROUP_DS_TEX
, ENABLE_ALL
},
581 [PIPE_SHADER_GEOMETRY
] = { FD6_GROUP_GS_TEX
, ENABLE_ALL
},
582 [PIPE_SHADER_FRAGMENT
] = { FD6_GROUP_FS_TEX
, ENABLE_DRAW
},
585 debug_assert(s
[type
].state_id
);
587 if (!v
->image_mapping
.num_tex
&& !v
->fb_read
) {
588 /* in the fast-path, when we don't have to mix in any image/SSBO
589 * related texture state, we can just lookup the stateobj and
592 * Also, framebuffer-read is a slow-path because an extra
593 * texture needs to be inserted.
595 * TODO we can probably simmplify things if we also treated
596 * border_color as a slow-path.. this way the tex state key
597 * wouldn't depend on bcolor_offset.. but fb_read might rather
598 * be *somehow* a fast-path if we eventually used it for PLS.
599 * I suppose there would be no harm in just *always* inserting
600 * an fb_read texture?
602 if ((ctx
->dirty_shader
[type
] & FD_DIRTY_SHADER_TEX
) &&
603 ctx
->tex
[type
].num_textures
> 0) {
604 struct fd6_texture_state
*tex
= fd6_texture_state(ctx
,
605 type
, &ctx
->tex
[type
]);
607 needs_border
|= tex
->needs_border
;
609 fd6_emit_add_group(emit
, tex
->stateobj
, s
[type
].state_id
,
610 s
[type
].enable_mask
);
613 /* In the slow-path, create a one-shot texture state object
614 * if either TEX|PROG|SSBO|IMAGE state is dirty:
616 if ((ctx
->dirty_shader
[type
] &
617 (FD_DIRTY_SHADER_TEX
| FD_DIRTY_SHADER_PROG
|
618 FD_DIRTY_SHADER_IMAGE
| FD_DIRTY_SHADER_SSBO
)) ||
620 struct fd_texture_stateobj
*tex
= &ctx
->tex
[type
];
621 struct fd_ringbuffer
*stateobj
=
622 fd_submit_new_ringbuffer(ctx
->batch
->submit
,
623 0x1000, FD_RINGBUFFER_STREAMING
);
624 unsigned bcolor_offset
=
625 fd6_border_color_offset(ctx
, type
, tex
);
627 needs_border
|= fd6_emit_textures(ctx
->pipe
, stateobj
, type
, tex
,
628 bcolor_offset
, v
, ctx
);
630 fd6_emit_take_group(emit
, stateobj
, s
[type
].state_id
,
631 s
[type
].enable_mask
);
638 static struct fd_ringbuffer
*
639 build_vbo_state(struct fd6_emit
*emit
, const struct ir3_shader_variant
*vp
)
641 const struct fd_vertex_state
*vtx
= emit
->vtx
;
644 struct fd_ringbuffer
*ring
= fd_submit_new_ringbuffer(emit
->ctx
->batch
->submit
,
645 4 * (10 * vp
->inputs_count
+ 2), FD_RINGBUFFER_STREAMING
);
647 for (i
= 0, j
= 0; i
<= vp
->inputs_count
; i
++) {
648 if (vp
->inputs
[i
].sysval
)
650 if (vp
->inputs
[i
].compmask
) {
651 struct pipe_vertex_element
*elem
= &vtx
->vtx
->pipe
[i
];
652 const struct pipe_vertex_buffer
*vb
=
653 &vtx
->vertexbuf
.vb
[elem
->vertex_buffer_index
];
654 struct fd_resource
*rsc
= fd_resource(vb
->buffer
.resource
);
655 enum pipe_format pfmt
= elem
->src_format
;
656 enum a6xx_format fmt
= fd6_pipe2vtx(pfmt
);
657 bool isint
= util_format_is_pure_integer(pfmt
);
658 uint32_t off
= vb
->buffer_offset
+ elem
->src_offset
;
659 uint32_t size
= fd_bo_size(rsc
->bo
) - off
;
660 debug_assert(fmt
!= ~0);
663 /* see dEQP-GLES31.stress.vertex_attribute_binding.buffer_bounds.bind_vertex_buffer_offset_near_wrap_10
665 if (off
> fd_bo_size(rsc
->bo
))
669 OUT_PKT4(ring
, REG_A6XX_VFD_FETCH(j
), 4);
670 OUT_RELOC(ring
, rsc
->bo
, off
, 0, 0);
671 OUT_RING(ring
, size
); /* VFD_FETCH[j].SIZE */
672 OUT_RING(ring
, vb
->stride
); /* VFD_FETCH[j].STRIDE */
674 OUT_PKT4(ring
, REG_A6XX_VFD_DECODE(j
), 2);
675 OUT_RING(ring
, A6XX_VFD_DECODE_INSTR_IDX(j
) |
676 A6XX_VFD_DECODE_INSTR_FORMAT(fmt
) |
677 COND(elem
->instance_divisor
, A6XX_VFD_DECODE_INSTR_INSTANCED
) |
678 A6XX_VFD_DECODE_INSTR_SWAP(fd6_pipe2swap(pfmt
)) |
679 A6XX_VFD_DECODE_INSTR_UNK30
|
680 COND(!isint
, A6XX_VFD_DECODE_INSTR_FLOAT
));
681 OUT_RING(ring
, MAX2(1, elem
->instance_divisor
)); /* VFD_DECODE[j].STEP_RATE */
683 OUT_PKT4(ring
, REG_A6XX_VFD_DEST_CNTL(j
), 1);
684 OUT_RING(ring
, A6XX_VFD_DEST_CNTL_INSTR_WRITEMASK(vp
->inputs
[i
].compmask
) |
685 A6XX_VFD_DEST_CNTL_INSTR_REGID(vp
->inputs
[i
].regid
));
691 OUT_PKT4(ring
, REG_A6XX_VFD_CONTROL_0
, 1);
692 OUT_RING(ring
, A6XX_VFD_CONTROL_0_FETCH_CNT(j
) |
693 A6XX_VFD_CONTROL_0_DECODE_CNT(j
));
698 static struct fd_ringbuffer
*
699 build_lrz(struct fd6_emit
*emit
, bool binning_pass
)
701 struct fd_context
*ctx
= emit
->ctx
;
702 struct fd6_blend_stateobj
*blend
= fd6_blend_stateobj(ctx
->blend
);
703 struct fd6_zsa_stateobj
*zsa
= fd6_zsa_stateobj(ctx
->zsa
);
704 struct pipe_framebuffer_state
*pfb
= &ctx
->batch
->framebuffer
;
705 struct fd_resource
*rsc
= fd_resource(pfb
->zsbuf
->texture
);
706 uint32_t gras_lrz_cntl
= zsa
->gras_lrz_cntl
;
707 uint32_t rb_lrz_cntl
= zsa
->rb_lrz_cntl
;
709 if (zsa
->invalidate_lrz
) {
710 rsc
->lrz_valid
= false;
713 } else if (emit
->no_lrz_write
|| !rsc
->lrz
|| !rsc
->lrz_valid
) {
716 } else if (binning_pass
&& blend
->lrz_write
&& zsa
->lrz_write
) {
717 gras_lrz_cntl
|= A6XX_GRAS_LRZ_CNTL_LRZ_WRITE
;
720 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
721 if ((fd6_ctx
->last
.lrz
[binning_pass
].gras_lrz_cntl
== gras_lrz_cntl
) &&
722 (fd6_ctx
->last
.lrz
[binning_pass
].rb_lrz_cntl
== rb_lrz_cntl
) &&
726 fd6_ctx
->last
.lrz
[binning_pass
].gras_lrz_cntl
= gras_lrz_cntl
;
727 fd6_ctx
->last
.lrz
[binning_pass
].rb_lrz_cntl
= rb_lrz_cntl
;
729 struct fd_ringbuffer
*ring
= fd_submit_new_ringbuffer(ctx
->batch
->submit
,
730 16, FD_RINGBUFFER_STREAMING
);
732 OUT_PKT4(ring
, REG_A6XX_GRAS_LRZ_CNTL
, 1);
733 OUT_RING(ring
, gras_lrz_cntl
);
735 OUT_PKT4(ring
, REG_A6XX_RB_LRZ_CNTL
, 1);
736 OUT_RING(ring
, rb_lrz_cntl
);
742 fd6_emit_streamout(struct fd_ringbuffer
*ring
, struct fd6_emit
*emit
, struct ir3_stream_output_info
*info
)
744 struct fd_context
*ctx
= emit
->ctx
;
745 const struct fd6_program_state
*prog
= fd6_emit_get_prog(emit
);
746 struct fd_streamout_stateobj
*so
= &ctx
->streamout
;
748 emit
->streamout_mask
= 0;
750 for (unsigned i
= 0; i
< so
->num_targets
; i
++) {
751 struct pipe_stream_output_target
*target
= so
->targets
[i
];
756 OUT_PKT4(ring
, REG_A6XX_VPC_SO_BUFFER_BASE_LO(i
), 3);
757 /* VPC_SO[i].BUFFER_BASE_LO: */
758 OUT_RELOCW(ring
, fd_resource(target
->buffer
)->bo
, target
->buffer_offset
, 0, 0);
759 OUT_RING(ring
, target
->buffer_size
- target
->buffer_offset
);
761 if (so
->reset
& (1 << i
)) {
762 unsigned offset
= (so
->offsets
[i
] * info
->stride
[i
] * 4);
763 OUT_PKT4(ring
, REG_A6XX_VPC_SO_BUFFER_OFFSET(i
), 1);
764 OUT_RING(ring
, offset
);
766 OUT_PKT7(ring
, CP_MEM_TO_REG
, 3);
767 OUT_RING(ring
, CP_MEM_TO_REG_0_REG(REG_A6XX_VPC_SO_BUFFER_OFFSET(i
)) |
768 CP_MEM_TO_REG_0_SHIFT_BY_2
| CP_MEM_TO_REG_0_UNK31
|
769 CP_MEM_TO_REG_0_CNT(0));
770 OUT_RELOC(ring
, control_ptr(fd6_context(ctx
), flush_base
[i
].offset
));
773 OUT_PKT4(ring
, REG_A6XX_VPC_SO_FLUSH_BASE_LO(i
), 2);
774 OUT_RELOCW(ring
, control_ptr(fd6_context(ctx
), flush_base
[i
]));
776 so
->reset
&= ~(1 << i
);
778 emit
->streamout_mask
|= (1 << i
);
781 if (emit
->streamout_mask
) {
782 const struct fd6_streamout_state
*tf
= &prog
->tf
;
784 OUT_PKT7(ring
, CP_CONTEXT_REG_BUNCH
, 12 + (2 * tf
->prog_count
));
785 OUT_RING(ring
, REG_A6XX_VPC_SO_BUF_CNTL
);
786 OUT_RING(ring
, tf
->vpc_so_buf_cntl
);
787 OUT_RING(ring
, REG_A6XX_VPC_SO_NCOMP(0));
788 OUT_RING(ring
, tf
->ncomp
[0]);
789 OUT_RING(ring
, REG_A6XX_VPC_SO_NCOMP(1));
790 OUT_RING(ring
, tf
->ncomp
[1]);
791 OUT_RING(ring
, REG_A6XX_VPC_SO_NCOMP(2));
792 OUT_RING(ring
, tf
->ncomp
[2]);
793 OUT_RING(ring
, REG_A6XX_VPC_SO_NCOMP(3));
794 OUT_RING(ring
, tf
->ncomp
[3]);
795 OUT_RING(ring
, REG_A6XX_VPC_SO_CNTL
);
796 OUT_RING(ring
, A6XX_VPC_SO_CNTL_ENABLE
);
797 for (unsigned i
= 0; i
< tf
->prog_count
; i
++) {
798 OUT_RING(ring
, REG_A6XX_VPC_SO_PROG
);
799 OUT_RING(ring
, tf
->prog
[i
]);
802 OUT_PKT7(ring
, CP_CONTEXT_REG_BUNCH
, 4);
803 OUT_RING(ring
, REG_A6XX_VPC_SO_CNTL
);
805 OUT_RING(ring
, REG_A6XX_VPC_SO_BUF_CNTL
);
811 emit_tess_bos(struct fd_ringbuffer
*ring
, struct fd6_emit
*emit
, struct ir3_shader_variant
*s
)
813 struct fd_context
*ctx
= emit
->ctx
;
814 const unsigned regid
= s
->shader
->const_state
.offsets
.primitive_param
* 4 + 4;
815 uint32_t dwords
= 16;
817 OUT_PKT7(ring
, fd6_stage2opcode(s
->type
), 3);
818 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(regid
/ 4) |
819 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
)|
820 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
821 CP_LOAD_STATE6_0_STATE_BLOCK(fd6_stage2shadersb(s
->type
)) |
822 CP_LOAD_STATE6_0_NUM_UNIT(dwords
/ 4));
823 OUT_RB(ring
, ctx
->batch
->tess_addrs_constobj
);
827 emit_stage_tess_consts(struct fd_ringbuffer
*ring
, struct ir3_shader_variant
*v
,
828 uint32_t *params
, int num_params
)
830 const unsigned regid
= v
->shader
->const_state
.offsets
.primitive_param
;
831 int size
= MIN2(1 + regid
, v
->constlen
) - regid
;
833 fd6_emit_const(ring
, v
->type
, regid
* 4, 0, num_params
, params
, NULL
);
837 fd6_emit_tess_const(struct fd6_emit
*emit
)
839 struct fd_context
*ctx
= emit
->ctx
;
841 struct fd_ringbuffer
*constobj
= fd_submit_new_ringbuffer(
842 ctx
->batch
->submit
, 0x1000, FD_RINGBUFFER_STREAMING
);
844 /* VS sizes are in bytes since that's what STLW/LDLW use, while the HS
845 * size is dwords, since that's what LDG/STG use.
847 unsigned num_vertices
=
849 emit
->info
->vertices_per_patch
:
850 emit
->gs
->shader
->nir
->info
.gs
.vertices_in
;
852 uint32_t vs_params
[4] = {
853 emit
->vs
->shader
->output_size
* num_vertices
* 4, /* vs primitive stride */
854 emit
->vs
->shader
->output_size
* 4, /* vs vertex stride */
859 emit_stage_tess_consts(constobj
, emit
->vs
, vs_params
, ARRAY_SIZE(vs_params
));
862 uint32_t hs_params
[4] = {
863 emit
->vs
->shader
->output_size
* num_vertices
* 4, /* vs primitive stride */
864 emit
->vs
->shader
->output_size
* 4, /* vs vertex stride */
865 emit
->hs
->shader
->output_size
,
866 emit
->info
->vertices_per_patch
869 emit_stage_tess_consts(constobj
, emit
->hs
, hs_params
, ARRAY_SIZE(hs_params
));
870 emit_tess_bos(constobj
, emit
, emit
->hs
);
873 num_vertices
= emit
->gs
->shader
->nir
->info
.gs
.vertices_in
;
875 uint32_t ds_params
[4] = {
876 emit
->ds
->shader
->output_size
* num_vertices
* 4, /* ds primitive stride */
877 emit
->ds
->shader
->output_size
* 4, /* ds vertex stride */
878 emit
->hs
->shader
->output_size
, /* hs vertex stride (dwords) */
879 emit
->hs
->shader
->nir
->info
.tess
.tcs_vertices_out
882 emit_stage_tess_consts(constobj
, emit
->ds
, ds_params
, ARRAY_SIZE(ds_params
));
883 emit_tess_bos(constobj
, emit
, emit
->ds
);
887 struct ir3_shader_variant
*prev
;
893 uint32_t gs_params
[4] = {
894 prev
->shader
->output_size
* num_vertices
* 4, /* ds primitive stride */
895 prev
->shader
->output_size
* 4, /* ds vertex stride */
900 num_vertices
= emit
->gs
->shader
->nir
->info
.gs
.vertices_in
;
901 emit_stage_tess_consts(constobj
, emit
->gs
, gs_params
, ARRAY_SIZE(gs_params
));
904 fd6_emit_take_group(emit
, constobj
, FD6_GROUP_PRIMITIVE_PARAMS
, ENABLE_ALL
);
908 fd6_emit_consts(struct fd6_emit
*emit
)
910 static const enum pipe_shader_type types
[] = {
911 PIPE_SHADER_VERTEX
, PIPE_SHADER_TESS_CTRL
, PIPE_SHADER_TESS_EVAL
,
912 PIPE_SHADER_GEOMETRY
, PIPE_SHADER_FRAGMENT
,
914 const struct ir3_shader_variant
*variants
[] = {
915 emit
->vs
, emit
->hs
, emit
->ds
, emit
->gs
, emit
->fs
,
917 struct fd_context
*ctx
= emit
->ctx
;
920 for (unsigned i
= 0; i
< ARRAY_SIZE(types
); i
++) {
923 sz
+= variants
[i
]->shader
->ubo_state
.cmdstream_size
;
926 struct fd_ringbuffer
*constobj
= fd_submit_new_ringbuffer(
927 ctx
->batch
->submit
, sz
, FD_RINGBUFFER_STREAMING
);
929 for (unsigned i
= 0; i
< ARRAY_SIZE(types
); i
++) {
932 ir3_emit_user_consts(ctx
->screen
, variants
[i
], constobj
, &ctx
->constbuf
[types
[i
]]);
933 ir3_emit_ubos(ctx
->screen
, variants
[i
], constobj
, &ctx
->constbuf
[types
[i
]]);
936 fd6_emit_take_group(emit
, constobj
, FD6_GROUP_CONST
, ENABLE_ALL
);
940 fd6_emit_state(struct fd_ringbuffer
*ring
, struct fd6_emit
*emit
)
942 struct fd_context
*ctx
= emit
->ctx
;
943 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
944 struct pipe_framebuffer_state
*pfb
= &ctx
->batch
->framebuffer
;
945 const struct fd6_program_state
*prog
= fd6_emit_get_prog(emit
);
946 const struct ir3_shader_variant
*vs
= emit
->vs
;
947 const struct ir3_shader_variant
*hs
= emit
->hs
;
948 const struct ir3_shader_variant
*ds
= emit
->ds
;
949 const struct ir3_shader_variant
*gs
= emit
->gs
;
950 const struct ir3_shader_variant
*fs
= emit
->fs
;
951 const enum fd_dirty_3d_state dirty
= emit
->dirty
;
952 bool needs_border
= false;
954 emit_marker6(ring
, 5);
956 /* NOTE: we track fb_read differently than _BLEND_ENABLED since
957 * we might at some point decide to do sysmem in some cases when
961 ctx
->batch
->gmem_reason
|= FD_GMEM_FB_READ
;
963 if (emit
->dirty
& (FD_DIRTY_VTXBUF
| FD_DIRTY_VTXSTATE
)) {
964 struct fd_ringbuffer
*state
;
966 state
= build_vbo_state(emit
, emit
->vs
);
967 fd6_emit_take_group(emit
, state
, FD6_GROUP_VBO
, ENABLE_ALL
);
970 if (dirty
& FD_DIRTY_ZSA
) {
971 struct fd6_zsa_stateobj
*zsa
= fd6_zsa_stateobj(ctx
->zsa
);
973 if (util_format_is_pure_integer(pipe_surface_format(pfb
->cbufs
[0])))
974 fd6_emit_add_group(emit
, zsa
->stateobj_no_alpha
, FD6_GROUP_ZSA
, ENABLE_ALL
);
976 fd6_emit_add_group(emit
, zsa
->stateobj
, FD6_GROUP_ZSA
, ENABLE_ALL
);
979 if ((dirty
& (FD_DIRTY_ZSA
| FD_DIRTY_BLEND
| FD_DIRTY_PROG
)) && pfb
->zsbuf
) {
980 struct fd_ringbuffer
*state
;
982 state
= build_lrz(emit
, false);
984 fd6_emit_take_group(emit
, state
, FD6_GROUP_LRZ
, ENABLE_DRAW
);
987 state
= build_lrz(emit
, true);
989 fd6_emit_take_group(emit
, state
,
990 FD6_GROUP_LRZ_BINNING
, CP_SET_DRAW_STATE__0_BINNING
);
994 if (dirty
& FD_DIRTY_STENCIL_REF
) {
995 struct pipe_stencil_ref
*sr
= &ctx
->stencil_ref
;
997 OUT_PKT4(ring
, REG_A6XX_RB_STENCILREF
, 1);
998 OUT_RING(ring
, A6XX_RB_STENCILREF_REF(sr
->ref_value
[0]) |
999 A6XX_RB_STENCILREF_BFREF(sr
->ref_value
[1]));
1002 /* NOTE: scissor enabled bit is part of rasterizer state, but
1003 * fd_rasterizer_state_bind() will mark scissor dirty if needed:
1005 if (dirty
& FD_DIRTY_SCISSOR
) {
1006 struct fd_ringbuffer
*ring
= fd_submit_new_ringbuffer(
1007 emit
->ctx
->batch
->submit
, 3*4, FD_RINGBUFFER_STREAMING
);
1008 struct pipe_scissor_state
*scissor
= fd_context_get_scissor(ctx
);
1010 OUT_PKT4(ring
, REG_A6XX_GRAS_SC_SCREEN_SCISSOR_TL_0
, 2);
1011 OUT_RING(ring
, A6XX_GRAS_SC_SCREEN_SCISSOR_TL_0_X(scissor
->minx
) |
1012 A6XX_GRAS_SC_SCREEN_SCISSOR_TL_0_Y(scissor
->miny
));
1013 OUT_RING(ring
, A6XX_GRAS_SC_SCREEN_SCISSOR_TL_0_X(scissor
->maxx
- 1) |
1014 A6XX_GRAS_SC_SCREEN_SCISSOR_TL_0_Y(scissor
->maxy
- 1));
1016 fd6_emit_take_group(emit
, ring
, FD6_GROUP_SCISSOR
, ENABLE_ALL
);
1018 ctx
->batch
->max_scissor
.minx
= MIN2(ctx
->batch
->max_scissor
.minx
, scissor
->minx
);
1019 ctx
->batch
->max_scissor
.miny
= MIN2(ctx
->batch
->max_scissor
.miny
, scissor
->miny
);
1020 ctx
->batch
->max_scissor
.maxx
= MAX2(ctx
->batch
->max_scissor
.maxx
, scissor
->maxx
);
1021 ctx
->batch
->max_scissor
.maxy
= MAX2(ctx
->batch
->max_scissor
.maxy
, scissor
->maxy
);
1024 if (dirty
& FD_DIRTY_VIEWPORT
) {
1025 struct pipe_scissor_state
*scissor
= &ctx
->viewport_scissor
;
1027 OUT_PKT4(ring
, REG_A6XX_GRAS_CL_VPORT_XOFFSET_0
, 6);
1028 OUT_RING(ring
, A6XX_GRAS_CL_VPORT_XOFFSET_0(ctx
->viewport
.translate
[0]));
1029 OUT_RING(ring
, A6XX_GRAS_CL_VPORT_XSCALE_0(ctx
->viewport
.scale
[0]));
1030 OUT_RING(ring
, A6XX_GRAS_CL_VPORT_YOFFSET_0(ctx
->viewport
.translate
[1]));
1031 OUT_RING(ring
, A6XX_GRAS_CL_VPORT_YSCALE_0(ctx
->viewport
.scale
[1]));
1032 OUT_RING(ring
, A6XX_GRAS_CL_VPORT_ZOFFSET_0(ctx
->viewport
.translate
[2]));
1033 OUT_RING(ring
, A6XX_GRAS_CL_VPORT_ZSCALE_0(ctx
->viewport
.scale
[2]));
1035 OUT_PKT4(ring
, REG_A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0
, 2);
1036 OUT_RING(ring
, A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0_X(scissor
->minx
) |
1037 A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0_Y(scissor
->miny
));
1038 OUT_RING(ring
, A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0_X(scissor
->maxx
- 1) |
1039 A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0_Y(scissor
->maxy
- 1));
1041 unsigned guardband_x
= fd_calc_guardband(scissor
->maxx
- scissor
->minx
);
1042 unsigned guardband_y
= fd_calc_guardband(scissor
->maxy
- scissor
->miny
);
1044 OUT_PKT4(ring
, REG_A6XX_GRAS_CL_GUARDBAND_CLIP_ADJ
, 1);
1045 OUT_RING(ring
, A6XX_GRAS_CL_GUARDBAND_CLIP_ADJ_HORZ(guardband_x
) |
1046 A6XX_GRAS_CL_GUARDBAND_CLIP_ADJ_VERT(guardband_y
));
1049 if (dirty
& FD_DIRTY_PROG
) {
1050 fd6_emit_add_group(emit
, prog
->config_stateobj
, FD6_GROUP_PROG_CONFIG
, ENABLE_ALL
);
1051 fd6_emit_add_group(emit
, prog
->stateobj
, FD6_GROUP_PROG
, ENABLE_DRAW
);
1052 fd6_emit_add_group(emit
, prog
->binning_stateobj
,
1053 FD6_GROUP_PROG_BINNING
, CP_SET_DRAW_STATE__0_BINNING
);
1055 /* emit remaining streaming program state, ie. what depends on
1056 * other emit state, so cannot be pre-baked.
1058 struct fd_ringbuffer
*streaming
= fd6_program_interp_state(emit
);
1060 fd6_emit_take_group(emit
, streaming
, FD6_GROUP_PROG_INTERP
, ENABLE_DRAW
);
1063 if (dirty
& FD_DIRTY_RASTERIZER
) {
1064 struct fd_ringbuffer
*stateobj
=
1065 fd6_rasterizer_state(ctx
, emit
->primitive_restart
);
1066 fd6_emit_add_group(emit
, stateobj
,
1067 FD6_GROUP_RASTERIZER
, ENABLE_ALL
);
1070 if (dirty
& (FD_DIRTY_FRAMEBUFFER
| FD_DIRTY_RASTERIZER_DISCARD
| FD_DIRTY_PROG
)) {
1071 struct fd_ringbuffer
*ring
= fd_submit_new_ringbuffer(
1072 emit
->ctx
->batch
->submit
, 5 * 4, FD_RINGBUFFER_STREAMING
);
1074 unsigned nr
= pfb
->nr_cbufs
;
1076 if (ctx
->rasterizer
->rasterizer_discard
)
1079 OUT_PKT4(ring
, REG_A6XX_RB_FS_OUTPUT_CNTL0
, 2);
1080 OUT_RING(ring
, COND(fs
->writes_pos
, A6XX_RB_FS_OUTPUT_CNTL0_FRAG_WRITES_Z
) |
1081 COND(fs
->writes_smask
&& pfb
->samples
> 1,
1082 A6XX_RB_FS_OUTPUT_CNTL0_FRAG_WRITES_SAMPMASK
));
1083 OUT_RING(ring
, A6XX_RB_FS_OUTPUT_CNTL1_MRT(nr
));
1085 OUT_PKT4(ring
, REG_A6XX_SP_FS_OUTPUT_CNTL1
, 1);
1086 OUT_RING(ring
, A6XX_SP_FS_OUTPUT_CNTL1_MRT(nr
));
1088 fd6_emit_take_group(emit
, ring
, FD6_GROUP_PROG_FB_RAST
, ENABLE_DRAW
);
1091 if (dirty
& (FD_DIRTY_CONST
| FD_DIRTY_PROG
)) {
1092 fd6_emit_consts(emit
);
1095 if (emit
->key
.key
.has_gs
|| emit
->key
.key
.tessellation
)
1096 fd6_emit_tess_const(emit
);
1098 /* if driver-params are needed, emit each time: */
1099 if (ir3_needs_vs_driver_params(vs
)) {
1100 struct fd_ringbuffer
*dpconstobj
= fd_submit_new_ringbuffer(
1101 ctx
->batch
->submit
, IR3_DP_VS_COUNT
* 4, FD_RINGBUFFER_STREAMING
);
1102 ir3_emit_vs_driver_params(vs
, dpconstobj
, ctx
, emit
->info
);
1103 fd6_emit_take_group(emit
, dpconstobj
, FD6_GROUP_VS_DRIVER_PARAMS
, ENABLE_ALL
);
1104 fd6_ctx
->has_dp_state
= true;
1105 } else if (fd6_ctx
->has_dp_state
) {
1106 fd6_emit_take_group(emit
, NULL
, FD6_GROUP_VS_DRIVER_PARAMS
, ENABLE_ALL
);
1107 fd6_ctx
->has_dp_state
= false;
1110 struct ir3_stream_output_info
*info
= &fd6_last_shader(prog
)->shader
->stream_output
;
1111 if (info
->num_outputs
)
1112 fd6_emit_streamout(ring
, emit
, info
);
1114 if (dirty
& (FD_DIRTY_BLEND
| FD_DIRTY_SAMPLE_MASK
)) {
1115 struct fd6_blend_variant
*blend
= fd6_blend_variant(ctx
->blend
,
1116 pfb
->samples
, ctx
->sample_mask
);
1117 fd6_emit_add_group(emit
, blend
->stateobj
, FD6_GROUP_BLEND
, ENABLE_DRAW
);
1120 if (dirty
& FD_DIRTY_BLEND_COLOR
) {
1121 struct pipe_blend_color
*bcolor
= &ctx
->blend_color
;
1122 struct fd_ringbuffer
*ring
= fd_submit_new_ringbuffer(
1123 emit
->ctx
->batch
->submit
, 5*4, FD_RINGBUFFER_STREAMING
);
1125 OUT_PKT4(ring
, REG_A6XX_RB_BLEND_RED_F32
, 4);
1126 OUT_RING(ring
, A6XX_RB_BLEND_RED_F32(bcolor
->color
[0]));
1127 OUT_RING(ring
, A6XX_RB_BLEND_GREEN_F32(bcolor
->color
[1]));
1128 OUT_RING(ring
, A6XX_RB_BLEND_BLUE_F32(bcolor
->color
[2]));
1129 OUT_RING(ring
, A6XX_RB_BLEND_ALPHA_F32(bcolor
->color
[3]));
1131 fd6_emit_take_group(emit
, ring
, FD6_GROUP_BLEND_COLOR
, ENABLE_DRAW
);
1134 needs_border
|= fd6_emit_combined_textures(ring
, emit
, PIPE_SHADER_VERTEX
, vs
);
1136 needs_border
|= fd6_emit_combined_textures(ring
, emit
, PIPE_SHADER_TESS_CTRL
, hs
);
1137 needs_border
|= fd6_emit_combined_textures(ring
, emit
, PIPE_SHADER_TESS_EVAL
, ds
);
1140 needs_border
|= fd6_emit_combined_textures(ring
, emit
, PIPE_SHADER_GEOMETRY
, gs
);
1142 needs_border
|= fd6_emit_combined_textures(ring
, emit
, PIPE_SHADER_FRAGMENT
, fs
);
1145 emit_border_color(ctx
, ring
);
1148 debug_assert(ir3_shader_nibo(hs
) == 0);
1149 debug_assert(ir3_shader_nibo(ds
) == 0);
1152 debug_assert(ir3_shader_nibo(gs
) == 0);
1155 #define DIRTY_IBO (FD_DIRTY_SHADER_SSBO | FD_DIRTY_SHADER_IMAGE | \
1156 FD_DIRTY_SHADER_PROG)
1157 if (ctx
->dirty_shader
[PIPE_SHADER_FRAGMENT
] & DIRTY_IBO
) {
1158 struct fd_ringbuffer
*state
=
1159 fd6_build_ibo_state(ctx
, fs
, PIPE_SHADER_FRAGMENT
);
1160 struct fd_ringbuffer
*obj
= fd_submit_new_ringbuffer(
1161 ctx
->batch
->submit
, 0x100, FD_RINGBUFFER_STREAMING
);
1163 OUT_PKT7(obj
, CP_LOAD_STATE6
, 3);
1164 OUT_RING(obj
, CP_LOAD_STATE6_0_DST_OFF(0) |
1165 CP_LOAD_STATE6_0_STATE_TYPE(ST6_SHADER
) |
1166 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
1167 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_IBO
) |
1168 CP_LOAD_STATE6_0_NUM_UNIT(ir3_shader_nibo(fs
)));
1171 OUT_PKT4(obj
, REG_A6XX_SP_IBO_LO
, 2);
1174 /* TODO if we used CP_SET_DRAW_STATE for compute shaders, we could
1175 * de-duplicate this from program->config_stateobj
1177 OUT_PKT4(obj
, REG_A6XX_SP_IBO_COUNT
, 1);
1178 OUT_RING(obj
, ir3_shader_nibo(fs
));
1180 ir3_emit_ssbo_sizes(ctx
->screen
, fs
, obj
,
1181 &ctx
->shaderbuf
[PIPE_SHADER_FRAGMENT
]);
1182 ir3_emit_image_dims(ctx
->screen
, fs
, obj
,
1183 &ctx
->shaderimg
[PIPE_SHADER_FRAGMENT
]);
1185 fd6_emit_take_group(emit
, obj
, FD6_GROUP_IBO
, ENABLE_DRAW
);
1186 fd_ringbuffer_del(state
);
1189 if (emit
->num_groups
> 0) {
1190 OUT_PKT7(ring
, CP_SET_DRAW_STATE
, 3 * emit
->num_groups
);
1191 for (unsigned i
= 0; i
< emit
->num_groups
; i
++) {
1192 struct fd6_state_group
*g
= &emit
->groups
[i
];
1193 unsigned n
= g
->stateobj
?
1194 fd_ringbuffer_size(g
->stateobj
) / 4 : 0;
1196 debug_assert((g
->enable_mask
& ~ENABLE_ALL
) == 0);
1199 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(0) |
1200 CP_SET_DRAW_STATE__0_DISABLE
|
1202 CP_SET_DRAW_STATE__0_GROUP_ID(g
->group_id
));
1203 OUT_RING(ring
, 0x00000000);
1204 OUT_RING(ring
, 0x00000000);
1206 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(n
) |
1208 CP_SET_DRAW_STATE__0_GROUP_ID(g
->group_id
));
1209 OUT_RB(ring
, g
->stateobj
);
1213 fd_ringbuffer_del(g
->stateobj
);
1215 emit
->num_groups
= 0;
1220 fd6_emit_cs_state(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
,
1221 struct ir3_shader_variant
*cp
)
1223 enum fd_dirty_shader_state dirty
= ctx
->dirty_shader
[PIPE_SHADER_COMPUTE
];
1225 if (dirty
& (FD_DIRTY_SHADER_TEX
| FD_DIRTY_SHADER_PROG
|
1226 FD_DIRTY_SHADER_IMAGE
| FD_DIRTY_SHADER_SSBO
)) {
1227 struct fd_texture_stateobj
*tex
= &ctx
->tex
[PIPE_SHADER_COMPUTE
];
1228 unsigned bcolor_offset
= fd6_border_color_offset(ctx
, PIPE_SHADER_COMPUTE
, tex
);
1230 bool needs_border
= fd6_emit_textures(ctx
->pipe
, ring
, PIPE_SHADER_COMPUTE
, tex
,
1231 bcolor_offset
, cp
, ctx
);
1234 emit_border_color(ctx
, ring
);
1236 OUT_PKT4(ring
, REG_A6XX_SP_VS_TEX_COUNT
, 1);
1239 OUT_PKT4(ring
, REG_A6XX_SP_HS_TEX_COUNT
, 1);
1242 OUT_PKT4(ring
, REG_A6XX_SP_DS_TEX_COUNT
, 1);
1245 OUT_PKT4(ring
, REG_A6XX_SP_GS_TEX_COUNT
, 1);
1248 OUT_PKT4(ring
, REG_A6XX_SP_FS_TEX_COUNT
, 1);
1252 if (dirty
& (FD_DIRTY_SHADER_SSBO
| FD_DIRTY_SHADER_IMAGE
)) {
1253 struct fd_ringbuffer
*state
=
1254 fd6_build_ibo_state(ctx
, cp
, PIPE_SHADER_COMPUTE
);
1256 OUT_PKT7(ring
, CP_LOAD_STATE6_FRAG
, 3);
1257 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(0) |
1258 CP_LOAD_STATE6_0_STATE_TYPE(ST6_IBO
) |
1259 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
1260 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_CS_SHADER
) |
1261 CP_LOAD_STATE6_0_NUM_UNIT(ir3_shader_nibo(cp
)));
1262 OUT_RB(ring
, state
);
1264 OUT_PKT4(ring
, REG_A6XX_SP_CS_IBO_LO
, 2);
1265 OUT_RB(ring
, state
);
1267 OUT_PKT4(ring
, REG_A6XX_SP_CS_IBO_COUNT
, 1);
1268 OUT_RING(ring
, ir3_shader_nibo(cp
));
1270 fd_ringbuffer_del(state
);
1275 /* emit setup at begin of new cmdstream buffer (don't rely on previous
1276 * state, there could have been a context switch between ioctls):
1279 fd6_emit_restore(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
)
1281 //struct fd_context *ctx = batch->ctx;
1283 fd_log(batch
, "START RESTORE");
1285 fd6_cache_inv(batch
, ring
);
1287 OUT_PKT4(ring
, REG_A6XX_HLSQ_UPDATE_CNTL
, 1);
1288 OUT_RING(ring
, 0xfffff);
1292 WRITE(REG_A6XX_RB_UNKNOWN_8E04
, 0x0);
1293 WRITE(REG_A6XX_SP_UNKNOWN_AE04
, 0x8);
1294 WRITE(REG_A6XX_SP_UNKNOWN_AE00
, 0);
1295 WRITE(REG_A6XX_SP_UNKNOWN_AE0F
, 0x3f);
1296 WRITE(REG_A6XX_SP_UNKNOWN_B605
, 0x44);
1297 WRITE(REG_A6XX_SP_UNKNOWN_B600
, 0x100000);
1298 WRITE(REG_A6XX_HLSQ_UNKNOWN_BE00
, 0x80);
1299 WRITE(REG_A6XX_HLSQ_UNKNOWN_BE01
, 0);
1301 WRITE(REG_A6XX_VPC_UNKNOWN_9600
, 0);
1302 WRITE(REG_A6XX_GRAS_UNKNOWN_8600
, 0x880);
1303 WRITE(REG_A6XX_HLSQ_UNKNOWN_BE04
, 0x80000);
1304 WRITE(REG_A6XX_SP_UNKNOWN_AE03
, 0x1430);
1305 WRITE(REG_A6XX_SP_IBO_COUNT
, 0);
1306 WRITE(REG_A6XX_SP_UNKNOWN_B182
, 0);
1307 WRITE(REG_A6XX_HLSQ_UNKNOWN_BB11
, 0);
1308 WRITE(REG_A6XX_UCHE_UNKNOWN_0E12
, 0x3200000);
1309 WRITE(REG_A6XX_UCHE_CLIENT_PF
, 4);
1310 WRITE(REG_A6XX_RB_UNKNOWN_8E01
, 0x1);
1311 WRITE(REG_A6XX_SP_UNKNOWN_AB00
, 0x5);
1312 WRITE(REG_A6XX_VFD_ADD_OFFSET
, A6XX_VFD_ADD_OFFSET_VERTEX
);
1313 WRITE(REG_A6XX_RB_UNKNOWN_8811
, 0x00000010);
1314 WRITE(REG_A6XX_PC_MODE_CNTL
, 0x1f);
1316 OUT_PKT4(ring
, REG_A6XX_RB_SRGB_CNTL
, 1);
1319 WRITE(REG_A6XX_GRAS_UNKNOWN_8101
, 0);
1320 WRITE(REG_A6XX_GRAS_SAMPLE_CNTL
, 0);
1321 WRITE(REG_A6XX_GRAS_UNKNOWN_8110
, 0x2);
1323 WRITE(REG_A6XX_RB_UNKNOWN_8818
, 0);
1324 WRITE(REG_A6XX_RB_UNKNOWN_8819
, 0);
1325 WRITE(REG_A6XX_RB_UNKNOWN_881A
, 0);
1326 WRITE(REG_A6XX_RB_UNKNOWN_881B
, 0);
1327 WRITE(REG_A6XX_RB_UNKNOWN_881C
, 0);
1328 WRITE(REG_A6XX_RB_UNKNOWN_881D
, 0);
1329 WRITE(REG_A6XX_RB_UNKNOWN_881E
, 0);
1330 WRITE(REG_A6XX_RB_UNKNOWN_88F0
, 0);
1332 WRITE(REG_A6XX_VPC_UNKNOWN_9236
,
1333 A6XX_VPC_UNKNOWN_9236_POINT_COORD_INVERT(0));
1334 WRITE(REG_A6XX_VPC_UNKNOWN_9300
, 0);
1336 WRITE(REG_A6XX_VPC_SO_OVERRIDE
, A6XX_VPC_SO_OVERRIDE_SO_DISABLE
);
1338 WRITE(REG_A6XX_PC_UNKNOWN_9990
, 0);
1339 WRITE(REG_A6XX_PC_UNKNOWN_9980
, 0);
1341 WRITE(REG_A6XX_PC_UNKNOWN_9B07
, 0);
1343 WRITE(REG_A6XX_SP_UNKNOWN_A81B
, 0);
1345 WRITE(REG_A6XX_SP_UNKNOWN_B183
, 0);
1347 WRITE(REG_A6XX_GRAS_UNKNOWN_8099
, 0);
1348 WRITE(REG_A6XX_GRAS_UNKNOWN_809B
, 0);
1349 WRITE(REG_A6XX_GRAS_UNKNOWN_80A0
, 2);
1350 WRITE(REG_A6XX_GRAS_UNKNOWN_80AF
, 0);
1351 WRITE(REG_A6XX_VPC_UNKNOWN_9210
, 0);
1352 WRITE(REG_A6XX_VPC_UNKNOWN_9211
, 0);
1353 WRITE(REG_A6XX_VPC_UNKNOWN_9602
, 0);
1354 WRITE(REG_A6XX_PC_UNKNOWN_9981
, 0x3);
1355 WRITE(REG_A6XX_PC_UNKNOWN_9E72
, 0);
1356 WRITE(REG_A6XX_VPC_UNKNOWN_9108
, 0x3);
1357 WRITE(REG_A6XX_SP_TP_SAMPLE_CONFIG
, 0);
1358 /* NOTE blob seems to (mostly?) use 0xb2 for SP_TP_UNKNOWN_B309
1359 * but this seems to kill texture gather offsets.
1361 WRITE(REG_A6XX_SP_TP_UNKNOWN_B309
, 0xa2);
1362 WRITE(REG_A6XX_RB_SAMPLE_CONFIG
, 0);
1363 WRITE(REG_A6XX_GRAS_SAMPLE_CONFIG
, 0);
1364 WRITE(REG_A6XX_RB_UNKNOWN_8878
, 0);
1365 WRITE(REG_A6XX_RB_UNKNOWN_8879
, 0);
1366 WRITE(REG_A6XX_HLSQ_CONTROL_5_REG
, 0xfc);
1368 emit_marker6(ring
, 7);
1370 OUT_PKT4(ring
, REG_A6XX_VFD_MODE_CNTL
, 1);
1371 OUT_RING(ring
, 0x00000000); /* VFD_MODE_CNTL */
1373 WRITE(REG_A6XX_VFD_UNKNOWN_A008
, 0);
1375 OUT_PKT4(ring
, REG_A6XX_PC_MODE_CNTL
, 1);
1376 OUT_RING(ring
, 0x0000001f); /* PC_MODE_CNTL */
1378 /* we don't use this yet.. probably best to disable.. */
1379 OUT_PKT7(ring
, CP_SET_DRAW_STATE
, 3);
1380 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(0) |
1381 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
1382 CP_SET_DRAW_STATE__0_GROUP_ID(0));
1383 OUT_RING(ring
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
1384 OUT_RING(ring
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
1386 OUT_PKT4(ring
, REG_A6XX_VPC_SO_BUF_CNTL
, 1);
1387 OUT_RING(ring
, 0x00000000); /* VPC_SO_BUF_CNTL */
1389 OUT_PKT4(ring
, REG_A6XX_GRAS_LRZ_CNTL
, 1);
1390 OUT_RING(ring
, 0x00000000);
1392 OUT_PKT4(ring
, REG_A6XX_RB_LRZ_CNTL
, 1);
1393 OUT_RING(ring
, 0x00000000);
1395 fd_log(batch
, "END RESTORE");
1399 fd6_mem_to_mem(struct fd_ringbuffer
*ring
, struct pipe_resource
*dst
,
1400 unsigned dst_off
, struct pipe_resource
*src
, unsigned src_off
,
1401 unsigned sizedwords
)
1403 struct fd_bo
*src_bo
= fd_resource(src
)->bo
;
1404 struct fd_bo
*dst_bo
= fd_resource(dst
)->bo
;
1407 for (i
= 0; i
< sizedwords
; i
++) {
1408 OUT_PKT7(ring
, CP_MEM_TO_MEM
, 5);
1409 OUT_RING(ring
, 0x00000000);
1410 OUT_RELOCW(ring
, dst_bo
, dst_off
, 0, 0);
1411 OUT_RELOC (ring
, src_bo
, src_off
, 0, 0);
1418 /* this is *almost* the same as fd6_cache_flush().. which I guess
1419 * could be re-worked to be something a bit more generic w/ param
1420 * indicating what needs to be flushed.. although that would mean
1421 * figuring out which events trigger what state to flush..
1424 fd6_framebuffer_barrier(struct fd_context
*ctx
)
1426 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
1427 struct fd_batch
*batch
= ctx
->batch
;
1428 struct fd_ringbuffer
*ring
= batch
->draw
;
1431 seqno
= fd6_event_write(batch
, ring
, RB_DONE_TS
, true);
1433 OUT_PKT7(ring
, CP_WAIT_REG_MEM
, 6);
1434 OUT_RING(ring
, CP_WAIT_REG_MEM_0_FUNCTION(WRITE_EQ
) |
1435 CP_WAIT_REG_MEM_0_POLL_MEMORY
);
1436 OUT_RELOC(ring
, control_ptr(fd6_ctx
, seqno
));
1437 OUT_RING(ring
, CP_WAIT_REG_MEM_3_REF(seqno
));
1438 OUT_RING(ring
, CP_WAIT_REG_MEM_4_MASK(~0));
1439 OUT_RING(ring
, CP_WAIT_REG_MEM_5_DELAY_LOOP_CYCLES(16));
1441 fd6_event_write(batch
, ring
, PC_CCU_FLUSH_COLOR_TS
, true);
1442 fd6_event_write(batch
, ring
, PC_CCU_FLUSH_DEPTH_TS
, true);
1444 seqno
= fd6_event_write(batch
, ring
, CACHE_FLUSH_TS
, true);
1446 fd6_event_write(batch
, ring
, 0x31, false);
1448 OUT_PKT7(ring
, CP_WAIT_MEM_GTE
, 4);
1449 OUT_RING(ring
, CP_WAIT_MEM_GTE_0_RESERVED(0));
1450 OUT_RELOC(ring
, control_ptr(fd6_ctx
, seqno
));
1451 OUT_RING(ring
, CP_WAIT_MEM_GTE_3_REF(seqno
));
1455 fd6_emit_init_screen(struct pipe_screen
*pscreen
)
1457 struct fd_screen
*screen
= fd_screen(pscreen
);
1458 screen
->emit_const
= fd6_emit_const
;
1459 screen
->emit_const_bo
= fd6_emit_const_bo
;
1460 screen
->emit_ib
= fd6_emit_ib
;
1461 screen
->mem_to_mem
= fd6_mem_to_mem
;
1465 fd6_emit_init(struct pipe_context
*pctx
)
1467 struct fd_context
*ctx
= fd_context(pctx
);
1468 ctx
->framebuffer_barrier
= fd6_framebuffer_barrier
;