diff --git a/src/compiler/nir/nir_lower_io_arrays_to_elements.c b/src/compiler/nir/nir_lower_io_arrays_to_elements.c index 376326575b0..26036673ed0 100644 --- a/src/compiler/nir/nir_lower_io_arrays_to_elements.c +++ b/src/compiler/nir/nir_lower_io_arrays_to_elements.c @@ -115,6 +115,18 @@ lower_array(nir_builder *b, nir_intrinsic_instr *intr, nir_variable *var, { b->cursor = nir_before_instr(&intr->instr); + if (nir_deref_instr_is_known_out_of_bounds(nir_src_as_deref(intr->src[0]))) { + /* See Section 5.11 (Out-of-Bounds Accesses) of the GLSL 4.60 */ + if (intr->intrinsic != nir_intrinsic_store_deref) { + nir_ssa_def *zero = nir_imm_zero(b, intr->dest.ssa.num_components, + intr->dest.ssa.bit_size); + nir_ssa_def_rewrite_uses(&intr->dest.ssa, + nir_src_for_ssa(zero)); + } + nir_instr_remove(&intr->instr); + return; + } + nir_variable **elements = get_array_elements(varyings, var, b->shader->info.stage);