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_inlines.h"
32 #include "util/u_format.h"
33 #include "util/bitset.h"
35 #include "freedreno_program.h"
37 #include "fd6_program.h"
39 #include "fd6_texture.h"
40 #include "fd6_format.h"
42 static struct ir3_shader
*
43 create_shader_stateobj(struct pipe_context
*pctx
, const struct pipe_shader_state
*cso
,
46 struct fd_context
*ctx
= fd_context(pctx
);
47 struct ir3_compiler
*compiler
= ctx
->screen
->compiler
;
48 return ir3_shader_create(compiler
, cso
, type
, &ctx
->debug
, pctx
->screen
);
52 fd6_fp_state_create(struct pipe_context
*pctx
,
53 const struct pipe_shader_state
*cso
)
55 return create_shader_stateobj(pctx
, cso
, MESA_SHADER_FRAGMENT
);
59 fd6_fp_state_delete(struct pipe_context
*pctx
, void *hwcso
)
61 struct ir3_shader
*so
= hwcso
;
62 struct fd_context
*ctx
= fd_context(pctx
);
63 ir3_cache_invalidate(fd6_context(ctx
)->shader_cache
, hwcso
);
64 ir3_shader_destroy(so
);
68 fd6_vp_state_create(struct pipe_context
*pctx
,
69 const struct pipe_shader_state
*cso
)
71 return create_shader_stateobj(pctx
, cso
, MESA_SHADER_VERTEX
);
75 fd6_vp_state_delete(struct pipe_context
*pctx
, void *hwcso
)
77 struct ir3_shader
*so
= hwcso
;
78 struct fd_context
*ctx
= fd_context(pctx
);
79 ir3_cache_invalidate(fd6_context(ctx
)->shader_cache
, hwcso
);
80 ir3_shader_destroy(so
);
84 fd6_emit_shader(struct fd_ringbuffer
*ring
, const struct ir3_shader_variant
*so
)
86 const struct ir3_info
*si
= &so
->info
;
87 enum a6xx_state_block sb
= fd6_stage2shadersb(so
->type
);
88 enum a6xx_state_src src
;
92 if (fd_mesa_debug
& FD_DBG_DIRECT
) {
95 bin
= fd_bo_map(so
->bo
);
103 case MESA_SHADER_VERTEX
:
104 opcode
= CP_LOAD_STATE6_GEOM
;
106 case MESA_SHADER_FRAGMENT
:
107 case MESA_SHADER_COMPUTE
:
108 case MESA_SHADER_KERNEL
:
109 opcode
= CP_LOAD_STATE6_FRAG
;
112 unreachable("bad shader type");
115 OUT_PKT7(ring
, opcode
, 3 + sz
);
116 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(0) |
117 CP_LOAD_STATE6_0_STATE_TYPE(ST6_SHADER
) |
118 CP_LOAD_STATE6_0_STATE_SRC(src
) |
119 CP_LOAD_STATE6_0_STATE_BLOCK(sb
) |
120 CP_LOAD_STATE6_0_NUM_UNIT(so
->instrlen
));
122 OUT_RING(ring
, CP_LOAD_STATE6_1_EXT_SRC_ADDR(0));
123 OUT_RING(ring
, CP_LOAD_STATE6_2_EXT_SRC_ADDR_HI(0));
125 OUT_RELOCD(ring
, so
->bo
, 0, 0, 0);
128 /* for how clever coverity is, it is sometimes rather dull, and
129 * doesn't realize that the only case where bin==NULL, sz==0:
131 assume(bin
|| (sz
== 0));
133 for (i
= 0; i
< sz
; i
++) {
134 OUT_RING(ring
, bin
[i
]);
138 /* Add any missing varyings needed for stream-out. Otherwise varyings not
139 * used by fragment shader will be stripped out.
142 link_stream_out(struct ir3_shader_linkage
*l
, const struct ir3_shader_variant
*v
)
144 const struct ir3_stream_output_info
*strmout
= &v
->shader
->stream_output
;
147 * First, any stream-out varyings not already in linkage map (ie. also
148 * consumed by frag shader) need to be added:
150 for (unsigned i
= 0; i
< strmout
->num_outputs
; i
++) {
151 const struct ir3_stream_output
*out
= &strmout
->output
[i
];
152 unsigned k
= out
->register_index
;
154 (1 << (out
->num_components
+ out
->start_component
)) - 1;
155 unsigned idx
, nextloc
= 0;
157 /* psize/pos need to be the last entries in linkage map, and will
158 * get added link_stream_out, so skip over them:
160 if ((v
->outputs
[k
].slot
== VARYING_SLOT_PSIZ
) ||
161 (v
->outputs
[k
].slot
== VARYING_SLOT_POS
))
164 for (idx
= 0; idx
< l
->cnt
; idx
++) {
165 if (l
->var
[idx
].regid
== v
->outputs
[k
].regid
)
167 nextloc
= MAX2(nextloc
, l
->var
[idx
].loc
+ 4);
170 /* add if not already in linkage map: */
172 ir3_link_add(l
, v
->outputs
[k
].regid
, compmask
, nextloc
);
174 /* expand component-mask if needed, ie streaming out all components
175 * but frag shader doesn't consume all components:
177 if (compmask
& ~l
->var
[idx
].compmask
) {
178 l
->var
[idx
].compmask
|= compmask
;
179 l
->max_loc
= MAX2(l
->max_loc
,
180 l
->var
[idx
].loc
+ util_last_bit(l
->var
[idx
].compmask
));
186 setup_stream_out(struct fd6_program_state
*state
, const struct ir3_shader_variant
*v
,
187 struct ir3_shader_linkage
*l
)
189 const struct ir3_stream_output_info
*strmout
= &v
->shader
->stream_output
;
190 struct fd6_streamout_state
*tf
= &state
->tf
;
192 memset(tf
, 0, sizeof(*tf
));
194 tf
->prog_count
= align(l
->max_loc
, 2) / 2;
196 debug_assert(tf
->prog_count
< ARRAY_SIZE(tf
->prog
));
198 for (unsigned i
= 0; i
< strmout
->num_outputs
; i
++) {
199 const struct ir3_stream_output
*out
= &strmout
->output
[i
];
200 unsigned k
= out
->register_index
;
203 tf
->ncomp
[out
->output_buffer
] += out
->num_components
;
205 /* linkage map sorted by order frag shader wants things, so
206 * a bit less ideal here..
208 for (idx
= 0; idx
< l
->cnt
; idx
++)
209 if (l
->var
[idx
].regid
== v
->outputs
[k
].regid
)
212 debug_assert(idx
< l
->cnt
);
214 for (unsigned j
= 0; j
< out
->num_components
; j
++) {
215 unsigned c
= j
+ out
->start_component
;
216 unsigned loc
= l
->var
[idx
].loc
+ c
;
217 unsigned off
= j
+ out
->dst_offset
; /* in dwords */
220 tf
->prog
[loc
/2] |= A6XX_VPC_SO_PROG_B_EN
|
221 A6XX_VPC_SO_PROG_B_BUF(out
->output_buffer
) |
222 A6XX_VPC_SO_PROG_B_OFF(off
* 4);
224 tf
->prog
[loc
/2] |= A6XX_VPC_SO_PROG_A_EN
|
225 A6XX_VPC_SO_PROG_A_BUF(out
->output_buffer
) |
226 A6XX_VPC_SO_PROG_A_OFF(off
* 4);
231 tf
->vpc_so_buf_cntl
= A6XX_VPC_SO_BUF_CNTL_ENABLE
|
232 COND(tf
->ncomp
[0] > 0, A6XX_VPC_SO_BUF_CNTL_BUF0
) |
233 COND(tf
->ncomp
[1] > 0, A6XX_VPC_SO_BUF_CNTL_BUF1
) |
234 COND(tf
->ncomp
[2] > 0, A6XX_VPC_SO_BUF_CNTL_BUF2
) |
235 COND(tf
->ncomp
[3] > 0, A6XX_VPC_SO_BUF_CNTL_BUF3
);
239 const struct ir3_shader_variant
*v
;
240 const struct ir3_info
*i
;
241 /* const sizes are in units of vec4, aligned to 4*vec4 */
243 /* instr sizes are in units of 16 instructions */
257 setup_stages(struct fd6_program_state
*state
, struct stage
*s
, bool binning_pass
)
262 static const struct ir3_shader_variant dummy_fs
= {0};
271 s
[HS
].v
= s
[DS
].v
= s
[GS
].v
= NULL
; /* for now */
273 for (i
= 0; i
< MAX_STAGES
; i
++) {
275 s
[i
].i
= &s
[i
].v
->info
;
276 s
[i
].constlen
= align(s
[i
].v
->constlen
, 4);
277 /* instrlen is already in units of 16 instr.. although
278 * probably we should ditch that and not make the compiler
279 * care about instruction group size of a3xx vs a5xx
281 s
[i
].instrlen
= s
[i
].v
->instrlen
;
289 /* since we share the constant state w/ VS we need to make sure
290 * constlen is sufficiently large for full VS, even if the binning
291 * pass shader doesn't use them all
294 s
[VS
].constlen
= MAX2(s
[VS
].constlen
, align(state
->bs
->constlen
, 4));
296 /* It should be impossible for VS to have smaller constlen than BS
297 * since BS is just a subset of VS.
299 debug_assert(s
[VS
].constlen
>= state
->bs
->constlen
);
303 static inline uint32_t
304 next_regid(uint32_t reg
, uint32_t increment
)
306 if (reg
== regid(63,0))
309 return reg
+ increment
;
312 #define VALIDREG(r) ((r) != regid(63,0))
313 #define CONDREG(r, val) COND(VALIDREG(r), (val))
316 setup_stateobj(struct fd_ringbuffer
*ring
, struct fd6_program_state
*state
,
317 const struct ir3_shader_key
*key
, bool binning_pass
)
319 struct stage s
[MAX_STAGES
];
320 uint32_t pos_regid
, psize_regid
, color_regid
[8], posz_regid
;
321 uint32_t face_regid
, coord_regid
, zwcoord_regid
, samp_id_regid
;
322 uint32_t smask_in_regid
, smask_regid
;
323 uint32_t vertex_regid
, instance_regid
;
324 uint32_t ij_pix_regid
, ij_samp_regid
, ij_cent_regid
, ij_size_regid
;
325 enum a3xx_threadsize fssz
;
326 uint8_t psize_loc
= ~0;
329 setup_stages(state
, s
, binning_pass
);
331 bool sample_shading
= s
[FS
].v
->per_samp
| key
->sample_shading
;
335 pos_regid
= ir3_find_output_regid(s
[VS
].v
, VARYING_SLOT_POS
);
336 psize_regid
= ir3_find_output_regid(s
[VS
].v
, VARYING_SLOT_PSIZ
);
337 vertex_regid
= ir3_find_sysval_regid(s
[VS
].v
, SYSTEM_VALUE_VERTEX_ID
);
338 instance_regid
= ir3_find_sysval_regid(s
[VS
].v
, SYSTEM_VALUE_INSTANCE_ID
);
340 if (s
[FS
].v
->color0_mrt
) {
341 color_regid
[0] = color_regid
[1] = color_regid
[2] = color_regid
[3] =
342 color_regid
[4] = color_regid
[5] = color_regid
[6] = color_regid
[7] =
343 ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_COLOR
);
345 color_regid
[0] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA0
);
346 color_regid
[1] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA1
);
347 color_regid
[2] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA2
);
348 color_regid
[3] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA3
);
349 color_regid
[4] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA4
);
350 color_regid
[5] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA5
);
351 color_regid
[6] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA6
);
352 color_regid
[7] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA7
);
355 samp_id_regid
= ir3_find_sysval_regid(s
[FS
].v
, SYSTEM_VALUE_SAMPLE_ID
);
356 smask_in_regid
= ir3_find_sysval_regid(s
[FS
].v
, SYSTEM_VALUE_SAMPLE_MASK_IN
);
357 face_regid
= ir3_find_sysval_regid(s
[FS
].v
, SYSTEM_VALUE_FRONT_FACE
);
358 coord_regid
= ir3_find_sysval_regid(s
[FS
].v
, SYSTEM_VALUE_FRAG_COORD
);
359 zwcoord_regid
= next_regid(coord_regid
, 2);
360 ij_pix_regid
= ir3_find_sysval_regid(s
[FS
].v
, SYSTEM_VALUE_BARYCENTRIC_PIXEL
);
361 ij_samp_regid
= ir3_find_sysval_regid(s
[FS
].v
, SYSTEM_VALUE_BARYCENTRIC_SAMPLE
);
362 ij_cent_regid
= ir3_find_sysval_regid(s
[FS
].v
, SYSTEM_VALUE_BARYCENTRIC_CENTROID
);
363 ij_size_regid
= ir3_find_sysval_regid(s
[FS
].v
, SYSTEM_VALUE_BARYCENTRIC_SIZE
);
364 posz_regid
= ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DEPTH
);
365 smask_regid
= ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_SAMPLE_MASK
);
367 /* we can't write gl_SampleMask for !msaa.. if b0 is zero then we
368 * end up masking the single sample!!
371 smask_regid
= regid(63, 0);
373 /* we could probably divide this up into things that need to be
374 * emitted if frag-prog is dirty vs if vert-prog is dirty..
377 OUT_PKT4(ring
, REG_A6XX_SP_VS_CONFIG
, 2);
378 OUT_RING(ring
, COND(s
[VS
].v
, A6XX_SP_VS_CONFIG_ENABLED
) |
379 A6XX_SP_VS_CONFIG_NIBO(s
[VS
].v
->image_mapping
.num_ibo
) |
380 A6XX_SP_VS_CONFIG_NTEX(s
[VS
].v
->num_samp
) |
381 A6XX_SP_VS_CONFIG_NSAMP(s
[VS
].v
->num_samp
)); /* SP_VS_CONFIG */
382 OUT_RING(ring
, s
[VS
].instrlen
); /* SP_VS_INSTRLEN */
384 OUT_PKT4(ring
, REG_A6XX_SP_HS_UNKNOWN_A831
, 1);
387 OUT_PKT4(ring
, REG_A6XX_SP_HS_CONFIG
, 2);
388 OUT_RING(ring
, COND(s
[HS
].v
, A6XX_SP_HS_CONFIG_ENABLED
)); /* SP_HS_CONFIG */
389 OUT_RING(ring
, s
[HS
].instrlen
); /* SP_HS_INSTRLEN */
391 OUT_PKT4(ring
, REG_A6XX_SP_DS_CONFIG
, 2);
392 OUT_RING(ring
, COND(s
[DS
].v
, A6XX_SP_DS_CONFIG_ENABLED
)); /* SP_DS_CONFIG */
393 OUT_RING(ring
, s
[DS
].instrlen
); /* SP_DS_INSTRLEN */
395 OUT_PKT4(ring
, REG_A6XX_SP_GS_UNKNOWN_A871
, 1);
398 OUT_PKT4(ring
, REG_A6XX_SP_GS_CONFIG
, 2);
399 OUT_RING(ring
, COND(s
[GS
].v
, A6XX_SP_GS_CONFIG_ENABLED
)); /* SP_GS_CONFIG */
400 OUT_RING(ring
, s
[GS
].instrlen
); /* SP_GS_INSTRLEN */
402 OUT_PKT4(ring
, REG_A6XX_SP_UNKNOWN_A99E
, 1);
403 OUT_RING(ring
, 0x7fc0);
405 OUT_PKT4(ring
, REG_A6XX_SP_UNKNOWN_A9A8
, 1);
408 OUT_PKT4(ring
, REG_A6XX_SP_UNKNOWN_AB00
, 1);
411 OUT_PKT4(ring
, REG_A6XX_SP_FS_CONFIG
, 2);
412 OUT_RING(ring
, COND(s
[FS
].v
, A6XX_SP_FS_CONFIG_ENABLED
) |
413 A6XX_SP_FS_CONFIG_NIBO(s
[FS
].v
->image_mapping
.num_ibo
) |
414 A6XX_SP_FS_CONFIG_NTEX(s
[FS
].v
->num_samp
) |
415 A6XX_SP_FS_CONFIG_NSAMP(s
[FS
].v
->num_samp
)); /* SP_FS_CONFIG */
416 OUT_RING(ring
, s
[FS
].instrlen
); /* SP_FS_INSTRLEN */
418 OUT_PKT4(ring
, REG_A6XX_SP_FS_OUTPUT_CNTL0
, 1);
419 OUT_RING(ring
, A6XX_SP_FS_OUTPUT_CNTL0_DEPTH_REGID(posz_regid
) |
420 A6XX_SP_FS_OUTPUT_CNTL0_SAMPMASK_REGID(smask_regid
) |
423 OUT_PKT4(ring
, REG_A6XX_HLSQ_VS_CNTL
, 4);
424 OUT_RING(ring
, A6XX_HLSQ_VS_CNTL_CONSTLEN(s
[VS
].constlen
) |
425 A6XX_HLSQ_VS_CNTL_ENABLED
);
426 OUT_RING(ring
, A6XX_HLSQ_HS_CNTL_CONSTLEN(s
[HS
].constlen
)); /* HLSQ_HS_CONSTLEN */
427 OUT_RING(ring
, A6XX_HLSQ_DS_CNTL_CONSTLEN(s
[DS
].constlen
)); /* HLSQ_DS_CONSTLEN */
428 OUT_RING(ring
, A6XX_HLSQ_GS_CNTL_CONSTLEN(s
[GS
].constlen
)); /* HLSQ_GS_CONSTLEN */
430 OUT_PKT4(ring
, REG_A6XX_HLSQ_FS_CNTL
, 1);
431 OUT_RING(ring
, A6XX_HLSQ_FS_CNTL_CONSTLEN(s
[FS
].constlen
) |
432 A6XX_HLSQ_FS_CNTL_ENABLED
);
434 OUT_PKT4(ring
, REG_A6XX_SP_VS_CTRL_REG0
, 1);
435 OUT_RING(ring
, A6XX_SP_VS_CTRL_REG0_THREADSIZE(fssz
) |
436 A6XX_SP_VS_CTRL_REG0_FULLREGFOOTPRINT(s
[VS
].i
->max_reg
+ 1) |
437 A6XX_SP_VS_CTRL_REG0_MERGEDREGS
|
438 A6XX_SP_VS_CTRL_REG0_BRANCHSTACK(s
[VS
].v
->branchstack
) |
439 COND(s
[VS
].v
->need_pixlod
, A6XX_SP_VS_CTRL_REG0_PIXLODENABLE
));
441 struct ir3_shader_linkage l
= {0};
442 ir3_link_shaders(&l
, s
[VS
].v
, s
[FS
].v
);
444 if ((s
[VS
].v
->shader
->stream_output
.num_outputs
> 0) && !binning_pass
)
445 link_stream_out(&l
, s
[VS
].v
);
447 BITSET_DECLARE(varbs
, 128) = {0};
448 uint32_t *varmask
= (uint32_t *)varbs
;
450 for (i
= 0; i
< l
.cnt
; i
++)
451 for (j
= 0; j
< util_last_bit(l
.var
[i
].compmask
); j
++)
452 BITSET_SET(varbs
, l
.var
[i
].loc
+ j
);
454 OUT_PKT4(ring
, REG_A6XX_VPC_VAR_DISABLE(0), 4);
455 OUT_RING(ring
, ~varmask
[0]); /* VPC_VAR[0].DISABLE */
456 OUT_RING(ring
, ~varmask
[1]); /* VPC_VAR[1].DISABLE */
457 OUT_RING(ring
, ~varmask
[2]); /* VPC_VAR[2].DISABLE */
458 OUT_RING(ring
, ~varmask
[3]); /* VPC_VAR[3].DISABLE */
460 /* a6xx appends pos/psize to end of the linkage map: */
461 if (VALIDREG(pos_regid
))
462 ir3_link_add(&l
, pos_regid
, 0xf, l
.max_loc
);
464 if (VALIDREG(psize_regid
)) {
465 psize_loc
= l
.max_loc
;
466 ir3_link_add(&l
, psize_regid
, 0x1, l
.max_loc
);
469 if ((s
[VS
].v
->shader
->stream_output
.num_outputs
> 0) && !binning_pass
) {
470 setup_stream_out(state
, s
[VS
].v
, &l
);
473 for (i
= 0, j
= 0; (i
< 16) && (j
< l
.cnt
); i
++) {
476 OUT_PKT4(ring
, REG_A6XX_SP_VS_OUT_REG(i
), 1);
478 reg
|= A6XX_SP_VS_OUT_REG_A_REGID(l
.var
[j
].regid
);
479 reg
|= A6XX_SP_VS_OUT_REG_A_COMPMASK(l
.var
[j
].compmask
);
482 reg
|= A6XX_SP_VS_OUT_REG_B_REGID(l
.var
[j
].regid
);
483 reg
|= A6XX_SP_VS_OUT_REG_B_COMPMASK(l
.var
[j
].compmask
);
489 for (i
= 0, j
= 0; (i
< 8) && (j
< l
.cnt
); i
++) {
492 OUT_PKT4(ring
, REG_A6XX_SP_VS_VPC_DST_REG(i
), 1);
494 reg
|= A6XX_SP_VS_VPC_DST_REG_OUTLOC0(l
.var
[j
++].loc
);
495 reg
|= A6XX_SP_VS_VPC_DST_REG_OUTLOC1(l
.var
[j
++].loc
);
496 reg
|= A6XX_SP_VS_VPC_DST_REG_OUTLOC2(l
.var
[j
++].loc
);
497 reg
|= A6XX_SP_VS_VPC_DST_REG_OUTLOC3(l
.var
[j
++].loc
);
502 OUT_PKT4(ring
, REG_A6XX_SP_VS_OBJ_START_LO
, 2);
503 OUT_RELOC(ring
, s
[VS
].v
->bo
, 0, 0, 0); /* SP_VS_OBJ_START_LO/HI */
506 fd6_emit_shader(ring
, s
[VS
].v
);
508 // TODO depending on other bits in this reg (if any) set somewhere else?
510 OUT_PKT4(ring
, REG_A6XX_PC_PRIM_VTX_CNTL
, 1);
511 OUT_RING(ring
, COND(s
[VS
].v
->writes_psize
, A6XX_PC_PRIM_VTX_CNTL_PSIZE
));
514 OUT_PKT4(ring
, REG_A6XX_SP_PRIMITIVE_CNTL
, 1);
515 OUT_RING(ring
, A6XX_SP_PRIMITIVE_CNTL_VSOUT(l
.cnt
));
517 bool enable_varyings
= s
[FS
].v
->total_in
> 0;
519 OUT_PKT4(ring
, REG_A6XX_VPC_CNTL_0
, 1);
520 OUT_RING(ring
, A6XX_VPC_CNTL_0_NUMNONPOSVAR(s
[FS
].v
->total_in
) |
521 COND(enable_varyings
, A6XX_VPC_CNTL_0_VARYING
) |
524 OUT_PKT4(ring
, REG_A6XX_PC_PRIMITIVE_CNTL_1
, 1);
525 OUT_RING(ring
, A6XX_PC_PRIMITIVE_CNTL_1_STRIDE_IN_VPC(l
.max_loc
) |
526 CONDREG(psize_regid
, 0x100));
529 OUT_PKT4(ring
, REG_A6XX_SP_FS_OBJ_START_LO
, 2);
530 OUT_RING(ring
, 0x00000000); /* SP_FS_OBJ_START_LO */
531 OUT_RING(ring
, 0x00000000); /* SP_FS_OBJ_START_HI */
533 OUT_PKT4(ring
, REG_A6XX_SP_FS_OBJ_START_LO
, 2);
534 OUT_RELOC(ring
, s
[FS
].v
->bo
, 0, 0, 0); /* SP_FS_OBJ_START_LO/HI */
537 OUT_PKT4(ring
, REG_A6XX_HLSQ_CONTROL_1_REG
, 5);
538 OUT_RING(ring
, 0x7); /* XXX */
539 OUT_RING(ring
, A6XX_HLSQ_CONTROL_2_REG_FACEREGID(face_regid
) |
540 A6XX_HLSQ_CONTROL_2_REG_SAMPLEID(samp_id_regid
) |
541 A6XX_HLSQ_CONTROL_2_REG_SAMPLEMASK(smask_in_regid
) |
542 A6XX_HLSQ_CONTROL_2_REG_SIZE(ij_size_regid
));
543 OUT_RING(ring
, A6XX_HLSQ_CONTROL_3_REG_BARY_IJ_PIXEL(ij_pix_regid
) |
544 A6XX_HLSQ_CONTROL_3_REG_BARY_IJ_CENTROID(ij_cent_regid
) |
545 0xfc00fc00); /* XXX */
546 OUT_RING(ring
, A6XX_HLSQ_CONTROL_4_REG_XYCOORDREGID(coord_regid
) |
547 A6XX_HLSQ_CONTROL_4_REG_ZWCOORDREGID(zwcoord_regid
) |
548 A6XX_HLSQ_CONTROL_4_REG_BARY_IJ_PIXEL_PERSAMP(ij_samp_regid
) |
549 0x0000fc00); /* XXX */
550 OUT_RING(ring
, 0xfc); /* XXX */
552 OUT_PKT4(ring
, REG_A6XX_HLSQ_UNKNOWN_B980
, 1);
553 OUT_RING(ring
, enable_varyings
? 3 : 1);
555 OUT_PKT4(ring
, REG_A6XX_SP_FS_CTRL_REG0
, 1);
556 OUT_RING(ring
, A6XX_SP_FS_CTRL_REG0_THREADSIZE(fssz
) |
557 COND(enable_varyings
, A6XX_SP_FS_CTRL_REG0_VARYING
) |
558 COND(s
[FS
].v
->frag_coord
, A6XX_SP_FS_CTRL_REG0_VARYING
) |
560 A6XX_SP_FS_CTRL_REG0_FULLREGFOOTPRINT(s
[FS
].i
->max_reg
+ 1) |
561 A6XX_SP_FS_CTRL_REG0_MERGEDREGS
|
562 A6XX_SP_FS_CTRL_REG0_BRANCHSTACK(s
[FS
].v
->branchstack
) |
563 COND(s
[FS
].v
->need_pixlod
, A6XX_SP_FS_CTRL_REG0_PIXLODENABLE
));
565 OUT_PKT4(ring
, REG_A6XX_SP_UNKNOWN_A982
, 1);
566 OUT_RING(ring
, 0); /* XXX */
568 OUT_PKT4(ring
, REG_A6XX_HLSQ_UPDATE_CNTL
, 1);
569 OUT_RING(ring
, 0xff); /* XXX */
571 OUT_PKT4(ring
, REG_A6XX_VPC_GS_SIV_CNTL
, 1);
572 OUT_RING(ring
, 0x0000ffff); /* XXX */
575 OUT_PKT4(ring
, REG_A6XX_SP_SP_CNTL
, 1);
576 OUT_RING(ring
, 0x00000010); /* XXX */
579 OUT_PKT4(ring
, REG_A6XX_GRAS_CNTL
, 1);
581 CONDREG(ij_pix_regid
, A6XX_GRAS_CNTL_VARYING
) |
582 CONDREG(ij_cent_regid
, A6XX_GRAS_CNTL_CENTROID
) |
583 CONDREG(ij_samp_regid
, A6XX_GRAS_CNTL_PERSAMP_VARYING
) |
584 COND(VALIDREG(ij_size_regid
) && !sample_shading
, A6XX_GRAS_CNTL_SIZE
) |
585 COND(VALIDREG(ij_size_regid
) && sample_shading
, A6XX_GRAS_CNTL_SIZE_PERSAMP
) |
586 COND(s
[FS
].v
->frag_coord
,
587 A6XX_GRAS_CNTL_SIZE
|
588 A6XX_GRAS_CNTL_XCOORD
|
589 A6XX_GRAS_CNTL_YCOORD
|
590 A6XX_GRAS_CNTL_ZCOORD
|
591 A6XX_GRAS_CNTL_WCOORD
) |
592 COND(s
[FS
].v
->frag_face
, A6XX_GRAS_CNTL_SIZE
));
594 OUT_PKT4(ring
, REG_A6XX_RB_RENDER_CONTROL0
, 2);
596 CONDREG(ij_pix_regid
, A6XX_RB_RENDER_CONTROL0_VARYING
) |
597 CONDREG(ij_cent_regid
, A6XX_RB_RENDER_CONTROL0_CENTROID
) |
598 CONDREG(ij_samp_regid
, A6XX_RB_RENDER_CONTROL0_PERSAMP_VARYING
) |
599 COND(enable_varyings
, A6XX_RB_RENDER_CONTROL0_UNK10
) |
600 COND(VALIDREG(ij_size_regid
) && !sample_shading
, A6XX_RB_RENDER_CONTROL0_SIZE
) |
601 COND(VALIDREG(ij_size_regid
) && sample_shading
, A6XX_RB_RENDER_CONTROL0_SIZE_PERSAMP
) |
602 COND(s
[FS
].v
->frag_coord
,
603 A6XX_RB_RENDER_CONTROL0_SIZE
|
604 A6XX_RB_RENDER_CONTROL0_XCOORD
|
605 A6XX_RB_RENDER_CONTROL0_YCOORD
|
606 A6XX_RB_RENDER_CONTROL0_ZCOORD
|
607 A6XX_RB_RENDER_CONTROL0_WCOORD
) |
608 COND(s
[FS
].v
->frag_face
, A6XX_RB_RENDER_CONTROL0_SIZE
));
611 CONDREG(smask_in_regid
, A6XX_RB_RENDER_CONTROL1_SAMPLEMASK
) |
612 CONDREG(samp_id_regid
, A6XX_RB_RENDER_CONTROL1_SAMPLEID
) |
613 CONDREG(ij_size_regid
, A6XX_RB_RENDER_CONTROL1_SIZE
) |
614 COND(s
[FS
].v
->frag_face
, A6XX_RB_RENDER_CONTROL1_FACENESS
));
616 OUT_PKT4(ring
, REG_A6XX_RB_SAMPLE_CNTL
, 1);
617 OUT_RING(ring
, COND(sample_shading
, A6XX_RB_SAMPLE_CNTL_PER_SAMP_MODE
));
619 OUT_PKT4(ring
, REG_A6XX_GRAS_UNKNOWN_8101
, 1);
620 OUT_RING(ring
, COND(sample_shading
, 0x6)); // XXX
622 OUT_PKT4(ring
, REG_A6XX_GRAS_SAMPLE_CNTL
, 1);
623 OUT_RING(ring
, COND(sample_shading
, A6XX_GRAS_SAMPLE_CNTL_PER_SAMP_MODE
));
625 OUT_PKT4(ring
, REG_A6XX_SP_FS_OUTPUT_REG(0), 8);
626 for (i
= 0; i
< 8; i
++) {
627 // TODO we could have a mix of half and full precision outputs,
628 // we really need to figure out half-precision from IR3_REG_HALF
629 OUT_RING(ring
, A6XX_SP_FS_OUTPUT_REG_REGID(color_regid
[i
]) |
631 A6XX_SP_FS_OUTPUT_REG_HALF_PRECISION
));
634 OUT_PKT4(ring
, REG_A6XX_VPC_PACK
, 1);
635 OUT_RING(ring
, A6XX_VPC_PACK_NUMNONPOSVAR(s
[FS
].v
->total_in
) |
636 A6XX_VPC_PACK_PSIZELOC(psize_loc
) |
637 A6XX_VPC_PACK_STRIDE_IN_VPC(l
.max_loc
));
640 /* figure out VARYING_INTERP / VARYING_PS_REPL register values: */
641 for (j
= -1; (j
= ir3_next_varying(s
[FS
].v
, j
)) < (int)s
[FS
].v
->inputs_count
; ) {
642 /* NOTE: varyings are packed, so if compmask is 0xb
643 * then first, third, and fourth component occupy
644 * three consecutive varying slots:
646 unsigned compmask
= s
[FS
].v
->inputs
[j
].compmask
;
648 uint32_t inloc
= s
[FS
].v
->inputs
[j
].inloc
;
650 if (s
[FS
].v
->inputs
[j
].interpolate
== INTERP_MODE_FLAT
) {
651 uint32_t loc
= inloc
;
653 for (i
= 0; i
< 4; i
++) {
654 if (compmask
& (1 << i
)) {
655 state
->vinterp
[loc
/ 16] |= 1 << ((loc
% 16) * 2);
665 fd6_emit_shader(ring
, s
[FS
].v
);
667 OUT_PKT4(ring
, REG_A6XX_VFD_CONTROL_1
, 6);
668 OUT_RING(ring
, A6XX_VFD_CONTROL_1_REGID4VTX(vertex_regid
) |
669 A6XX_VFD_CONTROL_1_REGID4INST(instance_regid
) |
671 OUT_RING(ring
, 0x0000fcfc); /* VFD_CONTROL_2 */
672 OUT_RING(ring
, 0xfcfcfcfc); /* VFD_CONTROL_3 */
673 OUT_RING(ring
, 0x000000fc); /* VFD_CONTROL_4 */
674 OUT_RING(ring
, 0x0000fcfc); /* VFD_CONTROL_5 */
675 OUT_RING(ring
, 0x00000000); /* VFD_CONTROL_6 */
677 bool fragz
= s
[FS
].v
->no_earlyz
| s
[FS
].v
->writes_pos
;
679 OUT_PKT4(ring
, REG_A6XX_RB_DEPTH_PLANE_CNTL
, 1);
680 OUT_RING(ring
, COND(fragz
, A6XX_RB_DEPTH_PLANE_CNTL_FRAG_WRITES_Z
));
682 OUT_PKT4(ring
, REG_A6XX_GRAS_SU_DEPTH_PLANE_CNTL
, 1);
683 OUT_RING(ring
, COND(fragz
, A6XX_GRAS_SU_DEPTH_PLANE_CNTL_FRAG_WRITES_Z
));
686 /* emits the program state which is not part of the stateobj because of
687 * dependency on other gl state (rasterflat or sprite-coord-replacement)
690 fd6_program_emit(struct fd_ringbuffer
*ring
, struct fd6_emit
*emit
)
692 const struct fd6_program_state
*state
= fd6_emit_get_prog(emit
);
694 if (!unlikely(emit
->rasterflat
|| emit
->sprite_coord_enable
)) {
696 OUT_PKT4(ring
, REG_A6XX_VPC_VARYING_INTERP_MODE(0), 8);
697 for (int i
= 0; i
< 8; i
++)
698 OUT_RING(ring
, state
->vinterp
[i
]); /* VPC_VARYING_INTERP[i].MODE */
700 OUT_PKT4(ring
, REG_A6XX_VPC_VARYING_PS_REPL_MODE(0), 8);
701 for (int i
= 0; i
< 8; i
++)
702 OUT_RING(ring
, 0x00000000); /* VPC_VARYING_PS_REPL[i] */
705 struct ir3_shader_variant
*fs
= state
->fs
;
706 uint32_t vinterp
[8], vpsrepl
[8];
708 memset(vinterp
, 0, sizeof(vinterp
));
709 memset(vpsrepl
, 0, sizeof(vpsrepl
));
711 for (int j
= -1; (j
= ir3_next_varying(fs
, j
)) < (int)fs
->inputs_count
; ) {
713 /* NOTE: varyings are packed, so if compmask is 0xb
714 * then first, third, and fourth component occupy
715 * three consecutive varying slots:
717 unsigned compmask
= fs
->inputs
[j
].compmask
;
719 uint32_t inloc
= fs
->inputs
[j
].inloc
;
721 if ((fs
->inputs
[j
].interpolate
== INTERP_MODE_FLAT
) ||
722 (fs
->inputs
[j
].rasterflat
&& emit
->rasterflat
)) {
723 uint32_t loc
= inloc
;
725 for (int i
= 0; i
< 4; i
++) {
726 if (compmask
& (1 << i
)) {
727 vinterp
[loc
/ 16] |= 1 << ((loc
% 16) * 2);
733 gl_varying_slot slot
= fs
->inputs
[j
].slot
;
735 /* since we don't enable PIPE_CAP_TGSI_TEXCOORD: */
736 if (slot
>= VARYING_SLOT_VAR0
) {
737 unsigned texmask
= 1 << (slot
- VARYING_SLOT_VAR0
);
738 /* Replace the .xy coordinates with S/T from the point sprite. Set
739 * interpolation bits for .zw such that they become .01
741 if (emit
->sprite_coord_enable
& texmask
) {
742 /* mask is two 2-bit fields, where:
745 * '11' -> 1 - T (flip mode)
747 unsigned mask
= emit
->sprite_coord_mode
? 0b1101 : 0b1001;
748 uint32_t loc
= inloc
;
749 if (compmask
& 0x1) {
750 vpsrepl
[loc
/ 16] |= ((mask
>> 0) & 0x3) << ((loc
% 16) * 2);
753 if (compmask
& 0x2) {
754 vpsrepl
[loc
/ 16] |= ((mask
>> 2) & 0x3) << ((loc
% 16) * 2);
757 if (compmask
& 0x4) {
759 vinterp
[loc
/ 16] |= 0b10 << ((loc
% 16) * 2);
762 if (compmask
& 0x8) {
764 vinterp
[loc
/ 16] |= 0b11 << ((loc
% 16) * 2);
771 OUT_PKT4(ring
, REG_A6XX_VPC_VARYING_INTERP_MODE(0), 8);
772 for (int i
= 0; i
< 8; i
++)
773 OUT_RING(ring
, vinterp
[i
]); /* VPC_VARYING_INTERP[i].MODE */
775 OUT_PKT4(ring
, REG_A6XX_VPC_VARYING_PS_REPL_MODE(0), 8);
776 for (int i
= 0; i
< 8; i
++)
777 OUT_RING(ring
, vpsrepl
[i
]); /* VPC_VARYING_PS_REPL[i] */
781 static struct ir3_program_state
*
782 fd6_program_create(void *data
, struct ir3_shader_variant
*bs
,
783 struct ir3_shader_variant
*vs
,
784 struct ir3_shader_variant
*fs
,
785 const struct ir3_shader_key
*key
)
787 struct fd_context
*ctx
= data
;
788 struct fd6_program_state
*state
= CALLOC_STRUCT(fd6_program_state
);
793 state
->binning_stateobj
= fd_ringbuffer_new_object(ctx
->pipe
, 0x1000);
794 state
->stateobj
= fd_ringbuffer_new_object(ctx
->pipe
, 0x1000);
796 setup_stateobj(state
->binning_stateobj
, state
, key
, true);
797 setup_stateobj(state
->stateobj
, state
, key
, false);
803 fd6_program_destroy(void *data
, struct ir3_program_state
*state
)
805 struct fd6_program_state
*so
= fd6_program_state(state
);
806 fd_ringbuffer_del(so
->stateobj
);
807 fd_ringbuffer_del(so
->binning_stateobj
);
811 static const struct ir3_cache_funcs cache_funcs
= {
812 .create_state
= fd6_program_create
,
813 .destroy_state
= fd6_program_destroy
,
817 fd6_prog_init(struct pipe_context
*pctx
)
819 struct fd_context
*ctx
= fd_context(pctx
);
821 fd6_context(ctx
)->shader_cache
= ir3_cache_create(&cache_funcs
, ctx
);
823 pctx
->create_fs_state
= fd6_fp_state_create
;
824 pctx
->delete_fs_state
= fd6_fp_state_delete
;
826 pctx
->create_vs_state
= fd6_vp_state_create
;
827 pctx
->delete_vs_state
= fd6_vp_state_delete
;