xserver: Branch 'master' - 8 commits

Keith Packard keithp at kemper.freedesktop.org
Thu Jul 5 11:54:38 PDT 2012


 glx/clientinfo.c       |   27 +++++++++----
 glx/createcontext.c    |  101 ++++++++++++++++++++++++++++++++++++++++++++++++-
 glx/extension_string.c |    2 
 glx/extension_string.h |    2 
 glx/glxcmds.c          |   10 ++++
 glx/glxcontext.h       |    5 ++
 glx/glxdri2.c          |   97 +++++++++++++++++++++++++++++++++++++++++++++--
 7 files changed, 232 insertions(+), 12 deletions(-)

New commits:
commit ed6daa15a7dcf8dba930f67401f4c1c8ca2e6fac
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Jul 4 15:21:09 2012 -0700

    glx/dri2: Enable GLX_ARB_create_context_robustness
    
    If the driver supports __DRI2_ROBUSTNESS, then enable
    GLX_ARB_create_cotnext_robustness as well.  If robustness values are
    passed to glXCreateContextAttribsARB and the driver doesn't support
    __DRI2_ROBUSTNESS, existing drivers will already generate the correct
    error values (so that the correct GLX errors are generated).
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index 8210a2b..1e99179 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -59,6 +59,16 @@ typedef struct __GLXDRIscreen __GLXDRIscreen;
 typedef struct __GLXDRIcontext __GLXDRIcontext;
 typedef struct __GLXDRIdrawable __GLXDRIdrawable;
 
+
+#ifdef __DRI2_ROBUSTNESS
+#define ALL_DRI_CTX_FLAGS (__DRI_CTX_FLAG_DEBUG                         \
+                           | __DRI_CTX_FLAG_FORWARD_COMPATIBLE          \
+                           | __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS)
+#else
+#define ALL_DRI_CTX_FLAGS (__DRI_CTX_FLAG_DEBUG                         \
+                           | __DRI_CTX_FLAG_FORWARD_COMPATIBLE)
+#endif
+
 struct __GLXDRIscreen {
     __GLXscreen base;
     __DRIscreen *driScreen;
@@ -381,7 +391,7 @@ __glXDRIscreenDestroy(__GLXscreen * baseScreen)
 static Bool
 dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
                          unsigned *major_ver, unsigned *minor_ver,
-                         uint32_t *flags, int *api, unsigned *error)
+                         uint32_t *flags, int *api, int *reset, unsigned *error)
 {
     unsigned i;
 
@@ -395,6 +405,11 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
 
     *major_ver = 1;
     *minor_ver = 0;
+#ifdef __DRI2_ROBUSTNESS
+    *reset = __DRI_CTX_RESET_NO_NOTIFICATION;
+#else
+    (void) reset;
+#endif
 
     for (i = 0; i < num_attribs; i++) {
         switch (attribs[i * 2]) {
@@ -425,6 +440,26 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
                 return False;
             }
             break;
+#ifdef __DRI2_ROBUSTNESS
+        case GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB:
+            if (screen->dri2->base.version >= 4) {
+                *error = BadValue;
+                return False;
+            }
+
+            switch (attribs[i * 2 + 1]) {
+            case GLX_NO_RESET_NOTIFICATION_ARB:
+                *reset = __DRI_CTX_RESET_NO_NOTIFICATION;
+                break;
+            case GLX_LOSE_CONTEXT_ON_RESET_ARB:
+                *reset = __DRI_CTX_RESET_LOSE_CONTEXT;
+                break;
+            default:
+                *error = BadValue;
+                return False;
+            }
+            break;
+#endif
         default:
             /* If an unknown attribute is received, fail.
              */
@@ -435,7 +470,7 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
 
     /* Unknown flag value.
      */
-    if (*flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_FORWARD_COMPATIBLE)) {
+    if ((*flags & ~ALL_DRI_CTX_FLAGS) != 0) {
         *error = BadValue;
         return False;
     }
@@ -473,12 +508,14 @@ create_driver_context(__GLXDRIcontext * context,
         unsigned major_ver;
         unsigned minor_ver;
         uint32_t flags;
+        int reset;
         int api;
 
         if (num_attribs != 0) {
             if (!dri2_convert_glx_attribs(num_attribs, attribs,
                                           &major_ver, &minor_ver,
-                                          &flags, &api, (unsigned *) error))
+                                          &flags, &api, &reset,
+                                          (unsigned *) error))
                 return NULL;
 
             ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_MAJOR_VERSION;
@@ -494,6 +531,14 @@ create_driver_context(__GLXDRIcontext * context,
                  */
                 ctx_attribs[num_ctx_attribs++] = flags;
             }
+
+#ifdef __DRI2_ROBUSTNESS
+            if (reset != __DRI_CTX_NO_RESET_NOTIFICATION) {
+                ctx_attribs[num_ctx_attribs++] =
+                    __DRI_CTX_ATTRIB_RESET_NOTIFICATION;
+                ctx_attribs[num_ctx_attribs++] = reset;
+            }
+#endif
         }
 
         context->driContext =
@@ -857,6 +902,16 @@ initializeExtensions(__GLXDRIscreen * screen)
         }
 #endif
 
