From 7da58350035dedf930d034f03a8dfe5f4d2f369d Mon Sep 17 00:00:00 2001 From: Connor Abbott Date: Tue, 25 Jun 2024 16:04:20 -0400 Subject: [PATCH] ir3: Make sure constlen includes stc/ldc.k/ldg.k instructions nir_opt_preamble sometimes adds useless expressions, in which case we may have stc instructions and no corresponding use of the constant. Things can go sideways when these aren't included in the constlen, so far only observed when earlypreamble is enabled. Fixes: ccc64b7e00b ("ir3: Plumb through store_uniform_ir3 intrinsic") Part-of: (cherry picked from commit c42f6597f9f1f27e632b47f77b360f5fb6a39e40) --- .pick_status.json | 2 +- src/freedreno/ir3/ir3_compiler_nir.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.pick_status.json b/.pick_status.json index c856dadec66..50b78941e74 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -244,7 +244,7 @@ "description": "ir3: Make sure constlen includes stc/ldc.k/ldg.k instructions", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "ccc64b7e00b69ce3b0e20df6cf6b6ad68e7c9f79", "notes": null diff --git a/src/freedreno/ir3/ir3_compiler_nir.c b/src/freedreno/ir3/ir3_compiler_nir.c index f5e89b4d0ec..a335ad04832 100644 --- a/src/freedreno/ir3/ir3_compiler_nir.c +++ b/src/freedreno/ir3/ir3_compiler_nir.c @@ -907,6 +907,12 @@ emit_intrinsic_copy_ubo_to_uniform(struct ir3_context *ctx, ir3_instr_set_address(ldc, addr1); + /* The assembler isn't aware of what value a1.x has, so make sure that + * constlen includes the ldc.k here. + */ + ctx->so->constlen = + MAX2(ctx->so->constlen, DIV_ROUND_UP(base + size * 4, 4)); + array_insert(b, b->keeps, ldc); } @@ -940,6 +946,12 @@ emit_intrinsic_copy_global_to_uniform(struct ir3_context *ctx, ldg->flags |= IR3_INSTR_A1EN; } + /* The assembler isn't aware of what value a1.x has, so make sure that + * constlen includes the ldg.k here. + */ + ctx->so->constlen = + MAX2(ctx->so->constlen, DIV_ROUND_UP(dst + size * 4, 4)); + array_insert(b, b->keeps, ldg); } @@ -2772,6 +2784,11 @@ emit_intrinsic(struct ir3_context *ctx, nir_intrinsic_instr *intr) ir3_instr_set_address(stc, a1); stc->flags |= IR3_INSTR_A1EN; } + /* The assembler isn't aware of what value a1.x has, so make sure that + * constlen includes the stc here. + */ + ctx->so->constlen = + MAX2(ctx->so->constlen, DIV_ROUND_UP(dst + components, 4)); array_insert(b, b->keeps, stc); break; }