Sign in to follow this  

precompile .fx-files

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this