From e37093b160796860beae31e35d750646a1e360ac Mon Sep 17 00:00:00 2001 From: Job Noorman Date: Wed, 10 Apr 2024 10:43:38 +0200 Subject: [PATCH] ir3: use nir_opt_offsets for SSBO accesses Signed-off-by: Job Noorman Part-of: --- src/freedreno/ir3/ir3_nir.c | 7 +++++-- src/freedreno/ir3/ir3_nir.h | 2 ++ src/freedreno/ir3/ir3_nir_lower_io_offsets.c | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/freedreno/ir3/ir3_nir.c b/src/freedreno/ir3/ir3_nir.c index f5085e21489..a3426e86d41 100644 --- a/src/freedreno/ir3/ir3_nir.c +++ b/src/freedreno/ir3/ir3_nir.c @@ -215,7 +215,7 @@ ir3_optimize_loop(struct ir3_compiler *compiler, nir_shader *s) progress |= OPT(s, nir_lower_pack); progress |= OPT(s, nir_opt_constant_folding); - static const nir_opt_offsets_options offset_options = { + const nir_opt_offsets_options offset_options = { /* How large an offset we can encode in the instr's immediate field. */ .uniform_max = (1 << 9) - 1, @@ -225,7 +225,10 @@ ir3_optimize_loop(struct ir3_compiler *compiler, nir_shader *s) */ .shared_max = (1 << 12) - 1, - .buffer_max = ~0, + .buffer_max = 0, + .max_offset_cb = ir3_nir_max_imm_offset, + .max_offset_data = compiler, + .allow_offset_wrap = true, }; progress |= OPT(s, nir_opt_offsets, &offset_options); diff --git a/src/freedreno/ir3/ir3_nir.h b/src/freedreno/ir3/ir3_nir.h index b5ded1c554c..452e4a38cbe 100644 --- a/src/freedreno/ir3/ir3_nir.h +++ b/src/freedreno/ir3/ir3_nir.h @@ -156,6 +156,8 @@ is_intrinsic_load(nir_intrinsic_op op) } } +uint32_t ir3_nir_max_imm_offset(nir_intrinsic_instr *intrin, const void *data); + ENDC; #endif /* IR3_NIR_H_ */ diff --git a/src/freedreno/ir3/ir3_nir_lower_io_offsets.c b/src/freedreno/ir3/ir3_nir_lower_io_offsets.c index 04710be33f0..621fe7c43a9 100644 --- a/src/freedreno/ir3/ir3_nir_lower_io_offsets.c +++ b/src/freedreno/ir3/ir3_nir_lower_io_offsets.c @@ -287,3 +287,23 @@ ir3_nir_lower_io_offsets(nir_shader *shader) return progress; } + +uint32_t +ir3_nir_max_imm_offset(nir_intrinsic_instr *intrin, const void *data) +{ + const struct ir3_compiler *compiler = data; + + if (!compiler->has_ssbo_imm_offsets) + return 0; + + switch (intrin->intrinsic) { + case nir_intrinsic_load_ssbo_ir3: + if ((nir_intrinsic_access(intrin) & ACCESS_CAN_REORDER)) + return 255; /* isam.v */ + return 127; /* ldib.b */ + case nir_intrinsic_store_ssbo_ir3: + return 127; /* stib.b */ + default: + return 0; + } +}