From 306800d747bcf210baa84594cdbdca21e435ddd9 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 19 Dec 2019 13:31:21 -0500 Subject: [PATCH] pan/midgard: Lower gl_VertexID/gl_InstanceID to attributes We have special records for these, put in a fixed location by convention per the blob. Signed-off-by: Alyssa Rosenzweig --- src/panfrost/midgard/midgard_compile.c | 26 ++++++++++++++++++++++++++ src/panfrost/midgard/midgard_compile.h | 9 +++++++++ 2 files changed, 35 insertions(+) diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c index be1b41f0a8a..64c9b23cfb4 100644 --- a/src/panfrost/midgard/midgard_compile.c +++ b/src/panfrost/midgard/midgard_compile.c @@ -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); diff --git a/src/panfrost/midgard/midgard_compile.h b/src/panfrost/midgard/midgard_compile.h index 809331fc9d9..2442ddf69fb 100644 --- a/src/panfrost/midgard/midgard_compile.h +++ b/src/panfrost/midgard/midgard_compile.h @@ -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; -- 2.30.2