From 99ab53061736d0f7559d0bd2f3ff0d4d1aa8e192 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Wed, 16 Mar 2022 16:58:02 +1100 Subject: [PATCH] nir: abort io info gathering if location is not set or is a temp value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unlike spirv glsl varyings might not have explicit locations set. nir_shader_gather_info() was once only called at the end of linking but these days it even gets called in NIR optimisation loops via nir_opt_phi_precision. In the following patches we implement a NIR version of the GLSL varying linker which means we will have varyings with no location set when nir_shader_gather_info() gets called the first few times, and temp values set only for the purpose of removing unmatched varyings between shaders for some calls after that. Here rather than asserting we simply abort the io info gathering, when we hit these values. Reviewed-by: Marek Olšák Part-of: --- src/compiler/nir/nir_gather_info.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/compiler/nir/nir_gather_info.c b/src/compiler/nir/nir_gather_info.c index f0e0262e58f..d372ac49ad6 100644 --- a/src/compiler/nir/nir_gather_info.c +++ b/src/compiler/nir/nir_gather_info.c @@ -79,7 +79,9 @@ set_io_mask(nir_shader *shader, nir_variable *var, int offset, int len, nir_deref_instr *deref, bool is_output_read) { for (int i = 0; i < len; i++) { - assert(var->data.location != -1); + /* Varyings might not have been assigned values yet so abort. */ + if (var->data.location == -1) + return; int idx = var->data.location + offset + i; bool is_patch_generic = var->data.patch && @@ -90,11 +92,17 @@ set_io_mask(nir_shader *shader, nir_variable *var, int offset, int len, uint64_t bitfield; if (is_patch_generic) { - assert(idx >= VARYING_SLOT_PATCH0 && idx < VARYING_SLOT_TESS_MAX); + /* Varyings might still have temp locations so abort */ + if (idx < VARYING_SLOT_PATCH0 || idx >= VARYING_SLOT_TESS_MAX) + return; + bitfield = BITFIELD64_BIT(idx - VARYING_SLOT_PATCH0); } else { - assert(idx < VARYING_SLOT_MAX); + /* Varyings might still have temp locations so abort */ + if (idx >= VARYING_SLOT_MAX) + return; + bitfield = BITFIELD64_BIT(idx); }