static branching with cG ?

Hi guys

I’m currently working on a DX9/OGL renderer
I’implemented a very simple vertex shader to test the latest static branching feature

something like that :

void main(...
   uniform bool bAddAmbient : register(b0),

on DX9 no problem to run it using the SetVertexShaderConstantB function

the problem arrives on OGL… i use the cgCreateProgram to compile at runtime the vertex shaders.
but this precedent line creates the following error :

error C5123: invalid register semantic "b0"

it seems that static branching isn’t supported by cg ??
any ideas ?

thanks a lot !!

I am no Cg expert at all, but I have only ever seen manual register assignment in HLSL. (not in Cg).

As Cg in OpenGL compiles to NV/ARB ASM that does not have “registers” like D3D does, I don’t know how it would work.

Perhaps you can just specify as a bool without the register assignment and test to see if static branching is picked up by the compiler? (compiler should be smart enough)

yes i can specify a constant bool without the register assignment like that:

uniform bool bAddAmbient;
void main(…

but i need to access the bool via its register assigned, not its name (performance issue)

nevermind a tried this but the problem now is how i can set the register value via cg ?
this kind of function doesnt’ exist ! :wink:

I am still a Cg n00b, but I always thought Cg worked like this:

//At compile time get the parameter index
CGparameter TimeParam1 = cgGetNamedParameter(program1, “time”);

//At runtime set the value
cgSetParameter1f(TimeParam1, 2.0);

So you should not need to set the bool via it’s name at runtime. (I see there is no cgGLSetParameter1b, but using cgGLSetParameter1f should work for bools - Cg experts correct this if wrong)

You may also want to look into Parameter Literalization (page 2 of Cg reference manual - )

That’s the way I remember it as well, but it’s been a while. I don’t recall messing with registers.

You can assing a uniform to a specific constant register using the Cn semantic.

For example:

uniform bool bAddAmbient : C21;