Mesa (main): intel/fs: Fix IsHelperInvocation for the case no discard/demote are used

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Mar 25 09:11:47 UTC 2022


Module: Mesa
Branch: main
Commit: f82731d0d7ada7bbca4a6742568925b6f97c91aa
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f82731d0d7ada7bbca4a6742568925b6f97c91aa

Author: Caio Oliveira <caio.oliveira at intel.com>
Date:   Tue Mar 15 17:04:04 2022 -0700

intel/fs: Fix IsHelperInvocation for the case no discard/demote are used

Use emit_predicate_on_sample_mask() helper that does check where to
get the correct mask depending on whether discard/demote was used or
not.

Fixes: 45f5db5a84a ("intel/fs: Implement "demote to helper invocation"")
Reviewed-by: Jason Ekstrand <jason.ekstrand at collabora.com>
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15400>

---

 src/intel/compiler/brw_fs.cpp     | 27 +++++++++++++++++++++++++++
 src/intel/compiler/brw_fs.h       |  1 +
 src/intel/compiler/brw_fs_nir.cpp | 17 ++---------------
 3 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/src/intel/compiler/brw_fs.cpp b/src/intel/compiler/brw_fs.cpp
index 97f0aee2d58..7914dd4c549 100644
--- a/src/intel/compiler/brw_fs.cpp
+++ b/src/intel/compiler/brw_fs.cpp
@@ -5478,6 +5478,33 @@ emit_predicate_on_sample_mask(const fs_builder &bld, fs_inst *inst)
    }
 }
 
+void
+fs_visitor::emit_is_helper_invocation(fs_reg result)
+{
+   /* Unlike the regular gl_HelperInvocation, that is defined at dispatch,
+    * the helperInvocationEXT() (aka SpvOpIsHelperInvocationEXT) takes into
+    * consideration demoted invocations.
+    */
+   result.type = BRW_REGISTER_TYPE_UD;
+
+   bld.MOV(result, brw_imm_ud(0));
+
+   /* See sample_mask_reg() for why we split SIMD32 into SIMD16 here. */
+   unsigned width = bld.dispatch_width();
+   for (unsigned i = 0; i < DIV_ROUND_UP(width, 16); i++) {
+      const fs_builder b = bld.group(MIN2(width, 16), i);
+
+      fs_inst *mov = b.MOV(offset(result, b, i), brw_imm_ud(~0));
+
+      /* The at() ensures that any code emitted to get the predicate happens
+       * before the mov right above.  This is not an issue elsewhere because
+       * lowering code already set up the builder this way.
+       */
+      emit_predicate_on_sample_mask(b.at(NULL, mov), mov);
+      mov->predicate_inverse = true;
+   }
+}
+
 /**
  * Predicate the specified instruction on the vector mask.
  */
diff --git a/src/intel/compiler/brw_fs.h b/src/intel/compiler/brw_fs.h
index 3f6489a88cd..4afb77146bc 100644
--- a/src/intel/compiler/brw_fs.h
+++ b/src/intel/compiler/brw_fs.h
@@ -203,6 +203,7 @@ public:
    void emit_dummy_fs();
    void emit_repclear_shader();
    void emit_fragcoord_interpolation(fs_reg wpos);
+   void emit_is_helper_invocation(fs_reg result);
    fs_reg emit_frontfacing_interpolation();
    fs_reg emit_samplepos_setup();
    fs_reg emit_sampleid_setup();
diff --git a/src/intel/compiler/brw_fs_nir.cpp b/src/intel/compiler/brw_fs_nir.cpp
index 76136fa16e3..b172d9c29a2 100644
--- a/src/intel/compiler/brw_fs_nir.cpp
+++ b/src/intel/compiler/brw_fs_nir.cpp
@@ -3458,22 +3458,9 @@ fs_visitor::nir_emit_fs_intrinsic(const fs_builder &bld,
       bld.MOV(dest, fetch_render_target_array_index(bld));
       break;
 
-   case nir_intrinsic_is_helper_invocation: {
-      /* Unlike the regular gl_HelperInvocation, that is defined at dispatch,
-       * the helperInvocationEXT() (aka SpvOpIsHelperInvocationEXT) takes into
-       * consideration demoted invocations.  That information is stored in
-       * f0.1.
-       */
-      dest.type = BRW_REGISTER_TYPE_UD;
-
-      bld.MOV(dest, brw_imm_ud(0));
-
-      fs_inst *mov = bld.MOV(dest, brw_imm_ud(~0));
-      mov->predicate = BRW_PREDICATE_NORMAL;
-      mov->predicate_inverse = true;
-      mov->flag_subreg = sample_mask_flag_subreg(this);
+   case nir_intrinsic_is_helper_invocation:
+      emit_is_helper_invocation(dest);
       break;
-   }
 
    case nir_intrinsic_load_helper_invocation:
    case nir_intrinsic_load_sample_mask_in:



More information about the mesa-commit mailing list