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

@@ -52,3 +52,19 @@ float4 main() : SV_TARGET
[test]
draw quad
probe (0, 0) rgba (0.0, 0.0, 0.0, 0.0)
% Test expression normalization and simplification.
[pixel shader]
uniform uint4 x;
float4 main() : SV_TARGET
{
return 6 + (2 * x * 3) - 5;
}
[test]
uniform 0 uint4 0 1 2 3
todo(msl) draw quad
probe (0, 0) rgba (1.0, 7.0, 13.0, 19.0)