From a506d49faecf06d5cd2fd2d049319d907b273b83 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Wed, 6 May 2020 13:35:51 -0700 Subject: [PATCH] nir: add helper to copy const_index[] It seems less brittle to not assume they are in the same order for src and dst instructions. Signed-off-by: Rob Clark Reviewed-by: Kristian H. Kristensen Reviewed-by: Eric Anholt --- src/compiler/nir/nir.h | 27 ++++++++++++++++++++ src/freedreno/ir3/ir3_nir_lower_io_offsets.c | 3 +-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index c2a0053c382..b12deb2cd78 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -1763,6 +1763,33 @@ nir_intrinsic_dest_components(nir_intrinsic_instr *intr) return intr->num_components; } +/** + * Helper to copy const_index[] from src to dst, without assuming they + * match in order. + */ +static inline void +nir_intrinsic_copy_const_indices(nir_intrinsic_instr *dst, nir_intrinsic_instr *src) +{ + if (src->intrinsic == dst->intrinsic) { + memcpy(dst->const_index, src->const_index, sizeof(dst->const_index)); + return; + } + + const nir_intrinsic_info *src_info = &nir_intrinsic_infos[src->intrinsic]; + const nir_intrinsic_info *dst_info = &nir_intrinsic_infos[dst->intrinsic]; + + for (unsigned i = 0; i < NIR_INTRINSIC_NUM_INDEX_FLAGS; i++) { + if (src_info->index_map[i] == 0) + continue; + + /* require that dst instruction also uses the same const_index[]: */ + assert(dst_info->index_map[i] > 0); + + dst->const_index[dst_info->index_map[i] - 1] = + src->const_index[src_info->index_map[i] - 1]; + } +} + #define INTRINSIC_IDX_ACCESSORS(name, flag, type) \ static inline type \ nir_intrinsic_##name(const nir_intrinsic_instr *instr) \ diff --git a/src/freedreno/ir3/ir3_nir_lower_io_offsets.c b/src/freedreno/ir3/ir3_nir_lower_io_offsets.c index 2d035eedd23..36c48cf1299 100644 --- a/src/freedreno/ir3/ir3_nir_lower_io_offsets.c +++ b/src/freedreno/ir3/ir3_nir_lower_io_offsets.c @@ -217,8 +217,7 @@ lower_offset_for_ssbo(nir_intrinsic_instr *intrinsic, nir_builder *b, for (unsigned i = 0; i < num_srcs; i++) new_intrinsic->src[i] = nir_src_for_ssa(intrinsic->src[i].ssa); - for (unsigned i = 0; i < NIR_INTRINSIC_MAX_CONST_INDEX; i++) - new_intrinsic->const_index[i] = intrinsic->const_index[i]; + nir_intrinsic_copy_const_indices(new_intrinsic, intrinsic); new_intrinsic->num_components = intrinsic->num_components; -- 2.30.2