From b9eeee8554cf1bd6c97e29e0ee1fc106a6b8b24d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20=C5=9Alusarz?= Date: Fri, 31 Mar 2023 11:56:11 +0200 Subject: [PATCH] nir: use constant components of num_workgroups in wg id to wg idx lowering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Timur Kristóf Part-of: --- src/compiler/nir/nir_lower_system_values.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/compiler/nir/nir_lower_system_values.c b/src/compiler/nir/nir_lower_system_values.c index 9904cc80543..ab9b51ebb9a 100644 --- a/src/compiler/nir/nir_lower_system_values.c +++ b/src/compiler/nir/nir_lower_system_values.c @@ -360,7 +360,8 @@ nir_lower_system_values(nir_shader *shader) static nir_ssa_def * lower_id_to_index_no_umod(nir_builder *b, nir_ssa_def *index, - nir_ssa_def *size, unsigned bit_size) + nir_ssa_def *size, unsigned bit_size, + const uint16_t *size_imm) { /* We lower ID to Index with the following formula: * @@ -373,8 +374,18 @@ lower_id_to_index_no_umod(nir_builder *b, nir_ssa_def *index, * not compile time known or not a power of two. */ - nir_ssa_def *size_x = nir_channel(b, size, 0); - nir_ssa_def *size_y = nir_channel(b, size, 1); + nir_ssa_def *size_x, *size_y; + + if (size_imm[0] > 0) + size_x = nir_imm_int(b, size_imm[0]); + else + size_x = nir_channel(b, size, 0); + + if (size_imm[1] > 0) + size_y = nir_imm_int(b, size_imm[1]); + else + size_y = nir_channel(b, size, 1); + nir_ssa_def *size_x_y = nir_imul(b, size_x, size_y); nir_ssa_def *id_z = nir_udiv(b, index, size_x_y); @@ -682,7 +693,8 @@ lower_compute_system_value_instr(nir_builder *b, return lower_id_to_index_no_umod(b, wg_idx, nir_load_num_workgroups(b, bit_size), - bit_size); + bit_size, + options->num_workgroups); } return NULL;