2 * Copyright © 2016 Broadcom
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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 #include "util/u_format.h"
26 #include "util/u_math.h"
27 #include "util/u_memory.h"
28 #include "util/ralloc.h"
29 #include "util/hash_table.h"
30 #include "compiler/nir/nir.h"
31 #include "compiler/nir/nir_builder.h"
32 #include "common/v3d_device_info.h"
33 #include "v3d_compiler.h"
35 /* We don't do any address packing. */
36 #define __gen_user_data void
37 #define __gen_address_type uint32_t
38 #define __gen_address_offset(reloc) (*reloc)
39 #define __gen_emit_reloc(cl, reloc)
40 #include "cle/v3d_packet_v41_pack.h"
42 #define GENERAL_TMU_LOOKUP_PER_QUAD (0 << 7)
43 #define GENERAL_TMU_LOOKUP_PER_PIXEL (1 << 7)
44 #define GENERAL_TMU_LOOKUP_TYPE_8BIT_I (0 << 0)
45 #define GENERAL_TMU_LOOKUP_TYPE_16BIT_I (1 << 0)
46 #define GENERAL_TMU_LOOKUP_TYPE_VEC2 (2 << 0)
47 #define GENERAL_TMU_LOOKUP_TYPE_VEC3 (3 << 0)
48 #define GENERAL_TMU_LOOKUP_TYPE_VEC4 (4 << 0)
49 #define GENERAL_TMU_LOOKUP_TYPE_8BIT_UI (5 << 0)
50 #define GENERAL_TMU_LOOKUP_TYPE_16BIT_UI (6 << 0)
51 #define GENERAL_TMU_LOOKUP_TYPE_32BIT_UI (7 << 0)
53 #define V3D_TSY_SET_QUORUM 0
54 #define V3D_TSY_INC_WAITERS 1
55 #define V3D_TSY_DEC_WAITERS 2
56 #define V3D_TSY_INC_QUORUM 3
57 #define V3D_TSY_DEC_QUORUM 4
58 #define V3D_TSY_FREE_ALL 5
59 #define V3D_TSY_RELEASE 6
60 #define V3D_TSY_ACQUIRE 7
61 #define V3D_TSY_WAIT 8
62 #define V3D_TSY_WAIT_INC 9
63 #define V3D_TSY_WAIT_CHECK 10
64 #define V3D_TSY_WAIT_INC_CHECK 11
65 #define V3D_TSY_WAIT_CV 12
66 #define V3D_TSY_INC_SEMAPHORE 13
67 #define V3D_TSY_DEC_SEMAPHORE 14
68 #define V3D_TSY_SET_QUORUM_FREE_ALL 15
71 ntq_emit_cf_list(struct v3d_compile
*c
, struct exec_list
*list
);
74 resize_qreg_array(struct v3d_compile
*c
,
79 if (*size
>= decl_size
)
82 uint32_t old_size
= *size
;
83 *size
= MAX2(*size
* 2, decl_size
);
84 *regs
= reralloc(c
, *regs
, struct qreg
, *size
);
86 fprintf(stderr
, "Malloc failure\n");
90 for (uint32_t i
= old_size
; i
< *size
; i
++)
91 (*regs
)[i
] = c
->undef
;
95 vir_emit_thrsw(struct v3d_compile
*c
)
100 /* Always thread switch after each texture operation for now.
102 * We could do better by batching a bunch of texture fetches up and
103 * then doing one thread switch and collecting all their results
106 c
->last_thrsw
= vir_NOP(c
);
107 c
->last_thrsw
->qpu
.sig
.thrsw
= true;
108 c
->last_thrsw_at_top_level
= !c
->in_control_flow
;
110 /* We need to lock the scoreboard before any tlb acess happens. If this
111 * thread switch comes after we have emitted a tlb load, then it means
112 * that we can't lock on the last thread switch any more.
114 if (c
->emitted_tlb_load
)
115 c
->lock_scoreboard_on_first_thrsw
= true;
119 v3d_general_tmu_op(nir_intrinsic_instr
*instr
)
121 switch (instr
->intrinsic
) {
122 case nir_intrinsic_load_ssbo
:
123 case nir_intrinsic_load_ubo
:
124 case nir_intrinsic_load_uniform
:
125 case nir_intrinsic_load_shared
:
126 case nir_intrinsic_load_scratch
:
127 case nir_intrinsic_store_ssbo
:
128 case nir_intrinsic_store_shared
:
129 case nir_intrinsic_store_scratch
:
130 return V3D_TMU_OP_REGULAR
;
131 case nir_intrinsic_ssbo_atomic_add
:
132 case nir_intrinsic_shared_atomic_add
:
133 return V3D_TMU_OP_WRITE_ADD_READ_PREFETCH
;
134 case nir_intrinsic_ssbo_atomic_imin
:
135 case nir_intrinsic_shared_atomic_imin
:
136 return V3D_TMU_OP_WRITE_SMIN
;
137 case nir_intrinsic_ssbo_atomic_umin
:
138 case nir_intrinsic_shared_atomic_umin
:
139 return V3D_TMU_OP_WRITE_UMIN_FULL_L1_CLEAR
;
140 case nir_intrinsic_ssbo_atomic_imax
:
141 case nir_intrinsic_shared_atomic_imax
:
142 return V3D_TMU_OP_WRITE_SMAX
;
143 case nir_intrinsic_ssbo_atomic_umax
:
144 case nir_intrinsic_shared_atomic_umax
:
145 return V3D_TMU_OP_WRITE_UMAX
;
146 case nir_intrinsic_ssbo_atomic_and
:
147 case nir_intrinsic_shared_atomic_and
:
148 return V3D_TMU_OP_WRITE_AND_READ_INC
;
149 case nir_intrinsic_ssbo_atomic_or
:
150 case nir_intrinsic_shared_atomic_or
:
151 return V3D_TMU_OP_WRITE_OR_READ_DEC
;
152 case nir_intrinsic_ssbo_atomic_xor
:
153 case nir_intrinsic_shared_atomic_xor
:
154 return V3D_TMU_OP_WRITE_XOR_READ_NOT
;
155 case nir_intrinsic_ssbo_atomic_exchange
:
156 case nir_intrinsic_shared_atomic_exchange
:
157 return V3D_TMU_OP_WRITE_XCHG_READ_FLUSH
;
158 case nir_intrinsic_ssbo_atomic_comp_swap
:
159 case nir_intrinsic_shared_atomic_comp_swap
:
160 return V3D_TMU_OP_WRITE_CMPXCHG_READ_FLUSH
;
162 unreachable("unknown intrinsic op");
167 * Implements indirect uniform loads and SSBO accesses through the TMU general
168 * memory access interface.
171 ntq_emit_tmu_general(struct v3d_compile
*c
, nir_intrinsic_instr
*instr
,
172 bool is_shared_or_scratch
)
174 /* XXX perf: We should turn add/sub of 1 to inc/dec. Perhaps NIR
175 * wants to have support for inc/dec?
178 uint32_t tmu_op
= v3d_general_tmu_op(instr
);
179 bool is_store
= (instr
->intrinsic
== nir_intrinsic_store_ssbo
||
180 instr
->intrinsic
== nir_intrinsic_store_scratch
||
181 instr
->intrinsic
== nir_intrinsic_store_shared
);
182 bool has_index
= !is_shared_or_scratch
;
185 int tmu_writes
= 1; /* address */
186 if (instr
->intrinsic
== nir_intrinsic_load_uniform
) {
188 } else if (instr
->intrinsic
== nir_intrinsic_load_ssbo
||
189 instr
->intrinsic
== nir_intrinsic_load_ubo
||
190 instr
->intrinsic
== nir_intrinsic_load_scratch
||
191 instr
->intrinsic
== nir_intrinsic_load_shared
) {
192 offset_src
= 0 + has_index
;
193 } else if (is_store
) {
194 offset_src
= 1 + has_index
;
195 for (int i
= 0; i
< instr
->num_components
; i
++) {
197 vir_reg(QFILE_MAGIC
, V3D_QPU_WADDR_TMUD
),
198 ntq_get_src(c
, instr
->src
[0], i
));
202 offset_src
= 0 + has_index
;
204 vir_reg(QFILE_MAGIC
, V3D_QPU_WADDR_TMUD
),
205 ntq_get_src(c
, instr
->src
[1 + has_index
], 0));
207 if (tmu_op
== V3D_TMU_OP_WRITE_CMPXCHG_READ_FLUSH
) {
209 vir_reg(QFILE_MAGIC
, V3D_QPU_WADDR_TMUD
),
210 ntq_get_src(c
, instr
->src
[2 + has_index
],
216 bool dynamic_src
= !nir_src_is_const(instr
->src
[offset_src
]);
217 uint32_t const_offset
= 0;
219 const_offset
= nir_src_as_uint(instr
->src
[offset_src
]);
221 /* Make sure we won't exceed the 16-entry TMU fifo if each thread is
222 * storing at the same time.
224 while (tmu_writes
> 16 / c
->threads
)
228 if (instr
->intrinsic
== nir_intrinsic_load_uniform
) {
229 const_offset
+= nir_intrinsic_base(instr
);
230 offset
= vir_uniform(c
, QUNIFORM_UBO_ADDR
,
231 v3d_unit_data_create(0, const_offset
));
233 } else if (instr
->intrinsic
== nir_intrinsic_load_ubo
) {
234 uint32_t index
= nir_src_as_uint(instr
->src
[0]) + 1;
235 /* Note that QUNIFORM_UBO_ADDR takes a UBO index shifted up by
236 * 1 (0 is gallium's constant buffer 0).
238 offset
= vir_uniform(c
, QUNIFORM_UBO_ADDR
,
239 v3d_unit_data_create(index
, const_offset
));
241 } else if (is_shared_or_scratch
) {
242 /* Shared and scratch variables have no buffer index, and all
243 * start from a common base that we set up at the start of
246 if (instr
->intrinsic
== nir_intrinsic_load_scratch
||
247 instr
->intrinsic
== nir_intrinsic_store_scratch
) {
248 offset
= c
->spill_base
;
250 offset
= c
->cs_shared_offset
;
251 const_offset
+= nir_intrinsic_base(instr
);
254 offset
= vir_uniform(c
, QUNIFORM_SSBO_OFFSET
,
255 nir_src_as_uint(instr
->src
[is_store
?
259 /* The spec says that for atomics, the TYPE field is ignored, but that
260 * doesn't seem to be the case for CMPXCHG. Just use the number of
261 * tmud writes we did to decide the type (or choose "32bit" for atomic
262 * reads, which has been fine).
265 if (tmu_op
== V3D_TMU_OP_WRITE_CMPXCHG_READ_FLUSH
)
268 num_components
= instr
->num_components
;
270 uint32_t config
= (0xffffff00 |
272 GENERAL_TMU_LOOKUP_PER_PIXEL
);
273 if (num_components
== 1) {
274 config
|= GENERAL_TMU_LOOKUP_TYPE_32BIT_UI
;
276 config
|= GENERAL_TMU_LOOKUP_TYPE_VEC2
+ num_components
- 2;
279 if (vir_in_nonuniform_control_flow(c
)) {
280 vir_set_pf(vir_MOV_dest(c
, vir_nop_reg(), c
->execute
),
286 tmua
= vir_reg(QFILE_MAGIC
, V3D_QPU_WADDR_TMUA
);
288 tmua
= vir_reg(QFILE_MAGIC
, V3D_QPU_WADDR_TMUAU
);
292 if (const_offset
!= 0) {
293 offset
= vir_ADD(c
, offset
,
294 vir_uniform_ui(c
, const_offset
));
296 tmu
= vir_ADD_dest(c
, tmua
, offset
,
297 ntq_get_src(c
, instr
->src
[offset_src
], 0));
299 if (const_offset
!= 0) {
300 tmu
= vir_ADD_dest(c
, tmua
, offset
,
301 vir_uniform_ui(c
, const_offset
));
303 tmu
= vir_MOV_dest(c
, tmua
, offset
);
308 tmu
->uniform
= vir_get_uniform_index(c
, QUNIFORM_CONSTANT
,
312 if (vir_in_nonuniform_control_flow(c
))
313 vir_set_cond(tmu
, V3D_QPU_COND_IFA
);
317 /* Read the result, or wait for the TMU op to complete. */
318 for (int i
= 0; i
< nir_intrinsic_dest_components(instr
); i
++)
319 ntq_store_dest(c
, &instr
->dest
, i
, vir_MOV(c
, vir_LDTMU(c
)));
321 if (nir_intrinsic_dest_components(instr
) == 0)
326 ntq_init_ssa_def(struct v3d_compile
*c
, nir_ssa_def
*def
)
328 struct qreg
*qregs
= ralloc_array(c
->def_ht
, struct qreg
,
329 def
->num_components
);
330 _mesa_hash_table_insert(c
->def_ht
, def
, qregs
);
335 * This function is responsible for getting VIR results into the associated
336 * storage for a NIR instruction.
338 * If it's a NIR SSA def, then we just set the associated hash table entry to
341 * If it's a NIR reg, then we need to update the existing qreg assigned to the
342 * NIR destination with the incoming value. To do that without introducing
343 * new MOVs, we require that the incoming qreg either be a uniform, or be
344 * SSA-defined by the previous VIR instruction in the block and rewritable by
345 * this function. That lets us sneak ahead and insert the SF flag beforehand
346 * (knowing that the previous instruction doesn't depend on flags) and rewrite
347 * its destination to be the NIR reg's destination
350 ntq_store_dest(struct v3d_compile
*c
, nir_dest
*dest
, int chan
,
353 struct qinst
*last_inst
= NULL
;
354 if (!list_empty(&c
->cur_block
->instructions
))
355 last_inst
= (struct qinst
*)c
->cur_block
->instructions
.prev
;
357 assert((result
.file
== QFILE_TEMP
&&
358 last_inst
&& last_inst
== c
->defs
[result
.index
]));
361 assert(chan
< dest
->ssa
.num_components
);
364 struct hash_entry
*entry
=
365 _mesa_hash_table_search(c
->def_ht
, &dest
->ssa
);
370 qregs
= ntq_init_ssa_def(c
, &dest
->ssa
);
372 qregs
[chan
] = result
;
374 nir_register
*reg
= dest
->reg
.reg
;
375 assert(dest
->reg
.base_offset
== 0);
376 assert(reg
->num_array_elems
== 0);
377 struct hash_entry
*entry
=
378 _mesa_hash_table_search(c
->def_ht
, reg
);
379 struct qreg
*qregs
= entry
->data
;
381 /* Insert a MOV if the source wasn't an SSA def in the
382 * previous instruction.
384 if ((vir_in_nonuniform_control_flow(c
) &&
385 c
->defs
[last_inst
->dst
.index
]->qpu
.sig
.ldunif
)) {
386 result
= vir_MOV(c
, result
);
387 last_inst
= c
->defs
[result
.index
];
390 /* We know they're both temps, so just rewrite index. */
391 c
->defs
[last_inst
->dst
.index
] = NULL
;
392 last_inst
->dst
.index
= qregs
[chan
].index
;
394 /* If we're in control flow, then make this update of the reg
395 * conditional on the execution mask.
397 if (vir_in_nonuniform_control_flow(c
)) {
398 last_inst
->dst
.index
= qregs
[chan
].index
;
400 /* Set the flags to the current exec mask.
402 c
->cursor
= vir_before_inst(last_inst
);
403 vir_set_pf(vir_MOV_dest(c
, vir_nop_reg(), c
->execute
),
405 c
->cursor
= vir_after_inst(last_inst
);
407 vir_set_cond(last_inst
, V3D_QPU_COND_IFA
);
413 ntq_get_src(struct v3d_compile
*c
, nir_src src
, int i
)
415 struct hash_entry
*entry
;
417 entry
= _mesa_hash_table_search(c
->def_ht
, src
.ssa
);
418 assert(i
< src
.ssa
->num_components
);
420 nir_register
*reg
= src
.reg
.reg
;
421 entry
= _mesa_hash_table_search(c
->def_ht
, reg
);
422 assert(reg
->num_array_elems
== 0);
423 assert(src
.reg
.base_offset
== 0);
424 assert(i
< reg
->num_components
);
427 struct qreg
*qregs
= entry
->data
;
432 ntq_get_alu_src(struct v3d_compile
*c
, nir_alu_instr
*instr
,
435 assert(util_is_power_of_two_or_zero(instr
->dest
.write_mask
));
436 unsigned chan
= ffs(instr
->dest
.write_mask
) - 1;
437 struct qreg r
= ntq_get_src(c
, instr
->src
[src
].src
,
438 instr
->src
[src
].swizzle
[chan
]);
440 assert(!instr
->src
[src
].abs
);
441 assert(!instr
->src
[src
].negate
);
447 ntq_minify(struct v3d_compile
*c
, struct qreg size
, struct qreg level
)
449 return vir_MAX(c
, vir_SHR(c
, size
, level
), vir_uniform_ui(c
, 1));
453 ntq_emit_txs(struct v3d_compile
*c
, nir_tex_instr
*instr
)
455 unsigned unit
= instr
->texture_index
;
456 int lod_index
= nir_tex_instr_src_index(instr
, nir_tex_src_lod
);
457 int dest_size
= nir_tex_instr_dest_size(instr
);
459 struct qreg lod
= c
->undef
;
461 lod
= ntq_get_src(c
, instr
->src
[lod_index
].src
, 0);
463 for (int i
= 0; i
< dest_size
; i
++) {
465 enum quniform_contents contents
;
467 if (instr
->is_array
&& i
== dest_size
- 1)
468 contents
= QUNIFORM_TEXTURE_ARRAY_SIZE
;
470 contents
= QUNIFORM_TEXTURE_WIDTH
+ i
;
472 struct qreg size
= vir_uniform(c
, contents
, unit
);
474 switch (instr
->sampler_dim
) {
475 case GLSL_SAMPLER_DIM_1D
:
476 case GLSL_SAMPLER_DIM_2D
:
477 case GLSL_SAMPLER_DIM_MS
:
478 case GLSL_SAMPLER_DIM_3D
:
479 case GLSL_SAMPLER_DIM_CUBE
:
480 /* Don't minify the array size. */
481 if (!(instr
->is_array
&& i
== dest_size
- 1)) {
482 size
= ntq_minify(c
, size
, lod
);
486 case GLSL_SAMPLER_DIM_RECT
:
487 /* There's no LOD field for rects */
491 unreachable("Bad sampler type");
494 ntq_store_dest(c
, &instr
->dest
, i
, size
);
499 ntq_emit_tex(struct v3d_compile
*c
, nir_tex_instr
*instr
)
501 unsigned unit
= instr
->texture_index
;
503 /* Since each texture sampling op requires uploading uniforms to
504 * reference the texture, there's no HW support for texture size and
505 * you just upload uniforms containing the size.
508 case nir_texop_query_levels
:
509 ntq_store_dest(c
, &instr
->dest
, 0,
510 vir_uniform(c
, QUNIFORM_TEXTURE_LEVELS
, unit
));
513 ntq_emit_txs(c
, instr
);
519 if (c
->devinfo
->ver
>= 40)
520 v3d40_vir_emit_tex(c
, instr
);
522 v3d33_vir_emit_tex(c
, instr
);
526 ntq_fsincos(struct v3d_compile
*c
, struct qreg src
, bool is_cos
)
528 struct qreg input
= vir_FMUL(c
, src
, vir_uniform_f(c
, 1.0f
/ M_PI
));
530 input
= vir_FADD(c
, input
, vir_uniform_f(c
, 0.5));
532 struct qreg periods
= vir_FROUND(c
, input
);
533 struct qreg sin_output
= vir_SIN(c
, vir_FSUB(c
, input
, periods
));
534 return vir_XOR(c
, sin_output
, vir_SHL(c
,
535 vir_FTOIN(c
, periods
),
536 vir_uniform_ui(c
, -1)));
540 ntq_fsign(struct v3d_compile
*c
, struct qreg src
)
542 struct qreg t
= vir_get_temp(c
);
544 vir_MOV_dest(c
, t
, vir_uniform_f(c
, 0.0));
545 vir_set_pf(vir_FMOV_dest(c
, vir_nop_reg(), src
), V3D_QPU_PF_PUSHZ
);
546 vir_MOV_cond(c
, V3D_QPU_COND_IFNA
, t
, vir_uniform_f(c
, 1.0));
547 vir_set_pf(vir_FMOV_dest(c
, vir_nop_reg(), src
), V3D_QPU_PF_PUSHN
);
548 vir_MOV_cond(c
, V3D_QPU_COND_IFA
, t
, vir_uniform_f(c
, -1.0));
549 return vir_MOV(c
, t
);
553 emit_fragcoord_input(struct v3d_compile
*c
, int attr
)
555 c
->inputs
[attr
* 4 + 0] = vir_FXCD(c
);
556 c
->inputs
[attr
* 4 + 1] = vir_FYCD(c
);
557 c
->inputs
[attr
* 4 + 2] = c
->payload_z
;
558 c
->inputs
[attr
* 4 + 3] = vir_RECIP(c
, c
->payload_w
);
562 emit_fragment_varying(struct v3d_compile
*c
, nir_variable
*var
,
563 uint8_t swizzle
, int array_index
)
565 struct qreg r3
= vir_reg(QFILE_MAGIC
, V3D_QPU_WADDR_R3
);
566 struct qreg r5
= vir_reg(QFILE_MAGIC
, V3D_QPU_WADDR_R5
);
569 if (c
->devinfo
->ver
>= 41) {
570 struct qinst
*ldvary
= vir_add_inst(V3D_QPU_A_NOP
, c
->undef
,
572 ldvary
->qpu
.sig
.ldvary
= true;
573 vary
= vir_emit_def(c
, ldvary
);
575 vir_NOP(c
)->qpu
.sig
.ldvary
= true;
579 /* For gl_PointCoord input or distance along a line, we'll be called
580 * with no nir_variable, and we don't count toward VPM size so we
581 * don't track an input slot.
584 return vir_FADD(c
, vir_FMUL(c
, vary
, c
->payload_w
), r5
);
587 int i
= c
->num_inputs
++;
589 v3d_slot_from_slot_and_component(var
->data
.location
+
590 array_index
, swizzle
);
592 switch (var
->data
.interpolation
) {
593 case INTERP_MODE_NONE
:
594 /* If a gl_FrontColor or gl_BackColor input has no interp
595 * qualifier, then if we're using glShadeModel(GL_FLAT) it
596 * needs to be flat shaded.
598 switch (var
->data
.location
+ array_index
) {
599 case VARYING_SLOT_COL0
:
600 case VARYING_SLOT_COL1
:
601 case VARYING_SLOT_BFC0
:
602 case VARYING_SLOT_BFC1
:
603 if (c
->fs_key
->shade_model_flat
) {
604 BITSET_SET(c
->flat_shade_flags
, i
);
605 vir_MOV_dest(c
, c
->undef
, vary
);
606 return vir_MOV(c
, r5
);
608 return vir_FADD(c
, vir_FMUL(c
, vary
,
615 case INTERP_MODE_SMOOTH
:
616 if (var
->data
.centroid
) {
617 BITSET_SET(c
->centroid_flags
, i
);
618 return vir_FADD(c
, vir_FMUL(c
, vary
,
619 c
->payload_w_centroid
), r5
);
621 return vir_FADD(c
, vir_FMUL(c
, vary
, c
->payload_w
), r5
);
623 case INTERP_MODE_NOPERSPECTIVE
:
624 BITSET_SET(c
->noperspective_flags
, i
);
625 return vir_FADD(c
, vir_MOV(c
, vary
), r5
);
626 case INTERP_MODE_FLAT
:
627 BITSET_SET(c
->flat_shade_flags
, i
);
628 vir_MOV_dest(c
, c
->undef
, vary
);
629 return vir_MOV(c
, r5
);
631 unreachable("Bad interp mode");
636 emit_fragment_input(struct v3d_compile
*c
, int attr
, nir_variable
*var
,
639 for (int i
= 0; i
< glsl_get_vector_elements(var
->type
); i
++) {
640 int chan
= var
->data
.location_frac
+ i
;
641 c
->inputs
[attr
* 4 + chan
] =
642 emit_fragment_varying(c
, var
, chan
, array_index
);
647 add_output(struct v3d_compile
*c
,
648 uint32_t decl_offset
,
652 uint32_t old_array_size
= c
->outputs_array_size
;
653 resize_qreg_array(c
, &c
->outputs
, &c
->outputs_array_size
,
656 if (old_array_size
!= c
->outputs_array_size
) {
657 c
->output_slots
= reralloc(c
,
659 struct v3d_varying_slot
,
660 c
->outputs_array_size
);
663 c
->output_slots
[decl_offset
] =
664 v3d_slot_from_slot_and_component(slot
, swizzle
);
668 * If compare_instr is a valid comparison instruction, emits the
669 * compare_instr's comparison and returns the sel_instr's return value based
670 * on the compare_instr's result.
673 ntq_emit_comparison(struct v3d_compile
*c
,
674 nir_alu_instr
*compare_instr
,
675 enum v3d_qpu_cond
*out_cond
)
677 struct qreg src0
= ntq_get_alu_src(c
, compare_instr
, 0);
679 if (nir_op_infos
[compare_instr
->op
].num_inputs
> 1)
680 src1
= ntq_get_alu_src(c
, compare_instr
, 1);
681 bool cond_invert
= false;
682 struct qreg nop
= vir_nop_reg();
684 switch (compare_instr
->op
) {
687 vir_set_pf(vir_FCMP_dest(c
, nop
, src0
, src1
), V3D_QPU_PF_PUSHZ
);
690 vir_set_pf(vir_XOR_dest(c
, nop
, src0
, src1
), V3D_QPU_PF_PUSHZ
);
695 vir_set_pf(vir_FCMP_dest(c
, nop
, src0
, src1
), V3D_QPU_PF_PUSHZ
);
699 vir_set_pf(vir_XOR_dest(c
, nop
, src0
, src1
), V3D_QPU_PF_PUSHZ
);
705 vir_set_pf(vir_FCMP_dest(c
, nop
, src1
, src0
), V3D_QPU_PF_PUSHC
);
708 vir_set_pf(vir_MIN_dest(c
, nop
, src1
, src0
), V3D_QPU_PF_PUSHC
);
712 vir_set_pf(vir_SUB_dest(c
, nop
, src0
, src1
), V3D_QPU_PF_PUSHC
);
718 vir_set_pf(vir_FCMP_dest(c
, nop
, src0
, src1
), V3D_QPU_PF_PUSHN
);
721 vir_set_pf(vir_MIN_dest(c
, nop
, src1
, src0
), V3D_QPU_PF_PUSHC
);
724 vir_set_pf(vir_SUB_dest(c
, nop
, src0
, src1
), V3D_QPU_PF_PUSHC
);
728 vir_set_pf(vir_MOV_dest(c
, nop
, src0
), V3D_QPU_PF_PUSHZ
);
733 vir_set_pf(vir_FMOV_dest(c
, nop
, src0
), V3D_QPU_PF_PUSHZ
);
741 *out_cond
= cond_invert
? V3D_QPU_COND_IFNA
: V3D_QPU_COND_IFA
;
746 /* Finds an ALU instruction that generates our src value that could
747 * (potentially) be greedily emitted in the consuming instruction.
749 static struct nir_alu_instr
*
750 ntq_get_alu_parent(nir_src src
)
752 if (!src
.is_ssa
|| src
.ssa
->parent_instr
->type
!= nir_instr_type_alu
)
754 nir_alu_instr
*instr
= nir_instr_as_alu(src
.ssa
->parent_instr
);
758 /* If the ALU instr's srcs are non-SSA, then we would have to avoid
759 * moving emission of the ALU instr down past another write of the
762 for (int i
= 0; i
< nir_op_infos
[instr
->op
].num_inputs
; i
++) {
763 if (!instr
->src
[i
].src
.is_ssa
)
770 /* Turns a NIR bool into a condition code to predicate on. */
771 static enum v3d_qpu_cond
772 ntq_emit_bool_to_cond(struct v3d_compile
*c
, nir_src src
)
774 nir_alu_instr
*compare
= ntq_get_alu_parent(src
);
778 enum v3d_qpu_cond cond
;
779 if (ntq_emit_comparison(c
, compare
, &cond
))
783 vir_set_pf(vir_MOV_dest(c
, vir_nop_reg(), ntq_get_src(c
, src
, 0)),
785 return V3D_QPU_COND_IFNA
;
789 ntq_emit_alu(struct v3d_compile
*c
, nir_alu_instr
*instr
)
791 /* This should always be lowered to ALU operations for V3D. */
792 assert(!instr
->dest
.saturate
);
794 /* Vectors are special in that they have non-scalarized writemasks,
795 * and just take the first swizzle channel for each argument in order
796 * into each writemask channel.
798 if (instr
->op
== nir_op_vec2
||
799 instr
->op
== nir_op_vec3
||
800 instr
->op
== nir_op_vec4
) {
802 for (int i
= 0; i
< nir_op_infos
[instr
->op
].num_inputs
; i
++)
803 srcs
[i
] = ntq_get_src(c
, instr
->src
[i
].src
,
804 instr
->src
[i
].swizzle
[0]);
805 for (int i
= 0; i
< nir_op_infos
[instr
->op
].num_inputs
; i
++)
806 ntq_store_dest(c
, &instr
->dest
.dest
, i
,
807 vir_MOV(c
, srcs
[i
]));
811 /* General case: We can just grab the one used channel per src. */
812 struct qreg src
[nir_op_infos
[instr
->op
].num_inputs
];
813 for (int i
= 0; i
< nir_op_infos
[instr
->op
].num_inputs
; i
++) {
814 src
[i
] = ntq_get_alu_src(c
, instr
, i
);
821 result
= vir_MOV(c
, src
[0]);
825 result
= vir_XOR(c
, src
[0], vir_uniform_ui(c
, 1 << 31));
828 result
= vir_NEG(c
, src
[0]);
832 result
= vir_FMUL(c
, src
[0], src
[1]);
835 result
= vir_FADD(c
, src
[0], src
[1]);
838 result
= vir_FSUB(c
, src
[0], src
[1]);
841 result
= vir_FMIN(c
, src
[0], src
[1]);
844 result
= vir_FMAX(c
, src
[0], src
[1]);
848 nir_alu_instr
*src0_alu
= ntq_get_alu_parent(instr
->src
[0].src
);
849 if (src0_alu
&& src0_alu
->op
== nir_op_fround_even
) {
850 result
= vir_FTOIN(c
, ntq_get_alu_src(c
, src0_alu
, 0));
852 result
= vir_FTOIZ(c
, src
[0]);
858 result
= vir_FTOUZ(c
, src
[0]);
861 result
= vir_ITOF(c
, src
[0]);
864 result
= vir_UTOF(c
, src
[0]);
867 result
= vir_AND(c
, src
[0], vir_uniform_f(c
, 1.0));
870 result
= vir_AND(c
, src
[0], vir_uniform_ui(c
, 1));
874 result
= vir_ADD(c
, src
[0], src
[1]);
877 result
= vir_SHR(c
, src
[0], src
[1]);
880 result
= vir_SUB(c
, src
[0], src
[1]);
883 result
= vir_ASR(c
, src
[0], src
[1]);
886 result
= vir_SHL(c
, src
[0], src
[1]);
889 result
= vir_MIN(c
, src
[0], src
[1]);
892 result
= vir_UMIN(c
, src
[0], src
[1]);
895 result
= vir_MAX(c
, src
[0], src
[1]);
898 result
= vir_UMAX(c
, src
[0], src
[1]);
901 result
= vir_AND(c
, src
[0], src
[1]);
904 result
= vir_OR(c
, src
[0], src
[1]);
907 result
= vir_XOR(c
, src
[0], src
[1]);
910 result
= vir_NOT(c
, src
[0]);
913 case nir_op_ufind_msb
:
914 result
= vir_SUB(c
, vir_uniform_ui(c
, 31), vir_CLZ(c
, src
[0]));
918 result
= vir_UMUL(c
, src
[0], src
[1]);
925 enum v3d_qpu_cond cond
;
926 MAYBE_UNUSED
bool ok
= ntq_emit_comparison(c
, instr
, &cond
);
928 result
= vir_MOV(c
, vir_SEL(c
, cond
,
929 vir_uniform_f(c
, 1.0),
930 vir_uniform_f(c
, 0.0)));
946 enum v3d_qpu_cond cond
;
947 MAYBE_UNUSED
bool ok
= ntq_emit_comparison(c
, instr
, &cond
);
949 result
= vir_MOV(c
, vir_SEL(c
, cond
,
950 vir_uniform_ui(c
, ~0),
951 vir_uniform_ui(c
, 0)));
958 ntq_emit_bool_to_cond(c
, instr
->src
[0].src
),
963 vir_set_pf(vir_MOV_dest(c
, vir_nop_reg(), src
[0]),
965 result
= vir_MOV(c
, vir_SEL(c
, V3D_QPU_COND_IFNA
,
970 result
= vir_RECIP(c
, src
[0]);
973 result
= vir_RSQRT(c
, src
[0]);
976 result
= vir_EXP(c
, src
[0]);
979 result
= vir_LOG(c
, src
[0]);
983 result
= vir_FCEIL(c
, src
[0]);
986 result
= vir_FFLOOR(c
, src
[0]);
988 case nir_op_fround_even
:
989 result
= vir_FROUND(c
, src
[0]);
992 result
= vir_FTRUNC(c
, src
[0]);
996 result
= ntq_fsincos(c
, src
[0], false);
999 result
= ntq_fsincos(c
, src
[0], true);
1003 result
= ntq_fsign(c
, src
[0]);
1007 result
= vir_FMOV(c
, src
[0]);
1008 vir_set_unpack(c
->defs
[result
.index
], 0, V3D_QPU_UNPACK_ABS
);
1013 result
= vir_MAX(c
, src
[0], vir_NEG(c
, src
[0]));
1017 case nir_op_fddx_coarse
:
1018 case nir_op_fddx_fine
:
1019 result
= vir_FDX(c
, src
[0]);
1023 case nir_op_fddy_coarse
:
1024 case nir_op_fddy_fine
:
1025 result
= vir_FDY(c
, src
[0]);
1028 case nir_op_uadd_carry
:
1029 vir_set_pf(vir_ADD_dest(c
, vir_nop_reg(), src
[0], src
[1]),
1031 result
= vir_MOV(c
, vir_SEL(c
, V3D_QPU_COND_IFA
,
1032 vir_uniform_ui(c
, ~0),
1033 vir_uniform_ui(c
, 0)));
1036 case nir_op_pack_half_2x16_split
:
1037 result
= vir_VFPACK(c
, src
[0], src
[1]);
1040 case nir_op_unpack_half_2x16_split_x
:
1041 result
= vir_FMOV(c
, src
[0]);
1042 vir_set_unpack(c
->defs
[result
.index
], 0, V3D_QPU_UNPACK_L
);
1045 case nir_op_unpack_half_2x16_split_y
:
1046 result
= vir_FMOV(c
, src
[0]);
1047 vir_set_unpack(c
->defs
[result
.index
], 0, V3D_QPU_UNPACK_H
);
1051 fprintf(stderr
, "unknown NIR ALU inst: ");
1052 nir_print_instr(&instr
->instr
, stderr
);
1053 fprintf(stderr
, "\n");
1057 /* We have a scalar result, so the instruction should only have a
1058 * single channel written to.
1060 assert(util_is_power_of_two_or_zero(instr
->dest
.write_mask
));
1061 ntq_store_dest(c
, &instr
->dest
.dest
,
1062 ffs(instr
->dest
.write_mask
) - 1, result
);
1065 /* Each TLB read/write setup (a render target or depth buffer) takes an 8-bit
1066 * specifier. They come from a register that's preloaded with 0xffffffff
1067 * (0xff gets you normal vec4 f16 RT0 writes), and when one is neaded the low
1068 * 8 bits are shifted off the bottom and 0xff shifted in from the top.
1070 #define TLB_TYPE_F16_COLOR (3 << 6)
1071 #define TLB_TYPE_I32_COLOR (1 << 6)
1072 #define TLB_TYPE_F32_COLOR (0 << 6)
1073 #define TLB_RENDER_TARGET_SHIFT 3 /* Reversed! 7 = RT 0, 0 = RT 7. */
1074 #define TLB_SAMPLE_MODE_PER_SAMPLE (0 << 2)
1075 #define TLB_SAMPLE_MODE_PER_PIXEL (1 << 2)
1076 #define TLB_F16_SWAP_HI_LO (1 << 1)
1077 #define TLB_VEC_SIZE_4_F16 (1 << 0)
1078 #define TLB_VEC_SIZE_2_F16 (0 << 0)
1079 #define TLB_VEC_SIZE_MINUS_1_SHIFT 0
1081 /* Triggers Z/Stencil testing, used when the shader state's "FS modifies Z"
1084 #define TLB_TYPE_DEPTH ((2 << 6) | (0 << 4))
1085 #define TLB_DEPTH_TYPE_INVARIANT (0 << 2) /* Unmodified sideband input used */
1086 #define TLB_DEPTH_TYPE_PER_PIXEL (1 << 2) /* QPU result used */
1087 #define TLB_V42_DEPTH_TYPE_INVARIANT (0 << 3) /* Unmodified sideband input used */
1088 #define TLB_V42_DEPTH_TYPE_PER_PIXEL (1 << 3) /* QPU result used */
1090 /* Stencil is a single 32-bit write. */
1091 #define TLB_TYPE_STENCIL_ALPHA ((2 << 6) | (1 << 4))
1094 emit_frag_end(struct v3d_compile
*c
)
1097 if (c->output_sample_mask_index != -1) {
1098 vir_MS_MASK(c, c->outputs[c->output_sample_mask_index]);
1102 bool has_any_tlb_color_write
= false;
1103 for (int rt
= 0; rt
< V3D_MAX_DRAW_BUFFERS
; rt
++) {
1104 if (c
->fs_key
->cbufs
& (1 << rt
) && c
->output_color_var
[rt
])
1105 has_any_tlb_color_write
= true;
1108 if (c
->fs_key
->sample_alpha_to_coverage
&& c
->output_color_var
[0]) {
1109 struct nir_variable
*var
= c
->output_color_var
[0];
1110 struct qreg
*color
= &c
->outputs
[var
->data
.driver_location
* 4];
1112 vir_SETMSF_dest(c
, vir_nop_reg(),
1115 vir_FTOC(c
, color
[3])));
1118 struct qreg tlb_reg
= vir_magic_reg(V3D_QPU_WADDR_TLB
);
1119 struct qreg tlbu_reg
= vir_magic_reg(V3D_QPU_WADDR_TLBU
);
1120 if (c
->output_position_index
!= -1) {
1121 struct qinst
*inst
= vir_MOV_dest(c
, tlbu_reg
,
1122 c
->outputs
[c
->output_position_index
]);
1123 uint8_t tlb_specifier
= TLB_TYPE_DEPTH
;
1125 if (c
->devinfo
->ver
>= 42) {
1126 tlb_specifier
|= (TLB_V42_DEPTH_TYPE_PER_PIXEL
|
1127 TLB_SAMPLE_MODE_PER_PIXEL
);
1129 tlb_specifier
|= TLB_DEPTH_TYPE_PER_PIXEL
;
1131 inst
->uniform
= vir_get_uniform_index(c
, QUNIFORM_CONSTANT
,
1135 } else if (c
->s
->info
.fs
.uses_discard
||
1136 !c
->s
->info
.fs
.early_fragment_tests
||
1137 c
->fs_key
->sample_alpha_to_coverage
||
1138 !has_any_tlb_color_write
) {
1139 /* Emit passthrough Z if it needed to be delayed until shader
1140 * end due to potential discards.
1142 * Since (single-threaded) fragment shaders always need a TLB
1143 * write, emit passthrouh Z if we didn't have any color
1144 * buffers and flag us as potentially discarding, so that we
1145 * can use Z as the TLB write.
1147 c
->s
->info
.fs
.uses_discard
= true;
1149 struct qinst
*inst
= vir_MOV_dest(c
, tlbu_reg
,
1151 uint8_t tlb_specifier
= TLB_TYPE_DEPTH
;
1153 if (c
->devinfo
->ver
>= 42) {
1154 /* The spec says the PER_PIXEL flag is ignored for
1155 * invariant writes, but the simulator demands it.
1157 tlb_specifier
|= (TLB_V42_DEPTH_TYPE_INVARIANT
|
1158 TLB_SAMPLE_MODE_PER_PIXEL
);
1160 tlb_specifier
|= TLB_DEPTH_TYPE_INVARIANT
;
1163 inst
->uniform
= vir_get_uniform_index(c
,
1170 /* XXX: Performance improvement: Merge Z write and color writes TLB
1174 for (int rt
= 0; rt
< V3D_MAX_DRAW_BUFFERS
; rt
++) {
1175 if (!(c
->fs_key
->cbufs
& (1 << rt
)) || !c
->output_color_var
[rt
])
1178 nir_variable
*var
= c
->output_color_var
[rt
];
1179 struct qreg
*color
= &c
->outputs
[var
->data
.driver_location
* 4];
1180 int num_components
= glsl_get_vector_elements(var
->type
);
1181 uint32_t conf
= 0xffffff00;
1184 conf
|= TLB_SAMPLE_MODE_PER_PIXEL
;
1185 conf
|= (7 - rt
) << TLB_RENDER_TARGET_SHIFT
;
1187 if (c
->fs_key
->swap_color_rb
& (1 << rt
))
1188 num_components
= MAX2(num_components
, 3);
1190 assert(num_components
!= 0);
1191 switch (glsl_get_base_type(var
->type
)) {
1192 case GLSL_TYPE_UINT
:
1194 /* The F32 vs I32 distinction was dropped in 4.2. */
1195 if (c
->devinfo
->ver
< 42)
1196 conf
|= TLB_TYPE_I32_COLOR
;
1198 conf
|= TLB_TYPE_F32_COLOR
;
1199 conf
|= ((num_components
- 1) <<
1200 TLB_VEC_SIZE_MINUS_1_SHIFT
);
1202 inst
= vir_MOV_dest(c
, tlbu_reg
, color
[0]);
1203 inst
->uniform
= vir_get_uniform_index(c
,
1207 for (int i
= 1; i
< num_components
; i
++) {
1208 inst
= vir_MOV_dest(c
, tlb_reg
, color
[i
]);
1213 struct qreg r
= color
[0];
1214 struct qreg g
= color
[1];
1215 struct qreg b
= color
[2];
1216 struct qreg a
= color
[3];
1218 if (c
->fs_key
->f32_color_rb
& (1 << rt
)) {
1219 conf
|= TLB_TYPE_F32_COLOR
;
1220 conf
|= ((num_components
- 1) <<
1221 TLB_VEC_SIZE_MINUS_1_SHIFT
);
1223 conf
|= TLB_TYPE_F16_COLOR
;
1224 conf
|= TLB_F16_SWAP_HI_LO
;
1225 if (num_components
>= 3)
1226 conf
|= TLB_VEC_SIZE_4_F16
;
1228 conf
|= TLB_VEC_SIZE_2_F16
;
1231 if (c
->fs_key
->swap_color_rb
& (1 << rt
)) {
1236 if (c
->fs_key
->sample_alpha_to_one
)
1237 a
= vir_uniform_f(c
, 1.0);
1239 if (c
->fs_key
->f32_color_rb
& (1 << rt
)) {
1240 inst
= vir_MOV_dest(c
, tlbu_reg
, r
);
1241 inst
->uniform
= vir_get_uniform_index(c
,
1245 if (num_components
>= 2)
1246 vir_MOV_dest(c
, tlb_reg
, g
);
1247 if (num_components
>= 3)
1248 vir_MOV_dest(c
, tlb_reg
, b
);
1249 if (num_components
>= 4)
1250 vir_MOV_dest(c
, tlb_reg
, a
);
1252 inst
= vir_VFPACK_dest(c
, tlb_reg
, r
, g
);
1254 inst
->dst
= tlbu_reg
;
1255 inst
->uniform
= vir_get_uniform_index(c
,
1260 if (num_components
>= 3)
1261 inst
= vir_VFPACK_dest(c
, tlb_reg
, b
, a
);
1270 vir_VPM_WRITE(struct v3d_compile
*c
, struct qreg val
, uint32_t vpm_index
)
1272 if (c
->devinfo
->ver
>= 40) {
1273 vir_STVPMV(c
, vir_uniform_ui(c
, vpm_index
), val
);
1275 /* XXX: v3d33_vir_vpm_write_setup(c); */
1276 vir_MOV_dest(c
, vir_reg(QFILE_MAGIC
, V3D_QPU_WADDR_VPM
), val
);
1281 emit_vert_end(struct v3d_compile
*c
)
1283 /* GFXH-1684: VPM writes need to be complete by the end of the shader.
1285 if (c
->devinfo
->ver
>= 40 && c
->devinfo
->ver
<= 42)
1290 v3d_optimize_nir(struct nir_shader
*s
)
1293 unsigned lower_flrp
=
1294 (s
->options
->lower_flrp16
? 16 : 0) |
1295 (s
->options
->lower_flrp32
? 32 : 0) |
1296 (s
->options
->lower_flrp64
? 64 : 0);
1301 NIR_PASS_V(s
, nir_lower_vars_to_ssa
);
1302 NIR_PASS(progress
, s
, nir_lower_alu_to_scalar
, NULL
);
1303 NIR_PASS(progress
, s
, nir_lower_phis_to_scalar
);
1304 NIR_PASS(progress
, s
, nir_copy_prop
);
1305 NIR_PASS(progress
, s
, nir_opt_remove_phis
);
1306 NIR_PASS(progress
, s
, nir_opt_dce
);
1307 NIR_PASS(progress
, s
, nir_opt_dead_cf
);
1308 NIR_PASS(progress
, s
, nir_opt_cse
);
1309 NIR_PASS(progress
, s
, nir_opt_peephole_select
, 8, true, true);
1310 NIR_PASS(progress
, s
, nir_opt_algebraic
);
1311 NIR_PASS(progress
, s
, nir_opt_constant_folding
);
1313 if (lower_flrp
!= 0) {
1314 bool lower_flrp_progress
= false;
1316 NIR_PASS(lower_flrp_progress
, s
, nir_lower_flrp
,
1318 false /* always_precise */,
1319 s
->options
->lower_ffma
);
1320 if (lower_flrp_progress
) {
1321 NIR_PASS(progress
, s
, nir_opt_constant_folding
);
1325 /* Nothing should rematerialize any flrps, so we only
1326 * need to do this lowering once.
1331 NIR_PASS(progress
, s
, nir_opt_undef
);
1334 NIR_PASS(progress
, s
, nir_opt_move_load_ubo
);
1338 driver_location_compare(const void *in_a
, const void *in_b
)
1340 const nir_variable
*const *a
= in_a
;
1341 const nir_variable
*const *b
= in_b
;
1343 return (*a
)->data
.driver_location
- (*b
)->data
.driver_location
;
1347 ntq_emit_vpm_read(struct v3d_compile
*c
,
1348 uint32_t *num_components_queued
,
1349 uint32_t *remaining
,
1352 struct qreg vpm
= vir_reg(QFILE_VPM
, vpm_index
);
1354 if (c
->devinfo
->ver
>= 40 ) {
1355 return vir_LDVPMV_IN(c
,
1357 (*num_components_queued
)++));
1360 if (*num_components_queued
!= 0) {
1361 (*num_components_queued
)--;
1362 return vir_MOV(c
, vpm
);
1365 uint32_t num_components
= MIN2(*remaining
, 32);
1367 v3d33_vir_vpm_read_setup(c
, num_components
);
1369 *num_components_queued
= num_components
- 1;
1370 *remaining
-= num_components
;
1372 return vir_MOV(c
, vpm
);
1376 ntq_setup_vpm_inputs(struct v3d_compile
*c
)
1378 /* Figure out how many components of each vertex attribute the shader
1379 * uses. Each variable should have been split to individual
1380 * components and unused ones DCEed. The vertex fetcher will load
1381 * from the start of the attribute to the number of components we
1382 * declare we need in c->vattr_sizes[].
1384 nir_foreach_variable(var
, &c
->s
->inputs
) {
1385 /* No VS attribute array support. */
1386 assert(MAX2(glsl_get_length(var
->type
), 1) == 1);
1388 unsigned loc
= var
->data
.driver_location
;
1389 int start_component
= var
->data
.location_frac
;
1390 int num_components
= glsl_get_components(var
->type
);
1392 c
->vattr_sizes
[loc
] = MAX2(c
->vattr_sizes
[loc
],
1393 start_component
+ num_components
);
1396 unsigned num_components
= 0;
1397 uint32_t vpm_components_queued
= 0;
1398 bool uses_iid
= c
->s
->info
.system_values_read
&
1399 (1ull << SYSTEM_VALUE_INSTANCE_ID
);
1400 bool uses_vid
= c
->s
->info
.system_values_read
&
1401 (1ull << SYSTEM_VALUE_VERTEX_ID
);
1402 num_components
+= uses_iid
;
1403 num_components
+= uses_vid
;
1405 for (int i
= 0; i
< ARRAY_SIZE(c
->vattr_sizes
); i
++)
1406 num_components
+= c
->vattr_sizes
[i
];
1409 c
->iid
= ntq_emit_vpm_read(c
, &vpm_components_queued
,
1410 &num_components
, ~0);
1414 c
->vid
= ntq_emit_vpm_read(c
, &vpm_components_queued
,
1415 &num_components
, ~0);
1418 /* The actual loads will happen directly in nir_intrinsic_load_input
1419 * on newer versions.
1421 if (c
->devinfo
->ver
>= 40)
1424 for (int loc
= 0; loc
< ARRAY_SIZE(c
->vattr_sizes
); loc
++) {
1425 resize_qreg_array(c
, &c
->inputs
, &c
->inputs_array_size
,
1428 for (int i
= 0; i
< c
->vattr_sizes
[loc
]; i
++) {
1429 c
->inputs
[loc
* 4 + i
] =
1430 ntq_emit_vpm_read(c
,
1431 &vpm_components_queued
,
1438 if (c
->devinfo
->ver
>= 40) {
1439 assert(vpm_components_queued
== num_components
);
1441 assert(vpm_components_queued
== 0);
1442 assert(num_components
== 0);
1447 var_needs_point_coord(struct v3d_compile
*c
, nir_variable
*var
)
1449 return (var
->data
.location
== VARYING_SLOT_PNTC
||
1450 (var
->data
.location
>= VARYING_SLOT_VAR0
&&
1451 (c
->fs_key
->point_sprite_mask
&
1452 (1 << (var
->data
.location
- VARYING_SLOT_VAR0
)))));
1456 program_reads_point_coord(struct v3d_compile
*c
)
1458 nir_foreach_variable(var
, &c
->s
->inputs
) {
1459 if (var_needs_point_coord(c
, var
))
1467 ntq_setup_fs_inputs(struct v3d_compile
*c
)
1469 unsigned num_entries
= 0;
1470 unsigned num_components
= 0;
1471 nir_foreach_variable(var
, &c
->s
->inputs
) {
1473 num_components
+= glsl_get_components(var
->type
);
1476 nir_variable
*vars
[num_entries
];
1479 nir_foreach_variable(var
, &c
->s
->inputs
)
1482 /* Sort the variables so that we emit the input setup in
1483 * driver_location order. This is required for VPM reads, whose data
1484 * is fetched into the VPM in driver_location (TGSI register index)
1487 qsort(&vars
, num_entries
, sizeof(*vars
), driver_location_compare
);
1489 for (unsigned i
= 0; i
< num_entries
; i
++) {
1490 nir_variable
*var
= vars
[i
];
1491 unsigned array_len
= MAX2(glsl_get_length(var
->type
), 1);
1492 unsigned loc
= var
->data
.driver_location
;
1494 resize_qreg_array(c
, &c
->inputs
, &c
->inputs_array_size
,
1495 (loc
+ array_len
) * 4);
1497 if (var
->data
.location
== VARYING_SLOT_POS
) {
1498 emit_fragcoord_input(c
, loc
);
1499 } else if (var_needs_point_coord(c
, var
)) {
1500 c
->inputs
[loc
* 4 + 0] = c
->point_x
;
1501 c
->inputs
[loc
* 4 + 1] = c
->point_y
;
1503 for (int j
= 0; j
< array_len
; j
++)
1504 emit_fragment_input(c
, loc
+ j
, var
, j
);
1510 ntq_setup_outputs(struct v3d_compile
*c
)
1512 if (c
->s
->info
.stage
!= MESA_SHADER_FRAGMENT
)
1515 nir_foreach_variable(var
, &c
->s
->outputs
) {
1516 unsigned array_len
= MAX2(glsl_get_length(var
->type
), 1);
1517 unsigned loc
= var
->data
.driver_location
* 4;
1519 assert(array_len
== 1);
1522 for (int i
= 0; i
< 4 - var
->data
.location_frac
; i
++) {
1523 add_output(c
, loc
+ var
->data
.location_frac
+ i
,
1525 var
->data
.location_frac
+ i
);
1528 switch (var
->data
.location
) {
1529 case FRAG_RESULT_COLOR
:
1530 c
->output_color_var
[0] = var
;
1531 c
->output_color_var
[1] = var
;
1532 c
->output_color_var
[2] = var
;
1533 c
->output_color_var
[3] = var
;
1535 case FRAG_RESULT_DATA0
:
1536 case FRAG_RESULT_DATA1
:
1537 case FRAG_RESULT_DATA2
:
1538 case FRAG_RESULT_DATA3
:
1539 c
->output_color_var
[var
->data
.location
-
1540 FRAG_RESULT_DATA0
] = var
;
1542 case FRAG_RESULT_DEPTH
:
1543 c
->output_position_index
= loc
;
1545 case FRAG_RESULT_SAMPLE_MASK
:
1546 c
->output_sample_mask_index
= loc
;
1553 * Sets up the mapping from nir_register to struct qreg *.
1555 * Each nir_register gets a struct qreg per 32-bit component being stored.
1558 ntq_setup_registers(struct v3d_compile
*c
, struct exec_list
*list
)
1560 foreach_list_typed(nir_register
, nir_reg
, node
, list
) {
1561 unsigned array_len
= MAX2(nir_reg
->num_array_elems
, 1);
1562 struct qreg
*qregs
= ralloc_array(c
->def_ht
, struct qreg
,
1564 nir_reg
->num_components
);
1566 _mesa_hash_table_insert(c
->def_ht
, nir_reg
, qregs
);
1568 for (int i
= 0; i
< array_len
* nir_reg
->num_components
; i
++)
1569 qregs
[i
] = vir_get_temp(c
);
1574 ntq_emit_load_const(struct v3d_compile
*c
, nir_load_const_instr
*instr
)
1576 /* XXX perf: Experiment with using immediate loads to avoid having
1577 * these end up in the uniform stream. Watch out for breaking the
1578 * small immediates optimization in the process!
1580 struct qreg
*qregs
= ntq_init_ssa_def(c
, &instr
->def
);
1581 for (int i
= 0; i
< instr
->def
.num_components
; i
++)
1582 qregs
[i
] = vir_uniform_ui(c
, instr
->value
[i
].u32
);
1584 _mesa_hash_table_insert(c
->def_ht
, &instr
->def
, qregs
);
1588 ntq_emit_ssa_undef(struct v3d_compile
*c
, nir_ssa_undef_instr
*instr
)
1590 struct qreg
*qregs
= ntq_init_ssa_def(c
, &instr
->def
);
1592 /* VIR needs there to be *some* value, so pick 0 (same as for
1593 * ntq_setup_registers().
1595 for (int i
= 0; i
< instr
->def
.num_components
; i
++)
1596 qregs
[i
] = vir_uniform_ui(c
, 0);
1600 ntq_emit_image_size(struct v3d_compile
*c
, nir_intrinsic_instr
*instr
)
1602 assert(instr
->intrinsic
== nir_intrinsic_image_deref_size
);
1603 nir_variable
*var
= nir_intrinsic_get_var(instr
, 0);
1604 unsigned image_index
= var
->data
.driver_location
;
1605 const struct glsl_type
*sampler_type
= glsl_without_array(var
->type
);
1606 bool is_array
= glsl_sampler_type_is_array(sampler_type
);
1608 ntq_store_dest(c
, &instr
->dest
, 0,
1609 vir_uniform(c
, QUNIFORM_IMAGE_WIDTH
, image_index
));
1610 if (instr
->num_components
> 1) {
1611 ntq_store_dest(c
, &instr
->dest
, 1,
1612 vir_uniform(c
, QUNIFORM_IMAGE_HEIGHT
,
1615 if (instr
->num_components
> 2) {
1616 ntq_store_dest(c
, &instr
->dest
, 2,
1619 QUNIFORM_IMAGE_ARRAY_SIZE
:
1620 QUNIFORM_IMAGE_DEPTH
,
1626 vir_emit_tlb_color_read(struct v3d_compile
*c
, nir_intrinsic_instr
*instr
)
1628 assert(c
->s
->info
.stage
== MESA_SHADER_FRAGMENT
);
1630 int rt
= nir_src_as_uint(instr
->src
[0]);
1631 assert(rt
< V3D_MAX_DRAW_BUFFERS
);
1633 int sample_index
= nir_intrinsic_base(instr
) ;
1634 assert(sample_index
== 0); /* XXX: multisample */
1636 int component
= nir_intrinsic_component(instr
);
1637 assert(component
< 4);
1639 /* We need to emit our TLB reads after we have acquired the scoreboard
1640 * lock, or the GPU will hang. Usually, we do our scoreboard locking on
1641 * the last thread switch to improve parallelism, however, that is only
1642 * guaranteed to happen before the tlb color writes.
1644 * To fix that, we make sure we always emit a thread switch before the
1645 * first tlb color read. If that happens to be the last thread switch
1646 * we emit, then everything is fine, but otherwsie, if any code after
1647 * this point needs to emit additional thread switches, then we will
1648 * switch the strategy to locking the scoreboard on the first thread
1649 * switch instead -- see vir_emit_thrsw().
1651 if (!c
->emitted_tlb_load
) {
1652 if (!c
->last_thrsw_at_top_level
) {
1653 assert(c
->devinfo
->ver
>= 41);
1657 c
->emitted_tlb_load
= true;
1660 struct qreg
*color_reads
=
1661 &c
->color_reads
[(rt
* V3D_MAX_SAMPLES
+ sample_index
) * 4];
1663 if (color_reads
[component
].file
== QFILE_NULL
) {
1664 enum pipe_format rt_format
= c
->fs_key
->color_fmt
[rt
].format
;
1665 int num_components
=
1666 util_format_get_nr_components(rt_format
);
1668 const bool swap_rb
= c
->fs_key
->swap_color_rb
& (1 << rt
);
1670 num_components
= MAX2(num_components
, 3);
1672 nir_variable
*var
= c
->output_color_var
[rt
];
1673 enum glsl_base_type type
= glsl_get_base_type(var
->type
);
1675 bool is_int_format
= type
== GLSL_TYPE_INT
||
1676 type
== GLSL_TYPE_UINT
;
1678 bool is_32b_tlb_format
= is_int_format
||
1679 (c
->fs_key
->f32_color_rb
& (1 << rt
));
1681 uint32_t conf
= 0xffffff00;
1682 conf
|= TLB_SAMPLE_MODE_PER_PIXEL
; /* XXX: multisample */
1683 conf
|= (7 - rt
) << TLB_RENDER_TARGET_SHIFT
;
1685 if (is_32b_tlb_format
) {
1686 /* The F32 vs I32 distinction was dropped in 4.2. */
1687 conf
|= (c
->devinfo
->ver
< 42 && is_int_format
) ?
1688 TLB_TYPE_I32_COLOR
: TLB_TYPE_F32_COLOR
;
1690 conf
|= ((num_components
- 1) <<
1691 TLB_VEC_SIZE_MINUS_1_SHIFT
);
1693 conf
|= TLB_TYPE_F16_COLOR
;
1694 conf
|= TLB_F16_SWAP_HI_LO
;
1696 if (num_components
>= 3)
1697 conf
|= TLB_VEC_SIZE_4_F16
;
1699 conf
|= TLB_VEC_SIZE_2_F16
;
1702 struct qreg r
, g
, b
, a
;
1703 if (is_32b_tlb_format
) {
1704 r
= conf
!= 0xffffffff ? vir_TLBU_COLOR_READ(c
, conf
) :
1705 vir_TLB_COLOR_READ(c
);
1706 if (num_components
>= 2)
1707 g
= vir_TLB_COLOR_READ(c
);
1708 if (num_components
>= 3)
1709 b
= vir_TLB_COLOR_READ(c
);
1710 if (num_components
>= 4)
1711 a
= vir_TLB_COLOR_READ(c
);
1713 struct qreg rg
= conf
!= 0xffffffff ?
1714 vir_TLBU_COLOR_READ(c
, conf
) :
1715 vir_TLB_COLOR_READ(c
);
1716 r
= vir_FMOV(c
, rg
);
1717 vir_set_unpack(c
->defs
[r
.index
], 0, V3D_QPU_UNPACK_L
);
1718 g
= vir_FMOV(c
, rg
);
1719 vir_set_unpack(c
->defs
[g
.index
], 0, V3D_QPU_UNPACK_H
);
1721 if (num_components
> 2) {
1722 struct qreg ba
= vir_TLB_COLOR_READ(c
);
1723 b
= vir_FMOV(c
, ba
);
1724 vir_set_unpack(c
->defs
[b
.index
], 0,
1726 a
= vir_FMOV(c
, ba
);
1727 vir_set_unpack(c
->defs
[a
.index
], 0,
1732 color_reads
[0] = swap_rb
? b
: r
;
1733 if (num_components
>= 2)
1735 if (num_components
>= 3)
1736 color_reads
[2] = swap_rb
? r
: b
;
1737 if (num_components
>= 4)
1741 assert(color_reads
[component
].file
!= QFILE_NULL
);
1742 ntq_store_dest(c
, &instr
->dest
, 0, vir_MOV(c
, color_reads
[component
]));
1746 ntq_emit_load_uniform(struct v3d_compile
*c
, nir_intrinsic_instr
*instr
)
1748 if (nir_src_is_const(instr
->src
[0])) {
1749 int offset
= (nir_intrinsic_base(instr
) +
1750 nir_src_as_uint(instr
->src
[0]));
1751 assert(offset
% 4 == 0);
1752 /* We need dwords */
1753 offset
= offset
/ 4;
1754 for (int i
= 0; i
< instr
->num_components
; i
++) {
1755 ntq_store_dest(c
, &instr
->dest
, i
,
1756 vir_uniform(c
, QUNIFORM_UNIFORM
,
1760 ntq_emit_tmu_general(c
, instr
, false);
1765 ntq_emit_load_input(struct v3d_compile
*c
, nir_intrinsic_instr
*instr
)
1767 /* XXX: Use ldvpmv (uniform offset) or ldvpmd (non-uniform offset)
1768 * and enable PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR.
1771 nir_intrinsic_base(instr
) + nir_src_as_uint(instr
->src
[0]);
1773 if (c
->s
->info
.stage
!= MESA_SHADER_FRAGMENT
&& c
->devinfo
->ver
>= 40) {
1774 /* Emit the LDVPM directly now, rather than at the top
1775 * of the shader like we did for V3D 3.x (which needs
1776 * vpmsetup when not just taking the next offset).
1778 * Note that delaying like this may introduce stalls,
1779 * as LDVPMV takes a minimum of 1 instruction but may
1780 * be slower if the VPM unit is busy with another QPU.
1783 if (c
->s
->info
.system_values_read
&
1784 (1ull << SYSTEM_VALUE_INSTANCE_ID
)) {
1787 if (c
->s
->info
.system_values_read
&
1788 (1ull << SYSTEM_VALUE_VERTEX_ID
)) {
1791 for (int i
= 0; i
< offset
; i
++)
1792 index
+= c
->vattr_sizes
[i
];
1793 index
+= nir_intrinsic_component(instr
);
1794 for (int i
= 0; i
< instr
->num_components
; i
++) {
1795 struct qreg vpm_offset
= vir_uniform_ui(c
, index
++);
1796 ntq_store_dest(c
, &instr
->dest
, i
,
1797 vir_LDVPMV_IN(c
, vpm_offset
));
1800 for (int i
= 0; i
< instr
->num_components
; i
++) {
1801 int comp
= nir_intrinsic_component(instr
) + i
;
1802 ntq_store_dest(c
, &instr
->dest
, i
,
1803 vir_MOV(c
, c
->inputs
[offset
* 4 + comp
]));
1809 ntq_emit_store_output(struct v3d_compile
*c
, nir_intrinsic_instr
*instr
)
1811 /* XXX perf: Use stvpmv with uniform non-constant offsets and
1812 * stvpmd with non-uniform offsets and enable
1813 * PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR.
1815 if (c
->s
->info
.stage
== MESA_SHADER_FRAGMENT
) {
1816 unsigned offset
= ((nir_intrinsic_base(instr
) +
1817 nir_src_as_uint(instr
->src
[1])) * 4 +
1818 nir_intrinsic_component(instr
));
1819 for (int i
= 0; i
< instr
->num_components
; i
++) {
1820 c
->outputs
[offset
+ i
] =
1821 vir_MOV(c
, ntq_get_src(c
, instr
->src
[0], i
));
1824 assert(instr
->num_components
== 1);
1827 ntq_get_src(c
, instr
->src
[0], 0),
1828 nir_intrinsic_base(instr
));
1833 ntq_emit_intrinsic(struct v3d_compile
*c
, nir_intrinsic_instr
*instr
)
1835 switch (instr
->intrinsic
) {
1836 case nir_intrinsic_load_uniform
:
1837 ntq_emit_load_uniform(c
, instr
);
1840 case nir_intrinsic_load_ubo
:
1841 ntq_emit_tmu_general(c
, instr
, false);
1844 case nir_intrinsic_ssbo_atomic_add
:
1845 case nir_intrinsic_ssbo_atomic_imin
:
1846 case nir_intrinsic_ssbo_atomic_umin
:
1847 case nir_intrinsic_ssbo_atomic_imax
:
1848 case nir_intrinsic_ssbo_atomic_umax
:
1849 case nir_intrinsic_ssbo_atomic_and
:
1850 case nir_intrinsic_ssbo_atomic_or
:
1851 case nir_intrinsic_ssbo_atomic_xor
:
1852 case nir_intrinsic_ssbo_atomic_exchange
:
1853 case nir_intrinsic_ssbo_atomic_comp_swap
:
1854 case nir_intrinsic_load_ssbo
:
1855 case nir_intrinsic_store_ssbo
:
1856 ntq_emit_tmu_general(c
, instr
, false);
1859 case nir_intrinsic_shared_atomic_add
:
1860 case nir_intrinsic_shared_atomic_imin
:
1861 case nir_intrinsic_shared_atomic_umin
:
1862 case nir_intrinsic_shared_atomic_imax
:
1863 case nir_intrinsic_shared_atomic_umax
:
1864 case nir_intrinsic_shared_atomic_and
:
1865 case nir_intrinsic_shared_atomic_or
:
1866 case nir_intrinsic_shared_atomic_xor
:
1867 case nir_intrinsic_shared_atomic_exchange
:
1868 case nir_intrinsic_shared_atomic_comp_swap
:
1869 case nir_intrinsic_load_shared
:
1870 case nir_intrinsic_store_shared
:
1871 case nir_intrinsic_load_scratch
:
1872 case nir_intrinsic_store_scratch
:
1873 ntq_emit_tmu_general(c
, instr
, true);
1876 case nir_intrinsic_image_deref_load
:
1877 case nir_intrinsic_image_deref_store
:
1878 case nir_intrinsic_image_deref_atomic_add
:
1879 case nir_intrinsic_image_deref_atomic_min
:
1880 case nir_intrinsic_image_deref_atomic_max
:
1881 case nir_intrinsic_image_deref_atomic_and
:
1882 case nir_intrinsic_image_deref_atomic_or
:
1883 case nir_intrinsic_image_deref_atomic_xor
:
1884 case nir_intrinsic_image_deref_atomic_exchange
:
1885 case nir_intrinsic_image_deref_atomic_comp_swap
:
1886 v3d40_vir_emit_image_load_store(c
, instr
);
1889 case nir_intrinsic_get_buffer_size
:
1890 ntq_store_dest(c
, &instr
->dest
, 0,
1891 vir_uniform(c
, QUNIFORM_GET_BUFFER_SIZE
,
1892 nir_src_as_uint(instr
->src
[0])));
1895 case nir_intrinsic_load_user_clip_plane
:
1896 for (int i
= 0; i
< instr
->num_components
; i
++) {
1897 ntq_store_dest(c
, &instr
->dest
, i
,
1898 vir_uniform(c
, QUNIFORM_USER_CLIP_PLANE
,
1899 nir_intrinsic_ucp_id(instr
) *
1904 case nir_intrinsic_load_viewport_x_scale
:
1905 ntq_store_dest(c
, &instr
->dest
, 0,
1906 vir_uniform(c
, QUNIFORM_VIEWPORT_X_SCALE
, 0));
1909 case nir_intrinsic_load_viewport_y_scale
:
1910 ntq_store_dest(c
, &instr
->dest
, 0,
1911 vir_uniform(c
, QUNIFORM_VIEWPORT_Y_SCALE
, 0));
1914 case nir_intrinsic_load_viewport_z_scale
:
1915 ntq_store_dest(c
, &instr
->dest
, 0,
1916 vir_uniform(c
, QUNIFORM_VIEWPORT_Z_SCALE
, 0));
1919 case nir_intrinsic_load_viewport_z_offset
:
1920 ntq_store_dest(c
, &instr
->dest
, 0,
1921 vir_uniform(c
, QUNIFORM_VIEWPORT_Z_OFFSET
, 0));
1924 case nir_intrinsic_load_alpha_ref_float
:
1925 ntq_store_dest(c
, &instr
->dest
, 0,
1926 vir_uniform(c
, QUNIFORM_ALPHA_REF
, 0));
1929 case nir_intrinsic_load_sample_mask_in
:
1930 ntq_store_dest(c
, &instr
->dest
, 0, vir_MSF(c
));
1933 case nir_intrinsic_load_helper_invocation
:
1934 vir_set_pf(vir_MSF_dest(c
, vir_nop_reg()), V3D_QPU_PF_PUSHZ
);
1935 ntq_store_dest(c
, &instr
->dest
, 0,
1936 vir_MOV(c
, vir_SEL(c
, V3D_QPU_COND_IFA
,
1937 vir_uniform_ui(c
, ~0),
1938 vir_uniform_ui(c
, 0))));
1941 case nir_intrinsic_load_front_face
:
1942 /* The register contains 0 (front) or 1 (back), and we need to
1943 * turn it into a NIR bool where true means front.
1945 ntq_store_dest(c
, &instr
->dest
, 0,
1947 vir_uniform_ui(c
, -1),
1951 case nir_intrinsic_load_instance_id
:
1952 ntq_store_dest(c
, &instr
->dest
, 0, vir_MOV(c
, c
->iid
));
1955 case nir_intrinsic_load_vertex_id
:
1956 ntq_store_dest(c
, &instr
->dest
, 0, vir_MOV(c
, c
->vid
));
1959 case nir_intrinsic_load_tlb_color_v3d
:
1960 vir_emit_tlb_color_read(c
, instr
);
1963 case nir_intrinsic_load_input
:
1964 ntq_emit_load_input(c
, instr
);
1967 case nir_intrinsic_store_output
:
1968 ntq_emit_store_output(c
, instr
);
1971 case nir_intrinsic_image_deref_size
:
1972 ntq_emit_image_size(c
, instr
);
1975 case nir_intrinsic_discard
:
1976 if (vir_in_nonuniform_control_flow(c
)) {
1977 vir_set_pf(vir_MOV_dest(c
, vir_nop_reg(), c
->execute
),
1979 vir_set_cond(vir_SETMSF_dest(c
, vir_nop_reg(),
1980 vir_uniform_ui(c
, 0)),
1983 vir_SETMSF_dest(c
, vir_nop_reg(),
1984 vir_uniform_ui(c
, 0));
1988 case nir_intrinsic_discard_if
: {
1989 enum v3d_qpu_cond cond
= ntq_emit_bool_to_cond(c
, instr
->src
[0]);
1991 if (vir_in_nonuniform_control_flow(c
)) {
1992 struct qinst
*exec_flag
= vir_MOV_dest(c
, vir_nop_reg(),
1994 if (cond
== V3D_QPU_COND_IFA
) {
1995 vir_set_uf(exec_flag
, V3D_QPU_UF_ANDZ
);
1997 vir_set_uf(exec_flag
, V3D_QPU_UF_NORNZ
);
1998 cond
= V3D_QPU_COND_IFA
;
2002 vir_set_cond(vir_SETMSF_dest(c
, vir_nop_reg(),
2003 vir_uniform_ui(c
, 0)), cond
);
2008 case nir_intrinsic_memory_barrier
:
2009 case nir_intrinsic_memory_barrier_atomic_counter
:
2010 case nir_intrinsic_memory_barrier_buffer
:
2011 case nir_intrinsic_memory_barrier_image
:
2012 case nir_intrinsic_memory_barrier_shared
:
2013 case nir_intrinsic_group_memory_barrier
:
2014 /* We don't do any instruction scheduling of these NIR
2015 * instructions between each other, so we just need to make
2016 * sure that the TMU operations before the barrier are flushed
2017 * before the ones after the barrier. That is currently
2018 * handled by having a THRSW in each of them and a LDTMU
2019 * series or a TMUWT after.
2023 case nir_intrinsic_barrier
:
2024 /* Emit a TSY op to get all invocations in the workgroup
2025 * (actually supergroup) to block until the last invocation
2026 * reaches the TSY op.
2028 if (c
->devinfo
->ver
>= 42) {
2029 vir_BARRIERID_dest(c
, vir_reg(QFILE_MAGIC
,
2030 V3D_QPU_WADDR_SYNCB
));
2032 struct qinst
*sync
=
2033 vir_BARRIERID_dest(c
,
2034 vir_reg(QFILE_MAGIC
,
2035 V3D_QPU_WADDR_SYNCU
));
2037 vir_get_uniform_index(c
, QUNIFORM_CONSTANT
,
2039 V3D_TSY_WAIT_INC_CHECK
);
2043 /* The blocking of a TSY op only happens at the next thread
2044 * switch. No texturing may be outstanding at the time of a
2045 * TSY blocking operation.
2050 case nir_intrinsic_load_num_work_groups
:
2051 for (int i
= 0; i
< 3; i
++) {
2052 ntq_store_dest(c
, &instr
->dest
, i
,
2053 vir_uniform(c
, QUNIFORM_NUM_WORK_GROUPS
,
2058 case nir_intrinsic_load_local_invocation_index
:
2059 ntq_store_dest(c
, &instr
->dest
, 0,
2060 vir_SHR(c
, c
->cs_payload
[1],
2061 vir_uniform_ui(c
, 32 - c
->local_invocation_index_bits
)));
2064 case nir_intrinsic_load_work_group_id
:
2065 ntq_store_dest(c
, &instr
->dest
, 0,
2066 vir_AND(c
, c
->cs_payload
[0],
2067 vir_uniform_ui(c
, 0xffff)));
2068 ntq_store_dest(c
, &instr
->dest
, 1,
2069 vir_SHR(c
, c
->cs_payload
[0],
2070 vir_uniform_ui(c
, 16)));
2071 ntq_store_dest(c
, &instr
->dest
, 2,
2072 vir_AND(c
, c
->cs_payload
[1],
2073 vir_uniform_ui(c
, 0xffff)));
2076 case nir_intrinsic_load_subgroup_id
:
2077 ntq_store_dest(c
, &instr
->dest
, 0, vir_EIDX(c
));
2081 fprintf(stderr
, "Unknown intrinsic: ");
2082 nir_print_instr(&instr
->instr
, stderr
);
2083 fprintf(stderr
, "\n");
2088 /* Clears (activates) the execute flags for any channels whose jump target
2089 * matches this block.
2091 * XXX perf: Could we be using flpush/flpop somehow for our execution channel
2094 * XXX perf: For uniform control flow, we should be able to skip c->execute
2095 * handling entirely.
2098 ntq_activate_execute_for_block(struct v3d_compile
*c
)
2100 vir_set_pf(vir_XOR_dest(c
, vir_nop_reg(),
2101 c
->execute
, vir_uniform_ui(c
, c
->cur_block
->index
)),
2104 vir_MOV_cond(c
, V3D_QPU_COND_IFA
, c
->execute
, vir_uniform_ui(c
, 0));
2108 ntq_emit_uniform_if(struct v3d_compile
*c
, nir_if
*if_stmt
)
2110 nir_block
*nir_else_block
= nir_if_first_else_block(if_stmt
);
2111 bool empty_else_block
=
2112 (nir_else_block
== nir_if_last_else_block(if_stmt
) &&
2113 exec_list_is_empty(&nir_else_block
->instr_list
));
2115 struct qblock
*then_block
= vir_new_block(c
);
2116 struct qblock
*after_block
= vir_new_block(c
);
2117 struct qblock
*else_block
;
2118 if (empty_else_block
)
2119 else_block
= after_block
;
2121 else_block
= vir_new_block(c
);
2123 /* Set up the flags for the IF condition (taking the THEN branch). */
2124 enum v3d_qpu_cond cond
= ntq_emit_bool_to_cond(c
, if_stmt
->condition
);
2127 vir_BRANCH(c
, cond
== V3D_QPU_COND_IFA
?
2128 V3D_QPU_BRANCH_COND_ALLNA
:
2129 V3D_QPU_BRANCH_COND_ALLA
);
2130 vir_link_blocks(c
->cur_block
, else_block
);
2131 vir_link_blocks(c
->cur_block
, then_block
);
2133 /* Process the THEN block. */
2134 vir_set_emit_block(c
, then_block
);
2135 ntq_emit_cf_list(c
, &if_stmt
->then_list
);
2137 if (!empty_else_block
) {
2138 /* At the end of the THEN block, jump to ENDIF */
2139 vir_BRANCH(c
, V3D_QPU_BRANCH_COND_ALWAYS
);
2140 vir_link_blocks(c
->cur_block
, after_block
);
2142 /* Emit the else block. */
2143 vir_set_emit_block(c
, else_block
);
2144 ntq_emit_cf_list(c
, &if_stmt
->else_list
);
2147 vir_link_blocks(c
->cur_block
, after_block
);
2149 vir_set_emit_block(c
, after_block
);
2153 ntq_emit_nonuniform_if(struct v3d_compile
*c
, nir_if
*if_stmt
)
2155 nir_block
*nir_else_block
= nir_if_first_else_block(if_stmt
);
2156 bool empty_else_block
=
2157 (nir_else_block
== nir_if_last_else_block(if_stmt
) &&
2158 exec_list_is_empty(&nir_else_block
->instr_list
));
2160 struct qblock
*then_block
= vir_new_block(c
);
2161 struct qblock
*after_block
= vir_new_block(c
);
2162 struct qblock
*else_block
;
2163 if (empty_else_block
)
2164 else_block
= after_block
;
2166 else_block
= vir_new_block(c
);
2168 bool was_uniform_control_flow
= false;
2169 if (!vir_in_nonuniform_control_flow(c
)) {
2170 c
->execute
= vir_MOV(c
, vir_uniform_ui(c
, 0));
2171 was_uniform_control_flow
= true;
2174 /* Set up the flags for the IF condition (taking the THEN branch). */
2175 enum v3d_qpu_cond cond
= ntq_emit_bool_to_cond(c
, if_stmt
->condition
);
2177 /* Update the flags+cond to mean "Taking the ELSE branch (!cond) and
2178 * was previously active (execute Z) for updating the exec flags.
2180 if (was_uniform_control_flow
) {
2181 cond
= v3d_qpu_cond_invert(cond
);
2183 struct qinst
*inst
= vir_MOV_dest(c
, vir_nop_reg(), c
->execute
);
2184 if (cond
== V3D_QPU_COND_IFA
) {
2185 vir_set_uf(inst
, V3D_QPU_UF_NORNZ
);
2187 vir_set_uf(inst
, V3D_QPU_UF_ANDZ
);
2188 cond
= V3D_QPU_COND_IFA
;
2192 vir_MOV_cond(c
, cond
,
2194 vir_uniform_ui(c
, else_block
->index
));
2196 /* Jump to ELSE if nothing is active for THEN, otherwise fall
2199 vir_set_pf(vir_MOV_dest(c
, vir_nop_reg(), c
->execute
), V3D_QPU_PF_PUSHZ
);
2200 vir_BRANCH(c
, V3D_QPU_BRANCH_COND_ALLNA
);
2201 vir_link_blocks(c
->cur_block
, else_block
);
2202 vir_link_blocks(c
->cur_block
, then_block
);
2204 /* Process the THEN block. */
2205 vir_set_emit_block(c
, then_block
);
2206 ntq_emit_cf_list(c
, &if_stmt
->then_list
);
2208 if (!empty_else_block
) {
2209 /* Handle the end of the THEN block. First, all currently
2210 * active channels update their execute flags to point to
2213 vir_set_pf(vir_MOV_dest(c
, vir_nop_reg(), c
->execute
),
2215 vir_MOV_cond(c
, V3D_QPU_COND_IFA
, c
->execute
,
2216 vir_uniform_ui(c
, after_block
->index
));
2218 /* If everything points at ENDIF, then jump there immediately. */
2219 vir_set_pf(vir_XOR_dest(c
, vir_nop_reg(),
2221 vir_uniform_ui(c
, after_block
->index
)),
2223 vir_BRANCH(c
, V3D_QPU_BRANCH_COND_ALLA
);
2224 vir_link_blocks(c
->cur_block
, after_block
);
2225 vir_link_blocks(c
->cur_block
, else_block
);
2227 vir_set_emit_block(c
, else_block
);
2228 ntq_activate_execute_for_block(c
);
2229 ntq_emit_cf_list(c
, &if_stmt
->else_list
);
2232 vir_link_blocks(c
->cur_block
, after_block
);
2234 vir_set_emit_block(c
, after_block
);
2235 if (was_uniform_control_flow
)
2236 c
->execute
= c
->undef
;
2238 ntq_activate_execute_for_block(c
);
2242 ntq_emit_if(struct v3d_compile
*c
, nir_if
*nif
)
2244 bool was_in_control_flow
= c
->in_control_flow
;
2245 c
->in_control_flow
= true;
2246 if (!vir_in_nonuniform_control_flow(c
) &&
2247 nir_src_is_dynamically_uniform(nif
->condition
)) {
2248 ntq_emit_uniform_if(c
, nif
);
2250 ntq_emit_nonuniform_if(c
, nif
);
2252 c
->in_control_flow
= was_in_control_flow
;
2256 ntq_emit_jump(struct v3d_compile
*c
, nir_jump_instr
*jump
)
2258 switch (jump
->type
) {
2259 case nir_jump_break
:
2260 vir_set_pf(vir_MOV_dest(c
, vir_nop_reg(), c
->execute
),
2262 vir_MOV_cond(c
, V3D_QPU_COND_IFA
, c
->execute
,
2263 vir_uniform_ui(c
, c
->loop_break_block
->index
));
2266 case nir_jump_continue
:
2267 vir_set_pf(vir_MOV_dest(c
, vir_nop_reg(), c
->execute
),
2269 vir_MOV_cond(c
, V3D_QPU_COND_IFA
, c
->execute
,
2270 vir_uniform_ui(c
, c
->loop_cont_block
->index
));
2273 case nir_jump_return
:
2274 unreachable("All returns shouold be lowered\n");
2279 ntq_emit_instr(struct v3d_compile
*c
, nir_instr
*instr
)
2281 switch (instr
->type
) {
2282 case nir_instr_type_deref
:
2283 /* ignored, will be walked by the intrinsic using it. */
2286 case nir_instr_type_alu
:
2287 ntq_emit_alu(c
, nir_instr_as_alu(instr
));
2290 case nir_instr_type_intrinsic
:
2291 ntq_emit_intrinsic(c
, nir_instr_as_intrinsic(instr
));
2294 case nir_instr_type_load_const
:
2295 ntq_emit_load_const(c
, nir_instr_as_load_const(instr
));
2298 case nir_instr_type_ssa_undef
:
2299 ntq_emit_ssa_undef(c
, nir_instr_as_ssa_undef(instr
));
2302 case nir_instr_type_tex
:
2303 ntq_emit_tex(c
, nir_instr_as_tex(instr
));
2306 case nir_instr_type_jump
:
2307 ntq_emit_jump(c
, nir_instr_as_jump(instr
));
2311 fprintf(stderr
, "Unknown NIR instr type: ");
2312 nir_print_instr(instr
, stderr
);
2313 fprintf(stderr
, "\n");
2319 ntq_emit_block(struct v3d_compile
*c
, nir_block
*block
)
2321 nir_foreach_instr(instr
, block
) {
2322 ntq_emit_instr(c
, instr
);
2326 static void ntq_emit_cf_list(struct v3d_compile
*c
, struct exec_list
*list
);
2329 ntq_emit_loop(struct v3d_compile
*c
, nir_loop
*loop
)
2331 bool was_in_control_flow
= c
->in_control_flow
;
2332 c
->in_control_flow
= true;
2334 bool was_uniform_control_flow
= false;
2335 if (!vir_in_nonuniform_control_flow(c
)) {
2336 c
->execute
= vir_MOV(c
, vir_uniform_ui(c
, 0));
2337 was_uniform_control_flow
= true;
2340 struct qblock
*save_loop_cont_block
= c
->loop_cont_block
;
2341 struct qblock
*save_loop_break_block
= c
->loop_break_block
;
2343 c
->loop_cont_block
= vir_new_block(c
);
2344 c
->loop_break_block
= vir_new_block(c
);
2346 vir_link_blocks(c
->cur_block
, c
->loop_cont_block
);
2347 vir_set_emit_block(c
, c
->loop_cont_block
);
2348 ntq_activate_execute_for_block(c
);
2350 ntq_emit_cf_list(c
, &loop
->body
);
2352 /* Re-enable any previous continues now, so our ANYA check below
2355 * XXX: Use the .ORZ flags update, instead.
2357 vir_set_pf(vir_XOR_dest(c
,
2360 vir_uniform_ui(c
, c
->loop_cont_block
->index
)),
2362 vir_MOV_cond(c
, V3D_QPU_COND_IFA
, c
->execute
, vir_uniform_ui(c
, 0));
2364 vir_set_pf(vir_MOV_dest(c
, vir_nop_reg(), c
->execute
), V3D_QPU_PF_PUSHZ
);
2366 struct qinst
*branch
= vir_BRANCH(c
, V3D_QPU_BRANCH_COND_ANYA
);
2367 /* Pixels that were not dispatched or have been discarded should not
2368 * contribute to looping again.
2370 branch
->qpu
.branch
.msfign
= V3D_QPU_MSFIGN_P
;
2371 vir_link_blocks(c
->cur_block
, c
->loop_cont_block
);
2372 vir_link_blocks(c
->cur_block
, c
->loop_break_block
);
2374 vir_set_emit_block(c
, c
->loop_break_block
);
2375 if (was_uniform_control_flow
)
2376 c
->execute
= c
->undef
;
2378 ntq_activate_execute_for_block(c
);
2380 c
->loop_break_block
= save_loop_break_block
;
2381 c
->loop_cont_block
= save_loop_cont_block
;
2385 c
->in_control_flow
= was_in_control_flow
;
2389 ntq_emit_function(struct v3d_compile
*c
, nir_function_impl
*func
)
2391 fprintf(stderr
, "FUNCTIONS not handled.\n");
2396 ntq_emit_cf_list(struct v3d_compile
*c
, struct exec_list
*list
)
2398 foreach_list_typed(nir_cf_node
, node
, node
, list
) {
2399 switch (node
->type
) {
2400 case nir_cf_node_block
:
2401 ntq_emit_block(c
, nir_cf_node_as_block(node
));
2404 case nir_cf_node_if
:
2405 ntq_emit_if(c
, nir_cf_node_as_if(node
));
2408 case nir_cf_node_loop
:
2409 ntq_emit_loop(c
, nir_cf_node_as_loop(node
));
2412 case nir_cf_node_function
:
2413 ntq_emit_function(c
, nir_cf_node_as_function(node
));
2417 fprintf(stderr
, "Unknown NIR node type\n");
2424 ntq_emit_impl(struct v3d_compile
*c
, nir_function_impl
*impl
)
2426 ntq_setup_registers(c
, &impl
->registers
);
2427 ntq_emit_cf_list(c
, &impl
->body
);
2431 nir_to_vir(struct v3d_compile
*c
)
2433 switch (c
->s
->info
.stage
) {
2434 case MESA_SHADER_FRAGMENT
:
2435 c
->payload_w
= vir_MOV(c
, vir_reg(QFILE_REG
, 0));
2436 c
->payload_w_centroid
= vir_MOV(c
, vir_reg(QFILE_REG
, 1));
2437 c
->payload_z
= vir_MOV(c
, vir_reg(QFILE_REG
, 2));
2439 /* V3D 4.x can disable implicit point coordinate varyings if
2440 * they are not used.
2442 if (c
->fs_key
->is_points
&&
2443 (c
->devinfo
->ver
< 40 || program_reads_point_coord(c
))) {
2444 c
->point_x
= emit_fragment_varying(c
, NULL
, 0, 0);
2445 c
->point_y
= emit_fragment_varying(c
, NULL
, 0, 0);
2446 c
->uses_implicit_point_line_varyings
= true;
2447 } else if (c
->fs_key
->is_lines
&& c
->devinfo
->ver
< 40) {
2448 c
->line_x
= emit_fragment_varying(c
, NULL
, 0, 0);
2449 c
->uses_implicit_point_line_varyings
= true;
2452 case MESA_SHADER_COMPUTE
:
2453 /* Set up the TSO for barriers, assuming we do some. */
2454 if (c
->devinfo
->ver
< 42) {
2455 vir_BARRIERID_dest(c
, vir_reg(QFILE_MAGIC
,
2456 V3D_QPU_WADDR_SYNC
));
2459 c
->cs_payload
[0] = vir_MOV(c
, vir_reg(QFILE_REG
, 0));
2460 c
->cs_payload
[1] = vir_MOV(c
, vir_reg(QFILE_REG
, 2));
2462 /* Set up the division between gl_LocalInvocationIndex and
2463 * wg_in_mem in the payload reg.
2465 int wg_size
= (c
->s
->info
.cs
.local_size
[0] *
2466 c
->s
->info
.cs
.local_size
[1] *
2467 c
->s
->info
.cs
.local_size
[2]);
2468 c
->local_invocation_index_bits
=
2469 ffs(util_next_power_of_two(MAX2(wg_size
, 64))) - 1;
2470 assert(c
->local_invocation_index_bits
<= 8);
2472 if (c
->s
->info
.cs
.shared_size
) {
2473 struct qreg wg_in_mem
= vir_SHR(c
, c
->cs_payload
[1],
2474 vir_uniform_ui(c
, 16));
2475 if (c
->s
->info
.cs
.local_size
[0] != 1 ||
2476 c
->s
->info
.cs
.local_size
[1] != 1 ||
2477 c
->s
->info
.cs
.local_size
[2] != 1) {
2479 c
->local_invocation_index_bits
);
2480 int wg_mask
= (1 << wg_bits
) - 1;
2481 wg_in_mem
= vir_AND(c
, wg_in_mem
,
2482 vir_uniform_ui(c
, wg_mask
));
2484 struct qreg shared_per_wg
=
2485 vir_uniform_ui(c
, c
->s
->info
.cs
.shared_size
);
2487 c
->cs_shared_offset
=
2489 vir_uniform(c
, QUNIFORM_SHARED_OFFSET
,0),
2490 vir_UMUL(c
, wg_in_mem
, shared_per_wg
));
2497 if (c
->s
->scratch_size
) {
2498 v3d_setup_spill_base(c
);
2499 c
->spill_size
+= V3D_CHANNELS
* c
->s
->scratch_size
;
2502 if (c
->s
->info
.stage
== MESA_SHADER_FRAGMENT
)
2503 ntq_setup_fs_inputs(c
);
2505 ntq_setup_vpm_inputs(c
);
2507 ntq_setup_outputs(c
);
2509 /* Find the main function and emit the body. */
2510 nir_foreach_function(function
, c
->s
) {
2511 assert(strcmp(function
->name
, "main") == 0);
2512 assert(function
->impl
);
2513 ntq_emit_impl(c
, function
->impl
);
2517 const nir_shader_compiler_options v3d_nir_options
= {
2518 .lower_all_io_to_temps
= true,
2519 .lower_extract_byte
= true,
2520 .lower_extract_word
= true,
2521 .lower_bitfield_insert_to_shifts
= true,
2522 .lower_bitfield_extract_to_shifts
= true,
2523 .lower_bitfield_reverse
= true,
2524 .lower_bit_count
= true,
2525 .lower_cs_local_id_from_index
= true,
2526 .lower_ffract
= true,
2528 .lower_pack_unorm_2x16
= true,
2529 .lower_pack_snorm_2x16
= true,
2530 .lower_pack_unorm_4x8
= true,
2531 .lower_pack_snorm_4x8
= true,
2532 .lower_unpack_unorm_4x8
= true,
2533 .lower_unpack_snorm_4x8
= true,
2534 .lower_pack_half_2x16
= true,
2535 .lower_unpack_half_2x16
= true,
2537 .lower_find_lsb
= true,
2539 .lower_flrp32
= true,
2542 .lower_fsqrt
= true,
2543 .lower_ifind_msb
= true,
2544 .lower_isign
= true,
2545 .lower_ldexp
= true,
2546 .lower_mul_high
= true,
2547 .lower_wpos_pntc
= true,
2548 .lower_rotate
= true,
2552 * When demoting a shader down to single-threaded, removes the THRSW
2553 * instructions (one will still be inserted at v3d_vir_to_qpu() for the
2557 vir_remove_thrsw(struct v3d_compile
*c
)
2559 vir_for_each_block(block
, c
) {
2560 vir_for_each_inst_safe(inst
, block
) {
2561 if (inst
->qpu
.sig
.thrsw
)
2562 vir_remove_instruction(c
, inst
);
2566 c
->last_thrsw
= NULL
;
2570 vir_emit_last_thrsw(struct v3d_compile
*c
)
2572 /* On V3D before 4.1, we need a TMU op to be outstanding when thread
2573 * switching, so disable threads if we didn't do any TMU ops (each of
2574 * which would have emitted a THRSW).
2576 if (!c
->last_thrsw_at_top_level
&& c
->devinfo
->ver
< 41) {
2579 vir_remove_thrsw(c
);
2583 /* If we're threaded and the last THRSW was in conditional code, then
2584 * we need to emit another one so that we can flag it as the last
2587 if (c
->last_thrsw
&& !c
->last_thrsw_at_top_level
) {
2588 assert(c
->devinfo
->ver
>= 41);
2592 /* If we're threaded, then we need to mark the last THRSW instruction
2593 * so we can emit a pair of them at QPU emit time.
2595 * For V3D 4.x, we can spawn the non-fragment shaders already in the
2596 * post-last-THRSW state, so we can skip this.
2598 if (!c
->last_thrsw
&& c
->s
->info
.stage
== MESA_SHADER_FRAGMENT
) {
2599 assert(c
->devinfo
->ver
>= 41);
2604 c
->last_thrsw
->is_last_thrsw
= true;
2607 /* There's a flag in the shader for "center W is needed for reasons other than
2608 * non-centroid varyings", so we just walk the program after VIR optimization
2609 * to see if it's used. It should be harmless to set even if we only use
2610 * center W for varyings.
2613 vir_check_payload_w(struct v3d_compile
*c
)
2615 if (c
->s
->info
.stage
!= MESA_SHADER_FRAGMENT
)
2618 vir_for_each_inst_inorder(inst
, c
) {
2619 for (int i
= 0; i
< vir_get_nsrc(inst
); i
++) {
2620 if (inst
->src
[i
].file
== QFILE_REG
&&
2621 inst
->src
[i
].index
== 0) {
2622 c
->uses_center_w
= true;
2631 v3d_nir_to_vir(struct v3d_compile
*c
)
2633 if (V3D_DEBUG
& (V3D_DEBUG_NIR
|
2634 v3d_debug_flag_for_shader_stage(c
->s
->info
.stage
))) {
2635 fprintf(stderr
, "%s prog %d/%d NIR:\n",
2636 vir_get_stage_name(c
),
2637 c
->program_id
, c
->variant_id
);
2638 nir_print_shader(c
->s
, stderr
);
2643 /* Emit the last THRSW before STVPM and TLB writes. */
2644 vir_emit_last_thrsw(c
);
2646 switch (c
->s
->info
.stage
) {
2647 case MESA_SHADER_FRAGMENT
:
2650 case MESA_SHADER_VERTEX
:
2653 case MESA_SHADER_COMPUTE
:
2656 unreachable("bad stage");
2659 if (V3D_DEBUG
& (V3D_DEBUG_VIR
|
2660 v3d_debug_flag_for_shader_stage(c
->s
->info
.stage
))) {
2661 fprintf(stderr
, "%s prog %d/%d pre-opt VIR:\n",
2662 vir_get_stage_name(c
),
2663 c
->program_id
, c
->variant_id
);
2665 fprintf(stderr
, "\n");
2670 vir_check_payload_w(c
);
2672 /* XXX perf: On VC4, we do a VIR-level instruction scheduling here.
2673 * We used that on that platform to pipeline TMU writes and reduce the
2674 * number of thread switches, as well as try (mostly successfully) to
2675 * reduce maximum register pressure to allow more threads. We should
2676 * do something of that sort for V3D -- either instruction scheduling
2677 * here, or delay the the THRSW and LDTMUs from our texture
2678 * instructions until the results are needed.
2681 if (V3D_DEBUG
& (V3D_DEBUG_VIR
|
2682 v3d_debug_flag_for_shader_stage(c
->s
->info
.stage
))) {
2683 fprintf(stderr
, "%s prog %d/%d VIR:\n",
2684 vir_get_stage_name(c
),
2685 c
->program_id
, c
->variant_id
);
2687 fprintf(stderr
, "\n");
2690 /* Attempt to allocate registers for the temporaries. If we fail,
2691 * reduce thread count and try again.
2693 int min_threads
= (c
->devinfo
->ver
>= 41) ? 2 : 1;
2694 struct qpu_reg
*temp_registers
;
2697 temp_registers
= v3d_register_allocate(c
, &spilled
);
2704 if (c
->threads
== min_threads
) {
2705 fprintf(stderr
, "Failed to register allocate at %d threads:\n",
2714 if (c
->threads
== 1)
2715 vir_remove_thrsw(c
);
2719 (V3D_DEBUG
& (V3D_DEBUG_VIR
|
2720 v3d_debug_flag_for_shader_stage(c
->s
->info
.stage
)))) {
2721 fprintf(stderr
, "%s prog %d/%d spilled VIR:\n",
2722 vir_get_stage_name(c
),
2723 c
->program_id
, c
->variant_id
);
2725 fprintf(stderr
, "\n");
2728 v3d_vir_to_qpu(c
, temp_registers
);