const usuage


I was wondering: are the current GPUs somehow paying attention to the const qualifier when using it inside some function arguments?

For example - would any fragment be faster on the screen, if I wrote:

float foo( const float x );
// instead of
float fooTwo( float x);

Thank you very much!

Most GPU’s inline the functions anyhow, so I would tip on “no”

Const is, and has always been, a compiler thing. It doesn’t change the code that is generated; it simply allows the compiler to catch semantic mistakes the programmer makes. So if you have a const float x, and you change x, the compiler can complain. But it won’t change the code generated.

Well, no exacly… In GLSL, yes, but in C-family const will imply passing arguments by reference

const does not imply pass by reference. To pass by reference you need to write:

float foo( const float &x );

float foo( const float x );

For the above line, I think it makes no difference but for

const float myvar=2.0;

maybe the compiler will generate special instructions for certain const numbers and depending on how you use it.

Other numbers that might be special could be

Humus, Korval, I guess you were right, sorry embarassed It seems I was thinking about pascal…

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.