From e7ca9d70f5fc6e4bce0f699a016e7fce4e87ec45 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marcin=20=C5=9Alusarz?= Date: Thu, 6 Apr 2023 15:09:12 +0200 Subject: [PATCH] nir: lower num_workgroups to constants MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reviewed-by: Timur Kristóf Part-of: --- src/compiler/nir/nir_lower_system_values.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/compiler/nir/nir_lower_system_values.c b/src/compiler/nir/nir_lower_system_values.c index ab9b51e..afd1e3a 100644 --- a/src/compiler/nir/nir_lower_system_values.c +++ b/src/compiler/nir/nir_lower_system_values.c @@ -701,6 +701,29 @@ lower_compute_system_value_instr(nir_builder *b, } + case nir_intrinsic_load_num_workgroups: { + if (!options) + return NULL; + + const uint16_t *num_wgs_imm = options->num_workgroups; + + /* Exit early when none of the num workgroups components are known at + * compile time. + */ + if (num_wgs_imm[0] == 0 && num_wgs_imm[1] == 0 && num_wgs_imm[2] == 0) + return NULL; + + b->cursor = nir_after_instr(instr); + + nir_ssa_def *num_wgs = &intrin->dest.ssa; + for (unsigned i = 0; i < 3; ++i) { + if (num_wgs_imm[i]) + num_wgs = nir_vector_insert_imm(b, num_wgs, nir_imm_int(b, num_wgs_imm[i]), i); + } + + return num_wgs; + } + default: return NULL; } -- 2.7.4