[Mesa-dev] [PATCH] dri_util: Don't assume __DRIcontext->driverPrivate is a gl_context

Ilia Mirkin imirkin at alum.mit.edu
Sat Dec 7 22:45:31 PST 2013


On Sun, Dec 8, 2013 at 1:02 AM, Kristian Høgsberg <krh at bitplanet.net> wrote:
> The driverPrivate pointer is opaque to the driver and we can't assume
> it's a struct gl_context in dri_util.c.  Instead provide a helper function
> to set the struct gl_context flags from the incoming DRI context flags.
>
> Signed-off-by: Kristian Høgsberg <krh at bitplanet.net>
> Cc: "10.0" <mesa-stable at lists.freedesktop.org>
>
> ---
>  src/mesa/drivers/dri/common/dri_util.c  | 11 +++++++----
>  src/mesa/drivers/dri/common/dri_util.h  |  3 +++
>  src/mesa/drivers/dri/i965/brw_context.c |  2 ++
>  3 files changed, 12 insertions(+), 4 deletions(-)
>
> I'd suggest something like this... I haven't verified that it actually fixes
> the problem, I just wanted to illustrate what the fix would look like and
> ended up writing the full patch after all.

Tested-by: Ilia Mirkin <imirkin at alum.mit.edu>

Verified that without this patch valgrind complains and glretrace
crashes. With this patch, all is well. (using nv50 gallium driver)

>
> Kristian
>
> diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c
> index 0bce77e..9134a94 100644
> --- a/src/mesa/drivers/dri/common/dri_util.c
> +++ b/src/mesa/drivers/dri/common/dri_util.c
> @@ -438,16 +438,19 @@ driCreateContextAttribs(__DRIscreen *screen, int api,
>          return NULL;
>      }
>
> -    struct gl_context *ctx = context->driverPrivate;
> +    *error = __DRI_CTX_ERROR_SUCCESS;
> +    return context;
> +}
> +
> +void
> +driContextSetFlags(struct gl_context *ctx, uint32_t flags)
> +{
>      if ((flags & __DRI_CTX_FLAG_FORWARD_COMPATIBLE) != 0)
>          ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
>      if ((flags & __DRI_CTX_FLAG_DEBUG) != 0) {
>          ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_DEBUG_BIT;
>          ctx->Debug.DebugOutput = GL_TRUE;
>      }
> -
> -    *error = __DRI_CTX_ERROR_SUCCESS;
> -    return context;
>  }
>
>  static __DRIcontext *
> diff --git a/src/mesa/drivers/dri/common/dri_util.h b/src/mesa/drivers/dri/common/dri_util.h
> index 79a8564..35f674e 100644
> --- a/src/mesa/drivers/dri/common/dri_util.h
> +++ b/src/mesa/drivers/dri/common/dri_util.h
> @@ -289,6 +289,9 @@ dri2InvalidateDrawable(__DRIdrawable *drawable);
>  extern void
>  driUpdateFramebufferSize(struct gl_context *ctx, const __DRIdrawable *dPriv);
>
> +extern void
> +driContextSetFlags(struct gl_context *ctx, uint32_t flags);
> +
>  extern const __DRIimageDriverExtension driImageDriverExtension;
>
>  #endif /* _DRI_UTIL_H_ */
> diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
> index 6de6759..46ae086 100644
> --- a/src/mesa/drivers/dri/i965/brw_context.c
> +++ b/src/mesa/drivers/dri/i965/brw_context.c
> @@ -631,6 +631,8 @@ brwCreateContext(gl_api api,
>        return false;
>     }
>
> +   driContextSetFlags(ctx, flags);
> +
>     /* Initialize the software rasterizer and helper modules.
>      *
>      * As of GL 3.1 core, the gen4+ driver doesn't need the swrast context for
> --
> 1.8.3.1
>


More information about the mesa-dev mailing list