aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium
diff options
context:
space:
mode:
authorJonathan Marek <[email protected]>2019-09-12 13:51:32 -0400
committerJonathan Marek <[email protected]>2019-09-28 00:34:43 -0400
commitdc3656c9c48915cd86f460021438b3a9ef85ef67 (patch)
tree319930f7cad2ef75d08ea34fe6df857b700d8689 /src/gallium
parentc4f63be5a6d04721b21ff7937900ca6699fbf1d7 (diff)
etnaviv: nir: make lower_alu easier to follow
Signed-off-by: Jonathan Marek <[email protected]> Reviewed-by: Christian Gmeiner <[email protected]>
Diffstat (limited to 'src/gallium')
-rw-r--r--src/gallium/drivers/etnaviv/etnaviv_compiler_nir_emit.h68
1 files changed, 36 insertions, 32 deletions
diff --git a/src/gallium/drivers/etnaviv/etnaviv_compiler_nir_emit.h b/src/gallium/drivers/etnaviv/etnaviv_compiler_nir_emit.h
index 0e0e0a5fd18..725ac481920 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_compiler_nir_emit.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_compiler_nir_emit.h
@@ -1239,37 +1239,9 @@ lower_alu(struct state *state, nir_alu_instr *alu)
switch (alu->op) {
case nir_op_vec2:
case nir_op_vec3:
- case nir_op_vec4: {
- nir_const_value value[4];
- unsigned num_components = 0;
-
- for (unsigned i = 0; i < info->num_inputs; i++) {
- nir_const_value *cv = nir_src_as_const_value(alu->src[i].src);
- if (cv)
- value[num_components++] = cv[alu->src[i].swizzle[0]];
- }
-
- if (num_components <= 1) /* nothing to do */
- break;
-
- nir_ssa_def *def = nir_build_imm(&b, num_components, 32, value);
-
- if (num_components == info->num_inputs) {
- nir_ssa_def_rewrite_uses(&alu->dest.dest.ssa, nir_src_for_ssa(def));
- nir_instr_remove(&alu->instr);
- return;
- }
-
- for (unsigned i = 0, j = 0; i < info->num_inputs; i++) {
- nir_const_value *cv = nir_src_as_const_value(alu->src[i].src);
- if (!cv)
- continue;
-
- nir_instr_rewrite_src(&alu->instr, &alu->src[i].src, nir_src_for_ssa(def));
- alu->src[i].swizzle[0] = j++;
- }
- } break;
- default: {
+ case nir_op_vec4:
+ break;
+ default:
/* pre-GC7000L can only have 1 uniform src per instruction */
if (state->c->specs->halti >= 5)
return;
@@ -1327,7 +1299,39 @@ lower_alu(struct state *state, nir_alu_instr *alu)
nir_ssa_def *mov = nir_mov(&b, alu->src[i].src.ssa);
nir_instr_rewrite_src(&alu->instr, &alu->src[i].src, nir_src_for_ssa(mov));
}
- } return;
+ return;
+ }
+
+ nir_const_value value[4];
+ unsigned num_components = 0;
+
+ for (unsigned i = 0; i < info->num_inputs; i++) {
+ nir_const_value *cv = nir_src_as_const_value(alu->src[i].src);
+ if (cv)
+ value[num_components++] = cv[alu->src[i].swizzle[0]];
+ }
+
+ /* if there is more than one constant source to the vecN, combine them
+ * into a single load_const (removing the vecN completely if all components
+ * are constant)
+ */
+ if (num_components > 1) {
+ nir_ssa_def *def = nir_build_imm(&b, num_components, 32, value);
+
+ if (num_components == info->num_inputs) {
+ nir_ssa_def_rewrite_uses(&alu->dest.dest.ssa, nir_src_for_ssa(def));
+ nir_instr_remove(&alu->instr);
+ return;
+ }
+
+ for (unsigned i = 0, j = 0; i < info->num_inputs; i++) {
+ nir_const_value *cv = nir_src_as_const_value(alu->src[i].src);
+ if (!cv)
+ continue;
+
+ nir_instr_rewrite_src(&alu->instr, &alu->src[i].src, nir_src_for_ssa(def));
+ alu->src[i].swizzle[0] = j++;
+ }
}
unsigned finished_write_mask = 0;