vkd3d-shader/hlsl: Support abs() for SM1.

This commit is contained in:
Nikolay Sivov 2023-02-05 02:30:36 +03:00 committed by Alexandre Julliard
parent 902ddee557
commit 240b2f966f
Notes: Alexandre Julliard 2023-02-09 23:23:41 +01:00
Approved-by: Zebediah Figura (@zfigura)
Approved-by: Francisco Casas (@fcasas)
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/86
2 changed files with 34 additions and 0 deletions

View File

@ -1591,6 +1591,31 @@ static bool lower_dot(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *co
return true; return true;
} }
/* Lower ABS to MAX */
static bool lower_abs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{
struct hlsl_ir_node *arg, *neg, *replacement;
struct hlsl_ir_expr *expr;
if (instr->type != HLSL_IR_EXPR)
return false;
expr = hlsl_ir_expr(instr);
arg = expr->operands[0].node;
if (expr->op != HLSL_OP1_ABS)
return false;
if (!(neg = hlsl_new_unary_expr(ctx, HLSL_OP1_NEG, arg, instr->loc)))
return false;
list_add_before(&instr->entry, &neg->entry);
if (!(replacement = hlsl_new_binary_expr(ctx, HLSL_OP2_MAX, neg, arg)))
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) 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; struct hlsl_type *type = instr->data_type, *arg_type;
@ -3009,6 +3034,11 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry
transform_ir(ctx, lower_dot, body, NULL); transform_ir(ctx, lower_dot, body, NULL);
} }
if (profile->major_version < 2)
{
transform_ir(ctx, lower_abs, body, NULL);
}
transform_ir(ctx, validate_static_object_references, body, NULL); transform_ir(ctx, validate_static_object_references, body, NULL);
/* TODO: move forward, remove when no longer needed */ /* TODO: move forward, remove when no longer needed */

View File

@ -682,6 +682,10 @@ static void write_sm1_expr(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *b
switch (expr->op) switch (expr->op)
{ {
case HLSL_OP1_ABS:
write_sm1_unary_op(ctx, buffer, D3DSIO_ABS, &instr->reg, &arg1->reg, 0, 0);
break;
case HLSL_OP1_EXP2: case HLSL_OP1_EXP2:
write_sm1_per_component_unary_op(ctx, buffer, instr, D3DSIO_EXP); write_sm1_per_component_unary_op(ctx, buffer, instr, D3DSIO_EXP);
break; break;