From: Mike Blumenkrantz Date: Mon, 24 Apr 2023 15:19:57 +0000 (-0400) Subject: nir/gs: fix array type copying for passthrough gs X-Git-Tag: upstream/23.3.3~9612 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=99121c9b77930aa6b6da8fcd087e4f03aac19323;p=platform%2Fupstream%2Fmesa.git nir/gs: fix array type copying for passthrough gs same mechanics as in zink passes Fixes: d0342e28b32 ("nir: Add helper to create passthrough GS shader") Reviewed-by: Antonino Maniscalco Part-of: --- diff --git a/src/compiler/nir/nir_passthrough_gs.c b/src/compiler/nir/nir_passthrough_gs.c index aebf75d..999358b 100644 --- a/src/compiler/nir/nir_passthrough_gs.c +++ b/src/compiler/nir/nir_passthrough_gs.c @@ -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);