Speed up shader compilation (HLSL)

Started by
33 comments, last by Meltac 11 years, 11 months ago
Sorry, I don't get you. In Part 2, the previously processed "Color" is passed in as a function parameter "Color", so this shouldn't override anything, but just takes the Color as input and returns a modified Color as output. So why should the compiler omit the previous statements? They are significant to get the final result, and it would be misbehavior of the compiler to exclude them.

Of course, I still have to figure out how to use the grad/ ddx/ddy texture functions to produce the correct result.

However, another discovery I made that the described compilation time differences are only so huge when using fxc. When triggering compilation instead through the d3dx9 library the difference is only about one seconds (instead of 3), but compilation seems to take more time overall in that case (up to ten seconds).

What brings me to another question: Might it be that the default behavior of the compiler is different when using fxc.exe or d3dx9.dll or d3dcompiler.dll directly? Or, in other words, do I need to specify some special compiler options such as shader profiles or switches (in the case of fxc) or function arguments (in the case of triggering compilation through one of the dll's) in order to get the exact same result?

Otherwise I see no reason for these obvious compilation differences...
Advertisement
oops, my apologize, I missed the Color passed by argument! Better look at the asm why it is optimizing faster. But anyway, I would quickly try to replace all tex2D by tex2Dlod and check how much It will reduce the compilation time. Also, if you are sampling a previous render target/backbuffer to apply some posteffects and that there is no mipmap, it is safe to use tex2Dlod on the mipmap 0 (t.w = 0).

fxc is using both d3dx9_43.dll and D3DCOMPILER_43.dll internally. Do you know the settings STALKER is using to compile your shaders? What profile are you using to compile your shaders? If you are using the same, you shouldn't have any differences.
Wow, I love tex2Dlod! Now THAT gave the thing a real boost! Thanks for the hint! Btw, does it speed up runtime as well or only compilation?

Now the next step would be find a way to make compilation of loops faster. Here making the [loop] attribute working would be best, don't know why it's not.

I don't know what settings STALKER is using to compile its shaders, nor do I have a clue how to figure that out (there's not much dev-internal information public available). All I know is that the game includes d3dx9_34.dll (not d3dx9_43.dll) which in turn triggers d3dcompiler.dll (don't remember the version) to compile the shaders. I can see the use of the method D3DXCompileShader in the dissambly but don't see what parameters actually are passed. All I know is they are compiling against vs_3_0 and ps_3_0.

Using the latest DX9 binaries (d3dx9_43.dll and the respective d3dcompiler.dll) doesn't seem to change a thing - although I can see the replaced new dll's are being used by the game engine, that doesn't speed up anything nor provide access to newer features such as attributes, strangely. Would enabling attributes require to call some other compiler method instead, or some special settings or something?
tex2Dlod doesn't need to compute the lod (mip-map) level, you pass it in manually, which means that no screen partial derivatives are needed. Things are then easier for both the compiler and run-time. While reading your questions, I gained the impression you needed to sample correct (automatic) mip-map levels, you wouldn't be able to use this instruction otherwise. If you can, use it pretty much "everywhere" :-)
I didn't have an idea like that before, but since xoofx noted that sampling from a backbuffer wouldn't require tex2D with mipmaps anyway I guess this is what saved my day.

Thanks again everbody!

This topic is closed to new replies.

Advertisement