[Mesa-dev] [RFC] GL fixed function fragment shaders

Eric Anholt eric at anholt.net
Wed Jan 12 14:04:50 PST 2011


This is a work-in-progress patch series to switch texenvprogram.c from
generating ARB_fp style Mesa IR to generating GLSL IR as its product.
For drivers without native GLSL codegen, that is then turned into the
Mesa IR that can be consumed.  However, for 965 we don't use the Mesa
IR product and just use the GLSL output, producing much better code
thanks to the new backend.  This is part of a long term goal to get
Mesa drivers off of Mesa IR and producing their instruction stream
directly from the GLSL IR.

I'm not planning on committing this series immediately, as I've still
got a regression in the 965 driver with texrect-many on the last
commit.

As a comparison, here's one of the shaders from openarena before:

wm-native:
add(16)         g10<1>UW        g1.4<2,4,0>UW   0x10101010V     { align1 };
add(16)         g12<1>UW        g1.5<2,4,0>UW   0x11001100V     { align1 };
add(16)         g14<1>F         g10<8,8,1>UW    -g1<0,1,0>F     { align1 compr };
add(16)         g16<1>F         g12<8,8,1>UW    -g1.1<0,1,0>F   { align1 compr };
line(16)        null            g3.4<0,1,0>F    g14<8,8,1>F     { align1 compr };
mac(16)         m2<1>F          g3.5<0,1,0>F    g16<8,8,1>F     { align1 compr };
send(8) 2       g10<1>F         null
                math inv mlen 1 rlen 1                          { align1 };
send(8) 3       g11<1>F         null
                math inv mlen 1 rlen 1                          { align1 sechalf };
line(16)        null            g6<0,1,0>F      g14<8,8,1>F     { align1 compr };
mac(16)         g2<1>F          g6.1<0,1,0>F    g16<8,8,1>F     { align1 compr };
line(16)        null            g6.4<0,1,0>F    g14<8,8,1>F     { align1 compr };
mac(16)         g12<1>F         g6.5<0,1,0>F    g16<8,8,1>F     { align1 compr };
mul(16)         m2<1>F          g2<8,8,1>F      g10<8,8,1>F     { align1 compr };
mul(16)         g12<1>F         g12<8,8,1>F     g10<8,8,1>F     { align1 compr };
line(16)        null            g8<0,1,0>F      g14<8,8,1>F     { align1 compr };
mac(16)         g6<1>F          g8.1<0,1,0>F    g16<8,8,1>F     { align1 compr };
line(16)        null            g8.4<0,1,0>F    g14<8,8,1>F     { align1 compr };
mac(16)         g18<1>F         g8.5<0,1,0>F    g16<8,8,1>F     { align1 compr };
mul(16)         g6<1>F          g6<8,8,1>F      g10<8,8,1>F     { align1 compr };
mul(16)         g18<1>F         g18<8,8,1>F     g10<8,8,1>F     { align1 compr };
line(16)        null            g4<0,1,0>F      g14<8,8,1>F     { align1 compr };
mac(16)         g8<1>F          g4.1<0,1,0>F    g16<8,8,1>F     { align1 compr };
line(16)        null            g4.4<0,1,0>F    g14<8,8,1>F     { align1 compr };
mac(16)         g20<1>F         g4.5<0,1,0>F    g16<8,8,1>F     { align1 compr };
line(16)        null            g5<0,1,0>F      g14<8,8,1>F     { align1 compr };
mac(16)         g22<1>F         g5.1<0,1,0>F    g16<8,8,1>F     { align1 compr };
line(16)        null            g5.4<0,1,0>F    g14<8,8,1>F     { align1 compr };
mac(16)         g24<1>F         g5.5<0,1,0>F    g16<8,8,1>F     { align1 compr };
mul(16)         g8<1>F          g8<8,8,1>F      g10<8,8,1>F     { align1 compr };
mul(16)         g20<1>F         g20<8,8,1>F     g10<8,8,1>F     { align1 compr };
mul(16)         g22<1>F         g22<8,8,1>F     g10<8,8,1>F     { align1 compr };
mul(16)         g24<1>F         g24<8,8,1>F     g10<8,8,1>F     { align1 compr };
mov(16)         m4<1>F          g12<8,8,1>F                     { align1 compr };
mov(8)          m1<1>UD         g0<8,8,1>UD                     { align1 nomask };
mov(1)          m1.2<1>UD       0x00008000UD                    { align1 nomask };
send(16) 1      g26<1>UW        null
                sampler (9, 0, 0, 2) mlen 5 rlen 6              { align1 };
mov(16)         m2<1>F          g6<8,8,1>F                      { align1 compr };
mov(16)         m4<1>F          g18<8,8,1>F                     { align1 compr };
mov(8)          m1<1>UD         g0<8,8,1>UD                     { align1 nomask };
mov(1)          m1.2<1>UD       0x00008000UD                    { align1 nomask };
send(16) 1      g10<1>UW        null
                sampler (10, 1, 0, 2) mlen 5 rlen 6             { align1 };
