zink: implement load_vertex_id
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Fri, 3 Jan 2020 11:21:02 +0000 (12:21 +0100)
committerErik Faye-Lund <erik.faye-lund@collabora.com>
Fri, 3 Jan 2020 22:20:12 +0000 (22:20 +0000)
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 <alyssa.rosenzweig@collabora.com>
src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c

index 3ccf90d83ca067618c6a9b8fee21af3320a0d8ef..b9fb5380b17ea4f02b899822dda0ee4b6e73cc30 100644 (file)
@@ -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);