Swizzling

Started by
7 comments, last by MoonJihad 21 years, 1 month ago
I have seen this term pop up a few times recently, and I was wondering what it meant.
-MoonJihad
Advertisement
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.
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]
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.
(glslang - the OGL 2.0 shading language - will also have swizzling)
_______________________________________Pixelante Game Studios - Fowl Language
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 -
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
sir, yuor post is ugly
implemnt these
and
tags poppet
poppet (Yoda), your spelling is horrible, please use a dictionary.

This topic is closed to new replies.

Advertisement