mul(16)         g2<1>F          g26<8,8,1>F     g8<8,8,1>F      { align1 compr };
mul(16)         g4<1>F          g28<8,8,1>F     g20<8,8,1>F     { align1 compr };
mul(16)         g6<1>F          g30<8,8,1>F     g22<8,8,1>F     { align1 compr };
add.sat(16)     g8<1>F          g10<8,8,1>F     g2<8,8,1>F      { align1 compr };
add.sat(16)     g16<1>F         g12<8,8,1>F     g4<8,8,1>F      { align1 compr };
add.sat(16)     g18<1>F         g14<8,8,1>F     g6<8,8,1>F      { align1 compr };
mov(16)         m2<1>F          g8<8,8,1>F                      { align1 compr4 };
mov(16)         m3<1>F          g16<8,8,1>F                     { align1 compr4 };
mov(16)         m4<1>F          g18<8,8,1>F                     { align1 compr4 };
mov(16)         m5<1>F          g24<8,8,1>F                     { align1 compr4 };
mov(8)          m1<1>F          g1<8,8,1>F                      { align1 nomask };
send(16) 0      null            g0<8,8,1>UW
                write (0, 8, 4, 0) mlen 10 rlen 0               { align1 EOT };
(54 instructions)

and after:
Native code for fragment shader 0:
   compute pixel centers
add(8)          g10<1>UW        g1.4<2,4,0>UW   0x10101010V     { align1 };
add(8)          g11<1>UW        g1.5<2,4,0>UW   0x11001100V     { align1 };
   compute pixel deltas from v0
add(8)          g12<1>F         g10<8,8,1>UW    -g1<0,1,0>F     { align1 };
add(8)          g13<1>F         g11<8,8,1>UW    -g1.1<0,1,0>F   { align1 };
   compute pos.w and 1/pos.w
pln(8)          g10<1>F         g3.4<0,1,0>F    g12<8,8,1>F     { align1 };
send(8) 2       g10<1>F         g10<8,8,1>F
                math inv mlen 1 rlen 1                          { align1 };
   (declare (in ) vec4 gl_Color at 0x9ffe278)
pln(8)          g11<1>F         g4<0,1,0>F      g12<8,8,1>F     { align1 };
pln(8)          g16<1>F         g4.4<0,1,0>F    g12<8,8,1>F     { align1 };
pln(8)          g17<1>F         g5<0,1,0>F      g12<8,8,1>F     { align1 };
pln(8)          g14<1>F         g5.4<0,1,0>F    g12<8,8,1>F     { align1 };
mul(8)          g11<1>F         g11<8,8,1>F     g10<8,8,1>F     { align1 };
mul(8)          g16<1>F         g16<8,8,1>F     g10<8,8,1>F     { align1 };
mul(8)          g17<1>F         g17<8,8,1>F     g10<8,8,1>F     { align1 };
mul(8)          m5<1>F          g14<8,8,1>F     g10<8,8,1>F     { align1 };
   (declare (in ) (array vec4 2) gl_TexCoord at 0x9fe8e10)
pln(8)          g14<1>F         g6<0,1,0>F      g12<8,8,1>F     { align1 };
pln(8)          g15<1>F         g6.4<0,1,0>F    g12<8,8,1>F     { align1 };
pln(8)          g18<1>F         g7.4<0,1,0>F    g12<8,8,1>F     { align1 };
mul(8)          g14<1>F         g14<8,8,1>F     g10<8,8,1>F     { align1 };
mul(8)          g15<1>F         g15<8,8,1>F     g10<8,8,1>F     { align1 };
mul(8)          g18<1>F         g18<8,8,1>F     g10<8,8,1>F     { align1 };
pln(8)          g19<1>F         g8<0,1,0>F      g12<8,8,1>F     { align1 };
pln(8)          g20<1>F         g8.4<0,1,0>F    g12<8,8,1>F     { align1 };
pln(8)          g21<1>F         g9.4<0,1,0>F    g12<8,8,1>F     { align1 };
mul(8)          g19<1>F         g19<8,8,1>F     g10<8,8,1>F     { align1 };
mul(8)          g20<1>F         g20<8,8,1>F     g10<8,8,1>F     { align1 };
mul(8)          g21<1>F         g21<8,8,1>F     g10<8,8,1>F     { align1 };
   (assign (constant bool (1)) (x) (var_ref projector at 0x9ffe3c8)  (expression float rcp (swiz w (array_ref (var_ref gl_TexCoord at 0x9fe8e10) (constant uint (0)) ) )) ) 
send(8) 2       g10<1>F         g18<8,8,1>F
                math inv mlen 1 rlen 1                          { align1 };
   (assign (constant bool (1)) (x) (var_ref flattening_tmp at 0x9fb9450)  (expression float * (swiz x (var_ref channel_expressions at 0x9ffd990) )(var_ref projector at 0x9ffe3c8) ) ) 
