Re: [Mesa-dev] [PATCH v5 08/34] nvir/nir: run some passes to make the conversion easier

2018-03-11 Thread Pierre Moreau
On 2018-02-20 — 22:02, Karol Herbst wrote:
> v2: add constant_folding
> 
> Signed-off-by: Karol Herbst 
> ---
>  .../drivers/nouveau/codegen/nv50_ir_from_nir.cpp   | 40 
> ++
>  1 file changed, 40 insertions(+)
> 
> diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp 
> b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp
> index 73527d4800..148db464bd 100644
> --- a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp
> +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp
> @@ -29,6 +29,12 @@
>  #include "codegen/nv50_ir_lowering_helper.h"
>  #include "codegen/nv50_ir_util.h"
>  
> +static int
> +type_size(const struct glsl_type *type)

From looking at the implementation of glsl_count_attribute_slots, it seems to
return the number of elements more than the number of bits/bytes taken up by
the type. So I should change the name of this function.

> +{
> +   return glsl_count_attribute_slots(type, false);
> +}
> +
>  namespace {
>  
>  using namespace nv50_ir;
> @@ -50,6 +56,40 @@ Converter::Converter(Program *prog, nir_shader *nir, 
> nv50_ir_prog_info *info)
>  bool
>  Converter::run()
>  {
> +   bool progress;
> +
> +   if (prog->dbgFlags & NV50_IR_DEBUG_BASIC)
> +  nir_print_shader(nir, stderr);
> +
> +   // converts intrinsic load_var to intrinsic load_uniform
> +   NIR_PASS_V(nir, nir_lower_io, nir_var_all, type_size, 
> (nir_lower_io_options)0);
> +
> +   NIR_PASS_V(nir, nir_lower_regs_to_ssa);
> +   NIR_PASS_V(nir, nir_lower_load_const_to_scalar);
> +
> +   do {
> +  progress = false;
> +  // we need this to_ssa otherwise the later opts are less effective
> +  NIR_PASS_V(nir, nir_lower_vars_to_ssa);

Do you need to lower to SSA on every loop run, shouldn’t it be enough to only
run it once?

> +  NIR_PASS(progress, nir, nir_lower_alu_to_scalar);
> +  NIR_PASS(progress, nir, nir_lower_phis_to_scalar);
> +  // some ops depend on having constant as sources, but those can also
> +  // point to expressions made from constants like 0 + 1
> +  NIR_PASS(progress, nir, nir_opt_constant_folding);
> +  NIR_PASS(progress, nir, nir_copy_prop);
> +  NIR_PASS(progress, nir, nir_opt_dce);
> +  NIR_PASS(progress, nir, nir_opt_dead_cf);
> +   } while (progress);
> +
> +   NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_local);
> +   NIR_PASS_V(nir, nir_convert_from_ssa, true);
> +
> +   /* Garbage collect dead instructions */
> +   nir_sweep(nir);
> +
> +   if (prog->dbgFlags & NV50_IR_DEBUG_BASIC)
> +  nir_print_shader(nir, stderr);
> +
> return false;
>  }
>  
> -- 
> 2.14.3
> 
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


signature.asc
Description: PGP signature
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v5 08/34] nvir/nir: run some passes to make the conversion easier

2018-02-20 Thread Karol Herbst
v2: add constant_folding

Signed-off-by: Karol Herbst 
---
 .../drivers/nouveau/codegen/nv50_ir_from_nir.cpp   | 40 ++
 1 file changed, 40 insertions(+)

diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp 
b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp
index 73527d4800..148db464bd 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp
@@ -29,6 +29,12 @@
 #include "codegen/nv50_ir_lowering_helper.h"
 #include "codegen/nv50_ir_util.h"
 
+static int
+type_size(const struct glsl_type *type)
+{
+   return glsl_count_attribute_slots(type, false);
+}
+
 namespace {
 
 using namespace nv50_ir;
@@ -50,6 +56,40 @@ Converter::Converter(Program *prog, nir_shader *nir, 
nv50_ir_prog_info *info)
 bool
 Converter::run()
 {
+   bool progress;
+
+   if (prog->dbgFlags & NV50_IR_DEBUG_BASIC)
+  nir_print_shader(nir, stderr);
+
+   // converts intrinsic load_var to intrinsic load_uniform
+   NIR_PASS_V(nir, nir_lower_io, nir_var_all, type_size, 
(nir_lower_io_options)0);
+
+   NIR_PASS_V(nir, nir_lower_regs_to_ssa);
+   NIR_PASS_V(nir, nir_lower_load_const_to_scalar);
+
+   do {
+  progress = false;
+  // we need this to_ssa otherwise the later opts are less effective
+  NIR_PASS_V(nir, nir_lower_vars_to_ssa);
+  NIR_PASS(progress, nir, nir_lower_alu_to_scalar);
+  NIR_PASS(progress, nir, nir_lower_phis_to_scalar);
+  // some ops depend on having constant as sources, but those can also
+  // point to expressions made from constants like 0 + 1
+  NIR_PASS(progress, nir, nir_opt_constant_folding);
+  NIR_PASS(progress, nir, nir_copy_prop);
+  NIR_PASS(progress, nir, nir_opt_dce);
+  NIR_PASS(progress, nir, nir_opt_dead_cf);
+   } while (progress);
+
+   NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_local);
+   NIR_PASS_V(nir, nir_convert_from_ssa, true);
+
+   /* Garbage collect dead instructions */
+   nir_sweep(nir);
+
+   if (prog->dbgFlags & NV50_IR_DEBUG_BASIC)
+  nir_print_shader(nir, stderr);
+
return false;
 }
 
-- 
2.14.3

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev