[PATCH] gl-renderer: Create a high priority context

Chris Wilson chris at chris-wilson.co.uk
Fri Mar 2 15:03:00 UTC 2018


Quoting Emil Velikov (2018-03-02 14:52:28)
> Hi Chris,
> 
> On 1 March 2018 at 08:28, Chris Wilson <chris at chris-wilson.co.uk> wrote:
> > EGL_IMG_context_priority allows the client to request that their
> > rendering be considered high priority. For ourselves, this is important
> > as we are interactive and any delay in our rendering causes input-output
> 
> > +       if (gr->has_context_priority) {
> > +               EGLint value = EGL_CONTEXT_PRIORITY_MEDIUM_IMG;
> > +
> > +               eglQueryContext(gr->egl_display, gr->egl_context,
> > +                               EGL_CONTEXT_PRIORITY_LEVEL_IMG, &value);
> > +
> > +               if (value != EGL_CONTEXT_PRIORITY_HIGH_IMG) {
> > +                       weston_log("Failed to obtain a high priority context.\n");
> > +                       /* Not an error, continue on as normal */
> > +               }
> While this (and EGL spec) says "not an error" the i965 driver will
> error out as the ioctl fails.

The high priority attribute is filtered out from the allowed set of EGL
attributes, so the request for a high priority context is silently
converted back to normal. You don't get as far as hitting the ioctl.

diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c
index 1b03160439..8c64f9ab82 100644
--- a/src/egl/main/eglcontext.c
+++ b/src/egl/main/eglcontext.c
@@ -332,6 +332,60 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *dpy,
          ctx->NoError = !!val;
          break;
 
+      case EGL_CONTEXT_PRIORITY_LEVEL_IMG:
+         /* The  EGL_IMG_context_priority spec says:
+          *
+          * "EGL_CONTEXT_PRIORITY_LEVEL_IMG determines the priority level of
+          * the context to be created. This attribute is a hint, as an
+          * implementation may not support multiple contexts at some
+          * priority levels and system policy may limit access to high
+          * priority contexts to appropriate system privilege level. The
+          * default value for EGL_CONTEXT_PRIORITY_LEVEL_IMG is
+          * EGL_CONTEXT_PRIORITY_MEDIUM_IMG."
+          */
+         {
+            int bit;
+
+            switch (val) {
+            case EGL_CONTEXT_PRIORITY_HIGH_IMG:
+               bit = __EGL_CONTEXT_PRIORITY_HIGH_BIT;
+               break;
+            case EGL_CONTEXT_PRIORITY_MEDIUM_IMG:
+               bit = __EGL_CONTEXT_PRIORITY_MEDIUM_BIT;
+               break;
+            case EGL_CONTEXT_PRIORITY_LOW_IMG:
+               bit = __EGL_CONTEXT_PRIORITY_LOW_BIT;
+               break;
+            default:
+               bit = -1;
+               break;
+            }
+
+            if (bit < 0) {
+               err = EGL_BAD_ATTRIBUTE;
+               break;
+            }
+
+            /* "This extension allows an EGLContext to be created with a
+             * priority hint. It is possible that an implementation will not
+             * honour the hint, especially if there are constraints on the
+             * number of high priority contexts available in the system, or
+             * system policy limits access to high priority contexts to
+             * appropriate system privilege level. A query is provided to find
+             * the real priority level assigned to the context after creation."
+             *
+             * We currently assume that the driver applies the priority hint
+             * and filters out any it cannot handle during the screen setup,
+             * e.g. dri2_setup_screen(). As such we can mask any change that
+             * the driver would fail, and ctx->ContextPriority matches the
+             * hint applied to the driver/hardware backend.
+             */
+            if (dpy->Extensions.IMG_context_priority & (1 << bit))
+               ctx->ContextPriority = val;
+
+            break;
+         }
+
       default:
          err = EGL_BAD_ATTRIBUTE;
          break;

and dpy->Extensions.IMG_context_priority should not have HIGH_BIT set.
-Chris


More information about the wayland-devel mailing list