From 43c5a7a6b4f5f771fcb6c07bf17dc5551ff727b5 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Fri, 28 Oct 2022 01:45:46 +0200 Subject: [PATCH] rusticl/kernel: add work_dim lowering No driver implements this in hardware, so let's implement it once in the frontend. Signed-off-by: Karol Herbst Part-of: --- src/gallium/frontends/rusticl/core/kernel.rs | 20 ++++++++++++++++++++ src/gallium/frontends/rusticl/rusticl_nir.c | 3 +++ src/gallium/frontends/rusticl/rusticl_nir.h | 1 + 3 files changed, 24 insertions(+) diff --git a/src/gallium/frontends/rusticl/core/kernel.rs b/src/gallium/frontends/rusticl/core/kernel.rs index 4d055dc1c50..5da5ac697b8 100644 --- a/src/gallium/frontends/rusticl/core/kernel.rs +++ b/src/gallium/frontends/rusticl/core/kernel.rs @@ -59,6 +59,7 @@ pub enum InternalKernelArgType { InlineSampler((cl_addressing_mode, cl_filter_mode, bool)), FormatArray, OrderArray, + WorkDim, } #[derive(Hash, PartialEq, Eq, Clone)] @@ -210,6 +211,7 @@ impl InternalKernelArg { } InternalKernelArgType::FormatArray => bin.push(4), InternalKernelArgType::OrderArray => bin.push(5), + InternalKernelArgType::WorkDim => bin.push(6), } bin @@ -231,6 +233,7 @@ impl InternalKernelArg { } 4 => InternalKernelArgType::FormatArray, 5 => InternalKernelArgType::OrderArray, + 6 => InternalKernelArgType::WorkDim, _ => return None, }; @@ -521,6 +524,20 @@ fn lower_and_optimize_nir_late( ); } + if nir.reads_sysval(gl_system_value::SYSTEM_VALUE_WORK_DIM) { + res.push(InternalKernelArg { + kind: InternalKernelArgType::WorkDim, + size: 1, + offset: 0, + }); + lower_state.work_dim = nir.add_var( + nir_variable_mode::nir_var_uniform, + unsafe { glsl_uint8_t_type() }, + args.len() + res.len() - 1, + "work_dim", + ); + } + nir.pass2( nir_lower_vars_to_explicit_types, nir_variable_mode::nir_var_mem_shared @@ -901,6 +918,9 @@ impl Kernel { input.extend_from_slice(&cl_prop::<&Vec>(&tex_orders)); input.extend_from_slice(&cl_prop::<&Vec>(&img_orders)); } + InternalKernelArgType::WorkDim => { + input.extend_from_slice(&[work_dim as u8; 1]); + } } } diff --git a/src/gallium/frontends/rusticl/rusticl_nir.c b/src/gallium/frontends/rusticl/rusticl_nir.c index 542f735612c..82543a14456 100644 --- a/src/gallium/frontends/rusticl/rusticl_nir.c +++ b/src/gallium/frontends/rusticl/rusticl_nir.c @@ -59,6 +59,9 @@ rusticl_lower_intrinsics_instr( return nir_load_var(b, state->const_buf); case nir_intrinsic_load_printf_buffer_address: return nir_load_var(b, state->printf_buf); + case nir_intrinsic_load_work_dim: + assert(state->work_dim); + return nir_u2u(b, nir_load_var(b, state->work_dim), nir_dest_bit_size(intrins->dest)); default: return NULL; } diff --git a/src/gallium/frontends/rusticl/rusticl_nir.h b/src/gallium/frontends/rusticl/rusticl_nir.h index fefd0b3bcf7..8237b804118 100644 --- a/src/gallium/frontends/rusticl/rusticl_nir.h +++ b/src/gallium/frontends/rusticl/rusticl_nir.h @@ -4,6 +4,7 @@ struct rusticl_lower_state { nir_variable *printf_buf; nir_variable *format_arr; nir_variable *order_arr; + nir_variable *work_dim; }; bool rusticl_lower_intrinsics(nir_shader *nir, struct rusticl_lower_state *state);