[Mesa-dev] [PATCH v4 4/4] glthread/gallium: require safe_glthread to start glthread
Marek Olšák
maraeo at gmail.com
Fri May 26 14:18:57 UTC 2017
There were some comments, but the overall idea sounds good to me.
Marek
On Sun, May 21, 2017 at 4:59 PM, Gregory Hainaut
<gregory.hainaut at gmail.com> wrote:
> Print an error message for the user if the requirement isn't met, or
> we're not thread safe.
>
> v2: based on Nicolai feedbacks
> Check the DRI extension version
> v3: based on Emil feedbacks
> improve commit and error messages.
> use backgroundCallable variable to improve readability
>
> Signed-off-by: Gregory Hainaut <gregory.hainaut at gmail.com>
> ---
> src/gallium/state_trackers/dri/dri_context.c | 21 +++++++++++++++++----
> 1 file changed, 17 insertions(+), 4 deletions(-)
>
> diff --git a/src/gallium/state_trackers/dri/dri_context.c b/src/gallium/state_trackers/dri/dri_context.c
> index 92d79849c4..8cbab5359f 100644
> --- a/src/gallium/state_trackers/dri/dri_context.c
> +++ b/src/gallium/state_trackers/dri/dri_context.c
> @@ -51,20 +51,22 @@ dri_create_context(gl_api api, const struct gl_config * visual,
> {
> __DRIscreen *sPriv = cPriv->driScreenPriv;
> struct dri_screen *screen = dri_screen(sPriv);
> struct st_api *stapi = screen->st_api;
> struct dri_context *ctx = NULL;
> struct st_context_iface *st_share = NULL;
> struct st_context_attribs attribs;
> enum st_context_error ctx_err = 0;
> unsigned allowed_flags = __DRI_CTX_FLAG_DEBUG |
> __DRI_CTX_FLAG_FORWARD_COMPATIBLE;
> + const __DRIbackgroundCallableExtension *backgroundCallable =
> + screen->sPriv->dri2.backgroundCallable;
>
> if (screen->has_reset_status_query)
> allowed_flags |= __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS;
>
> if (flags & ~allowed_flags) {
> *error = __DRI_CTX_ERROR_UNKNOWN_FLAG;
> goto fail;
> }
>
> if (!screen->has_reset_status_query && notify_reset) {
> @@ -151,24 +153,35 @@ dri_create_context(gl_api api, const struct gl_config * visual,
> ctx->st->st_manager_private = (void *) ctx;
> ctx->stapi = stapi;
>
> if (ctx->st->cso_context) {
> ctx->pp = pp_init(ctx->st->pipe, screen->pp_enabled, ctx->st->cso_context);
> ctx->hud = hud_create(ctx->st->pipe, ctx->st->cso_context);
> }
>
> /* Do this last. */
> if (ctx->st->start_thread &&
> - /* the driver loader must implement this */
> - screen->sPriv->dri2.backgroundCallable &&
> - driQueryOptionb(&screen->optionCache, "mesa_glthread"))
> - ctx->st->start_thread(ctx->st);
> + driQueryOptionb(&screen->optionCache, "mesa_glthread")) {
> +
> + if (backgroundCallable && backgroundCallable->base.version >= 2 &&
> + driQueryOptionb(&screen->optionCache, "mesa_glthread")) {
> +
> + if (backgroundCallable->isThreadSafe(cPriv->loaderPrivate))
> + ctx->st->start_thread(ctx->st);
> + else
> + fprintf(stderr, "dri_create_context: glthread isn't thread safe "
> + "- missing call XInitThreads\n");
> + } else {
> + fprintf(stderr, "dri_create_context: requested glthread but driver "
> + "is missing backgroundCallable V2 extension\n");
> + }
> + }
>
> *error = __DRI_CTX_ERROR_SUCCESS;
> return GL_TRUE;
>
> fail:
> if (ctx && ctx->st)
> ctx->st->destroy(ctx->st);
>
> free(ctx);
> return GL_FALSE;
> --
> 2.11.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list