precompile .fx-files

Started by
4 comments, last by SlimTimmy 19 years, 2 months ago
Hello, I want to implement some caching system in order to reduce the time required to load effect files (.fx) In the DX Docs they just speak of "an effect from an ASCII or binary effect description". Are these binary effect descriptions compiled effect files? I was wondering because at another place it says: "D3DXCreateEffectCompiler Function Creates an effect compiler from an ASCII or binary effect description." This wouldn't make sense if the binary description was a compiled effect. A compiler which compiles compiled code? ;) I think the docs aren't very clear concerning this issue. Can anybody help?
Advertisement
Good question. I'm not really sure what that "ASCII or binary effect description" means, because I've only ever used text files with the D3DXCreateEffect*() functions. However, I don't think this is a really big deal at all, because:

(1) Compiling an individaul effect doesn't take too long at all.

(2) Compiling an effect only occurs at loadtime, so the performance hit is virtually zero, in terms of it's effect at runtime.

(3) Compiling validates each individual effect. This is important, because an effect that may run on high-end hardware (ie ATI 9800xt) may not run on lower-end hardware (Nvidia GF4).

(4) Compiling first to binary and then loading it could present an annoying bottleneck in your art pipeline. Instead of simply being able to change an effect, you have to change it, and then compile it into binary form.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
There is a command line effect compiler included with directx 9. It is called fxc and it seems to compile effects into a number of forms. I have used it to produce ASM from HLSL, but you ought to be able to produce a compiled effect with the profile = fx_2_0. The docs are not real verbose on the subject, but it might be worth playing with.
Quote:
(1) Compiling an individaul effect doesn't take too long at all.

(2) Compiling an effect only occurs at loadtime, so the performance hit is virtually zero, in terms of it's effect at runtime.

(3) Compiling validates each individual effect. This is important, because an effect that may run on high-end hardware (ie ATI 9800xt) may not run on lower-end hardware (Nvidia GF4).

(4) Compiling first to binary and then loading it could present an annoying bottleneck in your art pipeline. Instead of simply being able to change an effect, you have to change it, and then compile it into binary form.


You would be right if I was shipping the compiled effects with the finished game.
But my approach is different:
On first startup of the game, the ASCII effect descriptions are loaded, compiled (using the hardware currently installed on this computer) and stored in a particular folder (the date when the effect was modified is also stored). In subsequent executions of the program the compiled effect files are loaded from this directory if they had not been modified (otherwise they will be recompiled)
With this approach you get the best of both worlds.
I think it would make a difference if you recompile all effect files each time you run the game. You have to keep in mind that each effect file aggregates several shaders (probably written in HLSL). Compiling these is also time consuming.

Quote:
There is a command line effect compiler included with directx 9. It is called fxc and it seems to compile effects into a number of forms. I have used it to produce ASM from HLSL, but you ought to be able to produce a compiled effect with the profile = fx_2_0. The docs are not real verbose on the subject, but it might be worth playing with.


I'll check it out. But I'm (as mentioned above) mainly interested in doing this at runtime.
I thought the compiler compiled the code depending on what the gfx card supports, so would precompiled effect files mean that can be done anymore. I'm probably wrong...
Quote:Original post by DrGUI
I thought the compiler compiled the code depending on what the gfx card supports, so would precompiled effect files mean that can be done anymore. I'm probably wrong...


You're wrong. ;) Normally you specify a certain vertex or pixel shader profile in the effect file. But otherwise it would also be possible to cope with this problem . (look at my last post)

This topic is closed to new replies.

Advertisement