vkd3d-shader/hlsl: Introduce a hlsl_new_bool_constant() helper.

This commit is contained in:
Zebediah Figura 2022-09-26 18:54:03 -05:00 committed by Alexandre Julliard
parent 4c5fd9c7b9
commit 3fc2fdc37f
Notes: Alexandre Julliard 2022-10-18 00:13:00 +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/22
3 changed files with 18 additions and 6 deletions

View File

@ -915,6 +915,16 @@ struct hlsl_ir_constant *hlsl_new_constant(struct hlsl_ctx *ctx, struct hlsl_typ
return c; return c;
} }
struct hlsl_ir_constant *hlsl_new_bool_constant(struct hlsl_ctx *ctx, bool b, const struct vkd3d_shader_location *loc)
{
struct hlsl_ir_constant *c;
if ((c = hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_BOOL), loc)))
c->value[0].u = b ? ~0u : 0;
return c;
}
struct hlsl_ir_constant *hlsl_new_float_constant(struct hlsl_ctx *ctx, float f, struct hlsl_ir_constant *hlsl_new_float_constant(struct hlsl_ctx *ctx, float f,
const struct vkd3d_shader_location *loc) const struct vkd3d_shader_location *loc)
{ {

View File

@ -751,6 +751,7 @@ struct hlsl_type *hlsl_get_element_type_from_path_index(struct hlsl_ctx *ctx, co
struct hlsl_type *hlsl_new_array_type(struct hlsl_ctx *ctx, struct hlsl_type *basic_type, unsigned int array_size); struct hlsl_type *hlsl_new_array_type(struct hlsl_ctx *ctx, struct hlsl_type *basic_type, unsigned int array_size);
struct hlsl_ir_node *hlsl_new_binary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *hlsl_new_binary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1,
struct hlsl_ir_node *arg2); struct hlsl_ir_node *arg2);
struct hlsl_ir_constant *hlsl_new_bool_constant(struct hlsl_ctx *ctx, bool b, const struct vkd3d_shader_location *loc);
struct hlsl_buffer *hlsl_new_buffer(struct hlsl_ctx *ctx, enum hlsl_buffer_type type, const char *name, struct hlsl_buffer *hlsl_new_buffer(struct hlsl_ctx *ctx, enum hlsl_buffer_type type, const char *name,
const struct hlsl_reg_reservation *reservation, struct vkd3d_shader_location loc); 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, struct hlsl_ir_expr *hlsl_new_cast(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_type *type,

View File

@ -2800,7 +2800,7 @@ static bool add_method_call(struct hlsl_ctx *ctx, struct list *instrs, struct hl
struct hlsl_type *type; struct hlsl_type *type;
INT intval; INT intval;
FLOAT floatval; FLOAT floatval;
BOOL boolval; bool boolval;
char *name; char *name;
DWORD modifiers; DWORD modifiers;
struct hlsl_ir_node *instr; struct hlsl_ir_node *instr;
@ -3857,11 +3857,11 @@ initializer_expr_list:
boolean: boolean:
KW_TRUE KW_TRUE
{ {
$$ = TRUE; $$ = true;
} }
| KW_FALSE | KW_FALSE
{ {
$$ = FALSE; $$ = false;
} }
statement_list: statement_list:
@ -4001,13 +4001,14 @@ primary_expr:
{ {
struct hlsl_ir_constant *c; struct hlsl_ir_constant *c;
if (!(c = hlsl_alloc(ctx, sizeof(*c)))) if (!(c = hlsl_new_bool_constant(ctx, $1, &@1)))
YYABORT; YYABORT;
init_node(&c->node, HLSL_IR_CONSTANT, hlsl_get_scalar_type(ctx, HLSL_TYPE_BOOL), @1);
c->value[0].u = $1 ? ~0u : 0;
if (!($$ = make_list(ctx, &c->node))) if (!($$ = make_list(ctx, &c->node)))
{
hlsl_free_instr(&c->node);
YYABORT; YYABORT;
} }
}
| VAR_IDENTIFIER | VAR_IDENTIFIER
{ {
struct hlsl_ir_load *load; struct hlsl_ir_load *load;