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

Started by
7 comments, last by Vertex333 15 years, 4 months ago
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
Advertisement
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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.
Question answered.

Thx both!
Vertex
Am I right that there is no way to precompile an effect (FX) file? only shaders are possible to be precompiled? I know fxc can compile both...

Am I right?

Thx
Vertex
Yes you can precompile fx files the same way you do with shaders. You can look for "offline compiling" in the sdk documentation.
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
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.
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

This topic is closed to new replies.

Advertisement