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

Author: Daniel Schürmann <dan...@schuermann.dev>
Date:   Thu Nov  2 15:44:40 2023 +0100

nir: add info.fs.require_full_quads

This flag indicates the requirement of helper invocations
in fragment shaders, independent from any present instructions.
This fixes the lowering of OpGroupNonUniformQuad* instructions.

Reviewed-by: Georg Lehmann <dadschoo...@gmail.com>
Reviewed-by: Caio Oliveira <caio.olive...@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26026>

---

 src/compiler/nir/nir_gather_info.c |  4 ++++
 src/compiler/nir/nir_print.c       |  1 +
 src/compiler/shader_info.h         |  9 +++++++--
 src/compiler/spirv/vtn_subgroup.c  | 12 ++++++++++++
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/compiler/nir/nir_gather_info.c 
b/src/compiler/nir/nir_gather_info.c
index 39767a71b2a..9eac4abc311 100644
--- a/src/compiler/nir/nir_gather_info.c
+++ b/src/compiler/nir/nir_gather_info.c
@@ -762,6 +762,10 @@ gather_intrinsic_info(nir_intrinsic_instr *instr, 
nir_shader *shader,
    case nir_intrinsic_mbcnt_amd:
    case nir_intrinsic_write_invocation_amd:
       shader->info.uses_wide_subgroup_intrinsics = true;
+
+      if (shader->info.stage == MESA_SHADER_FRAGMENT &&
+          shader->info.fs.require_full_quads)
+         shader->info.fs.needs_quad_helper_invocations = true;
       break;
 
    case nir_intrinsic_end_primitive:
diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c
index 9c1b85cc394..ddcdbd46fc1 100644
--- a/src/compiler/nir/nir_print.c
+++ b/src/compiler/nir/nir_print.c
@@ -2535,6 +2535,7 @@ print_shader_info(const struct shader_info *info, FILE 
*fp)
       print_nz_bool(fp, "uses_fbfetch_output", info->fs.uses_fbfetch_output);
       print_nz_bool(fp, "color_is_dual_source", info->fs.color_is_dual_source);
 
+      print_nz_bool(fp, "require_full_quads", info->fs.require_full_quads);
       print_nz_bool(fp, "needs_quad_helper_invocations", 
info->fs.needs_quad_helper_invocations);
       print_nz_bool(fp, "uses_sample_qualifier", 
info->fs.uses_sample_qualifier);
       print_nz_bool(fp, "uses_sample_shading", info->fs.uses_sample_shading);
diff --git a/src/compiler/shader_info.h b/src/compiler/shader_info.h
index 687b076ffdd..ccaefb0df2d 100644
--- a/src/compiler/shader_info.h
+++ b/src/compiler/shader_info.h
@@ -414,11 +414,16 @@ typedef struct shader_info {
          bool fbfetch_coherent:1;
          bool color_is_dual_source:1;
 
+         /**
+          * True if this fragment shader requires full quad invocations.
+          */
+         bool require_full_quads:1;
+
          /**
           * True if this fragment shader requires helper invocations.  This
           * can be caused by the use of ALU derivative ops, texture
-          * instructions which do implicit derivatives, and the use of quad
-          * subgroup operations.
+          * instructions which do implicit derivatives, the use of quad
+          * subgroup operations or if the shader requires full quads.
           */
          bool needs_quad_helper_invocations:1;
 
diff --git a/src/compiler/spirv/vtn_subgroup.c 
b/src/compiler/spirv/vtn_subgroup.c
index de18259a199..efd4ad8f5d3 100644
--- a/src/compiler/spirv/vtn_subgroup.c
+++ b/src/compiler/spirv/vtn_subgroup.c
@@ -341,6 +341,15 @@ vtn_handle_subgroup(struct vtn_builder *b, SpvOp opcode,
    }
 
    case SpvOpGroupNonUniformQuadBroadcast:
+      /* From the Vulkan spec 1.3.269:
+       *
+       * 9.27. Quad Group Operations:
+       * "Fragment shaders that statically execute quad group operations
+       * must launch sufficient invocations to ensure their correct operation;"
+       */
+      if (b->shader->info.stage == MESA_SHADER_FRAGMENT)
+         b->shader->info.fs.require_full_quads = true;
+
       vtn_push_ssa_value(b, w[2],
          vtn_build_subgroup_instr(b, nir_intrinsic_quad_broadcast,
                                   vtn_ssa_value(b, w[4]),
@@ -348,6 +357,9 @@ vtn_handle_subgroup(struct vtn_builder *b, SpvOp opcode,
       break;
 
    case SpvOpGroupNonUniformQuadSwap: {
+      if (b->shader->info.stage == MESA_SHADER_FRAGMENT)
+         b->shader->info.fs.require_full_quads = true;
+
       unsigned direction = vtn_constant_uint(b, w[5]);
       nir_intrinsic_op op;
       switch (direction) {

Reply via email to