From bb5d5029b7423d4ffe3b84149b2bc6a770647ef2 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Fri, 30 Oct 2020 12:30:09 -0500 Subject: [PATCH] nir: Use var->data.mode instead of deref->mode in a few cases We already have the variable so we know the mode exactly. Just use that instead of the deref mode. If these paths ever have to handle variable pointers (not likely since they're OpenGL-specific), we can fix them to handle crazy deref modes then. Reviewed-by: Jesse Natalie Part-of: --- src/compiler/glsl/gl_nir_lower_images.c | 2 +- src/compiler/nir/nir_lower_io.c | 4 ++-- src/compiler/nir/nir_lower_io_to_scalar.c | 4 ++-- src/compiler/nir/nir_lower_io_to_vector.c | 4 ++-- src/compiler/nir/nir_opt_large_constants.c | 2 +- src/compiler/nir/nir_remove_dead_variables.c | 5 +++-- src/gallium/drivers/radeonsi/si_shader_nir.c | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/compiler/glsl/gl_nir_lower_images.c b/src/compiler/glsl/gl_nir_lower_images.c index 632af71f329..ee74004de9d 100644 --- a/src/compiler/glsl/gl_nir_lower_images.c +++ b/src/compiler/glsl/gl_nir_lower_images.c @@ -87,7 +87,7 @@ lower_impl(nir_builder *b, nir_instr *instr, bool bindless_only) return false; } - bool bindless = deref->mode != nir_var_uniform || var->data.bindless; + bool bindless = var->data.mode != nir_var_uniform || var->data.bindless; if (bindless_only && !bindless) return false; diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c index cddfaada155..4c29aa443c7 100644 --- a/src/compiler/nir/nir_lower_io.c +++ b/src/compiler/nir/nir_lower_io.c @@ -634,8 +634,8 @@ nir_lower_io_block(nir_block *block, nir_ssa_def *offset; nir_ssa_def *vertex_index = NULL; unsigned component_offset = var->data.location_frac; - bool bindless_type_size = mode == nir_var_shader_in || - mode == nir_var_shader_out || + bool bindless_type_size = var->data.mode == nir_var_shader_in || + var->data.mode == nir_var_shader_out || var->data.bindless; if (nir_deref_instr_is_known_out_of_bounds(deref)) { diff --git a/src/compiler/nir/nir_lower_io_to_scalar.c b/src/compiler/nir/nir_lower_io_to_scalar.c index 5746f9f5c5f..77524ba27f3 100644 --- a/src/compiler/nir/nir_lower_io_to_scalar.c +++ b/src/compiler/nir/nir_lower_io_to_scalar.c @@ -314,11 +314,11 @@ nir_lower_io_to_scalar_early_instr(nir_builder *b, nir_instr *instr, void *data) return false; nir_deref_instr *deref = nir_src_as_deref(intr->src[0]); - nir_variable_mode mode = deref->mode; - if (!(mode & state->mask)) + if (!(deref->mode & state->mask)) return false; nir_variable *var = nir_deref_instr_get_variable(deref); + nir_variable_mode mode = var->data.mode; /* TODO: add patch support */ if (var->data.patch) diff --git a/src/compiler/nir/nir_lower_io_to_vector.c b/src/compiler/nir/nir_lower_io_to_vector.c index 022f9e2f7a2..be87c4b4e06 100644 --- a/src/compiler/nir/nir_lower_io_to_vector.c +++ b/src/compiler/nir/nir_lower_io_to_vector.c @@ -442,10 +442,10 @@ nir_lower_io_to_vector_impl(nir_function_impl *impl, nir_variable_mode modes) const unsigned loc = get_slot(old_var); const unsigned old_frac = old_var->data.location_frac; - nir_variable *new_var = old_deref->mode == nir_var_shader_in ? + nir_variable *new_var = old_var->data.mode == nir_var_shader_in ? new_inputs[loc][old_frac] : new_outputs[loc][old_frac]; - bool flat = old_deref->mode == nir_var_shader_in ? + bool flat = old_var->data.mode == nir_var_shader_in ? flat_inputs[loc] : flat_outputs[loc]; if (!new_var) break; diff --git a/src/compiler/nir/nir_opt_large_constants.c b/src/compiler/nir/nir_opt_large_constants.c index 3ee67b60159..f4ef4d351e1 100644 --- a/src/compiler/nir/nir_opt_large_constants.c +++ b/src/compiler/nir/nir_opt_large_constants.c @@ -208,7 +208,7 @@ nir_opt_large_constants(nir_shader *shader, */ nir_deref_instr *deref = nir_instr_as_deref(instr); if (deref->deref_type == nir_deref_type_var && - deref->mode == nir_var_function_temp && + deref->var->data.mode == nir_var_function_temp && nir_deref_instr_has_complex_use(deref)) var_infos[deref->var->index].is_constant = false; continue; diff --git a/src/compiler/nir/nir_remove_dead_variables.c b/src/compiler/nir/nir_remove_dead_variables.c index 5037b862263..3d1df3a58c9 100644 --- a/src/compiler/nir/nir_remove_dead_variables.c +++ b/src/compiler/nir/nir_remove_dead_variables.c @@ -70,8 +70,9 @@ add_var_use_deref(nir_deref_instr *deref, struct set *live) /* If it's not a local that never escapes the shader, then any access at * all means we need to keep it alive. */ - assert(deref->mode == deref->var->data.mode); - if (!(deref->mode & (nir_var_function_temp | nir_var_shader_temp | nir_var_mem_shared)) || + if (!(deref->var->data.mode & (nir_var_function_temp | + nir_var_shader_temp | + nir_var_mem_shared)) || deref_used_for_not_store(deref)) _mesa_set_add(live, deref->var); } diff --git a/src/gallium/drivers/radeonsi/si_shader_nir.c b/src/gallium/drivers/radeonsi/si_shader_nir.c index eddf4383bdc..81c2b5d3ba2 100644 --- a/src/gallium/drivers/radeonsi/si_shader_nir.c +++ b/src/gallium/drivers/radeonsi/si_shader_nir.c @@ -189,7 +189,7 @@ static void scan_instruction(const struct nir_shader *nir, struct si_shader_info nir_variable *var = deref ? nir_deref_instr_get_variable(deref) : NULL; if (var) { - if (deref->mode != nir_var_uniform || var->data.bindless) + if (var->data.mode != nir_var_uniform || var->data.bindless) info->uses_bindless_samplers = true; } } else if (instr->type == nir_instr_type_intrinsic) {