zink: factor out builtin-var creation
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Fri, 3 Jan 2020 11:20:02 +0000 (12:20 +0100)
committerErik Faye-Lund <erik.faye-lund@collabora.com>
Fri, 3 Jan 2020 22:20:12 +0000 (22:20 +0000)
This is useful so we can reuse it for the next patch

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c

index d7cfac147fff481bd83fde68f603becaacdf3959..3ccf90d83ca067618c6a9b8fee21af3320a0d8ef 100644 (file)
@@ -1245,25 +1245,33 @@ emit_store_deref(struct ntv_context *ctx, nir_intrinsic_instr *intr)
    spirv_builder_emit_store(&ctx->builder, ptr, result);
 }
 
+static SpvId
+create_builtin_var(struct ntv_context *ctx, SpvId var_type,
+                   SpvStorageClass storage_class,
+                   const char *name, SpvBuiltIn builtin)
+{
+   SpvId pointer_type = spirv_builder_type_pointer(&ctx->builder,
+                                                   storage_class,
+                                                   var_type);
+   SpvId var = spirv_builder_emit_var(&ctx->builder, pointer_type,
+                                      storage_class);
+   spirv_builder_emit_name(&ctx->builder, var, name);
+   spirv_builder_emit_builtin(&ctx->builder, var, builtin);
+
+   assert(ctx->num_entry_ifaces < ARRAY_SIZE(ctx->entry_ifaces));
+   ctx->entry_ifaces[ctx->num_entry_ifaces++] = var;
+   return var;
+}
+
 static void
 emit_load_front_face(struct ntv_context *ctx, nir_intrinsic_instr *intr)
 {
    SpvId var_type = spirv_builder_type_bool(&ctx->builder);
-   if (!ctx->front_face_var) {
-      SpvId pointer_type = spirv_builder_type_pointer(&ctx->builder,
-                                                      SpvStorageClassInput,
-                                                      var_type);
-      ctx->front_face_var = spirv_builder_emit_var(&ctx->builder,
-                                                   pointer_type,
-                                                   SpvStorageClassInput);
-      spirv_builder_emit_name(&ctx->builder, ctx->front_face_var,
-                              "gl_FrontFacing");
-      spirv_builder_emit_builtin(&ctx->builder, ctx->front_face_var,
-                                 SpvBuiltInFrontFacing);
-
-      assert(ctx->num_entry_ifaces < ARRAY_SIZE(ctx->entry_ifaces));
-      ctx->entry_ifaces[ctx->num_entry_ifaces++] = ctx->front_face_var;
-   }
+   if (!ctx->front_face_var)
+      ctx->front_face_var = create_builtin_var(ctx, var_type,
+                                               SpvStorageClassInput,
+                                               "gl_FrontFacing",
+                                               SpvBuiltInFrontFacing);
 
    SpvId result = spirv_builder_emit_load(&ctx->builder, var_type,
                                           ctx->front_face_var);