vkd3d-shader/hlsl: Collect together terms with constant coefficients.

We apply distributivity to applicable expressions, specifically with
the following rewrite rules:

  (x OPL a) OPR (x OPL b) -> x OPL (a OPR b)
  (y OPR (x OPL a)) OPR (x OPL b) -> y OPR (x OPL (a OPR b))
  ((x OPL a) OPR y) OPR (x OPL b) -> (x OPL (a OPR b)) OPR y
  (x OPL a) OPR ((x OPL b) OPR y) -> (x OPL (a OPR b)) OPR y
  (x OPL a) OPR (y OPR (x OPL b)) -> (x OPL (a OPR b)) OPR y

where a, b are constants.
This commit is contained in:
Shaun Ren
2024-12-11 11:30:34 -05:00
committed by Henri Verbeet
parent b60995b106
commit 646087d54c
Notes: Henri Verbeet 2025-01-10 20:14:25 +01:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1314
2 changed files with 124 additions and 3 deletions

View File

@@ -68,3 +68,23 @@ float4 main() : SV_TARGET
uniform 0 uint4 0 1 2 3
todo(msl) draw quad
probe (0, 0) rgba (1.0, 7.0, 13.0, 19.0)
% Test collecting terms with constant coefficients.
[pixel shader]
uniform uint x;
float4 main() : SV_TARGET
{
uint4 res;
res.x = x * 2 + (3 + 3 * x);
res.y = (x & 4) | (x & 1);
res.z = max(min(2, x), min(x, 10));
res.w = 0;
return res;
}
[test]
uniform 0 uint 7
todo(msl) draw quad
probe (0, 0) rgba(38.0, 5.0, 7.0, 0.0)