atb
atb

Reputation: 1462

glsl shader in/out variable packing

Does the order and/or size of shader in/out variables make any difference in memory use or performance? For example, are these:

// vert example:
out vec4 colorRadius;

// tess control example:
out vec4 colorRadius[];

// frag example:
in smooth vec4 colorRadius;

equivalent to these:

// vert example:
out vec3 color;
out float radius;

// tess control example:
out vec3 color[];
out float radius[];

// frag example:
in smooth vec3 color;
in smooth float radius;

Is there any additional cost with the second form or will the compiler pack them together in memory and treat them exactly the same?

Upvotes: 1

Views: 935

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473182

The compiler could pack these things together. But it doesn't have to, and there's little evidence that compilers commonly do this. So the top version will at least be no slower than the bottom version.

At the same time, this is more of a micro-optimization. So unless you know that this is a bottleneck, just let it go. It's best to write clear, easily understood code and optimize it when you know where your problems are, than to optimize it not knowing if it's going to be a concern.

Upvotes: 4

Related Questions