[Mesa-dev] [PATCH] mesa, st/glx, st/wgl: Move GL version validation into an helper.

Jose Fonseca jfonseca at vmware.com
Fri Nov 14 12:40:53 PST 2014


> Is it OK to depend on mesa/main from state trackers? (other than the GL state tracker, obviously)

No, not in general. It's only because these two state trackers are GL state trackers, and already depend on mesa/main. (The code src/mesa/state_tracker doesn't completely hide classic Mesa internals, and there's no harm in that.)

But a, vega, d3d state tracker, should not depend on mesa/main.  I think noawadays the place for putting code that should be used by gallium and mesa is src/util..

Jose 


________________________________________
From: ibmirkin at gmail.com <ibmirkin at gmail.com> on behalf of Ilia Mirkin <imirkin at alum.mit.edu>
Sent: 14 November 2014 20:36
To: Jose Fonseca
Cc: mesa-dev at lists.freedesktop.org; Brian Paul
Subject: Re: [Mesa-dev] [PATCH] mesa, st/glx, st/wgl: Move GL version validation into an helper.

On Fri, Nov 14, 2014 at 3:33 PM,  <jfonseca at vmware.com> wrote:
> From: José Fonseca <jfonseca at vmware.com>
>
> As suggested by Brian Paul.
>
> Tested with piglit glx-create-context-invalid-{gl,es}-version.
> ---
>  src/gallium/state_trackers/glx/xlib/glx_api.c    | 13 +++-------
>  src/gallium/state_trackers/wgl/stw_ext_context.c | 13 +++-------
>  src/mesa/main/version.c                          | 33 ++++++++++++++++++++++++
>  src/mesa/main/version.h                          |  6 +++++
>  4 files changed, 47 insertions(+), 18 deletions(-)

Is it OK to depend on mesa/main from state trackers? (other than the
GL state tracker, obviously)

