Skip to content

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.

For example, we can now simplify x * 2 + (3 + 3 * x) to x * 5 + 3, and (x & 4) | (x & 1) to x & 5.

Edited by Shaun Ren

Merge request reports

Loading