PDA

View Full Version : Inout parameters GLSL functions



Jeremy35
03-25-2014, 12:21 PM
Hello everybody,

I was wondering about the performance cost of passing heavy parameters to GLSL functions cause of an eventual copy into a temporary variable. Like matrix, sample or struct.
Is someone know more about this issue?

And moreover is the "inout" qualifier avoid the copy?
I'm not sure but according to this (https://www.opengl.org/wiki/Core_Language_(GLSL)), it doesn't. I think it is not the case because it says that the modified variable is copied out into the given parameter at the end of the function.

I hope my questions are clear.
Thank you.

Ilian Dinev
03-25-2014, 01:17 PM
In most cases it would all get inlined, and there'd be no difference whatsoever. If it doesn't get inlined, then the function parameters get allocated in a special place and out/inout get copied back to where you want them. The special place is a global range of temporaries, used only by that function, or exclusively accessed by various functions. Still, generally only functions that are either big or were medium-sized and used statically dozens of times, would not be inlined.

The only thing you should avoid is: passing arguments that would require int<->float conversion. The stuff would get inlined, but it will produce 2 extra instructions, to convert back and front.

Jeremy35
03-25-2014, 02:18 PM
Ok got it, thank you for your answer.