vkd3d-shader/tpf: Use 'movc' to implement ternary operator.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
Nikolay Sivov
2023-07-25 08:46:28 +02:00
committed by Alexandre Julliard
parent 2fb0c2d187
commit 1002a6b357
Notes: Alexandre Julliard 2023-09-07 23:01:33 +02: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/268
6 changed files with 100 additions and 1 deletions

View File

@@ -2391,6 +2391,54 @@ static bool lower_round(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *
return true;
}
/* Use 'movc' for the ternary operator. */
static bool lower_ternary(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{
struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS], *replacement;
struct hlsl_ir_node *zero, *cond, *first, *second;
struct hlsl_constant_value zero_value = { 0 };
struct hlsl_ir_expr *expr;
struct hlsl_type *type;
if (instr->type != HLSL_IR_EXPR)
return false;
expr = hlsl_ir_expr(instr);
if (expr->op != HLSL_OP3_TERNARY)
return false;
cond = expr->operands[0].node;
first = expr->operands[1].node;
second = expr->operands[2].node;
if (cond->data_type->base_type == HLSL_TYPE_FLOAT)
{
if (!(zero = hlsl_new_constant(ctx, cond->data_type, &zero_value, &instr->loc)))
return false;
list_add_tail(&instr->entry, &zero->entry);
memset(operands, 0, sizeof(operands));
operands[0] = zero;
operands[1] = cond;
type = cond->data_type;
type = hlsl_get_numeric_type(ctx, type->class, HLSL_TYPE_BOOL, type->dimx, type->dimy);
if (!(cond = hlsl_new_expr(ctx, HLSL_OP2_NEQUAL, operands, type, &instr->loc)))
return false;
list_add_before(&instr->entry, &cond->entry);
}
memset(operands, 0, sizeof(operands));
operands[0] = cond;
operands[1] = first;
operands[2] = second;
if (!(replacement = hlsl_new_expr(ctx, HLSL_OP3_MOVC, operands, first->data_type, &instr->loc)))
return false;
list_add_before(&instr->entry, &replacement->entry);
hlsl_replace_node(instr, replacement);
return true;
}
static bool lower_casts_to_bool(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{
struct hlsl_type *type = instr->data_type, *arg_type;
@@ -4349,6 +4397,8 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry
hlsl_transform_ir(ctx, track_object_components_usage, body, NULL);
sort_synthetic_separated_samplers_first(ctx);
if (profile->major_version >= 4)
hlsl_transform_ir(ctx, lower_ternary, body, NULL);
if (profile->major_version < 4)
{
hlsl_transform_ir(ctx, lower_division, body, NULL);