moving from old DX SDK to new one (problem with shader..)

Started by
3 comments, last by MJP 14 years, 2 months ago
I have a project that uses DX SDK from 2004 year, so I decided to move it to newer dx sdk 2009 (august). So I've moved project to new sdk, all compiles without any errors and changes. (I don't change version of used dx components in project, I use DX 9). All works excellent except one pixel shader... I use deferred shading, so this is main shader which assembles MRTs and does lighting. This shader compiles and works but it very slow at runtime, it slows down my application more than in twice (in comparison with old sdk used). But with old sdk all was ok, I had ~200 fps (and now about 90 fps). I've made some investigation and have seen that with old sdk D3DXCompileShaderFromFile() function's implementation stores in static d3dx9.lib and in new sdk - this function stores in d3dx9_xx.dll. So when I use old sdk - I use old shader compiler (via this function). But it works great and new one does not :( So why this happen? I have GF GTX 285 video card and think that new shader compiler should produce a more smart code which should runs better on new cards. I tried different combination of flags (sixth param) for D3DXCompileShaderFromFile() but no success. Any ideas? ps. my pixel shader compiles as "ps_3_0".
Advertisement
You could try compiling each shader with the command line fxc.exe that comes with each SDK and examine the generated code.

Also Nvidia and ATI both have tools available to developers for analysing shader performance.
I agree with Adam - why not take a look at the assembly code to see if you can figure out what the difference is. Also, try compiling the shaders with the highest available model. I have heard this as the general advice now, so it may or may not help...
Thanks for advice. So I've compiled this shader with diferent compilers (fxc.exe)
and I was surprised when looked the difference. It seems like older compiler (from 2004) produces smarter code, i.e. it apply more tricky optimizations than new one.
I'm not very strong in assembler but even with shallow look at that I can say that old compiler does in my case: loop unroling (shader has 'for' loop), adds trick optimization with 'if/else' which skips a lot of code in certain conditions, and gives preference to more lightweight instructions.
After playing with different flags for a new compiler I noticed that using
D3DXSHADER_USE_LEGACY_D3DX9_31_DLL flag gives more performance, and by the way
I found this theme about it: http://www.gamedev.net/community/forums/topic.asp?topic_id=495858
here you can find the same thoughts.
But any way using this flag my shader compiled with new compiler performs slower (but not too much) than with old. Of course this is not in all cases, it depends on shader code itself. So I think that old compiler not so bad, at least for DX 9.
If you want a loop to be unrolled, you can use the [unroll] attribute. If you want to preserve a loop, you can use [loop]. [branch] and [flatten] do the same for branches.

This topic is closed to new replies.

Advertisement