mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
vkd3d-shader/hlsl: Add constant folding for the ternary operator.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
parent
6d1ba83856
commit
d9c984c11a
Notes:
Alexandre Julliard
2023-09-22 22:46:41 +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/336
@ -869,6 +869,40 @@ static bool fold_nequal(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, c
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool fold_ternary(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, const struct hlsl_type *dst_type,
|
||||||
|
const struct hlsl_ir_constant *src1, const struct hlsl_ir_constant *src2, const struct hlsl_ir_constant *src3)
|
||||||
|
{
|
||||||
|
unsigned int k;
|
||||||
|
|
||||||
|
assert(dst_type->base_type == src2->node.data_type->base_type);
|
||||||
|
assert(dst_type->base_type == src3->node.data_type->base_type);
|
||||||
|
|
||||||
|
for (k = 0; k < dst_type->dimx; ++k)
|
||||||
|
{
|
||||||
|
switch (src1->node.data_type->base_type)
|
||||||
|
{
|
||||||
|
case HLSL_TYPE_FLOAT:
|
||||||
|
case HLSL_TYPE_HALF:
|
||||||
|
dst->u[k] = src1->value.u[k].f != 0.0f ? src2->value.u[k] : src3->value.u[k];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HLSL_TYPE_DOUBLE:
|
||||||
|
dst->u[k] = src1->value.u[k].d != 0.0 ? src2->value.u[k] : src3->value.u[k];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HLSL_TYPE_INT:
|
||||||
|
case HLSL_TYPE_UINT:
|
||||||
|
case HLSL_TYPE_BOOL:
|
||||||
|
dst->u[k] = src1->value.u[k].u ? src2->value.u[k] : src3->value.u[k];
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
vkd3d_unreachable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
|
bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_constant *arg1, *arg2 = NULL, *arg3 = NULL;
|
struct hlsl_ir_constant *arg1, *arg2 = NULL, *arg3 = NULL;
|
||||||
@ -990,6 +1024,10 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
|
|||||||
success = fold_dp2add(ctx, &res, instr->data_type, arg1, arg2, arg3);
|
success = fold_dp2add(ctx, &res, instr->data_type, arg1, arg2, arg3);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case HLSL_OP3_TERNARY:
|
||||||
|
success = fold_ternary(ctx, &res, instr->data_type, arg1, arg2, arg3);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
FIXME("Fold \"%s\" expression.\n", debug_hlsl_expr_op(expr->op));
|
FIXME("Fold \"%s\" expression.\n", debug_hlsl_expr_op(expr->op));
|
||||||
success = false;
|
success = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user