nir: Properly preserve metadata in more cases
[mesa.git] / src / compiler / nir / nir_lower_clip_cull_distance_arrays.c
index 70578d6f3fd3631b64143c2ea57cb67f767a675b..390eded7b01a4a5610f734f2709203baddab5477 100644 (file)
@@ -72,8 +72,17 @@ combine_clip_cull(nir_shader *nir,
          cull = var;
    }
 
-   if (!cull && !clip)
+   if (!cull && !clip) {
+      /* If this is run after optimizations and the variables have been
+       * eliminated, we should update the shader info, because no other
+       * place does that.
+       */
+      if (store_info) {
+         nir->info.clip_distance_array_size = 0;
+         nir->info.cull_distance_array_size = 0;
+      }
       return false;
+   }
 
    if (!cull && clip) {
       /* The GLSL IR lowering pass must have converted these to vectors */
@@ -107,16 +116,6 @@ combine_clip_cull(nir_shader *nir,
       cull->data.location_frac = clip_array_size % 4;
    }
 
-   nir_foreach_function(function, nir) {
-      if (function->impl) {
-         nir_metadata_preserve(function->impl,
-                               nir_metadata_block_index |
-                               nir_metadata_dominance |
-                               nir_metadata_live_ssa_defs |
-                               nir_metadata_loop_analysis);
-      }
-   }
-
    return true;
 }
 
@@ -131,5 +130,20 @@ nir_lower_clip_cull_distance_arrays(nir_shader *nir)
    if (nir->info.stage > MESA_SHADER_VERTEX)
       progress |= combine_clip_cull(nir, &nir->inputs, false);
 
+   nir_foreach_function(function, nir) {
+      if (!function->impl)
+         continue;
+
+      if (progress) {
+         nir_metadata_preserve(function->impl,
+                               nir_metadata_block_index |
+                               nir_metadata_dominance |
+                               nir_metadata_live_ssa_defs |
+                               nir_metadata_loop_analysis);
+      } else {
+         nir_metadata_preserve(function->impl, nir_metadata_all);
+      }
+   }
+
    return progress;
 }