Cg and 'Invalid Parameters'...

What it says on the tin: a place to discuss proposed new features.
Post Reply
User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

Cg and 'Invalid Parameters'...

Post by Zeal »

I noticed this little 'problem' while doing a little shadow mapping cg shader (hlsl/glsl may have this problem as well, im not sure). The trouble came about when I was setting the shadowViewProj matrix via...

Code: Select all

params->setNamedConstant( "shadowViewProj", mat );
...which crashed my app, no assertions or unhandled exceptions, just a error in the ogre log...
OGRE EXCEPTION(2:InvalidParametersException): Parameter called shadowViewProj does not exist. in GpuProgramParameters::_findNamedConstantDefinition at c:\sdks\ogrecvs\ogrenew\ogremain\src\ogregpuprogram.cpp (line 883)
What I didnt realize was - just declaring a param in your shader isnt enough, you have to actually USE it (or it will get removed automatically by the compiler).

My complaint is - if I want to tweak/test a shader (comment/uncomment lines of code), I have to comment out the 'params->setNamedConstant' line, and recompile! I cant just turn shadowing on/off with a simple comment, becuase that causes the param declaration to vanish!

My suggestion - Wouldnt it be better to NOT crash your application when a shader param cant be found? Isnt a warning in the ogre log good enough?
User avatar
HexiDave
OGRE Expert User
OGRE Expert User
Posts: 1538
Joined: Sat Jan 14, 2006 8:00 pm
x 1

Post by HexiDave »

Very easy work-around:

Code: Select all

					if (pParams->_findNamedConstantDefinition("shadowViewProj"))
						pParams->setNamedConstant("shadowViewProj",mat );
That's essentially what you'd be having Ogre do anyways. I always assumed it was one of those things that was on a mental list of things to do and became a "wait, what was that other thing?"

Edit: Also, "just a warning in the log" could turn into several thousand warnings in the log if it goes unchecked long enough - I know I'll have little warning log items and suddenly my program is REALLY slow. Once I shut it all down, I'll find a 10-50 MB Ogre.log waiting for me.
User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

Post by Zeal »

Ok fair enough. But correct me if im wrong, the other way of setting custom params...

Code: Select all

ent->getSubEntity(0)->setCustomParameter
doesnt have this problem does it? Im almost positive you can set a custom parameter that isnt being used via that method.

Either way, your suggested work around does 'work' fine I suppose.
Post Reply