nir: add lowering for gl_HelperInvocation
authorRob Clark <robdclark@gmail.com>
Fri, 1 Jun 2018 18:07:15 +0000 (14:07 -0400)
committerRob Clark <robdclark@gmail.com>
Wed, 18 Jul 2018 14:10:44 +0000 (10:10 -0400)
v2: reword comment about lower_helper_invocations to be more clear
    that it might not work on all hardware
v3: add special variant of load_sample_id which does not imply per-
    sample shading

Signed-off-by: Rob Clark <robdclark@gmail.com>
src/compiler/nir/nir.h
src/compiler/nir/nir_intrinsics.py
src/compiler/nir/nir_lower_system_values.c
src/gallium/drivers/freedreno/ir3/ir3_compiler_nir.c
src/gallium/drivers/freedreno/ir3/ir3_nir.c

index d3e63be091fef0b58a8e92460ae650b396f2083c..3bfe7d7f7bf83e781f46b7942caa133259ec1b97 100644 (file)
@@ -2006,6 +2006,20 @@ typedef struct nir_shader_compiler_options {
     */
    bool lower_base_vertex;
 
+   /**
+    * If enabled, gl_HelperInvocation will be lowered as:
+    *
+    *   !((1 << sample_id) & sample_mask_in))
+    *
+    * This depends on some possibly hw implementation details, which may
+    * not be true for all hw.  In particular that the FS is only executed
+    * for covered samples or for helper invocations.  So, do not blindly
+    * enable this option.
+    *
+    * Note: See also issue #22 in ARB_shader_image_load_store
+    */
+   bool lower_helper_invocation;
+
    bool lower_cs_local_index_from_id;
 
    bool lower_device_index_to_zero;
index eaa40e95acc16a334af2d5c666e1913fa88d22ac..d688a57181b06908b98f3680694c66c9c5ed6134 100644 (file)
@@ -424,6 +424,9 @@ system_value("instance_id", 1)
 system_value("base_instance", 1)
 system_value("draw_id", 1)
 system_value("sample_id", 1)
+# sample_id_no_per_sample is like sample_id but does not imply per-
+# sample shading.  See the lower_helper_invocation option.
+system_value("sample_id_no_per_sample", 1)
 system_value("sample_pos", 2)
 system_value("sample_mask_in", 1)
 system_value("primitive_id", 1)
index da04895d66cc4ff7f2a63f5c922810816fa78088..2820dcd1b3ce83139a0cdbbb780c469ad2e871e9 100644 (file)
@@ -144,6 +144,23 @@ convert_block(nir_block *block, nir_builder *b)
                               nir_load_first_vertex(b));
          break;
 
+      case SYSTEM_VALUE_HELPER_INVOCATION:
+         if (b->shader->options->lower_helper_invocation) {
+            nir_ssa_def *tmp;
+
+            tmp = nir_ishl(b,
+                           nir_imm_int(b, 1),
+                           nir_load_sample_id_no_per_sample(b));
+
+            tmp = nir_iand(b,
+                           nir_load_sample_mask_in(b),
+                           tmp);
+
+            sysval = nir_inot(b, nir_i2b(b, tmp));
+         }
+
+         break;
+
       case SYSTEM_VALUE_INSTANCE_INDEX:
          sysval = nir_iadd(b,
                            nir_load_instance_id(b),
index 892fb0614427eb2c1b2d1713344dac7783a90588..9f74fa2530a9ad333c7a03d28f019ee89cbf59c6 100644 (file)
@@ -2445,6 +2445,7 @@ emit_intrinsic(struct ir3_context *ctx, nir_intrinsic_instr *intr)
                dst[0] = ctx->instance_id;
                break;
        case nir_intrinsic_load_sample_id:
+       case nir_intrinsic_load_sample_id_no_per_sample:
                if (!ctx->samp_id) {
                        ctx->samp_id = create_input(b, 0);
                        ctx->samp_id->regs[0]->flags |= IR3_REG_HALF;
index 8f46aef14e4b174c2b54f14a77d2cb2ac4309357..db1d74fdee766c732874e30c23c6a17c1d001135 100644 (file)
@@ -52,6 +52,7 @@ static const nir_shader_compiler_options options = {
                .lower_extract_byte = true,
                .lower_extract_word = true,
                .lower_all_io_to_temps = true,
+               .lower_helper_invocation = true,
 };
 
 struct nir_shader *