# Does GLSL copy function arguments by value?

My question is about passing variables to GLSL shader. I'm not sure how that works and what are the performance implications.

Say I got a function that accepts a "vec4" variable. The question is - is that variable copied at the entrance? I guess it makes impact on performance if so. And if it happens to be that way is there a way to pass only references like in C/C++?

• GLSL doesn't run on the CPU so you shouldn't think about it in the same terms as code that does run on the CPU. Mar 4 '14 at 21:00
• This ^ comment is totally uninformative. Tell us how we should think about it, running on the GPU, then.. ¯_(ツ)_/¯ Jun 19 '18 at 23:15

Note that passing by const& in C++ is completely different from "passing by reference." In passing by reference, the function is allowed to change the argument, and these changes are visible to the calling function. "inout" achieves a similar result, but is not quite the same as vec4& in C++ if you pass the same variable to different parameters of a function.
vec4 is a primitive type in GLSL, you can expect it to behave like a int or float for performance. Finally, vec4 is only 128 bits, which is one or two cycles to copy.
• Correction: In C++ passing by const& IS passing by reference. It's just a read-only reference. Sep 25 '20 at 15:13