This model pushes on code portability, decoupling the GLSL code from any specific platform (hardware and/or software). Because it is a royalty-free standard, every vendor could decide to support GLSL platform. Normally this support will result in a OS-specific OpenGL driver implementation.
many drivers provide buggy compilers
Probably there are many bugs in the drivers out there, but my experience says that the most of the times the bug is not a bug, but it is a misunderstanding of the GLSL specification. For example, this code run fine on NVIDIA platforms, while not on Intel platforms:
// We are in fragment shader
in vec2 ds_TexCoord[3];
uniform int ds_FrontMaterialAmbientTexCoord = -1;
uniform sampler2D ds_FrontMaterialAmbientTexture;
...
if (ds_FrontMaterialAmbientTexCoord >= 0) {
fragmentMaterial.AmbientColor = texture(ds_FrontMaterialAmbientTexture, ds_TexCoord[ds_FrontMaterialAmbientTexCoord]);
}
The trick here is that the array cannot be accessed using directly an uniform variable. Indeed the code running on NVIDIA and Intel platforms is:
if (ds_FrontMaterialAmbientTexCoord >= 0) {
int index = ds_FrontMaterialAmbientTexCoord;
fragmentMaterial.AmbientColor = texture(ds_FrontMaterialAmbientTexture, ds_TexCoord[index]);
}
Once you got few tricks, writing portable GLSL code is just like writing C.
compilers differ in terms of strictness (one GPU can accept a program
while another won't)
Use the strictest one. AMD and Intel have a strict interpretation of the GLSL specification, while NVIDIA don't: this is because the GLSL compiler is based on CG implementation, indeed being more permessive than what should be allowed.
The solution is simple: follow strctly the GLSL specification.
also we can't know how the assembler code will be optimised
If you can about optimization, write in ARB assembly (here some specification and hints). The driver will probably do the best it can for the current platform, will you do better?
Remember that the main goal is portability!