From 2a9e98130b0354f391ef9e530eacafadb52b0633 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 18 Dec 2020 16:43:56 +1000 Subject: [PATCH] gallivm: fix non-32bit ubo loads 8/16-bit storage requires ubo loads for the smaller types, fix the ubo loading and bounds checking. Acked-by: Adam Jackson Reviewed-by: Roland Scheidegger Part-of: --- src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c index 1160722..4a33bec 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c @@ -974,15 +974,14 @@ static void emit_load_ubo(struct lp_build_nir_context *bld_base, struct gallivm_state *gallivm = bld_base->base.gallivm; LLVMBuilderRef builder = gallivm->builder; struct lp_build_context *uint_bld = &bld_base->uint_bld; - struct lp_build_context *bld_broad = bit_size == 64 ? &bld_base->dbl_bld : &bld_base->base; + struct lp_build_context *bld_broad = get_int_bld(bld_base, true, bit_size); LLVMValueRef consts_ptr = lp_build_array_get(gallivm, bld->consts_ptr, index); unsigned size_shift = bit_size_to_shift_size(bit_size); if (size_shift) offset = lp_build_shr(uint_bld, offset, lp_build_const_int_vec(gallivm, uint_bld->type, size_shift)); - if (bit_size == 64) { - LLVMTypeRef dptr_type = LLVMPointerType(bld_base->dbl_bld.elem_type, 0); - consts_ptr = LLVMBuildBitCast(builder, consts_ptr, dptr_type, ""); - } + + LLVMTypeRef ptr_type = LLVMPointerType(bld_broad->elem_type, 0); + consts_ptr = LLVMBuildBitCast(builder, consts_ptr, ptr_type, ""); if (offset_is_uniform) { offset = LLVMBuildExtractElement(builder, offset, lp_build_const_int32(gallivm, 0), ""); @@ -998,6 +997,13 @@ static void emit_load_ubo(struct lp_build_nir_context *bld_base, LLVMValueRef num_consts = lp_build_array_get(gallivm, bld->const_sizes_ptr, index); num_consts = lp_build_broadcast_scalar(uint_bld, num_consts); + if (bit_size == 64) + num_consts = lp_build_shr_imm(uint_bld, num_consts, 1); + else if (bit_size == 16) + num_consts = lp_build_shl_imm(uint_bld, num_consts, 1); + else if (bit_size == 8) + num_consts = lp_build_shl_imm(uint_bld, num_consts, 2); + for (unsigned c = 0; c < nc; c++) { LLVMValueRef this_offset = lp_build_add(uint_bld, offset, lp_build_const_int_vec(gallivm, uint_bld->type, c)); overflow_mask = lp_build_compare(gallivm, uint_bld->type, PIPE_FUNC_GEQUAL, -- 2.7.4