GLSL optimization


I have a glsl fragment shader of about 800 lines, don’t know if that’s too much or not. To make my algorithms understandable, I create a lot of layers of abstractions using functions. However, as I was wrapping a bit of code into a function, I’ve noticed that the performance decreases when I use that function instead of using the unwrapped code. Based on all the function calls I have, I believe my fragment program could run much faster, but how should I proceed to optimize it?

I also have plenty of if statements and loops. And one big concern of mine is that some of the loops seem to go on forever unless I set some kind of loop breaker (i.e. for(loopbreaker = 0; loopbreaker < 50; ++loopbreaker)). I don’t really understand why some of these loops don’t exit sooner because all the conditions should have been met.

Maybe this is a bit vague, sorry. However, as for the performance decrease I found when moving code into a function, could it be something other than the fact that it calls a function? For example this wrapper function is void, but it uses a lot of inout parameters, some of these parameters are checked in order to conditionally exit the loop that calls this function. However, it’s much faster to have the function’s code inside this loop.

Also, is there any tool I can use to automatically optimize my 4.3 glsl code? Or is there a website with guidelines to help me optimize it manually?

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