CG Compiler Code Released!

alexsok

Regular
http://developer.nvidia.com/view.asp?IO=cg_compiler_code

This release provides the source code for the Cg compiler (cgc.exe) with a "generic" profile, which does some minimal semantic checks and prints out a tree representation of the code. It can be built either with the included Microsoft Visual C++ 6.0 projects and workspace, or with the included Makefile. The release also includes examples, along with a detailed description of the release contents in the Readme.txt file.

Please make sure to look through the accompanying license.txt file before working with the provided code.
 
EEeerrrrr... and what is this output supposed to be :

Code:
{
B   - 4 5 assignv  float[4]
    B L - - - mselect  float[4]
        S L - - - var    "I" struct appdata
        S L - - - member "position" float[4]
    B L - - - mselect  float[4]
        S L - - - var    "$vin" struct $vin
        S L - - - member "ATTRIB0" float[4]
B   - 3 5 assignv  float[3]
    B L - - - mselect  float[3]
        S L - - - var    "I" struct appdata
        S L - - - member "normal" float[3]
    B L - - - mselect  float[3]
        S L - - - var    "$vin" struct $vin
        S L - - - member "ATTRIB1" float[3]
B   - 4 5 assignv  float[4]
    S L - - - var    "v" float[4]
    B   - - - call    float[4]
        S L - - - var    "mul" (float[4][4], float[4])
        B L - - - arg     uniform float[4][4]
            S L - - - var    "modelview_matrix" uniform float[4][4]
            B L - - - arg     float[4]
                B L - - - mselect  float[4]
                    S L - - - var    "I" struct appdata
                    S L - - - member "position" float[4]
                NULL
B   - 3 5 assignv  float[3]
    S L - - - var    "u" float[3]
    B   - - - call    float[3]
        S L - - - var    "normalize" (float[3])
        B L - - - arg     float[3]
            U L 3 4 5 swizzle  xyz float[3]
                S L - - - var    "v" float[4]
            NULL
B   - 3 5 assignv  float[3]
    U L 3 3 3 5 swizmat  _00_01_02 float[3]
        S L - - - var    "m3" float[3][3]
    U L 4 3 4 5 swizmat  _00_01_02 float[3]
        S L - - - var    "modelview_matrix" uniform float[4][4]
B   - 3 5 assignv  float[3]
    U L 3 3 3 5 swizmat  _10_11_12 float[3]
        S L - - - var    "m3" float[3][3]
    U L 4 3 4 5 swizmat  _10_11_12 float[3]
        S L - - - var    "modelview_matrix" uniform float[4][4]
B   - 3 5 assignv  float[3]
    U L 3 3 3 5 swizmat  _20_21_22 float[3]
        S L - - - var    "m3" float[3][3]
    U L 4 3 4 5 swizmat  _20_21_22 float[3]
        S L - - - var    "modelview_matrix" uniform float[4][4]
B   - 3 5 assignv  float[3]
    S L - - - var    "n" float[3]
    B   - - - call    float[3]
        S L - - - var    "mul" (float[3][3], float[3])
        B L - - - arg     float[3][3]
            S L - - - var    "m3" float[3][3]
            B L - - - arg     float[3]
                B L - - - mselect  float[3]
                    S L - - - var    "I" struct appdata
                    S L - - - member "normal" float[3]
                NULL
B   - 3 5 assignv  float[3]
    S L - - - var    "r" float[3]
    B   - 3 5 subv    float[3]
        S L - - - var    "u" float[3]
        B   - 3 5 mulvs   float[3]
            B   - 3 5 mulsv   float[3]
                C   - - 5 fconst 2 float
                S L - - - var    "n" float[3]
            B   - - - call    float
                S L - - - var    "dot" (float[3], float[3])
                B L - - - arg     float[3]
                    S L - - - var    "n" float[3]
                    B L - - - arg     float[3]
                        S L - - - var    "u" float[3]
                        NULL
B   - - 5 assign  float
    U L 0 3 5 swizzle  z float
        S L - - - var    "r" float[3]
    B   - - 5 add     float
        U L 0 3 5 swizzle  z float
            S L - - - var    "r" float[3]
        C   - - 5 fconst 1 float
B   - - 5 assign  float
    S L - - - var    "m" float
    B   - - 5 mul     float
        C   - - 5 fconst 0.5 float
        B   - - - builtin  float
            S L - - - var    "rsqrt" (float)
            B   - - - arg     float
                B   - - - call    float
                    S L - - - var    "dot" (float[3], float[3])
                    B L - - - arg     float[3]
                        S L - - - var    "r" float[3]
                        B L - - - arg     float[3]
                            S L - - - var    "r" float[3]
                            NULL
                NULL
B   - - 5 assign  float
    U L 0 4 5 swizzle  x float
        B L - - - mselect  float[4]
            S L - - - var    "O" struct vf20
            S L - - - member "TEX0" float[4]
    B   - - 5 add     float
        B   - - 5 mul     float
            U L 0 3 5 swizzle  x float
                S L - - - var    "r" float[3]
            S L - - - var    "m" float
        C   - - 5 fconst 0.5 float
B   - - 5 assign  float
    U L 0 4 5 swizzle  y float
        B L - - - mselect  float[4]
            S L - - - var    "O" struct vf20
            S L - - - member "TEX0" float[4]
    B   - - 5 add     float
        B   - - 5 mul     float
            U L 0 3 5 swizzle  y float
                S L - - - var    "r" float[3]
            S L - - - var    "m" float
        C   - - 5 fconst 0.5 float
B   - 4 5 assignv  float[4]
    B L - - - mselect  float[4]
        S L - - - var    "O" struct vf20
        S L - - - member "HPOS" float[4]
    B   - - - call    float[4]
        S L - - - var    "mul" (float[4][4], float[4])
        B L - - - arg     uniform float[4][4]
            S L - - - var    "projection_matrix" uniform float[4][4]
            B L - - - arg     float[4]
                S L - - - var    "v" float[4]
                NULL
B   - 4 5 assignv  float[4]
    B L - - - mselect  float[4]
        S L - - - var    "$vout" struct $vout
        S L - - - member "POSITION" float[4]
    B L - - - mselect  float[4]
        S L - - - var    "O" struct vf20
        S L - - - member "HPOS" float[4]
B   - 4 5 assignv  float[4]
    B L - - - mselect  float[4]
        S L - - - var    "$vout" struct $vout
        S L - - - member "COLOR0" float[4]
    B L - - - mselect  float[4]
        S L - - - var    "O" struct vf20
        S L - - - member "COL0" float[4]
B   - 4 5 assignv  float[4]
    B L - - - mselect  float[4]
        S L - - - var    "$vout" struct $vout
        S L - - - member "TEXCOORD0" float[4]
    B L - - - mselect  float[4]
        S L - - - var    "O" struct vf20
        S L - - - member "TEX0" float[4]
}

Anyone ?

G~
 
The output is simply the internal representation of the compiled Cg code.

The IHV would replace the printf's (or cout's) and use it to write their own back end and spit out appropriate code for their device.
 
It's just a serialized printout of the parse tree. To turn generate code, you'd need to minimally construct a control flow graph and do register allocation, although register allocation could be super simple given the number of registers and the unlikelyhood of a conflict in a most shaders.

However, the output won' t be very optimal.
 
I thought they were going to release a default backend outputting default DX code as well ? This looks like a syntax verification and then a tree structure of the program splitting up in instruction and various input/output elements. We are still quite a bit away from an assembler program IMHO.

K-
 
Back
Top