vkd3d-shader/hlsl: Add constant folding for lshift.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
Nikolay Sivov 2023-09-13 07:29:10 +02:00 committed by Alexandre Julliard
parent 8c9d65d6b3
commit 6e74819eb7
Notes: Alexandre Julliard 2023-10-05 22:37:14 +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/363
2 changed files with 49 additions and 0 deletions

View File

@ -832,6 +832,36 @@ static bool fold_less(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, con
return true;
}
static bool fold_lshift(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)
{
unsigned int k;
assert(dst_type->base_type == src1->node.data_type->base_type);
assert(src2->node.data_type->base_type == HLSL_TYPE_INT);
for (k = 0; k < dst_type->dimx; ++k)
{
unsigned int shift = src2->value.u[k].u % 32;
switch (src1->node.data_type->base_type)
{
case HLSL_TYPE_INT:
dst->u[k].i = src1->value.u[k].i << shift;
break;
case HLSL_TYPE_UINT:
dst->u[k].u = src1->value.u[k].u << shift;
break;
default:
vkd3d_unreachable();
}
}
return true;
}
static bool fold_max(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)
{
@ -1169,6 +1199,10 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
success = fold_less(ctx, &res, instr->data_type, arg1, arg2);
break;
case HLSL_OP2_LSHIFT:
success = fold_lshift(ctx, &res, instr->data_type, arg1, arg2);
break;
case HLSL_OP2_MAX:
success = fold_max(ctx, &res, instr->data_type, arg1, arg2);
break;

View File

@ -14,6 +14,21 @@ float4 main() : SV_TARGET
draw quad
probe all rgba (0.0, 0.0, 163840.0, 480.0)
[pixel shader]
float4 main() : sv_target
{
int x = 1;
int y = -1;
int z = 34;
uint x2 = 1;
return float4(x << y, x << z, x2 << y, x2 << z);
}
[test]
draw quad
probe all rgba (-2147483648.0, 4.0, 2147483650.0, 4.0)
[pixel shader]
float4 main() : SV_TARGET
{