From e3abbe7a24c0a1927313ce629b0d14a11d7e61c8 Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Tue, 12 Jan 2021 10:25:58 -0800 Subject: [PATCH] spirv: Count variables *after* unused ones are removed Previous code was counting more variables than those used by the entry point. Reviewed-by: Jason Ekstrand Part-of: --- src/compiler/spirv/spirv_to_nir.c | 16 ++++++++++++++++ src/compiler/spirv/vtn_variables.c | 6 ------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index 2586b9ecba6..8060e24c9fb 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -5991,6 +5991,22 @@ spirv_to_nir(const uint32_t *words, size_t word_count, b->vars_used_indirectly ? &dead_opts : NULL); } + nir_foreach_variable_in_shader(var, b->shader) { + switch (var->data.mode) { + case nir_var_mem_ubo: + b->shader->info.num_ubos++; + break; + case nir_var_mem_ssbo: + b->shader->info.num_ssbos++; + break; + case nir_var_mem_push_const: + vtn_assert(b->shader->num_uniforms == 0); + b->shader->num_uniforms = + glsl_get_explicit_size(glsl_without_array(var->type), false); + break; + } + } + /* We sometimes generate bogus derefs that, while never used, give the * validator a bit of heartburn. Run dead code to get rid of them. */ diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c index c21ac8194d8..bda82103348 100644 --- a/src/compiler/spirv/vtn_variables.c +++ b/src/compiler/spirv/vtn_variables.c @@ -1767,7 +1767,6 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val, case vtn_variable_mode_ubo: /* There's no other way to get vtn_variable_mode_ubo */ vtn_assert(without_array->block); - b->shader->info.num_ubos++; break; case vtn_variable_mode_ssbo: if (storage_class == SpvStorageClassStorageBuffer && @@ -1785,11 +1784,6 @@ vtn_create_variable(struct vtn_builder *b, struct vtn_value *val, "have a struct type with the Block decoration"); } } - b->shader->info.num_ssbos++; - break; - case vtn_variable_mode_push_constant: - b->shader->num_uniforms = - glsl_get_explicit_size(without_array->type, false); break; case vtn_variable_mode_generic: