glx: add support for GLX_ARB_create_context_no_error (v3)
authorGrigori Goronzy <greg@chown.ath.cx>
Thu, 3 Aug 2017 18:07:58 +0000 (20:07 +0200)
committerAdam Jackson <ajax@redhat.com>
Tue, 12 Mar 2019 23:12:21 +0000 (19:12 -0400)
v2: Only reject no-error contexts for too-old GL if we're actually
trying to create a no-error context (Adam Jackson)
v3: Fix share contexts (Adam Jackson)

Reviewed-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/glx/dri2_glx.c
src/glx/dri3_glx.c
src/glx/dri_common.c
src/glx/dri_common.h
src/glx/drisw_glx.c
src/glx/glxclient.h
src/glx/glxextensions.c
src/glx/glxextensions.h

index d8c5ba25f04e8533a916f21ec8150dadd8e642fe..d6a543c8da0c5361808272b84354bd90b84bbe78 100644 (file)
@@ -263,6 +263,10 @@ dri2_create_context_attribs(struct glx_screen *base,
                                  &api, &reset, &release, error))
       goto error_exit;
 
+   if (!dri2_check_no_error(flags, shareList, major_ver, error)) {
+      goto error_exit;
+   }
+
    /* Check the renderType value */
    if (!validate_renderType_against_config(config_base, renderType))
        goto error_exit;
@@ -314,6 +318,9 @@ dri2_create_context_attribs(struct glx_screen *base,
     */
    pcp->base.renderType = renderType;
 
+   if (flags & __DRI_CTX_FLAG_NO_ERROR)
+      pcp->base.noError = GL_TRUE;
+
    pcp->driContext =
       (*psc->dri2->createContextAttribs) (psc->driScreen,
                                          api,
@@ -1164,6 +1171,14 @@ dri2BindExtensions(struct dri2_screen *psc, struct glx_display * priv,
          __glXEnableDirectExtension(&psc->base,
                                     "GLX_ARB_create_context_robustness");
 
+      /* DRI2 version 3 is also required because
+       * GLX_ARB_create_context_no_error requires GLX_ARB_create_context.
+       */
+      if (psc->dri2->base.version >= 3
+          && strcmp(extensions[i]->name, __DRI2_NO_ERROR) == 0)
+         __glXEnableDirectExtension(&psc->base,
+                                    "GLX_ARB_create_context_no_error");
+
       /* DRI2 version 3 is also required because GLX_MESA_query_renderer
        * requires GLX_ARB_create_context_profile.
        */
index 298adc80ef162740912fa179595d634d99210a12..9d023341e6b944bb40daf64ff68b6eaef14c128b 100644 (file)
@@ -259,6 +259,10 @@ dri3_create_context_attribs(struct glx_screen *base,
                                  &reset, &release, error))
       goto error_exit;
 
+   if (!dri2_check_no_error(flags, shareList, major_ver, error)) {
+      goto error_exit;
+   }
+
    /* Check the renderType value */
    if (!validate_renderType_against_config(config_base, render_type))
        goto error_exit;
@@ -303,6 +307,9 @@ dri3_create_context_attribs(struct glx_screen *base,
        * GLX_CONTEXT_*_BIT values.
        */
       ctx_attribs[num_ctx_attribs++] = flags;
+
+      if (flags & __DRI_CTX_FLAG_NO_ERROR)
+         pcp->base.noError = GL_TRUE;
    }
 
    pcp->driContext =
@@ -780,6 +787,10 @@ dri3_bind_extensions(struct dri3_screen *psc, struct glx_display * priv,
          __glXEnableDirectExtension(&psc->base,
                                     "GLX_ARB_create_context_robustness");
 
+      if (strcmp(extensions[i]->name, __DRI2_NO_ERROR) == 0)
+         __glXEnableDirectExtension(&psc->base,
+                                    "GLX_ARB_create_context_no_error");
+
       if (strcmp(extensions[i]->name, __DRI2_RENDERER_QUERY) == 0) {
          psc->rendererQuery = (__DRI2rendererQueryExtension *) extensions[i];
          __glXEnableDirectExtension(&psc->base, "GLX_MESA_query_renderer");
index fb8a29f099343ec4cec33d836d3cf96833d20c6f..2db29fd6abbfd4886133a0d5db028308d15e973c 100644 (file)
@@ -427,6 +427,7 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
 {
    unsigned i;
    bool got_profile = false;
+   int no_error = 0;
    uint32_t profile;
 
    *major_ver = 1;
@@ -459,6 +460,9 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
       case GLX_CONTEXT_FLAGS_ARB:
         *flags = attribs[i * 2 + 1];
         break;
+      case GLX_CONTEXT_OPENGL_NO_ERROR_ARB:
+        no_error = attribs[i * 2 + 1];
+        break;
       case GLX_CONTEXT_PROFILE_MASK_ARB:
         profile = attribs[i * 2 + 1];
         got_profile = true;
@@ -500,6 +504,10 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
       }
    }
 
+   if (no_error) {
+      *flags |= __DRI_CTX_FLAG_NO_ERROR;
+   }
+
    if (!got_profile) {
       if (*major_ver > 3 || (*major_ver == 3 && *minor_ver >= 2))
         *api = __DRI_API_OPENGL_CORE;
@@ -540,7 +548,8 @@ 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
-                  | __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS)) {
+                  | __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS
+                  | __DRI_CTX_FLAG_NO_ERROR)) {
       *error = __DRI_CTX_ERROR_UNKNOWN_FLAG;
       return false;
    }
@@ -565,4 +574,45 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
    return true;
 }
 
