I've created a new branch in git for my new work on the GLSL compiler. I'm basically replacing Michal's compiler back-end with a new one that produces vertex/fragment programs like those of GL_NV/ARB_vertex/fragment_program. With a little additional work, this'll allow running GLSL on hardware which supports vertex/fragment programs.
The stack-oriented interpreter formerly used for running GLSL programs will go away (it's mostly dead now). The current code is FAR from finished. The progs/demos/fplight demo works though. Here's a rough list of things that work: 1. Basic float/vector/matrix arithmetic is pretty much all working. 2. Function calls (all function calls are inlined). 3. if/then/else contructs 4. while/for loops implemented (but untested) 5. Some GL state uniforms Thinks that don't work: 1. user-defined structs 2. arrays 3. texture sampling 4. linking of multiple vertex/fragment sub-programs 5. some constructors 6. tons of stuff I'm forgetting.. Code of interest: slang/slang_codegen.c - this file basically traverses the AST (Abstract Syntax Tree) produced by the parser and produces IR (Intermediate Representation) trees. This should be familiar to anyone who's studied compilers. slang/slang_emit.c - traverses the IR tree and emits vertex/fragment program instructions. slang/slang_link2.c - new linker. Resolves storage of varying vars, uniforms, etc. Here's an example. This fragment shader: //////// test fragment shader uniform vec4 diffuse; uniform vec3 lightPos; uniform vec4 specular; varying vec3 normal; void main() { float dotProd = dot(lightPos, normalize(normal)); dotProd = clamp(dotProd, 0.0, 1.0); if (dotProd > 0.5) gl_FragColor = diffuse * dotProd + specular * pow(dotProd, 20.0); else if (dotProd > 0.4) gl_FragColor = diffuse + diffuse; else gl_FragColor = diffuse; } Compiles into the following fragment program: 0: DP3 TEMP[4].x, INPUT[12], INPUT[12]; 1: RSQ TEMP[2].x, TEMP[4].xxxx; 2: MUL TEMP[1].xyz, INPUT[12], TEMP[2].xxxw; 3: NOP; # __endOfFunc_normalize_102 4: DP3 TEMP[0].x, UNIFORM[7], TEMP[1]; 5: MAX TEMP[3].x, TEMP[0].xxxx, CONST[10]; 6: MIN TEMP[0].x, TEMP[3].xxxx, CONST[11]; 7: NOP; # __endOfFunc_clamp_104 8: SGT.C TEMP[5], TEMP[0].xxxx, CONST[12]; 9: BRA 15 (EQ..xxxx); # __else105 10: MUL TEMP[6], UNIFORM[8], TEMP[0].xxxx; 11: POW TEMP[7].x, TEMP[0].xxxx, CONST[13]; 12: MUL TEMP[8], UNIFORM[9], TEMP[7].xxxx; 13: ADD OUTPUT[0], TEMP[6], TEMP[8]; 14: BRA 23 (TR.); # __endif106 15: NOP; # __else105 16: SGT.C TEMP[9], TEMP[0].xxxx, CONST[14]; 17: BRA 20 (EQ..xxxx); # __else110 18: ADD OUTPUT[0], UNIFORM[8], UNIFORM[8]; 19: BRA 22 (TR.); # __endif111 20: NOP; # __else110 21: MOV OUTPUT[0], UNIFORM[8]; 22: NOP; # __endif111 23: NOP; # __endif106 24: NOP; # __endOfFunction_Main100 25: END; The quality of the generated code is actually pretty decent at this point (ignore the NOPs). Though, I've made almost no attempt at minimizing temporary usage (some relatively simple programs blow up simply because they use too many temps.) And at some point I'd like to add a BURG-style code generator to do optimizations (like finding places for MAD instructions, etc) but that's a ways off. Anyway, there's probably enough there for people to tinker with. But please keep in mind that it's a work in progress. I'll be on vacation Dec 22 - Jan 2 and don't know how much progress I'll make during that time. -Brian ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Mesa3d-dev mailing list Mesa3d-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mesa3d-dev