From a29ed5ba5dda7a783a27dff200928a696860a963 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 17 May 2023 11:42:19 +1000 Subject: [PATCH] gallivm/nir: add a mesh interface and vert/prim count setting. This adds a callback to the driver for a mesh interface to implement the set_vertex_and_primitive_count intrinsic Reviewed-by: Roland Scheidegger Part-of: --- src/gallium/auxiliary/gallivm/lp_bld_nir.c | 5 +++++ src/gallium/auxiliary/gallivm/lp_bld_nir.h | 5 +++++ .../auxiliary/gallivm/lp_bld_nir_soa.c | 20 +++++++++++++++++++ src/gallium/auxiliary/gallivm/lp_bld_tgsi.h | 9 +++++++++ 4 files changed, 39 insertions(+) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir.c b/src/gallium/auxiliary/gallivm/lp_bld_nir.c index 6466e6610ce..2f4ab4cf9e8 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir.c @@ -2218,6 +2218,11 @@ visit_intrinsic(struct lp_build_nir_context *bld_base, case nir_intrinsic_task_payload_atomic_swap: visit_payload_atomic(bld_base, instr, result); break; + case nir_intrinsic_set_vertex_and_primitive_count: + bld_base->set_vertex_and_primitive_count(bld_base, + get_src(bld_base, instr->src[0]), + get_src(bld_base, instr->src[1])); + break; default: fprintf(stderr, "Unsupported intrinsic: "); nir_print_instr(&instr->instr, stderr); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir.h b/src/gallium/auxiliary/gallivm/lp_bld_nir.h index d268c4f8733..e51db20d7a5 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir.h @@ -231,6 +231,9 @@ struct lp_build_nir_context unsigned const_index, LLVMValueRef indir_index, LLVMValueRef offsets[2], LLVMValueRef dst[4]); + void (*set_vertex_and_primitive_count)(struct lp_build_nir_context *bld_base, + LLVMValueRef vert_count, + LLVMValueRef prim_count); void (*launch_mesh_workgroups)(struct lp_build_nir_context *bld_base, LLVMValueRef launch_grid); // LLVMValueRef main_function @@ -270,6 +273,8 @@ struct lp_build_nir_soa_context const struct lp_build_tcs_iface *tcs_iface; const struct lp_build_tes_iface *tes_iface; const struct lp_build_fs_iface *fs_iface; + const struct lp_build_mesh_iface *mesh_iface; + LLVMValueRef emitted_prims_vec_ptr[PIPE_MAX_VERTEX_STREAMS]; LLVMValueRef total_emitted_vertices_vec_ptr[PIPE_MAX_VERTEX_STREAMS]; LLVMValueRef emitted_vertices_vec_ptr[PIPE_MAX_VERTEX_STREAMS]; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c index 84c215d9619..4f2b5f3461d 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c @@ -2517,6 +2517,24 @@ emit_interp_at(struct lp_build_nir_context *bld_base, } } +static void +emit_set_vertex_and_primitive_count(struct lp_build_nir_context *bld_base, + LLVMValueRef vert_count, + LLVMValueRef prim_count) +{ + struct lp_build_nir_soa_context *bld = (struct lp_build_nir_soa_context *)bld_base; + struct gallivm_state *gallivm = bld_base->base.gallivm; + assert(bld->mesh_iface); + LLVMValueRef idx = first_active_invocation(bld_base); + + LLVMValueRef vcount = LLVMBuildExtractElement(gallivm->builder, + vert_count, idx, ""); + LLVMValueRef pcount = LLVMBuildExtractElement(gallivm->builder, + prim_count, idx, ""); + + bld->mesh_iface->emit_vertex_and_primitive_count(bld->mesh_iface, &bld_base->base, vcount, pcount); +} + static void emit_launch_mesh_workgroups(struct lp_build_nir_context *bld_base, LLVMValueRef launch_grid) @@ -2765,6 +2783,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.set_vertex_and_primitive_count = emit_set_vertex_and_primitive_count; bld.bld_base.launch_mesh_workgroups = emit_launch_mesh_workgroups; bld.mask = params->mask; @@ -2793,6 +2812,7 @@ void lp_build_nir_soa(struct gallivm_state *gallivm, bld.tcs_iface = params->tcs_iface; bld.tes_iface = params->tes_iface; bld.fs_iface = params->fs_iface; + bld.mesh_iface = params->mesh_iface; if (bld.gs_iface) { struct lp_build_context *uint_bld = &bld.bld_base.uint_bld; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h index 3b4e8347800..21dbc4e3074 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h @@ -278,6 +278,7 @@ struct lp_build_tgsi_params { const struct lp_build_gs_iface *gs_iface; const struct lp_build_tcs_iface *tcs_iface; const struct lp_build_tes_iface *tes_iface; + const struct lp_build_mesh_iface *mesh_iface; LLVMValueRef ssbo_ptr; LLVMValueRef ssbo_sizes_ptr; const struct lp_build_image_soa *image; @@ -505,6 +506,14 @@ struct lp_build_tes_iface LLVMValueRef swizzle_index); }; +struct lp_build_mesh_iface +{ + void (*emit_vertex_and_primitive_count)(const struct lp_build_mesh_iface *mesh_iface, + struct lp_build_context *bld, + LLVMValueRef vertices_count, + LLVMValueRef primitives_count); +}; + struct lp_build_tgsi_soa_context { struct lp_build_tgsi_context bld_base;