From 51840bbdced88a60389e8c24935d23145c3c814a Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 3 Aug 2023 11:16:47 +1000 Subject: [PATCH] nir: add a deref slot counter that handles compact Conor suggested this, so we can mark slots properly in the io marking. This fixes a problem seen when rewriting llvmpipe to use nir info instead of tgsi info. Part-of: --- src/compiler/nir/nir.h | 16 ++++++++++++++++ src/compiler/nir/nir_gather_info.c | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 3fb6cb626cb..7d3754e89cd 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -6133,6 +6133,22 @@ nir_variable_count_slots(const nir_variable *var, const struct glsl_type *type) return var->data.compact ? DIV_ROUND_UP(var->data.location_frac + glsl_get_length(type), 4) : glsl_count_attribute_slots(type, false); } +static inline unsigned +nir_deref_count_slots(nir_deref_instr *deref, nir_variable *var) +{ + if (var->data.compact) { + switch (deref->deref_type) { + case nir_deref_type_array: + return 1; + case nir_deref_type_var: + return nir_variable_count_slots(var, deref->type); + default: + unreachable("illegal deref type"); + } + } + return glsl_count_attribute_slots(deref->type, false); +} + /* See default_ub_config in nir_range_analysis.c for documentation. */ typedef struct nir_unsigned_upper_bound_config { unsigned min_subgroup_size; diff --git a/src/compiler/nir/nir_gather_info.c b/src/compiler/nir/nir_gather_info.c index af138de62bb..865d976a98e 100644 --- a/src/compiler/nir/nir_gather_info.c +++ b/src/compiler/nir/nir_gather_info.c @@ -291,7 +291,7 @@ try_mask_partial_io(nir_shader *shader, nir_variable *var, return false; } - unsigned len = glsl_count_attribute_slots(deref->type, false); + unsigned len = nir_deref_count_slots(deref, var); set_io_mask(shader, var, offset, len, deref, is_output_read); return true; }