vkd3d-shader/hlsl: Cast slt before multiplying on ternary operator.

Otherwise we may get a failing
    "hlsl_types_are_equal(arg1->data_type, arg2->data_type)"
assertion on hlsl_new_binary_expr() when creating the MUL.

This happens in the test introducing in the following patch:

    int a, b, c;

    void main(out float4 res : COLOR1, in float4 pos : position, out float4 out_pos : sv_position)
    {
        out_pos = pos;

        res = a ? b/1000.0 : c/1000.0;
    }
This commit is contained in:
Francisco Casas 2024-03-07 11:19:07 -03:00 committed by Alexandre Julliard
parent fda08de61d
commit cfac67ccc2
Notes: Alexandre Julliard 2024-03-11 23:06:28 +01:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Zebediah Figura (@zfigura)
Approved-by: Francisco Casas (@fcasas)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/694

View File

@ -2948,7 +2948,7 @@ static bool lower_ternary(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, stru
}
else if (ctx->profile->major_version < 4 && ctx->profile->type == VKD3D_SHADER_TYPE_VERTEX)
{
struct hlsl_ir_node *neg, *slt, *sum, *mul, *cond2;
struct hlsl_ir_node *neg, *slt, *sum, *cond2, *slt_cast, *mul;
/* Expression used here is "slt(<cond>) * (first - second) + second". */
@ -2980,7 +2980,11 @@ static bool lower_ternary(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, stru
return false;
hlsl_block_add_instr(block, sum);
if (!(mul = hlsl_new_binary_expr(ctx, HLSL_OP2_MUL, slt, sum)))
if (!(slt_cast = hlsl_new_cast(ctx, slt, sum->data_type, &instr->loc)))
return false;
hlsl_block_add_instr(block, slt_cast);
if (!(mul = hlsl_new_binary_expr(ctx, HLSL_OP2_MUL, slt_cast, sum)))
return false;
hlsl_block_add_instr(block, mul);