[Mesa-dev] [RFC 2/3] egl, dri: Propagate context priority hint to driver->CreateContext

Chris Wilson chris at chris-wilson.co.uk
Fri Oct 28 08:10:48 UTC 2016


Jump through the layers of abstraction between egl and dri in order to
feed the context priority attribute through to the backend. This
requires us to read the value from the base _egl_context, convert it to
a DRI attribute, parse it again in the generic context creater before
passing it to the driver as a function parameter.

Issues:

 * How to pass back the priority of the create context (as it may be
modified by the driver) back to EGL?

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 include/GL/internal/dri_interface.h            |  6 +++++
 src/egl/drivers/dri2/egl_dri2.c                | 36 +++++++++++++++++++++-----
 src/mesa/drivers/dri/common/dri_util.c         |  7 ++++-
 src/mesa/drivers/dri/common/dri_util.h         |  1 +
 src/mesa/drivers/dri/i915/intel_screen.c       |  1 +
 src/mesa/drivers/dri/i965/brw_context.c        |  1 +
 src/mesa/drivers/dri/i965/brw_context.h        |  1 +
 src/mesa/drivers/dri/nouveau/nouveau_context.c |  1 +
 src/mesa/drivers/dri/nouveau/nouveau_context.h |  4 +--
 src/mesa/drivers/dri/r200/r200_context.c       |  1 +
 src/mesa/drivers/dri/r200/r200_context.h       |  1 +
 src/mesa/drivers/dri/radeon/radeon_context.c   |  1 +
 src/mesa/drivers/dri/radeon/radeon_context.h   |  1 +
 src/mesa/drivers/dri/swrast/swrast.c           |  1 +
 14 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
