From 4a84ebfcb196631b3bc9aa2271606e105be3e7ec Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Thu, 22 May 2025 18:08:50 +0200 Subject: [PATCH] ac/llvm: rework component trimming in visit_tex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The referenced commit was a step in the right direction, but not complete. ac_build_image_opcode returns a vec<4> or a struct, int> so we can simplify visit_tex. We just need to map these 4/5 values to the expected layout from NIR. eg: depth + TFE would produces ", t" so it has to be transformed into . nir_texop_fragment_mask_fetch_amd + sparse doesn't exist, so it's another opportunity for simplification. This is required to get KHR-GL46.sparse_texture2_tests.SparseTexture2Lookup_texture_2d_depth_component16 working properly. The same test fails with ACO so it probably needs a change in the same area. Fixes: c0ef2aa7f8b ("DEPENDENCY: ac/llvm: fix sparse code handling") Reviewed-by: Marek Olšák Part-of: --- src/amd/llvm/ac_nir_to_llvm.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/amd/llvm/ac_nir_to_llvm.c b/src/amd/llvm/ac_nir_to_llvm.c index b7ccaa8338d..9c5cf9ab398 100644 --- a/src/amd/llvm/ac_nir_to_llvm.c +++ b/src/amd/llvm/ac_nir_to_llvm.c @@ -3754,16 +3754,7 @@ static void visit_tex(struct ac_nir_context *ctx, nir_tex_instr *instr) result = build_tex_intrinsic(ctx, instr, &args); - LLVMValueRef code = NULL; - if (instr->is_sparse) { - unsigned num_color_components = num_components - 1; - code = ac_llvm_extract_elem(&ctx->ac, result, num_color_components); - result = ac_trim_vector(&ctx->ac, result, num_color_components); - } - - if (is_new_style_shadow) - result = LLVMBuildExtractElement(ctx->ac.builder, result, ctx->ac.i32_0, ""); - else if (instr->op == nir_texop_fragment_mask_fetch_amd) { + if (instr->op == nir_texop_fragment_mask_fetch_amd) { /* Use 0x76543210 if the image doesn't have FMASK. */ LLVMValueRef tmp = LLVMBuildBitCast(ctx->ac.builder, args.resource, ctx->ac.v8i32, ""); tmp = LLVMBuildExtractElement(ctx->ac.builder, tmp, ctx->ac.i32_1, ""); @@ -3772,12 +3763,19 @@ static void visit_tex(struct ac_nir_context *ctx, nir_tex_instr *instr) LLVMBuildExtractElement(ctx->ac.builder, result, ctx->ac.i32_0, ""), LLVMConstInt(ctx->ac.i32, 0x76543210, false), ""); } else { - unsigned num_color_components = num_components - (instr->is_sparse ? 1 : 0); - result = ac_trim_vector(&ctx->ac, result, num_color_components); - } + /* ac_build_image_opcode always returns 4 components plus 1 optional value + * containing residency information. Adjust result to match the output expected by + * the NIR instruction. + */ + LLVMValueRef code = NULL; + if (instr->is_sparse) + code = ac_llvm_extract_elem(&ctx->ac, result, 4); - if (instr->is_sparse) - result = ac_build_concat(&ctx->ac, result, code); + result = ac_trim_vector(&ctx->ac, result, num_components - (instr->is_sparse ? 1 : 0)); + + if (code) + result = ac_build_concat(&ctx->ac, result, code); + } if (result) { result = ac_to_integer(&ctx->ac, result);