diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index 526ce88b..51f2f9cc 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -1430,6 +1430,40 @@ static bool constant_is_zero(struct hlsl_ir_constant *const_arg) return true; } +static bool constant_is_one(struct hlsl_ir_constant *const_arg) +{ + struct hlsl_type *data_type = const_arg->node.data_type; + unsigned int k; + + for (k = 0; k < data_type->dimx; ++k) + { + switch (data_type->base_type) + { + case HLSL_TYPE_FLOAT: + case HLSL_TYPE_HALF: + if (const_arg->value.u[k].f != 1.0f) + return false; + break; + + case HLSL_TYPE_DOUBLE: + if (const_arg->value.u[k].d != 1.0) + return false; + break; + + case HLSL_TYPE_UINT: + case HLSL_TYPE_INT: + case HLSL_TYPE_BOOL: + if (const_arg->value.u[k].u != 1) + return false; + break; + + default: + return false; + } + } + return true; +} + bool hlsl_fold_constant_identities(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) { struct hlsl_ir_constant *const_arg = NULL; @@ -1475,6 +1509,11 @@ bool hlsl_fold_constant_identities(struct hlsl_ctx *ctx, struct hlsl_ir_node *in res_node = mut_arg; break; + case HLSL_OP2_MUL: + if (constant_is_one(const_arg)) + res_node = mut_arg; + break; + default: break; }