From 9414cbc13c964b567a15637eaa7dc32899391594 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 2 Sep 2020 17:38:23 -0500 Subject: [PATCH] nir: Don't bail too early in lower_mem_constant_vars 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 Part-of: --- src/compiler/nir/nir_lower_io.c | 37 ++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c index 00ea0bd739a..651c7460cd7 100644 --- a/src/compiler/nir/nir_lower_io.c +++ b/src/compiler/nir/nir_lower_io.c @@ -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; } /** -- 2.30.2