From 7a1061e0dd5392d3798091cdb2d01c969e9adfa7 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Wed, 29 May 2024 11:10:05 +1000 Subject: [PATCH] nir: add max_ifc_array_access field to vars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will be used in following patches by the nir based glsl linker code. Acked-by: Marek Olšák Part-of: --- src/compiler/glsl/glsl_to_nir.cpp | 10 ++++++++++ src/compiler/nir/nir.h | 12 ++++++++++++ src/compiler/nir/nir_clone.c | 7 +++++++ 3 files changed, 29 insertions(+) diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp index f1d6ee85105..d9d8802c262 100644 --- a/src/compiler/glsl/glsl_to_nir.cpp +++ b/src/compiler/glsl/glsl_to_nir.cpp @@ -597,6 +597,16 @@ nir_visitor::visit(ir_variable *ir) var->data.explicit_xfb_buffer = ir->data.explicit_xfb_buffer; var->data.explicit_xfb_stride = ir->data.explicit_xfb_stride; + if (ir->is_interface_instance()) { + int *max_ifc_array_access = ir->get_max_ifc_array_access(); + if (max_ifc_array_access) { + var->max_ifc_array_access = + rzalloc_array(var, int, ir->get_interface_type()->length); + memcpy(var->max_ifc_array_access, max_ifc_array_access, + ir->get_interface_type()->length * sizeof(unsigned)); + } + } + var->num_state_slots = ir->get_num_state_slots(); if (var->num_state_slots > 0) { var->state_slots = rzalloc_array(var, nir_state_slot, diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 9306104f22e..e32934f7e6c 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -837,6 +837,18 @@ typedef struct nir_variable { /* Number of nir_variable_data members */ uint16_t num_members; + /** + * For variables with non NULL interface_type, this points to an array of + * integers such that if the ith member of the interface block is an array, + * max_ifc_array_access[i] is the maximum array element of that member that + * has been accessed. If the ith member of the interface block is not an + * array, max_ifc_array_access[i] is unused. + * + * For variables whose type is not an interface block, this pointer is + * NULL. + */ + int *max_ifc_array_access; + /** * Built-in state that backs this uniform * diff --git a/src/compiler/nir/nir_clone.c b/src/compiler/nir/nir_clone.c index b684fe9e5a2..dd37f282d31 100644 --- a/src/compiler/nir/nir_clone.c +++ b/src/compiler/nir/nir_clone.c @@ -163,6 +163,13 @@ nir_variable_clone(const nir_variable *var, nir_shader *shader) } nvar->interface_type = var->interface_type; + if (var->max_ifc_array_access) { + nvar->max_ifc_array_access = + rzalloc_array(nvar, int, var->interface_type->length); + memcpy(nvar->max_ifc_array_access, var->max_ifc_array_access, + var->interface_type->length * sizeof(unsigned)); + } + nvar->num_members = var->num_members; if (var->num_members) { nvar->members = ralloc_array(nvar, struct nir_variable_data,