Archived

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

MoonJihad

Swizzling

Recommended Posts

Guest Anonymous Poster
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 this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites