2 * Copyright (C) 2016 Rob Clark <robclark@freedesktop.org>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Rob Clark <robclark@freedesktop.org>
27 #include "pipe/p_state.h"
28 #include "util/u_string.h"
29 #include "util/u_memory.h"
30 #include "util/u_inlines.h"
31 #include "util/format/u_format.h"
32 #include "util/bitset.h"
34 #include "freedreno_program.h"
36 #include "fd5_program.h"
38 #include "fd5_texture.h"
39 #include "fd5_format.h"
41 #include "ir3_cache.h"
44 fd5_emit_shader(struct fd_ringbuffer
*ring
, const struct ir3_shader_variant
*so
)
46 const struct ir3_info
*si
= &so
->info
;
47 enum a4xx_state_block sb
= fd4_stage2shadersb(so
->type
);
48 enum a4xx_state_src src
;
51 if (fd_mesa_debug
& FD_DBG_DIRECT
) {
54 bin
= fd_bo_map(so
->bo
);
61 OUT_PKT7(ring
, CP_LOAD_STATE4
, 3 + sz
);
62 OUT_RING(ring
, CP_LOAD_STATE4_0_DST_OFF(0) |
63 CP_LOAD_STATE4_0_STATE_SRC(src
) |
64 CP_LOAD_STATE4_0_STATE_BLOCK(sb
) |
65 CP_LOAD_STATE4_0_NUM_UNIT(so
->instrlen
));
67 OUT_RING(ring
, CP_LOAD_STATE4_1_EXT_SRC_ADDR(0) |
68 CP_LOAD_STATE4_1_STATE_TYPE(ST4_SHADER
));
69 OUT_RING(ring
, CP_LOAD_STATE4_2_EXT_SRC_ADDR_HI(0));
71 OUT_RELOCD(ring
, so
->bo
, 0,
72 CP_LOAD_STATE4_1_STATE_TYPE(ST4_SHADER
), 0);
75 /* for how clever coverity is, it is sometimes rather dull, and
76 * doesn't realize that the only case where bin==NULL, sz==0:
78 assume(bin
|| (sz
== 0));
80 for (i
= 0; i
< sz
; i
++) {
81 OUT_RING(ring
, bin
[i
]);
85 /* Add any missing varyings needed for stream-out. Otherwise varyings not
86 * used by fragment shader will be stripped out.
89 link_stream_out(struct ir3_shader_linkage
*l
, const struct ir3_shader_variant
*v
)
91 const struct ir3_stream_output_info
*strmout
= &v
->shader
->stream_output
;
94 * First, any stream-out varyings not already in linkage map (ie. also
95 * consumed by frag shader) need to be added:
97 for (unsigned i
= 0; i
< strmout
->num_outputs
; i
++) {
98 const struct ir3_stream_output
*out
= &strmout
->output
[i
];
99 unsigned k
= out
->register_index
;
101 (1 << (out
->num_components
+ out
->start_component
)) - 1;
102 unsigned idx
, nextloc
= 0;
104 /* psize/pos need to be the last entries in linkage map, and will
105 * get added link_stream_out, so skip over them:
107 if ((v
->outputs
[k
].slot
== VARYING_SLOT_PSIZ
) ||
108 (v
->outputs
[k
].slot
== VARYING_SLOT_POS
))
111 for (idx
= 0; idx
< l
->cnt
; idx
++) {
112 if (l
->var
[idx
].regid
== v
->outputs
[k
].regid
)
114 nextloc
= MAX2(nextloc
, l
->var
[idx
].loc
+ 4);
117 /* add if not already in linkage map: */
119 ir3_link_add(l
, v
->outputs
[k
].regid
, compmask
, nextloc
);
121 /* expand component-mask if needed, ie streaming out all components
122 * but frag shader doesn't consume all components:
124 if (compmask
& ~l
->var
[idx
].compmask
) {
125 l
->var
[idx
].compmask
|= compmask
;
126 l
->max_loc
= MAX2(l
->max_loc
,
127 l
->var
[idx
].loc
+ util_last_bit(l
->var
[idx
].compmask
));
132 /* TODO maybe some of this we could pre-compute once rather than having
133 * so much draw-time logic?
136 emit_stream_out(struct fd_ringbuffer
*ring
, const struct ir3_shader_variant
*v
,
137 struct ir3_shader_linkage
*l
)
139 const struct ir3_stream_output_info
*strmout
= &v
->shader
->stream_output
;
140 unsigned ncomp
[PIPE_MAX_SO_BUFFERS
] = {0};
141 unsigned prog
[align(l
->max_loc
, 2) / 2];
143 memset(prog
, 0, sizeof(prog
));
145 for (unsigned i
= 0; i
< strmout
->num_outputs
; i
++) {
146 const struct ir3_stream_output
*out
= &strmout
->output
[i
];
147 unsigned k
= out
->register_index
;
150 ncomp
[out
->output_buffer
] += out
->num_components
;
152 /* linkage map sorted by order frag shader wants things, so
153 * a bit less ideal here..
155 for (idx
= 0; idx
< l
->cnt
; idx
++)
156 if (l
->var
[idx
].regid
== v
->outputs
[k
].regid
)
159 debug_assert(idx
< l
->cnt
);
161 for (unsigned j
= 0; j
< out
->num_components
; j
++) {
162 unsigned c
= j
+ out
->start_component
;
163 unsigned loc
= l
->var
[idx
].loc
+ c
;
164 unsigned off
= j
+ out
->dst_offset
; /* in dwords */
167 prog
[loc
/2] |= A5XX_VPC_SO_PROG_B_EN
|
168 A5XX_VPC_SO_PROG_B_BUF(out
->output_buffer
) |
169 A5XX_VPC_SO_PROG_B_OFF(off
* 4);
171 prog
[loc
/2] |= A5XX_VPC_SO_PROG_A_EN
|
172 A5XX_VPC_SO_PROG_A_BUF(out
->output_buffer
) |
173 A5XX_VPC_SO_PROG_A_OFF(off
* 4);
178 OUT_PKT7(ring
, CP_CONTEXT_REG_BUNCH
, 12 + (2 * ARRAY_SIZE(prog
)));
179 OUT_RING(ring
, REG_A5XX_VPC_SO_BUF_CNTL
);
180 OUT_RING(ring
, A5XX_VPC_SO_BUF_CNTL_ENABLE
|
181 COND(ncomp
[0] > 0, A5XX_VPC_SO_BUF_CNTL_BUF0
) |
182 COND(ncomp
[1] > 0, A5XX_VPC_SO_BUF_CNTL_BUF1
) |
183 COND(ncomp
[2] > 0, A5XX_VPC_SO_BUF_CNTL_BUF2
) |
184 COND(ncomp
[3] > 0, A5XX_VPC_SO_BUF_CNTL_BUF3
));
185 OUT_RING(ring
, REG_A5XX_VPC_SO_NCOMP(0));
186 OUT_RING(ring
, ncomp
[0]);
187 OUT_RING(ring
, REG_A5XX_VPC_SO_NCOMP(1));
188 OUT_RING(ring
, ncomp
[1]);
189 OUT_RING(ring
, REG_A5XX_VPC_SO_NCOMP(2));
190 OUT_RING(ring
, ncomp
[2]);
191 OUT_RING(ring
, REG_A5XX_VPC_SO_NCOMP(3));
192 OUT_RING(ring
, ncomp
[3]);
193 OUT_RING(ring
, REG_A5XX_VPC_SO_CNTL
);
194 OUT_RING(ring
, A5XX_VPC_SO_CNTL_ENABLE
);
195 for (unsigned i
= 0; i
< ARRAY_SIZE(prog
); i
++) {
196 OUT_RING(ring
, REG_A5XX_VPC_SO_PROG
);
197 OUT_RING(ring
, prog
[i
]);
202 const struct ir3_shader_variant
*v
;
203 const struct ir3_info
*i
;
204 /* const sizes are in units of 4 * vec4 */
207 /* instr sizes are in units of 16 instructions */
222 setup_stages(struct fd5_emit
*emit
, struct stage
*s
)
226 s
[VS
].v
= fd5_emit_get_vp(emit
);
227 s
[FS
].v
= fd5_emit_get_fp(emit
);
229 s
[HS
].v
= s
[DS
].v
= s
[GS
].v
= NULL
; /* for now */
231 for (i
= 0; i
< MAX_STAGES
; i
++) {
233 s
[i
].i
= &s
[i
].v
->info
;
234 /* constlen is in units of 4 * vec4: */
235 s
[i
].constlen
= align(s
[i
].v
->constlen
, 4) / 4;
236 /* instrlen is already in units of 16 instr.. although
237 * probably we should ditch that and not make the compiler
238 * care about instruction group size of a3xx vs a5xx
240 s
[i
].instrlen
= s
[i
].v
->instrlen
;
248 /* NOTE: at least for gles2, blob partitions VS at bottom of const
249 * space and FS taking entire remaining space. We probably don't
250 * need to do that the same way, but for now mimic what the blob
251 * does to make it easier to diff against register values from blob
253 * NOTE: if VS.instrlen + FS.instrlen > 64, then one or both shaders
254 * is run from external memory.
256 if ((s
[VS
].instrlen
+ s
[FS
].instrlen
) > 64) {
257 /* prioritize FS for internal memory: */
258 if (s
[FS
].instrlen
< 64) {
259 /* if FS can fit, kick VS out to external memory: */
261 } else if (s
[VS
].instrlen
< 64) {
262 /* otherwise if VS can fit, kick out FS: */
265 /* neither can fit, run both from external memory: */
271 unsigned constoff
= 0;
272 for (i
= 0; i
< MAX_STAGES
; i
++) {
273 s
[i
].constoff
= constoff
;
274 constoff
+= s
[i
].constlen
;
278 s
[FS
].instroff
= 64 - s
[FS
].instrlen
;
279 s
[HS
].instroff
= s
[DS
].instroff
= s
[GS
].instroff
= s
[FS
].instroff
;
283 fd5_program_emit(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
,
284 struct fd5_emit
*emit
)
286 struct stage s
[MAX_STAGES
];
287 uint32_t pos_regid
, psize_regid
, color_regid
[8];
288 uint32_t face_regid
, coord_regid
, zwcoord_regid
, samp_id_regid
, samp_mask_regid
;
289 uint32_t vcoord_regid
, vertex_regid
, instance_regid
;
290 enum a3xx_threadsize fssz
;
291 uint8_t psize_loc
= ~0;
294 setup_stages(emit
, s
);
296 fssz
= (s
[FS
].i
->max_reg
>= 24) ? TWO_QUADS
: FOUR_QUADS
;
298 pos_regid
= ir3_find_output_regid(s
[VS
].v
, VARYING_SLOT_POS
);
299 psize_regid
= ir3_find_output_regid(s
[VS
].v
, VARYING_SLOT_PSIZ
);
300 vertex_regid
= ir3_find_sysval_regid(s
[VS
].v
, SYSTEM_VALUE_VERTEX_ID_ZERO_BASE
);
301 instance_regid
= ir3_find_sysval_regid(s
[VS
].v
, SYSTEM_VALUE_INSTANCE_ID
);
303 if (s
[FS
].v
->color0_mrt
) {
304 color_regid
[0] = color_regid
[1] = color_regid
[2] = color_regid
[3] =
305 color_regid
[4] = color_regid
[5] = color_regid
[6] = color_regid
[7] =
306 ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_COLOR
);
308 color_regid
[0] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA0
);
309 color_regid
[1] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA1
);
310 color_regid
[2] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA2
);
311 color_regid
[3] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA3
);
312 color_regid
[4] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA4
);
313 color_regid
[5] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA5
);
314 color_regid
[6] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA6
);
315 color_regid
[7] = ir3_find_output_regid(s
[FS
].v
, FRAG_RESULT_DATA7
);
318 samp_id_regid
= ir3_find_sysval_regid(s
[FS
].v
, SYSTEM_VALUE_SAMPLE_ID
);
319 samp_mask_regid
= ir3_find_sysval_regid(s
[FS
].v
, SYSTEM_VALUE_SAMPLE_MASK_IN
);
320 face_regid
= ir3_find_sysval_regid(s
[FS
].v
, SYSTEM_VALUE_FRONT_FACE
);
321 coord_regid
= ir3_find_sysval_regid(s
[FS
].v
, SYSTEM_VALUE_FRAG_COORD
);
322 zwcoord_regid
= (coord_regid
== regid(63,0)) ? regid(63,0) : (coord_regid
+ 2);
323 vcoord_regid
= ir3_find_sysval_regid(s
[FS
].v
, SYSTEM_VALUE_BARYCENTRIC_PERSP_PIXEL
);
325 /* we could probably divide this up into things that need to be
326 * emitted if frag-prog is dirty vs if vert-prog is dirty..
329 OUT_PKT4(ring
, REG_A5XX_HLSQ_VS_CONFIG
, 5);
330 OUT_RING(ring
, A5XX_HLSQ_VS_CONFIG_CONSTOBJECTOFFSET(s
[VS
].constoff
) |
331 A5XX_HLSQ_VS_CONFIG_SHADEROBJOFFSET(s
[VS
].instroff
) |
332 COND(s
[VS
].v
, A5XX_HLSQ_VS_CONFIG_ENABLED
));
333 OUT_RING(ring
, A5XX_HLSQ_FS_CONFIG_CONSTOBJECTOFFSET(s
[FS
].constoff
) |
334 A5XX_HLSQ_FS_CONFIG_SHADEROBJOFFSET(s
[FS
].instroff
) |
335 COND(s
[FS
].v
, A5XX_HLSQ_FS_CONFIG_ENABLED
));
336 OUT_RING(ring
, A5XX_HLSQ_HS_CONFIG_CONSTOBJECTOFFSET(s
[HS
].constoff
) |
337 A5XX_HLSQ_HS_CONFIG_SHADEROBJOFFSET(s
[HS
].instroff
) |
338 COND(s
[HS
].v
, A5XX_HLSQ_HS_CONFIG_ENABLED
));
339 OUT_RING(ring
, A5XX_HLSQ_DS_CONFIG_CONSTOBJECTOFFSET(s
[DS
].constoff
) |
340 A5XX_HLSQ_DS_CONFIG_SHADEROBJOFFSET(s
[DS
].instroff
) |
341 COND(s
[DS
].v
, A5XX_HLSQ_DS_CONFIG_ENABLED
));
342 OUT_RING(ring
, A5XX_HLSQ_GS_CONFIG_CONSTOBJECTOFFSET(s
[GS
].constoff
) |
343 A5XX_HLSQ_GS_CONFIG_SHADEROBJOFFSET(s
[GS
].instroff
) |
344 COND(s
[GS
].v
, A5XX_HLSQ_GS_CONFIG_ENABLED
));
346 OUT_PKT4(ring
, REG_A5XX_HLSQ_CS_CONFIG
, 1);
347 OUT_RING(ring
, 0x00000000);
349 OUT_PKT4(ring
, REG_A5XX_HLSQ_VS_CNTL
, 5);
350 OUT_RING(ring
, A5XX_HLSQ_VS_CNTL_INSTRLEN(s
[VS
].instrlen
) |
351 COND(s
[VS
].v
&& s
[VS
].v
->has_ssbo
, A5XX_HLSQ_VS_CNTL_SSBO_ENABLE
));
352 OUT_RING(ring
, A5XX_HLSQ_FS_CNTL_INSTRLEN(s
[FS
].instrlen
) |
353 COND(s
[FS
].v
&& s
[FS
].v
->has_ssbo
, A5XX_HLSQ_FS_CNTL_SSBO_ENABLE
));
354 OUT_RING(ring
, A5XX_HLSQ_HS_CNTL_INSTRLEN(s
[HS
].instrlen
) |
355 COND(s
[HS
].v
&& s
[HS
].v
->has_ssbo
, A5XX_HLSQ_HS_CNTL_SSBO_ENABLE
));
356 OUT_RING(ring
, A5XX_HLSQ_DS_CNTL_INSTRLEN(s
[DS
].instrlen
) |
357 COND(s
[DS
].v
&& s
[DS
].v
->has_ssbo
, A5XX_HLSQ_DS_CNTL_SSBO_ENABLE
));
358 OUT_RING(ring
, A5XX_HLSQ_GS_CNTL_INSTRLEN(s
[GS
].instrlen
) |
359 COND(s
[GS
].v
&& s
[GS
].v
->has_ssbo
, A5XX_HLSQ_GS_CNTL_SSBO_ENABLE
));
361 OUT_PKT4(ring
, REG_A5XX_SP_VS_CONFIG
, 5);
362 OUT_RING(ring
, A5XX_SP_VS_CONFIG_CONSTOBJECTOFFSET(s
[VS
].constoff
) |
363 A5XX_SP_VS_CONFIG_SHADEROBJOFFSET(s
[VS
].instroff
) |
364 COND(s
[VS
].v
, A5XX_SP_VS_CONFIG_ENABLED
));
365 OUT_RING(ring
, A5XX_SP_FS_CONFIG_CONSTOBJECTOFFSET(s
[FS
].constoff
) |
366 A5XX_SP_FS_CONFIG_SHADEROBJOFFSET(s
[FS
].instroff
) |
367 COND(s
[FS
].v
, A5XX_SP_FS_CONFIG_ENABLED
));
368 OUT_RING(ring
, A5XX_SP_HS_CONFIG_CONSTOBJECTOFFSET(s
[HS
].constoff
) |
369 A5XX_SP_HS_CONFIG_SHADEROBJOFFSET(s
[HS
].instroff
) |
370 COND(s
[HS
].v
, A5XX_SP_HS_CONFIG_ENABLED
));
371 OUT_RING(ring
, A5XX_SP_DS_CONFIG_CONSTOBJECTOFFSET(s
[DS
].constoff
) |
372 A5XX_SP_DS_CONFIG_SHADEROBJOFFSET(s
[DS
].instroff
) |
373 COND(s
[DS
].v
, A5XX_SP_DS_CONFIG_ENABLED
));
374 OUT_RING(ring
, A5XX_SP_GS_CONFIG_CONSTOBJECTOFFSET(s
[GS
].constoff
) |
375 A5XX_SP_GS_CONFIG_SHADEROBJOFFSET(s
[GS
].instroff
) |
376 COND(s
[GS
].v
, A5XX_SP_GS_CONFIG_ENABLED
));
378 OUT_PKT4(ring
, REG_A5XX_SP_CS_CONFIG
, 1);
379 OUT_RING(ring
, 0x00000000);
381 OUT_PKT4(ring
, REG_A5XX_HLSQ_VS_CONSTLEN
, 2);
382 OUT_RING(ring
, s
[VS
].constlen
); /* HLSQ_VS_CONSTLEN */
383 OUT_RING(ring
, s
[VS
].instrlen
); /* HLSQ_VS_INSTRLEN */
385 OUT_PKT4(ring
, REG_A5XX_HLSQ_FS_CONSTLEN
, 2);
386 OUT_RING(ring
, s
[FS
].constlen
); /* HLSQ_FS_CONSTLEN */
387 OUT_RING(ring
, s
[FS
].instrlen
); /* HLSQ_FS_INSTRLEN */
389 OUT_PKT4(ring
, REG_A5XX_HLSQ_HS_CONSTLEN
, 2);
390 OUT_RING(ring
, s
[HS
].constlen
); /* HLSQ_HS_CONSTLEN */
391 OUT_RING(ring
, s
[HS
].instrlen
); /* HLSQ_HS_INSTRLEN */
393 OUT_PKT4(ring
, REG_A5XX_HLSQ_DS_CONSTLEN
, 2);
394 OUT_RING(ring
, s
[DS
].constlen
); /* HLSQ_DS_CONSTLEN */
395 OUT_RING(ring
, s
[DS
].instrlen
); /* HLSQ_DS_INSTRLEN */
397 OUT_PKT4(ring
, REG_A5XX_HLSQ_GS_CONSTLEN
, 2);
398 OUT_RING(ring
, s
[GS
].constlen
); /* HLSQ_GS_CONSTLEN */
399 OUT_RING(ring
, s
[GS
].instrlen
); /* HLSQ_GS_INSTRLEN */
401 OUT_PKT4(ring
, REG_A5XX_HLSQ_CS_CONSTLEN
, 2);
402 OUT_RING(ring
, 0x00000000); /* HLSQ_CS_CONSTLEN */
403 OUT_RING(ring
, 0x00000000); /* HLSQ_CS_INSTRLEN */
405 OUT_PKT4(ring
, REG_A5XX_SP_VS_CTRL_REG0
, 1);
406 OUT_RING(ring
, A5XX_SP_VS_CTRL_REG0_HALFREGFOOTPRINT(s
[VS
].i
->max_half_reg
+ 1) |
407 A5XX_SP_VS_CTRL_REG0_FULLREGFOOTPRINT(s
[VS
].i
->max_reg
+ 1) |
408 0x6 | /* XXX seems to be always set? */
409 A5XX_SP_VS_CTRL_REG0_BRANCHSTACK(s
[VS
].v
->branchstack
) |
410 COND(s
[VS
].v
->num_samp
> 0, A5XX_SP_VS_CTRL_REG0_PIXLODENABLE
));
412 struct ir3_shader_linkage l
= {0};
413 ir3_link_shaders(&l
, s
[VS
].v
, s
[FS
].v
);
415 if ((s
[VS
].v
->shader
->stream_output
.num_outputs
> 0) &&
417 link_stream_out(&l
, s
[VS
].v
);
419 BITSET_DECLARE(varbs
, 128) = {0};
420 uint32_t *varmask
= (uint32_t *)varbs
;
422 for (i
= 0; i
< l
.cnt
; i
++)
423 for (j
= 0; j
< util_last_bit(l
.var
[i
].compmask
); j
++)
424 BITSET_SET(varbs
, l
.var
[i
].loc
+ j
);
426 OUT_PKT4(ring
, REG_A5XX_VPC_VAR_DISABLE(0), 4);
427 OUT_RING(ring
, ~varmask
[0]); /* VPC_VAR[0].DISABLE */
428 OUT_RING(ring
, ~varmask
[1]); /* VPC_VAR[1].DISABLE */
429 OUT_RING(ring
, ~varmask
[2]); /* VPC_VAR[2].DISABLE */
430 OUT_RING(ring
, ~varmask
[3]); /* VPC_VAR[3].DISABLE */
432 /* a5xx appends pos/psize to end of the linkage map: */
433 if (pos_regid
!= regid(63,0))
434 ir3_link_add(&l
, pos_regid
, 0xf, l
.max_loc
);
436 if (psize_regid
!= regid(63,0)) {
437 psize_loc
= l
.max_loc
;
438 ir3_link_add(&l
, psize_regid
, 0x1, l
.max_loc
);
441 if ((s
[VS
].v
->shader
->stream_output
.num_outputs
> 0) &&
442 !emit
->binning_pass
) {
443 emit_stream_out(ring
, s
[VS
].v
, &l
);
445 OUT_PKT4(ring
, REG_A5XX_VPC_SO_OVERRIDE
, 1);
446 OUT_RING(ring
, 0x00000000);
448 OUT_PKT4(ring
, REG_A5XX_VPC_SO_OVERRIDE
, 1);
449 OUT_RING(ring
, A5XX_VPC_SO_OVERRIDE_SO_DISABLE
);
452 for (i
= 0, j
= 0; (i
< 16) && (j
< l
.cnt
); i
++) {
455 OUT_PKT4(ring
, REG_A5XX_SP_VS_OUT_REG(i
), 1);
457 reg
|= A5XX_SP_VS_OUT_REG_A_REGID(l
.var
[j
].regid
);
458 reg
|= A5XX_SP_VS_OUT_REG_A_COMPMASK(l
.var
[j
].compmask
);
461 reg
|= A5XX_SP_VS_OUT_REG_B_REGID(l
.var
[j
].regid
);
462 reg
|= A5XX_SP_VS_OUT_REG_B_COMPMASK(l
.var
[j
].compmask
);
468 for (i
= 0, j
= 0; (i
< 8) && (j
< l
.cnt
); i
++) {
471 OUT_PKT4(ring
, REG_A5XX_SP_VS_VPC_DST_REG(i
), 1);
473 reg
|= A5XX_SP_VS_VPC_DST_REG_OUTLOC0(l
.var
[j
++].loc
);
474 reg
|= A5XX_SP_VS_VPC_DST_REG_OUTLOC1(l
.var
[j
++].loc
);
475 reg
|= A5XX_SP_VS_VPC_DST_REG_OUTLOC2(l
.var
[j
++].loc
);
476 reg
|= A5XX_SP_VS_VPC_DST_REG_OUTLOC3(l
.var
[j
++].loc
);
481 OUT_PKT4(ring
, REG_A5XX_SP_VS_OBJ_START_LO
, 2);
482 OUT_RELOC(ring
, s
[VS
].v
->bo
, 0, 0, 0); /* SP_VS_OBJ_START_LO/HI */
485 fd5_emit_shader(ring
, s
[VS
].v
);
487 // TODO depending on other bits in this reg (if any) set somewhere else?
488 OUT_PKT4(ring
, REG_A5XX_PC_PRIM_VTX_CNTL
, 1);
489 OUT_RING(ring
, COND(s
[VS
].v
->writes_psize
, A5XX_PC_PRIM_VTX_CNTL_PSIZE
));
491 OUT_PKT4(ring
, REG_A5XX_SP_PRIMITIVE_CNTL
, 1);
492 OUT_RING(ring
, A5XX_SP_PRIMITIVE_CNTL_VSOUT(l
.cnt
));
494 OUT_PKT4(ring
, REG_A5XX_VPC_CNTL_0
, 1);
495 OUT_RING(ring
, A5XX_VPC_CNTL_0_STRIDE_IN_VPC(l
.max_loc
) |
496 COND(s
[FS
].v
->total_in
> 0, A5XX_VPC_CNTL_0_VARYING
) |
497 COND(s
[FS
].v
->frag_coord
, A5XX_VPC_CNTL_0_VARYING
) |
500 fd5_context(ctx
)->max_loc
= l
.max_loc
;
502 if (emit
->binning_pass
) {
503 OUT_PKT4(ring
, REG_A5XX_SP_FS_OBJ_START_LO
, 2);
504 OUT_RING(ring
, 0x00000000); /* SP_FS_OBJ_START_LO */
505 OUT_RING(ring
, 0x00000000); /* SP_FS_OBJ_START_HI */
507 OUT_PKT4(ring
, REG_A5XX_SP_FS_OBJ_START_LO
, 2);
508 OUT_RELOC(ring
, s
[FS
].v
->bo
, 0, 0, 0); /* SP_FS_OBJ_START_LO/HI */
511 OUT_PKT4(ring
, REG_A5XX_HLSQ_CONTROL_0_REG
, 5);
512 OUT_RING(ring
, A5XX_HLSQ_CONTROL_0_REG_FSTHREADSIZE(fssz
) |
513 A5XX_HLSQ_CONTROL_0_REG_CSTHREADSIZE(TWO_QUADS
) |
514 0x00000880); /* XXX HLSQ_CONTROL_0 */
515 OUT_RING(ring
, A5XX_HLSQ_CONTROL_1_REG_PRIMALLOCTHRESHOLD(63));
516 OUT_RING(ring
, A5XX_HLSQ_CONTROL_2_REG_FACEREGID(face_regid
) |
517 A5XX_HLSQ_CONTROL_2_REG_SAMPLEID(samp_id_regid
) |
518 A5XX_HLSQ_CONTROL_2_REG_SAMPLEMASK(samp_mask_regid
) |
519 0xfc000000); /* XXX */
520 OUT_RING(ring
, A5XX_HLSQ_CONTROL_3_REG_FRAGCOORDXYREGID(vcoord_regid
) |
521 0xfcfcfc00); /* XXX */
522 OUT_RING(ring
, A5XX_HLSQ_CONTROL_4_REG_XYCOORDREGID(coord_regid
) |
523 A5XX_HLSQ_CONTROL_4_REG_ZWCOORDREGID(zwcoord_regid
) |
524 0x0000fcfc); /* XXX */
526 OUT_PKT4(ring
, REG_A5XX_SP_FS_CTRL_REG0
, 1);
527 OUT_RING(ring
, COND(s
[FS
].v
->total_in
> 0, A5XX_SP_FS_CTRL_REG0_VARYING
) |
528 COND(s
[FS
].v
->frag_coord
, A5XX_SP_FS_CTRL_REG0_VARYING
) |
529 0x40006 | /* XXX set pretty much everywhere */
530 A5XX_SP_FS_CTRL_REG0_THREADSIZE(fssz
) |
531 A5XX_SP_FS_CTRL_REG0_HALFREGFOOTPRINT(s
[FS
].i
->max_half_reg
+ 1) |
532 A5XX_SP_FS_CTRL_REG0_FULLREGFOOTPRINT(s
[FS
].i
->max_reg
+ 1) |
533 A5XX_SP_FS_CTRL_REG0_BRANCHSTACK(s
[FS
].v
->branchstack
) |
534 COND(s
[FS
].v
->num_samp
> 0, A5XX_SP_FS_CTRL_REG0_PIXLODENABLE
));
536 OUT_PKT4(ring
, REG_A5XX_HLSQ_UPDATE_CNTL
, 1);
537 OUT_RING(ring
, 0x020fffff); /* XXX */
539 OUT_PKT4(ring
, REG_A5XX_VPC_GS_SIV_CNTL
, 1);
540 OUT_RING(ring
, 0x0000ffff); /* XXX */
542 OUT_PKT4(ring
, REG_A5XX_SP_SP_CNTL
, 1);
543 OUT_RING(ring
, 0x00000010); /* XXX */
545 OUT_PKT4(ring
, REG_A5XX_GRAS_CNTL
, 1);
546 OUT_RING(ring
, COND(s
[FS
].v
->total_in
> 0, A5XX_GRAS_CNTL_VARYING
) |
547 COND(s
[FS
].v
->frag_coord
, A5XX_GRAS_CNTL_XCOORD
|
548 A5XX_GRAS_CNTL_YCOORD
|
549 A5XX_GRAS_CNTL_ZCOORD
|
550 A5XX_GRAS_CNTL_WCOORD
|
551 A5XX_GRAS_CNTL_UNK3
) |
552 COND(s
[FS
].v
->frag_face
, A5XX_GRAS_CNTL_UNK3
));
554 OUT_PKT4(ring
, REG_A5XX_RB_RENDER_CONTROL0
, 2);
555 OUT_RING(ring
, COND(s
[FS
].v
->total_in
> 0, A5XX_RB_RENDER_CONTROL0_VARYING
) |
556 COND(s
[FS
].v
->frag_coord
, A5XX_RB_RENDER_CONTROL0_XCOORD
|
557 A5XX_RB_RENDER_CONTROL0_YCOORD
|
558 A5XX_RB_RENDER_CONTROL0_ZCOORD
|
559 A5XX_RB_RENDER_CONTROL0_WCOORD
|
560 A5XX_RB_RENDER_CONTROL0_UNK3
) |
561 COND(s
[FS
].v
->frag_face
, A5XX_RB_RENDER_CONTROL0_UNK3
));
563 COND(samp_mask_regid
!= regid(63, 0),
564 A5XX_RB_RENDER_CONTROL1_SAMPLEMASK
) |
565 COND(s
[FS
].v
->frag_face
, A5XX_RB_RENDER_CONTROL1_FACENESS
) |
566 COND(samp_id_regid
!= regid(63, 0),
567 A5XX_RB_RENDER_CONTROL1_SAMPLEID
));
569 OUT_PKT4(ring
, REG_A5XX_SP_FS_OUTPUT_REG(0), 8);
570 for (i
= 0; i
< 8; i
++) {
571 OUT_RING(ring
, A5XX_SP_FS_OUTPUT_REG_REGID(color_regid
[i
]) |
572 COND(color_regid
[i
] & HALF_REG_ID
, A5XX_SP_FS_OUTPUT_REG_HALF_PRECISION
));
576 OUT_PKT4(ring
, REG_A5XX_VPC_PACK
, 1);
577 OUT_RING(ring
, A5XX_VPC_PACK_NUMNONPOSVAR(s
[FS
].v
->total_in
) |
578 A5XX_VPC_PACK_PSIZELOC(psize_loc
));
580 if (!emit
->binning_pass
) {
581 uint32_t vinterp
[8], vpsrepl
[8];
583 memset(vinterp
, 0, sizeof(vinterp
));
584 memset(vpsrepl
, 0, sizeof(vpsrepl
));
586 /* looks like we need to do int varyings in the frag
587 * shader on a5xx (no flatshad reg? or a420.0 bug?):
590 * (sy)ldlv.u32 r0.x,l[r0.x], 1
591 * ldlv.u32 r0.y,l[r0.x+1], 1
592 * (ss)bary.f (ei)r63.x, 0, r0.x
593 * (ss)(rpt1)cov.s32f16 hr0.x, (r)r0.x
595 * sam (f16)(xyzw)hr0.x, hr0.x, s#0, t#0
597 * Possibly on later a5xx variants we'll be able to use
598 * something like the code below instead of workaround
601 /* figure out VARYING_INTERP / VARYING_PS_REPL register values: */
602 for (j
= -1; (j
= ir3_next_varying(s
[FS
].v
, j
)) < (int)s
[FS
].v
->inputs_count
; ) {
603 /* NOTE: varyings are packed, so if compmask is 0xb
604 * then first, third, and fourth component occupy
605 * three consecutive varying slots:
607 unsigned compmask
= s
[FS
].v
->inputs
[j
].compmask
;
609 uint32_t inloc
= s
[FS
].v
->inputs
[j
].inloc
;
611 if ((s
[FS
].v
->inputs
[j
].interpolate
== INTERP_MODE_FLAT
) ||
612 (s
[FS
].v
->inputs
[j
].rasterflat
&& emit
->rasterflat
)) {
613 uint32_t loc
= inloc
;
615 for (i
= 0; i
< 4; i
++) {
616 if (compmask
& (1 << i
)) {
617 vinterp
[loc
/ 16] |= 1 << ((loc
% 16) * 2);
618 //flatshade[loc / 32] |= 1 << (loc % 32);
624 gl_varying_slot slot
= s
[FS
].v
->inputs
[j
].slot
;
626 /* since we don't enable PIPE_CAP_TGSI_TEXCOORD: */
627 if (slot
>= VARYING_SLOT_VAR0
) {
628 unsigned texmask
= 1 << (slot
- VARYING_SLOT_VAR0
);
629 /* Replace the .xy coordinates with S/T from the point sprite. Set
630 * interpolation bits for .zw such that they become .01
632 if (emit
->sprite_coord_enable
& texmask
) {
633 /* mask is two 2-bit fields, where:
636 * '11' -> 1 - T (flip mode)
638 unsigned mask
= emit
->sprite_coord_mode
? 0b1101 : 0b1001;
639 uint32_t loc
= inloc
;
640 if (compmask
& 0x1) {
641 vpsrepl
[loc
/ 16] |= ((mask
>> 0) & 0x3) << ((loc
% 16) * 2);
644 if (compmask
& 0x2) {
645 vpsrepl
[loc
/ 16] |= ((mask
>> 2) & 0x3) << ((loc
% 16) * 2);
648 if (compmask
& 0x4) {
650 vinterp
[loc
/ 16] |= 0b10 << ((loc
% 16) * 2);
653 if (compmask
& 0x8) {
655 vinterp
[loc
/ 16] |= 0b11 << ((loc
% 16) * 2);
662 OUT_PKT4(ring
, REG_A5XX_VPC_VARYING_INTERP_MODE(0), 8);
663 for (i
= 0; i
< 8; i
++)
664 OUT_RING(ring
, vinterp
[i
]); /* VPC_VARYING_INTERP[i].MODE */
666 OUT_PKT4(ring
, REG_A5XX_VPC_VARYING_PS_REPL_MODE(0), 8);
667 for (i
= 0; i
< 8; i
++)
668 OUT_RING(ring
, vpsrepl
[i
]); /* VPC_VARYING_PS_REPL[i] */
671 if (!emit
->binning_pass
)
673 fd5_emit_shader(ring
, s
[FS
].v
);
675 OUT_PKT4(ring
, REG_A5XX_VFD_CONTROL_1
, 5);
676 OUT_RING(ring
, A5XX_VFD_CONTROL_1_REGID4VTX(vertex_regid
) |
677 A5XX_VFD_CONTROL_1_REGID4INST(instance_regid
) |
679 OUT_RING(ring
, 0x0000fcfc); /* VFD_CONTROL_2 */
680 OUT_RING(ring
, 0x0000fcfc); /* VFD_CONTROL_3 */
681 OUT_RING(ring
, 0x000000fc); /* VFD_CONTROL_4 */
682 OUT_RING(ring
, 0x00000000); /* VFD_CONTROL_5 */
686 fd5_prog_init(struct pipe_context
*pctx
)