From 74365417ac61afe4daeb1a8f9aa747c35e519811 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Mon, 2 Dec 2024 14:26:35 +0100 Subject: [PATCH] vkd3d-shader/hlsl: Output the candidates for ambiguous function calls. --- libs/vkd3d-shader/hlsl.c | 2 +- libs/vkd3d-shader/hlsl.h | 2 ++ libs/vkd3d-shader/hlsl.y | 44 +++++++++++++++++++++++++++++++++------- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 98ceb9dd..f0d24b83 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -3111,7 +3111,7 @@ const char *debug_hlsl_swizzle(uint32_t swizzle, unsigned int size) return vkd3d_dbg_sprintf(".%s", string); } -static void hlsl_dump_ir_function_decl(struct hlsl_ctx *ctx, +void hlsl_dump_ir_function_decl(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_function_decl *f) { size_t i; diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 0d98d7fd..42f669db 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -1437,6 +1437,8 @@ void hlsl_block_cleanup(struct hlsl_block *block); bool hlsl_clone_block(struct hlsl_ctx *ctx, struct hlsl_block *dst_block, const struct hlsl_block *src_block); void hlsl_dump_function(struct hlsl_ctx *ctx, const struct hlsl_ir_function_decl *func); +void hlsl_dump_ir_function_decl(struct hlsl_ctx *ctx, + struct vkd3d_string_buffer *buffer, const struct hlsl_ir_function_decl *f); void hlsl_dump_var_default_values(const struct hlsl_ir_var *var); bool hlsl_state_block_add_entry(struct hlsl_state_block *state_block, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index b247c791..afa41f4b 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -3012,9 +3012,16 @@ static struct hlsl_ir_function_decl *find_function_call(struct hlsl_ctx *ctx, const char *name, const struct parse_initializer *args, bool is_compile, const struct vkd3d_shader_location *loc) { - struct hlsl_ir_function_decl *decl, *compatible_match = NULL; + struct hlsl_ir_function_decl *decl; + struct vkd3d_string_buffer *s; struct hlsl_ir_function *func; struct rb_entry *entry; + size_t i; + struct + { + struct hlsl_ir_function_decl **candidates; + size_t count, capacity; + } candidates = {0}; if (!(entry = rb_get(&ctx->functions, name))) return NULL; @@ -3022,18 +3029,41 @@ static struct hlsl_ir_function_decl *find_function_call(struct hlsl_ctx *ctx, LIST_FOR_EACH_ENTRY(decl, &func->overloads, struct hlsl_ir_function_decl, entry) { - if (func_is_compatible_match(ctx, decl, is_compile, args)) + if (!func_is_compatible_match(ctx, decl, is_compile, args)) + continue; + + if (!(hlsl_array_reserve(ctx, (void **)&candidates.candidates, + &candidates.capacity, candidates.count + 1, sizeof(decl)))) { - if (compatible_match) + vkd3d_free(candidates.candidates); + return NULL; + } + candidates.candidates[candidates.count++] = decl; + } + + if (!candidates.count) + return NULL; + + if (candidates.count > 1) + { + hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_AMBIGUOUS_CALL, "Ambiguous function call."); + if ((s = hlsl_get_string_buffer(ctx))) + { + hlsl_note(ctx, loc, VKD3D_SHADER_LOG_ERROR, "Candidates are:"); + for (i = 0; i < candidates.count; ++i) { - hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_AMBIGUOUS_CALL, "Ambiguous function call."); - break; + hlsl_dump_ir_function_decl(ctx, s, candidates.candidates[i]); + hlsl_note(ctx, loc, VKD3D_SHADER_LOG_ERROR, " %s;", s->buffer); + vkd3d_string_buffer_clear(s); } - compatible_match = decl; + hlsl_release_string_buffer(ctx, s); } } - return compatible_match; + decl = candidates.candidates[0]; + vkd3d_free(candidates.candidates); + + return decl; } static struct hlsl_ir_node *hlsl_new_void_expr(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc)