Commit
624789e3708c 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: 624789e3708c ("compiler/glsl: handle case where we have multiple users for types")
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
#endif
struct glcpp_parser;
+struct _mesa_glsl_parse_state;
typedef void (*glcpp_extension_iterator)(
struct _mesa_glsl_parse_state *state,
struct si_context *sctx = (struct si_context *)context;
int i;
+ util_queue_finish(&sctx->screen->shader_compiler_queue);
+ util_queue_finish(&sctx->screen->shader_compiler_queue_low_priority);
+
/* Unreference the framebuffer normally to disable related logic
* properly.
*/
if (!sscreen->ws->unref(sscreen->ws))
return;
+ mtx_destroy(&sscreen->aux_context_lock);
+ sscreen->aux_context->destroy(sscreen->aux_context);
+
util_queue_destroy(&sscreen->shader_compiler_queue);
util_queue_destroy(&sscreen->shader_compiler_queue_low_priority);
si_gpu_load_kill_thread(sscreen);
mtx_destroy(&sscreen->gpu_load_mutex);
- mtx_destroy(&sscreen->aux_context_lock);
- sscreen->aux_context->destroy(sscreen->aux_context);
slab_destroy_parent(&sscreen->pool_transfers);
driDestroyOptionCache(&intel->optionCache);
/* free the Mesa context */
- _mesa_free_context_data(&intel->ctx);
+ _mesa_free_context_data(&intel->ctx, true);
_math_matrix_dtr(&intel->ViewportMatrix);
driDestroyOptionCache(&brw->optionCache);
/* free the Mesa context */
- _mesa_free_context_data(&brw->ctx);
+ _mesa_free_context_data(&brw->ctx, true);
ralloc_free(brw);
driContextPriv->driverPrivate = NULL;
nouveau_object_del(&nctx->hw.chan);
nouveau_scratch_destroy(ctx);
- _mesa_free_context_data(ctx);
+ _mesa_free_context_data(ctx, true);
}
void
/* free atom list */
/* free the Mesa context data */
- _mesa_free_context_data(&radeon->glCtx);
+ _mesa_free_context_data(&radeon->glCtx, true);
/* free the option cache */
driDestroyOptionCache(&radeon->optionCache);
osmesa->gl_buffer = _mesa_create_framebuffer(osmesa->gl_visual);
if (!osmesa->gl_buffer) {
_mesa_destroy_visual( osmesa->gl_visual );
- _mesa_free_context_data( &osmesa->mesa );
+ _mesa_free_context_data(&osmesa->mesa, true);
free(osmesa);
return NULL;
}
!_tnl_CreateContext( ctx ) ||
!_swsetup_CreateContext( ctx )) {
_mesa_destroy_visual(osmesa->gl_visual);
- _mesa_free_context_data(ctx);
+ _mesa_free_context_data(ctx, true);
free(osmesa);
return NULL;
}
if (ctx->Version < version_major * 10 + version_minor) {
_mesa_destroy_visual(osmesa->gl_visual);
- _mesa_free_context_data(ctx);
+ _mesa_free_context_data(ctx, true);
free(osmesa);
return NULL;
}
_mesa_destroy_visual( osmesa->gl_visual );
_mesa_reference_framebuffer( &osmesa->gl_buffer, NULL );
- _mesa_free_context_data( &osmesa->mesa );
+ _mesa_free_context_data(&osmesa->mesa, true);
free( osmesa );
}
}
!_vbo_CreateContext( mesaCtx ) ||
!_tnl_CreateContext( mesaCtx ) ||
!_swsetup_CreateContext( mesaCtx )) {
- _mesa_free_context_data(&c->mesa);
+ _mesa_free_context_data(&c->mesa, true);
free(c);
return NULL;
}
_swrast_DestroyContext( mesaCtx );
_tnl_DestroyContext( mesaCtx );
_vbo_DestroyContext( mesaCtx );
- _mesa_free_context_data( mesaCtx );
+ _mesa_free_context_data(mesaCtx, true);
free( c );
}
* \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
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()) {
_mesa_destroy_context( struct gl_context *ctx )
{
if (ctx) {
- _mesa_free_context_data(ctx);
+ _mesa_free_context_data(ctx, true);
free( (void *) ctx );
}
}
const struct dd_function_table *driverFunctions);
extern void
-_mesa_free_context_data( struct gl_context *ctx );
+_mesa_free_context_data(struct gl_context *ctx, bool destroy_compiler_types);
extern void
_mesa_destroy_context( struct gl_context *ctx );
#include "util/u_upload_mgr.h"
#include "util/u_vbuf.h"
#include "cso_cache/cso_context.h"
+#include "compiler/glsl/glsl_parser_extras.h"
DEBUG_GET_ONCE_BOOL_OPTION(mesa_mvp_dp4, "MESA_MVP_DP4", FALSE)
st_destroy_program_variants(st);
- _mesa_free_context_data(ctx);
+ _mesa_free_context_data(ctx, false);
/* This will free the st_context too, so 'st' must not be accessed
* afterwards. */
st_destroy_context_priv(st, true);
st = NULL;
+ /* This must be called after st_destroy_context_priv() to avoid a race
+ * condition between any shader compiler threads and context destruction.
+ */
+ _mesa_destroy_shader_compiler_types();
+
free(ctx);
if (save_ctx == ctx) {