[Mesa-dev] Thoughts about threading the GLSL compiler

Eric Anholt eric at anholt.net
Tue Apr 8 15:05:33 PDT 2014


Ian Romanick <idr at freedesktop.org> writes:

> The topic of improving application load time by running the GLSL
> compiler in a separate thread for each call to glCompileShader (or
> glLinkProgram).  Eric had done some experiments with this before (is
> there a branch somewhere?), and he found that it wasn't a win because
> programs regularly do

That's the compiler-threads branch of my tree.

> 	glCompileShader(sh, ...);
> 	glGetShaderiv(sh, GL_COMPILE_STATUS);
>
> Calling glGetShaderiv effectively blocked waiting for the compiler
> thread to finish.

Before thinking about optimizing these paths, it's important to break
out the profiler.  I took a slow-to-compile (but not exceptionally slow)
program: unigine heaven #465.

run_test (33.6%)
 -> glCompileShader (9.4%)
   -> preprocess (1.4%)
   -> parse (.9%)
   -> ast_to_hir (1.3%)
   -> do_common_optimization (5.7%)
 -> glLinkProgram (24.3%)
   -> link_shaders (4.5%)
   -> brw_link_shader (19.8%)
     -> do_common_optimization (7.1%)
     -> other brw transforms (1.2%)
     -> brw_fs_precompile (11.2%)

So the screwup I made is obvious now: I tried to optimize CompileShader,
because it was easy, but even if they didn't check compile status after
the compile, they're going to link right after the compile and block
anyway.

Even if I just moved optimization to a thread instead of all of parsing,
and they they happened to do all compiles (and status checks) and then
all links, it would still be relatively little of the overhead I pushed
out -- only the 5.7%/33.6% in do_common_optimization.

What I should have tackled instead was shoving brw_link_shader's
optimization and precompile out to a thread, and then join with the
threaded precompile (reaping its output, since we don't want reentrance
in the context's program cache) when you go to search for a compiled
shader for the program at draw time.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20140408/d1f5f47c/attachment.sig>


More information about the mesa-dev mailing list