mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-09-12 18:50:22 -07:00
vkd3d-shader/hlsl: Store function overloads in a list.
The choice to store them in an rbtree was made early on. It does not seem likely
that HLSL programs would define many overloads for any of their functions, but I
suspect the idea was rather that intrinsics would be defined as plain
hlsl_ir_function_decl structures [cf. 447463e590]
and that some intrinsics that could operate on any type would therefore need
many overrides.
This is not how we deal with intrinsics, however. When the first intrinsics were
implemented I made the choice disregard this intended design, and instead match
and convert their types manually, in C. Nothing that has happened in the time
since has led me to question that choice, and in fact, the flexibility with
which we must accommodate functions has led me to believe that matching in this
way was definitely the right choice. The main other designs I see would have
been:
* define each intrinsic variant separately using existing HLSL types. Besides
efficiency concerns (i.e. this would take more space in memory, and would take
longer to generate each variant), the normal type-matching rules don't really
apply to intrinsics.
[For example: elementwise intrinsics like abs() return the same type as the
input, including preserving the distinction between float and float1. It is
legal to define separate HLSL overloads taking float and float1, but trying to
invoke these functions yields an "ambiguous function call" error.]
* introduce new (semi-)generic types. This is far more code and ends up acting
like our current scheme (with helpers) in a slightly more complex form.
So I think we can go ahead and rip out this vestige of the original design for
intrinsics.
As for why to change it: rbtrees are simply more complex to deal with, and it
seems unlikely to me that the difference is going to matter. I do not expect any
program to define large quantities of intrinsics; linked list search should be
good enough.
This commit is contained in:
committed by
Alexandre Julliard
parent
2b59a759d5
commit
b1c2852cd7
Notes:
Alexandre Julliard
2023-11-10 00:10:07 +01:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/454
@@ -827,15 +827,13 @@ struct hlsl_ir_function *hlsl_get_function(struct hlsl_ctx *ctx, const char *nam
|
||||
|
||||
struct hlsl_ir_function_decl *hlsl_get_first_func_decl(struct hlsl_ctx *ctx, const char *name)
|
||||
{
|
||||
struct hlsl_ir_function_decl *decl;
|
||||
struct hlsl_ir_function *func;
|
||||
struct rb_entry *entry;
|
||||
|
||||
if ((entry = rb_get(&ctx->functions, name)))
|
||||
{
|
||||
func = RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry);
|
||||
RB_FOR_EACH_ENTRY(decl, &func->overloads, struct hlsl_ir_function_decl, entry)
|
||||
return decl;
|
||||
return LIST_ENTRY(list_head(&func->overloads), struct hlsl_ir_function_decl, entry);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -2104,10 +2102,9 @@ static int compare_param_hlsl_types(const struct hlsl_type *t1, const struct hls
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int compare_function_decl_rb(const void *key, const struct rb_entry *entry)
|
||||
static int compare_function_decl(const struct hlsl_ir_function_decl *decl,
|
||||
const struct hlsl_func_parameters *parameters)
|
||||
{
|
||||
const struct hlsl_ir_function_decl *decl = RB_ENTRY_VALUE(entry, const struct hlsl_ir_function_decl, entry);
|
||||
const struct hlsl_func_parameters *parameters = key;
|
||||
size_t i;
|
||||
int r;
|
||||
|
||||
@@ -2122,6 +2119,24 @@ static int compare_function_decl_rb(const void *key, const struct rb_entry *entr
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct hlsl_ir_function_decl *hlsl_get_func_decl(struct hlsl_ctx *ctx, const char *name,
|
||||
const struct hlsl_func_parameters *parameters)
|
||||
{
|
||||
struct hlsl_ir_function_decl *decl;
|
||||
struct hlsl_ir_function *func;
|
||||
|
||||
if (!(func = hlsl_get_function(ctx, name)))
|
||||
return NULL;
|
||||
|
||||
LIST_FOR_EACH_ENTRY(decl, &func->overloads, struct hlsl_ir_function_decl, entry)
|
||||
{
|
||||
if (!compare_function_decl(decl, parameters))
|
||||
return decl;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const struct hlsl_type *type)
|
||||
{
|
||||
struct vkd3d_string_buffer *string, *inner_string;
|
||||
@@ -3138,14 +3153,12 @@ static void free_function_decl(struct hlsl_ir_function_decl *decl)
|
||||
vkd3d_free(decl);
|
||||
}
|
||||
|
||||
static void free_function_decl_rb(struct rb_entry *entry, void *context)
|
||||
{
|
||||
free_function_decl(RB_ENTRY_VALUE(entry, struct hlsl_ir_function_decl, entry));
|
||||
}
|
||||
|
||||
static void free_function(struct hlsl_ir_function *func)
|
||||
{
|
||||
rb_destroy(&func->overloads, free_function_decl_rb, NULL);
|
||||
struct hlsl_ir_function_decl *decl, *next;
|
||||
|
||||
LIST_FOR_EACH_ENTRY_SAFE(decl, next, &func->overloads, struct hlsl_ir_function_decl, entry)
|
||||
free_function_decl(decl);
|
||||
vkd3d_free((void *)func->name);
|
||||
vkd3d_free(func);
|
||||
}
|
||||
@@ -3175,17 +3188,15 @@ void hlsl_add_function(struct hlsl_ctx *ctx, char *name, struct hlsl_ir_function
|
||||
{
|
||||
func = RB_ENTRY_VALUE(func_entry, struct hlsl_ir_function, entry);
|
||||
decl->func = func;
|
||||
|
||||
if (rb_put(&func->overloads, &decl->parameters, &decl->entry) == -1)
|
||||
ERR("Failed to insert function overload.\n");
|
||||
list_add_tail(&func->overloads, &decl->entry);
|
||||
vkd3d_free(name);
|
||||
return;
|
||||
}
|
||||
func = hlsl_alloc(ctx, sizeof(*func));
|
||||
func->name = name;
|
||||
rb_init(&func->overloads, compare_function_decl_rb);
|
||||
list_init(&func->overloads);
|
||||
decl->func = func;
|
||||
rb_put(&func->overloads, &decl->parameters, &decl->entry);
|
||||
list_add_tail(&func->overloads, &decl->entry);
|
||||
rb_put(&ctx->functions, func->name, &func->entry);
|
||||
}
|
||||
|
||||
@@ -3674,7 +3685,7 @@ int hlsl_compile_shader(const struct vkd3d_shader_code *hlsl, const struct vkd3d
|
||||
|
||||
if ((func = hlsl_get_function(&ctx, entry_point)))
|
||||
{
|
||||
RB_FOR_EACH_ENTRY(decl, &func->overloads, struct hlsl_ir_function_decl, entry)
|
||||
LIST_FOR_EACH_ENTRY(decl, &func->overloads, struct hlsl_ir_function_decl, entry)
|
||||
{
|
||||
if (!decl->has_body)
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user