What is swizzling?

Started by
6 comments, last by ProgramMax 20 years, 6 months ago
A buddy was talking about a clever idea he had for culling objects from a scene. He said it was based on swizzling. I did a bit of research and haven''t quite grasped what swizzling is exactly. Could anyone help me out? Thanks!
Advertisement
Shizzle yo swizzle.
In shader/assembly teminology, swizzling means changing parameter register order while calling some operation.

I have a hard time imagining how it could be used for culling...

-Nik

Niko Suni

you declare two vectors.

Vector2 foo;
Vector4 bar = Vector4(1.0f, 3.0f, 1.0f, 1.0f);

foo.xy = bar.zw; <-- this is swizzling.
-jonnii=========jon@voodooextreme.comwww.voodooextreme.com
The other meaning of "swizzling" is converting stored offsets and references to direct memory addresses. Sort of like what you''d do when loading a binary tree structure from a file into memory.

How appropriate. You fight like a cow.
quote:Original post by Sneftel
The other meaning of "swizzling" is converting stored offsets and references to direct memory addresses. Sort of like what you''d do when loading a binary tree structure from a file into memory.


I''ve always called this "indexing".
Well, live and learn

-Nik

Niko Suni

Can also mean "reorganising data for more optimal access"

For example say you have a set of 4 component vectors in memory:
xyzw,xyzw,xyzw,...,xyzw

For some algorithms implemented with SIMD CPU instructions (MMX, SSE, 3DNow!), if the data is "swizzled" into a form such as:
xxxx,yyyy,zzzz,...,xxxx

Then the implementation can often use less or faster instructions.


Another common type of "swizzle" (reorganisation of data) is for textures on graphics cards - many reorganise the layout of texels in memory to allow better texel/texture cache use (assuming the app uses textures in a "usual" way).


AFAIK it comes from "swizzle stick" which is a nick name for a drink stirrer (i.e. "mix up" the drink).

--
Simon O''Connor
3D Game Programmer &
Microsoft DirectX MVP

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

The SIMD and cache example makes a lot of sense to me.

The buddy I was talking about is programming his own database driver for his project. The objects which could be potentially culled are in this database. Given this situation, the comment about swizzling being memory access instead of offsets and references makes sense.

Anyway, this sounds really great. I like the SIMD stuff a lot. Are there any pages that you guys can think of which are kinda a tutorial for swizzling being used in gaming?

Thanks again!

This topic is closed to new replies.

Advertisement