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"
49 shader_t_to_opcode(gl_shader_stage type
)
52 case MESA_SHADER_VERTEX
:
53 case MESA_SHADER_TESS_CTRL
:
54 case MESA_SHADER_TESS_EVAL
:
55 case MESA_SHADER_GEOMETRY
:
56 return CP_LOAD_STATE6_GEOM
;
57 case MESA_SHADER_FRAGMENT
:
58 case MESA_SHADER_COMPUTE
:
59 case MESA_SHADER_KERNEL
:
60 return CP_LOAD_STATE6_FRAG
;
62 unreachable("bad shader type");
66 /* regid: base const register
67 * prsc or dwords: buffer containing constant values
68 * sizedwords: size of const value buffer
71 fd6_emit_const(struct fd_ringbuffer
*ring
, gl_shader_stage type
,
72 uint32_t regid
, uint32_t offset
, uint32_t sizedwords
,
73 const uint32_t *dwords
, struct pipe_resource
*prsc
)
76 enum a6xx_state_src src
;
78 debug_assert((regid
% 4) == 0);
79 debug_assert((sizedwords
% 4) == 0);
89 OUT_PKT7(ring
, shader_t_to_opcode(type
), 3 + sz
);
90 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(regid
/4) |
91 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
92 CP_LOAD_STATE6_0_STATE_SRC(src
) |
93 CP_LOAD_STATE6_0_STATE_BLOCK(fd6_stage2shadersb(type
)) |
94 CP_LOAD_STATE6_0_NUM_UNIT(sizedwords
/4));
96 struct fd_bo
*bo
= fd_resource(prsc
)->bo
;
97 OUT_RELOC(ring
, bo
, offset
, 0, 0);
99 OUT_RING(ring
, CP_LOAD_STATE6_1_EXT_SRC_ADDR(0));
100 OUT_RING(ring
, CP_LOAD_STATE6_2_EXT_SRC_ADDR_HI(0));
101 dwords
= (uint32_t *)&((uint8_t *)dwords
)[offset
];
103 for (i
= 0; i
< sz
; i
++) {
104 OUT_RING(ring
, dwords
[i
]);
109 fd6_emit_const_bo(struct fd_ringbuffer
*ring
, gl_shader_stage type
, boolean write
,
110 uint32_t regid
, uint32_t num
, struct pipe_resource
**prscs
, uint32_t *offsets
)
112 uint32_t anum
= align(num
, 2);
115 debug_assert((regid
% 4) == 0);
117 OUT_PKT7(ring
, shader_t_to_opcode(type
), 3 + (2 * anum
));
118 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(regid
/4) |
119 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
)|
120 CP_LOAD_STATE6_0_STATE_SRC(SS6_DIRECT
) |
121 CP_LOAD_STATE6_0_STATE_BLOCK(fd6_stage2shadersb(type
)) |
122 CP_LOAD_STATE6_0_NUM_UNIT(anum
/2));
123 OUT_RING(ring
, CP_LOAD_STATE6_1_EXT_SRC_ADDR(0));
124 OUT_RING(ring
, CP_LOAD_STATE6_2_EXT_SRC_ADDR_HI(0));
126 for (i
= 0; i
< num
; i
++) {
129 OUT_RELOCW(ring
, fd_resource(prscs
[i
])->bo
, offsets
[i
], 0, 0);
131 OUT_RELOC(ring
, fd_resource(prscs
[i
])->bo
, offsets
[i
], 0, 0);
134 OUT_RING(ring
, 0xbad00000 | (i
<< 16));
135 OUT_RING(ring
, 0xbad00000 | (i
<< 16));
139 for (; i
< anum
; i
++) {
140 OUT_RING(ring
, 0xffffffff);
141 OUT_RING(ring
, 0xffffffff);
145 /* Border color layout is diff from a4xx/a5xx.. if it turns out to be
146 * the same as a6xx then move this somewhere common ;-)
148 * Entry layout looks like (total size, 0x60 bytes):
151 struct PACKED bcolor_entry
{
163 uint32_t z24
; /* also s8? */
164 uint16_t srgb
[4]; /* appears to duplicate fp16[], but clamped, used for srgb */
168 #define FD6_BORDER_COLOR_SIZE 0x60
169 #define FD6_BORDER_COLOR_UPLOAD_SIZE (2 * PIPE_MAX_SAMPLERS * FD6_BORDER_COLOR_SIZE)
172 setup_border_colors(struct fd_texture_stateobj
*tex
, struct bcolor_entry
*entries
)
175 STATIC_ASSERT(sizeof(struct bcolor_entry
) == FD6_BORDER_COLOR_SIZE
);
177 for (i
= 0; i
< tex
->num_samplers
; i
++) {
178 struct bcolor_entry
*e
= &entries
[i
];
179 struct pipe_sampler_state
*sampler
= tex
->samplers
[i
];
180 union pipe_color_union
*bc
;
185 bc
= &sampler
->border_color
;
190 * The border colors need to be swizzled in a particular
191 * format-dependent order. Even though samplers don't know about
192 * formats, we can assume that with a GL state tracker, there's a
193 * 1:1 correspondence between sampler and texture. Take advantage
196 if ((i
>= tex
->num_textures
) || !tex
->textures
[i
])
199 enum pipe_format format
= tex
->textures
[i
]->format
;
200 const struct util_format_description
*desc
=
201 util_format_description(format
);
209 for (j
= 0; j
< 4; j
++) {
210 int c
= desc
->swizzle
[j
];
214 * HACK: for PIPE_FORMAT_X24S8_UINT we end up w/ the
215 * stencil border color value in bc->ui[0] but according
216 * to desc->swizzle and desc->channel, the .x component
217 * is NONE and the stencil value is in the y component.
218 * Meanwhile the hardware wants this in the .x componetn.
220 if ((format
== PIPE_FORMAT_X24S8_UINT
) ||
221 (format
== PIPE_FORMAT_X32_S8X24_UINT
)) {
233 if (desc
->channel
[c
].pure_integer
) {
235 switch (desc
->channel
[c
].size
) {
237 assert(desc
->channel
[c
].type
== UTIL_FORMAT_TYPE_UNSIGNED
);
238 clamped
= CLAMP(bc
->ui
[j
], 0, 0x3);
241 if (desc
->channel
[c
].type
== UTIL_FORMAT_TYPE_SIGNED
)
242 clamped
= CLAMP(bc
->i
[j
], -128, 127);
244 clamped
= CLAMP(bc
->ui
[j
], 0, 255);
247 assert(desc
->channel
[c
].type
== UTIL_FORMAT_TYPE_UNSIGNED
);
248 clamped
= CLAMP(bc
->ui
[j
], 0, 0x3ff);
251 if (desc
->channel
[c
].type
== UTIL_FORMAT_TYPE_SIGNED
)
252 clamped
= CLAMP(bc
->i
[j
], -32768, 32767);
254 clamped
= CLAMP(bc
->ui
[j
], 0, 65535);
257 assert(!"Unexpected bit size");
262 e
->fp32
[cd
] = bc
->ui
[j
];
263 e
->fp16
[cd
] = clamped
;
266 float f_u
= CLAMP(f
, 0, 1);
267 float f_s
= CLAMP(f
, -1, 1);
270 e
->fp16
[c
] = util_float_to_half(f
);
271 e
->srgb
[c
] = util_float_to_half(f_u
);
272 e
->ui16
[c
] = f_u
* 0xffff;
273 e
->si16
[c
] = f_s
* 0x7fff;
274 e
->ui8
[c
] = f_u
* 0xff;
275 e
->si8
[c
] = f_s
* 0x7f;
277 e
->rgb565
|= (int)(f_u
* 0x3f) << 5;
279 e
->rgb565
|= (int)(f_u
* 0x1f) << (c
? 11 : 0);
281 e
->rgb5a1
|= (f_u
> 0.5) ? 0x8000 : 0;
283 e
->rgb5a1
|= (int)(f_u
* 0x1f) << (c
* 5);
285 e
->rgb10a2
|= (int)(f_u
* 0x3) << 30;
287 e
->rgb10a2
|= (int)(f_u
* 0x3ff) << (c
* 10);
288 e
->rgba4
|= (int)(f_u
* 0xf) << (c
* 4);
290 e
->z24
= f_u
* 0xffffff;
295 memset(&e
->__pad0
, 0, sizeof(e
->__pad0
));
296 memset(&e
->__pad1
, 0, sizeof(e
->__pad1
));
302 emit_border_color(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
)
304 struct fd6_context
*fd6_ctx
= fd6_context(ctx
);
305 struct bcolor_entry
*entries
;
309 STATIC_ASSERT(sizeof(struct bcolor_entry
) == FD6_BORDER_COLOR_SIZE
);
311 u_upload_alloc(fd6_ctx
->border_color_uploader
,
312 0, FD6_BORDER_COLOR_UPLOAD_SIZE
,
313 FD6_BORDER_COLOR_UPLOAD_SIZE
, &off
,
314 &fd6_ctx
->border_color_buf
,
319 setup_border_colors(&ctx
->tex
[PIPE_SHADER_VERTEX
], &entries
[0]);
320 setup_border_colors(&ctx
->tex
[PIPE_SHADER_FRAGMENT
],
321 &entries
[ctx
->tex
[PIPE_SHADER_VERTEX
].num_samplers
]);
323 OUT_PKT4(ring
, REG_A6XX_SP_TP_BORDER_COLOR_BASE_ADDR_LO
, 2);
324 OUT_RELOC(ring
, fd_resource(fd6_ctx
->border_color_buf
)->bo
, off
, 0, 0);
326 u_upload_unmap(fd6_ctx
->border_color_uploader
);
330 fd6_emit_textures(struct fd_pipe
*pipe
, struct fd_ringbuffer
*ring
,
331 enum a6xx_state_block sb
, struct fd_texture_stateobj
*tex
,
332 unsigned bcolor_offset
,
333 /* can be NULL if no image/SSBO state to merge in: */
334 const struct ir3_shader_variant
*v
, struct fd_shaderbuf_stateobj
*buf
,
335 struct fd_shaderimg_stateobj
*img
)
337 bool needs_border
= false;
338 unsigned opcode
, tex_samp_reg
, tex_const_reg
, tex_count_reg
;
342 opcode
= CP_LOAD_STATE6_GEOM
;
343 tex_samp_reg
= REG_A6XX_SP_VS_TEX_SAMP_LO
;
344 tex_const_reg
= REG_A6XX_SP_VS_TEX_CONST_LO
;
345 tex_count_reg
= REG_A6XX_SP_VS_TEX_COUNT
;
348 opcode
= CP_LOAD_STATE6_FRAG
;
349 tex_samp_reg
= REG_A6XX_SP_FS_TEX_SAMP_LO
;
350 tex_const_reg
= REG_A6XX_SP_FS_TEX_CONST_LO
;
351 tex_count_reg
= REG_A6XX_SP_FS_TEX_COUNT
;
354 opcode
= CP_LOAD_STATE6_FRAG
;
355 tex_samp_reg
= REG_A6XX_SP_CS_TEX_SAMP_LO
;
356 tex_const_reg
= REG_A6XX_SP_CS_TEX_CONST_LO
;
357 tex_count_reg
= REG_A6XX_SP_CS_TEX_COUNT
;
360 unreachable("bad state block");
363 if (tex
->num_samplers
> 0) {
364 struct fd_ringbuffer
*state
=
365 fd_ringbuffer_new_object(pipe
, tex
->num_samplers
* 4 * 4);
366 for (unsigned i
= 0; i
< tex
->num_samplers
; i
++) {
367 static const struct fd6_sampler_stateobj dummy_sampler
= {};
368 const struct fd6_sampler_stateobj
*sampler
= tex
->samplers
[i
] ?
369 fd6_sampler_stateobj(tex
->samplers
[i
]) : &dummy_sampler
;
370 OUT_RING(state
, sampler
->texsamp0
);
371 OUT_RING(state
, sampler
->texsamp1
);
372 OUT_RING(state
, sampler
->texsamp2
|
373 A6XX_TEX_SAMP_2_BCOLOR_OFFSET((i
+ bcolor_offset
) * sizeof(struct bcolor_entry
)));
374 OUT_RING(state
, sampler
->texsamp3
);
375 needs_border
|= sampler
->needs_border
;
378 /* output sampler state: */
379 OUT_PKT7(ring
, opcode
, 3);
380 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(0) |
381 CP_LOAD_STATE6_0_STATE_TYPE(ST6_SHADER
) |
382 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
383 CP_LOAD_STATE6_0_STATE_BLOCK(sb
) |
384 CP_LOAD_STATE6_0_NUM_UNIT(tex
->num_samplers
));
385 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
387 OUT_PKT4(ring
, tex_samp_reg
, 2);
388 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
390 fd_ringbuffer_del(state
);
393 unsigned num_merged_textures
= tex
->num_textures
;
394 unsigned num_textures
= tex
->num_textures
;
396 num_merged_textures
+= v
->image_mapping
.num_tex
;
398 /* There could be more bound textures than what the shader uses.
399 * Which isn't known at shader compile time. So in the case we
400 * are merging tex state, only emit the textures that the shader
401 * uses (since the image/SSBO related tex state comes immediately
404 num_textures
= v
->image_mapping
.tex_base
;
407 if (num_merged_textures
> 0) {
408 struct fd_ringbuffer
*state
=
409 fd_ringbuffer_new_object(pipe
, num_merged_textures
* 16 * 4);
410 for (unsigned i
= 0; i
< num_textures
; i
++) {
411 static const struct fd6_pipe_sampler_view dummy_view
= {};
412 const struct fd6_pipe_sampler_view
*view
= tex
->textures
[i
] ?
413 fd6_pipe_sampler_view(tex
->textures
[i
]) : &dummy_view
;
415 OUT_RING(state
, view
->texconst0
);
416 OUT_RING(state
, view
->texconst1
);
417 OUT_RING(state
, view
->texconst2
);
418 OUT_RING(state
, view
->texconst3
);
420 if (view
->base
.texture
) {
421 struct fd_resource
*rsc
= fd_resource(view
->base
.texture
);
422 if (view
->base
.format
== PIPE_FORMAT_X32_S8X24_UINT
)
424 OUT_RELOC(state
, rsc
->bo
, view
->offset
,
425 (uint64_t)view
->texconst5
<< 32, 0);
427 OUT_RING(state
, 0x00000000);
428 OUT_RING(state
, view
->texconst5
);
431 OUT_RING(state
, view
->texconst6
);
432 OUT_RING(state
, view
->texconst7
);
433 OUT_RING(state
, view
->texconst8
);
434 OUT_RING(state
, view
->texconst9
);
435 OUT_RING(state
, view
->texconst10
);
436 OUT_RING(state
, view
->texconst11
);
444 const struct ir3_ibo_mapping
*mapping
= &v
->image_mapping
;
446 for (unsigned i
= 0; i
< mapping
->num_tex
; i
++) {
447 unsigned idx
= mapping
->tex_to_image
[i
];
448 if (idx
& IBO_SSBO
) {
449 fd6_emit_ssbo_tex(state
, &buf
->sb
[idx
& ~IBO_SSBO
]);
451 fd6_emit_image_tex(state
, &img
->si
[idx
]);
456 /* emit texture state: */
457 OUT_PKT7(ring
, opcode
, 3);
458 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(0) |
459 CP_LOAD_STATE6_0_STATE_TYPE(ST6_CONSTANTS
) |
460 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
461 CP_LOAD_STATE6_0_STATE_BLOCK(sb
) |
462 CP_LOAD_STATE6_0_NUM_UNIT(num_merged_textures
));
463 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
465 OUT_PKT4(ring
, tex_const_reg
, 2);
466 OUT_RB(ring
, state
); /* SRC_ADDR_LO/HI */
468 fd_ringbuffer_del(state
);
471 OUT_PKT4(ring
, tex_count_reg
, 1);
472 OUT_RING(ring
, num_merged_textures
);
477 /* Emits combined texture state, which also includes any Image/SSBO
478 * related texture state merged in (because we must have all texture
479 * state for a given stage in a single buffer). In the fast-path, if
480 * we don't need to merge in any image/ssbo related texture state, we
481 * just use cached texture stateobj. Otherwise we generate a single-
484 * TODO Is there some sane way we can still use cached texture stateobj
485 * with image/ssbo in use?
487 * returns whether border_color is required:
490 fd6_emit_combined_textures(struct fd_ringbuffer
*ring
, struct fd6_emit
*emit
,
491 enum pipe_shader_type type
, const struct ir3_shader_variant
*v
)
493 struct fd_context
*ctx
= emit
->ctx
;
494 bool needs_border
= false;
496 static const struct {
497 enum a6xx_state_block sb
;
498 enum fd6_state_id state_id
;
499 } s
[PIPE_SHADER_TYPES
] = {
500 [PIPE_SHADER_VERTEX
] = { SB6_VS_TEX
, FD6_GROUP_VS_TEX
},
501 [PIPE_SHADER_FRAGMENT
] = { SB6_FS_TEX
, FD6_GROUP_FS_TEX
},
504 debug_assert(s
[type
].state_id
);
506 if (!v
->image_mapping
.num_tex
) {
507 /* in the fast-path, when we don't have to mix in any image/SSBO
508 * related texture state, we can just lookup the stateobj and
511 if ((ctx
->dirty_shader
[type
] & FD_DIRTY_SHADER_TEX
) &&
512 ctx
->tex
[type
].num_textures
> 0) {
513 struct fd6_texture_state
*tex
= fd6_texture_state(ctx
,
514 s
[type
].sb
, &ctx
->tex
[type
]);
516 needs_border
|= tex
->needs_border
;
518 fd6_emit_add_group(emit
, tex
->stateobj
, s
[type
].state_id
, 0x7);
521 /* In the slow-path, create a one-shot texture state object
522 * if either TEX|PROG|SSBO|IMAGE state is dirty:
524 if (ctx
->dirty_shader
[type
] &
525 (FD_DIRTY_SHADER_TEX
| FD_DIRTY_SHADER_PROG
|
526 FD_DIRTY_SHADER_IMAGE
| FD_DIRTY_SHADER_SSBO
)) {
527 struct fd_texture_stateobj
*tex
= &ctx
->tex
[type
];
528 struct fd_shaderbuf_stateobj
*buf
= &ctx
->shaderbuf
[type
];
529 struct fd_shaderimg_stateobj
*img
= &ctx
->shaderimg
[type
];
530 struct fd_ringbuffer
*stateobj
=
531 fd_submit_new_ringbuffer(ctx
->batch
->submit
,
532 0x1000, FD_RINGBUFFER_STREAMING
);
533 unsigned bcolor_offset
=
534 fd6_border_color_offset(ctx
, s
[type
].sb
, tex
);
536 needs_border
|= fd6_emit_textures(ctx
->pipe
, stateobj
, s
[type
].sb
, tex
,
537 bcolor_offset
, v
, buf
, img
);
539 fd6_emit_add_group(emit
, stateobj
, s
[type
].state_id
, 0x7);
541 fd_ringbuffer_del(stateobj
);
548 static struct fd_ringbuffer
*
549 build_vbo_state(struct fd6_emit
*emit
, const struct ir3_shader_variant
*vp
)
551 const struct fd_vertex_state
*vtx
= emit
->vtx
;
554 struct fd_ringbuffer
*ring
= fd_submit_new_ringbuffer(emit
->ctx
->batch
->submit
,
555 4 * (10 * vp
->inputs_count
+ 2), FD_RINGBUFFER_STREAMING
);
557 for (i
= 0, j
= 0; i
<= vp
->inputs_count
; i
++) {
558 if (vp
->inputs
[i
].sysval
)
560 if (vp
->inputs
[i
].compmask
) {
561 struct pipe_vertex_element
*elem
= &vtx
->vtx
->pipe
[i
];
562 const struct pipe_vertex_buffer
*vb
=
563 &vtx
->vertexbuf
.vb
[elem
->vertex_buffer_index
];
564 struct fd_resource
*rsc
= fd_resource(vb
->buffer
.resource
);
565 enum pipe_format pfmt
= elem
->src_format
;
566 enum a6xx_vtx_fmt fmt
= fd6_pipe2vtx(pfmt
);
567 bool isint
= util_format_is_pure_integer(pfmt
);
568 uint32_t off
= vb
->buffer_offset
+ elem
->src_offset
;
569 uint32_t size
= fd_bo_size(rsc
->bo
) - off
;
570 debug_assert(fmt
!= ~0);
573 /* see dEQP-GLES31.stress.vertex_attribute_binding.buffer_bounds.bind_vertex_buffer_offset_near_wrap_10
575 if (off
> fd_bo_size(rsc
->bo
))
579 OUT_PKT4(ring
, REG_A6XX_VFD_FETCH(j
), 4);
580 OUT_RELOC(ring
, rsc
->bo
, off
, 0, 0);
581 OUT_RING(ring
, size
); /* VFD_FETCH[j].SIZE */
582 OUT_RING(ring
, vb
->stride
); /* VFD_FETCH[j].STRIDE */
584 OUT_PKT4(ring
, REG_A6XX_VFD_DECODE(j
), 2);
585 OUT_RING(ring
, A6XX_VFD_DECODE_INSTR_IDX(j
) |
586 A6XX_VFD_DECODE_INSTR_FORMAT(fmt
) |
587 COND(elem
->instance_divisor
, A6XX_VFD_DECODE_INSTR_INSTANCED
) |
588 A6XX_VFD_DECODE_INSTR_SWAP(fd6_pipe2swap(pfmt
)) |
589 A6XX_VFD_DECODE_INSTR_UNK30
|
590 COND(!isint
, A6XX_VFD_DECODE_INSTR_FLOAT
));
591 OUT_RING(ring
, MAX2(1, elem
->instance_divisor
)); /* VFD_DECODE[j].STEP_RATE */
593 OUT_PKT4(ring
, REG_A6XX_VFD_DEST_CNTL(j
), 1);
594 OUT_RING(ring
, A6XX_VFD_DEST_CNTL_INSTR_WRITEMASK(vp
->inputs
[i
].compmask
) |
595 A6XX_VFD_DEST_CNTL_INSTR_REGID(vp
->inputs
[i
].regid
));
601 OUT_PKT4(ring
, REG_A6XX_VFD_CONTROL_0
, 1);
602 OUT_RING(ring
, A6XX_VFD_CONTROL_0_VTXCNT(j
) | (j
<< 8));
607 static struct fd_ringbuffer
*
608 build_lrz(struct fd6_emit
*emit
, bool binning_pass
)
610 struct fd6_zsa_stateobj
*zsa
= fd6_zsa_stateobj(emit
->ctx
->zsa
);
611 struct pipe_framebuffer_state
*pfb
= &emit
->ctx
->batch
->framebuffer
;
612 struct fd_resource
*rsc
= fd_resource(pfb
->zsbuf
->texture
);
613 uint32_t gras_lrz_cntl
= zsa
->gras_lrz_cntl
;
614 uint32_t rb_lrz_cntl
= zsa
->rb_lrz_cntl
;
616 struct fd_ringbuffer
*ring
= fd_submit_new_ringbuffer(emit
->ctx
->batch
->submit
,
617 16, FD_RINGBUFFER_STREAMING
);
619 if (emit
->no_lrz_write
|| !rsc
->lrz
|| !rsc
->lrz_valid
) {
622 } else if (binning_pass
&& zsa
->lrz_write
) {
623 gras_lrz_cntl
|= A6XX_GRAS_LRZ_CNTL_LRZ_WRITE
;
626 OUT_PKT4(ring
, REG_A6XX_GRAS_LRZ_CNTL
, 1);
627 OUT_RING(ring
, gras_lrz_cntl
);
629 OUT_PKT4(ring
, REG_A6XX_RB_LRZ_CNTL
, 1);
630 OUT_RING(ring
, rb_lrz_cntl
);
636 fd6_emit_streamout(struct fd_ringbuffer
*ring
, struct fd6_emit
*emit
, struct ir3_stream_output_info
*info
)
638 struct fd_context
*ctx
= emit
->ctx
;
639 const struct fd6_program_state
*prog
= fd6_emit_get_prog(emit
);
640 struct fd_streamout_stateobj
*so
= &ctx
->streamout
;
642 emit
->streamout_mask
= 0;
644 for (unsigned i
= 0; i
< so
->num_targets
; i
++) {
645 struct pipe_stream_output_target
*target
= so
->targets
[i
];
650 unsigned offset
= (so
->offsets
[i
] * info
->stride
[i
] * 4) +
651 target
->buffer_offset
;
653 OUT_PKT4(ring
, REG_A6XX_VPC_SO_BUFFER_BASE_LO(i
), 3);
654 /* VPC_SO[i].BUFFER_BASE_LO: */
655 OUT_RELOCW(ring
, fd_resource(target
->buffer
)->bo
, 0, 0, 0);
656 OUT_RING(ring
, target
->buffer_size
+ offset
);
658 OUT_PKT4(ring
, REG_A6XX_VPC_SO_BUFFER_OFFSET(i
), 3);
659 OUT_RING(ring
, offset
);
660 /* VPC_SO[i].FLUSH_BASE_LO/HI: */
661 // TODO just give hw a dummy addr for now.. we should
662 // be using this an then CP_MEM_TO_REG to set the
663 // VPC_SO[i].BUFFER_OFFSET for the next draw..
664 OUT_RELOCW(ring
, fd6_context(ctx
)->blit_mem
, 0x100, 0, 0);
666 emit
->streamout_mask
|= (1 << i
);
669 if (emit
->streamout_mask
) {
670 const struct fd6_streamout_state
*tf
= &prog
->tf
;
672 OUT_PKT7(ring
, CP_CONTEXT_REG_BUNCH
, 12 + (2 * tf
->prog_count
));
673 OUT_RING(ring
, REG_A6XX_VPC_SO_BUF_CNTL
);
674 OUT_RING(ring
, tf
->vpc_so_buf_cntl
);
675 OUT_RING(ring
, REG_A6XX_VPC_SO_NCOMP(0));
676 OUT_RING(ring
, tf
->ncomp
[0]);
677 OUT_RING(ring
, REG_A6XX_VPC_SO_NCOMP(1));
678 OUT_RING(ring
, tf
->ncomp
[1]);
679 OUT_RING(ring
, REG_A6XX_VPC_SO_NCOMP(2));
680 OUT_RING(ring
, tf
->ncomp
[2]);
681 OUT_RING(ring
, REG_A6XX_VPC_SO_NCOMP(3));
682 OUT_RING(ring
, tf
->ncomp
[3]);
683 OUT_RING(ring
, REG_A6XX_VPC_SO_CNTL
);
684 OUT_RING(ring
, A6XX_VPC_SO_CNTL_ENABLE
);
685 for (unsigned i
= 0; i
< tf
->prog_count
; i
++) {
686 OUT_RING(ring
, REG_A6XX_VPC_SO_PROG
);
687 OUT_RING(ring
, tf
->prog
[i
]);
690 OUT_PKT4(ring
, REG_A6XX_VPC_SO_OVERRIDE
, 1);
693 OUT_PKT7(ring
, CP_CONTEXT_REG_BUNCH
, 4);
694 OUT_RING(ring
, REG_A6XX_VPC_SO_CNTL
);
696 OUT_RING(ring
, REG_A6XX_VPC_SO_BUF_CNTL
);
699 OUT_PKT4(ring
, REG_A6XX_VPC_SO_OVERRIDE
, 1);
700 OUT_RING(ring
, A6XX_VPC_SO_OVERRIDE_SO_DISABLE
);
706 fd6_emit_state(struct fd_ringbuffer
*ring
, struct fd6_emit
*emit
)
708 struct fd_context
*ctx
= emit
->ctx
;
709 struct pipe_framebuffer_state
*pfb
= &ctx
->batch
->framebuffer
;
710 const struct fd6_program_state
*prog
= fd6_emit_get_prog(emit
);
711 const struct ir3_shader_variant
*vp
= emit
->vs
;
712 const struct ir3_shader_variant
*fp
= emit
->fs
;
713 const enum fd_dirty_3d_state dirty
= emit
->dirty
;
714 bool needs_border
= false;
716 emit_marker6(ring
, 5);
718 if (emit
->dirty
& (FD_DIRTY_VTXBUF
| FD_DIRTY_VTXSTATE
)) {
719 struct fd_ringbuffer
*state
;
721 state
= build_vbo_state(emit
, emit
->vs
);
722 fd6_emit_add_group(emit
, state
, FD6_GROUP_VBO
, 0x6);
723 fd_ringbuffer_del(state
);
725 state
= build_vbo_state(emit
, emit
->bs
);
726 fd6_emit_add_group(emit
, state
, FD6_GROUP_VBO_BINNING
, 0x1);
727 fd_ringbuffer_del(state
);
730 if (dirty
& FD_DIRTY_ZSA
) {
731 struct fd6_zsa_stateobj
*zsa
= fd6_zsa_stateobj(ctx
->zsa
);
733 if (util_format_is_pure_integer(pipe_surface_format(pfb
->cbufs
[0])))
734 fd6_emit_add_group(emit
, zsa
->stateobj_no_alpha
, FD6_GROUP_ZSA
, 0x7);
736 fd6_emit_add_group(emit
, zsa
->stateobj
, FD6_GROUP_ZSA
, 0x7);
739 if ((dirty
& (FD_DIRTY_ZSA
| FD_DIRTY_PROG
)) && pfb
->zsbuf
) {
740 struct fd_ringbuffer
*state
;
742 state
= build_lrz(emit
, false);
743 fd6_emit_add_group(emit
, state
, FD6_GROUP_LRZ
, 0x6);
744 fd_ringbuffer_del(state
);
746 state
= build_lrz(emit
, true);
747 fd6_emit_add_group(emit
, state
, FD6_GROUP_LRZ_BINNING
, 0x1);
748 fd_ringbuffer_del(state
);
751 if (dirty
& FD_DIRTY_STENCIL_REF
) {
752 struct pipe_stencil_ref
*sr
= &ctx
->stencil_ref
;
754 OUT_PKT4(ring
, REG_A6XX_RB_STENCILREF
, 1);
755 OUT_RING(ring
, A6XX_RB_STENCILREF_REF(sr
->ref_value
[0]) |
756 A6XX_RB_STENCILREF_BFREF(sr
->ref_value
[1]));
759 /* NOTE: scissor enabled bit is part of rasterizer state: */
760 if (dirty
& (FD_DIRTY_SCISSOR
| FD_DIRTY_RASTERIZER
)) {
761 struct pipe_scissor_state
*scissor
= fd_context_get_scissor(ctx
);
763 OUT_PKT4(ring
, REG_A6XX_GRAS_SC_SCREEN_SCISSOR_TL_0
, 2);
764 OUT_RING(ring
, A6XX_GRAS_SC_SCREEN_SCISSOR_TL_0_X(scissor
->minx
) |
765 A6XX_GRAS_SC_SCREEN_SCISSOR_TL_0_Y(scissor
->miny
));
766 OUT_RING(ring
, A6XX_GRAS_SC_SCREEN_SCISSOR_TL_0_X(scissor
->maxx
- 1) |
767 A6XX_GRAS_SC_SCREEN_SCISSOR_TL_0_Y(scissor
->maxy
- 1));
769 ctx
->batch
->max_scissor
.minx
= MIN2(ctx
->batch
->max_scissor
.minx
, scissor
->minx
);
770 ctx
->batch
->max_scissor
.miny
= MIN2(ctx
->batch
->max_scissor
.miny
, scissor
->miny
);
771 ctx
->batch
->max_scissor
.maxx
= MAX2(ctx
->batch
->max_scissor
.maxx
, scissor
->maxx
);
772 ctx
->batch
->max_scissor
.maxy
= MAX2(ctx
->batch
->max_scissor
.maxy
, scissor
->maxy
);
775 if (dirty
& FD_DIRTY_VIEWPORT
) {
776 struct pipe_scissor_state
*scissor
= &ctx
->viewport_scissor
;
778 OUT_PKT4(ring
, REG_A6XX_GRAS_CL_VPORT_XOFFSET_0
, 6);
779 OUT_RING(ring
, A6XX_GRAS_CL_VPORT_XOFFSET_0(ctx
->viewport
.translate
[0]));
780 OUT_RING(ring
, A6XX_GRAS_CL_VPORT_XSCALE_0(ctx
->viewport
.scale
[0]));
781 OUT_RING(ring
, A6XX_GRAS_CL_VPORT_YOFFSET_0(ctx
->viewport
.translate
[1]));
782 OUT_RING(ring
, A6XX_GRAS_CL_VPORT_YSCALE_0(ctx
->viewport
.scale
[1]));
783 OUT_RING(ring
, A6XX_GRAS_CL_VPORT_ZOFFSET_0(ctx
->viewport
.translate
[2]));
784 OUT_RING(ring
, A6XX_GRAS_CL_VPORT_ZSCALE_0(ctx
->viewport
.scale
[2]));
786 OUT_PKT4(ring
, REG_A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0
, 2);
787 OUT_RING(ring
, A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0_X(scissor
->minx
) |
788 A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0_Y(scissor
->miny
));
789 OUT_RING(ring
, A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0_X(scissor
->maxx
- 1) |
790 A6XX_GRAS_SC_VIEWPORT_SCISSOR_TL_0_Y(scissor
->maxy
- 1));
792 unsigned guardband_x
= fd_calc_guardband(scissor
->maxx
- scissor
->minx
);
793 unsigned guardband_y
= fd_calc_guardband(scissor
->maxy
- scissor
->miny
);
795 OUT_PKT4(ring
, REG_A6XX_GRAS_CL_GUARDBAND_CLIP_ADJ
, 1);
796 OUT_RING(ring
, A6XX_GRAS_CL_GUARDBAND_CLIP_ADJ_HORZ(guardband_x
) |
797 A6XX_GRAS_CL_GUARDBAND_CLIP_ADJ_VERT(guardband_y
));
800 if (dirty
& FD_DIRTY_PROG
) {
801 fd6_emit_add_group(emit
, prog
->stateobj
, FD6_GROUP_PROG
, 0x6);
802 fd6_emit_add_group(emit
, prog
->binning_stateobj
,
803 FD6_GROUP_PROG_BINNING
, 0x1);
805 /* emit remaining non-stateobj program state, ie. what depends
806 * on other emit state, so cannot be pre-baked. This could
807 * be moved to a separate stateobj which is dynamically
810 fd6_program_emit(ring
, emit
);
813 if (dirty
& FD_DIRTY_RASTERIZER
) {
814 struct fd6_rasterizer_stateobj
*rasterizer
=
815 fd6_rasterizer_stateobj(ctx
->rasterizer
);
816 fd6_emit_add_group(emit
, rasterizer
->stateobj
,
817 FD6_GROUP_RASTERIZER
, 0x7);
820 /* Since the primitive restart state is not part of a tracked object, we
821 * re-emit this register every time.
823 if (emit
->info
&& ctx
->rasterizer
) {
824 struct fd6_rasterizer_stateobj
*rasterizer
=
825 fd6_rasterizer_stateobj(ctx
->rasterizer
);
826 OUT_PKT4(ring
, REG_A6XX_PC_UNKNOWN_9806
, 1);
828 OUT_PKT4(ring
, REG_A6XX_PC_UNKNOWN_9990
, 1);
830 OUT_PKT4(ring
, REG_A6XX_VFD_UNKNOWN_A008
, 1);
833 OUT_PKT4(ring
, REG_A6XX_PC_PRIMITIVE_CNTL_0
, 1);
834 OUT_RING(ring
, rasterizer
->pc_primitive_cntl
|
835 COND(emit
->info
->primitive_restart
&& emit
->info
->index_size
,
836 A6XX_PC_PRIMITIVE_CNTL_0_PRIMITIVE_RESTART
));
839 if (dirty
& (FD_DIRTY_FRAMEBUFFER
| FD_DIRTY_RASTERIZER
| FD_DIRTY_PROG
)) {
840 unsigned nr
= pfb
->nr_cbufs
;
842 if (ctx
->rasterizer
->rasterizer_discard
)
845 OUT_PKT4(ring
, REG_A6XX_RB_FS_OUTPUT_CNTL0
, 2);
846 OUT_RING(ring
, COND(fp
->writes_pos
, A6XX_RB_FS_OUTPUT_CNTL0_FRAG_WRITES_Z
));
847 OUT_RING(ring
, A6XX_RB_FS_OUTPUT_CNTL1_MRT(nr
));
849 OUT_PKT4(ring
, REG_A6XX_SP_FS_OUTPUT_CNTL1
, 1);
850 OUT_RING(ring
, A6XX_SP_FS_OUTPUT_CNTL1_MRT(nr
));
853 #define DIRTY_CONST (FD_DIRTY_SHADER_PROG | FD_DIRTY_SHADER_CONST | \
854 FD_DIRTY_SHADER_SSBO | FD_DIRTY_SHADER_IMAGE)
856 if (ctx
->dirty_shader
[PIPE_SHADER_VERTEX
] & DIRTY_CONST
) {
857 struct fd_ringbuffer
*vsconstobj
= fd_submit_new_ringbuffer(
858 ctx
->batch
->submit
, 0x1000, FD_RINGBUFFER_STREAMING
);
860 OUT_WFI5(vsconstobj
);
861 ir3_emit_vs_consts(vp
, vsconstobj
, ctx
, emit
->info
);
862 fd6_emit_add_group(emit
, vsconstobj
, FD6_GROUP_VS_CONST
, 0x7);
863 fd_ringbuffer_del(vsconstobj
);
866 if (ctx
->dirty_shader
[PIPE_SHADER_FRAGMENT
] & DIRTY_CONST
) {
867 struct fd_ringbuffer
*fsconstobj
= fd_submit_new_ringbuffer(
868 ctx
->batch
->submit
, 0x1000, FD_RINGBUFFER_STREAMING
);
870 OUT_WFI5(fsconstobj
);
871 ir3_emit_fs_consts(fp
, fsconstobj
, ctx
);
872 fd6_emit_add_group(emit
, fsconstobj
, FD6_GROUP_FS_CONST
, 0x6);
873 fd_ringbuffer_del(fsconstobj
);
876 struct ir3_stream_output_info
*info
= &vp
->shader
->stream_output
;
877 if (info
->num_outputs
)
878 fd6_emit_streamout(ring
, emit
, info
);
880 if (dirty
& FD_DIRTY_BLEND
) {
881 struct fd6_blend_stateobj
*blend
= fd6_blend_stateobj(ctx
->blend
);
884 for (i
= 0; i
< pfb
->nr_cbufs
; i
++) {
885 enum pipe_format format
= pipe_surface_format(pfb
->cbufs
[i
]);
886 bool is_int
= util_format_is_pure_integer(format
);
887 bool has_alpha
= util_format_has_alpha(format
);
888 uint32_t control
= blend
->rb_mrt
[i
].control
;
889 uint32_t blend_control
= blend
->rb_mrt
[i
].blend_control_alpha
;
892 control
&= A6XX_RB_MRT_CONTROL_COMPONENT_ENABLE__MASK
;
893 control
|= A6XX_RB_MRT_CONTROL_ROP_CODE(ROP_COPY
);
897 blend_control
|= blend
->rb_mrt
[i
].blend_control_rgb
;
899 blend_control
|= blend
->rb_mrt
[i
].blend_control_no_alpha_rgb
;
900 control
&= ~A6XX_RB_MRT_CONTROL_BLEND2
;
903 OUT_PKT4(ring
, REG_A6XX_RB_MRT_CONTROL(i
), 1);
904 OUT_RING(ring
, control
);
906 OUT_PKT4(ring
, REG_A6XX_RB_MRT_BLEND_CONTROL(i
), 1);
907 OUT_RING(ring
, blend_control
);
910 OUT_PKT4(ring
, REG_A6XX_SP_BLEND_CNTL
, 1);
911 OUT_RING(ring
, blend
->sp_blend_cntl
);
914 if (dirty
& (FD_DIRTY_BLEND
| FD_DIRTY_SAMPLE_MASK
)) {
915 struct fd6_blend_stateobj
*blend
= fd6_blend_stateobj(ctx
->blend
);
917 OUT_PKT4(ring
, REG_A6XX_RB_BLEND_CNTL
, 1);
918 OUT_RING(ring
, blend
->rb_blend_cntl
|
919 A6XX_RB_BLEND_CNTL_SAMPLE_MASK(ctx
->sample_mask
));
922 if (dirty
& FD_DIRTY_BLEND_COLOR
) {
923 struct pipe_blend_color
*bcolor
= &ctx
->blend_color
;
925 OUT_PKT4(ring
, REG_A6XX_RB_BLEND_RED_F32
, 4);
926 OUT_RING(ring
, A6XX_RB_BLEND_RED_F32(bcolor
->color
[0]));
927 OUT_RING(ring
, A6XX_RB_BLEND_GREEN_F32(bcolor
->color
[1]));
928 OUT_RING(ring
, A6XX_RB_BLEND_BLUE_F32(bcolor
->color
[2]));
929 OUT_RING(ring
, A6XX_RB_BLEND_ALPHA_F32(bcolor
->color
[3]));
932 needs_border
|= fd6_emit_combined_textures(ring
, emit
, PIPE_SHADER_VERTEX
, vp
);
933 needs_border
|= fd6_emit_combined_textures(ring
, emit
, PIPE_SHADER_FRAGMENT
, fp
);
936 emit_border_color(ctx
, ring
);
938 if (ctx
->dirty_shader
[PIPE_SHADER_FRAGMENT
] &
939 (FD_DIRTY_SHADER_SSBO
| FD_DIRTY_SHADER_IMAGE
)) {
940 struct fd_ringbuffer
*state
=
941 fd6_build_ibo_state(ctx
, fp
, PIPE_SHADER_FRAGMENT
);
942 struct fd_ringbuffer
*obj
= fd_submit_new_ringbuffer(
943 ctx
->batch
->submit
, 9 * 4, FD_RINGBUFFER_STREAMING
);
944 const struct ir3_ibo_mapping
*mapping
= &fp
->image_mapping
;
946 OUT_PKT7(obj
, CP_LOAD_STATE6
, 3);
947 OUT_RING(obj
, CP_LOAD_STATE6_0_DST_OFF(0) |
948 CP_LOAD_STATE6_0_STATE_TYPE(ST6_SHADER
) |
949 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
950 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_IBO
) |
951 CP_LOAD_STATE6_0_NUM_UNIT(mapping
->num_ibo
));
954 OUT_PKT4(obj
, REG_A6XX_SP_IBO_LO
, 2);
957 OUT_PKT4(obj
, REG_A6XX_SP_IBO_COUNT
, 1);
958 OUT_RING(obj
, mapping
->num_ibo
);
960 fd6_emit_add_group(emit
, obj
, FD6_GROUP_IBO
, 0x7);
961 fd_ringbuffer_del(obj
);
962 fd_ringbuffer_del(state
);
965 if (emit
->num_groups
> 0) {
966 OUT_PKT7(ring
, CP_SET_DRAW_STATE
, 3 * emit
->num_groups
);
967 for (unsigned i
= 0; i
< emit
->num_groups
; i
++) {
968 struct fd6_state_group
*g
= &emit
->groups
[i
];
969 unsigned n
= fd_ringbuffer_size(g
->stateobj
) / 4;
972 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(0) |
973 CP_SET_DRAW_STATE__0_DISABLE
|
974 CP_SET_DRAW_STATE__0_ENABLE_MASK(g
->enable_mask
) |
975 CP_SET_DRAW_STATE__0_GROUP_ID(g
->group_id
));
976 OUT_RING(ring
, 0x00000000);
977 OUT_RING(ring
, 0x00000000);
979 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(n
) |
980 CP_SET_DRAW_STATE__0_ENABLE_MASK(g
->enable_mask
) |
981 CP_SET_DRAW_STATE__0_GROUP_ID(g
->group_id
));
982 OUT_RB(ring
, g
->stateobj
);
985 fd_ringbuffer_del(g
->stateobj
);
987 emit
->num_groups
= 0;
992 fd6_emit_cs_state(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
,
993 struct ir3_shader_variant
*cp
)
995 enum fd_dirty_shader_state dirty
= ctx
->dirty_shader
[PIPE_SHADER_COMPUTE
];
997 if (dirty
& (FD_DIRTY_SHADER_TEX
| FD_DIRTY_SHADER_PROG
|
998 FD_DIRTY_SHADER_IMAGE
| FD_DIRTY_SHADER_SSBO
)) {
999 struct fd_texture_stateobj
*tex
= &ctx
->tex
[PIPE_SHADER_COMPUTE
];
1000 struct fd_shaderbuf_stateobj
*buf
= &ctx
->shaderbuf
[PIPE_SHADER_COMPUTE
];
1001 struct fd_shaderimg_stateobj
*img
= &ctx
->shaderimg
[PIPE_SHADER_COMPUTE
];
1002 unsigned bcolor_offset
= fd6_border_color_offset(ctx
, SB6_CS_TEX
, tex
);
1004 bool needs_border
= fd6_emit_textures(ctx
->pipe
, ring
, SB6_CS_TEX
, tex
,
1005 bcolor_offset
, cp
, buf
, img
);
1008 emit_border_color(ctx
, ring
);
1010 OUT_PKT4(ring
, REG_A6XX_SP_VS_TEX_COUNT
, 1);
1013 OUT_PKT4(ring
, REG_A6XX_SP_HS_TEX_COUNT
, 1);
1016 OUT_PKT4(ring
, REG_A6XX_SP_DS_TEX_COUNT
, 1);
1019 OUT_PKT4(ring
, REG_A6XX_SP_GS_TEX_COUNT
, 1);
1022 OUT_PKT4(ring
, REG_A6XX_SP_FS_TEX_COUNT
, 1);
1026 if (dirty
& (FD_DIRTY_SHADER_SSBO
| FD_DIRTY_SHADER_IMAGE
)) {
1027 struct fd_ringbuffer
*state
=
1028 fd6_build_ibo_state(ctx
, cp
, PIPE_SHADER_COMPUTE
);
1029 const struct ir3_ibo_mapping
*mapping
= &cp
->image_mapping
;
1031 OUT_PKT7(ring
, CP_LOAD_STATE6_FRAG
, 3);
1032 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(0) |
1033 CP_LOAD_STATE6_0_STATE_TYPE(ST6_IBO
) |
1034 CP_LOAD_STATE6_0_STATE_SRC(SS6_INDIRECT
) |
1035 CP_LOAD_STATE6_0_STATE_BLOCK(SB6_CS_SHADER
) |
1036 CP_LOAD_STATE6_0_NUM_UNIT(mapping
->num_ibo
));
1037 OUT_RB(ring
, state
);
1039 OUT_PKT4(ring
, REG_A6XX_SP_CS_IBO_LO
, 2);
1040 OUT_RB(ring
, state
);
1042 OUT_PKT4(ring
, REG_A6XX_SP_CS_IBO_COUNT
, 1);
1043 OUT_RING(ring
, mapping
->num_ibo
);
1045 fd_ringbuffer_del(state
);
1050 /* emit setup at begin of new cmdstream buffer (don't rely on previous
1051 * state, there could have been a context switch between ioctls):
1054 fd6_emit_restore(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
)
1056 //struct fd_context *ctx = batch->ctx;
1058 fd6_cache_inv(batch
, ring
);
1060 OUT_PKT4(ring
, REG_A6XX_HLSQ_UPDATE_CNTL
, 1);
1061 OUT_RING(ring
, 0xfffff);
1064 t7 opcode: CP_PERFCOUNTER_ACTION (50) (4 dwords)
1065 0000000500024048: 70d08003 00000000 001c5000 00000005
1066 t7 opcode: CP_PERFCOUNTER_ACTION (50) (4 dwords)
1067 0000000500024058: 70d08003 00000010 001c7000 00000005
1069 t7 opcode: CP_WAIT_FOR_IDLE (26) (1 dwords)
1070 0000000500024068: 70268000
1073 WRITE(REG_A6XX_RB_CCU_CNTL
, 0x7c400004);
1074 WRITE(REG_A6XX_RB_UNKNOWN_8E04
, 0x00100000);
1075 WRITE(REG_A6XX_SP_UNKNOWN_AE04
, 0x8);
1076 WRITE(REG_A6XX_SP_UNKNOWN_AE00
, 0);
1077 WRITE(REG_A6XX_SP_UNKNOWN_AE0F
, 0x3f);
1078 WRITE(REG_A6XX_SP_UNKNOWN_B605
, 0x44);
1079 WRITE(REG_A6XX_SP_UNKNOWN_B600
, 0x100000);
1080 WRITE(REG_A6XX_HLSQ_UNKNOWN_BE00
, 0x80);
1081 WRITE(REG_A6XX_HLSQ_UNKNOWN_BE01
, 0);
1083 WRITE(REG_A6XX_VPC_UNKNOWN_9600
, 0);
1084 WRITE(REG_A6XX_GRAS_UNKNOWN_8600
, 0x880);
1085 WRITE(REG_A6XX_HLSQ_UNKNOWN_BE04
, 0);
1086 WRITE(REG_A6XX_SP_UNKNOWN_AE03
, 0x00000410);
1087 WRITE(REG_A6XX_SP_IBO_COUNT
, 0);
1088 WRITE(REG_A6XX_SP_UNKNOWN_B182
, 0);
1089 WRITE(REG_A6XX_HLSQ_UNKNOWN_BB11
, 0);
1090 WRITE(REG_A6XX_UCHE_UNKNOWN_0E12
, 0x3200000);
1091 WRITE(REG_A6XX_UCHE_CLIENT_PF
, 4);
1092 WRITE(REG_A6XX_RB_UNKNOWN_8E01
, 0x0);
1093 WRITE(REG_A6XX_SP_UNKNOWN_AB00
, 0x5);
1094 WRITE(REG_A6XX_VFD_UNKNOWN_A009
, 0x00000001);
1095 WRITE(REG_A6XX_RB_UNKNOWN_8811
, 0x00000010);
1096 WRITE(REG_A6XX_PC_MODE_CNTL
, 0x1f);
1098 OUT_PKT4(ring
, REG_A6XX_RB_SRGB_CNTL
, 1);
1101 WRITE(REG_A6XX_GRAS_UNKNOWN_8101
, 0);
1102 WRITE(REG_A6XX_GRAS_UNKNOWN_8109
, 0);
1103 WRITE(REG_A6XX_GRAS_UNKNOWN_8110
, 0);
1105 WRITE(REG_A6XX_RB_RENDER_CONTROL0
, 0x401);
1106 WRITE(REG_A6XX_RB_RENDER_CONTROL1
, 0);
1107 WRITE(REG_A6XX_RB_FS_OUTPUT_CNTL0
, 0);
1108 WRITE(REG_A6XX_RB_UNKNOWN_8810
, 0);
1109 WRITE(REG_A6XX_RB_UNKNOWN_8818
, 0);
1110 WRITE(REG_A6XX_RB_UNKNOWN_8819
, 0);
1111 WRITE(REG_A6XX_RB_UNKNOWN_881A
, 0);
1112 WRITE(REG_A6XX_RB_UNKNOWN_881B
, 0);
1113 WRITE(REG_A6XX_RB_UNKNOWN_881C
, 0);
1114 WRITE(REG_A6XX_RB_UNKNOWN_881D
, 0);
1115 WRITE(REG_A6XX_RB_UNKNOWN_881E
, 0);
1116 WRITE(REG_A6XX_RB_UNKNOWN_88F0
, 0);
1118 WRITE(REG_A6XX_VPC_UNKNOWN_9101
, 0xffff00);
1119 WRITE(REG_A6XX_VPC_UNKNOWN_9107
, 0);
1121 WRITE(REG_A6XX_VPC_UNKNOWN_9236
,
1122 A6XX_VPC_UNKNOWN_9236_POINT_COORD_INVERT(0));
1123 WRITE(REG_A6XX_VPC_UNKNOWN_9300
, 0);
1125 WRITE(REG_A6XX_VPC_SO_OVERRIDE
, A6XX_VPC_SO_OVERRIDE_SO_DISABLE
);
1127 WRITE(REG_A6XX_PC_UNKNOWN_9801
, 0);
1128 WRITE(REG_A6XX_PC_UNKNOWN_9806
, 0);
1129 WRITE(REG_A6XX_PC_UNKNOWN_9980
, 0);
1131 WRITE(REG_A6XX_PC_UNKNOWN_9B06
, 0);
1132 WRITE(REG_A6XX_PC_UNKNOWN_9B06
, 0);
1134 WRITE(REG_A6XX_SP_UNKNOWN_A81B
, 0);
1136 WRITE(REG_A6XX_SP_UNKNOWN_B183
, 0);
1138 WRITE(REG_A6XX_GRAS_UNKNOWN_8099
, 0);
1139 WRITE(REG_A6XX_GRAS_UNKNOWN_809B
, 0);
1140 WRITE(REG_A6XX_GRAS_UNKNOWN_80A0
, 2);
1141 WRITE(REG_A6XX_GRAS_UNKNOWN_80AF
, 0);
1142 WRITE(REG_A6XX_VPC_UNKNOWN_9210
, 0);
1143 WRITE(REG_A6XX_VPC_UNKNOWN_9211
, 0);
1144 WRITE(REG_A6XX_VPC_UNKNOWN_9602
, 0);
1145 WRITE(REG_A6XX_PC_UNKNOWN_9981
, 0x3);
1146 WRITE(REG_A6XX_PC_UNKNOWN_9E72
, 0);
1147 WRITE(REG_A6XX_VPC_UNKNOWN_9108
, 0x3);
1148 WRITE(REG_A6XX_SP_TP_UNKNOWN_B304
, 0);
1149 WRITE(REG_A6XX_SP_TP_UNKNOWN_B309
, 0x000000a2);
1150 WRITE(REG_A6XX_RB_UNKNOWN_8804
, 0);
1151 WRITE(REG_A6XX_GRAS_UNKNOWN_80A4
, 0);
1152 WRITE(REG_A6XX_GRAS_UNKNOWN_80A5
, 0);
1153 WRITE(REG_A6XX_GRAS_UNKNOWN_80A6
, 0);
1154 WRITE(REG_A6XX_RB_UNKNOWN_8805
, 0);
1155 WRITE(REG_A6XX_RB_UNKNOWN_8806
, 0);
1156 WRITE(REG_A6XX_RB_UNKNOWN_8878
, 0);
1157 WRITE(REG_A6XX_RB_UNKNOWN_8879
, 0);
1158 WRITE(REG_A6XX_HLSQ_CONTROL_5_REG
, 0xfc);
1160 emit_marker6(ring
, 7);
1162 OUT_PKT4(ring
, REG_A6XX_VFD_MODE_CNTL
, 1);
1163 OUT_RING(ring
, 0x00000000); /* VFD_MODE_CNTL */
1165 WRITE(REG_A6XX_VFD_UNKNOWN_A008
, 0);
1167 OUT_PKT4(ring
, REG_A6XX_PC_MODE_CNTL
, 1);
1168 OUT_RING(ring
, 0x0000001f); /* PC_MODE_CNTL */
1170 /* we don't use this yet.. probably best to disable.. */
1171 OUT_PKT7(ring
, CP_SET_DRAW_STATE
, 3);
1172 OUT_RING(ring
, CP_SET_DRAW_STATE__0_COUNT(0) |
1173 CP_SET_DRAW_STATE__0_DISABLE_ALL_GROUPS
|
1174 CP_SET_DRAW_STATE__0_GROUP_ID(0));
1175 OUT_RING(ring
, CP_SET_DRAW_STATE__1_ADDR_LO(0));
1176 OUT_RING(ring
, CP_SET_DRAW_STATE__2_ADDR_HI(0));
1178 OUT_PKT4(ring
, REG_A6XX_VPC_SO_BUF_CNTL
, 1);
1179 OUT_RING(ring
, 0x00000000); /* VPC_SO_BUF_CNTL */
1181 OUT_PKT4(ring
, REG_A6XX_SP_HS_CTRL_REG0
, 1);
1182 OUT_RING(ring
, 0x00000000);
1184 OUT_PKT4(ring
, REG_A6XX_SP_GS_CTRL_REG0
, 1);
1185 OUT_RING(ring
, 0x00000000);
1187 OUT_PKT4(ring
, REG_A6XX_GRAS_LRZ_CNTL
, 1);
1188 OUT_RING(ring
, 0x00000000);
1190 OUT_PKT4(ring
, REG_A6XX_RB_LRZ_CNTL
, 1);
1191 OUT_RING(ring
, 0x00000000);
1195 fd6_mem_to_mem(struct fd_ringbuffer
*ring
, struct pipe_resource
*dst
,
1196 unsigned dst_off
, struct pipe_resource
*src
, unsigned src_off
,
1197 unsigned sizedwords
)
1199 struct fd_bo
*src_bo
= fd_resource(src
)->bo
;
1200 struct fd_bo
*dst_bo
= fd_resource(dst
)->bo
;
1203 for (i
= 0; i
< sizedwords
; i
++) {
1204 OUT_PKT7(ring
, CP_MEM_TO_MEM
, 5);
1205 OUT_RING(ring
, 0x00000000);
1206 OUT_RELOCW(ring
, dst_bo
, dst_off
, 0, 0);
1207 OUT_RELOC (ring
, src_bo
, src_off
, 0, 0);
1215 fd6_emit_init(struct pipe_context
*pctx
)
1217 struct fd_context
*ctx
= fd_context(pctx
);
1218 ctx
->emit_const
= fd6_emit_const
;
1219 ctx
->emit_const_bo
= fd6_emit_const_bo
;
1220 ctx
->emit_ib
= fd6_emit_ib
;
1221 ctx
->mem_to_mem
= fd6_mem_to_mem
;