From 58074143f540925da92f85a5fb314929648f6dca Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Mon, 13 Jan 2020 10:35:40 +0100 Subject: [PATCH] compiler/nir: make lowering global-id to local-id optional For D3D12, we don't want to lower this, as there's a dedicated global-id system-value that might be faster to use, depending on the hardware. Reviewed-by: Karol Herbst Reviewed-by: Jason Ekstrand Part-of: --- src/compiler/nir/nir.h | 3 +++ src/compiler/nir/nir_lower_system_values.c | 16 ++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 25176a95e57..bb43ab18a9d 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -3124,6 +3124,9 @@ typedef struct nir_shader_compiler_options { bool lower_cs_local_index_from_id; bool lower_cs_local_id_from_index; + /* Prevents lowering global_invocation_id to be in terms of work_group_id */ + bool has_cs_global_id; + bool lower_device_index_to_zero; /* Set if nir_lower_wpos_ytransform() should also invert gl_PointCoord. */ diff --git a/src/compiler/nir/nir_lower_system_values.c b/src/compiler/nir/nir_lower_system_values.c index 92723a5bffb..bc6a3931767 100644 --- a/src/compiler/nir/nir_lower_system_values.c +++ b/src/compiler/nir/nir_lower_system_values.c @@ -188,13 +188,17 @@ lower_system_value_instr(nir_builder *b, nir_instr *instr, void *_state) } case nir_intrinsic_load_global_invocation_id: { - nir_ssa_def *group_size = nir_load_local_group_size(b); - nir_ssa_def *group_id = nir_load_work_group_id(b, bit_size); - nir_ssa_def *local_id = nir_load_local_invocation_id(b); + if (!b->shader->options->has_cs_global_id) { + nir_ssa_def *group_size = nir_load_local_group_size(b); + nir_ssa_def *group_id = nir_load_work_group_id(b, bit_size); + nir_ssa_def *local_id = nir_load_local_invocation_id(b); - return nir_iadd(b, nir_imul(b, group_id, - nir_u2u(b, group_size, bit_size)), - nir_u2u(b, local_id, bit_size)); + return nir_iadd(b, nir_imul(b, group_id, + nir_u2u(b, group_size, bit_size)), + nir_u2u(b, local_id, bit_size)); + } else { + return NULL; + } } case nir_intrinsic_load_global_invocation_index: { -- 2.30.2