[Mesa-dev] GLSL compiler produces different code for the same source

Vadim Girlin vadimgirlin at gmail.com
Fri Mar 30 14:11:43 PDT 2012


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 at 2)  (var_ref gl_Position) ) 
>       (assign  (xyzw) (var_ref gl_FrontColor at 3)  (var_ref gl_FrontColor) ) 

Another variant has another order of the last two assignments:

>       (assign  (xyzw) (var_ref gl_FrontColor at 4)  (var_ref gl_FrontColor) ) 
>       (assign  (xyzw) (var_ref gl_Position at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: glsl_uncertain_order.c
Type: text/x-csrc
Size: 623 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20120331/0e292f94/attachment.c>


More information about the mesa-dev mailing list