From: Gregory Hainaut <[email protected]> While a context only has a single glthread, the context itself can be attached to several threads. Therefore the dispatch table must be updated in all threads before the destruction of glthread. In others words, glthread can only be destroyed safely when the context is deleted.
Fixes remaining crashes in the glx-multithread-makecurrent* tests. V2: (Timothy Arceri) updated gl_API.dtd marshal_fail description. Signed-off-by: Gregory Hainaut <[email protected]> --- src/mapi/glapi/gen/gl_API.dtd | 6 +++--- src/mapi/glapi/gen/gl_marshal.py | 3 ++- src/mesa/main/glthread.c | 8 ++++++++ src/mesa/main/glthread.h | 7 +++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/mapi/glapi/gen/gl_API.dtd b/src/mapi/glapi/gen/gl_API.dtd index dc4a199..b464250 100644 --- a/src/mapi/glapi/gen/gl_API.dtd +++ b/src/mapi/glapi/gen/gl_API.dtd @@ -124,23 +124,23 @@ param: "width" field in the protocol for TexImage1D. marshal - One of "sync", "async", "draw", or "custom", defaulting to async unless one of the arguments is something we know we can't codegen for. If "sync", we finish any queued glthread work and call the Mesa implementation directly. If "async", we queue the function call to be performed by glthread. If "custom", the prototype will be generated but a custom implementation will be present in marshal.c. If "draw", it will follow the "async" rules except that "indices" are ignored (since they may come from a VBO). marshal_fail - an expression that, if it evaluates true, causes glthread - to finish and tear down before the Mesa implementation is called - directly. Used to disable glthread for GL compatibility interactions - that we don't want to track state for. + to switch back to the Mesa implementation and call it directly. Used + to disable glthread for GL compatibility interactions that we don't + want to track state for. glx: rop - Opcode value for "render" commands sop - Opcode value for "single" commands vendorpriv - Opcode value for vendor private (or vendor private with reply) commands large - set to "true" of the render command can use RenderLarge protocol. doubles_in_order - older commands always put GLdouble data at the start of the render packet. Newer commands (e.g., ProgramEnvParameter4dvARB) put the in the order that they appear diff --git a/src/mapi/glapi/gen/gl_marshal.py b/src/mapi/glapi/gen/gl_marshal.py index 1652759..d73f08b 100644 --- a/src/mapi/glapi/gen/gl_marshal.py +++ b/src/mapi/glapi/gen/gl_marshal.py @@ -232,21 +232,22 @@ class PrintCode(gl_XML.gl_print_base): out('size_t cmd_size = {0};'.format(' + '.join(size_terms))) out('{0} *cmd;'.format(struct)) out('debug_print_marshal("{0}");'.format(func.name)) self.validate_count_or_return(func) if func.marshal_fail: out('if ({0}) {{'.format(func.marshal_fail)) with indent(): - out('_mesa_glthread_destroy(ctx);') + out('_mesa_glthread_finish(ctx);') + out('_mesa_glthread_restore_dispatch(ctx);') self.print_sync_dispatch(func) out('return;') out('}') out('if (cmd_size <= MARSHAL_MAX_CMD_SIZE) {') with indent(): self.print_async_dispatch(func) out('} else {') with indent(): self.print_sync_dispatch(func) diff --git a/src/mesa/main/glthread.c b/src/mesa/main/glthread.c index 8ee7d8d..d2ce0ff 100644 --- a/src/mesa/main/glthread.c +++ b/src/mesa/main/glthread.c @@ -166,20 +166,28 @@ _mesa_glthread_destroy(struct gl_context *ctx) * point, and no batches queued. */ assert(!glthread->batch->used); assert(!glthread->batch->next); free(glthread->batch); assert(!glthread->batch_queue); free(glthread); ctx->GLThread = NULL; + _mesa_glthread_restore_dispatch(ctx); + + puts(__func__); +} + +void +_mesa_glthread_restore_dispatch(struct gl_context *ctx) +{ /* Remove ourselves from the dispatch table except if another ctx/thread * already installed a new dispatch table. * * Typically glxMakeCurrent will bind a new context (install new table) then * old context might be deleted. */ if (_glapi_get_dispatch() == ctx->MarshalExec) { ctx->CurrentClientDispatch = ctx->CurrentServerDispatch; _glapi_set_dispatch(ctx->CurrentClientDispatch); } diff --git a/src/mesa/main/glthread.h b/src/mesa/main/glthread.h index 04eb5ff..327c549 100644 --- a/src/mesa/main/glthread.h +++ b/src/mesa/main/glthread.h @@ -112,31 +112,38 @@ struct glthread_batch /** * Data contained in the command buffer. */ uint8_t buffer[MARSHAL_MAX_CMD_SIZE]; }; void _mesa_glthread_init(struct gl_context *ctx); void _mesa_glthread_destroy(struct gl_context *ctx); +void _mesa_glthread_restore_dispatch(struct gl_context *ctx); void _mesa_glthread_flush_batch(struct gl_context *ctx); void _mesa_glthread_finish(struct gl_context *ctx); #else /* HAVE_PTHREAD */ static inline void _mesa_glthread_init(struct gl_context *ctx) { } static inline void _mesa_glthread_destroy(struct gl_context *ctx) { } static inline void _mesa_glthread_finish(struct gl_context *ctx) { } + +static inline void +_mesa_glthread_restore_dispatch(struct gl_context *ctx); +{ +} + #endif /* !HAVE_PTHREAD */ #endif /* _GLTHREAD_H*/ -- 2.9.3 _______________________________________________ mesa-dev mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/mesa-dev
