#### Archived

This topic is now archived and is closed to further replies.

# Swizzling

This topic is 5545 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have seen this term pop up a few times recently, and I was wondering what it meant.

##### Share on other sites
well, it is used in Cg, but i dont know any other languages that use it. it is not necasary for openGL. basically, it is a way to rearrange vectors or something. if you really need to know what it is, someone else can explain better than i can.

##### Share on other sites
Swizzling is a postfix operator that can be applied to certain vector processing opcodes or constructs in some languages (Cg, HLSL, but also shader ASM). It can remap, exchange or copy the components of a vector, on an individual basis. It's a very useful feature to reduce the number of opcodes, esp. since it comes for free (performance-wise) on most hardware.

From the Cg manual:

Swizzle Operator
Cg has a swizzle operator ( . ) that allows the components of a vector to be
rearranged to form a new vector. The new vector need not be the same size as
the original vector - elements can be repeated or omitted. The characters x , y ,
z , and w represent the first, second, third, and fourth components of the original
vector, respectively. The characters r , g , b , and a can be used for the same
purpose. Because the swizzle operator is implemented efficiently in the GPU
hardware, its use is usually free.

The following are some examples of swizzling:

float3(a, b, c).zyx yields float3(c, b, a)
float4(a, b, c, d).xxyy yields float4(a, a, b, b)
float2(a, b).yyxx yields float4(b, b, a, a)
float4(a, b, c, d).w yields d

The swizzle operator can also be used to create a vector from a scalar:

a.xxxx yields float4(a, a, a, a)

The precedence of the swizzle operator is the same as that of the array
subscripting operator ( [] ).

[edited by - Yann L on March 16, 2003 8:26:46 PM]

##### Share on other sites
Many hardware texturing architectures (most 3d accelerators) use "swizzled textures" to improve locality of cache references.. that it the textures are not stored linearly, but in for example 4x4 blocks which fit in a hw cache line or something.

##### Share on other sites
(glslang - the OGL 2.0 shading language - will also have swizzling)

##### Share on other sites
quote:

Many hardware texturing architectures (most 3d accelerators) use "swizzled textures" to improve locality of cache references.. that it the textures are not stored linearly, but in for example 4x4 blocks which fit in a hw cache line or something.

Xbox.

------------
- outRider -

##### Share on other sites
outRider wrote
"quote:
_
Many hardware texturing architectures (most 3d accelerators) use "swizzled textures" to improve locality of cache references.. that it the textures are not stored linearly, but in for example 4x4 blocks which fit in a hw cache line or something.
_

Xbox. "

GameCube

##### Share on other sites
sir, yuor post is ugly
implemnt these [ quote ] and [ /quote ] tags poppet

• 9
• 23
• 10
• 19