egl,dri: Propagate context priority hint to driver->CreateContext
authorChris Wilson <chris@chris-wilson.co.uk>
Thu, 27 Oct 2016 18:54:49 +0000 (19:54 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Fri, 20 Oct 2017 10:28:17 +0000 (11:28 +0100)
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 creator before
passing it to the driver as a function parameter.

In order to not require us to pass back the actual value of the context
priority after creation, we impose that drivers should report the
available set of priorities during screen setup (and then they may chose
to fail if given an invalid value as that should have been checked at
the user boundary.)

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Acked-by: Ben Widawsky <ben@bwidawsk.net> # i915/i965
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
16 files changed:
include/GL/internal/dri_interface.h
src/egl/drivers/dri2/egl_dri2.c
src/gallium/state_trackers/dri/dri_context.c
src/gallium/state_trackers/dri/dri_context.h
src/mesa/drivers/dri/common/dri_util.c
src/mesa/drivers/dri/common/dri_util.h
src/mesa/drivers/dri/i915/intel_screen.c
src/mesa/drivers/dri/i965/brw_context.c
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/nouveau/nouveau_context.c
src/mesa/drivers/dri/nouveau/nouveau_context.h
src/mesa/drivers/dri/r200/r200_context.c
src/mesa/drivers/dri/r200/r200_context.h
src/mesa/drivers/dri/radeon/radeon_context.c
src/mesa/drivers/dri/radeon/radeon_context.h
src/mesa/drivers/dri/swrast/swrast.c

index 7ed0169a98459951a45e5cf698b34bcd46fb4988..98402eae057e6ffda2773529b751f014b23f793a 100644 (file)
@@ -1100,6 +1100,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
  */
index e18e05e4a99d45e0ba5ecc35bc172199ea22a739..503450542e52f8d06826ba9505ebc95d70b04b6f 100644 (file)
@@ -92,6 +92,8 @@
 #define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
 #endif
 
+#define NUM_ATTRIBS 10
+
 static void
 dri_set_background_context(void *loaderPrivate)
 {
@@ -1166,7 +1168,7 @@ dri2_fill_context_attribs(struct dri2_egl_context *dri2_ctx,
 {
    int pos = 0;
 
-   assert(*num_attribs >= 8);
+   assert(*num_attribs >= NUM_ATTRIBS);
 
    ctx_attribs[pos++] = __DRI_CTX_ATTRIB_MAJOR_VERSION;
    ctx_attribs[pos++] = dri2_ctx->base.ClientMajorVersion;
@@ -1203,6 +1205,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;
@@ -1317,8 +1341,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 = NUM_ATTRIBS;
+      uint32_t ctx_attribs[NUM_ATTRIBS];
 
       if (!dri2_fill_context_attribs(dri2_ctx, dri2_dpy, ctx_attribs,
                                         &num_attribs))
@@ -1337,8 +1361,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 = NUM_ATTRIBS;
+         uint32_t ctx_attribs[NUM_ATTRIBS];
 
          if (!dri2_fill_context_attribs(dri2_ctx, dri2_dpy, ctx_attribs,
                                         &num_attribs))
@@ -1366,8 +1390,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 = NUM_ATTRIBS;
+         uint32_t ctx_attribs[NUM_ATTRIBS];
 
          if (!dri2_fill_context_attribs(dri2_ctx, dri2_dpy, ctx_attribs,
                                         &num_attribs))
index 8b9323faa4f0e7e9087b2f2483775dafcb6d3908..8776aacc093bee20ad8eab89a58d237bb611175a 100644 (file)
@@ -47,6 +47,7 @@ dri_create_context(gl_api api, const struct gl_config * visual,
                   unsigned minor_version,
                   uint32_t flags,
                    bool notify_reset,
+                   unsigned priority,
                   unsigned *error,
                   void *sharedContextPrivate)
 {
index 96f06442fa0297740edf409b542b86ede78bbbed..afa9c49ff3b804746007d5e207b97f511b81ac01 100644 (file)
@@ -90,6 +90,7 @@ dri_create_context(gl_api api,
                   unsigned minor_version,
                   uint32_t flags,
                   bool notify_reset,
+                   unsigned priority,
                   unsigned *error,
                   void *sharedContextPrivate);
 
index 31a3040365a3a4b090bdb8afbc2009d7f90db29a..1cff0ddb2de6094afa9c977cabc5f9d12960d41b 100644 (file)
@@ -306,6 +306,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));
 
@@ -348,6 +349,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.
@@ -451,7 +455,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;
     }
index 25a3ae47a2310c3bf9eb224a64fd1e8541bff466..ecc2a4750739bff1917170a3a6083f0119ff615d 100644 (file)
@@ -85,11 +85,12 @@ struct __DriverAPIRec {
     GLboolean (*CreateContext)(gl_api api,
                                const struct gl_config *glVis,
                                __DRIcontext *driContextPriv,
-                              unsigned major_version,
-                              unsigned minor_version,
-                              uint32_t flags,
+                               unsigned major_version,
+                               unsigned minor_version,
+                               uint32_t flags,
                                bool notify_reset,
-                              unsigned *error,
+                               unsigned priority,
+                               unsigned *error,
                                void *sharedContextPrivate);
 
     void (*DestroyContext)(__DRIcontext *driContextPriv);
index ba49e90fef5cf42b901e3a02d101fb76357afa17..1621a6246bae279526dc5703114592d1cf4ae096 100644 (file)
@@ -956,13 +956,14 @@ i915CreateContext(int api,
 
 static GLboolean
 intelCreateContext(gl_api api,
-                  const struct gl_config * mesaVis,
+                   const struct gl_config * mesaVis,
                    __DRIcontext * driContextPriv,
-                  unsigned major_version,
-                  unsigned minor_version,
-                  uint32_t flags,
+                   unsigned major_version,
+                   unsigned minor_version,
+                   uint32_t flags,
                    bool notify_reset,
-                  unsigned *error,
+                   unsigned priority,
+                   unsigned *error,
                    void *sharedContextPrivate)
 {
    bool success = false;
index 609d8150641953fc0500d9536a4598f0f40fb047..a86367cc46b8791f98250f8be038655688009b64 100644 (file)
@@ -820,14 +820,15 @@ brw_process_driconf_options(struct brw_context *brw)
 
 GLboolean
 brwCreateContext(gl_api api,
-                const struct gl_config *mesaVis,
-                __DRIcontext *driContextPriv,
+                 const struct gl_config *mesaVis,
+                 __DRIcontext *driContextPriv,
                  unsigned major_version,
                  unsigned minor_version,
                  uint32_t flags,
                  bool notify_reset,
+                 unsigned priority,
                  unsigned *dri_ctx_error,
-                void *sharedContextPrivate)
+                 void *sharedContextPrivate)
 {
    struct gl_context *shareCtx = (struct gl_context *) sharedContextPrivate;
    struct intel_screen *screen = driContextPriv->driScreenPriv->driverPrivate;
index 679b848c5057cff0262da4d8c568bdfadcf1859a..26e71e62b54f5f2fb197d622e17d973c85e9c24f 100644 (file)
@@ -1240,14 +1240,15 @@ void intel_resolve_for_dri2_flush(struct brw_context *brw,
                                   __DRIdrawable *drawable);
 
 GLboolean brwCreateContext(gl_api api,
-                     const struct gl_config *mesaVis,
-                     __DRIcontext *driContextPriv,
-                      unsigned major_version,
-                      unsigned minor_version,
-                      uint32_t flags,
-                      bool notify_reset,
-                      unsigned *error,
-                     void *sharedContextPrivate);
+                           const struct gl_config *mesaVis,
+                           __DRIcontext *driContextPriv,
+                           unsigned major_version,
+                           unsigned minor_version,
+                           uint32_t flags,
+                           bool notify_reset,
+                           unsigned priority,
+                           unsigned *error,
+                           void *sharedContextPrivate);
 
 /*======================================================================
  * brw_misc_state.c
index d6f9e5338485cbc4e915fb59078b93581738f644..39620e10214135abbad03c42d5c9ca3737cbe2eb 100644 (file)
@@ -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)
 {
index b6cbde44ac6127150f53d452fb3a83faed07537a..6ab865c7bdea627051eb18ad08678c5ebd27fbc3 100644 (file)
@@ -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,
index b6354dccbb92bb06e73b15a772157f90f40a96d9..bd4f8b62cd2d90fdadb655b3d61634290ed457a3 100644 (file)
@@ -178,6 +178,7 @@ GLboolean r200CreateContext( gl_api api,
                             unsigned minor_version,
                             uint32_t flags,
                              bool notify_reset,
+                             unsigned priority,
                             unsigned *error,
                             void *sharedContextPrivate)
 {
index 550203d24dac8a769cb2589d546d7dae55c4dd34..200e0a24312d5ac840c1c28495a6397be59dd268 100644 (file)
@@ -632,6 +632,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,
index c1ee8d8a76792ee823d2a44f71e07cb71ec61672..866dc80c98f2cdafbd079ceeeedd50fbc5c7c7fe 100644 (file)
@@ -144,6 +144,7 @@ r100CreateContext( gl_api api,
                   unsigned minor_version,
                   uint32_t flags,
                    bool notify_reset,
+                  unsigned priority,
                   unsigned *error,
                   void *sharedContextPrivate)
 {
index 88a295386ca3eea4d1d07f74ed6da3af50fe9708..4124f50db5e4ff71b899a6562f88cee4e46f4955 100644 (file)
@@ -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);
 
index 45d8279d3649595d70d2820d4675b6f23589b089..6b71d806f09e4ae4bbed92c1fa54151e8ee4c008 100644 (file)
@@ -756,6 +756,7 @@ dri_create_context(gl_api api,
                   unsigned minor_version,
                   uint32_t flags,
                   bool notify_reset,
+                  unsigned priority,
                   unsigned *error,
                   void *sharedContextPrivate)
 {