Module: vkd3d Branch: master Commit: 6e74819eb7a3548bcdf581b043677ed2f31eb0de URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/6e74819eb7a3548bcdf581b043677e...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Wed Sep 13 07:29:10 2023 +0200
vkd3d-shader/hlsl: Add constant folding for lshift.
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com
---
libs/vkd3d-shader/hlsl_constant_ops.c | 34 ++++++++++++++++++++++++++++++++++ tests/hlsl/bitwise.shader_test | 15 +++++++++++++++ 2 files changed, 49 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index 3b4c86dc..b681b2d3 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -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; diff --git a/tests/hlsl/bitwise.shader_test b/tests/hlsl/bitwise.shader_test index 55160037..08f02105 100644 --- a/tests/hlsl/bitwise.shader_test +++ b/tests/hlsl/bitwise.shader_test @@ -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 {