Sign in to follow this  
schupf

Functions in HLSL

Recommended Posts

Hi all, an easy (?) question: Will functions affect performance in HLSL Code? I could imagine that there isnt even a call instruction in shader assembly code and that all function in HLSL (in an effect file) will be inlined. But since I am not sure I wanna ask here. BTW: I pass a lot of parameters (float3) to that function - maybe thats important. Thanks!

Share this post


Link to post
Share on other sites
Not really my field, but I don't see that there should be a major overhead for using functions. As you guessed, there isn't the same sort of infrastructure for function calls as on a regular CPU. As such, a function fall will probably be inlined, and in the worst case, it will be a jump with the parameters handled by clever register allocation.

So I would say you can use functions to your hearts content, with little penalty.

Share this post


Link to post
Share on other sites
Current HLSL is all inlined at compile-time so it won't make any difference. In the interest of maintainable good quality code I suggest you use them.

I vaguely remember seeing some talk about future versions of HLSL maybe having a limited version of function calling / call-stack, but I suspect that'd be the D3D11 timeframe rather than anytime soon [smile]

Lots of variables may increase register pressure which may increase instruction counts, but thats a whole seperate issue!

hth
Jack

Share this post


Link to post
Share on other sites
ooh, just had a re-read of the D3D10 specification I have... there are in fact call and return instructions in SM4. Nesting can go as deep as 32 and can be recursive as well...

No idea if the current HLSL compiler actually generate these instructions, but if its in the spec then it would be perfectly legal to use them [smile]


Jack

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this