[Mesa-dev] GLSL swizzle lowering

Luca Barbieri luca at luca-barbieri.com
Tue Aug 31 13:55:27 PDT 2010


With Cg toolkit 2.1, it prints this:
test.glsl(6) : error C1011: cannot index a non-array value

With Cg toolkit 3.0, it works, but produces a mess in any profile,
which seems among the worst ways you could imagine of doing this.
Perhaps the feature is infrequently used, so they didn't bother to
optimize for it at all (and didn't even parse it before Fermi,
apparently).

For ARB_fragment_program, it gives this:

$ cgc -O3 -oglsl -profile arbfp1 test.glsl
test.glsl
8 lines, 0 errors.
!!ARBfp1.0
# cgc version 3.0.0007, build date Jul 22 2010
# command line args: -O3 -oglsl -profile arbfp1
# source file: test.glsl
#vendor NVIDIA Corporation
#version 3.0.0.07
#profile arbfp1
#program main
#semantic i
#semantic c
#semantic d
#var float4 gl_FragColor : $vout.COLOR : COL : -1 : 1
#var int i :  : c[0] : -1 : 1
#var float4 c :  : c[1] : -1 : 1
#var float4 d :  :  : -1 : 0
#const c[2] = 0 1 2
PARAM c[3] = { program.local[0..1],
		{ 0, 1, 2 } };
TEMP R0;
TEMP R1;
ABS R0.y, c[0].x;
CMP R1.x, -R0.y, c[2].y, c[2];
MOV R0.zw, c[2].xyyz;
ADD R0.zw, -R0, c[0].x;
ABS R0.zw, R0;
CMP R0.zw, -R0, c[2].x, c[2].y;
MUL R1.y, R1.x, R0.z;
CMP R0.z, -R1.y, c[2].x, R1.x;
CMP R0.y, -R0, R0.x, c[1].x;
MUL R1.x, R1, R0.z;
MUL R0.x, R1, R0.w;
CMP R0.w, -R1.y, c[1].y, R0.y;
CMP R0.y, -R0.x, c[2].x, R0.z;
CMP R0.z, -R0.x, c[1], R0.w;
MUL R0.x, R1, R0.y;
CMP result.color, -R0.x, c[1].w, R0.z;
END
# 16 instructions, 2 R-regs




The GLSL output profile produces this:
void main()
{
    _TMP5 = true;
    _bvec10004 = bvec3(_i == 0, _i == 1, _i == 2);
    if (_bvec10004.x) { // if begin
        _TMP3 = _c.x;
        _TMP5 = false;
    } // end if
    if (_TMP5) { // if begin
        if (_bvec10004.y) { // if begin
            _TMP3 = _c.y;
            _TMP5 = false;
        } // end if
        if (_TMP5) { // if begin
            if (_bvec10004.z) { // if begin
                _TMP3 = _c.z;
                _TMP5 = false;
            } // end if
            if (_TMP5) { // if begin
                _TMP3 = _c.w;
            } // end if
        } // end if
    } // end if
    gl_FragColor = vec4(_TMP3, _TMP3, _TMP3, _TMP3);
    COL0 = gl_FragColor;
} // main end


More information about the mesa-dev mailing list