Sign in to follow this  
Vertex333

Compile shader/effect files at runtime or at program compiletime?

Recommended Posts

In a final release version, what is the right way to go for best optimized shader performance? Is there a performance difference between runtime and compiletime compilation? I think of display driver which offers a better compiler that catches the call and recompiles it or so... or the d3d runtime detects a card and does special optimizations. Am I right that runtime compilation is only for flexibility? So what should I do, if I don't need the runtime compilation flexiblitiy? Thx, Vertex

Share this post


Link to post
Share on other sites
The benefit is all load-time, not runtime. You can run off 100 or 100,000 combinations of effects and shaders at build time and simply index into the BLOB's to load them - could save you several seconds of load time depending on your usage.

Unlike OpenGL the driver shouldn't be involved in the main compilation. This was a conscious design decision on MS's part to avoid IHV differences. Naturally that has no bearing on what happens at a lower level (the GPU/driver still has to compile it for the actual hardware microcode) but for the HLSL->ASM and/or ASM->Bytecode when/where you do compilation won't make any difference to the runtime result.


hth
Jack

Share this post


Link to post
Share on other sites
There is no difference between a shader compiled at runtime and one compiled offline. They will both invoke the same exact shader compiler. There would only be differences if you modify the code or compilation based on the hardware detected.

Also keep in mind that no matter what the driver will be "recompiling" and optimizing your shader at runtime.

Share this post


Link to post
Share on other sites
Quote:
Original post by KOzymandias
Yes you can precompile fx files the same way you do with shaders. You can look for "offline compiling" in the sdk documentation.

mhm ok, sorry that I was not that accurate, but does this work in D3D10 too? The docu says compile works, but in the load section they mention the D3DXCreateEffect function, which seems a bit too much d3d9 to me (there is no d3d10 version). So how do I load a !precompiled! D3D10Effect? D3DX10CreateEffectFromMemory?

mhm... I don't really understand this?!?

Vertex

Share this post


Link to post
Share on other sites
I really don't know dx10, but looking at the doc, they say an effect is created by calling D3D10CreateEffectFromMemory, which takes a compiled effect. And you compile the effect using D3DX10CompileFromFile or D3DX10CompileFromMemory.

Share this post


Link to post
Share on other sites
Quote:
Original post by KOzymandias
I really don't know dx10, but looking at the doc, they say an effect is created by calling D3D10CreateEffectFromMemory, which takes a compiled effect. And you compile the effect using D3DX10CompileFromFile or D3DX10CompileFromMemory.
For a first thought this would make sense, but as I can see in the doc, this may not work this way. Also the tutorials only use the createeffect* functions with plain text of FX file code. As far as I can see effect files have to be created/compiled at runtime. mhm.. :(

edit: I was wrong, I read D3DX instead of D3D. Well, D3D10CreateEffectFromMemory without X seems to load a precompiled file. Big THX!

Thx,
Vertex

Share this post


Link to post
Share on other sites

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