From 68a35bad8616976d16b20996f33e586ba59692cf Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Mon, 24 Apr 2023 11:19:57 -0400 Subject: [PATCH] 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: (cherry picked from commit 99121c9b77930aa6b6da8fcd087e4f03aac19323) --- .pick_status.json | 2 +- src/compiler/nir/nir_passthrough_gs.c | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 2884d6c72ae..dae2e2d6c6c 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -67,7 +67,7 @@ "description": "nir/gs: fix array type copying for passthrough gs", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "d0342e28b32d7aa4b25cf045ac9933348ec053a9" }, diff --git a/src/compiler/nir/nir_passthrough_gs.c b/src/compiler/nir/nir_passthrough_gs.c index aebf75dfbe6..999358b4068 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);