egl: Add a 565 pbuffer-only EGL config under X11.
authorEric Anholt <eric@anholt.net>
Sat, 25 Aug 2018 21:16:59 +0000 (14:16 -0700)
committerEric Anholt <eric@anholt.net>
Fri, 22 Mar 2019 22:22:40 +0000 (15:22 -0700)
The CTS requires a 565-no-depth-no-stencil (meaning d/s not-required, not
not-present) config for ES 3.0, but at depth 24 of X11 we wouldn't do so.
We can satisfy that bad requirement using a pbuffer-only visual with
whatever other buffers the driver happens to have given us.

I've tried to raise this as an absurd requirement with Khronos and made no
progress.

v2: Make sure it's single sample, no depth, no stencil.  Comment typo fix

Reviewed-by: Adam Jackson <ajax@redhat.com>
src/egl/drivers/dri2/platform_x11.c

index 5d6efea6141785e18aad6c7f353cc5dc0a92f43e..c8c676d2f00161d25050c263b65560e27d44ed72 100644 (file)
@@ -766,6 +766,18 @@ dri2_x11_authenticate(_EGLDisplay *disp, uint32_t id)
    return dri2_x11_do_authenticate(dri2_dpy, id);
 }
 
+static bool
+dri2_x11_config_match_attrib(struct dri2_egl_display *dri2_dpy,
+                             const __DRIconfig *config,
+                             unsigned int attrib,
+                             unsigned int value)
+{
+   uint32_t config_val;
+   if (!dri2_dpy->core->getConfigAttrib(config, attrib, &config_val))
+      return false;
+   return config_val == value;
+}
+
 static EGLBoolean
 dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy,
                                  _EGLDisplay *disp, bool supports_preserved)
@@ -844,6 +856,41 @@ dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy,
       xcb_depth_next(&d);
    }
 
+   /* Add a 565-no-depth-no-stencil pbuffer-only config.  If X11 is depth 24,
+    * we wouldn't have 565 available, which the CTS demands.
+    */
+   for (int j = 0; dri2_dpy->driver_configs[j]; j++) {
+      const __DRIconfig *config = dri2_dpy->driver_configs[j];
+      const EGLint config_attrs[] = {
+         EGL_NATIVE_VISUAL_ID,    0,
+         EGL_NATIVE_VISUAL_TYPE,  EGL_NONE,
+         EGL_NONE
+      };
+      EGLint surface_type = EGL_PBUFFER_BIT;
+      unsigned int rgba_masks[4] = {
+         0x1f << 11,
+         0x3f << 5,
+         0x1f << 0,
+         0,
+      };
+
+      /* Check that we've found single-sample, no depth, no stencil. */
+      if (!dri2_x11_config_match_attrib(dri2_dpy, config,
+                                        __DRI_ATTRIB_DEPTH_SIZE, 0) ||
+          !dri2_x11_config_match_attrib(dri2_dpy, config,
+                                        __DRI_ATTRIB_STENCIL_SIZE, 0) ||
+          !dri2_x11_config_match_attrib(dri2_dpy, config,
+                                        __DRI_ATTRIB_SAMPLES, 0)) {
+         continue;
+      }
+
+      if (dri2_add_config(disp, config, config_count + 1, surface_type,
+                          config_attrs, rgba_masks)) {
+         config_count++;
+         break;
+      }
+   }
+
    if (!config_count) {
       _eglLog(_EGL_WARNING, "DRI2: failed to create any config");
       return EGL_FALSE;