vkd3d-shader/hlsl: Pass hlsl_constant_value and hlsl_type pointers to fold_abs().

This commit is contained in:
Zebediah Figura 2023-05-23 10:07:58 -05:00 committed by Alexandre Julliard
parent c805eb1191
commit b453a0acd6
Notes: Alexandre Julliard 2023-05-26 22:17:06 +02:00
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/210

View File

@ -22,40 +22,41 @@
#include "hlsl.h" #include "hlsl.h"
static bool fold_abs(struct hlsl_ctx *ctx, struct hlsl_ir_constant *dst, struct hlsl_ir_constant *src) static bool fold_abs(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst,
const struct hlsl_type *dst_type, const struct hlsl_ir_constant *src)
{ {
enum hlsl_base_type type = dst->node.data_type->base_type; enum hlsl_base_type type = dst_type->base_type;
unsigned int k; unsigned int k;
assert(type == src->node.data_type->base_type); assert(type == src->node.data_type->base_type);
for (k = 0; k < 4; ++k) for (k = 0; k < dst_type->dimx; ++k)
{ {
switch (type) switch (type)
{ {
case HLSL_TYPE_FLOAT: case HLSL_TYPE_FLOAT:
case HLSL_TYPE_HALF: case HLSL_TYPE_HALF:
dst->value.u[k].f = fabsf(src->value.u[k].f); dst->u[k].f = fabsf(src->value.u[k].f);
break; break;
case HLSL_TYPE_DOUBLE: case HLSL_TYPE_DOUBLE:
dst->value.u[k].d = fabs(src->value.u[k].d); dst->u[k].d = fabs(src->value.u[k].d);
break; break;
case HLSL_TYPE_INT: case HLSL_TYPE_INT:
/* C's abs(INT_MIN) is undefined, but HLSL evaluates this to INT_MIN */ /* C's abs(INT_MIN) is undefined, but HLSL evaluates this to INT_MIN */
if (src->value.u[k].i == INT_MIN) if (src->value.u[k].i == INT_MIN)
dst->value.u[k].i = INT_MIN; dst->u[k].i = INT_MIN;
else else
dst->value.u[k].i = abs(src->value.u[k].i); dst->u[k].i = abs(src->value.u[k].i);
break; break;
case HLSL_TYPE_UINT: case HLSL_TYPE_UINT:
dst->value.u[k].u = src->value.u[k].u; dst->u[k].u = src->value.u[k].u;
break; break;
default: default:
FIXME("Fold abs() for type %s.\n", debug_hlsl_type(ctx, dst->node.data_type)); FIXME("Fold abs() for type %s.\n", debug_hlsl_type(ctx, dst_type));
return false; return false;
} }
} }
@ -576,7 +577,7 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
switch (expr->op) switch (expr->op)
{ {
case HLSL_OP1_ABS: case HLSL_OP1_ABS:
success = fold_abs(ctx, res, arg1); success = fold_abs(ctx, &res->value, instr->data_type, arg1);
break; break;
case HLSL_OP1_CAST: case HLSL_OP1_CAST: