Cg Shader question

Started by
1 comment, last by Ashkan 15 years, 11 months ago
Hi, I'm pretty new to Cg Shaders and I was just wondering what the overhead of cgGetNamedParameter() was. Basically, I have a small wrapper over the Cg runtime library that calls cgGetNamedParameter() each time a parameter will be set, instead of caching off the resulting CGparameter object. Is this inefficient? Or should I consider caching the CGparameter objects in an unordered_map? Also, as another question, what justifies needing to set uniform parameters again? In other words, if I set a uniform parameter only 1 time at Cg initialization time (like the ModelView projection) my geometry will not draw. However, if I set the uniform parameter 1 time before I bind the vertex shader each frame, it works. So, my question really is, what causes the uniform parameters to be "reset"? Thanks.
Advertisement
Your model view projection matrix will be changing all the time so that parameter needs to be bound every frame (or at least every time it changes, may aswell be every frame). You only need to set the uniform parameters when they change afaik. There is a way to bind the OpenGL matrix to the modelview matrix using Cg API, check out cgGLSetStateMatrixParameter.
Hi,

Quote:Original post by MrDoomMaster
I'm pretty new to Cg Shaders and I was just wondering what the overhead of cgGetNamedParameter() was. Basically, I have a small wrapper over the Cg runtime library that calls cgGetNamedParameter() each time a parameter will be set, instead of caching off the resulting CGparameter object. Is this inefficient? Or should I consider caching the CGparameter objects in an unordered_map?


Profile and optimize accordingly. That's the zeroth rule of optimization. No one can really answer such questions since there are two many varying parameters involved. This is totally implementation-dependent and might even change from one version to another, so the only people who can accurately answer questions of this nature are the implementors of the library themselves.

That said, I just implemented a small cache to store the results mainly because it required a small amount of effort; too small to give it considerable thought.

To reiterate my point, do not optimize prematurely. If you're not sure how much extra performance an optimization is going to gain you, it's probably not worth implementing in the first run. The time you spend on such premature optimization is time you can spend elsewhere to improve your software's quality.

Just my 2 cents...

This topic is closed to new replies.

Advertisement