+_X_HIDDEN bool
+dri2_check_no_error(uint32_t flags, struct glx_context *share_context,
+                    int major, unsigned *error)
+{
+   Bool noError = flags & __DRI_CTX_FLAG_NO_ERROR;
+
+   /* The KHR_no_error specs say:
+    *
+    *    Requires OpenGL ES 2.0 or OpenGL 2.0.
+    */
+   if (noError && major < 2) {
+      *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
+      return false;
+   }
+
+   /* The GLX_ARB_create_context_no_error specs say:
+    *
+    *    BadMatch is generated if the value of GLX_CONTEXT_OPENGL_NO_ERROR_ARB
+    *    used to create <share_context> does not match the value of
+    *    GLX_CONTEXT_OPENGL_NO_ERROR_ARB for the context being created.
+    */
+   if (share_context && !!share_context->noError != !!noError) {
+      *error = __DRI_CTX_ERROR_BAD_FLAG;
+      return false;
+   }
+
+   /* The GLX_ARB_create_context_no_error specs say:
+    *
+    *    BadMatch is generated if the GLX_CONTEXT_OPENGL_NO_ERROR_ARB is TRUE at
+    *    the same time as a debug or robustness context is specified.
+    *
+    */
+   if (noError && ((flags & __DRI_CTX_FLAG_DEBUG) ||
+                   (flags & __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS))) {
+      *error = __DRI_CTX_ERROR_BAD_FLAG;
+      return false;
+   }
+
+   return true;
+}
+
 #endif /* GLX_DIRECT_RENDERING */
index 363f15bf9bb292759c72a807736094459b693e1c..1b74397063be0678a4ecc5bede5dc8593ac82d4b 100644 (file)
@@ -78,4 +78,9 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
                          uint32_t *render_type, uint32_t *flags, unsigned *api,
                          int *reset, int *release, unsigned *error);
 
+extern bool
+dri2_check_no_error(uint32_t flags, struct glx_context *share_context,
+                    int major, unsigned *error);
+
+
 #endif /* _DRI_COMMON_H */
index 48c03ca42e0342b831ce3b8d87fffb6f0cf40341..c63b097a71abe8cd9f85758967fe9a038fe10411 100644 (file)
@@ -599,6 +599,9 @@ drisw_create_context_attribs(struct glx_screen *base,
                                  &api, &reset, &release, error))
       return NULL;
 
+   if (!dri2_check_no_error(flags, shareList, major_ver, error))
+      return NULL;
+
    /* Check the renderType value */
    if (!validate_renderType_against_config(config_base, renderType)) {
        return NULL;
@@ -641,6 +644,9 @@ drisw_create_context_attribs(struct glx_screen *base,
        * GLX_CONTEXT_*_BIT values.
        */
       ctx_attribs[num_ctx_attribs++] = flags;
+
+      if (flags & __DRI_CTX_FLAG_NO_ERROR)
+         pcp->base.noError = GL_TRUE;
    }
 
    pcp->base.renderType = renderType;
index df51f2b8ce4703baae0482e36571d4f8dc2a08d8..3e8274e1c3ab9db0711954b8024e121a650f1cb4 100644 (file)
@@ -437,6 +437,12 @@ struct glx_context
     */
    unsigned long thread_refcount;
 
+   /**
+    * GLX_ARB_create_context_no_error setting for this context.
+    * This needs to be kept here to enforce shared context rules.
+    */
+   Bool noError;
+
    char gl_extension_bits[__GL_EXT_BYTES];
 };
 
index e85a8c928468353bd4bfbdbc73f017b19101362c..f6a7a31a2195dfdf6a7c920c5c06435061c73598 100644 (file)
@@ -134,6 +134,7 @@ struct extension_info
 static const struct extension_info known_glx_extensions[] = {
    { GLX(ARB_context_flush_control),   VER(0,0), Y, N, N, N },
    { GLX(ARB_create_context),          VER(0,0), Y, N, N, N },
+   { GLX(ARB_create_context_no_error), VER(1,4), Y, N, N, N },
    { GLX(ARB_create_context_profile),  VER(0,0), Y, N, N, N },
    { GLX(ARB_create_context_robustness), VER(0,0), Y, N, N, N },
    { GLX(ARB_fbconfig_float),          VER(0,0), Y, Y, N, N },
index c6428d46b4d83990bdb3c3f10780be17fe23ebf7..bbdb00dd63173adebae6fa5a61e018820583e4eb 100644 (file)
@@ -39,6 +39,7 @@ enum
 {
    ARB_context_flush_control_bit = 0,
    ARB_create_context_bit,
+   ARB_create_context_no_error_bit,
    ARB_create_context_profile_bit,
    ARB_create_context_robustness_bit,
    ARB_fbconfig_float_bit,