diff options
author | Erik Faye-Lund <[email protected]> | 2020-01-03 12:20:02 +0100 |
---|---|---|
committer | Erik Faye-Lund <[email protected]> | 2020-01-03 22:20:12 +0000 |
commit | 1b2731f26860954a593ba0170413ed3a87713ae9 (patch) | |
tree | 71c630f87f7754b9362f1cdba9ee8ef2270f54a9 /src | |
parent | ce1ea6e9c23ee5a9640a95457ef8cb0283586d4c (diff) |
zink: factor out builtin-var creation
This is useful so we can reuse it for the next patch
Reviewed-by: Alyssa Rosenzweig <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c | 38 |
1 files changed, 23 insertions, 15 deletions
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 d7cfac147ff..3ccf90d83ca 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 @@ -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); |