[Mesa-dev] [PATCH 3/3] nir: Conditionalize the POW reconstruction on shader compiler options.

Eric Anholt eric at anholt.net
Mon Feb 2 16:29:27 PST 2015


Mesa has a shader compiler struct flagging whether GLSL IR's opt_algebraic
and other passes should try and generate certain types of opcodes or
patterns.  Extend that to NIR by defining our own struct, which is
automatically generated from the Mesa struct in glsl_to_nir and provided
directly by the driver in TGSI-to-NIR.

v2: Split out the previous two prep patches.
---
 src/gallium/drivers/vc4/vc4_program.c | 1 +
 src/glsl/nir/glsl_to_nir.cpp          | 3 +++
 src/glsl/nir/nir.h                    | 1 +
 src/glsl/nir/nir_opt_algebraic.py     | 4 ++--
 4 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/vc4/vc4_program.c b/src/gallium/drivers/vc4/vc4_program.c
index 3c76025..9c178c2 100644
--- a/src/gallium/drivers/vc4/vc4_program.c
+++ b/src/gallium/drivers/vc4/vc4_program.c
@@ -2098,6 +2098,7 @@ nir_to_qir(struct vc4_compile *c)
 }
 
 static const nir_shader_compiler_options nir_options = {
+        .lower_fpow = true,
 };
 
 static struct vc4_compile *
diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp
index 929291d..8136051 100644
--- a/src/glsl/nir/glsl_to_nir.cpp
+++ b/src/glsl/nir/glsl_to_nir.cpp
@@ -142,6 +142,9 @@ glsl_to_nir(exec_list *ir, _mesa_glsl_parse_state *state,
          nir_shader_compiler_options *new_options =
             rzalloc(ctx, nir_shader_compiler_options);
          options = gl_options->NirOptions = new_options;
+
+         if (gl_options->EmitNoPow)
+            new_options->lower_fpow = true;
       } else {
          options = gl_options->NirOptions;
       }
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index cc0aed1..a2163ed 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1327,6 +1327,7 @@ typedef struct nir_function {
                   exec_list_get_head(&(func)->overload_list), node)
 
 typedef struct nir_shader_compiler_options {
+   bool lower_fpow;
 } nir_shader_compiler_options;
 
 typedef struct nir_shader {
diff --git a/src/glsl/nir/nir_opt_algebraic.py b/src/glsl/nir/nir_opt_algebraic.py
index c635ab3..2414f71 100644
--- a/src/glsl/nir/nir_opt_algebraic.py
+++ b/src/glsl/nir/nir_opt_algebraic.py
@@ -107,8 +107,8 @@ optimizations = [
    (('fexp',  ('flog',  a)), a), # e^ln(a)  = a
    (('flog2', ('fexp2', a)), a), # lg2(2^a) = a
    (('flog',  ('fexp',  a)), a), # ln(e^a)  = a
-   (('fexp2', ('fmul', ('flog2', a), b)), ('fpow', a, b)), # 2^(lg2(a)*b) = a^b
-   (('fexp',  ('fmul', ('flog', a), b)),  ('fpow', a, b)), # e^(ln(a)*b) = a^b
+   (('fexp2', ('fmul', ('flog2', a), b)), ('fpow', a, b), '!options->lower_fpow'), # 2^(lg2(a)*b) = a^b
+   (('fexp',  ('fmul', ('flog', a), b)),  ('fpow', a, b), '!options->lower_fpow'), # e^(ln(a)*b) = a^b
    (('fpow', a, 1.0), a),
    (('fpow', a, 2.0), ('fmul', a, a)),
    (('fpow', 2.0, a), ('fexp2', a)),
-- 
2.1.4



More information about the mesa-dev mailing list