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

## Recommended Posts

Hello, i read that switch of shaders is "expensive". So what's the cost in dx9 ? lets say i have 10 switches per frame (scene,cloth,player,put all together (deffered shading),3 types of light,SSAO,reflect,refract) is it many ? What about creating only one technique but many passes : so instead of :
technique Technique0
{
pass Pass0
{
}
}

technique post
{
pass Pass0
{
}
}

it will be :
technique Technique0
{
pass Pass0
{
}

pass Pass1
{
}

}

and in code i will change pass instead of technique ? or performance will be same ?

##### Share on other sites
10 switches isn't too much. Even several times that should be okay.

Changing from many techniques to many passes won't change the the number of shader changes, so there's no reason to do it.

##### Share on other sites
Quote:
 Original post by ET3D10 switches isn't too much. Even several times that should be okay.Changing from many techniques to many passes won't change the the number of shader changes, so there's no reason to do it.

I agree but I have a doubt.

I subspect the 2-pass technique has the potential to be a bit faster on D3D9 because a smart graphics driver could avoid an extra "vertex format/vertex shader input" linkage (as long as the VB is untouched and the vertex shader inputs are the same for both passes).

From what I saw performing speed tests on D3D9 vs D3D10, I suppose changing a VB in D3D9 always issues a new linking task (regardless of the fact the vertex format is the same), but I don't know if the same applies to techniques/passes.

To me, if one of the two is more likely to be optimized it is the pass, not the technique.

##### Share on other sites
Quote:
 Original post by undeadI subspect the 2-pass technique has the potential to be a bit faster on D3D9 because a smart graphics driver could avoid an extra "vertex format/vertex shader input" linkage (as long as the VB is untouched and the vertex shader inputs are the same for both passes).

That doesn't really make sense, since the driver has no knowledge of techniques or passes. Those are purely user-side constructs that are part of the effects framework. Either way the driver will only know that you switched shaders.

[Edited by - MJP on December 29, 2009 3:27:31 AM]

##### Share on other sites
Quote:
Original post by MJP
Quote:
 Original post by undeadI subspect the 2-pass technique has the potential to be a bit faster on D3D9 because a smart graphics driver could avoid an extra "vertex format/vertex shader input" linkage (as long as the VB is untouched and the vertex shader inputs are the same for both passes).

That doesn't really make sense, since the driver has no knowledge of techniques are passes. Those are purely user-side constructs that are part of the effects framework. Either way the driver will only know that you switched shaders.

It seems you have a (strong) point.

I still wonder if the single technique is faster, as my reasoning can be applied to the effect framework.

I was referring to this part of D3D10 documentation:

Quote:
 Mapping the vertex data to the shader inputs with an input layout is a new way of doing things in Direct3D 10 that improves performance.In Direct3D 10 the vertex data is mapped to the shader inputs when the input layout object is created, whereas in Direct3D 9 this mapping was done at Draw time based on the currently bound vertex declarations, vertex buffers, and vertex shaders. Doing this mapping when the input layout object is created reduces or eliminates extra linkage work for drivers at Draw time because this re-mapping is no longer necessary.

I was wondering if somewhere (it could be the effect framework itself) a part of code could verify if the vertex shader inputs are the same for both passes and skip the unnecessary linking for the second pass until another technique is in use.

After all a technique is in use between Begin/End pairs and the technique itself can know if its passes have compatible vertex shader inputs. So to just have a list of vertex shader input formats would allow the effect framework to perform such an optimization. 3 passes, one vertex shader input format.. et voila!

If it's impossible to do it because D3D API always performs linkage after a draw call, then I'm forced to believe sending a set of N draw calls, one after another without changing shader or VB forces N re-links!!!
Wow.. it would be a very bad way to draw stuff!!!

If it's the case, then I understand why they changed this mechanism... :)

1. 1
2. 2
Rutin
20
3. 3
4. 4
frob
13
5. 5

• 9
• 13
• 10
• 9
• 17
• ### Forum Statistics

• Total Topics
632601
• Total Posts
3007352

×