Open Source Cg compiler adventures

Member
Posts: 45
Joined: 2006.11
Post: #1
After about an hour of code tinkering, I actually got the open source Cg compiler released by NVidia to compile on MacOS X 10.2.
Someone should have checked the code before they released it, since typos and errors are frequent in the code, but mostly it was ok. There were actually two programs included with the source code, and they shared header files. This confused me at first, before reading the Makefile to see which files went to which program. There's the cgc program and a program called tokenize, which has no explanation in the readme file (or even mention). I got both to compile, though tokenize dereferences a null pointer towards the beginning and crashes. Finally, the cgc compiler, with the generic profile, does not even compile the example Cg files it comes bundled with. This, even after converting them to Unix text. I believe that this has something to do with the tokenize program, but as it has no documentation and it's not immediately obvious to me how to fix its null pointer problem, I have no idea what it does or how it works.... Oh... and the compiler has no backend profiles for any kind of shader language.
Here is the output of the cgc compiler after attempting to compile one of the included example Cg files:
Code:
# Generic output by Cg compiler
// cgc version 1.1.0000, build date 09/14/02  21:52:23
// command line args: -profile generic /Users/bellj/Desktop/opensrc/reflection.cg
/Users/bellj/Desktop/opensrc/reflection.cg(17) : error C0000: parse error at token "float4x4"
/Users/bellj/Desktop/opensrc/reflection.cg(17) : error C0501: type name expected at token "float4x4"
/Users/bellj/Desktop/opensrc/reflection.cg(18) : error C0000: parse error at token "float4x4"
/Users/bellj/Desktop/opensrc/reflection.cg(18) : error C0501: type name expected at token "float4x4"
/Users/bellj/Desktop/opensrc/reflection.cg(27) : error C1008: undefined variable "float3x3"
/Users/bellj/Desktop/opensrc/reflection.cg(27) : error C0000: parse error at token "m3"
/Users/bellj/Desktop/opensrc/reflection.cg(27) : error C0501: type name expected at token "m3"
/Users/bellj/Desktop/opensrc/reflection.cg(30) : error C1008: undefined variable "mul"
/Users/bellj/Desktop/opensrc/reflection.cg(30) : error C1008: undefined variable "modelview_matrix"
/Users/bellj/Desktop/opensrc/reflection.cg(30) : error C1008: undefined variable "I"
/Users/bellj/Desktop/opensrc/reflection.cg(30) : error C1048: invalid character 'p' in swizzle "position"
/Users/bellj/Desktop/opensrc/reflection.cg(30) : error C1105: cannot call a non-function
/Users/bellj/Desktop/opensrc/reflection.cg(33) : error C1008: undefined variable "normalize"
/Users/bellj/Desktop/opensrc/reflection.cg(33) : error C1105: cannot call a non-function
/Users/bellj/Desktop/opensrc/reflection.cg(38) : error C1048: invalid character '_' in swizzle "_m00_m01_m02"
/Users/bellj/Desktop/opensrc/reflection.cg(38) : error C1048: invalid character '_' in swizzle "_m00_m01_m02"
/Users/bellj/Desktop/opensrc/reflection.cg(39) : error C1048: invalid character '_' in swizzle "_m10_m11_m12"
/Users/bellj/Desktop/opensrc/reflection.cg(39) : error C1048: invalid character '_' in swizzle "_m10_m11_m12"
/Users/bellj/Desktop/opensrc/reflection.cg(40) : error C1048: invalid character '_' in swizzle "_m20_m21_m22"
/Users/bellj/Desktop/opensrc/reflection.cg(40) : error C1048: invalid character '_' in swizzle "_m20_m21_m22"
/Users/bellj/Desktop/opensrc/reflection.cg(41) : error C1048: invalid character 'n' in swizzle "normal"
/Users/bellj/Desktop/opensrc/reflection.cg(41) : error C1105: cannot call a non-function
/Users/bellj/Desktop/opensrc/reflection.cg(44) : error C1008: undefined variable "dot"
/Users/bellj/Desktop/opensrc/reflection.cg(44) : error C1105: cannot call a non-function
/Users/bellj/Desktop/opensrc/reflection.cg(44) : error C1022: operands to "*" must be numeric
/Users/bellj/Desktop/opensrc/reflection.cg(44) : error C1022: operands to "-" must be numeric
/Users/bellj/Desktop/opensrc/reflection.cg(48) : error C1008: undefined variable "rsqrt"
/Users/bellj/Desktop/opensrc/reflection.cg(48) : error C1105: cannot call a non-function
/Users/bellj/Desktop/opensrc/reflection.cg(48) : error C1105: cannot call a non-function
/Users/bellj/Desktop/opensrc/reflection.cg(48) : error C1022: operands to "*" must be numeric
/Users/bellj/Desktop/opensrc/reflection.cg(54) : error C1105: cannot call a non-function


nice. Am I missing something?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Quote:Am I missing something?

Yeah... a hefty dose of cynicism about NVidia's good will and the benefits of them "open-sourcing" their compiler...
Quote this message in a reply
Member
Posts: 45
Joined: 2006.11
Post: #3
Someone informed me that the tokenize program must be run before cgc will be able to compile programs, but I'm going to have to fix the NULL pointer error before it will work. I'll also have to make sure there aren't any other errors NVidia left in the code. Would someone like to collaberate with me on this effort? I have relatively little experience with porting things from other platforms, and could use some help trying to figure out what the NVidia programmers intended the code to do. Once that is done, we can work on adding some Mac specific backends, and maybe even a Cocoa based GUI for the compiler. Or, if possible, adding Cg support to Shader Builder?
Quote this message in a reply
henryj
Unregistered
 
Post: #4
A couple of things...

1. cg is the work of the devil. May it burn in hellSmile

2. This is a big job and from what I have read (which isn't much 'cause I tend to avoid devil worship) you then have to write the compiler. All they've given away is the front end.

3. nVidia aren't actually interested in anyone using this. It's a marketing exercise, hence the broken code. Either that or they used Visual Studio, which amounts to the same thing.
Quote this message in a reply
Member
Posts: 45
Joined: 2006.11
Post: #5
Well, it turns out there was a little mishap with the order things had to be done in the build process. Tokenize must be built first. tokenize shares some header files with cgc, but defines a few functions differently. I had to figure out which files should not be included in the tokenize target so that a symbol conflict didn't occur. This solved the null pointer problem with the tokenize app. Next, you must use the tokenize app to build stdlib.c out of stdlib.cg. Then, you have to include stdlib.c in the project for cgc. And then it compiles, and works! Yay!


Now, how to go about making an ARB_Vertex_Program profile....
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Compiler error JeroMiya 6 4,784 Sep 25, 2002 11:03 PM
Last Post: henryj
  BSP tree compiler ClarustheDogCow 3 3,723 Jul 4, 2002 09:30 AM
Last Post: ClarustheDogCow