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
);
52 fd6_fp_state_create(struct pipe_context
*pctx
,
53 const struct pipe_shader_state
*cso
)
55 return create_shader_stateobj(pctx
, cso
, 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
, 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
);
104 opcode
= CP_LOAD_STATE6_GEOM
;
106 case SHADER_FRAGMENT
:
108 opcode
= CP_LOAD_STATE6_FRAG
;
111 unreachable("bad shader type");
114 OUT_PKT7(ring
, opcode
, 3 + sz
);
115 OUT_RING(ring
, CP_LOAD_STATE6_0_DST_OFF(0) |
116 CP_LOAD_STATE6_0_STATE_TYPE(ST6_SHADER
) |
117 CP_LOAD_STATE6_0_STATE_SRC(src
) |
118 CP_LOAD_STATE6_0_STATE_BLOCK(sb
) |
119 CP_LOAD_STATE6_0_NUM_UNIT(so
->instrlen
));
121 OUT_RING(ring
, CP_LOAD_STATE6_1_EXT_SRC_ADDR(0));
122 OUT_RING(ring
, CP_LOAD_STATE6_2_EXT_SRC_ADDR_HI(0));
124 OUT_RELOC(ring
, so
->bo
, 0, 0, 0);
127 /* for how clever coverity is, it is sometimes rather dull, and
128 * doesn't realize that the only case where bin==NULL, sz==0:
130 assume(bin
|| (sz
== 0));
132 for (i
= 0; i
< sz
; i
++) {
133 OUT_RING(ring
, bin
[i
]);
137 /* Add any missing varyings needed for stream-out. Otherwise varyings not
138 * used by fragment shader will be stripped out.
141 link_stream_out(struct ir3_shader_linkage
*l
, const struct ir3_shader_variant
*v
)
143 const struct pipe_stream_output_info
*strmout
= &v
->shader
->stream_output
;
146 * First, any stream-out varyings not already in linkage map (ie. also
147 * consumed by frag shader) need to be added:
149 for (unsigned i
= 0; i
< strmout
->num_outputs
; i
++) {
150 const struct pipe_stream_output
*out
= &strmout
->output
[i
];
151 unsigned k
= out
->register_index
;
153 (1 << (out
->num_components
+ out
->start_component
)) - 1;
154 unsigned idx
, nextloc
= 0;
156 /* psize/pos need to be the last entries in linkage map, and will
157 * get added link_stream_out, so skip over them:
159 if ((v
->outputs
[k
].slot
== VARYING_SLOT_PSIZ
) ||
160 (v
->outputs
[k
].slot
== VARYING_SLOT_POS
))
163 for (idx
= 0; idx
< l
->cnt
; idx
++) {
164 if (l
->var
[idx
].regid
== v
->outputs
[k
].regid
)
166 nextloc
= MAX2(nextloc
, l
->var
[idx
].loc
+ 4);
169 /* add if not already in linkage map: */
171 ir3_link_add(l
, v
->outputs
[k
].regid
, compmask
, nextloc
);
173 /* expand component-mask if needed, ie streaming out all components
174 * but frag shader doesn't consume all components:
176 if (compmask
& ~l
->var
[idx
].compmask
) {
177 l
->var
[idx
].compmask
|= compmask
;
178 l
->max_loc
= MAX2(l
->max_loc
,
179 l
->var
[idx
].loc
+ util_last_bit(l
->var
[idx
].compmask
));
185 setup_stream_out(struct fd6_program_state
*state
, const struct ir3_shader_variant
*v
,
186 struct ir3_shader_linkage
*l
)
188 const struct pipe_stream_output_info
*strmout
= &v
->shader
->stream_output
;
189 struct fd6_streamout_state
*tf
= &state
->tf
;
191 memset(tf
, 0, sizeof(*tf
));
193 tf
->prog_count
= align(l
->max_loc
, 2) / 2;
195 debug_assert(tf
->prog_count
< ARRAY_SIZE(tf
->prog
));
197 for (unsigned i
= 0; i
< strmout
->num_outputs
; i
++) {
198 const struct pipe_stream_output
*out
= &strmout
->output
[i
];
199 unsigned k
= out
->register_index
;
202 tf
->ncomp
[out
->output_buffer
] += out
->num_components
;
204 /* linkage map sorted by order frag shader wants things, so
205 * a bit less ideal here..
207 for (idx
= 0; idx
< l
->cnt
; idx
++)
208 if (l
->var
[idx
].regid
== v
->outputs
[k
].regid
)
211 debug_assert(idx
< l
->cnt
);
213 for (unsigned j
= 0; j
< out
->num_components
; j
++) {
214 unsigned c
= j
+ out
->start_component
;
215 unsigned loc
= l
->var
[idx
].loc
+ c
;
216 unsigned off
= j
+ out
->dst_offset
; /* in dwords */
219 tf
->prog
[loc
/2] |= A6XX_VPC_SO_PROG_B_EN
|
220 A6XX_VPC_SO_PROG_B_BUF(out
->output_buffer
) |
221 A6XX_VPC_SO_PROG_B_OFF(off
* 4);
223 tf
->prog
[loc
/2] |= A6XX_VPC_SO_PROG_A_EN
|
224 A6XX_VPC_SO_PROG_A_BUF(out
->output_buffer
) |
225 A6XX_VPC_SO_PROG_A_OFF(off
* 4);
230 tf
->vpc_so_buf_cntl
= A6XX_VPC_SO_BUF_CNTL_ENABLE
|
231 COND(tf
->ncomp
[0] > 0, A6XX_VPC_SO_BUF_CNTL_BUF0
) |
232 COND(tf
->ncomp
[1] > 0, A6XX_VPC_SO_BUF_CNTL_BUF1
) |
233 COND(tf
->ncomp
[2] > 0, A6XX_VPC_SO_BUF_CNTL_BUF2
) |
234 COND(tf
->ncomp
[3] > 0, A6XX_VPC_SO_BUF_CNTL_BUF3
);
238 const struct ir3_shader_variant
*v
;
239 const struct ir3_info
*i
;
240 /* const sizes are in units of 4 * vec4 */
243 /* instr sizes are in units of 16 instructions */
258 setup_stages(struct fd6_program_state
*state
, struct stage
*s
, bool binning_pass
)
263 static const struct ir3_shader_variant dummy_fs
= {0};
272 s
[HS
].v
= s
[DS
].v
= s
[GS
].v
= NULL
; /* for now */
274 for (i
= 0; i
< MAX_STAGES
; i
++) {
276 s
[i
].i
= &s
[i
].v
->info
;
277 s
[i
].constlen
= align(s
[i
].v
->constlen
, 4);
278 /* instrlen is already in units of 16 instr.. although
279 * probably we should ditch that and not make the compiler
280 * care about instruction group size of a3xx vs a5xx
282 s
[i
].instrlen
= s
[i
].v
->instrlen
;
290 unsigned constoff
= 0;
291 for (i
= 0; i
< MAX_STAGES
; i
++) {
292 s
[i
].constoff
= constoff
;
293 constoff
+= s
[i
].constlen
;
297 s
[FS
].instroff
= 64 - s
[FS
].instrlen
;
298 s
[HS
].instroff
= s
[DS
].instroff
= s
[GS
].instroff
= s
[FS
].instroff
;
302 setup_stateobj(struct fd_ringbuffer
*ring
,
303 struct fd6_program_state
*state
, bool binning_pass
)
305 struct stage s
[MAX_STAGES
];
306 uint32_t pos_regid
, psize_regid
, color_regid
[8];
307 uint32_t face_regid
, coord_regid
, zwcoord_regid
, samp_id_regid
, samp_mask_regid
;
308 uint32_t vcoord_regid
, vertex_regid
, instance_regid
;
309 enum a3xx_threadsize fssz
;
310 uint8_t psize_loc
= ~0;
313 setup_stages(state
, s
, binning_pass
);
317 pos_regid
= ir3_find_output_regid(s
[VS
].v
, VARYING_SLOT_POS
);
318 psize_regid
= ir3_find_output_regid(s
[VS
].v
, VARYING_SLOT_PSIZ
);
319 vertex_regid
= ir3_find_sysval_regid(s
[VS
].v
, SYSTEM_VALUE_VERTEX_ID_ZERO_BASE
);
320 instance_regid
= ir3_find_sysval_regid(s
[VS
].v
, SYSTEM_VALUE_INSTANCE_ID
);
322 if (s
[FS
].v
->color0_mrt
) {
323 color_regid
[0] = color_regid
[1] = color_regid
[2] = color_regid
[3] =
324 color_regid
[4] = color_regid
[5] = color_regid
[6] = color_regid
[7] =
325 ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_COLOR
);
327 color_regid
[0] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA0
);
328 color_regid
[1] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA1
);
329 color_regid
[2] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA2
);
330 color_regid
[3] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA3
);
331 color_regid
[4] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA4
);
332 color_regid
[5] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA5
);
333 color_regid
[6] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA6
);
334 color_regid
[7] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA7
);
337 samp_id_regid
= ir3_find_sysval_regid(s
[FS
].v
, SYSTEM_VALUE_SAMPLE_ID
);
338 samp_mask_regid
= ir3_find_sysval_regid(s
[FS
].v
, SYSTEM_VALUE_SAMPLE_MASK_IN
);
339 face_regid
= ir3_find_sysval_regid(s
[FS
].v
, SYSTEM_VALUE_FRONT_FACE
);
340 coord_regid
= ir3_find_sysval_regid(s
[FS
].v
, SYSTEM_VALUE_FRAG_COORD
);
341 zwcoord_regid
= (coord_regid
== regid(63,0)) ? regid(63,0) : (coord_regid
+ 2);
342 vcoord_regid
= ir3_find_sysval_regid(s
[FS
].v
, SYSTEM_VALUE_VARYING_COORD
);
344 /* we could probably divide this up into things that need to be
345 * emitted if frag-prog is dirty vs if vert-prog is dirty..
348 OUT_PKT4(ring
, REG_A6XX_SP_VS_CONFIG
, 2);
349 OUT_RING(ring
, COND(s
[VS
].v
, A6XX_SP_VS_CONFIG_ENABLED
) |
350 A6XX_SP_VS_CONFIG_NTEX(s
[VS
].v
->num_samp
) |
351 A6XX_SP_VS_CONFIG_NSAMP(s
[VS
].v
->num_samp
)); /* SP_VS_CONFIG */
352 OUT_RING(ring
, s
[VS
].instrlen
); /* SP_VS_INSTRLEN */
354 OUT_PKT4(ring
, REG_A6XX_SP_HS_UNKNOWN_A831
, 1);
357 OUT_PKT4(ring
, REG_A6XX_SP_HS_CONFIG
, 2);
358 OUT_RING(ring
, COND(s
[HS
].v
, A6XX_SP_HS_CONFIG_ENABLED
)); /* SP_HS_CONFIG */
359 OUT_RING(ring
, s
[HS
].instrlen
); /* SP_HS_INSTRLEN */
361 OUT_PKT4(ring
, REG_A6XX_SP_DS_CONFIG
, 2);
362 OUT_RING(ring
, COND(s
[DS
].v
, A6XX_SP_DS_CONFIG_ENABLED
)); /* SP_DS_CONFIG */
363 OUT_RING(ring
, s
[DS
].instrlen
); /* SP_DS_INSTRLEN */
365 OUT_PKT4(ring
, REG_A6XX_SP_GS_UNKNOWN_A871
, 1);
368 OUT_PKT4(ring
, REG_A6XX_SP_GS_CONFIG
, 2);
369 OUT_RING(ring
, COND(s
[GS
].v
, A6XX_SP_GS_CONFIG_ENABLED
)); /* SP_GS_CONFIG */
370 OUT_RING(ring
, s
[GS
].instrlen
); /* SP_GS_INSTRLEN */
372 OUT_PKT4(ring
, REG_A6XX_SP_UNKNOWN_A99E
, 1);
373 OUT_RING(ring
, 0x7fc0);
375 OUT_PKT4(ring
, REG_A6XX_SP_UNKNOWN_A9A8
, 1);
378 OUT_PKT4(ring
, REG_A6XX_SP_UNKNOWN_AB00
, 1);
381 OUT_PKT4(ring
, REG_A6XX_SP_FS_CONFIG
, 2);
382 OUT_RING(ring
, COND(s
[FS
].v
, A6XX_SP_FS_CONFIG_ENABLED
) |
383 A6XX_SP_FS_CONFIG_NTEX(s
[FS
].v
->num_samp
) |
384 A6XX_SP_FS_CONFIG_NSAMP(s
[FS
].v
->num_samp
)); /* SP_FS_CONFIG */
385 OUT_RING(ring
, s
[FS
].instrlen
); /* SP_FS_INSTRLEN */
387 OUT_PKT4(ring
, REG_A6XX_HLSQ_VS_CNTL
, 4);
388 OUT_RING(ring
, A6XX_HLSQ_VS_CNTL_CONSTLEN(s
[VS
].constlen
) | 0x100); /* HLSQ_VS_CONSTLEN */
389 OUT_RING(ring
, A6XX_HLSQ_HS_CNTL_CONSTLEN(s
[HS
].constlen
)); /* HLSQ_HS_CONSTLEN */
390 OUT_RING(ring
, A6XX_HLSQ_DS_CNTL_CONSTLEN(s
[DS
].constlen
)); /* HLSQ_DS_CONSTLEN */
391 OUT_RING(ring
, A6XX_HLSQ_GS_CNTL_CONSTLEN(s
[GS
].constlen
)); /* HLSQ_GS_CONSTLEN */
393 OUT_PKT4(ring
, REG_A6XX_HLSQ_FS_CNTL
, 1);
394 OUT_RING(ring
, A6XX_HLSQ_VS_CNTL_CONSTLEN(s
[FS
].constlen
) | 0x100); /* HLSQ_FS_CONSTLEN */
396 OUT_PKT4(ring
, REG_A6XX_SP_VS_CTRL_REG0
, 1);
397 OUT_RING(ring
, A6XX_SP_VS_CTRL_REG0_THREADSIZE(fssz
) |
398 A6XX_SP_VS_CTRL_REG0_FULLREGFOOTPRINT(s
[VS
].i
->max_reg
+ 1) |
399 A6XX_SP_VS_CTRL_REG0_MERGEDREGS
|
400 A6XX_SP_VS_CTRL_REG0_BRANCHSTACK(0x3) | // XXX need to figure this out somehow..
401 COND(s
[VS
].v
->num_samp
> 0, A6XX_SP_VS_CTRL_REG0_PIXLODENABLE
));
403 struct ir3_shader_linkage l
= {0};
404 ir3_link_shaders(&l
, s
[VS
].v
, s
[FS
].v
);
406 if ((s
[VS
].v
->shader
->stream_output
.num_outputs
> 0) && !binning_pass
)
407 link_stream_out(&l
, s
[VS
].v
);
409 BITSET_DECLARE(varbs
, 128) = {0};
410 uint32_t *varmask
= (uint32_t *)varbs
;
412 for (i
= 0; i
< l
.cnt
; i
++)
413 for (j
= 0; j
< util_last_bit(l
.var
[i
].compmask
); j
++)
414 BITSET_SET(varbs
, l
.var
[i
].loc
+ j
);
416 OUT_PKT4(ring
, REG_A6XX_VPC_VAR_DISABLE(0), 4);
417 OUT_RING(ring
, ~varmask
[0]); /* VPC_VAR[0].DISABLE */
418 OUT_RING(ring
, ~varmask
[1]); /* VPC_VAR[1].DISABLE */
419 OUT_RING(ring
, ~varmask
[2]); /* VPC_VAR[2].DISABLE */
420 OUT_RING(ring
, ~varmask
[3]); /* VPC_VAR[3].DISABLE */
422 /* a6xx appends pos/psize to end of the linkage map: */
423 if (pos_regid
!= regid(63,0))
424 ir3_link_add(&l
, pos_regid
, 0xf, l
.max_loc
);
426 if (psize_regid
!= regid(63,0)) {
427 psize_loc
= l
.max_loc
;
428 ir3_link_add(&l
, psize_regid
, 0x1, l
.max_loc
);
431 if ((s
[VS
].v
->shader
->stream_output
.num_outputs
> 0) && !binning_pass
) {
432 setup_stream_out(state
, s
[VS
].v
, &l
);
435 for (i
= 0, j
= 0; (i
< 16) && (j
< l
.cnt
); i
++) {
438 OUT_PKT4(ring
, REG_A6XX_SP_VS_OUT_REG(i
), 1);
440 reg
|= A6XX_SP_VS_OUT_REG_A_REGID(l
.var
[j
].regid
);
441 reg
|= A6XX_SP_VS_OUT_REG_A_COMPMASK(l
.var
[j
].compmask
);
444 reg
|= A6XX_SP_VS_OUT_REG_B_REGID(l
.var
[j
].regid
);
445 reg
|= A6XX_SP_VS_OUT_REG_B_COMPMASK(l
.var
[j
].compmask
);
451 for (i
= 0, j
= 0; (i
< 8) && (j
< l
.cnt
); i
++) {
454 OUT_PKT4(ring
, REG_A6XX_SP_VS_VPC_DST_REG(i
), 1);
456 reg
|= A6XX_SP_VS_VPC_DST_REG_OUTLOC0(l
.var
[j
++].loc
);
457 reg
|= A6XX_SP_VS_VPC_DST_REG_OUTLOC1(l
.var
[j
++].loc
);
458 reg
|= A6XX_SP_VS_VPC_DST_REG_OUTLOC2(l
.var
[j
++].loc
);
459 reg
|= A6XX_SP_VS_VPC_DST_REG_OUTLOC3(l
.var
[j
++].loc
);
464 OUT_PKT4(ring
, REG_A6XX_SP_VS_OBJ_START_LO
, 2);
465 OUT_RELOC(ring
, s
[VS
].v
->bo
, 0, 0, 0); /* SP_VS_OBJ_START_LO/HI */
468 fd6_emit_shader(ring
, s
[VS
].v
);
470 // TODO depending on other bits in this reg (if any) set somewhere else?
472 OUT_PKT4(ring
, REG_A6XX_PC_PRIM_VTX_CNTL
, 1);
473 OUT_RING(ring
, COND(s
[VS
].v
->writes_psize
, A6XX_PC_PRIM_VTX_CNTL_PSIZE
));
476 OUT_PKT4(ring
, REG_A6XX_SP_PRIMITIVE_CNTL
, 1);
477 OUT_RING(ring
, A6XX_SP_PRIMITIVE_CNTL_VSOUT(l
.cnt
));
479 bool enable_varyings
= s
[FS
].v
->total_in
> 0;
481 OUT_PKT4(ring
, REG_A6XX_VPC_CNTL_0
, 1);
482 OUT_RING(ring
, A6XX_VPC_CNTL_0_NUMNONPOSVAR(s
[FS
].v
->total_in
) |
483 COND(enable_varyings
, A6XX_VPC_CNTL_0_VARYING
) |
486 OUT_PKT4(ring
, REG_A6XX_PC_PRIMITIVE_CNTL_1
, 1);
487 OUT_RING(ring
, A6XX_PC_PRIMITIVE_CNTL_1_STRIDE_IN_VPC(l
.max_loc
) |
488 COND(psize_regid
!= regid(63,0), 0x100));
491 OUT_PKT4(ring
, REG_A6XX_SP_FS_OBJ_START_LO
, 2);
492 OUT_RING(ring
, 0x00000000); /* SP_FS_OBJ_START_LO */
493 OUT_RING(ring
, 0x00000000); /* SP_FS_OBJ_START_HI */
495 OUT_PKT4(ring
, REG_A6XX_SP_FS_OBJ_START_LO
, 2);
496 OUT_RELOC(ring
, s
[FS
].v
->bo
, 0, 0, 0); /* SP_FS_OBJ_START_LO/HI */
499 OUT_PKT4(ring
, REG_A6XX_HLSQ_CONTROL_1_REG
, 5);
500 OUT_RING(ring
, 0x7); /* XXX */
501 OUT_RING(ring
, A6XX_HLSQ_CONTROL_2_REG_FACEREGID(face_regid
) |
502 A6XX_HLSQ_CONTROL_2_REG_SAMPLEID(samp_id_regid
) |
503 A6XX_HLSQ_CONTROL_2_REG_SAMPLEMASK(samp_mask_regid
) |
504 0xfc000000); /* XXX */
505 OUT_RING(ring
, A6XX_HLSQ_CONTROL_3_REG_FRAGCOORDXYREGID(vcoord_regid
) |
506 0xfcfcfc00); /* XXX */
507 OUT_RING(ring
, A6XX_HLSQ_CONTROL_4_REG_XYCOORDREGID(coord_regid
) |
508 A6XX_HLSQ_CONTROL_4_REG_ZWCOORDREGID(zwcoord_regid
) |
509 0x0000fcfc); /* XXX */
510 OUT_RING(ring
, 0xfc); /* XXX */
512 OUT_PKT4(ring
, REG_A6XX_HLSQ_UNKNOWN_B980
, 1);
513 OUT_RING(ring
, s
[FS
].v
->total_in
> 0 ? 3 : 1);
515 OUT_PKT4(ring
, REG_A6XX_SP_FS_CTRL_REG0
, 1);
516 OUT_RING(ring
, A6XX_SP_FS_CTRL_REG0_THREADSIZE(fssz
) |
517 COND(s
[FS
].v
->total_in
> 0, A6XX_SP_FS_CTRL_REG0_VARYING
) |
518 COND(s
[FS
].v
->frag_coord
, A6XX_SP_FS_CTRL_REG0_VARYING
) |
520 A6XX_SP_FS_CTRL_REG0_FULLREGFOOTPRINT(s
[FS
].i
->max_reg
+ 1) |
521 A6XX_SP_FS_CTRL_REG0_MERGEDREGS
|
522 A6XX_SP_FS_CTRL_REG0_BRANCHSTACK(0x3) | // XXX need to figure this out somehow..
523 COND(s
[FS
].v
->num_samp
> 0, A6XX_SP_FS_CTRL_REG0_PIXLODENABLE
));
525 OUT_PKT4(ring
, REG_A6XX_SP_UNKNOWN_A982
, 1);
526 OUT_RING(ring
, 0); /* XXX */
528 OUT_PKT4(ring
, REG_A6XX_HLSQ_UPDATE_CNTL
, 1);
529 OUT_RING(ring
, 0xff); /* XXX */
531 OUT_PKT4(ring
, REG_A6XX_VPC_GS_SIV_CNTL
, 1);
532 OUT_RING(ring
, 0x0000ffff); /* XXX */
535 OUT_PKT4(ring
, REG_A6XX_SP_SP_CNTL
, 1);
536 OUT_RING(ring
, 0x00000010); /* XXX */
539 OUT_PKT4(ring
, REG_A6XX_GRAS_CNTL
, 1);
540 OUT_RING(ring
, COND(enable_varyings
, A6XX_GRAS_CNTL_VARYING
) |
541 COND(s
[FS
].v
->frag_coord
,
542 A6XX_GRAS_CNTL_UNK3
|
543 A6XX_GRAS_CNTL_XCOORD
|
544 A6XX_GRAS_CNTL_YCOORD
|
545 A6XX_GRAS_CNTL_ZCOORD
|
546 A6XX_GRAS_CNTL_WCOORD
));
548 OUT_PKT4(ring
, REG_A6XX_RB_RENDER_CONTROL0
, 2);
549 OUT_RING(ring
, COND(enable_varyings
, A6XX_RB_RENDER_CONTROL0_VARYING
|
550 A6XX_RB_RENDER_CONTROL0_UNK10
) |
551 COND(s
[FS
].v
->frag_coord
,
552 A6XX_RB_RENDER_CONTROL0_UNK3
|
553 A6XX_RB_RENDER_CONTROL0_XCOORD
|
554 A6XX_RB_RENDER_CONTROL0_YCOORD
|
555 A6XX_RB_RENDER_CONTROL0_ZCOORD
|
556 A6XX_RB_RENDER_CONTROL0_WCOORD
));
557 OUT_RING(ring
, COND(s
[FS
].v
->frag_face
, A6XX_RB_RENDER_CONTROL1_FACENESS
));
559 OUT_PKT4(ring
, REG_A6XX_SP_FS_OUTPUT_REG(0), 8);
560 for (i
= 0; i
< 8; i
++) {
561 // TODO we could have a mix of half and full precision outputs,
562 // we really need to figure out half-precision from IR3_REG_HALF
563 OUT_RING(ring
, A6XX_SP_FS_OUTPUT_REG_REGID(color_regid
[i
]) |
565 A6XX_SP_FS_OUTPUT_REG_HALF_PRECISION
));
568 OUT_PKT4(ring
, REG_A6XX_VPC_PACK
, 1);
569 OUT_RING(ring
, A6XX_VPC_PACK_NUMNONPOSVAR(s
[FS
].v
->total_in
) |
570 A6XX_VPC_PACK_PSIZELOC(psize_loc
) |
571 A6XX_VPC_PACK_STRIDE_IN_VPC(l
.max_loc
));
574 /* figure out VARYING_INTERP / VARYING_PS_REPL register values: */
575 for (j
= -1; (j
= ir3_next_varying(s
[FS
].v
, j
)) < (int)s
[FS
].v
->inputs_count
; ) {
576 /* NOTE: varyings are packed, so if compmask is 0xb
577 * then first, third, and fourth component occupy
578 * three consecutive varying slots:
580 unsigned compmask
= s
[FS
].v
->inputs
[j
].compmask
;
582 uint32_t inloc
= s
[FS
].v
->inputs
[j
].inloc
;
584 if (s
[FS
].v
->inputs
[j
].interpolate
== INTERP_MODE_FLAT
) {
585 uint32_t loc
= inloc
;
587 for (i
= 0; i
< 4; i
++) {
588 if (compmask
& (1 << i
)) {
589 state
->vinterp
[loc
/ 16] |= 1 << ((loc
% 16) * 2);
599 fd6_emit_shader(ring
, s
[FS
].v
);
601 OUT_PKT4(ring
, REG_A6XX_VFD_CONTROL_1
, 6);
602 OUT_RING(ring
, A6XX_VFD_CONTROL_1_REGID4VTX(vertex_regid
) |
603 A6XX_VFD_CONTROL_1_REGID4INST(instance_regid
) |
605 OUT_RING(ring
, 0x0000fcfc); /* VFD_CONTROL_2 */
606 OUT_RING(ring
, 0xfcfcfcfc); /* VFD_CONTROL_3 */
607 OUT_RING(ring
, 0x000000fc); /* VFD_CONTROL_4 */
608 OUT_RING(ring
, 0x0000fcfc); /* VFD_CONTROL_5 */
609 OUT_RING(ring
, 0x00000000); /* VFD_CONTROL_6 */
612 /* emits the program state which is not part of the stateobj because of
613 * dependency on other gl state (rasterflat or sprite-coord-replacement)
616 fd6_program_emit(struct fd_ringbuffer
*ring
, struct fd6_emit
*emit
)
618 const struct fd6_program_state
*state
= fd6_emit_get_prog(emit
);
620 if (!unlikely(emit
->rasterflat
|| emit
->sprite_coord_enable
)) {
622 OUT_PKT4(ring
, REG_A6XX_VPC_VARYING_INTERP_MODE(0), 8);
623 for (int i
= 0; i
< 8; i
++)
624 OUT_RING(ring
, state
->vinterp
[i
]); /* VPC_VARYING_INTERP[i].MODE */
626 OUT_PKT4(ring
, REG_A6XX_VPC_VARYING_PS_REPL_MODE(0), 8);
627 for (int i
= 0; i
< 8; i
++)
628 OUT_RING(ring
, 0x00000000); /* VPC_VARYING_PS_REPL[i] */
631 struct ir3_shader_variant
*fs
= state
->fs
;
632 uint32_t vinterp
[8], vpsrepl
[8];
634 memset(vinterp
, 0, sizeof(vinterp
));
635 memset(vpsrepl
, 0, sizeof(vpsrepl
));
637 for (int i
= 0; i
< state
->fs_inputs_count
; i
++) {
638 int j
= state
->fs_inputs
[i
];
640 /* NOTE: varyings are packed, so if compmask is 0xb
641 * then first, third, and fourth component occupy
642 * three consecutive varying slots:
644 unsigned compmask
= fs
->inputs
[j
].compmask
;
646 uint32_t inloc
= fs
->inputs
[j
].inloc
;
648 if ((fs
->inputs
[j
].interpolate
== INTERP_MODE_FLAT
) ||
649 (fs
->inputs
[j
].rasterflat
&& emit
->rasterflat
)) {
650 uint32_t loc
= inloc
;
652 for (i
= 0; i
< 4; i
++) {
653 if (compmask
& (1 << i
)) {
654 vinterp
[loc
/ 16] |= 1 << ((loc
% 16) * 2);
660 gl_varying_slot slot
= fs
->inputs
[j
].slot
;
662 /* since we don't enable PIPE_CAP_TGSI_TEXCOORD: */
663 if (slot
>= VARYING_SLOT_VAR0
) {
664 unsigned texmask
= 1 << (slot
- VARYING_SLOT_VAR0
);
665 /* Replace the .xy coordinates with S/T from the point sprite. Set
666 * interpolation bits for .zw such that they become .01
668 if (emit
->sprite_coord_enable
& texmask
) {
669 /* mask is two 2-bit fields, where:
672 * '11' -> 1 - T (flip mode)
674 unsigned mask
= emit
->sprite_coord_mode
? 0b1101 : 0b1001;
675 uint32_t loc
= inloc
;
676 if (compmask
& 0x1) {
677 vpsrepl
[loc
/ 16] |= ((mask
>> 0) & 0x3) << ((loc
% 16) * 2);
680 if (compmask
& 0x2) {
681 vpsrepl
[loc
/ 16] |= ((mask
>> 2) & 0x3) << ((loc
% 16) * 2);
684 if (compmask
& 0x4) {
686 vinterp
[loc
/ 16] |= 0b10 << ((loc
% 16) * 2);
689 if (compmask
& 0x8) {
691 vinterp
[loc
/ 16] |= 0b11 << ((loc
% 16) * 2);
698 OUT_PKT4(ring
, REG_A6XX_VPC_VARYING_INTERP_MODE(0), 8);
699 for (int i
= 0; i
< 8; i
++)
700 OUT_RING(ring
, vinterp
[i
]); /* VPC_VARYING_INTERP[i].MODE */
702 OUT_PKT4(ring
, REG_A6XX_VPC_VARYING_PS_REPL_MODE(0), 8);
703 for (int i
= 0; i
< 8; i
++)
704 OUT_RING(ring
, vpsrepl
[i
]); /* VPC_VARYING_PS_REPL[i] */
708 static struct ir3_program_state
*
709 fd6_program_create(void *data
, struct ir3_shader_variant
*bs
,
710 struct ir3_shader_variant
*vs
,
711 struct ir3_shader_variant
*fs
,
712 const struct ir3_shader_key
*key
)
714 struct fd_context
*ctx
= data
;
715 struct fd6_program_state
*state
= CALLOC_STRUCT(fd6_program_state
);
720 state
->binning_stateobj
= fd_ringbuffer_new_object(ctx
->pipe
, 0x1000);
721 state
->stateobj
= fd_ringbuffer_new_object(ctx
->pipe
, 0x1000);
723 setup_stateobj(state
->binning_stateobj
, state
, true);
724 setup_stateobj(state
->stateobj
, state
, false);
730 fd6_program_destroy(void *data
, struct ir3_program_state
*state
)
732 struct fd6_program_state
*so
= fd6_program_state(state
);
733 fd_ringbuffer_del(so
->stateobj
);
734 fd_ringbuffer_del(so
->binning_stateobj
);
738 static const struct ir3_cache_funcs cache_funcs
= {
739 .create_state
= fd6_program_create
,
740 .destroy_state
= fd6_program_destroy
,
744 fd6_prog_init(struct pipe_context
*pctx
)
746 struct fd_context
*ctx
= fd_context(pctx
);
748 fd6_context(ctx
)->shader_cache
= ir3_cache_create(&cache_funcs
, ctx
);
750 pctx
->create_fs_state
= fd6_fp_state_create
;
751 pctx
->delete_fs_state
= fd6_fp_state_delete
;
753 pctx
->create_vs_state
= fd6_vp_state_create
;
754 pctx
->delete_vs_state
= fd6_vp_state_delete
;