vkd3d-shader/hlsl: Implement normalization of binary expressions.

We normalize binary expressions by attempting to group constants
together, in order to facilitate further simplification of the
expressions.

For any binary operator OP, non-constants x, y, and constants a, b, we
apply the following rewrite rules:

  a OP x -> x OP a, if OP is commutative.

  (x OP a) OP b -> x OP (a OP b), if OP is associative.

  (x OP a) OP y -> (x OP y) OP a, if OP is associative and commutative.

  x OP (y OP a) -> (x OP y) OP a, if OP is associative.

Note that we consider floating point operations to be
non-associative.
This commit is contained in:
Shaun Ren
2024-12-06 17:07:13 -05:00
committed by Henri Verbeet
parent 65b67e84a8
commit 2c9cf7c78b
Notes: Henri Verbeet 2024-12-11 15:37:25 +01:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1307
4 changed files with 161 additions and 0 deletions

View File

@@ -6569,6 +6569,7 @@ void hlsl_run_const_passes(struct hlsl_ctx *ctx, struct hlsl_block *body)
{
progress = hlsl_transform_ir(ctx, hlsl_fold_constant_exprs, body, NULL);
progress |= hlsl_transform_ir(ctx, hlsl_fold_constant_identities, body, NULL);
progress |= hlsl_transform_ir(ctx, hlsl_normalize_binary_exprs, body, NULL);
progress |= hlsl_transform_ir(ctx, hlsl_fold_constant_swizzles, body, NULL);
progress |= hlsl_copy_propagation_execute(ctx, body);
progress |= hlsl_transform_ir(ctx, fold_swizzle_chains, body, NULL);