views:

334

answers:

2

Hi,

I am coding a 3d Application with DirectX 10 and I am wondering how the tackeling of the Shadermanagement is.

Is it most effective to preload all shaders there are on application start and then use them as needed or does this train the resources of the hardware if the number gets higher.

Also I wonder if it is a speed consideration to order the rendering by shader so the shader switches are minimized.

+2  A: 

I've not worked with DX10, only DX9, but I'm guessing these things are still the same.

Depending on your application, you might actually generate shaders at runtime (many current sophisticated 3D games do this).

Preloading the shaders isn't a bad idea, depending on if you generate shaders, how many there are, what your memory considerations are - it depends. However, preloading a shader (by which I assume you mean creating the ID3DXEffect instance) only takes memory at runtime, no CPU usage.

Ordering by shader is a good idea. In general, sorting by material is a good idea, because switching shaders does incur some overhead (not excessively, but noticeable depending on the complexity of your app).

For sorting your drawcalls, read this: http://realtimecollisiondetection.net/blog/?p=86

arke
+1  A: 

In D3D10, all the device resources are virtualized so you won't run out of them. Of course, you can still exhaust the physical resources on the card and cause lots of thrashing if you don't pay attention to what you're doing.

In addition, they've changed the device state significantly to reduce the cost of switching state, including shaders.

But what you're really asking is "is method X faster than method Y for my application?" and although D3D10 simplifies state management to make switching state faster, the only way to answer the question above is to do a performance measurement with your application and your data.

The realtimecollectiondetection.net blog post is just talking about sorting your draw calls. This is going to lead to less state switching. It doesn't matter how fast state switching is, doing less of it is always faster. So that's good general advice.

legalize