From 52a55f097f3105e25e778f173c2133bfc00478ad Mon Sep 17 00:00:00 2001 From: Jordan Justen Date: Thu, 9 Dec 2021 13:05:29 -0800 Subject: [PATCH] intel/compiler: Use nir_lower_tex_options::lower_offset_filter for tg4 on XeHP Based on Rafael's: * "nir/lower_tex: Add option to lower offset for tg4 too." * "intel/compiler: Lower offsets for tg4 on gen9+." * "WIP: Do not lower basic offsets." * "WIP: intel/compiler: Enable lowering offsets restriction." But, with these changes: * Fixed range checking to be signed 4 bits * Converted to filter * Apply only to gfx12.5+ * Use nir_src_is_const / nir_src_comp_as_int (s-b Jason) Signed-off-by: Jordan Justen Reviewed-by: Jason Ekstrand Part-of: --- src/intel/compiler/brw_nir.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c index 16a2e7c..ec0a690 100644 --- a/src/intel/compiler/brw_nir.c +++ b/src/intel/compiler/brw_nir.c @@ -746,6 +746,34 @@ lower_bit_size_callback(const nir_instr *instr, UNUSED void *data) } } +/* On gfx12.5+, if the offsets are not both constant and in the {-8,7} range, + * we will have nir_lower_tex() lower the source offset by returning true from + * this filter function. + */ +static bool +lower_xehp_tg4_offset_filter(const nir_instr *instr, UNUSED const void *data) +{ + if (instr->type != nir_instr_type_tex) + return false; + + nir_tex_instr *tex = nir_instr_as_tex(instr); + + if (tex->op != nir_texop_tg4) + return false; + + int offset_index = nir_tex_instr_src_index(tex, nir_tex_src_offset); + if (offset_index < 0) + return false; + + if (!nir_src_is_const(tex->src[offset_index].src)) + return true; + + int64_t offset_x = nir_src_comp_as_int(tex->src[offset_index].src, 0); + int64_t offset_y = nir_src_comp_as_int(tex->src[offset_index].src, 1); + + return offset_x < -8 || offset_x > 7 || offset_y < -8 || offset_y > 7; +} + /* Does some simple lowering and runs the standard suite of optimizations * * This is intended to be called more-or-less directly after you get the @@ -792,6 +820,8 @@ brw_preprocess_nir(const struct brw_compiler *compiler, nir_shader *nir, .lower_txd_offset_clamp = true, .lower_tg4_offsets = true, .lower_txs_lod = true, /* Wa_14012320009 */ + .lower_offset_filter = + devinfo->verx10 >= 125 ? lower_xehp_tg4_offset_filter : NULL, }; OPT(nir_lower_tex, &tex_options); -- 2.7.4