[Mesa-dev] [PATCHv3 11/16] mesa: add infrastructure for threaded shader compilation

Chia-I Wu olvaffe at gmail.com
Wed Aug 20 19:06:28 PDT 2014


On Thu, Aug 21, 2014 at 12:40 AM, Fredrik Höglund <fredrik at kde.org> wrote:
> On Wednesday 20 August 2014, Chia-I Wu wrote:
>> Add _mesa_enable_glsl_threadpool to enable the thread pool for a context, and
>> add ctx->Const.DeferCompileShader and ctx->Const.DeferLinkProgram to
>> fine-control what gets threaded.
>>
>> Setting DeferCompileShader to true will make _mesa_glsl_compile_shader be
>> executed in a worker thread.  The function is thread-safe so there is no
>> restriction on DeferCompileShader.
>>
>> Setting DeferLinkProgram to true will make _mesa_glsl_link_shader be executed
>> in a worker thread.  The function is thread-safe only when certain driver
>> functions (as documented in struct gl_constants) are thread-safe.  It is
>> drivers' responsibility to fix those driver functions before setting
>> DeferLinkProgram.
>>
>> When DeferLinkProgram is set, drivers are not supposed to inspect the context
>> in their LinkShader callbacks.  Instead, NotifyLinkShader is added.  Drivers
>> should inspect the context in NotifyLinkShader and save what they need for
>> LinkShader in gl_shader_program.
>>
>> As a final note, most applications will not benefit from threaded shader
>> compilation because they check GL_COMPILE_STATUS/GL_LINK_STATUS immediately,
>> giving the worker threads no time to do their jobs.  A possible improvement is
>> to split LinkShader into two parts: the first part links and error checks
>> while the second part optimizes and generates the machine code.  With the
>> split, we can always defer the second part to the thread pool.
>
> It looks like _mesa_create_shader_program() needs a bit of work since
> it also checks the compile status immediately after compiling the shader.
It is left out in this series because I have no real-world app to
measure the time difference.  I also want to keep this series simple.

To support it, it should be possible to have a deferred function that
combines deferred_compile_shader and deferred_link_program, and delete
the shader afterward.


>
> Fredrik
>



-- 
olv at LunarG.com


More information about the mesa-dev mailing list