From 8482ad01102a3c15d60549229109b1b97b1c34e4 Mon Sep 17 00:00:00 2001 From: Danylo Piliaiev Date: Tue, 29 Nov 2022 12:41:08 +0100 Subject: [PATCH] nir/nir_lower_is_helper_invocation: Lower helper invocation if required nir_lower_is_helper_invocation lowers intrinsic_is_helper_invocation and uses load_helper_invocation (which is lowered by nir_lower_system_values). While nir_lower_system_values may lower SYSTEM_VALUE_HELPER_INVOCATION into intrinsic_is_helper_invocation. So they depend on each other. Break the dependency by making nir_lower_is_helper_invocation aware of lower_helper_invocation option and emitting lowered load_helper_invocation when required. Happens with SPIR-V 1.6 for which gl_HelperInvocation is translated into "BuiltIn HelperInvocation" + "Volatile", which nir_lower_system_values translates into is_helper_invocation. Signed-off-by: Danylo Piliaiev Reviewed-by: Emma Anholt Part-of: --- src/compiler/nir/nir.h | 3 +++ .../nir/nir_lower_is_helper_invocation.c | 4 +++- src/compiler/nir/nir_lower_system_values.c | 16 +++++++++++----- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index aba5f11a60b..a893c4760af 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -5034,6 +5034,9 @@ bool nir_lower_subgroups(nir_shader *shader, bool nir_lower_system_values(nir_shader *shader); +nir_ssa_def * +nir_build_lowered_load_helper_invocation(struct nir_builder *b); + typedef struct nir_lower_compute_system_values_options { bool has_base_global_invocation_id:1; bool has_base_workgroup_id:1; diff --git a/src/compiler/nir/nir_lower_is_helper_invocation.c b/src/compiler/nir/nir_lower_is_helper_invocation.c index b2dfb84f65a..a7b72293d47 100644 --- a/src/compiler/nir/nir_lower_is_helper_invocation.c +++ b/src/compiler/nir/nir_lower_is_helper_invocation.c @@ -114,7 +114,9 @@ nir_lower_is_helper_invocation(nir_shader *shader) glsl_bool_type(), "gl_IsHelperInvocationEXT"); - nir_ssa_def *started_as_helper = nir_load_helper_invocation(&b, 1); + nir_ssa_def *started_as_helper = shader->options->lower_helper_invocation ? + nir_build_lowered_load_helper_invocation(&b) : + nir_load_helper_invocation(&b, 1); nir_deref_instr *is_helper_deref = nir_build_deref_var(&b, is_helper); nir_store_deref(&b, is_helper_deref, started_as_helper, 1); diff --git a/src/compiler/nir/nir_lower_system_values.c b/src/compiler/nir/nir_lower_system_values.c index a32bceac858..ba4187a12ca 100644 --- a/src/compiler/nir/nir_lower_system_values.c +++ b/src/compiler/nir/nir_lower_system_values.c @@ -105,11 +105,7 @@ lower_system_value_instr(nir_builder *b, nir_instr *instr, void *_state) case nir_intrinsic_load_helper_invocation: if (b->shader->options->lower_helper_invocation) { - nir_ssa_def *tmp; - tmp = nir_ishl(b, nir_imm_int(b, 1), - nir_load_sample_id_no_per_sample(b)); - tmp = nir_iand(b, nir_load_sample_mask_in(b), tmp); - return nir_inot(b, nir_i2b(b, tmp)); + return nir_build_lowered_load_helper_invocation(b); } else { return NULL; } @@ -245,6 +241,16 @@ lower_system_value_instr(nir_builder *b, nir_instr *instr, void *_state) } } +nir_ssa_def * +nir_build_lowered_load_helper_invocation(nir_builder *b) +{ + nir_ssa_def *tmp; + tmp = nir_ishl(b, nir_imm_int(b, 1), + nir_load_sample_id_no_per_sample(b)); + tmp = nir_iand(b, nir_load_sample_mask_in(b), tmp); + return nir_inot(b, nir_i2b(b, tmp)); +} + bool nir_lower_system_values(nir_shader *shader) { -- 2.34.1