Jump to content

  • Log In with Google      Sign In   
  • Create Account

Texture swizzle


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 samoth   Crossbones+   -  Reputation: 5034

Like
0Likes
Like

Posted 20 March 2012 - 07:21 AM

GL_ARB_texture_swizzle, which is core as of OpenGL 3.3 allows you to swizzle color samples according to texture state that you can set in the application -- before a shader sampling the texture gets to see them.

Which means you can write shaders that are agnostic of the actual channel layout of a texture as long as the application cares to set the state appropriately. For example, storing normal X/Y in green and alpha in a compressed texture, or using red and green instead from an uncompressed texture would work the same without the shader needing to know.

Now, how would I have to imagine this functionality? Should I think in terms of "driver secretly inserts swizzle instructions without me knowing", or should I think of "texture hardware can do this trivially anyway, and only needs to be told". The reason why I'm wondering is because if it's truly "free", then that's a feature just too good to be true. On the other hand, if it's a mere convenience thingie that impacts performance, one would probably rather have specialized shaders for each situation and do careful bookkeeping in order to batch them right.

Sponsor:

#2 Hodgman   Moderators   -  Reputation: 31843

Like
0Likes
Like

Posted 20 March 2012 - 08:29 AM

Not sure about current cards, but many ~6 year old cards use a crossbar design for the texture-fetching hardware that allows any output channel to be connected to any input channel, which results in "free" swizzle. If it passed ARB, then I assume this hardware is still around.

AFAIK, this has been used for a long time to allow textures to be stored as both RGBA and BGRA layouts in memory without the shader being aware.

#3 samoth   Crossbones+   -  Reputation: 5034

Like
0Likes
Like

Posted 21 March 2012 - 02:27 AM

That makes sense, thank you. RGBA vs BGRA is an important argument. As far as I know, pretty much all cards support that transparently.
So that's good news :)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS