Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ValveSoftware/vkd3d.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiovanni Mascellani <gmascellani@codeweavers.com>2021-09-21 18:21:44 +0300
committerGiovanni Mascellani <gmascellani@codeweavers.com>2022-07-26 15:48:57 +0300
commitf9fe79fb3278cd1d3f65292c546b2378f1ddd9f4 (patch)
tree826f073d2c608152b05017fe074f81acda3073f3
parenta455ce00490d4f633b3ab8fa005e18d184d3fb05 (diff)
vkd3d-shader/hlsl: Lower int absolute value.
Signed-off-by: Giovanni Mascellani <gmascellani@codeweavers.com>
-rw-r--r--libs/vkd3d-shader/hlsl_codegen.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
index bb1602ca..f1c7eec5 100644
--- a/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -1574,6 +1574,35 @@ static bool lower_casts_to_bool(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr
return true;
}
+static bool lower_int_abs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
+{
+ struct hlsl_type *type = instr->data_type;
+ struct hlsl_ir_node *arg, *neg;
+ struct hlsl_ir_expr *expr;
+
+ if (instr->type != HLSL_IR_EXPR)
+ return false;
+ expr = hlsl_ir_expr(instr);
+
+ if (expr->op != HLSL_OP1_ABS)
+ return false;
+ if (type->type != HLSL_CLASS_SCALAR && type->type != HLSL_CLASS_VECTOR)
+ return false;
+ if (type->base_type != HLSL_TYPE_INT)
+ return false;
+
+ arg = expr->operands[0].node;
+
+ if (!(neg = hlsl_new_unary_expr(ctx, HLSL_OP1_NEG, arg, instr->loc)))
+ return false;
+ list_add_before(&instr->entry, &neg->entry);
+
+ expr->op = HLSL_OP2_MAX;
+ hlsl_src_from_node(&expr->operands[1], neg);
+
+ return true;
+}
+
static bool dce(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{
switch (instr->type)
@@ -2706,6 +2735,7 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry
transform_ir(ctx, split_matrix_copies, body, NULL);
transform_ir(ctx, lower_narrowing_casts, body, NULL);
transform_ir(ctx, lower_casts_to_bool, body, NULL);
+ transform_ir(ctx, lower_int_abs, body, NULL);
do
{
progress = transform_ir(ctx, hlsl_fold_constant_exprs, body, NULL);