Module: vkd3d Branch: master Commit: 4c5fd9c7b96e45a769bd21f1b6adcf2469083431 URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/4c5fd9c7b96e45a769bd21f1b6adcf...
Author: Zebediah Figura zfigura@codeweavers.com Date: Mon Sep 26 18:50:04 2022 -0500
vkd3d-shader/hlsl: Introduce a hlsl_new_float_constant() helper.
---
libs/vkd3d-shader/hlsl.c | 11 +++++++++++ libs/vkd3d-shader/hlsl.h | 2 ++ libs/vkd3d-shader/hlsl.y | 4 +--- 3 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index c4848632..cb1fd14a 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -915,6 +915,17 @@ struct hlsl_ir_constant *hlsl_new_constant(struct hlsl_ctx *ctx, struct hlsl_typ return c; }
+struct hlsl_ir_constant *hlsl_new_float_constant(struct hlsl_ctx *ctx, float f, + const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_constant *c; + + if ((c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_FLOAT), loc))) + c->value[0].f = f; + + return c; +} + struct hlsl_ir_constant *hlsl_new_int_constant(struct hlsl_ctx *ctx, int n, const struct vkd3d_shader_location *loc) { diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index b9dfc9cd..c5bd9b79 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -758,6 +758,8 @@ struct hlsl_ir_expr *hlsl_new_cast(struct hlsl_ctx *ctx, struct hlsl_ir_node *no struct hlsl_ir_constant *hlsl_new_constant(struct hlsl_ctx *ctx, struct hlsl_type *type, const struct vkd3d_shader_location *loc); struct hlsl_ir_expr *hlsl_new_copy(struct hlsl_ctx *ctx, struct hlsl_ir_node *node); +struct hlsl_ir_constant *hlsl_new_float_constant(struct hlsl_ctx *ctx, + float f, const struct vkd3d_shader_location *loc); struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_ctx *ctx, struct hlsl_type *return_type, struct list *parameters, const struct hlsl_semantic *semantic, struct vkd3d_shader_location loc); struct hlsl_ir_if *hlsl_new_if(struct hlsl_ctx *ctx, struct hlsl_ir_node *condition, struct vkd3d_shader_location loc); diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 4c9b912c..565a551d 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -3981,10 +3981,8 @@ primary_expr: { struct hlsl_ir_constant *c;
- if (!(c = hlsl_alloc(ctx, sizeof(*c)))) + if (!(c = hlsl_new_float_constant(ctx, $1, &@1))) YYABORT; - init_node(&c->node, HLSL_IR_CONSTANT, hlsl_get_scalar_type(ctx, HLSL_TYPE_FLOAT), @1); - c->value[0].f = $1; if (!($$ = make_list(ctx, &c->node))) YYABORT; }