glx: Implement GLX_ARB_context_flush_control
authorNeil Roberts <neil@linux.intel.com>
Wed, 1 Oct 2014 19:00:48 +0000 (20:00 +0100)
committerAdam Jackson <ajax@redhat.com>
Mon, 6 Nov 2017 21:09:02 +0000 (16:09 -0500)
Reviewed-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Neil Roberts <neil@linux.intel.com>
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/glxextensions.c
src/glx/glxextensions.h

index ae8cb11ef8f38cb09861f188e406ff02ee33b21b..e67a15f9dabddf7e15f55eaed6fa3a08396716f0 100644 (file)
@@ -247,7 +247,8 @@ dri2_create_context_attribs(struct glx_screen *base,
    uint32_t flags;
    unsigned api;
    int reset;
-   uint32_t ctx_attribs[2 * 5];
+   int release;
+   uint32_t ctx_attribs[2 * 6];
    unsigned num_ctx_attribs = 0;
 
    if (psc->dri2->base.version < 3) {
@@ -259,7 +260,7 @@ dri2_create_context_attribs(struct glx_screen *base,
     */
    if (!dri2_convert_glx_attribs(num_attribs, attribs,
                                  &major_ver, &minor_ver, &renderType, &flags,
-                                 &api, &reset, error))
+                                 &api, &reset, &release, error))
       goto error_exit;
 
    /* Check the renderType value */
@@ -294,6 +295,11 @@ dri2_create_context_attribs(struct glx_screen *base,
       ctx_attribs[num_ctx_attribs++] = reset;
    }
 
+   if (release != __DRI_CTX_RELEASE_BEHAVIOR_FLUSH) {
+      ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR;
+      ctx_attribs[num_ctx_attribs++] = release;
+   }
+
    if (flags != 0) {
       ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_FLAGS;
 
@@ -1170,6 +1176,14 @@ dri2BindExtensions(struct dri2_screen *psc, struct glx_display * priv,
 
       if (strcmp(extensions[i]->name, __DRI2_INTEROP) == 0)
         psc->interop = (__DRI2interopExtension*)extensions[i];
+
+      /* DRI2 version 3 is also required because
+       * GLX_ARB_control_flush_control requires GLX_ARB_create_context.
+       */
+      if (psc->dri2->base.version >= 3
+          && strcmp(extensions[i]->name, __DRI2_FLUSH_CONTROL) == 0)
+         __glXEnableDirectExtension(&psc->base,
+                                    "GLX_ARB_context_flush_control");
    }
 }
 
index b79fec7335c85f28bf8b098d8700cff946219863..d613073994cde99a794764053e2d64984853efe3 100644 (file)
@@ -235,7 +235,8 @@ dri3_create_context_attribs(struct glx_screen *base,
    uint32_t flags = 0;
    unsigned api;
    int reset = __DRI_CTX_RESET_NO_NOTIFICATION;
-   uint32_t ctx_attribs[2 * 5];
+   int release = __DRI_CTX_RELEASE_BEHAVIOR_FLUSH;
+   uint32_t ctx_attribs[2 * 6];
    unsigned num_ctx_attribs = 0;
    uint32_t render_type;
 
@@ -244,7 +245,7 @@ dri3_create_context_attribs(struct glx_screen *base,
    if (!dri2_convert_glx_attribs(num_attribs, attribs,
                                  &major_ver, &minor_ver,
                                  &render_type, &flags, &api,
-                                 &reset, error))
+                                 &reset, &release, error))
       goto error_exit;
 
    /* Check the renderType value */
@@ -279,6 +280,11 @@ dri3_create_context_attribs(struct glx_screen *base,
       ctx_attribs[num_ctx_attribs++] = reset;
    }
 
+   if (release != __DRI_CTX_RELEASE_BEHAVIOR_FLUSH) {
+      ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR;
+      ctx_attribs[num_ctx_attribs++] = release;
+   }
+
    if (flags != 0) {
       ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_FLAGS;
 
@@ -755,6 +761,10 @@ dri3_bind_extensions(struct dri3_screen *psc, struct glx_display * priv,
 
       if (strcmp(extensions[i]->name, __DRI2_INTEROP) == 0)
         psc->interop = (__DRI2interopExtension*)extensions[i];
+
+      if (strcmp(extensions[i]->name, __DRI2_FLUSH_CONTROL) == 0)
+         __glXEnableDirectExtension(&psc->base,
+                                    "GLX_ARB_context_flush_control");
    }
 }
 
index e2bbd48d3a59da79780093bf6cf43b459ca32697..3b82309fa20fb274c5d800048ea1f3839e73247b 100644 (file)
@@ -475,7 +475,7 @@ _X_HIDDEN bool
 dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
                          unsigned *major_ver, unsigned *minor_ver,
                          uint32_t *render_type, uint32_t *flags, unsigned *api,
-                         int *reset, unsigned *error)
+                         int *reset, int *release, unsigned *error)
 {
    unsigned i;
    bool got_profile = false;
@@ -485,6 +485,7 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
    *minor_ver = 0;
    *render_type = GLX_RGBA_TYPE;
    *reset = __DRI_CTX_RESET_NO_NOTIFICATION;
+   *release = __DRI_CTX_RELEASE_BEHAVIOR_FLUSH;
    *flags = 0;
    *api = __DRI_API_OPENGL;
 
@@ -530,6 +531,19 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
             return false;
          }
          break;
