pan/midgard: Lower gl_VertexID/gl_InstanceID to attributes
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Thu, 19 Dec 2019 18:31:21 +0000 (13:31 -0500)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 25 Dec 2019 03:55:04 +0000 (22:55 -0500)
We have special records for these, put in a fixed location by convention
per the blob.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/panfrost/midgard/midgard_compile.c
src/panfrost/midgard/midgard_compile.h

index be1b41f0a8a666eb0dc019259ae512f1967727eb..64c9b23cfb48936200b15a78a5aa7cb8db6c3867 100644 (file)
@@ -1400,6 +1400,27 @@ emit_compute_builtin(compiler_context *ctx, nir_intrinsic_instr *instr)
         ins.load_store.arg_1 = compute_builtin_arg(instr->intrinsic);
         emit_mir_instruction(ctx, ins);
 }
+
+static unsigned
+vertex_builtin_arg(nir_op op)
+{
+        switch (op) {
+        case nir_intrinsic_load_vertex_id:
+                return PAN_VERTEX_ID;
+        case nir_intrinsic_load_instance_id:
+                return PAN_INSTANCE_ID;
+        default:
+                unreachable("Invalid vertex builtin");
+        }
+}
+
+static void
+emit_vertex_builtin(compiler_context *ctx, nir_intrinsic_instr *instr)
+{
+        unsigned reg = nir_dest_index(ctx, &instr->dest);
+        emit_attr_read(ctx, reg, vertex_builtin_arg(instr->intrinsic), 1, nir_type_int);
+}
+
 static void
 emit_intrinsic(compiler_context *ctx, nir_intrinsic_instr *instr)
 {
@@ -1632,6 +1653,11 @@ emit_intrinsic(compiler_context *ctx, nir_intrinsic_instr *instr)
                 emit_compute_builtin(ctx, instr);
                 break;
 
+        case nir_intrinsic_load_vertex_id:
+        case nir_intrinsic_load_instance_id:
+                emit_vertex_builtin(ctx, instr);
+                break;
+
         default:
                 printf ("Unhandled intrinsic\n");
                 assert(0);
index 809331fc9d908d9d9728a414b75e08b40b8f850f..2442ddf69fbcd1e3a25e3877d11ed55dd2708f77 100644 (file)
@@ -57,6 +57,15 @@ enum {
 #define PAN_SYSVAL_ID_TO_TXS_DIM(id)            (((id) >> 7) & 0x3)
 #define PAN_SYSVAL_ID_TO_TXS_IS_ARRAY(id)       !!((id) & (1 << 9))
 
+/* Special attribute slots for vertex builtings. Sort of arbitrary but let's be
+ * consistent with the blob so we can compare traces easier. */
+
+enum {
+        PAN_VERTEX_ID   = 16,
+        PAN_INSTANCE_ID = 17,
+        PAN_MAX_ATTRIBUTE
+} pan_special_attributes;
+
 typedef struct {
         int work_register_count;
         int uniform_count;