From aebb47b7d1da799e2b0df14314a8e729c73dca0a Mon Sep 17 00:00:00 2001 From: Iago Toral Quiroga Date: Thu, 29 Apr 2021 11:10:32 +0200 Subject: [PATCH] compiler/nir: add a divergence analysis option for non-uniform workgroup id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The V3D hardware allows us to pack multiple workgroups together to avoid wasting execution lanes in shader cores. For example, if we dispatch 16 workgroups with a local size of 1 element, we can pack all 16 workgroups in a single 16-wide dispatch where each lane executes a different workgroup, instead of 16 1-wide dispatches. When we do this, we don't have a uniform workgroup id any more. Reviewed-by: Jason Ekstrand Reviewed-by: Alejandro PiƱeiro Part-of: --- src/compiler/nir/nir.h | 1 + src/compiler/nir/nir_divergence_analysis.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 967c57773cd..d154d41fbaa 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -3126,6 +3126,7 @@ typedef enum { nir_divergence_single_patch_per_tes_subgroup = (1 << 2), nir_divergence_view_index_uniform = (1 << 3), nir_divergence_single_frag_shading_rate_per_subgroup = (1 << 4), + nir_divergence_multiple_workgroup_per_compute_subgroup = (1 << 5), } nir_divergence_options; typedef struct nir_shader_compiler_options { diff --git a/src/compiler/nir/nir_divergence_analysis.c b/src/compiler/nir/nir_divergence_analysis.c index e377a2c3697..12a261276a5 100644 --- a/src/compiler/nir/nir_divergence_analysis.c +++ b/src/compiler/nir/nir_divergence_analysis.c @@ -101,7 +101,6 @@ visit_intrinsic(nir_shader *shader, nir_intrinsic_instr *instr) case nir_intrinsic_vote_ieq: case nir_intrinsic_load_push_constant: case nir_intrinsic_load_work_dim: - case nir_intrinsic_load_work_group_id: case nir_intrinsic_load_num_work_groups: case nir_intrinsic_load_local_group_size: case nir_intrinsic_load_subgroup_id: @@ -233,6 +232,11 @@ visit_intrinsic(nir_shader *shader, nir_intrinsic_instr *instr) assert(stage == MESA_SHADER_TESS_CTRL); break; + case nir_intrinsic_load_work_group_id: + assert(stage == MESA_SHADER_COMPUTE); + is_divergent |= (options & nir_divergence_multiple_workgroup_per_compute_subgroup); + break; + /* Clustered reductions are uniform if cluster_size == subgroup_size or * the source is uniform and the operation is invariant. * Inclusive scans are uniform if