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 <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6954>
This commit is contained in:
Dave Airlie 2020-10-01 11:05:11 +10:00
parent 545d852a7a
commit 35b162eb2c

View file

@ -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, "");