nir: Introduce a nir_vec_scalars() helper using nir_ssa_scalar.
Many users of nir_vec() do so by nir_channel()-ing a new ssa defs as movs from other vectors to put the new vector together, which then just have to get copy-propagated into the ALU srcs and DCEed away the temporary movs. If they instead take nir_ssa_scalar, we can avoid that extra work. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Daniel Schürmann <daniel@schuermann.dev> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14865>
This commit is contained in:
@@ -215,6 +215,32 @@ nir_build_alu_src_arr(nir_builder *build, nir_op op, nir_ssa_def **srcs)
|
||||
return nir_builder_alu_instr_finish_and_insert(build, instr);
|
||||
}
|
||||
|
||||
nir_ssa_def *
|
||||
nir_vec_scalars(nir_builder *build, nir_ssa_scalar *comp, unsigned num_components)
|
||||
{
|
||||
nir_op op = nir_op_vec(num_components);
|
||||
nir_alu_instr *instr = nir_alu_instr_create(build->shader, op);
|
||||
if (!instr)
|
||||
return NULL;
|
||||
|
||||
for (unsigned i = 0; i < num_components; i++) {
|
||||
instr->src[i].src = nir_src_for_ssa(comp[i].def);
|
||||
instr->src[i].swizzle[0] = comp[i].comp;
|
||||
}
|
||||
instr->exact = build->exact;
|
||||
|
||||
/* Note: not reusing nir_builder_alu_instr_finish_and_insert() because it
|
||||
* can't re-guess the num_components when num_components == 1 (nir_op_mov).
|
||||
*/
|
||||
nir_ssa_dest_init(&instr->instr, &instr->dest.dest, num_components,
|
||||
comp[0].def->bit_size, NULL);
|
||||
instr->dest.write_mask = (1 << num_components) - 1;
|
||||
|
||||
nir_builder_instr_insert(build, &instr->instr);
|
||||
|
||||
return &instr->dest.dest.ssa;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns a nir_src into a nir_ssa_def * so it can be passed to
|
||||
* nir_build_alu()-based builder calls.
|
||||
|
@@ -371,6 +371,9 @@ nir_vec(nir_builder *build, nir_ssa_def **comp, unsigned num_components)
|
||||
return nir_build_alu_src_arr(build, nir_op_vec(num_components), comp);
|
||||
}
|
||||
|
||||
nir_ssa_def *
|
||||
nir_vec_scalars(nir_builder *build, nir_ssa_scalar *comp, unsigned num_components);
|
||||
|
||||
static inline nir_ssa_def *
|
||||
nir_mov_alu(nir_builder *build, nir_alu_src src, unsigned num_components)
|
||||
{
|
||||
|
Reference in New Issue
Block a user