Hi, I noticed that GLSL compiler sometimes produces different code for the same shader source, e.g.:
Vertex shader source: > gl_Position = gl_Vertex; > gl_FrontColor = gl_Vertex; GLSL IR: > (assign (xyzw) (var_ref gl_Position) (var_ref gl_Vertex) ) > (assign (xyzw) (var_ref gl_FrontColor) (var_ref gl_Vertex) ) > (assign (xyzw) (var_ref gl_Position@2) (var_ref gl_Position) ) > (assign (xyzw) (var_ref gl_FrontColor@3) (var_ref gl_FrontColor) ) Another variant has another order of the last two assignments: > (assign (xyzw) (var_ref gl_FrontColor@4) (var_ref gl_FrontColor) ) > (assign (xyzw) (var_ref gl_Position@5) (var_ref gl_Position) ) Both variants are correct, but it makes the debugging harder - e.g. one of the variants uncovers the bug in my code, and it's hard to reproduce it. I guess we might want to remove the dependency on the moon phase etc, and maybe provide some way to control it for debugging. My knowledge of the GLSL compiler is still not good enough to fix it quickly, so I'd be grateful if somebody could help. There is the reduced test program in the attachment that demonstrates the problem. It compiles the shader every second, so running it with the following command line usually shows both variants during the first 10 seconds: > MESA_GLSL=dump ./test | grep -A 20 linked Vadim
#include <GL/gl.h> #include <GL/glut.h> #include <string.h> char * vs = "void main()" "{" " gl_Position = gl_Vertex;" " gl_FrontColor = gl_Vertex;" "}"; void create_shader() { GLuint v = glCreateShader(GL_VERTEX_SHADER); GLint l = strlen(vs); glShaderSource(v, 1, &vs, &l); glCompileShader(v); GLuint p = glCreateProgram(); glAttachShader(p,v); glLinkProgram(p); glUseProgram(p); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize (250, 250); glutCreateWindow ("Test"); while (1) { create_shader(); sleep(1); } return 0; }
_______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev