nir: Don't bail too early in lower_mem_constant_vars
authorJason Ekstrand <jason@jlekstrand.net>
Wed, 2 Sep 2020 22:38:23 +0000 (17:38 -0500)
committerMarge Bot <eric+marge@anholt.net>
Thu, 3 Sep 2020 18:02:50 +0000 (18:02 +0000)
If there were no constant variables, we would bail out entirely.
However, we may still have constant input pointers coming in from the
client.

Fixes: 4360a8a2b3fce "nir/lower_io: Add support for nir_var_mem_constant"
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6472>

src/compiler/nir/nir_lower_io.c

index 00ea0bd739a9f555d066d4d8627d473a8d16fa92..651c7460cd7b68b7a4fd59baab767ba4aa5176ea 100644 (file)
@@ -1724,32 +1724,35 @@ bool
 nir_lower_mem_constant_vars(nir_shader *shader,
                             glsl_type_size_align_func type_info)
 {
-   unsigned old_constant_data_size = shader->constant_data_size;
-   if (!lower_vars_to_explicit(shader, &shader->variables,
-                               nir_var_mem_constant, type_info)) {
-      nir_shader_preserve_all_metadata(shader);
-      return false;
-   }
-
-   shader->constant_data = rerzalloc_size(shader, shader->constant_data,
-                                          old_constant_data_size,
-                                          shader->constant_data_size);
+   bool progress = false;
 
-   nir_foreach_variable_with_modes(var, shader, nir_var_mem_constant) {
-      write_constant((char *)shader->constant_data + var->data.driver_location,
-                     var->constant_initializer, var->type);
+   unsigned old_constant_data_size = shader->constant_data_size;
+   if (lower_vars_to_explicit(shader, &shader->variables,
+                              nir_var_mem_constant, type_info)) {
+      assert(shader->constant_data_size > old_constant_data_size);
+      shader->constant_data = rerzalloc_size(shader, shader->constant_data,
+                                             old_constant_data_size,
+                                             shader->constant_data_size);
+
+      nir_foreach_variable_with_modes(var, shader, nir_var_mem_constant) {
+         write_constant((char *)shader->constant_data +
+                           var->data.driver_location,
+                        var->constant_initializer, var->type);
+      }
+      progress = true;
    }
 
    nir_foreach_function(function, shader) {
       if (!function->impl)
          continue;
 
-      nir_lower_vars_to_explicit_types_impl(function->impl,
-                                            nir_var_mem_constant,
-                                            type_info);
+      if (nir_lower_vars_to_explicit_types_impl(function->impl,
+                                                nir_var_mem_constant,
+                                                type_info))
+         progress = true;
    }
 
-   return true;
+   return progress;
 }
 
 /**