From 02b249d5e753f3271877094c454b68d618870440 Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Mon, 24 Jun 2024 17:30:46 -0400 Subject: [PATCH] vkd3d-shader/hlsl: Introduce enum hlsl_compile_type. --- libs/vkd3d-shader/hlsl.c | 47 +++++++++++++++++++++++++--------------- libs/vkd3d-shader/hlsl.h | 16 +++++++++----- libs/vkd3d-shader/hlsl.y | 3 ++- 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 6f737be2..d86097a3 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1847,30 +1847,36 @@ struct hlsl_ir_node *hlsl_new_swizzle(struct hlsl_ctx *ctx, uint32_t s, unsigned return &swizzle->node; } -struct hlsl_ir_node *hlsl_new_compile(struct hlsl_ctx *ctx, const char *profile_name, - struct hlsl_ir_node **args, unsigned int args_count, struct hlsl_block *args_instrs, - const struct vkd3d_shader_location *loc) +struct hlsl_ir_node *hlsl_new_compile(struct hlsl_ctx *ctx, enum hlsl_compile_type compile_type, + const char *profile_name, struct hlsl_ir_node **args, unsigned int args_count, + struct hlsl_block *args_instrs, const struct vkd3d_shader_location *loc) { const struct hlsl_profile_info *profile_info = NULL; struct hlsl_ir_compile *compile; struct hlsl_type *type = NULL; unsigned int i; - if (!(profile_info = hlsl_get_target_info(profile_name))) + switch (compile_type) { - hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_PROFILE, "Unknown profile \"%s\".", profile_name); - return NULL; - } + case HLSL_COMPILE_TYPE_COMPILE: + if (!(profile_info = hlsl_get_target_info(profile_name))) + { + hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_PROFILE, "Unknown profile \"%s\".", profile_name); + return NULL; + } - if (profile_info->type == VKD3D_SHADER_TYPE_PIXEL) - type = hlsl_get_type(ctx->cur_scope, "PixelShader", true, true); - else if (profile_info->type == VKD3D_SHADER_TYPE_VERTEX) - type = hlsl_get_type(ctx->cur_scope, "VertexShader", true, true); + if (profile_info->type == VKD3D_SHADER_TYPE_PIXEL) + type = hlsl_get_type(ctx->cur_scope, "PixelShader", true, true); + else if (profile_info->type == VKD3D_SHADER_TYPE_VERTEX) + type = hlsl_get_type(ctx->cur_scope, "VertexShader", true, true); - if (!type) - { - hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_PROFILE, "Invalid profile \"%s\".", profile_name); - return NULL; + if (!type) + { + hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_PROFILE, "Invalid profile \"%s\".", profile_name); + return NULL; + } + + break; } if (!(compile = hlsl_alloc(ctx, sizeof(*compile)))) @@ -1878,6 +1884,7 @@ struct hlsl_ir_node *hlsl_new_compile(struct hlsl_ctx *ctx, const char *profile_ init_node(&compile->node, HLSL_IR_COMPILE, type, loc); + compile->compile_type = compile_type; compile->profile = profile_info; hlsl_block_init(&compile->instrs); @@ -2271,7 +2278,8 @@ static struct hlsl_ir_node *clone_compile(struct hlsl_ctx *ctx, if (compile->profile) profile_name = compile->profile->name; - if (!(node = hlsl_new_compile(ctx, profile_name, args, compile->args_count, &block, &compile->node.loc))) + if (!(node = hlsl_new_compile(ctx, compile->compile_type, profile_name, + args, compile->args_count, &block, &compile->node.loc))) { hlsl_block_cleanup(&block); vkd3d_free(args); @@ -3300,7 +3308,12 @@ static void dump_ir_compile(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *bu { unsigned int i; - vkd3d_string_buffer_printf(buffer, "compile %s {\n", compile->profile->name); + switch (compile->compile_type) + { + case HLSL_COMPILE_TYPE_COMPILE: + vkd3d_string_buffer_printf(buffer, "compile %s {\n", compile->profile->name); + break; + } dump_block(ctx, buffer, &compile->instrs); diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 6e61db74..c39d58d9 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -875,14 +875,20 @@ struct hlsl_ir_compile { struct hlsl_ir_node node; - /* Special field to store the profile argument. */ + enum hlsl_compile_type + { + /* A shader compilation through the CompileShader() function or the "compile" syntax. */ + HLSL_COMPILE_TYPE_COMPILE, + } compile_type; + + /* Special field to store the profile argument for HLSL_COMPILE_TYPE_COMPILE. */ const struct hlsl_profile_info *profile; /* Block containing the instructions required by the arguments of the * compilation call. */ struct hlsl_block instrs; - /* Arguments to the compilation call. For a "compile" or "CompileShader()" + /* Arguments to the compilation call. For HLSL_COMPILE_TYPE_COMPILE * args[0] is an hlsl_ir_call to the specified function. */ struct hlsl_src *args; unsigned int args_count; @@ -1491,9 +1497,9 @@ bool hlsl_index_is_noncontiguous(struct hlsl_ir_index *index); bool hlsl_index_is_resource_access(struct hlsl_ir_index *index); bool hlsl_index_chain_has_resource_access(struct hlsl_ir_index *index); -struct hlsl_ir_node *hlsl_new_compile(struct hlsl_ctx *ctx, const char *profile_name, - struct hlsl_ir_node **args, unsigned int args_count, struct hlsl_block *args_instrs, - const struct vkd3d_shader_location *loc); +struct hlsl_ir_node *hlsl_new_compile(struct hlsl_ctx *ctx, enum hlsl_compile_type compile_type, + const char *profile_name, struct hlsl_ir_node **args, unsigned int args_count, + struct hlsl_block *args_instrs, const struct vkd3d_shader_location *loc); struct hlsl_ir_node *hlsl_new_index(struct hlsl_ctx *ctx, struct hlsl_ir_node *val, struct hlsl_ir_node *idx, const struct vkd3d_shader_location *loc); struct hlsl_ir_node *hlsl_new_loop(struct hlsl_ctx *ctx, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 60e196c6..77134c26 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -5224,7 +5224,8 @@ static struct hlsl_block *add_shader_compilation(struct hlsl_ctx *ctx, const cha return NULL; } - if (!(compile = hlsl_new_compile(ctx, profile_name, &call_to_compile, 1, args->instrs, loc))) + if (!(compile = hlsl_new_compile(ctx, HLSL_COMPILE_TYPE_COMPILE, + profile_name, &call_to_compile, 1, args->instrs, loc))) { free_parse_initializer(args); return NULL;