+#ifdef __DRI2_ROBUSTNESS
+        if (strcmp(extensions[i]->name, __DRI2_ROBUSTNESS) == 0 &&
+            screen->dri2->base.version >= 3) {
+            __glXEnableExtension(screen->glx_enable_bits,
+                                 "GLX_ARB_create_context_robustness");
+            LogMessage(X_INFO,
+                       "AIGLX: enabled GLX_ARB_create_context_robustness\n");
+        }
+#endif
+
         /* Ignore unknown extensions */
     }
 }
commit 90aa2486e394c0344aceb2a70432761665a79333
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Jul 4 15:21:08 2012 -0700

    glx: Allow attributes and flags from GLX_ARB_create_context_robustness
    
    The assumtion is that if the underlying provider (e.g., glxdri2.c) doesn't
    support this extension, it will generate BadMatch for these flags and
    attributes.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/createcontext.c b/glx/createcontext.c
index 7d653e9..13d21cc 100644
--- a/glx/createcontext.c
+++ b/glx/createcontext.c
@@ -30,7 +30,8 @@
 #include "indirect_dispatch.h"
 
 #define ALL_VALID_FLAGS \
-    (GLX_CONTEXT_DEBUG_BIT_ARB | GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB)
+    (GLX_CONTEXT_DEBUG_BIT_ARB | GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB \
+     | GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB)
 
 static Bool
 validate_GL_version(int major_version, int minor_version)
@@ -183,6 +184,14 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
             profile = attribs[2 * i + 1];
             break;
 
+        case GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB:
+            reset = attribs[2 * i + 1];
+            if (reset != GLX_NO_RESET_NOTIFICATION_ARB
+                && reset != GLX_LOSE_CONTEXT_ON_RESET_ARB)
+                return BadValue;
+
+            break;
+
         default:
             return BadValue;
         }
commit aef0b4593e165634ca7fa0745882dad12a54ebed
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Jul 4 15:21:07 2012 -0700

    glx: Track the reset notification strategy for a context
    
    Also require that the reset notification for a new context and the other
    context in the share group match.  There isn't yet any way to specify a
    non-default reset notification strategy, but that will come.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/createcontext.c b/glx/createcontext.c
index 205a919..7d653e9 100644
--- a/glx/createcontext.c
+++ b/glx/createcontext.c
@@ -90,6 +90,13 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
     __GLXconfig *config;
     int err;
 
+    /* The GLX_ARB_create_context_robustness spec says:
+     *
+     *     "The default value for GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB
+     *     is GLX_NO_RESET_NOTIFICATION_ARB."
+     */
+    int reset = GLX_NO_RESET_NOTIFICATION_ARB;
+
     /* The GLX_ARB_create_context_profile spec says:
      *
      *     "The default value for GLX_CONTEXT_PROFILE_MASK_ARB is
@@ -259,6 +266,14 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
         return __glXError(GLXBadProfileARB);
     }
 
+    /* The GLX_ARB_create_context_robustness spec says:
+     *
+     *     "* If the reset notification behavior of <share_context> and the
+     *        newly created context are different, BadMatch is generated."
+     */
+    if (shareCtx != NULL && shareCtx->resetNotificationStrategy != reset)
+        return BadMatch;
+
     /* There is no GLX protocol for desktop OpenGL versions after 1.4.  There
      * is no GLX protocol for any version of OpenGL ES.  If the application is
      * requested an indirect rendering context for a version that cannot be
@@ -306,6 +321,7 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
     ctx->selectBufSize = 0;
     ctx->drawPriv = NULL;
     ctx->readPriv = NULL;
+    ctx->resetNotificationStrategy = reset;
 
     /* Add the new context to the various global tables of GLX contexts.
      */
diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index d483bbf..d054219 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -308,6 +308,16 @@ DoCreateContext(__GLXclientState * cl, GLXContextID gcId,
     glxc->drawPriv = NULL;
     glxc->readPriv = NULL;
 
+    /* The GLX_ARB_create_context_robustness spec says:
+     *
+     *     "The default value for GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB
+     *     is GLX_NO_RESET_NOTIFICATION_ARB."
+     *
+     * Without using glXCreateContextAttribsARB, there is no way to specify a
+     * non-default reset notification strategy.
+     */
+    glxc->resetNotificationStrategy = GLX_NO_RESET_NOTIFICATION_ARB;
+
     /* Add the new context to the various global tables of GLX contexts.
      */
     if (!__glXAddContext(glxc)) {
diff --git a/glx/glxcontext.h b/glx/glxcontext.h
index b803a7f..4764e56 100644
--- a/glx/glxcontext.h
+++ b/glx/glxcontext.h
@@ -104,6 +104,11 @@ struct __GLXcontext {
      */
     GLenum renderMode;
 
+    /**
+     * Reset notification strategy used when a GPU reset occurs.
+     */
+    GLenum resetNotificationStrategy;
+
     /*
      ** Buffers for feedback and selection.
      */
commit f8198285cfc4704bc4d56922e5a2e99030a83778
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Jul 4 15:21:06 2012 -0700

    glx: Add extension string tracking for GLX_ARB_create_context_robustness
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/extension_string.c b/glx/extension_string.c
index 2d550a9..ee9864e 100644
--- a/glx/extension_string.c
+++ b/glx/extension_string.c
@@ -70,6 +70,7 @@ static const struct extension_info known_glx_extensions[] = {
     /* *INDENT-OFF* */
     { GLX(ARB_create_context),          VER(0,0), N, },
     { GLX(ARB_create_context_profile),  VER(0,0), N, },
+    { GLX(ARB_create_context_robustness), VER(0,0), N, },
     { GLX(ARB_multisample),             VER(1,4), Y, },
 
     { GLX(EXT_create_context_es2_profile), VER(0,0), N, },
diff --git a/glx/extension_string.h b/glx/extension_string.h
index 1704696..7a4a8b1 100644
--- a/glx/extension_string.h
+++ b/glx/extension_string.h
@@ -38,6 +38,7 @@ enum {
 /*   GLX_ARB_get_proc_address is implemented on the client. */
     ARB_create_context_bit = 0,
     ARB_create_context_profile_bit,
+    ARB_create_context_robustness_bit,
     ARB_multisample_bit,
     EXT_create_context_es2_profile_bit,
     EXT_import_context_bit,
commit 4ffbc984eac8a15925094614021de30dc8084e65
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Jul 4 15:21:05 2012 -0700

    glx: Reject creations of indirect contexts with unsupportable versions.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/createcontext.c b/glx/createcontext.c
index 2ba0e18..205a919 100644
--- a/glx/createcontext.c
+++ b/glx/createcontext.c
@@ -259,6 +259,23 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
         return __glXError(GLXBadProfileARB);
     }
 
+    /* There is no GLX protocol for desktop OpenGL versions after 1.4.  There
+     * is no GLX protocol for any version of OpenGL ES.  If the application is
+     * requested an indirect rendering context for a version that cannot be
+     * satisfied, reject it.
+     *
+     * The GLX_ARB_create_context spec says:
+     *
+     *     "* If <config> does not support compatible OpenGL contexts
+     *        providing the requested API major and minor version,
+     *        forward-compatible flag, and debug context flag, GLXBadFBConfig
+     *        is generated."
+     */
+    if (!req->isDirect && (major_version > 1 || minor_version > 4
+                           || profile == GLX_CONTEXT_ES2_PROFILE_BIT_EXT)) {
+        return __glXError(GLXBadFBConfig);
+    }
+
     /* Allocate memory for the new context
      */
     if (req->isDirect) {
commit 41d5120eaf2bdf308eb904cac9b5027b003fea8d
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Jul 4 15:21:04 2012 -0700

    glx: Implement GLX_EXT_create_context_es2_profile
    
    This patch builds on the infrastucture put in place for
    GLX_ARB_create_context_profile.  If GLX_CONTEXT_ES2_PROFILE_BIT_EXT is
    specified and the requested version is 2.0, create a context with the
    __DRI_API_GLES2 API.
    
    This change assumes that any DRI2 driver can handle (possibly by saying "no
    seeing an API setting other than __DRI_API_OPENGL or __DRI_API_OPENGL_CORE.
    This allows enabling the extension any time GLX_ARB_create_context (and
    GLX_ARB_create_context_profile) is enabled.
    
    v2: Clean up some comments.  Note that our behavior for
    GLX_CONTEXT_ES2_PROFILE_BIT_EXT w/version != 2.0 matches NVIDIA's.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/createcontext.c b/glx/createcontext.c
index 6f580f0..2ba0e18 100644
--- a/glx/createcontext.c
+++ b/glx/createcontext.c
@@ -229,6 +229,32 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
     case GLX_CONTEXT_CORE_PROFILE_BIT_ARB:
     case GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB:
         break;
+    case GLX_CONTEXT_ES2_PROFILE_BIT_EXT:
+        /* The GLX_EXT_create_context_es2_profile spec says:
+         *
+         *     "... If the version requested is 2.0, and the
+         *     GLX_CONTEXT_ES2_PROFILE_BIT_EXT bit is set in the
+         *     GLX_CONTEXT_PROFILE_MASK_ARB attribute (see below), then the
+         *     context returned will implement OpenGL ES 2.0."
+         *
+         * It also says:
+         *
+         *     "* If attribute GLX_CONTEXT_PROFILE_MASK_ARB has no bits set;
+         *        has any bits set other than
+         *        GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
+         *        GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, or
+         *        GLX_CONTEXT_ES2_PROFILE_BIT_EXT; has more than one of these
+         *        bits set; or if the implementation does not supported the
+         *        requested profile, then GLXBadProfileARB is generated."
+         *
+         * It does not specifically say what is supposed to happen if
+         * GLX_CONTEXT_ES2_PROFILE_BIT_EXT is set but the version requested is
+         * not 2.0.  We choose to generate GLXBadProfileARB as this matches
+         * NVIDIA's behavior.
+         */
+        if (major_version != 2 || minor_version != 0)
+            return __glXError(GLXBadProfileARB);
+        break;
     default:
         return __glXError(GLXBadProfileARB);
     }
diff --git a/glx/extension_string.c b/glx/extension_string.c
index 6a1a6c6..2d550a9 100644
--- a/glx/extension_string.c
+++ b/glx/extension_string.c
@@ -72,6 +72,7 @@ static const struct extension_info known_glx_extensions[] = {
     { GLX(ARB_create_context_profile),  VER(0,0), N, },
     { GLX(ARB_multisample),             VER(1,4), Y, },
 
+    { GLX(EXT_create_context_es2_profile), VER(0,0), N, },
     { GLX(EXT_import_context),          VER(0,0), Y, },
     { GLX(EXT_texture_from_pixmap),     VER(0,0), Y, },
     { GLX(EXT_visual_info),             VER(0,0), Y, },
diff --git a/glx/extension_string.h b/glx/extension_string.h
index 947bf89..1704696 100644
--- a/glx/extension_string.h
+++ b/glx/extension_string.h
@@ -39,6 +39,7 @@ enum {
     ARB_create_context_bit = 0,
     ARB_create_context_profile_bit,
     ARB_multisample_bit,
+    EXT_create_context_es2_profile_bit,
     EXT_import_context_bit,
     EXT_texture_from_pixmap_bit,
     EXT_visual_info_bit,
diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index 7ec4337..8210a2b 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -417,6 +417,9 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
             case GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB:
                 *api = __DRI_API_OPENGL;
                 break;
+            case GLX_CONTEXT_ES2_PROFILE_BIT_EXT:
+                *api = __DRI_API_GLES2;
+                break;
             default:
                 *error = __glXError(GLXBadProfileARB);
                 return False;
@@ -812,8 +815,12 @@ initializeExtensions(__GLXDRIscreen * screen)
                              "GLX_ARB_create_context");
         __glXEnableExtension(screen->glx_enable_bits,
                              "GLX_ARB_create_context_profile");
+        __glXEnableExtension(screen->glx_enable_bits,
+                             "GLX_EXT_create_context_es2_profile");
         LogMessage(X_INFO, "AIGLX: enabled GLX_ARB_create_context\n");
         LogMessage(X_INFO, "AIGLX: enabled GLX_ARB_create_context_profile\n");
+        LogMessage(X_INFO,
+                   "AIGLX: enabled GLX_EXT_create_context_es2_profile\n");
     }
 #endif
 
commit cef0b808d3152a20cd98d32457dde08bd5434e7c
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Jul 4 15:21:03 2012 -0700

    glx: Implement GLX_ARB_create_context_profile
    
    Most of the infrastructure was already in place.  This just adds:
    
        * Validate values specified with the GLX_CONTEXT_PROFILE_MASK_ARB
          attribute.
    
        * Select a DRI2 "api" based on the setting of
          GLX_CONTEXT_PROFILE_MASK_ARB.
    
        * Enable GLX_ARB_create_context_profile extension.
    
    This change assumes that any DRI2 driver can handle (possibly by saying "no")
    seeing an API setting other than __DRI_API_OPENGL.  This allows enabling this
    extension any time GLX_ARB_create_context is enabled.
    
    Also, the validation code in __glXDisp_CreateContextAttribsARB is structured
    in a very verbose manner (using a switch-statement) to ease the addition of
    GLX_EXT_create_context_es2_profile.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/createcontext.c b/glx/createcontext.c
index 025c423..6f580f0 100644
--- a/glx/createcontext.c
+++ b/glx/createcontext.c
@@ -90,6 +90,17 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
     __GLXconfig *config;
     int err;
 
+    /* The GLX_ARB_create_context_profile spec says:
+     *
+     *     "The default value for GLX_CONTEXT_PROFILE_MASK_ARB is
+     *     GLX_CONTEXT_CORE_PROFILE_BIT_ARB."
+     *
+     * The core profile only makes sense for OpenGL versions 3.2 and later.
+     * If the version ultimately specified is less than 3.2, the core profile
+     * bit is cleared (see below).
+     */
+    int profile = GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
+
     /* Verify that the size of the packet matches the size inferred from the
      * sizes specified for the various fields.
      */
@@ -161,6 +172,10 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
             render_type = attribs[2 * i + 1];
             break;
 
+        case GLX_CONTEXT_PROFILE_MASK_ARB:
+            profile = attribs[2 * i + 1];
+            break;
+
         default:
             return BadValue;
         }
@@ -202,6 +217,22 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
     if ((flags & ~ALL_VALID_FLAGS) != 0)
         return BadValue;
 
+    /* The GLX_ARB_create_context_profile spec says:
+     *
+     *     "* If attribute GLX_CONTEXT_PROFILE_MASK_ARB has no bits set; has
+     *        any bits set other than GLX_CONTEXT_CORE_PROFILE_BIT_ARB and
+     *        GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; has more than one of
+     *        these bits set; or if the implementation does not support the
+     *        requested profile, then GLXBadProfileARB is generated."
+     */
+    switch (profile) {
+    case GLX_CONTEXT_CORE_PROFILE_BIT_ARB:
+    case GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB:
+        break;
+    default:
+        return __glXError(GLXBadProfileARB);
+    }
+
     /* Allocate memory for the new context
      */
     if (req->isDirect) {
diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index 7b76c3a..7ec4337 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -381,7 +381,7 @@ __glXDRIscreenDestroy(__GLXscreen * baseScreen)
 static Bool
 dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
                          unsigned *major_ver, unsigned *minor_ver,
-                         uint32_t *flags, unsigned *error)
+                         uint32_t *flags, int *api, unsigned *error)
 {
     unsigned i;
 
@@ -409,6 +409,19 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
             break;
         case GLX_RENDER_TYPE:
             break;
+        case GLX_CONTEXT_PROFILE_MASK_ARB:
+            switch (attribs[i * 2 + 1]) {
+            case GLX_CONTEXT_CORE_PROFILE_BIT_ARB:
+                *api = __DRI_API_OPENGL_CORE;
+                break;
+            case GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB:
+                *api = __DRI_API_OPENGL;
+                break;
+            default:
+                *error = __glXError(GLXBadProfileARB);
+                return False;
+            }
+            break;
         default:
             /* If an unknown attribute is received, fail.
              */
@@ -424,6 +437,16 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
         return False;
     }
 
+    /* If the core profile is requested for a GL version is less than 3.2,
+     * request the non-core profile from the DRI driver.  The core profile
+     * only makes sense for GL versions >= 3.2, and many DRI drivers that
+     * don't support OpenGL 3.2 may fail the request for a core profile.
+     */
+    if (*api == __DRI_API_OPENGL_CORE
+        && (*major_ver < 3 || (*major_ver < 3 && *minor_ver < 2))) {
+        *api == __DRI_API_OPENGL;
+    }
+
     *error = Success;
     return True;
 }
@@ -447,11 +470,12 @@ create_driver_context(__GLXDRIcontext * context,
         unsigned major_ver;
         unsigned minor_ver;
         uint32_t flags;
+        int api;
 
         if (num_attribs != 0) {
             if (!dri2_convert_glx_attribs(num_attribs, attribs,
                                           &major_ver, &minor_ver,
-                                          &flags, (unsigned *) error))
+                                          &flags, &api, (unsigned *) error))
                 return NULL;
 
             ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_MAJOR_VERSION;
@@ -471,7 +495,7 @@ create_driver_context(__GLXDRIcontext * context,
 
         context->driContext =
             (*screen->dri2->createContextAttribs)(screen->driScreen,
-                                                  __DRI_API_OPENGL,
+                                                  api,
                                                   config->driConfig,
                                                   driShare,
                                                   num_ctx_attribs / 2,
@@ -786,7 +810,10 @@ initializeExtensions(__GLXDRIscreen * screen)
     if (screen->dri2->base.version >= 3) {
         __glXEnableExtension(screen->glx_enable_bits,
                              "GLX_ARB_create_context");
+        __glXEnableExtension(screen->glx_enable_bits,
+                             "GLX_ARB_create_context_profile");
         LogMessage(X_INFO, "AIGLX: enabled GLX_ARB_create_context\n");
+        LogMessage(X_INFO, "AIGLX: enabled GLX_ARB_create_context_profile\n");
     }
 #endif
 
commit 09a8a169d5929665778ae33e58e345fe1192b64c
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Jul 4 15:21:02 2012 -0700

    glx: Implement GLX SetClientInfo2ARB protocol
    
    The protocol is almost identical to SetClientInfoARB.  The only
    difference is the GL versions include an extra 4 bytes for the supported
    profile.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/clientinfo.c b/glx/clientinfo.c
index b26ac1a..4aaa4c9 100644
--- a/glx/clientinfo.c
+++ b/glx/clientinfo.c
@@ -29,10 +29,10 @@
 #include "glxbyteorder.h"
 #include "unpack.h"
 
-int
-__glXDisp_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc)
+static int
+set_client_info(__GLXclientState * cl, xGLXSetClientInfoARBReq * req,
+                unsigned bytes_per_version)
 {
-    xGLXSetClientInfoARBReq *req = (xGLXSetClientInfoARBReq *) pc;
     char *gl_extensions;
     char *glx_extensions;
 
@@ -40,7 +40,7 @@ __glXDisp_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc)
      * sizes specified for the various fields.
      */
     const unsigned expected_size = sz_xGLXSetClientInfoARBReq
-        + (req->numVersions * 8)
+        + (req->numVersions * bytes_per_version)
         + __GLX_PAD(req->numGLExtensionBytes)
         + __GLX_PAD(req->numGLXExtensionBytes);
 
@@ -50,7 +50,7 @@ __glXDisp_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc)
     /* Verify that the actual length of the GL extension string matches what's
      * encoded in protocol packet.
      */
-    gl_extensions = (char *) (req + 1) + (req->numVersions * 8);
+    gl_extensions = (char *) (req + 1) + (req->numVersions * bytes_per_version);
     if (req->numGLExtensionBytes != 0
         && memchr(gl_extensions, 0,
                   __GLX_PAD(req->numGLExtensionBytes)) == NULL)
@@ -72,6 +72,12 @@ __glXDisp_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc)
 }
 
 int
+__glXDisp_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc)
+{
+    return set_client_info(cl, (xGLXSetClientInfoARBReq *) pc, 8);
+}
+
+int
 __glXDispSwap_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc)
 {
     xGLXSetClientInfoARBReq *req = (xGLXSetClientInfoARBReq *) pc;
@@ -87,11 +93,18 @@ __glXDispSwap_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDisp_SetClientInfo2ARB(__GLXclientState * cl, GLbyte * pc)
 {
-    return BadRequest;
+    return set_client_info(cl, (xGLXSetClientInfoARBReq *) pc, 12);
 }
 
 int
 __glXDispSwap_SetClientInfo2ARB(__GLXclientState * cl, GLbyte * pc)
 {
-    return BadRequest;
+    xGLXSetClientInfoARBReq *req = (xGLXSetClientInfoARBReq *) pc;
+
+    req->length = bswap_16(req->length);
+    req->numVersions = bswap_32(req->numVersions);
+    req->numGLExtensionBytes = bswap_32(req->numGLExtensionBytes);
+    req->numGLXExtensionBytes = bswap_32(req->numGLXExtensionBytes);
+
+    return __glXDisp_SetClientInfo2ARB(cl, pc);
 }


More information about the xorg-commit mailing list