From 94c8a0e82081346bd7653c8047e0f0b905356570 Mon Sep 17 00:00:00 2001 From: Konstantin Seurer Date: Thu, 30 Jan 2025 21:37:15 +0100 Subject: [PATCH] lavapipe: Implement KHR_shader_quad_control Reviewed-by: Mike Blumenkrantz Part-of: --- src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c | 17 +++++++++++++---- src/gallium/frontends/lavapipe/lvp_device.c | 4 ++++ src/gallium/frontends/lavapipe/lvp_pipeline.c | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c index 4d821431be9..31ef9a25a50 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c @@ -352,6 +352,15 @@ mask_vec_with_helpers(struct lp_build_nir_soa_context *bld) bld->uint_bld.type, -1); } +static LLVMValueRef +group_op_mask_vec(struct lp_build_nir_soa_context *bld) +{ + if (bld->shader->info.fs.require_full_quads) + return mask_vec_with_helpers(bld); + + return mask_vec(bld); +} + static bool lp_exec_mask_is_nz(struct lp_build_nir_soa_context *bld) { @@ -2154,7 +2163,7 @@ static void emit_vote(struct lp_build_nir_soa_context *bld, LLVMValueRef src, struct gallivm_state * gallivm = bld->base.gallivm; LLVMBuilderRef builder = gallivm->builder; uint32_t bit_size = nir_src_bit_size(instr->src[0]); - LLVMValueRef exec_mask = mask_vec(bld); + LLVMValueRef exec_mask = group_op_mask_vec(bld); struct lp_build_loop_state loop_state; LLVMValueRef outer_cond = LLVMBuildICmp(builder, LLVMIntNE, exec_mask, bld->uint_bld.zero, ""); @@ -2225,7 +2234,7 @@ static void emit_ballot(struct lp_build_nir_soa_context *bld, LLVMValueRef src, { struct gallivm_state * gallivm = bld->base.gallivm; LLVMBuilderRef builder = gallivm->builder; - LLVMValueRef exec_mask = mask_vec(bld); + LLVMValueRef exec_mask = group_op_mask_vec(bld); struct lp_build_loop_state loop_state; src = LLVMBuildSExt(builder, src, bld->int_bld.vec_type, ""); src = LLVMBuildAnd(builder, src, exec_mask, ""); @@ -2249,7 +2258,7 @@ static void emit_elect(struct lp_build_nir_soa_context *bld, LLVMValueRef result { struct gallivm_state *gallivm = bld->base.gallivm; LLVMBuilderRef builder = gallivm->builder; - LLVMValueRef exec_mask = mask_vec(bld); + LLVMValueRef exec_mask = group_op_mask_vec(bld); struct lp_build_loop_state loop_state; LLVMValueRef idx_store = lp_build_alloca(gallivm, bld->int_bld.elem_type, ""); @@ -2289,7 +2298,7 @@ static void emit_reduce(struct lp_build_nir_soa_context *bld, LLVMValueRef src, LLVMBuilderRef builder = gallivm->builder; uint32_t bit_size = nir_src_bit_size(instr->src[0]); /* can't use llvm reduction intrinsics because of exec_mask */ - LLVMValueRef exec_mask = mask_vec(bld); + LLVMValueRef exec_mask = group_op_mask_vec(bld); nir_op reduction_op = nir_intrinsic_reduction_op(instr); uint32_t cluster_size = 0; diff --git a/src/gallium/frontends/lavapipe/lvp_device.c b/src/gallium/frontends/lavapipe/lvp_device.c index 76d784d6721..f63d9b9b233 100644 --- a/src/gallium/frontends/lavapipe/lvp_device.c +++ b/src/gallium/frontends/lavapipe/lvp_device.c @@ -176,6 +176,7 @@ static const struct vk_device_extension_table lvp_device_extensions_supported = .KHR_shader_integer_dot_product = true, .KHR_shader_maximal_reconvergence = true, .KHR_shader_non_semantic_info = true, + .KHR_shader_quad_control = true, .KHR_shader_relaxed_extended_instruction = true, .KHR_shader_subgroup_extended_types = true, .KHR_shader_subgroup_rotate = true, @@ -759,6 +760,9 @@ lvp_get_features(const struct lvp_physical_device *pdevice, /* VK_KHR_compute_shader_derivatives */ .computeDerivativeGroupQuads = true, .computeDerivativeGroupLinear = true, + + /* VK_KHR_shader_quad_control */ + .shaderQuadControl = true, }; } diff --git a/src/gallium/frontends/lavapipe/lvp_pipeline.c b/src/gallium/frontends/lavapipe/lvp_pipeline.c index 8d3b7e3f326..b0cd5dd50c8 100644 --- a/src/gallium/frontends/lavapipe/lvp_pipeline.c +++ b/src/gallium/frontends/lavapipe/lvp_pipeline.c @@ -359,6 +359,7 @@ lvp_shader_lower(struct lvp_device *pdevice, nir_shader *nir, struct lvp_pipelin struct nir_lower_subgroups_options subgroup_opts = {0}; subgroup_opts.lower_quad = true; + subgroup_opts.lower_quad_vote = true; subgroup_opts.ballot_components = 1; subgroup_opts.ballot_bit_size = 32; subgroup_opts.lower_inverse_ballot = true;