laurentlb / shader-minifier

Minify and obfuscate GLSL or HLSL code
https://ctrl-alt-test.fr/minifier/
Apache License 2.0
454 stars 34 forks source link

More function inlining #470

Open therontarigo opened 2 weeks ago

therontarigo commented 2 weeks ago

It should (in some circumstances) be possible to inline a function that follows these rules:

eldritchconundrum commented 2 weeks ago

Inlining is not that simple. There are many potential issues to tackle.

laurentlb commented 2 weeks ago

A difficulty is to handle variables correctly, even with shadowing (renaming might be required).

If the function return value is used, it can be difficult to inline it (and do side-effects in the correct order).

int f() {
  for (...) { ... }
  return ...;
} 

void main() {
  int a = g() + f();
}

To inline f() here, you might need to introduce new local variables and split the line.

therontarigo commented 2 weeks ago

I reopened #469 , as it is the only one with a chance of being easy to implement.

therontarigo commented 2 weeks ago

I was thinking that it is an unnecessary restriction in the case that the function is called in a simple assignment statement: float x = func(...); However, considering more carefully what the resulting minified code would be, there's no case for that where return-by-inout wouldn't work just as well. So that's one more reason to abandon this and focus on #469 .