diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index b681b2d3..3e8c3fc1 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -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; diff --git a/tests/hlsl/bitwise.shader_test b/tests/hlsl/bitwise.shader_test index 08f02105..20a9db55 100644 --- a/tests/hlsl/bitwise.shader_test +++ b/tests/hlsl/bitwise.shader_test @@ -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 {