mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
vkd3d-shader/hlsl: Lower int absolute value.
This commit is contained in:
parent
ef4990d996
commit
4c13ae5764
Notes:
Alexandre Julliard
2022-10-18 00:13:00 +02:00
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/28
@ -1284,6 +1284,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)
|
||||
@ -2268,6 +2297,7 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry
|
||||
|
||||
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);
|
||||
|
@ -38,5 +38,5 @@ float4 main() : SV_TARGET
|
||||
|
||||
[test]
|
||||
uniform 0 float4 5.0 -7.0 0.0 -10.0
|
||||
todo draw quad
|
||||
draw quad
|
||||
probe all rgba (5.0, 7.0, 0.0, 10.0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user