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 rshift.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
parent
6e74819eb7
commit
8ebccad3c9
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
@ -1086,6 +1086,36 @@ static bool fold_ternary(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool fold_rshift(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;
|
||||
}
|
||||
|
||||
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;
|
||||
@ -1223,6 +1253,10 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
|
||||
success = fold_nequal(ctx, &res, instr->data_type, arg1, arg2);
|
||||
break;
|
||||
|
||||
case HLSL_OP2_RSHIFT:
|
||||
success = fold_rshift(ctx, &res, instr->data_type, arg1, arg2);
|
||||
break;
|
||||
|
||||
case HLSL_OP3_DP2ADD:
|
||||
success = fold_dp2add(ctx, &res, instr->data_type, arg1, arg2, arg3);
|
||||
break;
|
||||
|
@ -29,6 +29,21 @@ float4 main() : sv_target
|
||||
draw quad
|
||||
probe all rgba (-2147483648.0, 4.0, 2147483650.0, 4.0)
|
||||
|
||||
[pixel shader]
|
||||
float4 main() : sv_target
|
||||
{
|
||||
int x = 2147483647;
|
||||
int y = -1;
|
||||
int z = 34;
|
||||
uint x2 = 4294967295;
|
||||
|
||||
return float4(x >> y, x >> z, x2 >> y, x2 >> z);
|
||||
}
|
||||
|
||||
[test]
|
||||
draw quad
|
||||
probe all rgba (0.0, 536870912.0, 1.0, 1073741824.0)
|
||||
|
||||
[pixel shader]
|
||||
float4 main() : SV_TARGET
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user