gecko-dev/third_party/rust/glslopt
Jamie Nicol abab286bf9 Bug 1689316 - Update glslopt to optimize shader switch statements in to fewer ifs. r=jrmuizel
We have encountered issues on some platforms due to a large number of
if statements in shaders. The shader optimizer previously generated
code with a large number of if statements, due to the way in which it
optimized switch statements.

Previously the optimizer output 2 if statements for every case in a
switch. First it ORs the "fallthrough" var with the case's
condition. Then sets the fallthrough var to false if the "break" var
is true. Then conditionally executes the case's instructions if
fallthrough is true. For example:

  switch (uMode) {
    case 0:
      gl_Position = vec4(0.0);
      break;
    case 1:
      gl_Position = vec4(1.0);
      break;
  }

becomes:

  bool break_var = bool(0);
  bool fallthrough_var = (0 == uMode);
  if (break_var) fallthrough_var = bool(0);
  if (fallthrough_var) {
    gl_Position = vec4(0.0, 0.0, 0.0, 0.0);
    break_var = bool(1);
  };
  fallthrough_var = (fallthrough_var || (1 == uMode));
  if (break_var) fallthrough_var = bool(0);
  if (fallthrough_var) {
    gl_Position = vec4(1.0, 1.0, 1.0, 1.0);
    break_var = bool(1);
  };

This update removes one of these ifs, by ANDing the fallthrough_var
with !break_var rather than conditionally setting it to false. eg:

  bool break_var = bool(0);
  bool fallthrough_var = (0 == uMode);
  if (fallthrough_var) {
    gl_Position = vec4(0.0, 0.0, 0.0, 0.0);
    break_var = bool(1);
  };
  fallthrough_var = (fallthrough_var || (1 == uMode));
  fallthrough_var = (fallthrough_var && !(break_var));
  if (fallthrough_var) {
    gl_Position = vec4(1.0, 1.0, 1.0, 1.0);
    break_var = bool(1);
  };

This is logically equivalent but uses half as many if statements,
which helps to avoid driver bugs on some platforms.

Differential Revision: https://phabricator.services.mozilla.com/D103713
2021-02-01 21:14:15 +00:00
..
glsl-optimizer Bug 1689316 - Update glslopt to optimize shader switch statements in to fewer ifs. r=jrmuizel 2021-02-01 21:14:15 +00:00
src
.cargo-checksum.json Bug 1689316 - Update glslopt to optimize shader switch statements in to fewer ifs. r=jrmuizel 2021-02-01 21:14:15 +00:00
Cargo.toml Bug 1689316 - Update glslopt to optimize shader switch statements in to fewer ifs. r=jrmuizel 2021-02-01 21:14:15 +00:00
README.md Bug 1637148 - Update glslopt to fix intermittent build error. r=lsalzman 2020-07-29 15:12:38 +00:00
build.rs Bug 1661045 - Update glslopt to fix build on OpenBSD. r=lsalzman 2020-08-26 14:13:11 +00:00
wrapper.hpp

README.md

glslopt-rs

Rust bindings to glsl-optimizer.

Updating glsl-optimizer

To update the version of glsl-optimizer, update the git submodule:

git submodule update --remote glsl-optimizer

Then, if required, regenerate the bindings:

cargo install bindgen
bindgen wrapper.hpp -o src/bindings.rs

Then commit the changes.