Skip to content

Instantly share code, notes, and snippets.

@JayFoxRox
Last active September 25, 2015 12:50
Show Gist options
  • Save JayFoxRox/dd6cefaec3822d30a1cc to your computer and use it in GitHub Desktop.
Save JayFoxRox/dd6cefaec3822d30a1cc to your computer and use it in GitHub Desktop.
MESA GLSL Notes
// Ran with MESA_GLSL=dump, "Mesa 11.0.0-devel (git-1bba29e) is supported"
#version 130
uniform vec4 ua;
uniform vec4 ub;
float add(float a, float b) {
#if 1 // GOOD! (Inlined + this is the only one which does vector math!)
return a + b;
#endif
#if 0 // OKISH! (Puts a > 0.0 in a temporary)
float c = mix(a + b, a + b, a > 0.0);
return mix(c, a + b, a > 0.0);
#endif
#if 0 // OKISH! (CSEL)
return mix(a + b, a + b, a > 0.0);
#endif
#if 0 // OKISH! (CSEL, same as before)
return mix(a + b, a + b, greaterThan(a, 0.0));
#endif
#if 0 // BAD! (IF + ASSIGN)
return (a > 0.0) ? a + b : a + b;
#endif
#if 0 // BAD! (IF + ASSIGN)
if (a > 0.0) {
return a + b;
} else {
return a + b;
}
#endif
}
vec4 add4(vec4 va, vec4 vb) {
#if 0 // TESTS
return vec4(add(va.x,vb.x),
add(va.y,vb.y),
add(va.z,vb.z),
add(va.w,vb.w));
#endif
#if 1 // GOOD! (Inlined + vector math)
bvec4 vc = greaterThan(va, vec4(0.0));
return mix(va, vb, vc);
#endif
}
void main()
{
gl_Position = add4(ua,ub);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment