From 70be21e7c600baa3dc190f9fa6a683719780adc0 Mon Sep 17 00:00:00 2001 From: Emma Anholt Date: Mon, 30 Jan 2023 15:33:44 -0800 Subject: [PATCH] gallivm: Use first active invocation in some image/ssbo accesses. These should be looking at that rather than blindly using invocation 0 (which may be junk when in control flow). Reviewed-by: Roland Scheidegger Part-of: --- src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c index df5581f776c..3a01549e2f3 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c @@ -1621,7 +1621,11 @@ static LLVMValueRef emit_get_ssbo_size(struct lp_build_nir_context *bld_base, struct lp_build_nir_soa_context *bld = (struct lp_build_nir_soa_context *)bld_base; LLVMBuilderRef builder = bld->bld_base.base.gallivm->builder; struct lp_build_context *bld_broad = &bld_base->uint_bld; - LLVMValueRef size_ptr = lp_llvm_buffer_num_elements(gallivm, bld->ssbo_ptr, LLVMBuildExtractElement(builder, index, lp_build_const_int32(gallivm, 0), ""), LP_MAX_TGSI_SHADER_BUFFERS); + LLVMValueRef ssbo_index = LLVMBuildExtractElement(builder, index, + first_active_invocation(bld_base), ""); + LLVMValueRef size_ptr = lp_llvm_buffer_num_elements(gallivm, bld->ssbo_ptr, + ssbo_index, + LP_MAX_TGSI_SHADER_BUFFERS); return lp_build_broadcast_scalar(bld_broad, size_ptr); } @@ -1641,7 +1645,7 @@ static void emit_image_op(struct lp_build_nir_context *bld_base, if (params->image_index_offset) params->image_index_offset = LLVMBuildExtractElement(gallivm->builder, params->image_index_offset, - lp_build_const_int32(gallivm, 0), ""); + first_active_invocation(bld_base), ""); bld->image->emit_op(bld->image, bld->bld_base.base.gallivm, @@ -1661,7 +1665,7 @@ static void emit_image_size(struct lp_build_nir_context *bld_base, if (params->texture_unit_offset) params->texture_unit_offset = LLVMBuildExtractElement(gallivm->builder, params->texture_unit_offset, - lp_build_const_int32(gallivm, 0), ""); + first_active_invocation(bld_base), ""); bld->image->emit_size_query(bld->image, bld->bld_base.base.gallivm, params);