#include "util/u_format.h"
/**
- * Walks the NIR generated by TGSI-to-NIR to lower its io intrinsics into
- * something amenable to the VC4 architecture.
+ * Walks the NIR generated by TGSI-to-NIR or GLSL-to-NIR to lower its io
+ * intrinsics into something amenable to the VC4 architecture.
*
* Currently, it splits VS inputs and uniforms into scalars, drops any
* non-position outputs in coordinate shaders, and fixes up the addressing on
*/
static void
-replace_intrinsic_with_vec4(nir_builder *b, nir_intrinsic_instr *intr,
- nir_ssa_def **comps)
+replace_intrinsic_with_vec(nir_builder *b, nir_intrinsic_instr *intr,
+ nir_ssa_def **comps)
{
- /* Batch things back together into a vec4. This will get split by the
- * later ALU scalarization pass.
+ /* Batch things back together into a vector. This will get split by
+ * the later ALU scalarization pass.
*/
- nir_ssa_def *vec = nir_vec4(b, comps[0], comps[1], comps[2], comps[3]);
+ nir_ssa_def *vec = nir_vec(b, comps, intr->num_components);
/* Replace the old intrinsic with a reference to our reconstructed
- * vec4.
+ * vector.
*/
nir_ssa_def_rewrite_uses(&intr->dest.ssa, nir_src_for_ssa(vec));
nir_instr_remove(&intr->instr);
enum pipe_format format = c->vs_key->attr_formats[attr];
uint32_t attr_size = util_format_get_blocksize(format);
- /* All TGSI-to-NIR inputs are vec4. */
- assert(intr->num_components == 4);
-
/* We only accept direct outputs and TGSI only ever gives them to us
* with an offset value of 0.
*/
util_format_description(format);
nir_ssa_def *dests[4];
- for (int i = 0; i < 4; i++) {
+ for (int i = 0; i < intr->num_components; i++) {
uint8_t swiz = desc->swizzle[i];
dests[i] = vc4_nir_get_vattr_channel_vpm(c, b, vpm_reads, swiz,
desc);
}
}
- replace_intrinsic_with_vec4(b, intr, dests);
+ replace_intrinsic_with_vec(b, intr, dests);
}
static bool
vc4_nir_lower_uniform(struct vc4_compile *c, nir_builder *b,
nir_intrinsic_instr *intr)
{
- /* All TGSI-to-NIR uniform loads are vec4, but we need byte offsets
- * in the backend.
- */
- if (intr->num_components == 1)
- return;
- assert(intr->num_components == 4);
-
b->cursor = nir_before_instr(&intr->instr);
- /* Generate scalar loads equivalent to the original VEC4. */
+ /* Generate scalar loads equivalent to the original vector. */
nir_ssa_def *dests[4];
for (unsigned i = 0; i < intr->num_components; i++) {
nir_intrinsic_instr *intr_comp =
nir_builder_instr_insert(b, &intr_comp->instr);
}
- replace_intrinsic_with_vec4(b, intr, dests);
+ replace_intrinsic_with_vec(b, intr, dests);
}
static void