[Mesa-dev] [PATCH v4 009/129] nir: add deref lowering sanity checking

Jason Ekstrand jason at jlekstrand.net
Fri Jun 1 05:01:52 UTC 2018


From: Rob Clark <robdclark at gmail.com>

This will be removed at the end of the transition, but add some tracking
plus asserts to help ensure that lowering passes are called at the
correct point (pre or post deref instruction lowering) as passes are
converted and the point where lower_deref_instrs() is called is moved.

Signed-off-by: Rob Clark <robdclark at gmail.com>
---
 src/compiler/glsl/gl_nir_lower_atomics.c               |  2 ++
 src/compiler/glsl/gl_nir_lower_samplers.c              |  2 ++
 src/compiler/glsl/gl_nir_lower_samplers_as_deref.c     |  2 ++
 src/compiler/nir/nir.c                                 |  1 +
 src/compiler/nir/nir.h                                 | 12 ++++++++++++
 src/compiler/nir/nir_clone.c                           |  1 +
 src/compiler/nir/nir_deref.c                           |  2 ++
 src/compiler/nir/nir_gather_info.c                     |  2 ++
 src/compiler/nir/nir_linking_helpers.c                 |  2 ++
 src/compiler/nir/nir_loop_analyze.c                    |  1 +
 src/compiler/nir/nir_lower_alpha_test.c                |  2 ++
 src/compiler/nir/nir_lower_clamp_color_outputs.c       |  2 ++
 src/compiler/nir/nir_lower_clip_cull_distance_arrays.c |  2 ++
 src/compiler/nir/nir_lower_drawpixels.c                |  5 +++++
 src/compiler/nir/nir_lower_global_vars_to_local.c      |  3 +++
 src/compiler/nir/nir_lower_indirect_derefs.c           |  2 ++
 src/compiler/nir/nir_lower_io.c                        |  2 ++
 src/compiler/nir/nir_lower_io_arrays_to_elements.c     |  5 +++++
 src/compiler/nir/nir_lower_io_to_scalar.c              |  2 ++
 src/compiler/nir/nir_lower_io_types.c                  |  2 ++
 src/compiler/nir/nir_lower_locals_to_regs.c            |  2 ++
 src/compiler/nir/nir_lower_phis_to_scalar.c            |  2 ++
 src/compiler/nir/nir_lower_system_values.c             |  2 ++
 src/compiler/nir/nir_lower_tex.c                       |  2 ++
 src/compiler/nir/nir_lower_var_copies.c                |  2 ++
 src/compiler/nir/nir_lower_vars_to_ssa.c               |  2 ++
 src/compiler/nir/nir_lower_wpos_center.c               |  2 ++
 src/compiler/nir/nir_lower_wpos_ytransform.c           |  2 ++
 src/compiler/nir/nir_opt_copy_prop_vars.c              |  2 ++
 src/compiler/nir/nir_opt_peephole_select.c             |  2 ++
 src/compiler/nir/nir_opt_undef.c                       |  2 ++
 src/compiler/nir/nir_propagate_invariant.c             |  2 ++
 src/compiler/nir/nir_remove_dead_variables.c           |  2 ++
 src/compiler/nir/nir_serialize.c                       |  2 ++
 src/compiler/nir/nir_split_var_copies.c                |  2 ++
 src/mesa/state_tracker/st_nir_lower_builtin.c          |  1 +
 36 files changed, 85 insertions(+)

