gallivm: add sample id/pos intrinsic support

The sample position is looked up in an incoming array using the
sample id.

(These are mostly for ARB_sample_shading support)

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4122>
This commit is contained in:
Dave Airlie 2020-03-19 14:04:47 +10:00 committed by Marge Bot
parent 455c8e3584
commit d89499063b
3 changed files with 15 additions and 0 deletions

View File

@ -1340,6 +1340,8 @@ static void visit_intrinsic(struct lp_build_nir_context *bld_base,
case nir_intrinsic_load_tess_level_outer:
case nir_intrinsic_load_tess_level_inner:
case nir_intrinsic_load_patch_vertices_in:
case nir_intrinsic_load_sample_id:
case nir_intrinsic_load_sample_pos:
bld_base->sysval_intrin(bld_base, instr, result);
break;
case nir_intrinsic_load_helper_invocation:

View File

@ -1375,6 +1375,17 @@ static void emit_sysval_intrin(struct lp_build_nir_context *bld_base,
case nir_intrinsic_load_patch_vertices_in:
result[0] = bld->system_values.vertices_in;
break;
case nir_intrinsic_load_sample_id:
result[0] = lp_build_broadcast_scalar(&bld_base->uint_bld, bld->system_values.sample_id);
break;
case nir_intrinsic_load_sample_pos:
for (unsigned i = 0; i < 2; i++) {
LLVMValueRef idx = LLVMBuildMul(gallivm->builder, bld->system_values.sample_id, lp_build_const_int32(gallivm, 2), "");
idx = LLVMBuildAdd(gallivm->builder, idx, lp_build_const_int32(gallivm, i), "");
LLVMValueRef val = LLVMBuildGEP(gallivm->builder, bld->system_values.sample_pos, &idx, 1, "");
result[i] = lp_build_broadcast_scalar(&bld_base->base, LLVMBuildLoad(gallivm->builder, val, ""));
}
break;
}
}

View File

@ -183,6 +183,8 @@ struct lp_bld_tgsi_system_values {
LLVMValueRef tess_outer;
LLVMValueRef tess_inner;
LLVMValueRef vertices_in;
LLVMValueRef sample_id;
LLVMValueRef sample_pos;
};