gallivm: add subgroup ballot support

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9645>
This commit is contained in:
Dave Airlie 2021-03-19 12:03:38 +10:00 committed by Marge Bot
parent 7b3073ad44
commit 2d6a0a8620
3 changed files with 29 additions and 1 deletions

View file

@ -1794,6 +1794,9 @@ static void visit_intrinsic(struct lp_build_nir_context *bld_base,
case nir_intrinsic_exclusive_scan:
bld_base->reduce(bld_base, cast_type(bld_base, get_src(bld_base, instr->src[0]), nir_type_int, nir_src_bit_size(instr->src[0])), instr, result);
break;
case nir_intrinsic_ballot:
bld_base->ballot(bld_base, cast_type(bld_base, get_src(bld_base, instr->src[0]), nir_type_int, 32), instr, result);
break;
case nir_intrinsic_interp_deref_at_offset:
case nir_intrinsic_interp_deref_at_centroid:
case nir_intrinsic_interp_deref_at_sample:

View file

@ -187,6 +187,7 @@ struct lp_build_nir_context
void (*vote)(struct lp_build_nir_context *bld_base, LLVMValueRef src, nir_intrinsic_instr *instr, LLVMValueRef dst[4]);
void (*elect)(struct lp_build_nir_context *bld_base, LLVMValueRef dst[4]);
void (*reduce)(struct lp_build_nir_context *bld_base, LLVMValueRef src, nir_intrinsic_instr *instr, LLVMValueRef dst[4]);
void (*ballot)(struct lp_build_nir_context *bld_base, LLVMValueRef src, nir_intrinsic_instr *instr, LLVMValueRef dst[4]);
void (*helper_invocation)(struct lp_build_nir_context *bld_base, LLVMValueRef *dst);
void (*interp_at)(struct lp_build_nir_context *bld_base,

View file

@ -1880,7 +1880,30 @@ static void emit_vote(struct lp_build_nir_context *bld_base, LLVMValueRef src,
LLVMBuildStore(builder, res, res_store);
lp_build_endif(&ifthen);
lp_build_loop_end_cond(&loop_state, lp_build_const_int32(gallivm, bld_base->uint_bld.type.length),
NULL, LLVMIntUGE);
NULL, LLVMIntUGE);
result[0] = lp_build_broadcast_scalar(&bld_base->uint_bld, LLVMBuildLoad(builder, res_store, ""));
}
static void emit_ballot(struct lp_build_nir_context *bld_base, LLVMValueRef src, nir_intrinsic_instr *instr, LLVMValueRef result[4])
{
struct gallivm_state * gallivm = bld_base->base.gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef exec_mask = mask_vec(bld_base);
struct lp_build_loop_state loop_state;
src = LLVMBuildAnd(builder, src, exec_mask, "");
LLVMValueRef res_store = lp_build_alloca(gallivm, bld_base->int_bld.elem_type, "");
LLVMValueRef res;
lp_build_loop_begin(&loop_state, gallivm, lp_build_const_int32(gallivm, 0));
LLVMValueRef value_ptr = LLVMBuildExtractElement(gallivm->builder, src,
loop_state.counter, "");
res = LLVMBuildLoad(builder, res_store, "");
res = LLVMBuildOr(builder,
res,
LLVMBuildAnd(builder, value_ptr, LLVMBuildShl(builder, lp_build_const_int32(gallivm, 1), loop_state.counter, ""), ""), "");
LLVMBuildStore(builder, res, res_store);
lp_build_loop_end_cond(&loop_state, lp_build_const_int32(gallivm, bld_base->uint_bld.type.length),
NULL, LLVMIntUGE);
result[0] = lp_build_broadcast_scalar(&bld_base->uint_bld, LLVMBuildLoad(builder, res_store, ""));
}
@ -2317,6 +2340,7 @@ void lp_build_nir_soa(struct gallivm_state *gallivm,
bld.bld_base.vote = emit_vote;
bld.bld_base.elect = emit_elect;
bld.bld_base.reduce = emit_reduce;
bld.bld_base.ballot = emit_ballot;
bld.bld_base.helper_invocation = emit_helper_invocation;
bld.bld_base.interp_at = emit_interp_at;
bld.bld_base.load_scratch = emit_load_scratch;