Jump to content
  • Advertisement
Sign in to follow this  
jamesleighe

'Uber' Shader Questions

This topic is 2339 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was thinking of making an 'uber' shader with constants defining how it should operate and I have a few questions.

* What happens if I have a vertex shader that takes as input a position, texture coordinates & a color but I use a vertex declaration that doesn't have the color?
Also similar issues with output, am I wasting allot of bandwidth sending output with some of the variables unset?

* I guess shaders don't have a native 'bool' type so I just check if some float value is equal to zero or not to enable-disable behavior? (Am I going to run into floating point precision issues here?)

Share this post


Link to post
Share on other sites
Advertisement
Which graphics API are you using?

* What happens if I have a vertex shader that takes as input a position, texture coordinates & a color but I use a vertex declaration that doesn't have the color?
Also similar issues with output, am I wasting allot of bandwidth sending output with some of the variables unset?
Preferably, your VD should match the VS inputs, and the VS output should match the PS inputs. IIRC, dx9 will work even if these things don't match (but you pay a performance cost for it), while in dx11 you're forced to match things up properly.
* I guess shaders don't have a native 'bool' type so I just check if some float value is equal to zero or not to enable-disable behavior? (Am I going to run into floating point precision issues here?)
[/quote]There are bools, which are designed for being used in branch statements (branching on a bool is much faster than branching on a float).
See IDirect3DDevice9::SetPixelShaderConstantB.

However, in my experience, uber-shaders are usually implemented with compile-time branching, not runtime branching. i.e. you figure out every different permutation of your if/else conditions, then compile each permutation as a different shader program. At runtime, you just choose the right shader program based off your booleans (instead of sending the booleans to the GPU, and having the shader branch per vertex/pixel).

Share this post


Link to post
Share on other sites
(I'm using dx9)

I thought uber-shaders were supposed to save you having to switch shaders allot...
But I guess doing all that branching would be bad anyway, it's prolly just faster to switch between them I suppose.

Share this post


Link to post
Share on other sites

(I'm using dx9)

I thought uber-shaders were supposed to save you having to switch shaders allot...
But I guess doing all that branching would be bad anyway, it's prolly just faster to switch between them I suppose.


The trick is to build your renderer so that you can try out both approaches and just take the faster one :rolleyes: Really it depends on what your scene complexity is, how fancy the shaders are, and whole bunch of other metrics that can't be directly thought of before hand - you need to try it out both ways for a given scene and hardware configuration and see what is better.

Share this post


Link to post
Share on other sites

(I'm using dx9)

I thought uber-shaders were supposed to save you having to switch shaders allot...
But I guess doing all that branching would be bad anyway, it's prolly just faster to switch between them I suppose.


Usually when people refer to "uber-shaders" they're talking about a big shader with multiple static permutations compiled from it. However in some cases people will refer to an "uber-shader" that uses dynamic or static branching. The former is nice because each individual permutation gets maximum optimization, and you never have to worry about any runtime costs for branching. It can also be nasty because you can end up needing to compiling many many many permutations, which can take a long time to compile and also increases runtime memory + shader switching costs. The latter is nice because you only compile the shader once and don't need to switch as much, but on the other hand the compiler can't optimize around your static branches.

Share this post


Link to post
Share on other sites
Today I wrote some note on my blog regarding managing uber-shader "subshaders". It's here http://maxestws.blogspot.com/2012/04/managing-shaders-combinations.html . Feel free to comment :) Edited by maxest

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!