Shader_Minifier icon indicating copy to clipboard operation
Shader_Minifier copied to clipboard

Inlining vs inout

Open therontarigo opened this issue 11 months ago • 6 comments

When inlining a function, Minifier behaves as though all parameters are qualified inout.

Contrived example reproducing the bug:

out vec4 O;
float i_func(float p) {
  return p-=2.,p*p;
}
void main() {
  float x=gl_FragCoord.x;
  O.x=i_func(x);
  O.y=x;
}
out vec4 v;
void main()
{
  float x=gl_FragCoord.x;
  v.x=(x-=2.,x*x);
  v.y=x;
}

With the current single-expression-only inlining, this hasn't been an issue in practice. However it is likely to come up if allowing #470 . The simplest fix is to enforce a rule: Every parameter declaration of a function to be inlined must be either qualified inout or used immutably (no assignments).

therontarigo avatar Nov 07 '24 00:11 therontarigo