mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
vkd3d-shader/hlsl: Implement ternary operator for older vertex profiles.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56333 Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
parent
f866fb95ad
commit
937d76507d
Notes:
Alexandre Julliard
2024-03-06 23:29:00 +01:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Zebediah Figura (@zfigura) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/669
@ -2329,6 +2329,10 @@ static void write_sm1_expr(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *b
|
||||
}
|
||||
break;
|
||||
|
||||
case HLSL_OP2_SLT:
|
||||
write_sm1_binary_op(ctx, buffer, D3DSIO_SLT, &instr->reg, &arg1->reg, &arg2->reg);
|
||||
break;
|
||||
|
||||
case HLSL_OP3_CMP:
|
||||
write_sm1_ternary_op(ctx, buffer, D3DSIO_CMP, &instr->reg, &arg1->reg, &arg2->reg, &arg3->reg);
|
||||
break;
|
||||
|
@ -2611,6 +2611,7 @@ const char *debug_hlsl_expr_op(enum hlsl_ir_expr_op op)
|
||||
[HLSL_OP2_MUL] = "*",
|
||||
[HLSL_OP2_NEQUAL] = "!=",
|
||||
[HLSL_OP2_RSHIFT] = ">>",
|
||||
[HLSL_OP2_SLT] = "slt",
|
||||
|
||||
[HLSL_OP3_CMP] = "cmp",
|
||||
[HLSL_OP3_DP2ADD] = "dp2add",
|
||||
|
@ -593,6 +593,7 @@ enum hlsl_ir_expr_op
|
||||
HLSL_OP2_MUL,
|
||||
HLSL_OP2_NEQUAL,
|
||||
HLSL_OP2_RSHIFT,
|
||||
HLSL_OP2_SLT,
|
||||
|
||||
/* DP2ADD(a, b, c) computes the scalar product of a.xy and b.xy,
|
||||
* then adds c. */
|
||||
|
@ -2903,7 +2903,7 @@ static bool lower_floor(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, struct
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Use 'movc' for the ternary operator. */
|
||||
/* Use movc/cmp/slt for the ternary operator. */
|
||||
static bool lower_ternary(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, struct hlsl_block *block)
|
||||
{
|
||||
struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS] = { 0 }, *replacement;
|
||||
@ -2949,8 +2949,44 @@ 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)
|
||||
{
|
||||
hlsl_fixme(ctx, &instr->loc, "Ternary operator is not implemented for %s profile.", ctx->profile->name);
|
||||
return false;
|
||||
struct hlsl_ir_node *neg, *slt, *sum, *mul, *cond2;
|
||||
|
||||
/* Expression used here is "slt(<cond>) * (first - second) + second". */
|
||||
|
||||
if (ctx->profile->major_version == 3)
|
||||
{
|
||||
if (!(cond2 = hlsl_new_unary_expr(ctx, HLSL_OP1_ABS, cond, &instr->loc)))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(cond2 = hlsl_new_binary_expr(ctx, HLSL_OP2_MUL, cond, cond)))
|
||||
return false;
|
||||
}
|
||||
hlsl_block_add_instr(block, cond2);
|
||||
|
||||
if (!(neg = hlsl_new_unary_expr(ctx, HLSL_OP1_NEG, cond2, &instr->loc)))
|
||||
return false;
|
||||
hlsl_block_add_instr(block, neg);
|
||||
|
||||
if (!(slt = hlsl_new_binary_expr(ctx, HLSL_OP2_SLT, neg, cond2)))
|
||||
return false;
|
||||
hlsl_block_add_instr(block, slt);
|
||||
|
||||
if (!(neg = hlsl_new_unary_expr(ctx, HLSL_OP1_NEG, second, &instr->loc)))
|
||||
return false;
|
||||
hlsl_block_add_instr(block, neg);
|
||||
|
||||
if (!(sum = hlsl_new_binary_expr(ctx, HLSL_OP2_ADD, first, neg)))
|
||||
return false;
|
||||
hlsl_block_add_instr(block, sum);
|
||||
|
||||
if (!(mul = hlsl_new_binary_expr(ctx, HLSL_OP2_MUL, slt, sum)))
|
||||
return false;
|
||||
hlsl_block_add_instr(block, mul);
|
||||
|
||||
if (!(replacement = hlsl_new_binary_expr(ctx, HLSL_OP2_ADD, mul, second)))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user