Mesa (master): nir/lower_input_attachments: lower nir_texop_fragment_{mask}_fetch

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jan 23 11:10:19 UTC 2020


Module: Mesa
Branch: master
Commit: 84b08971fbdced78dbcb085d633298db7e4bfa7f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=84b08971fbdced78dbcb085d633298db7e4bfa7f

Author: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Date:   Tue Jan  7 10:01:14 2020 +0100

nir/lower_input_attachments: lower nir_texop_fragment_{mask}_fetch

These instructions are allowed to fetch from multisampled
subpass input attachments.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3304>

---

 src/compiler/nir/nir_lower_input_attachments.c | 62 +++++++++++++++++++++-----
 1 file changed, 52 insertions(+), 10 deletions(-)

diff --git a/src/compiler/nir/nir_lower_input_attachments.c b/src/compiler/nir/nir_lower_input_attachments.c
index a82e887ad8c..72dd7afc33a 100644
--- a/src/compiler/nir/nir_lower_input_attachments.c
+++ b/src/compiler/nir/nir_lower_input_attachments.c
@@ -126,6 +126,35 @@ try_lower_input_load(nir_function_impl *impl, nir_intrinsic_instr *load,
    return true;
 }
 
+static bool
+try_lower_input_texop(nir_function_impl *impl, nir_tex_instr *tex,
+							 bool use_fragcoord_sysval)
+{
+   nir_deref_instr *deref = nir_src_as_deref(tex->src[0].src);
+   assert(glsl_type_is_image(deref->type));
+
+   if (glsl_get_sampler_dim(deref->type) != GLSL_SAMPLER_DIM_SUBPASS_MS)
+      return false;
+
+   nir_builder b;
+   nir_builder_init(&b, impl);
+   b.cursor = nir_before_instr(&tex->instr);
+
+   nir_ssa_def *frag_coord = use_fragcoord_sysval ? nir_load_frag_coord(&b)
+                                                  : load_frag_coord(&b);
+   frag_coord = nir_f2i32(&b, frag_coord);
+
+   nir_ssa_def *layer = nir_load_layer_id(&b);
+   nir_ssa_def *coord = nir_vec3(&b, nir_channel(&b, frag_coord, 0),
+                                     nir_channel(&b, frag_coord, 1), layer);
+
+   tex->coord_components = 3;
+
+   nir_instr_rewrite_src(&tex->instr, &tex->src[1].src, nir_src_for_ssa(coord));
+
+   return true;
+}
+
 bool
 nir_lower_input_attachments(nir_shader *shader, bool use_fragcoord_sysval)
 {
@@ -138,16 +167,29 @@ nir_lower_input_attachments(nir_shader *shader, bool use_fragcoord_sysval)
 
       nir_foreach_block(block, function->impl) {
          nir_foreach_instr_safe(instr, block) {
-            if (instr->type != nir_instr_type_intrinsic)
-               continue;
-
-            nir_intrinsic_instr *load = nir_instr_as_intrinsic(instr);
-
-            if (load->intrinsic != nir_intrinsic_image_deref_load)
-               continue;
-
-            progress |= try_lower_input_load(function->impl, load,
-                                             use_fragcoord_sysval);
+            switch (instr->type) {
+            case nir_instr_type_tex: {
+               nir_tex_instr *tex = nir_instr_as_tex(instr);
+
+               if (tex->op == nir_texop_fragment_mask_fetch ||
+                   tex->op == nir_texop_fragment_fetch) {
+                  progress |= try_lower_input_texop(function->impl, tex,
+                                                    use_fragcoord_sysval);
+               }
+               break;
+            }
+            case nir_instr_type_intrinsic: {
+               nir_intrinsic_instr *load = nir_instr_as_intrinsic(instr);
+
+               if (load->intrinsic == nir_intrinsic_image_deref_load) {
+                  progress |= try_lower_input_load(function->impl, load,
+                                                   use_fragcoord_sysval);
+               }
+               break;
+            }
+            default:
+               break;
+            }
          }
       }
    }



More information about the mesa-commit mailing list