On my current project, (not OpenGL based) if we had to compile the shaders on startup, it would take literally hours to start. (LOTS of shader combinations)
Same problem here. I use 218 SM2 combinations. Takes almost 10s to initialize. The offline DX9 version of my program initializes in 0.1 seconds.
Even a "binary blob" solution would not really be a good fit. Imagine seeing "Please wait, compiling shaders" for a few hours when you first load the game.
Not very good idea, indeed… That’s where an offline compiler can help.
I am not convinced that current OpenGL shaders are any faster than D3D shaders which use a intermediate language. (infact, OpenGL might even be slower as they don’t have much time to optimize)
In all the programs I did, the DX9 shaders ( with almost the same shader code) were a 200-500% faster than the GLSL ones. Using a profiler discovered that OGL is way faster than DX9 in the draw calls. Using a shader profiler I could see the problem are, in fact, the shaders. So, if you think GLSL runtime-compiled can optimize better something is wrong there ( or perhaps is the lack of half precission in the GLSL model what slows )
I also think the next generation of graphics should focus on accuracy and predictability, (I get frustrated with GLSL’s flakiness sometimes between vendors) and a common intermediate language would go a long way towards that.
Same here. I am tired of getting stupid warnings and errors with well syntax written GLSL that fails unexpectly with some graphic drivers. I have never got the same problem with DX9 btw.
It will be interesting to see what Long Peaks
Well I heard Open ES was getting an offline compiler…
Also, a bird told me they are putting there a system like DX9/DX10 coming with glFX… wait and see!
Originally posted by Korval:
Without those semantics (function calls, structs, etc), the final compiler cannot determine when to inline and when not to, which is something that can change based on the hardware.
Well, the ps3.0 included a “call” asm instruction. In the practice inlines all which can be bad…
I wish new shader models could include some kind of C stack to call recursively the functions.
About the structs are just a linear data pointer with the [] operator applied. Perhaps the intermediate language could conserve the struct “structure” as you mention, but the members should be “obfuscated” to hide the curious people the meaning. Something like:
Original struct:
struct VSIn
{
vec3 pos, normal;
vec2 uv;
};
Obfuscated struct:
struct VSIn
{
vec3 a123, b5087;
vec2 c38024;
};
We could use some kind of “reflection” in the shaders taking into consideration the obfuscation system. The code obfuscator should replace all the VSIn.pos by the a123 in the code ( which is not a problem really and does not affect the speed of the shader ).
For the uniforms(like uniform vec3 g_vLightPos) the offline compiler need to encrypt it into “AHDKDSF” and tell us the constant index assigned in a table. This is what Dx9 does when you compile an effect:
vertexshader =
asm {
//
// Generated by Microsoft (R) D3DX9 Shader Compiler
//
// Parameters:
//
// float4x4 g_mNegZInvCamProjTM;
// float4 g_vCamPos;
//
//
// Registers:
//
// Name Reg Size
// ------------------- ----- ----
// g_mNegZInvCamProjTM c0 4
// g_vCamPos c4 1
//
See, it assigned the g_vCamPos to the c4.
It also saves some kind of obfuscated “reflection” information into the compiled shader… so we could do after:
m_pFX->SetVector("g_vCamPos",1.0f,-17.0f,-32.0f);
which internally goes to the reflection encrypted table, searches the “g_vCamPos”, gets the c4 register as return value and assigns it. Also is possible to get a “g_vCamPos” handle to avoid string map fetch.
Btw, notice also I just wanted to put the PS3.0 as example of code obfuscation, not as a good intermediate language example!
ps: What’s wrong with the edit system in forums? I edit the post and puts old data into the textbox!