mul(8)          m2<1>F          g14<8,8,1>F     g10<8,8,1>F     { align1 };
   (assign (constant bool (1)) (y) (var_ref flattening_tmp at 0x9fb9450)  (expression float * (swiz y (var_ref channel_expressions at 0x9ffd990) )(var_ref projector at 0x9ffe3c8) ) ) 
mul(8)          m3<1>F          g15<8,8,1>F     g10<8,8,1>F     { align1 };
   (assign (constant bool (1)) (xyzw) (var_ref channel_expressions at 0x9fb7510)  (tex (var_ref sampler_0 at 0x9fbb280)  (var_ref flattening_tmp at 0x9fb9450)  (1 0 0) 1 () )) 
send(8) 1       g12<1>UW        g0<8,8,1>UW
                sampler (9, 0, 0, 1) mlen 3 rlen 4              { align1 };
   (assign (constant bool (1)) (x) (var_ref flattening_tmp at 0x9fb95a8)  (expression float * (swiz x (var_ref channel_expressions at 0x9fb7510) )(swiz x (var_ref gl_Color at 0x9ffe278) )) ) 
mul(8)          g10<1>F         g12<8,8,1>F     g11<8,8,1>F     { align1 };
   (assign (constant bool (1)) (y) (var_ref flattening_tmp at 0x9fb95a8)  (expression float * (swiz y (var_ref channel_expressions at 0x9fb7510) )(swiz y (var_ref gl_Color at 0x9ffe278) )) ) 
mul(8)          g11<1>F         g13<8,8,1>F     g16<8,8,1>F     { align1 };
   (assign (constant bool (1)) (z) (var_ref flattening_tmp at 0x9fb95a8)  (expression float * (swiz z (var_ref channel_expressions at 0x9fb7510) )(swiz z (var_ref gl_Color at 0x9ffe278) )) ) 
mul(8)          g12<1>F         g14<8,8,1>F     g17<8,8,1>F     { align1 };
   (assign (constant bool (1)) (x) (var_ref projector at 0x9fb9238)  (expression float rcp (swiz w (array_ref (var_ref gl_TexCoord at 0x9fe8e10) (constant uint (1)) ) )) ) 
send(8) 2       g13<1>F         g21<8,8,1>F
                math inv mlen 1 rlen 1                          { align1 };
   (assign (constant bool (1)) (x) (var_ref flattening_tmp at 0x9fb9748)  (expression float * (swiz x (var_ref channel_expressions at 0x9fb6e00) )(var_ref projector at 0x9fb9238) ) ) 
mul(8)          m2<1>F          g19<8,8,1>F     g13<8,8,1>F     { align1 };
   (assign (constant bool (1)) (y) (var_ref flattening_tmp at 0x9fb9748)  (expression float * (swiz y (var_ref channel_expressions at 0x9fb6e00) )(var_ref projector at 0x9fb9238) ) ) 
mul(8)          m3<1>F          g20<8,8,1>F     g13<8,8,1>F     { align1 };
   (assign (constant bool (1)) (xyzw) (var_ref channel_expressions at 0x9fb61c0)  (tex (var_ref sampler_1 at 0x9fbb220)  (var_ref flattening_tmp at 0x9fb9748)  (0 0 0) 1 () )) 
send(8) 1       g13<1>UW        g0<8,8,1>UW
                sampler (10, 1, 0, 1) mlen 3 rlen 4             { align1 };
   (assign (constant bool (1)) (x) (var_ref flattening_tmp at 0x9fb98e8)  (expression float + (swiz x (var_ref channel_expressions at 0x9fb61c0) )(swiz x (var_ref texenv_combine at 0x9fe8f38) )) ) 
add.sat(8)      m2<1>F          g13<8,8,1>F     g10<8,8,1>F     { align1 };
   (assign (constant bool (1)) (y) (var_ref flattening_tmp at 0x9fb98e8)  (expression float + (swiz y (var_ref channel_expressions at 0x9fb61c0) )(swiz y (var_ref texenv_combine at 0x9fe8f38) )) ) 
add.sat(8)      m3<1>F          g14<8,8,1>F     g11<8,8,1>F     { align1 };
   (assign (constant bool (1)) (z) (var_ref flattening_tmp at 0x9fb98e8)  (expression float + (swiz z (var_ref channel_expressions at 0x9fb61c0) )(swiz z (var_ref texenv_combine at 0x9fe8f38) )) ) 
add.sat(8)      m4<1>F          g15<8,8,1>F     g12<8,8,1>F     { align1 };
   (assign (constant bool (1)) (w) (var_ref gl_FragColor at 0x9ffe1d0)  (swiz w (var_ref texenv_combine at 0x9fe8f38) )) 
   FB write target 0
mov(8)          m1<1>F          g1<8,8,1>F                      { align1 nomask };
send(8) 0       null            g0<8,8,1>UW
                write (0, 12, 4, 0) mlen 6 rlen 0               { align1 EOT };
(41 instructions)



More information about the mesa-dev mailing list