From 67f32f8ac8742bc10006df795e8175c30cb1d551 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Mon, 24 Apr 2023 11:40:16 -0400 Subject: [PATCH] zink: fix array copying in pv lowering Fixes: 5a4083349f3 ("zink: add provoking vertex mode lowering") Reviewed-by: Antonino Maniscalco Part-of: (cherry picked from commit edaf49160e5293d30aab1d3bcf5452b8c3178096) --- .pick_status.json | 2 +- src/gallium/drivers/zink/zink_compiler.c | 43 ++++++++++++------------ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index dae2e2d6c6c..a920f024030 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -58,7 +58,7 @@ "description": "zink: fix array copying in pv lowering", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "5a4083349f36ef6db36a962327de6952a30d0c92" }, diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c index ef8dc766ea0..e6820b3d1c1 100644 --- a/src/gallium/drivers/zink/zink_compiler.c +++ b/src/gallium/drivers/zink/zink_compiler.c @@ -50,6 +50,26 @@ bool zink_lower_cubemap_to_array(nir_shader *s, uint32_t nonseamless_cube_mask); + +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)); + } +} + #define SIZEOF_FIELD(type, field) sizeof(((type *)0)->field) static void @@ -488,8 +508,8 @@ lower_pv_mode_emit_rotated_prim(nir_builder *b, gl_varying_slot location = var->data.location; if (state->varyings[location]) { nir_ssa_def *index = lower_pv_mode_gs_ring_index(b, state, rotated_i); - nir_ssa_def *value = nir_load_array_var(b, state->varyings[location], index); - nir_store_var(b, var, value, (1u << value->num_components) - 1); + nir_deref_instr *value = nir_build_deref_array(b, nir_build_deref_var(b, state->varyings[location]), index); + copy_vars(b, nir_build_deref_var(b, var), value); } } nir_emit_vertex(b); @@ -1160,25 +1180,6 @@ lower_64bit_pack(nir_shader *shader) nir_metadata_block_index | nir_metadata_dominance, NULL); } -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)); - } -} - nir_shader * zink_create_quads_emulation_gs(const nir_shader_compiler_options *options, const nir_shader *prev_stage,