PDA

View Full Version : Expected instruction cost of a function call?



MalcolmB
03-21-2006, 02:40 PM
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

Korval
03-22-2006, 01:23 PM
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.

MalcolmB
03-22-2006, 03:17 PM
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?

V-man
03-23-2006, 08:26 AM
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

Korval
03-23-2006, 01:33 PM
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.