Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- v2: * Assert type class --- libs/vkd3d-shader/hlsl.c | 31 ++++++++++++++++++++++++------- libs/vkd3d-shader/hlsl.h | 2 ++ 2 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 36cc3a91..664f7813 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -563,15 +563,31 @@ struct hlsl_ir_store *hlsl_new_simple_store(struct hlsl_ctx *ctx, struct hlsl_ir return hlsl_new_store(ctx, lhs, NULL, rhs, 0, rhs->loc); }
-struct hlsl_ir_constant *hlsl_new_int_constant(struct hlsl_ctx *ctx, int n, +struct hlsl_ir_constant *hlsl_new_constant(struct hlsl_ctx *ctx, struct hlsl_type *type, const struct vkd3d_shader_location *loc) { struct hlsl_ir_constant *c;
+ assert(type->type <= HLSL_CLASS_VECTOR); + if (!(c = hlsl_alloc(ctx, sizeof(*c)))) return NULL; - init_node(&c->node, HLSL_IR_CONSTANT, hlsl_get_scalar_type(ctx, HLSL_TYPE_INT), *loc); - c->value[0].i = n; + + init_node(&c->node, HLSL_IR_CONSTANT, type, *loc); + + return c; +} + +struct hlsl_ir_constant *hlsl_new_int_constant(struct hlsl_ctx *ctx, int n, + const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_constant *c; + + c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_INT), loc); + + if (c) + c->value[0].i = n; + return c; }
@@ -580,10 +596,11 @@ struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned i { struct hlsl_ir_constant *c;
- if (!(c = hlsl_alloc(ctx, sizeof(*c)))) - return NULL; - init_node(&c->node, HLSL_IR_CONSTANT, hlsl_get_scalar_type(ctx, HLSL_TYPE_UINT), *loc); - c->value[0].u = n; + c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_UINT), loc); + + if (c) + c->value[0].u = n; + return c; }
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index c9abbd4a..e4db386f 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -733,6 +733,8 @@ struct hlsl_buffer *hlsl_new_buffer(struct hlsl_ctx *ctx, enum hlsl_buffer_type const struct hlsl_reg_reservation *reservation, struct vkd3d_shader_location loc); struct hlsl_ir_expr *hlsl_new_cast(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_type *type, const struct vkd3d_shader_location *loc); +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_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);