- assert(src_tail->type == dest_tail->type);
-
- /* Make sure these really are the tails of the deref chains */
- assert(dest_tail->child == NULL);
- assert(src_tail->child == NULL);
-
- switch (glsl_get_base_type(src_tail->type)) {
- case GLSL_TYPE_ARRAY: {
- /* Make a wildcard dereference */
- nir_deref_array *deref = nir_deref_array_create(state->dead_ctx);
- deref->deref.type = glsl_get_array_element(src_tail->type);
- deref->deref_array_type = nir_deref_array_type_wildcard;
-
- /* Set the tail of both as the newly created wildcard deref. It is
- * safe to use the same wildcard in both places because a) we will be
- * copying it before we put it in an actual instruction and b)
- * everything that will potentially add another link in the deref
- * chain will also add the same thing to both chains.
- */
- src_tail->child = &deref->deref;
- dest_tail->child = &deref->deref;
-
- split_var_copy_instr(old_copy, dest_head, src_head,
- dest_tail->child, src_tail->child, state);
-
- /* Set it back to the way we found it */
- src_tail->child = NULL;
- dest_tail->child = NULL;
- break;
- }
-
- case GLSL_TYPE_STRUCT:
- /* This is the only part that actually does any interesting
- * splitting. For array types, we just use wildcards and resolve
- * them later. For structure types, we need to emit one copy
- * instruction for every structure element. Because we may have
- * structs inside structs, we just recurse and let the next level
- * take care of any additional structures.
- */
- for (unsigned i = 0; i < glsl_get_length(src_tail->type); i++) {
- nir_deref_struct *deref = nir_deref_struct_create(state->dead_ctx, i);
- deref->deref.type = glsl_get_struct_field(src_tail->type, i);
-
- /* Set the tail of both as the newly created structure deref. It
- * is safe to use the same wildcard in both places because a) we
- * will be copying it before we put it in an actual instruction
- * and b) everything that will potentially add another link in the
- * deref chain will also add the same thing to both chains.
- */
- src_tail->child = &deref->deref;
- dest_tail->child = &deref->deref;
-
- split_var_copy_instr(old_copy, dest_head, src_head,
- dest_tail->child, src_tail->child, state);
+ assert(dst->type == src->type);
+ if (glsl_type_is_vector_or_scalar(src->type)) {
+ nir_copy_deref(b, dst, src);
+ } else if (glsl_type_is_struct(src->type)) {
+ for (unsigned i = 0; i < glsl_get_length(src->type); i++) {
+ split_deref_copy_instr(b, nir_build_deref_struct(b, dst, i),
+ nir_build_deref_struct(b, src, i));