Expected instruction cost of a function call?

Lets say I have a simple vertex shader like this

vec3 deform(vec3 input)
{
vec3 result;
// Deform stuff here
return result;
}

vec4 deform(vec4 input)
{
vec4 result;
// Deform stuff here
return result;
}

varying vec3 vNormal;
void main()
{
gl_Position = deform(gl_Position);
vNormal = deform(gl_Normal);
}

Now, here’s the question, say I input another vector attribute, e.g a Tangent, and I deform that the same way as the normal. Should the instruction count of my program increase significantly? I’m seeing that it inlines every function call to the point where I go above the instruction count limit of the vertex shader.
With dynamic branching is this expected? Is dynamic branching only used for avoiding code but not to reuse it?

This is on a Quadrio 4500 (7800 equivalent if you dont know)

Thanks

The “expected” cost of a function call is unknown.

In general, many functions can and will be inlined by the linker (on good compilers), so there is no actual cost except in the number of instructions. On hardware that actually supports branches, some functions may be actual function calls.

There’s no way to know without benchmarking it.

Ok, so the branching hardware can infact branch function calls? Would it correct to say if a compile inlines functions to the point where it goes above the instrucion limit (instead of doing a branch), its a compiler bug?

Of course it can branch. This is a SM2 (shader model 2) level feature of vertex shaders. I had also noticed the preference to not branch.

its a compiler bug?
yes

Ok, so the branching hardware can infact branch function calls? Would it correct to say if a compile inlines functions to the point where it goes above the instrucion limit (instead of doing a branch), its a compiler bug?
Maybe.

I would point out, however, that instruction counts for branching hardware are well beyond the means of most graphical needs. So if it does exceed the instruction counts, you probably have bigger things to worry about.

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