From 35b162eb2c0b8d8b3d41e276e9193bd9b0edd464 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 1 Oct 2020 11:05:11 +1000 Subject: [PATCH] gallivm/nir: make sure to mask global reads. Make the driver only read values for the active lanes, otherwise it can cause unwanted oob accesses that aren't the apps fault. Reviewed-by: Roland Scheidegger Part-of: --- src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c index 652b160..2f27c9a 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c @@ -782,10 +782,15 @@ static void emit_load_global(struct lp_build_nir_context *bld_base, for (unsigned c = 0; c < nc; c++) { LLVMValueRef result = lp_build_alloca(gallivm, res_bld->vec_type, ""); - + LLVMValueRef exec_mask = mask_vec(bld_base); struct lp_build_loop_state loop_state; lp_build_loop_begin(&loop_state, gallivm, lp_build_const_int32(gallivm, 0)); + struct lp_build_if_state ifthen; + LLVMValueRef cond = LLVMBuildICmp(gallivm->builder, LLVMIntNE, exec_mask, uint_bld->zero, ""); + cond = LLVMBuildExtractElement(gallivm->builder, cond, loop_state.counter, ""); + lp_build_if(&ifthen, gallivm, cond); + LLVMValueRef addr_ptr = LLVMBuildExtractElement(gallivm->builder, addr, loop_state.counter, ""); addr_ptr = global_addr_to_ptr(gallivm, addr_ptr, bit_size); @@ -796,6 +801,7 @@ static void emit_load_global(struct lp_build_nir_context *bld_base, temp_res = LLVMBuildLoad(builder, result, ""); temp_res = LLVMBuildInsertElement(builder, temp_res, value_ptr, loop_state.counter, ""); LLVMBuildStore(builder, temp_res, result); + lp_build_endif(&ifthen); lp_build_loop_end_cond(&loop_state, lp_build_const_int32(gallivm, uint_bld->type.length), NULL, LLVMIntUGE); outval[c] = LLVMBuildLoad(builder, result, ""); -- 2.7.4