What exactly constitutes swizzling in OpenGL ES 2.0? (PowerVR SGX specifically.)

5.1k Views Asked by At

PowerVR says

Swizzling the components of lowp vectors is expensive and should be avoided.

What exactly is swizzling?

color.brg  // This fits the definition I'm familiar with.

But what about vec3(color.b, color.r, color.g), or vec3(color), when color is a vec4?

Does accessing or modifying a single component constitute a swizzle? I really wouldn't think so, but if not, then you could work around swizzling by just doing a few more assignment operations manually. I don't have a problem doing that, but it seems like magic to me, if you could get the same effect at a faster speed just by writing the code without swizzle notation.

2

There are 2 best solutions below

2
On BEST ANSWER

According to the GLSL specification, "swizzle masks" are defined as the component field selectors for vector types. .brg is a swizzle mask, as is .rgba or .b. All of those do swizzling.

As for what PowerVR is talking about, that's up to them. Maybe .rgb is fine, since it selects the components in the same order. Or maybe it's not.

0
On

Swizzling the components of lowp vectors is expensive and should be avoided.

lowp vectors are 8-bit floating per channel, i am not sure about Powervr but in generally speaking transferring moving data between Floating 32-bit register(or 16-bit, again depending on architecture) is more efficient in contrast to Floating 8-bit, because it doesn't requires extra maskin/moving instructions.mostly GPU memory are alligned that way.

What exactly is swizzling?

In simple words,

swizzle tells that which channel of source(or combination of sources)should go in which channel of destination

example:

vec3 dest.rgb = vec3(src1.r, src2.r, src3.r);

will move src1.r channel to dest.r channel, src2.r channel to dest.g channel and src3.r channel to dest.b channel.

using swizzle is more efficient than manually moving channels because GPUs support that in hardware.(again some of the GPU compilers can detect that and can optimise the moves also).