3

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 Answers2

3

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.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • Thanks for this; I searched 'GLSL specification +"swizzle masks"' and got your info reiterated with examples. I didn't see anything about array notation, e.g. color[1], though. Is that not swizzling? –  Aug 31 '11 at 13:34
  • I tried PVRUniSCo Editor today, and it seems to be as helpful as any rule of thumb. –  Sep 01 '11 at 00:54
2

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).

n1ckolas
  • 4,380
  • 3
  • 37
  • 43