gallivm: add sample id/pos intrinsic support
authorDave Airlie <airlied@redhat.com>
Thu, 19 Mar 2020 04:04:47 +0000 (14:04 +1000)
committerMarge Bot <eric+marge@anholt.net>
Wed, 6 May 2020 06:20:37 +0000 (06:20 +0000)
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>

src/gallium/auxiliary/gallivm/lp_bld_nir.c
src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c
src/gallium/auxiliary/gallivm/lp_bld_tgsi.h

index 1b1d7002099d34fe8782852f218526e2879dd563..4944b0f944ec6dea0a4a0c7c9868e09a2ca75e4f 100644 (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:
index e5bc1c75f2cdb7e7ddad1b22553e1e19181b521f..3ae332369ac98c604ae95aeaadadd6f096801ced 100644 (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;
    }
 }
 
index 6af8b0bea5510b17bd64808f63be699ea4955aab..a543e2e69ccec0c9f29ec4f1de9ce2a26e4c7277 100644 (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;
 };