#### Archived

This topic is now archived and is closed to further replies.

# Help with Cg

This topic is 5048 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Yeah so I'm a definatly a CG newbie. I'm having some difficulties getting the compiliation to work with DX9 - here's the Cg code - it's fairly simple. ------------------------------------------------------------- struct OutParms { float4 position : POSITION; float4 color : COLOR; }; OutParms main(float2 position : POSITION) { OutParms OUT; OUT.position = float4(position, 0, 1); OUT.color = float4(1, 0, 1, 1); // RGBA green return OUT; } ------------------------------------------------------------- Now I compile this using the command line Cg compiler using the profile settings of vs_1_1 and get ------------------------------------------------------------- vs.1.1 // DX8 Vertex shader generated by NVIDIA Cg compiler // cgc version 1.1.0003, build date Jul 7 2003 11:55:19 // command line args: -entry main -profile vs_1_1 // nv30vp backend compiling 'main' program def c1, 1, 0, 1, 1 def c0, 0, 1, 0, 0 //vendor NVIDIA Corporation //version 1.0.02 //profile vs_1_1 //program main //var float2 position : $vin.POSITION : POSITION : 0 : 1 //var float4 position :$vout.POSITION : POSITION : -1 : 1 //var float4 color : $vout.COLOR : COLOR : -1 : 1 //const c[1] = 1 0 1 1 //const c[0] = 0 1 0 0 mov oPos.xy, v0.xyyy mov oPos.zw, c0.yyxy mov oD0, c1 // 3 instructions // 0 temp registers // End of program ---------------------------------------------------------- Which again is pretty simple. The problem is we're trying to copy the contents of v0, which doesnt look like it has been initialized into oPos. The internal D3DXAssembleShaderFromFile function of course fails and returns an error saying attempting to read from un-initialized variables. I added the line dcl_position v0 Above the mov commands, and I assemble fine. I am not sure what to do. Compiling with vs_2_0 yields --------------------------------------------------------- vs_2_0 // DX9 Vertex shader generated by NVIDIA Cg compiler // cgc version 1.1.0003, build date Jul 7 2003 11:55:19 // command line args: -entry main -profile vs_2_0 // nv30vp backend compiling 'main' program def c1, 1, 0, 1, 1 def c0, 0, 1, 0, 0 //vendor NVIDIA Corporation //version 1.0.02 //profile vs_2_0 //program main //var float2 position :$vin.POSITION : POSITION : 0 : 1 //var float4 position : $vout.POSITION : POSITION : -1 : 1 //var float4 color :$vout.COLOR : COLOR : -1 : 1 //const c[1] = 1 0 1 1 //const c[0] = 0 1 0 0 dcl_position v0 mov oPos.xy, v0.xyyy mov oPos.zw, c0.yyxy mov oD0, c1 // 3 instructions // 0 temp registers // End of program ----------------------------------------------------------- Which as you can see has the dcl_position v0 line in it. The problem is my card doesnt support vs_2_0 as CreateVertexshader fails when I use 2_0. So, am I going to have to add those dcl lines to all my compiled Cg programs? If I switch the vs_2_0 at the top to vs_1_1, I assemble fine. Not sure what to do. Any advice appreciated. Thanks! -Zaya Edit: Typo [edited by - Zaya on February 20, 2004 12:45:32 PM]

##### Share on other sites
i dont know cg, but in vs_1_0 you don''t need to declare the constant inputs (dcl_xx). in vs_1_1 you do so that''s why vs_1_0 compiles. however I think MS will beat us if anyone uses vs_1_0

##### Share on other sites
You may also want to try www.cgshaders.org for CG specific stuff. But perhaps there are some people on this board that use CG that can help.

neneboricua

##### Share on other sites
I would, cept the site is down =(

##### Share on other sites
Crap, you''re right. Didn''t realize that. sorry. I''m sure someone on here uses CG and will be able to help.

##### Share on other sites
I suppose you may need to do that. But why do you want to compile your shaders? Why not use them directly via the cgProgram or whatever? Then, you could use the compile function to compile the shader during runtime under the optimal profile. It''s much simpler to set parameters and stuff directly that way.

##### Share on other sites
Normally, I would use the cgRuntime. The problem is, when I use the runtime with vs_1_1 it wont assemble (since both the cgc and the runtime libraries compile without the dcl_position v0) I get assemble errors. I was using cgc to figure out what was wrong.

##### Share on other sites
Do you have the latest verison of cgc? Probably nVIDIA "rectified", or rather "added" this "feature" to the new compiler. Otherwise, writing "dcl_position v0" for every shader you write will be a real pain!

ah well

-Zaya

##### Share on other sites
You have to use additional option "-profileopts dcls" to compile into DX9 style vertex shader profile.

##### Share on other sites
Woot! That was right! I knew it was something newbish =/ I used cgc to compile with those options, and it worked. Also, in the runtime, I added the -profileopts to the last paramaeter of

cgCreateProgramFromFile

... Of course, if I would have used the
cgD3D9GetLatestVertexProfile
cgD3D9GetOptimalOptions

Functions after setting the device, I would have known this hehe.

Thanks again!

-Zaya

• ### Forum Statistics

• Total Topics
628728
• Total Posts
2984419

• 25
• 11
• 10
• 16
• 14