nir/lower_tex: Add filter for tex offset lowering
authorJordan Justen <jordan.l.justen@intel.com>
Thu, 9 Dec 2021 20:55:21 +0000 (12:55 -0800)
committerJordan Justen <jordan.l.justen@intel.com>
Tue, 14 Dec 2021 00:56:23 +0000 (16:56 -0800)
Rework:
 * Add callback_data (s-b Jason)

Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14142>

src/compiler/nir/nir.h
src/compiler/nir/nir_lower_tex.c

index a177daa..2a664c9 100644 (file)
@@ -4735,6 +4735,12 @@ typedef struct nir_lower_tex_options {
    bool lower_rect_offset;
 
    /**
+    * If not NULL, this filter will return true for tex instructions that
+    * should lower away nir_tex_src_offset.
+    */
+   nir_instr_filter_cb lower_offset_filter;
+
+   /**
     * If true, lower rect textures to 2D, using txs to fetch the
     * texture dimensions and dividing the texture coords by the
     * texture dims to normalize.
@@ -4897,6 +4903,11 @@ typedef struct nir_lower_tex_options {
     * absolute values of derivatives is 0 for all coordinates.
     */
    bool lower_lod_zero_width;
+
+   /**
+    * Payload data to be sent to callback / filter functions.
+    */
+   void *callback_data;
 } nir_lower_tex_options;
 
 /** Lowers complex texture instructions to simpler ones */
index d3ff7ca..2664925 100644 (file)
@@ -1321,7 +1321,9 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
       if ((tex->op == nir_texop_txf && options->lower_txf_offset) ||
           (sat_mask && nir_tex_instr_src_index(tex, nir_tex_src_coord) >= 0) ||
           (tex->sampler_dim == GLSL_SAMPLER_DIM_RECT &&
-           options->lower_rect_offset)) {
+           options->lower_rect_offset) ||
+          (options->lower_offset_filter &&
+           options->lower_offset_filter(instr, options->callback_data))) {
          progress = lower_offset(b, tex) || progress;
       }