Go to bottom

Unbearable GLSL compile time!

category: code [glöplog]
I have a few shaders for different materials / combinations / etc, and the shader compile time is getting annoying.
Do you have any ideas on how to improve this?
added on the 2011-05-29 02:47:11 by xernobyl xernobyl
#pragma optimize(off)
added on the 2011-05-29 02:55:23 by las las
(But yeah, you know - stuff might be slower than...)
added on the 2011-05-29 02:56:38 by las las
added on the 2011-05-29 02:56:48 by las las
I've been thinking about that more than a year ago. So here's the question: Do shaders have something like a function wise calling convention? I think it would save a lot of time compiling permutations of the same shaders base code. -.-

thx to the lekktor for the idea. ;)
added on the 2011-05-29 03:10:31 by yumeji yumeji
yumeji: I think everything in a shader is inlined. I'm not sure.
added on the 2011-05-29 03:24:54 by xernobyl xernobyl
yo sorry. I think I'm wrong in that GLthread anyway. DX movin'. :D
added on the 2011-05-29 04:06:44 by yumeji yumeji
yumeji, take a look at dx shader asm ;)
added on the 2011-05-29 04:40:13 by las las
I'm a lil huge outdated... so what? any news? las? fish the whoreship. ;D
added on the 2011-05-29 05:21:23 by yumeji yumeji
Things that can speed up compiles times.
- Dont use include files (Let you framework just cache the include file and inject it as needed)
- If you work in WebGL make sure you have 'Use OpenGL' enabled so he doesn't convert the shaders to DX
added on the 2011-05-29 09:54:42 by Xetick Xetick
Generally you should try to trick the compiler to not be able to unroll loops etc. You can also often do a lot to minimize the number of places a function is called.
DX11 has a system of linking shaders but even that leads to the big fat compilation when you actually want to use this linked shader, so it's not helping the problem.
And I doubt dx shader asm is any better - most of the time is spent by creating the shader from the binary blob (actual driver compilation) - not translating it from hlsl to the blob.
Last time I checked the same (very complex) shader in ogl and dx, it compiled much faster in ogl (and produced a much slower shader).
added on the 2011-05-29 10:25:59 by Psycho Psycho
3. Make sure you are on nvidia card. Do not ever use ati.
added on the 2011-05-29 11:31:03 by unc unc
you can give a try at ARB_get_program_binary, compiling only the first time you run your application on a given client machine and saving the binary, but as psycho said, it maybe won't help much..
added on the 2011-05-29 11:32:10 by nystep nystep
unc: if you write nvsl instead of real glsl it will usually compile very fast on ati ;)
For hlsl or glsl there isn't much difference.

nystep: the idea for that extension (haven't looked into it at all though) is to be client specific, so it *should* compile to real code for the actual gpu, unlike the dx intermediate code that still has the hard part ahead of it.
added on the 2011-05-29 11:54:40 by Psycho Psycho
anyone have an example of a shader that takes a while to compile? (i've never actually seen a shader take more than a fraction of a second to compile here.. maybe it means i'm not getting optimised shaders? This is on mac/ati with glsl)
added on the 2011-05-29 12:50:16 by psonice psonice
psonice: try having some 10 shaders, each a version for different materials, etc.
added on the 2011-05-29 15:55:33 by xernobyl xernobyl
Use less shaders.
Because I don't believe you really HAVE to use hundreds of them.
added on the 2011-05-29 16:35:13 by chudik chudik
Use less shaders.
Because I don't believe you really HAVE to use hundreds of them.

It can even be thousands, depending directly on the number of permutations you have. As soon as you have complex materials multiplied by the number of variations of your lighting passes and various options, the numbers skyrocket (exponentially).

Console games usually have thousands shaders per platform (Far Cry 2 had 30,000+ shaders on Xbox 360 afair and from what I know God Of War 3 had more than 40,000)
added on the 2011-05-29 16:52:37 by keops keops
Yes, of course... but I mean a *single* shader with long compile time.
added on the 2011-05-29 17:09:32 by psonice psonice
psonice: [url=http://www.pouet.net/prod.php?which=57248]gl1k Cotton Candy/url] might be your gem :\ it compiles fine in Chrome and Opera but takes forever to compile in Firefox ( at least on Win7 ).
added on the 2011-07-06 09:57:32 by p01 p01


Go to top