From aa28fcb6105d4504850cf649e483289a86f37605 Mon Sep 17 00:00:00 2001 From: Konstantin Seurer Date: Sat, 1 Nov 2025 14:19:59 +0100 Subject: [PATCH] llvmpipe: Always recompute 1/w The value depends on the tgsi_interpolate_loc which is not constant for the loop. llvm should be able to cse in cases where they are the same. cc: mesa-stable Reviewed-by: Dave Airlie Part-of: --- src/gallium/drivers/llvmpipe/lp_bld_interp.c | 35 +++++++++----------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/gallium/drivers/llvmpipe/lp_bld_interp.c b/src/gallium/drivers/llvmpipe/lp_bld_interp.c index 3fbe0c92fd4..ea6d4af2303 100644 --- a/src/gallium/drivers/llvmpipe/lp_bld_interp.c +++ b/src/gallium/drivers/llvmpipe/lp_bld_interp.c @@ -338,7 +338,6 @@ attribs_update_simple(struct lp_build_interp_soa_context *bld, LLVMBuilderRef builder = gallivm->builder; struct lp_build_context *coeff_bld = &bld->coeff_bld; struct lp_build_context *setup_bld = &bld->setup_bld; - LLVMValueRef oow = NULL; LLVMValueRef pixoffx; LLVMValueRef pixoffy; LLVMValueRef ptr; @@ -425,25 +424,23 @@ attribs_update_simple(struct lp_build_interp_soa_context *bld, } if (interp == LP_INTERP_PERSPECTIVE) { - if (oow == NULL) { - LLVMValueRef w; - assert(attrib != 0); - assert(bld->mask[0] & TGSI_WRITEMASK_W); - if (bld->coverage_samples > 1 && - (loc == TGSI_INTERPOLATE_LOC_SAMPLE || - loc == TGSI_INTERPOLATE_LOC_CENTROID)) { - /* - * We can't use the precalculated 1/w since we didn't know - * the actual position yet (we were assuming center). - */ - LLVMValueRef indexw = lp_build_const_int32(gallivm, 3); - w = interp_attrib_linear(bld, 0, indexw, chan_pixoffx, chan_pixoffy); - } - else { - w = bld->attribs[0][3]; - } - oow = lp_build_rcp(coeff_bld, w); + LLVMValueRef w; + assert(attrib != 0); + assert(bld->mask[0] & TGSI_WRITEMASK_W); + if (bld->coverage_samples > 1 && + (loc == TGSI_INTERPOLATE_LOC_SAMPLE || + loc == TGSI_INTERPOLATE_LOC_CENTROID)) { + /* + * We can't use the precalculated 1/w since we didn't know + * the actual position yet (we were assuming center). + */ + LLVMValueRef indexw = lp_build_const_int32(gallivm, 3); + w = interp_attrib_linear(bld, 0, indexw, chan_pixoffx, chan_pixoffy); } + else { + w = bld->attribs[0][3]; + } + LLVMValueRef oow = lp_build_rcp(coeff_bld, w); a = lp_build_mul(coeff_bld, a, oow); }