diff options
author | Christian Gmeiner <cgmeiner@igalia.com> | 2023-07-08 17:37:35 +0200 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2023-07-12 10:03:06 +0000 |
commit | f831883af6389097624d0f9d8b067eb59b2c4780 (patch) | |
tree | a2a426f89982de8934db79304d43f56a026719b3 | |
parent | 938300980946526926bdd2082178133d6081f4df (diff) |
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 <cgmeiner@igalia.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24054>
-rw-r--r-- | src/compiler/nir/nir_lower_tex.c | 11 |
1 files 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, |