diff --git a/src/compiler/nir/nir_linking_helpers.c b/src/compiler/nir/nir_linking_helpers.c index 758246a4b17..c94c0dfc92a 100644 --- a/src/compiler/nir/nir_linking_helpers.c +++ b/src/compiler/nir/nir_linking_helpers.c @@ -1202,9 +1202,18 @@ nir_clone_deref_instr(nir_builder *b, nir_variable *var, */ switch (deref->deref_type) { case nir_deref_type_array: { - nir_load_const_instr *index = - nir_instr_as_load_const(deref->arr.index.ssa->parent_instr); - return nir_build_deref_array_imm(b, parent, index->value->i64); + if (b->shader == + nir_cf_node_get_function(&deref->instr.block->cf_node)->function->shader) { + /* Cloning within the same shader. */ + return nir_build_deref_array(b, parent, deref->arr.index.ssa); + } else { + /* Cloning to a different shader. The index must be constant because + * we don't implement cloning the index SSA here. + */ + nir_load_const_instr *index = + nir_instr_as_load_const(deref->arr.index.ssa->parent_instr); + return nir_build_deref_array_imm(b, parent, index->value->i64); + } } case nir_deref_type_ptr_as_array: { nir_load_const_instr *index =