nir/subgroups: Lower clustered reductions with cluster_size >= subgroup_size into...
authorRhys Perry <pendingchaos02@gmail.com>
Wed, 24 Apr 2019 09:25:25 +0000 (10:25 +0100)
committerDaniel Schürmann <daniel@schuermann.dev>
Tue, 20 Aug 2019 15:40:10 +0000 (17:40 +0200)
The behavior for reductions with cluster_size >= subgroup_size is implementation defined.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/nir/nir_lower_subgroups.c

index 1e2e3f0eebf2003d834f1fe76a1d9e5f27e757f4..249d5e446bdc48c43c6d341558478fa99fec9b2a 100644 (file)
@@ -479,7 +479,18 @@ lower_subgroups_instr(nir_builder *b, nir_instr *instr, void *_options)
          return lower_subgroup_op_to_scalar(b, intrin, false);
       break;
 
-   case nir_intrinsic_reduce:
+   case nir_intrinsic_reduce: {
+      nir_ssa_def *ret = NULL;
+      /* A cluster size greater than the subgroup size is implemention defined */
+      if (options->subgroup_size &&
+          nir_intrinsic_cluster_size(intrin) >= options->subgroup_size) {
+         nir_intrinsic_set_cluster_size(intrin, 0);
+         ret = NIR_LOWER_INSTR_PROGRESS;
+      }
+      if (options->lower_to_scalar && intrin->num_components > 1)
+         ret = lower_subgroup_op_to_scalar(b, intrin, false);
+      return ret;
+   }
    case nir_intrinsic_inclusive_scan:
    case nir_intrinsic_exclusive_scan:
       if (options->lower_to_scalar && intrin->num_components > 1)