mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-09-12 18:50:22 -07:00
vkd3d-shader/hlsl: Define smoothstep() in HLSL.
This commit is contained in:
committed by
Alexandre Julliard
parent
d396c4ce27
commit
9ab77658f2
Notes:
Alexandre Julliard
2023-08-30 23:19:43 +02: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/310
@@ -2988,6 +2988,16 @@ void hlsl_add_function(struct hlsl_ctx *ctx, char *name, struct hlsl_ir_function
|
||||
struct hlsl_ir_function *func;
|
||||
struct rb_entry *func_entry;
|
||||
|
||||
if (ctx->internal_func_name)
|
||||
{
|
||||
char *internal_name;
|
||||
|
||||
if (!(internal_name = hlsl_strdup(ctx, ctx->internal_func_name)))
|
||||
return;
|
||||
vkd3d_free(name);
|
||||
name = internal_name;
|
||||
}
|
||||
|
||||
func_entry = rb_get(&ctx->functions, name);
|
||||
if (func_entry)
|
||||
{
|
||||
@@ -3519,3 +3529,44 @@ int hlsl_compile_shader(const struct vkd3d_shader_code *hlsl, const struct vkd3d
|
||||
hlsl_ctx_cleanup(&ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct hlsl_ir_function_decl *hlsl_compile_internal_function(struct hlsl_ctx *ctx, const char *name, const char *hlsl)
|
||||
{
|
||||
const struct hlsl_ir_function_decl *saved_cur_function = ctx->cur_function;
|
||||
struct vkd3d_shader_code code = {.code = hlsl, .size = strlen(hlsl)};
|
||||
const char *saved_internal_func_name = ctx->internal_func_name;
|
||||
struct vkd3d_string_buffer *internal_name;
|
||||
struct hlsl_ir_function_decl *func;
|
||||
void *saved_scanner = ctx->scanner;
|
||||
int ret;
|
||||
|
||||
TRACE("name %s, hlsl %s.\n", debugstr_a(name), debugstr_a(hlsl));
|
||||
|
||||
/* The actual name of the function is mangled with a unique prefix, both to
|
||||
* allow defining multiple variants of a function with the same name, and to
|
||||
* avoid polluting the user name space. */
|
||||
|
||||
if (!(internal_name = hlsl_get_string_buffer(ctx)))
|
||||
return NULL;
|
||||
vkd3d_string_buffer_printf(internal_name, "<%s-%u>", name, ctx->internal_name_counter++);
|
||||
|
||||
/* Save and restore everything that matters.
|
||||
* Note that saving the scope stack is hard, and shouldn't be necessary. */
|
||||
|
||||
ctx->scanner = NULL;
|
||||
ctx->internal_func_name = internal_name->buffer;
|
||||
ctx->cur_function = NULL;
|
||||
ret = hlsl_lexer_compile(ctx, &code);
|
||||
ctx->scanner = saved_scanner;
|
||||
ctx->internal_func_name = saved_internal_func_name;
|
||||
ctx->cur_function = saved_cur_function;
|
||||
if (ret)
|
||||
{
|
||||
ERR("Failed to compile intrinsic, error %u.\n", ret);
|
||||
hlsl_release_string_buffer(ctx, internal_name);
|
||||
return NULL;
|
||||
}
|
||||
func = hlsl_get_func_decl(ctx, internal_name->buffer);
|
||||
hlsl_release_string_buffer(ctx, internal_name);
|
||||
return func;
|
||||
}
|
||||
|
Reference in New Issue
Block a user