diff --git a/src/compiler/glsl/gl_nir_lower_atomics.c b/src/compiler/glsl/gl_nir_lower_atomics.c
index e203b39..35a304a 100644
--- a/src/compiler/glsl/gl_nir_lower_atomics.c
+++ b/src/compiler/glsl/gl_nir_lower_atomics.c
@@ -185,6 +185,8 @@ gl_nir_lower_atomics(nir_shader *shader,
 {
    bool progress = false;
 
+   nir_assert_lowered_derefs(shader, nir_lower_atomic_counter_derefs);
+
    nir_foreach_function(function, shader) {
       if (!function->impl)
          continue;
diff --git a/src/compiler/glsl/gl_nir_lower_samplers.c b/src/compiler/glsl/gl_nir_lower_samplers.c
index a53fabb..3722fe6 100644
--- a/src/compiler/glsl/gl_nir_lower_samplers.c
+++ b/src/compiler/glsl/gl_nir_lower_samplers.c
@@ -154,6 +154,8 @@ gl_nir_lower_samplers(nir_shader *shader,
 {
    bool progress = false;
 
+   nir_assert_lowered_derefs(shader, nir_lower_texture_derefs);
+
    nir_foreach_function(function, shader) {
       if (function->impl)
          progress |= lower_impl(function->impl, shader_program,
diff --git a/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c b/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c
index 47115f9..be1baa1 100644
--- a/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c
+++ b/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c
@@ -233,6 +233,8 @@ gl_nir_lower_samplers_as_deref(nir_shader *shader,
    bool progress = false;
    struct lower_samplers_as_deref_state state;
 
+   nir_assert_lowered_derefs(shader, nir_lower_texture_derefs);
+
    state.shader = shader;
    state.shader_program = shader_program;
    state.remap_table = _mesa_hash_table_create(NULL, _mesa_key_hash_string,
diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index 44f4752..df8214d 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -64,6 +64,7 @@ nir_shader_create(void *mem_ctx,
    shader->num_outputs = 0;
    shader->num_uniforms = 0;
    shader->num_shared = 0;
+   shader->lowered_derefs = 0;
 
    return shader;
 }
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index f8a12c1..37df451 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2080,8 +2080,19 @@ typedef struct nir_shader {
     * access plus one
     */
    unsigned num_inputs, num_uniforms, num_outputs, num_shared;
+
+   /* temporary, tracking for which derefs instructions have been lowered
+    * to deref chains
+    */
+   unsigned lowered_derefs;
 } nir_shader;
 
+#define nir_assert_lowered_derefs(shader, mask) \
+   assert(((shader)->lowered_derefs & (mask)) == (mask))
+
+#define nir_assert_unlowered_derefs(shader, mask) \
+   assert(!((shader)->lowered_derefs & (mask)))
+
 static inline nir_function_impl *
 nir_shader_get_entrypoint(nir_shader *shader)
 {
@@ -2628,6 +2639,7 @@ enum nir_lower_deref_flags {
    nir_lower_atomic_counter_derefs =   (1 << 3),
    nir_lower_atomic_derefs =           (1 << 4),
    nir_lower_image_derefs =            (1 << 5),
+   nir_lower_all_derefs =              (1 << 6) - 1,
 };
 
 bool nir_lower_deref_instrs(nir_shader *shader,
diff --git a/src/compiler/nir/nir_clone.c b/src/compiler/nir/nir_clone.c
index 20eaaff..7236f08 100644
--- a/src/compiler/nir/nir_clone.c
+++ b/src/compiler/nir/nir_clone.c
@@ -816,6 +816,7 @@ nir_shader_clone(void *mem_ctx, const nir_shader *s)
    ns->num_uniforms = s->num_uniforms;
    ns->num_outputs = s->num_outputs;
    ns->num_shared = s->num_shared;
+   ns->lowered_derefs = s->lowered_derefs;
 
    free_clone_state(&state);
 
diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c
index 0e8699a..d7b4bbc 100644
--- a/src/compiler/nir/nir_deref.c
+++ b/src/compiler/nir/nir_deref.c
@@ -350,5 +350,7 @@ nir_lower_deref_instrs(nir_shader *shader,
       progress |= nir_lower_deref_instrs_impl(function->impl, flags);
    }
 
+   shader->lowered_derefs |= flags;
+
    return progress;
 }
diff --git a/src/compiler/nir/nir_gather_info.c b/src/compiler/nir/nir_gather_info.c
index dba9f19..8c485d1 100644
--- a/src/compiler/nir/nir_gather_info.c
+++ b/src/compiler/nir/nir_gather_info.c
@@ -355,6 +355,8 @@ gather_info_block(nir_block *block, nir_shader *shader)
 void
 nir_shader_gather_info(nir_shader *shader, nir_function_impl *entrypoint)
 {
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs | nir_lower_interp_derefs);
+
    shader->info.num_textures = 0;
    shader->info.num_images = 0;
    nir_foreach_variable(var, &shader->uniforms) {
diff --git a/src/compiler/nir/nir_linking_helpers.c b/src/compiler/nir/nir_linking_helpers.c
index 2b0a266..707bce1 100644
--- a/src/compiler/nir/nir_linking_helpers.c
+++ b/src/compiler/nir/nir_linking_helpers.c
@@ -133,6 +133,8 @@ nir_remove_unused_varyings(nir_shader *producer, nir_shader *consumer)
 {
    assert(producer->info.stage != MESA_SHADER_FRAGMENT);
    assert(consumer->info.stage != MESA_SHADER_VERTEX);
+   nir_assert_lowered_derefs(producer, nir_lower_load_store_derefs);
+   nir_assert_lowered_derefs(consumer, nir_lower_load_store_derefs);
 
    uint64_t read[4] = { 0 }, written[4] = { 0 };
    uint64_t patches_read[4] = { 0 }, patches_written[4] = { 0 };
diff --git a/src/compiler/nir/nir_loop_analyze.c b/src/compiler/nir/nir_loop_analyze.c
index 84da035..4b8738f 100644
--- a/src/compiler/nir/nir_loop_analyze.c
+++ b/src/compiler/nir/nir_loop_analyze.c
@@ -838,6 +838,7 @@ void
 nir_loop_analyze_impl(nir_function_impl *impl,
                       nir_variable_mode indirect_mask)
 {
+   nir_assert_lowered_derefs(impl->function->shader, nir_lower_load_store_derefs);
    nir_index_ssa_defs(impl);
    foreach_list_typed(nir_cf_node, node, node, &impl->body)
       process_loops(node, indirect_mask);
diff --git a/src/compiler/nir/nir_lower_alpha_test.c b/src/compiler/nir/nir_lower_alpha_test.c
index 6bf9ff1..4dfd798 100644
--- a/src/compiler/nir/nir_lower_alpha_test.c
+++ b/src/compiler/nir/nir_lower_alpha_test.c
@@ -41,6 +41,8 @@ nir_lower_alpha_test(nir_shader *shader, enum compare_func func,
 {
    assert(shader->info.stage == MESA_SHADER_FRAGMENT);
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
+
    nir_foreach_function(function, shader) {
       nir_function_impl *impl = function->impl;
       nir_builder b;
diff --git a/src/compiler/nir/nir_lower_clamp_color_outputs.c b/src/compiler/nir/nir_lower_clamp_color_outputs.c
index 55becbf..17bda24 100644
--- a/src/compiler/nir/nir_lower_clamp_color_outputs.c
+++ b/src/compiler/nir/nir_lower_clamp_color_outputs.c
@@ -134,6 +134,8 @@ nir_lower_clamp_color_outputs(nir_shader *shader)
       .shader = shader,
    };
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
+
    nir_foreach_function(function, shader) {
       if (function->impl)
          progress |= lower_impl(&state, function->impl);
diff --git a/src/compiler/nir/nir_lower_clip_cull_distance_arrays.c b/src/compiler/nir/nir_lower_clip_cull_distance_arrays.c
index 95eda82..6a93f1c 100644
--- a/src/compiler/nir/nir_lower_clip_cull_distance_arrays.c
+++ b/src/compiler/nir/nir_lower_clip_cull_distance_arrays.c
@@ -194,6 +194,8 @@ nir_lower_clip_cull_distance_arrays(nir_shader *nir)
 {
    bool progress = false;
 
+   nir_assert_lowered_derefs(nir, nir_lower_load_store_derefs);
+
    if (nir->info.stage <= MESA_SHADER_GEOMETRY)
       progress |= combine_clip_cull(nir, &nir->outputs, true);
 
diff --git a/src/compiler/nir/nir_lower_drawpixels.c b/src/compiler/nir/nir_lower_drawpixels.c
index 5cc358d..fcdc0bc 100644
--- a/src/compiler/nir/nir_lower_drawpixels.c
+++ b/src/compiler/nir/nir_lower_drawpixels.c
@@ -253,6 +253,11 @@ nir_lower_drawpixels(nir_shader *shader,
       .shader = shader,
    };
 
+   /* note that this pass already assumes texture/sampler derefs are already
+    * lowered to index
+    */
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
+
    assert(shader->info.stage == MESA_SHADER_FRAGMENT);
 
    nir_foreach_function(function, shader) {
diff --git a/src/compiler/nir/nir_lower_global_vars_to_local.c b/src/compiler/nir/nir_lower_global_vars_to_local.c
index c8fdfde..9b3bc4c 100644
--- a/src/compiler/nir/nir_lower_global_vars_to_local.c
+++ b/src/compiler/nir/nir_lower_global_vars_to_local.c
@@ -76,6 +76,9 @@ nir_lower_global_vars_to_local(nir_shader *shader)
       _mesa_hash_table_create(NULL, _mesa_hash_pointer,
                               _mesa_key_pointer_equal);
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs | nir_lower_interp_derefs |
+         nir_lower_atomic_counter_derefs | nir_lower_atomic_derefs | nir_lower_image_derefs);
+
    nir_foreach_function(function, shader) {
       if (function->impl) {
          nir_foreach_block(block, function->impl)
diff --git a/src/compiler/nir/nir_lower_indirect_derefs.c b/src/compiler/nir/nir_lower_indirect_derefs.c
index 02f202d..ed27c8f 100644
--- a/src/compiler/nir/nir_lower_indirect_derefs.c
+++ b/src/compiler/nir/nir_lower_indirect_derefs.c
@@ -211,6 +211,8 @@ nir_lower_indirect_derefs(nir_shader *shader, nir_variable_mode modes)
 {
    bool progress = false;
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs | nir_lower_interp_derefs);
+
    nir_foreach_function(function, shader) {
       if (function->impl)
          progress = lower_indirects_impl(function->impl, modes) || progress;
diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c
index df91feb..7ec2df1 100644
--- a/src/compiler/nir/nir_lower_io.c
+++ b/src/compiler/nir/nir_lower_io.c
@@ -511,6 +511,8 @@ nir_lower_io(nir_shader *shader, nir_variable_mode modes,
 {
    bool progress = false;
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs | nir_lower_interp_derefs | nir_lower_atomic_derefs);
+
    nir_foreach_function(function, shader) {
       if (function->impl) {
          progress |= nir_lower_io_impl(function->impl, modes,
diff --git a/src/compiler/nir/nir_lower_io_arrays_to_elements.c b/src/compiler/nir/nir_lower_io_arrays_to_elements.c
index 9a5eec8..c9c6c95 100644
--- a/src/compiler/nir/nir_lower_io_arrays_to_elements.c
+++ b/src/compiler/nir/nir_lower_io_arrays_to_elements.c
@@ -356,6 +356,8 @@ nir_lower_io_arrays_to_elements_no_indirects(nir_shader *shader,
       _mesa_hash_table_create(NULL, _mesa_hash_pointer,
                               _mesa_key_pointer_equal);
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs | nir_lower_interp_derefs);
+
    uint64_t indirects[4] = {0}, patch_indirects[4] = {0};
 
    lower_io_arrays_to_elements(shader, nir_var_shader_out, indirects,
@@ -398,6 +400,9 @@ nir_lower_io_arrays_to_elements(nir_shader *producer, nir_shader *consumer)
       _mesa_hash_table_create(NULL, _mesa_hash_pointer,
                               _mesa_key_pointer_equal);
 
+   nir_assert_lowered_derefs(producer, nir_lower_load_store_derefs | nir_lower_interp_derefs);
+   nir_assert_lowered_derefs(consumer, nir_lower_load_store_derefs | nir_lower_interp_derefs);
+
    uint64_t indirects[4] = {0}, patch_indirects[4] = {0};
    create_indirects_mask(producer, indirects, patch_indirects,
                          nir_var_shader_out);
diff --git a/src/compiler/nir/nir_lower_io_to_scalar.c b/src/compiler/nir/nir_lower_io_to_scalar.c
index 7774c2d..0dc135e 100644
--- a/src/compiler/nir/nir_lower_io_to_scalar.c
+++ b/src/compiler/nir/nir_lower_io_to_scalar.c
@@ -289,6 +289,8 @@ nir_lower_io_to_scalar_early(nir_shader *shader, nir_variable_mode mask)
       _mesa_hash_table_create(NULL, _mesa_hash_pointer,
                               _mesa_key_pointer_equal);
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs | nir_lower_interp_derefs);
+
    nir_foreach_function(function, shader) {
       if (function->impl) {
          nir_builder b;
diff --git a/src/compiler/nir/nir_lower_io_types.c b/src/compiler/nir/nir_lower_io_types.c
index 795bbd8..bbdbcda 100644
--- a/src/compiler/nir/nir_lower_io_types.c
+++ b/src/compiler/nir/nir_lower_io_types.c
@@ -161,6 +161,8 @@ nir_lower_io_types(nir_shader *shader)
 {
    struct lower_io_types_state state;
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
+
    state.shader = shader;
    exec_list_make_empty(&state.new_ins);
    exec_list_make_empty(&state.new_outs);
diff --git a/src/compiler/nir/nir_lower_locals_to_regs.c b/src/compiler/nir/nir_lower_locals_to_regs.c
index d0667bc..822c443 100644
--- a/src/compiler/nir/nir_lower_locals_to_regs.c
+++ b/src/compiler/nir/nir_lower_locals_to_regs.c
@@ -292,6 +292,8 @@ nir_lower_locals_to_regs(nir_shader *shader)
 {
    bool progress = false;
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
+
    nir_foreach_function(function, shader) {
       if (function->impl)
          progress = nir_lower_locals_to_regs_impl(function->impl) || progress;
diff --git a/src/compiler/nir/nir_lower_phis_to_scalar.c b/src/compiler/nir/nir_lower_phis_to_scalar.c
index b12718f..d055e78 100644
--- a/src/compiler/nir/nir_lower_phis_to_scalar.c
+++ b/src/compiler/nir/nir_lower_phis_to_scalar.c
@@ -299,6 +299,8 @@ nir_lower_phis_to_scalar(nir_shader *shader)
 {
    bool progress = false;
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
+
    nir_foreach_function(function, shader) {
       if (function->impl)
          progress = lower_phis_to_scalar_impl(function->impl) || progress;
diff --git a/src/compiler/nir/nir_lower_system_values.c b/src/compiler/nir/nir_lower_system_values.c
index 487da04..dc71a8c 100644
--- a/src/compiler/nir/nir_lower_system_values.c
+++ b/src/compiler/nir/nir_lower_system_values.c
@@ -203,6 +203,8 @@ nir_lower_system_values(nir_shader *shader)
 {
    bool progress = false;
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
+
    nir_foreach_function(function, shader) {
       if (function->impl)
          progress = convert_impl(function->impl) || progress;
diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c
index 1062afd..f4c3c9c 100644
--- a/src/compiler/nir/nir_lower_tex.c
+++ b/src/compiler/nir/nir_lower_tex.c
@@ -865,6 +865,8 @@ nir_lower_tex(nir_shader *shader, const nir_lower_tex_options *options)
 {
    bool progress = false;
 
+   nir_assert_lowered_derefs(shader, nir_lower_texture_derefs);
+
    nir_foreach_function(function, shader) {
       if (function->impl)
          progress |= nir_lower_tex_impl(function->impl, options);
diff --git a/src/compiler/nir/nir_lower_var_copies.c b/src/compiler/nir/nir_lower_var_copies.c
index 6288bdc..e7b2bd5 100644
--- a/src/compiler/nir/nir_lower_var_copies.c
+++ b/src/compiler/nir/nir_lower_var_copies.c
@@ -192,6 +192,8 @@ nir_lower_var_copies(nir_shader *shader)
 {
    bool progress = false;
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
+
    nir_foreach_function(function, shader) {
       if (function->impl)
          progress |= lower_var_copies_impl(function->impl);
diff --git a/src/compiler/nir/nir_lower_vars_to_ssa.c b/src/compiler/nir/nir_lower_vars_to_ssa.c
index 8bc847f..27f0ccb 100644
--- a/src/compiler/nir/nir_lower_vars_to_ssa.c
+++ b/src/compiler/nir/nir_lower_vars_to_ssa.c
@@ -737,6 +737,8 @@ nir_lower_vars_to_ssa(nir_shader *shader)
 {
    bool progress = false;
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
+
    nir_foreach_function(function, shader) {
       if (function->impl)
          progress |= nir_lower_vars_to_ssa_impl(function->impl);
diff --git a/src/compiler/nir/nir_lower_wpos_center.c b/src/compiler/nir/nir_lower_wpos_center.c
index dca810d..fa22599 100644
--- a/src/compiler/nir/nir_lower_wpos_center.c
+++ b/src/compiler/nir/nir_lower_wpos_center.c
@@ -107,6 +107,8 @@ nir_lower_wpos_center(nir_shader *shader, const bool for_sample_shading)
 
    assert(shader->info.stage == MESA_SHADER_FRAGMENT);
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
+
    nir_foreach_function(function, shader) {
       if (function->impl) {
          nir_builder_init(&b, function->impl);
diff --git a/src/compiler/nir/nir_lower_wpos_ytransform.c b/src/compiler/nir/nir_lower_wpos_ytransform.c
index 62166e7..9cb5c71 100644
--- a/src/compiler/nir/nir_lower_wpos_ytransform.c
+++ b/src/compiler/nir/nir_lower_wpos_ytransform.c
@@ -352,6 +352,8 @@ nir_lower_wpos_ytransform(nir_shader *shader,
       .shader = shader,
    };
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
+
    assert(shader->info.stage == MESA_SHADER_FRAGMENT);
 
    nir_foreach_function(function, shader) {
diff --git a/src/compiler/nir/nir_opt_copy_prop_vars.c b/src/compiler/nir/nir_opt_copy_prop_vars.c
index cc8f00f..2e1a2e0 100644
--- a/src/compiler/nir/nir_opt_copy_prop_vars.c
+++ b/src/compiler/nir/nir_opt_copy_prop_vars.c
@@ -768,6 +768,8 @@ nir_opt_copy_prop_vars(nir_shader *shader)
 {
    struct copy_prop_var_state state;
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
+
    state.shader = shader;
    state.mem_ctx = ralloc_context(NULL);
    list_inithead(&state.copies);
diff --git a/src/compiler/nir/nir_opt_peephole_select.c b/src/compiler/nir/nir_opt_peephole_select.c
index 4ca4f80..24a232e 100644
--- a/src/compiler/nir/nir_opt_peephole_select.c
+++ b/src/compiler/nir/nir_opt_peephole_select.c
@@ -255,6 +255,8 @@ nir_opt_peephole_select(nir_shader *shader, unsigned limit)
 {
    bool progress = false;
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
+
    nir_foreach_function(function, shader) {
       if (function->impl)
          progress |= nir_opt_peephole_select_impl(function->impl, limit);
diff --git a/src/compiler/nir/nir_opt_undef.c b/src/compiler/nir/nir_opt_undef.c
index 8d3210c..b344377 100644
--- a/src/compiler/nir/nir_opt_undef.c
+++ b/src/compiler/nir/nir_opt_undef.c
@@ -133,6 +133,8 @@ nir_opt_undef(nir_shader *shader)
    nir_builder b;
    bool progress = false;
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
+
    nir_foreach_function(function, shader) {
       if (function->impl) {
          nir_builder_init(&b, function->impl);
diff --git a/src/compiler/nir/nir_propagate_invariant.c b/src/compiler/nir/nir_propagate_invariant.c
index 7b5bd6c..d8dc6a0 100644
--- a/src/compiler/nir/nir_propagate_invariant.c
+++ b/src/compiler/nir/nir_propagate_invariant.c
@@ -184,6 +184,8 @@ nir_propagate_invariant(nir_shader *shader)
    struct set *invariants = _mesa_set_create(NULL, _mesa_hash_pointer,
                                              _mesa_key_pointer_equal);
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
+
    bool progress = false;
    nir_foreach_function(function, shader) {
       if (function->impl && propagate_invariant_impl(function->impl, invariants))
diff --git a/src/compiler/nir/nir_remove_dead_variables.c b/src/compiler/nir/nir_remove_dead_variables.c
index eff66f9..4a36ef9 100644
--- a/src/compiler/nir/nir_remove_dead_variables.c
+++ b/src/compiler/nir/nir_remove_dead_variables.c
@@ -172,6 +172,8 @@ nir_remove_dead_variables(nir_shader *shader, nir_variable_mode modes)
    struct set *live =
       _mesa_set_create(NULL, _mesa_hash_pointer, _mesa_key_pointer_equal);
 
+   nir_assert_lowered_derefs(shader, nir_lower_all_derefs);
+
    add_var_use_shader(shader, live, modes);
 
    if (modes & nir_var_uniform)
diff --git a/src/compiler/nir/nir_serialize.c b/src/compiler/nir/nir_serialize.c
index 834a65b..155205d 100644
--- a/src/compiler/nir/nir_serialize.c
+++ b/src/compiler/nir/nir_serialize.c
@@ -1215,6 +1215,7 @@ nir_serialize(struct blob *blob, const nir_shader *nir)
    blob_write_uint32(blob, nir->num_uniforms);
    blob_write_uint32(blob, nir->num_outputs);
    blob_write_uint32(blob, nir->num_shared);
+   blob_write_uint32(blob, nir->lowered_derefs);
 
    blob_write_uint32(blob, exec_list_length(&nir->functions));
    nir_foreach_function(fxn, nir) {
@@ -1270,6 +1271,7 @@ nir_deserialize(void *mem_ctx,
    ctx.nir->num_uniforms = blob_read_uint32(blob);
    ctx.nir->num_outputs = blob_read_uint32(blob);
    ctx.nir->num_shared = blob_read_uint32(blob);
+   ctx.nir->lowered_derefs = blob_read_uint32(blob);
 
    unsigned num_functions = blob_read_uint32(blob);
    for (unsigned i = 0; i < num_functions; i++)
diff --git a/src/compiler/nir/nir_split_var_copies.c b/src/compiler/nir/nir_split_var_copies.c
index bc3ceed..c18d77d 100644
--- a/src/compiler/nir/nir_split_var_copies.c
+++ b/src/compiler/nir/nir_split_var_copies.c
@@ -287,6 +287,8 @@ nir_split_var_copies(nir_shader *shader)
 {
    bool progress = false;
 
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
+
    nir_foreach_function(function, shader) {
       if (function->impl)
          progress = split_var_copies_impl(function->impl) || progress;
diff --git a/src/mesa/state_tracker/st_nir_lower_builtin.c b/src/mesa/state_tracker/st_nir_lower_builtin.c
index 660fdf3..8221502 100644
--- a/src/mesa/state_tracker/st_nir_lower_builtin.c
+++ b/src/mesa/state_tracker/st_nir_lower_builtin.c
@@ -239,6 +239,7 @@ lower_builtin_impl(lower_builtin_state *state, nir_function_impl *impl)
 void
 st_nir_lower_builtin(nir_shader *shader)
 {
+   nir_assert_lowered_derefs(shader, nir_lower_load_store_derefs);
    lower_builtin_state state;
    state.shader = shader;
    nir_foreach_function(function, shader) {
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list