Skip to main content
GameDev.net gamedev.net
🔒 Locked

What is swizzling?

Started by ProgramMax Oct 9, 2003 at 12:39 AM 6 replies 23.6k views
Original Post
ProgramMax
ProgramMax
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!
Nik02
Nik02
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
jonnii
jonnii
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
Sneftel
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.


How appropriate. You fight like a cow.
Nik02
Nik02
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
S1CA
S1CA
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
ProgramMax
ProgramMax
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!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.