Frequent shader change
In our game we want to use shaders. We want to use them frequently, few ten-times, maybe few hundred-times shader change per frame. Is that approach good, or it will be incredible slow?
Thanks in advance
Hi there JoystickX,
How are you doing?
The Problem
Changing shaders alot of times per frame
The Solution
Doing alot of changes per frame is always bad.. What I normally do might help you in deciding how you will do yours.
I have a shader manager that batches all the entities that needs to be drawn with the same shader. This will save state changes.
With frequent do you mean like changing them alot or just using them to render entities... if so, my approach will work out for you.
Some other people might have some better solutions and I hope you come right.
Take care bud,
Good luck
How are you doing?
The Problem
Changing shaders alot of times per frame
The Solution
Doing alot of changes per frame is always bad.. What I normally do might help you in deciding how you will do yours.
I have a shader manager that batches all the entities that needs to be drawn with the same shader. This will save state changes.
With frequent do you mean like changing them alot or just using them to render entities... if so, my approach will work out for you.
Some other people might have some better solutions and I hope you come right.
Take care bud,
Good luck
I don't do a lot of shading yet, but it seems like you could do the following approach:
Depending on the complexity of your shaders, you could probably throw 4 or 5 together and check flags in the constants register. Each time you want to use 1 of the 5 shaders, you'd just set a constant to 0 through 4. You'd still have to batch those up, because obviously the larger the shader gets, the longer it takes to load. There are also size limitations. 100's of shaders seems unusual per frame. What exactly are you doing? Maybe there are other ways to do it?
Depending on the complexity of your shaders, you could probably throw 4 or 5 together and check flags in the constants register. Each time you want to use 1 of the 5 shaders, you'd just set a constant to 0 through 4. You'd still have to batch those up, because obviously the larger the shader gets, the longer it takes to load. There are also size limitations. 100's of shaders seems unusual per frame. What exactly are you doing? Maybe there are other ways to do it?
I have found that the easiest way to batch states is to organize all of them into a tree-like structure, similar to the one below:
This minimizes state changes, like Armadon and Supernat mentioned. It's also really easy to implement and transverse.
Shader1 Shader2 |--------|--------| |--------|--------| TextureSet1 TextureSet2 TextureSet3 TextureSet4 |--------|--------| ... ... ... ConstantSet1 ConstantSet2 | | Entity1 Entity5 Entity2 Entity6 Entity3 Entity4
This minimizes state changes, like Armadon and Supernat mentioned. It's also really easy to implement and transverse.
You know, Dustin, I've seen this diagram of yours a billion times. Do you keep it in the clipboard or what? [grin]
Quote:Original post by Coder
You know, Dustin, I've seen this diagram of yours a billion times. Do you keep it in the clipboard or what? [grin]
[lol] What can I say? It's a handy diagram!
p.s. I store it in my bookmarks
To give you a benchmark number, AOE3 has
120 Shader changes per frame and 360 texture changes per frame
380,000 tris / frame
3,900 drawprim calls per frame.
120 Shader changes per frame and 360 texture changes per frame
380,000 tris / frame
3,900 drawprim calls per frame.
One way I thought would be good is to create 2 Draw Lists while culling one with alpha and one without. Then I sort the opaque objects by shader and sort the alpha objects by distance.
Anyone else know of any better ways?
Anyone else know of any better ways?
Quote:Original post by ph33r
To give you a benchmark number, AOE3 has
120 Shader changes per frame and 360 texture changes per frame
380,000 tris / frame
3,900 drawprim calls per frame.
That is quite unusual. Both ATI and Nvidia recommend a *maximum* of 1,000 DIP calls per frame. Also, at the rate you are suggesting, only 97 triangles are drawn per batch.
Do you have a source for this info or something?
Quote:Original post by ph33r
To give you a benchmark number, AOE3 has
120 Shader changes per frame and 360 texture changes per frame
380,000 tris / frame
3,900 drawprim calls per frame.
From where do you know this? Can you give a link?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement