[Mesa-dev] [PATCH 9/9] nir: Report progress from nir_normalize_cubemap_coords().

Kenneth Graunke kenneth at whitecape.org
Fri Sep 18 08:37:15 PDT 2015


This also required adding a struct.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/glsl/nir/nir.h                          |  2 +-
 src/glsl/nir/nir_normalize_cubemap_coords.c | 28 +++++++++++++++++++++-------
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index 8a6a75f..1452b4c 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1845,7 +1845,7 @@ void nir_lower_clip_fs(nir_shader *shader, unsigned ucp_enables);
 void nir_lower_atomics(nir_shader *shader);
 void nir_lower_to_source_mods(nir_shader *shader);
 
-void nir_normalize_cubemap_coords(nir_shader *shader);
+bool nir_normalize_cubemap_coords(nir_shader *shader);
 
 void nir_live_variables_impl(nir_function_impl *impl);
 bool nir_ssa_defs_interfere(nir_ssa_def *a, nir_ssa_def *b);
diff --git a/src/glsl/nir/nir_normalize_cubemap_coords.c b/src/glsl/nir/nir_normalize_cubemap_coords.c
index dd6de40..1dfe3d5 100644
--- a/src/glsl/nir/nir_normalize_cubemap_coords.c
+++ b/src/glsl/nir/nir_normalize_cubemap_coords.c
@@ -33,10 +33,16 @@
  * or 1.0.  This is based on the old GLSL IR based pass by Eric.
  */
 
+struct normcube_state {
+   nir_builder b;
+   bool progress;
+};
+
 static bool
 normalize_cubemap_coords_block(nir_block *block, void *void_state)
 {
-   nir_builder *b = void_state;
+   struct normcube_state *state = void_state;
+   nir_builder *b = &state->b;
 
    nir_foreach_instr(block, instr) {
       if (instr->type != nir_instr_type_tex)
@@ -77,29 +83,37 @@ normalize_cubemap_coords_block(nir_block *block, void *void_state)
          nir_instr_rewrite_src(&tex->instr,
                                &tex->src[i].src,
                                nir_src_for_ssa(normalized));
+
+         state->progress = true;
       }
    }
 
    return true;
 }
 
-static void
+static bool
 normalize_cubemap_coords_impl(nir_function_impl *impl)
 {
-   nir_builder b;
-   nir_builder_init(&b, impl);
+   struct normcube_state state;
+   nir_builder_init(&state.b, impl);
+   state.progress = false;
 
-   nir_foreach_block(impl, normalize_cubemap_coords_block, &b);
+   nir_foreach_block(impl, normalize_cubemap_coords_block, &state);
 
    nir_metadata_preserve(impl, nir_metadata_block_index |
                                nir_metadata_dominance);
+   return state.progress;
 }
 
-void
+bool
 nir_normalize_cubemap_coords(nir_shader *shader)
 {
+   bool progress = false;
+
    nir_foreach_overload(shader, overload) {
       if (overload->impl)
-         normalize_cubemap_coords_impl(overload->impl);
+         progress = normalize_cubemap_coords_impl(overload->impl) || progress;
    }
+
+   return progress;
 }
-- 
2.5.1



More information about the mesa-dev mailing list