index ca1fc38..6d27e86 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1024,6 +1024,12 @@ struct __DRIdri2LoaderExtensionRec {
 #define __DRI_CTX_RESET_LOSE_CONTEXT		1
 /*@}*/
 
+#define __DRI_CTX_ATTRIB_PRIORITY		4
+
+#define __DRI_CTX_PRIORITY_LOW			0
+#define __DRI_CTX_PRIORITY_MEDIUM		1
+#define __DRI_CTX_PRIORITY_HIGH			2
+
 /**
  * \name Reasons that __DRIdri2Extension::createContextAttribs might fail
  */
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 5cd073e..e3f7dd6 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1019,7 +1019,7 @@ dri2_fill_context_attribs(struct dri2_egl_context *dri2_ctx,
 {
    int pos = 0;
 
-   assert(*num_attribs >= 8);
+   assert(*num_attribs >= 10);
 
    ctx_attribs[pos++] = __DRI_CTX_ATTRIB_MAJOR_VERSION;
    ctx_attribs[pos++] = dri2_ctx->base.ClientMajorVersion;
@@ -1055,6 +1055,28 @@ dri2_fill_context_attribs(struct dri2_egl_context *dri2_ctx,
       ctx_attribs[pos++] = __DRI_CTX_RESET_LOSE_CONTEXT;
    }
 
+   if (dri2_ctx->base.ContextPriority != EGL_CONTEXT_PRIORITY_MEDIUM_IMG) {
+      unsigned val;
+
+      switch (dri2_ctx->base.ContextPriority) {
+      case EGL_CONTEXT_PRIORITY_HIGH_IMG:
+         val = __DRI_CTX_PRIORITY_HIGH;
+         break;
+      case EGL_CONTEXT_PRIORITY_MEDIUM_IMG:
+         val = __DRI_CTX_PRIORITY_MEDIUM;
+         break;
+      case EGL_CONTEXT_PRIORITY_LOW_IMG:
+         val = __DRI_CTX_PRIORITY_LOW;
+         break;
+      default:
+         _eglError(EGL_BAD_CONFIG, "eglCreateContext");
+         return false;
+      }
+
+      ctx_attribs[pos++] = __DRI_CTX_ATTRIB_PRIORITY;
+      ctx_attribs[pos++] = val;;
+   }
+
    *num_attribs = pos;
 
    return true;
@@ -1144,8 +1166,8 @@ dri2_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
 
    if (dri2_dpy->image_driver) {
       unsigned error;
-      unsigned num_attribs = 8;
-      uint32_t ctx_attribs[8];
+      unsigned num_attribs = 10;
+      uint32_t ctx_attribs[10];
 
       if (!dri2_fill_context_attribs(dri2_ctx, dri2_dpy, ctx_attribs,
                                         &num_attribs))
@@ -1164,8 +1186,8 @@ dri2_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
    } else if (dri2_dpy->dri2) {
       if (dri2_dpy->dri2->base.version >= 3) {
          unsigned error;
-         unsigned num_attribs = 8;
-         uint32_t ctx_attribs[8];
+         unsigned num_attribs = 10;
+         uint32_t ctx_attribs[10];
 
          if (!dri2_fill_context_attribs(dri2_ctx, dri2_dpy, ctx_attribs,
                                         &num_attribs))
@@ -1193,8 +1215,8 @@ dri2_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
       assert(dri2_dpy->swrast);
       if (dri2_dpy->swrast->base.version >= 3) {
          unsigned error;
-         unsigned num_attribs = 8;
-         uint32_t ctx_attribs[8];
+         unsigned num_attribs = 10;
+         uint32_t ctx_attribs[10];
 
          if (!dri2_fill_context_attribs(dri2_ctx, dri2_dpy, ctx_attribs,
                                         &num_attribs))
diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c
index 9dcc997..0510a65 100644
--- a/src/mesa/drivers/dri/common/dri_util.c
+++ b/src/mesa/drivers/dri/common/dri_util.c
@@ -304,6 +304,7 @@ driCreateContextAttribs(__DRIscreen *screen, int api,
     unsigned minor_version = 0;
     uint32_t flags = 0;
     bool notify_reset = false;
+    unsigned priority = __DRI_CTX_PRIORITY_MEDIUM;
 
     assert((num_attribs == 0) || (attribs != NULL));
 
@@ -346,6 +347,9 @@ driCreateContextAttribs(__DRIscreen *screen, int api,
             notify_reset = (attribs[i * 2 + 1]
                             != __DRI_CTX_RESET_NO_NOTIFICATION);
             break;
+	case __DRI_CTX_ATTRIB_PRIORITY:
+	    priority = attribs[i * 2 + 1];
+	    break;
 	default:
 	    /* We can't create a context that satisfies the requirements of an
 	     * attribute that we don't understand.  Return failure.
@@ -447,7 +451,8 @@ driCreateContextAttribs(__DRIscreen *screen, int api,
 
     if (!screen->driver->CreateContext(mesa_api, modes, context,
                                        major_version, minor_version,
-                                       flags, notify_reset, error, shareCtx)) {
+                                       flags, notify_reset, priority,
+				       error, shareCtx)) {
         free(context);
         return NULL;
     }
diff --git a/src/mesa/drivers/dri/common/dri_util.h b/src/mesa/drivers/dri/common/dri_util.h
index eb761d4..ab2ee2e 100644
--- a/src/mesa/drivers/dri/common/dri_util.h
+++ b/src/mesa/drivers/dri/common/dri_util.h
@@ -89,6 +89,7 @@ struct __DriverAPIRec {
 			       unsigned minor_version,
 			       uint32_t flags,
                                bool notify_reset,
+			       unsigned priority,
 			       unsigned *error,
                                void *sharedContextPrivate);
 
diff --git a/src/mesa/drivers/dri/i915/intel_screen.c b/src/mesa/drivers/dri/i915/intel_screen.c
index 1b80df0..077240c 100644
--- a/src/mesa/drivers/dri/i915/intel_screen.c
+++ b/src/mesa/drivers/dri/i915/intel_screen.c
@@ -953,6 +953,7 @@ intelCreateContext(gl_api api,
 		   unsigned minor_version,
 		   uint32_t flags,
                    bool notify_reset,
+                   unsigned priority,
 		   unsigned *error,
                    void *sharedContextPrivate)
 {
diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index 5ae8e23..1d3ee1d 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -923,6 +923,7 @@ brwCreateContext(gl_api api,
                  unsigned minor_version,
                  uint32_t flags,
                  bool notify_reset,
+                 unsigned priority,
                  unsigned *dri_ctx_error,
 	         void *sharedContextPrivate)
 {
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index bc9e2ae..4cc8949 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1300,6 +1300,7 @@ GLboolean brwCreateContext(gl_api api,
                       unsigned minor_version,
                       uint32_t flags,
                       bool notify_reset,
+                      unsigned priority,
                       unsigned *error,
 		      void *sharedContextPrivate);
 
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_context.c b/src/mesa/drivers/dri/nouveau/nouveau_context.c
index cb854b8..7467830 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_context.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_context.c
@@ -55,6 +55,7 @@ nouveau_context_create(gl_api api,
 		       unsigned minor_version,
 		       uint32_t flags,
 		       bool notify_reset,
+                       unsigned priority,
 		       unsigned *error,
 		       void *share_ctx)
 {
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_context.h b/src/mesa/drivers/dri/nouveau/nouveau_context.h
index b6cbde4..8106bad 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_context.h
+++ b/src/mesa/drivers/dri/nouveau/nouveau_context.h
@@ -111,8 +111,8 @@ GLboolean
 nouveau_context_create(gl_api api,
 		       const struct gl_config *visual, __DRIcontext *dri_ctx,
 		       unsigned major_version, unsigned minor_version,
-		       uint32_t flags, bool notify_reset, unsigned *error,
-		       void *share_ctx);
+		       uint32_t flags, bool notify_reset, unsigned priority,
+                       unsigned *error, void *share_ctx);
 
 GLboolean
 nouveau_context_init(struct gl_context *ctx, gl_api api,
diff --git a/src/mesa/drivers/dri/r200/r200_context.c b/src/mesa/drivers/dri/r200/r200_context.c
index 2a42ab3..a87ea1a 100644
--- a/src/mesa/drivers/dri/r200/r200_context.c
+++ b/src/mesa/drivers/dri/r200/r200_context.c
@@ -179,6 +179,7 @@ GLboolean r200CreateContext( gl_api api,
 			     unsigned minor_version,
 			     uint32_t flags,
                              bool notify_reset,
+                             unsigned priority,
 			     unsigned *error,
 			     void *sharedContextPrivate)
 {
diff --git a/src/mesa/drivers/dri/r200/r200_context.h b/src/mesa/drivers/dri/r200/r200_context.h
index 07eae23..01b040c 100644
--- a/src/mesa/drivers/dri/r200/r200_context.h
+++ b/src/mesa/drivers/dri/r200/r200_context.h
@@ -633,6 +633,7 @@ extern GLboolean r200CreateContext( gl_api api,
 				    unsigned minor_version,
 				    uint32_t flags,
                                     bool notify_reset,
+                                    unsigned priority,
 				    unsigned *error,
 				    void *sharedContextPrivate);
 extern GLboolean r200MakeCurrent( __DRIcontext *driContextPriv,
diff --git a/src/mesa/drivers/dri/radeon/radeon_context.c b/src/mesa/drivers/dri/radeon/radeon_context.c
index 5e15b46..885510f 100644
--- a/src/mesa/drivers/dri/radeon/radeon_context.c
+++ b/src/mesa/drivers/dri/radeon/radeon_context.c
@@ -144,6 +144,7 @@ r100CreateContext( gl_api api,
 		   unsigned minor_version,
 		   uint32_t flags,
                    bool notify_reset,
+		   unsigned priority,
 		   unsigned *error,
 		   void *sharedContextPrivate)
 {
diff --git a/src/mesa/drivers/dri/radeon/radeon_context.h b/src/mesa/drivers/dri/radeon/radeon_context.h
index 88a2953..4124f50 100644
--- a/src/mesa/drivers/dri/radeon/radeon_context.h
+++ b/src/mesa/drivers/dri/radeon/radeon_context.h
@@ -456,6 +456,7 @@ extern GLboolean r100CreateContext( gl_api api,
 				    unsigned minor_version,
 				    uint32_t flags,
                                     bool notify_reset,
+                                    unsigned priority,
 				    unsigned *error,
 				    void *sharedContextPrivate);
 
diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c
index 0402232..8af18cd 100644
--- a/src/mesa/drivers/dri/swrast/swrast.c
+++ b/src/mesa/drivers/dri/swrast/swrast.c
@@ -750,6 +750,7 @@ dri_create_context(gl_api api,
 		   unsigned minor_version,
 		   uint32_t flags,
 		   bool notify_reset,
+                   unsigned priority,
 		   unsigned *error,
 		   void *sharedContextPrivate)
 {
-- 
2.10.1



More information about the mesa-dev mailing list