From: Christian Gmeiner Date: Mon, 29 Jun 2020 11:22:33 +0000 (+0200) Subject: etnaviv: move etna_lower_alu(..) to etnaviv_nir.c X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1636e14cfd4ff310e5be76ab1ff8a60c548cb817;p=mesa.git etnaviv: move etna_lower_alu(..) to etnaviv_nir.c Signed-off-by: Christian Gmeiner Acked-by: Jonathan Marek Part-of: --- diff --git a/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c b/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c index 9a4b461d3b0..f04b97b0d46 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c +++ b/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c @@ -111,73 +111,6 @@ etna_alu_to_scalar_filter_cb(const nir_instr *instr, const void *data) return false; } -static void -etna_lower_alu_impl(nir_function_impl *impl, bool has_new_transcendentals) -{ - nir_shader *shader = impl->function->shader; - - nir_builder b; - nir_builder_init(&b, impl); - - /* in a seperate loop so we can apply the multiple-uniform logic to the new fmul */ - nir_foreach_block(block, impl) { - nir_foreach_instr_safe(instr, block) { - if (instr->type != nir_instr_type_alu) - continue; - - nir_alu_instr *alu = nir_instr_as_alu(instr); - /* multiply sin/cos src by constant - * TODO: do this earlier (but it breaks const_prop opt) - */ - if (alu->op == nir_op_fsin || alu->op == nir_op_fcos) { - b.cursor = nir_before_instr(instr); - - nir_ssa_def *imm = has_new_transcendentals ? - nir_imm_float(&b, 1.0 / M_PI) : - nir_imm_float(&b, 2.0 / M_PI); - - nir_instr_rewrite_src(instr, &alu->src[0].src, - nir_src_for_ssa(nir_fmul(&b, alu->src[0].src.ssa, imm))); - } - - /* change transcendental ops to vec2 and insert vec1 mul for the result - * TODO: do this earlier (but it breaks with optimizations) - */ - if (has_new_transcendentals && ( - alu->op == nir_op_fdiv || alu->op == nir_op_flog2 || - alu->op == nir_op_fsin || alu->op == nir_op_fcos)) { - nir_ssa_def *ssa = &alu->dest.dest.ssa; - - assert(ssa->num_components == 1); - - nir_alu_instr *mul = nir_alu_instr_create(shader, nir_op_fmul); - mul->src[0].src = mul->src[1].src = nir_src_for_ssa(ssa); - mul->src[1].swizzle[0] = 1; - - mul->dest.write_mask = 1; - nir_ssa_dest_init(&mul->instr, &mul->dest.dest, 1, 32, NULL); - - ssa->num_components = 2; - - mul->dest.saturate = alu->dest.saturate; - alu->dest.saturate = 0; - - nir_instr_insert_after(instr, &mul->instr); - - nir_ssa_def_rewrite_uses_after(ssa, nir_src_for_ssa(&mul->dest.dest.ssa), &mul->instr); - } - } - } -} - -static void etna_lower_alu(nir_shader *shader, bool has_new_transcendentals) -{ - nir_foreach_function(function, shader) { - if (function->impl) - etna_lower_alu_impl(function->impl, has_new_transcendentals); - } -} - static void emit_inst(struct etna_compile *c, struct etna_inst *inst) { diff --git a/src/gallium/drivers/etnaviv/etnaviv_nir.c b/src/gallium/drivers/etnaviv/etnaviv_nir.c index 5ac5d283708..13aa73b0839 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_nir.c +++ b/src/gallium/drivers/etnaviv/etnaviv_nir.c @@ -192,3 +192,71 @@ etna_lower_io(nir_shader *shader, struct etna_shader_variant *v) } } } + +static void +etna_lower_alu_impl(nir_function_impl *impl, bool has_new_transcendentals) +{ + nir_shader *shader = impl->function->shader; + + nir_builder b; + nir_builder_init(&b, impl); + + /* in a seperate loop so we can apply the multiple-uniform logic to the new fmul */ + nir_foreach_block(block, impl) { + nir_foreach_instr_safe(instr, block) { + if (instr->type != nir_instr_type_alu) + continue; + + nir_alu_instr *alu = nir_instr_as_alu(instr); + /* multiply sin/cos src by constant + * TODO: do this earlier (but it breaks const_prop opt) + */ + if (alu->op == nir_op_fsin || alu->op == nir_op_fcos) { + b.cursor = nir_before_instr(instr); + + nir_ssa_def *imm = has_new_transcendentals ? + nir_imm_float(&b, 1.0 / M_PI) : + nir_imm_float(&b, 2.0 / M_PI); + + nir_instr_rewrite_src(instr, &alu->src[0].src, + nir_src_for_ssa(nir_fmul(&b, alu->src[0].src.ssa, imm))); + } + + /* change transcendental ops to vec2 and insert vec1 mul for the result + * TODO: do this earlier (but it breaks with optimizations) + */ + if (has_new_transcendentals && ( + alu->op == nir_op_fdiv || alu->op == nir_op_flog2 || + alu->op == nir_op_fsin || alu->op == nir_op_fcos)) { + nir_ssa_def *ssa = &alu->dest.dest.ssa; + + assert(ssa->num_components == 1); + + nir_alu_instr *mul = nir_alu_instr_create(shader, nir_op_fmul); + mul->src[0].src = mul->src[1].src = nir_src_for_ssa(ssa); + mul->src[1].swizzle[0] = 1; + + mul->dest.write_mask = 1; + nir_ssa_dest_init(&mul->instr, &mul->dest.dest, 1, 32, NULL); + + ssa->num_components = 2; + + mul->dest.saturate = alu->dest.saturate; + alu->dest.saturate = 0; + + nir_instr_insert_after(instr, &mul->instr); + + nir_ssa_def_rewrite_uses_after(ssa, nir_src_for_ssa(&mul->dest.dest.ssa), &mul->instr); + } + } + } +} + +void +etna_lower_alu(nir_shader *shader, bool has_new_transcendentals) +{ + nir_foreach_function(function, shader) { + if (function->impl) + etna_lower_alu_impl(function->impl, has_new_transcendentals); + } +} diff --git a/src/gallium/drivers/etnaviv/etnaviv_nir.h b/src/gallium/drivers/etnaviv/etnaviv_nir.h index fc312305331..44258a8711a 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_nir.h +++ b/src/gallium/drivers/etnaviv/etnaviv_nir.h @@ -31,4 +31,7 @@ void etna_lower_io(nir_shader *shader, struct etna_shader_variant *v); +void +etna_lower_alu(nir_shader *shader, bool has_new_transcendentals); + #endif