From d89499063bd96bcc5d7d9239a1da43bf568c11fa Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 19 Mar 2020 14:04:47 +1000 Subject: [PATCH] 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 Part-of: --- src/gallium/auxiliary/gallivm/lp_bld_nir.c | 2 ++ src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c | 11 +++++++++++ src/gallium/auxiliary/gallivm/lp_bld_tgsi.h | 2 ++ 3 files changed, 15 insertions(+) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir.c b/src/gallium/auxiliary/gallivm/lp_bld_nir.c index 1b1d7002099..4944b0f944e 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir.c @@ -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: diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c index e5bc1c75f2c..3ae332369ac 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c @@ -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; } } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h index 6af8b0bea55..a543e2e69cc 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h @@ -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; }; -- 2.30.2