nir: Add a nir_system_value_from_intrinsic() function.
authorKenneth Graunke <kenneth@whitecape.org>
Mon, 3 Aug 2015 23:02:16 +0000 (16:02 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Wed, 9 Sep 2015 01:02:08 +0000 (18:02 -0700)
This converts NIR intrinsics that load system values into Mesa's
SYSTEM_VALUE_* enumerations.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
src/glsl/nir/nir.c
src/glsl/nir/nir.h

index 3f4bec4625d40836f15de5ae53e5355d46b92669..ab06ea2bc19353234a1128ed24f5aad57f31c125 100644 (file)
@@ -1404,3 +1404,37 @@ nir_index_ssa_defs(nir_function_impl *impl)
    nir_foreach_block(impl, index_ssa_block, &index);
    impl->ssa_alloc = index;
 }
+
+gl_system_value
+nir_system_value_from_intrinsic(nir_intrinsic_op intrin)
+{
+   switch (intrin) {
+   case nir_intrinsic_load_vertex_id:
+      return SYSTEM_VALUE_VERTEX_ID;
+   case nir_intrinsic_load_instance_id:
+      return SYSTEM_VALUE_INSTANCE_ID;
+   case nir_intrinsic_load_vertex_id_zero_base:
+      return SYSTEM_VALUE_VERTEX_ID_ZERO_BASE;
+   case nir_intrinsic_load_base_vertex:
+      return SYSTEM_VALUE_BASE_VERTEX;
+   case nir_intrinsic_load_invocation_id:
+      return SYSTEM_VALUE_INVOCATION_ID;
+   case nir_intrinsic_load_front_face:
+      return SYSTEM_VALUE_FRONT_FACE;
+   case nir_intrinsic_load_sample_id:
+      return SYSTEM_VALUE_SAMPLE_ID;
+   case nir_intrinsic_load_sample_pos:
+      return SYSTEM_VALUE_SAMPLE_POS;
+   case nir_intrinsic_load_sample_mask_in:
+      return SYSTEM_VALUE_SAMPLE_MASK_IN;
+   /* FINISHME: Add tessellation intrinsics.
+      return SYSTEM_VALUE_TESS_COORD;
+      return SYSTEM_VALUE_VERTICES_IN;
+      return SYSTEM_VALUE_PRIMITIVE_ID;
+      return SYSTEM_VALUE_TESS_LEVEL_OUTER;
+      return SYSTEM_VALUE_TESS_LEVEL_INNER;
+    */
+   default:
+      unreachable("intrinsic doesn't produce a system value");
+   }
+}
index e73b7fbc4e1eca523b75abc9f37b43b172cccb4f..3c375f30c5321bf57a8afc263c3bd93c8cbc0ce9 100644 (file)
@@ -1842,6 +1842,8 @@ bool nir_opt_undef(nir_shader *shader);
 
 void nir_sweep(nir_shader *shader);
 
+gl_system_value nir_system_value_from_intrinsic(nir_intrinsic_op intrin);
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif