From: Francisco Casas fcasas@codeweavers.com
--- libs/vkd3d-shader/hlsl.y | 55 +++++++++++++--------------------------- 1 file changed, 18 insertions(+), 37 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 7d9d8a18..91daa482 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2226,7 +2226,8 @@ static struct hlsl_ir_node *intrinsic_float_convert_arg(struct hlsl_ctx *ctx, }
static bool elementwise_intrinsic_convert_args(struct hlsl_ctx *ctx, - const struct parse_initializer *params, const struct vkd3d_shader_location *loc) + const struct parse_initializer *params, bool convert_to_float, + const struct vkd3d_shader_location *loc) { enum hlsl_base_type base = params->args[0]->data_type->base_type; bool vectors = false, matrices = false; @@ -2253,6 +2254,9 @@ static bool elementwise_intrinsic_convert_args(struct hlsl_ctx *ctx, } }
+ if (convert_to_float) + base = HLSL_TYPE_FLOAT; + if (matrices && vectors) { hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, @@ -2339,7 +2343,7 @@ static bool intrinsic_clamp(struct hlsl_ctx *ctx, { struct hlsl_ir_node *max;
- if (!elementwise_intrinsic_convert_args(ctx, params, loc)) + if (!elementwise_intrinsic_convert_args(ctx, params, false, loc)) return false;
if (!(max = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MAX, params->args[0], params->args[1], loc))) @@ -2423,13 +2427,10 @@ static bool intrinsic_ldexp(struct hlsl_ctx *ctx, { struct hlsl_ir_node *arg;
- if (!elementwise_intrinsic_convert_args(ctx, params, loc)) - return false; - - if (!(arg = intrinsic_float_convert_arg(ctx, params, params->args[1], loc))) + if (!elementwise_intrinsic_convert_args(ctx, params, true, loc)) return false;
- if (!(arg = add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_EXP2, arg, loc))) + if (!(arg = add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_EXP2, params->args[1], loc))) return false;
return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, params->args[0], arg, loc); @@ -2463,15 +2464,12 @@ static bool intrinsic_length(struct hlsl_ctx *ctx, static bool intrinsic_lerp(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { - struct hlsl_ir_node *arg, *neg, *add, *mul; + struct hlsl_ir_node *neg, *add, *mul;
- if (!elementwise_intrinsic_convert_args(ctx, params, loc)) + if (!elementwise_intrinsic_convert_args(ctx, params, true, loc)) return false;
- if (!(arg = intrinsic_float_convert_arg(ctx, params, params->args[0], loc))) - return false; - - if (!(neg = add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_NEG, arg, loc))) + if (!(neg = add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_NEG, params->args[0], loc))) return false;
if (!(add = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, params->args[1], neg, loc))) @@ -2480,13 +2478,13 @@ static bool intrinsic_lerp(struct hlsl_ctx *ctx, if (!(mul = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, params->args[2], add, loc))) return false;
- return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, arg, mul, loc); + return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, params->args[0], mul, loc); }
static bool intrinsic_max(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { - if (!elementwise_intrinsic_convert_args(ctx, params, loc)) + if (!elementwise_intrinsic_convert_args(ctx, params, false, loc)) return false;
return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MAX, params->args[0], params->args[1], loc); @@ -2495,7 +2493,7 @@ static bool intrinsic_max(struct hlsl_ctx *ctx, static bool intrinsic_min(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { - if (!elementwise_intrinsic_convert_args(ctx, params, loc)) + if (!elementwise_intrinsic_convert_args(ctx, params, false, loc)) return false;
return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MIN, params->args[0], params->args[1], loc); @@ -2630,15 +2628,12 @@ static bool intrinsic_normalize(struct hlsl_ctx *ctx, static bool intrinsic_pow(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { - struct hlsl_ir_node *log, *exp, *arg, *mul; - - if (!elementwise_intrinsic_convert_args(ctx, params, loc)) - return false; + struct hlsl_ir_node *log, *exp, *mul;
- if (!(arg = intrinsic_float_convert_arg(ctx, params, params->args[0], loc))) + if (!elementwise_intrinsic_convert_args(ctx, params, true, loc)) return false;
- if (!(log = hlsl_new_unary_expr(ctx, HLSL_OP1_LOG2, arg, *loc))) + if (!(log = hlsl_new_unary_expr(ctx, HLSL_OP1_LOG2, params->args[0], *loc))) return false; list_add_tail(params->instrs, &log->entry);
@@ -2679,28 +2674,14 @@ static bool intrinsic_smoothstep(struct hlsl_ctx *ctx, { struct hlsl_ir_node *min_arg, *max_arg, *x_arg, *p, *p_num, *p_denom, *res; struct hlsl_ir_constant *one, *minus_two, *three; - struct hlsl_type *common_type;
- if (!elementwise_intrinsic_convert_args(ctx, params, loc)) + if (!elementwise_intrinsic_convert_args(ctx, params, true, loc)) return false;
min_arg = params->args[0]; max_arg = params->args[1]; x_arg = params->args[2];
- common_type = x_arg->data_type; - common_type = hlsl_get_numeric_type(ctx, common_type->type, HLSL_TYPE_FLOAT, common_type->dimx, - common_type->dimy); - - if (!(min_arg = add_implicit_conversion(ctx, params->instrs, min_arg, common_type, loc))) - return false; - - if (!(max_arg = add_implicit_conversion(ctx, params->instrs, max_arg, common_type, loc))) - return false; - - if (!(x_arg = add_implicit_conversion(ctx, params->instrs, x_arg, common_type, loc))) - return false; - if (!(min_arg = add_unary_arithmetic_expr(ctx, params->instrs, HLSL_OP1_NEG, min_arg, loc))) return false;