From f831883af6389097624d0f9d8b067eb59b2c4780 Mon Sep 17 00:00:00 2001 From: Christian Gmeiner Date: Sat, 8 Jul 2023 17:37:35 +0200 Subject: [PATCH] nir/lower_tex: optimize offset lowering for has_texture_scaling Generates much better code and even helps to beat a blob driver. Signed-off-by: Christian Gmeiner Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir_lower_tex.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c index 3e9d43e9cbb..8453adbe388 100644 --- a/src/compiler/nir/nir_lower_tex.c +++ b/src/compiler/nir/nir_lower_tex.c @@ -176,8 +176,15 @@ lower_offset(nir_builder *b, nir_tex_instr *tex) if (tex->sampler_dim == GLSL_SAMPLER_DIM_RECT) { offset_coord = nir_fadd(b, coord, nir_i2f32(b, offset)); } else { - nir_ssa_def *txs = nir_i2f32(b, nir_get_texture_size(b, tex)); - nir_ssa_def *scale = nir_frcp(b, txs); + nir_ssa_def *scale = NULL; + + if (b->shader->options->has_texture_scaling) { + nir_ssa_def *idx = nir_imm_int(b, tex->texture_index); + scale = nir_load_texture_scale(b, 32, idx); + } else { + nir_ssa_def *txs = nir_i2f32(b, nir_get_texture_size(b, tex)); + scale = nir_frcp(b, txs); + } offset_coord = nir_fadd(b, coord, nir_fmul(b,