nir/gs: fix array type copying for passthrough gs

same mechanics as in zink passes

Fixes: d0342e28b3 ("nir: Add helper to create passthrough GS shader")

Reviewed-by: Antonino Maniscalco <antonino.maniscalco@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22669>
This commit is contained in:
Mike Blumenkrantz
2023-04-24 11:19:57 -04:00
committed by Marge Bot
parent 796109cb08
commit 99121c9b77

View File

@@ -122,6 +122,25 @@ array_size_for_prim(enum shader_prim prim)
}
}
static void
copy_vars(nir_builder *b, nir_deref_instr *dst, nir_deref_instr *src)
{
assert(glsl_get_bare_type(dst->type) == glsl_get_bare_type(src->type));
if (glsl_type_is_struct(dst->type)) {
for (unsigned i = 0; i < glsl_get_length(dst->type); ++i) {
copy_vars(b, nir_build_deref_struct(b, dst, i), nir_build_deref_struct(b, src, i));
}
} else if (glsl_type_is_array_or_matrix(dst->type)) {
unsigned count = glsl_type_is_array(dst->type) ? glsl_array_size(dst->type) : glsl_get_matrix_columns(dst->type);
for (unsigned i = 0; i < count; i++) {
copy_vars(b, nir_build_deref_array_imm(b, dst, i), nir_build_deref_array_imm(b, src, i));
}
} else {
nir_ssa_def *load = nir_load_deref(b, src);
nir_store_deref(b, dst, load, BITFIELD_MASK(load->num_components));
}
}
/*
* A helper to create a passthrough GS shader for drivers that needs to lower
* some rendering tasks to the GS.
@@ -261,9 +280,8 @@ nir_create_passthrough_gs(const nir_shader_compiler_options *options,
unsigned mask = 1u << (of++);
index = nir_bcsel(&b, nir_ieq_imm(&b, nir_iand_imm(&b, flat_interp_mask_def, mask), 0), nir_imm_int(&b, idx), pv_vert_index);
}
nir_ssa_def *value = nir_load_array_var(&b, in_vars[j], index);
nir_store_var(&b, out_vars[oj], value,
(1u << value->num_components) - 1);
nir_deref_instr *value = nir_build_deref_array(&b, nir_build_deref_var(&b, in_vars[j]), index);
copy_vars(&b, nir_build_deref_var(&b, out_vars[oj]), value);
++oj;
}
nir_emit_vertex(&b, 0);