st/mesa/radeonsi: fix race between destruction of types and shader compilation

Commit 624789e370 moved the destruction of types out of atexit() and
made use of a ref count instead. This is useful for avoiding a crash
where drivers such as radeonsi are still compiling in a thread when the app
exits and has not called MakeCurrent to change from the current context.

While the above scenario is technically an app bug we shouldn't crash.
However that change caused another race condition between the shader
compilation tread in radeonsi and context teardown functions.

This patch makes two changes to fix this new problem:

First we explicitly call _mesa_destroy_shader_compiler_types() when destroying
the st context rather than calling it indirectly via _mesa_free_context_data().
We do this as we must call it after st_destroy_context_priv() so that we don't
destory the glsl types before the compilation threads finish.

Next wait for the shader threads to finish in si_destroy_context() this
also means we need to call context destroy before destroying the queues
in si_destroy_screen().

Fixes: 624789e370 ("compiler/glsl: handle case where we have multiple users for types")

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
This commit is contained in:
Timothy Arceri
2019-04-23 12:54:38 +10:00
parent 3844ed8d44
commit a6b7068ff5
11 changed files with 29 additions and 17 deletions

View File

@@ -1310,7 +1310,7 @@ fail:
* \sa _mesa_initialize_context() and init_attrib_groups().
*/
void
_mesa_free_context_data( struct gl_context *ctx )
_mesa_free_context_data(struct gl_context *ctx, bool destroy_compiler_types)
{
if (!_mesa_get_current_context()){
/* No current context, but we may need one in order to delete
@@ -1385,7 +1385,8 @@ _mesa_free_context_data( struct gl_context *ctx )
free(ctx->VersionString);
_mesa_destroy_shader_compiler_types();
if (destroy_compiler_types)
_mesa_destroy_shader_compiler_types();
/* unbind the context if it's currently bound */
if (ctx == _mesa_get_current_context()) {
@@ -1405,7 +1406,7 @@ void
_mesa_destroy_context( struct gl_context *ctx )
{
if (ctx) {
_mesa_free_context_data(ctx);
_mesa_free_context_data(ctx, true);
free( (void *) ctx );
}
}