From: Rhys Perry Date: Fri, 29 Sep 2023 15:33:50 +0000 (+0100) Subject: nir/constant_folding: remove zero texel offset X-Git-Tag: upstream/23.3.3~1383 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7139a789596ea59698ad4d01a9401266f2da2e52;p=platform%2Fupstream%2Fmesa.git nir/constant_folding: remove zero texel offset fossil-db (navi31): Totals from 7 (0.01% of 79330) affected shaders: Instrs: 7001 -> 6993 (-0.11%) CodeSize: 35736 -> 35692 (-0.12%) InvThroughput: 3232 -> 3229 (-0.09%) Copies: 552 -> 549 (-0.54%) PreSGPRs: 277 -> 273 (-1.44%) Signed-off-by: Rhys Perry Reviewed-by: Alyssa Rosenzweig Reviewed-by: Daniel Schürmann Part-of: --- diff --git a/src/compiler/nir/nir_opt_constant_folding.c b/src/compiler/nir/nir_opt_constant_folding.c index 7231678..2e5987c 100644 --- a/src/compiler/nir/nir_opt_constant_folding.c +++ b/src/compiler/nir/nir_opt_constant_folding.c @@ -338,6 +338,27 @@ try_fold_tex_offset(nir_tex_instr *tex, unsigned *index, } static bool +try_fold_texel_offset_src(nir_tex_instr *tex) +{ + int offset_src = nir_tex_instr_src_index(tex, nir_tex_src_offset); + if (offset_src < 0) + return false; + + unsigned size = nir_tex_instr_src_size(tex, offset_src); + nir_tex_src *src = &tex->src[offset_src]; + + for (unsigned i = 0; i < size; i++) { + nir_scalar comp = nir_scalar_resolved(src->src.ssa, i); + if (!nir_scalar_is_const(comp) || nir_scalar_as_uint(comp) != 0) + return false; + } + + nir_tex_instr_remove_src(tex, offset_src); + + return true; +} + +static bool try_fold_tex(nir_builder *b, nir_tex_instr *tex) { bool progress = false; @@ -351,6 +372,9 @@ try_fold_tex(nir_builder *b, nir_tex_instr *tex) if (tex->op == nir_texop_txb) progress |= try_fold_txb_to_tex(b, tex); + /* tex with a zero offset is just tex. */ + progress |= try_fold_texel_offset_src(tex); + return progress; }