+      case GLX_CONTEXT_RELEASE_BEHAVIOR_ARB:
+         switch (attribs[i * 2 + 1]) {
+         case GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB:
+            *release = __DRI_CTX_RELEASE_BEHAVIOR_NONE;
+            break;
+         case GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB:
+            *release = __DRI_CTX_RELEASE_BEHAVIOR_FLUSH;
+            break;
+         default:
+            *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
+            return false;
+         }
+         break;
       default:
         /* If an unknown attribute is received, fail.
          */
index 947d331772fa25f42ef4226c33a0e92bce1cba43..4d97ff82b4d1cd37f24d168fddefb158c9ed689e 100644 (file)
@@ -78,6 +78,6 @@ extern bool
 dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
                          unsigned *major_ver, unsigned *minor_ver,
                          uint32_t *render_type, uint32_t *flags, unsigned *api,
-                         int *reset, unsigned *error);
+                         int *reset, int *release, unsigned *error);
 
 #endif /* _DRI_COMMON_H */
index 110b7f8d92d10c4db96f31e184c700c292a831c6..a471856634d12cdd81b1337f22a6ea2c164569b1 100644 (file)
@@ -417,7 +417,8 @@ drisw_create_context_attribs(struct glx_screen *base,
    uint32_t flags;
    unsigned api;
    int reset;
-   uint32_t ctx_attribs[2 * 4];
+   int release;
+   uint32_t ctx_attribs[2 * 5];
    unsigned num_ctx_attribs = 0;
 
    if (!psc->base.driScreen)
@@ -430,7 +431,7 @@ drisw_create_context_attribs(struct glx_screen *base,
     */
    if (!dri2_convert_glx_attribs(num_attribs, attribs,
                                  &major_ver, &minor_ver, &renderType, &flags,
-                                 &api, &reset, error))
+                                 &api, &reset, &release, error))
       return NULL;
 
    /* Check the renderType value */
@@ -441,6 +442,10 @@ drisw_create_context_attribs(struct glx_screen *base,
    if (reset != __DRI_CTX_RESET_NO_NOTIFICATION)
       return NULL;
 
+   if (release != __DRI_CTX_RELEASE_BEHAVIOR_FLUSH &&
+       release != __DRI_CTX_RELEASE_BEHAVIOR_NONE)
+      return NULL;
+
    if (shareList) {
       pcp_shared = (struct drisw_context *) shareList;
       shared = pcp_shared->driContext;
@@ -459,6 +464,10 @@ drisw_create_context_attribs(struct glx_screen *base,
    ctx_attribs[num_ctx_attribs++] = major_ver;
    ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_MINOR_VERSION;
    ctx_attribs[num_ctx_attribs++] = minor_ver;
+   if (release != __DRI_CTX_RELEASE_BEHAVIOR_FLUSH) {
+       ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR;
+       ctx_attribs[num_ctx_attribs++] = release;
+   }
 
    if (flags != 0) {
       ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_FLAGS;
@@ -647,6 +656,10 @@ driswBindExtensions(struct drisw_screen *psc, const __DRIextension **extensions)
          psc->rendererQuery = (__DRI2rendererQueryExtension *) extensions[i];
          __glXEnableDirectExtension(&psc->base, "GLX_MESA_query_renderer");
       }
+      if (strcmp(extensions[i]->name, __DRI2_FLUSH_CONTROL) == 0) {
+         __glXEnableDirectExtension(&psc->base,
+                                    "GLX_ARB_context_flush_control");
+      }
    }
 }
 
index 6882e442fe4eabea06bb80aa07d82f4ba0bcd1c1..af6ffbf660072a9014bb568c29ab447caca1fd7f 100644 (file)
@@ -132,6 +132,7 @@ struct extension_info
 
 /* *INDENT-OFF* */
 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_profile),  VER(0,0), Y, N, N, N },
    { GLX(ARB_create_context_robustness), VER(0,0), Y, N, N, N },
index 6225742da5180c6506f1e042db36554c86ade9b0..d73128bd0ea382627b3c0578b6d1b3ec2545da0c 100644 (file)
@@ -37,7 +37,8 @@ extern "C" {
 
 enum
 {
-   ARB_create_context_bit = 0,
+   ARB_context_flush_control_bit = 0,
+   ARB_create_context_bit,
    ARB_create_context_profile_bit,
    ARB_create_context_robustness_bit,
    ARB_fbconfig_float_bit,