From 24fe5abbaefaff6a524042c7eaed86e23ba8c597 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 17 May 2023 11:40:32 +1000 Subject: [PATCH] gallivm/nir: add launch mesh workgroups add support the launch mesh workgroups intrinsic for task shaders. This writes the values out to the start of the payload. Reviewed-by: Roland Scheidegger Part-of: --- src/gallium/auxiliary/gallivm/lp_bld_nir.c | 4 ++++ src/gallium/auxiliary/gallivm/lp_bld_nir.h | 2 ++ src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c | 29 ++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir.c b/src/gallium/auxiliary/gallivm/lp_bld_nir.c index f24761c..6466e66 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir.c @@ -2204,6 +2204,10 @@ visit_intrinsic(struct lp_build_nir_context *bld_base, case nir_intrinsic_shader_clock: bld_base->clock(bld_base, result); break; + case nir_intrinsic_launch_mesh_workgroups: + bld_base->launch_mesh_workgroups(bld_base, + get_src(bld_base, instr->src[0])); + break; case nir_intrinsic_load_task_payload: visit_payload_load(bld_base, instr, result); break; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir.h b/src/gallium/auxiliary/gallivm/lp_bld_nir.h index 59b096c..d268c4f 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir.h @@ -231,6 +231,8 @@ struct lp_build_nir_context unsigned const_index, LLVMValueRef indir_index, LLVMValueRef offsets[2], LLVMValueRef dst[4]); + void (*launch_mesh_workgroups)(struct lp_build_nir_context *bld_base, + LLVMValueRef launch_grid); // LLVMValueRef main_function }; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c index a138da6..84c215d 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c @@ -2517,6 +2517,34 @@ emit_interp_at(struct lp_build_nir_context *bld_base, } } +static void +emit_launch_mesh_workgroups(struct lp_build_nir_context *bld_base, + LLVMValueRef launch_grid) +{ + struct lp_build_nir_soa_context *bld = (struct lp_build_nir_soa_context *)bld_base; + struct gallivm_state *gallivm = bld_base->base.gallivm; + LLVMTypeRef vec_type = LLVMArrayType(LLVMInt32TypeInContext(gallivm->context), 3); + + LLVMValueRef local_invoc_idx = get_local_invocation_index(bld); + + vec_type = LLVMPointerType(vec_type, 0); + + local_invoc_idx = LLVMBuildExtractElement(gallivm->builder, local_invoc_idx, lp_build_const_int32(gallivm, 0), ""); + LLVMValueRef if_cond = LLVMBuildICmp(gallivm->builder, LLVMIntEQ, local_invoc_idx, lp_build_const_int32(gallivm, 0), ""); + struct lp_build_if_state ifthen; + lp_build_if(&ifthen, gallivm, if_cond); + LLVMValueRef ptr = bld->payload_ptr; + ptr = LLVMBuildPtrToInt(gallivm->builder, ptr, bld_base->int64_bld.elem_type, ""); + for (unsigned i = 0; i < 3; i++) { + LLVMValueRef lg = LLVMBuildExtractValue(gallivm->builder, launch_grid, i, ""); + lg = LLVMBuildExtractElement(gallivm->builder, lg, lp_build_const_int32(gallivm, 0), ""); + LLVMValueRef this_ptr = LLVMBuildIntToPtr(gallivm->builder, ptr, LLVMPointerType(LLVMInt32TypeInContext(gallivm->context), 0), ""); + LLVMBuildStore(gallivm->builder, lg, this_ptr); + ptr = LLVMBuildAdd(gallivm->builder, ptr, lp_build_const_int64(gallivm, 4), ""); + } + lp_build_endif(&ifthen); +} + static LLVMValueRef get_scratch_thread_offsets(struct gallivm_state *gallivm, struct lp_type type, unsigned scratch_size) @@ -2737,6 +2765,7 @@ void lp_build_nir_soa(struct gallivm_state *gallivm, bld.bld_base.store_scratch = emit_store_scratch; bld.bld_base.load_const = emit_load_const; bld.bld_base.clock = emit_clock; + bld.bld_base.launch_mesh_workgroups = emit_launch_mesh_workgroups; bld.mask = params->mask; bld.inputs = params->inputs; -- 2.7.4