From e51bf4914c4412644b4049385286596abead22d8 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Fri, 3 Jan 2020 12:21:02 +0100 Subject: [PATCH] zink: implement load_vertex_id Not 100% sure if this matches the semantics, but it seems to pass the tests, so it seems like an improvement. Reviewed-by: Alyssa Rosenzweig --- .../drivers/zink/nir_to_spirv/nir_to_spirv.c | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c index 3ccf90d83ca..b9fb5380b17 100644 --- a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c +++ b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c @@ -56,7 +56,7 @@ struct ntv_context { bool block_started; SpvId loop_break, loop_cont; - SpvId front_face_var; + SpvId front_face_var, vertex_id_var; }; static SpvId @@ -1280,6 +1280,22 @@ emit_load_front_face(struct ntv_context *ctx, nir_intrinsic_instr *intr) store_dest_uint(ctx, &intr->dest, result); } +static void +emit_load_vertex_id(struct ntv_context *ctx, nir_intrinsic_instr *intr) +{ + SpvId var_type = spirv_builder_type_uint(&ctx->builder, 32); + if (!ctx->vertex_id_var) + ctx->vertex_id_var = create_builtin_var(ctx, var_type, + SpvStorageClassInput, + "gl_VertexID", + SpvBuiltInVertexIndex); + + SpvId result = spirv_builder_emit_load(&ctx->builder, var_type, + ctx->vertex_id_var); + assert(1 == nir_dest_num_components(intr->dest)); + store_dest_uint(ctx, &intr->dest, result); +} + static void emit_intrinsic(struct ntv_context *ctx, nir_intrinsic_instr *intr) { @@ -1304,6 +1320,10 @@ emit_intrinsic(struct ntv_context *ctx, nir_intrinsic_instr *intr) emit_load_front_face(ctx, intr); break; + case nir_intrinsic_load_vertex_id: + emit_load_vertex_id(ctx, intr); + break; + default: fprintf(stderr, "emit_intrinsic: not implemented (%s)\n", nir_intrinsic_infos[intr->intrinsic].name); -- 2.30.2