>
> diff --git a/src/gallium/state_trackers/glx/xlib/glx_api.c b/src/gallium/state_trackers/glx/xlib/glx_api.c
> index 1807edb..d4e028c 100644
> --- a/src/gallium/state_trackers/glx/xlib/glx_api.c
> +++ b/src/gallium/state_trackers/glx/xlib/glx_api.c
> @@ -36,6 +36,8 @@
>  #include <X11/Xmd.h>
>  #include <GL/glxproto.h>
>
> +#include "main/version.h"
> +
>  #include "xm_api.h"
>
>
> @@ -2792,19 +2794,12 @@ glXCreateContextAttribsARB(Display *dpy, GLXFBConfig config,
>     if (majorVersion <= 0 ||
>         minorVersion < 0 ||
>         (profileMask != GLX_CONTEXT_ES_PROFILE_BIT_EXT &&
> -        ((majorVersion == 1 && minorVersion > 5) ||
> -         (majorVersion == 2 && minorVersion > 1) ||
> -         (majorVersion == 3 && minorVersion > 3) ||
> -         (majorVersion == 4 && minorVersion > 5) ||
> -         majorVersion > 4))) {
> +        !_mesa_is_valid_version(majorVersion, minorVersion))) {
>        generate_error(dpy, BadMatch, 0, X_GLXCreateContextAtrribsARB, True);
>        return NULL;
>     }
>     if (profileMask == GLX_CONTEXT_ES_PROFILE_BIT_EXT &&
> -       ((majorVersion == 1 && minorVersion > 1) ||
> -        (majorVersion == 2 && minorVersion > 0) ||
> -        (majorVersion == 3 && minorVersion > 1) ||
> -        majorVersion > 3)) {
> +       !_mesa_is_valid_es_version(majorVersion, minorVersion)) {
>        /* GLX_EXT_create_context_es2_profile says nothing to justifying a
>         * different error code for invalid ES versions, but this is what NVIDIA
>         * does and piglit expects.
> diff --git a/src/gallium/state_trackers/wgl/stw_ext_context.c b/src/gallium/state_trackers/wgl/stw_ext_context.c
> index 8a96cac..ee46334 100644
> --- a/src/gallium/state_trackers/wgl/stw_ext_context.c
> +++ b/src/gallium/state_trackers/wgl/stw_ext_context.c
> @@ -30,6 +30,8 @@
>  #include <GL/gl.h>
>  #include <GL/wglext.h>
>
> +#include "main/version.h"
> +
>  #include "stw_icd.h"
>  #include "stw_context.h"
>  #include "stw_device.h"
> @@ -114,16 +116,9 @@ wglCreateContextAttribsARB(HDC hDC, HGLRC hShareContext, const int *attribList)
>     if (majorVersion <= 0 ||
>         minorVersion < 0 ||
>         (profileMask != WGL_CONTEXT_ES_PROFILE_BIT_EXT &&
> -        ((majorVersion == 1 && minorVersion > 5) ||
> -         (majorVersion == 2 && minorVersion > 1) ||
> -         (majorVersion == 3 && minorVersion > 3) ||
> -         (majorVersion == 4 && minorVersion > 5) ||
> -         majorVersion > 4)) ||
> +        !_mesa_is_valid_version(majorVersion, minorVersion)) ||
>         (profileMask == WGL_CONTEXT_ES_PROFILE_BIT_EXT &&
> -        ((majorVersion == 1 && minorVersion > 1) ||
> -         (majorVersion == 2 && minorVersion > 0) ||
> -         (majorVersion == 3 && minorVersion > 1) ||
> -         majorVersion > 3))) {
> +        !_mesa_is_valid_es_version(majorVersion, minorVersion))) {
>        SetLastError(ERROR_INVALID_VERSION_ARB);
>        return NULL;
>     }
> diff --git a/src/mesa/main/version.c b/src/mesa/main/version.c
> index 4951891..5bdef16 100644
> --- a/src/mesa/main/version.c
> +++ b/src/mesa/main/version.c
> @@ -460,3 +460,36 @@ _mesa_compute_version(struct gl_context *ctx)
>        break;
>     }
>  }
> +
> +
> +GLboolean
> +_mesa_is_valid_version(int major, int minor)
> +{
> +   static const char max_minor_version[] = {
> +      /* 1 . */ 5,
> +      /* 2 . */ 1,
> +      /* 3 . */ 3,
> +      /* 4 . */ 5,
> +   };
> +
> +   return (major >= 0 &&
> +           major < sizeof max_minor_version &&
> +           minor >= 0 &&
> +           minor <= max_minor_version[major - 1]);
> +}
> +
> +
> +GLboolean
> +_mesa_is_valid_es_version(int major, int minor)
> +{
> +   static const char max_minor_version[] = {
> +      /* 1 . */ 1,
> +      /* 2 . */ 0,
> +      /* 3 . */ 1,
> +   };
> +
> +   return (major >= 0 &&
> +           major < sizeof max_minor_version &&
> +           minor >= 0 &&
> +           minor <= max_minor_version[major - 1]);
> +}
> diff --git a/src/mesa/main/version.h b/src/mesa/main/version.h
> index 450a0e3..e2e1fc2 100644
> --- a/src/mesa/main/version.h
> +++ b/src/mesa/main/version.h
> @@ -50,4 +50,10 @@ _mesa_override_glsl_version(struct gl_constants *consts);
>  extern int
>  _mesa_get_gl_version_override(void);
>
> +extern GLboolean
> +_mesa_is_valid_version(int major, int minor);
> +
> +extern GLboolean
> +_mesa_is_valid_es_version(int major, int minor);
> +
>  #endif /* VERSION_H */
> --
> 2.1.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.freedesktop.org_mailman_listinfo_mesa-2Ddev&d=AAIFaQ&c=Sqcl0Ez6M0X8aeM67LKIiDJAXVeAw-YihVMNtXt-uEs&r=zfmBZnnVGHeYde45pMKNnVyzeaZbdIqVLprmZCM2zzE&m=LEU_PTYFT1dtiPV53wdDhy73cR7ILnd7bmfa7LxqLk0&s=ay8IZCyk7leqplKIV6RLnh6qOOUQpjrVXIJdfadtJ04&e=


More information about the mesa-dev mailing list