[Mesa-dev] [RFC 1/3] egl: Support IMG_context_priority

Tapani Pälli tapani.palli at intel.com
Fri Oct 28 08:47:55 UTC 2016


First patch is
Reviewed-by: Tapani Pälli <tapani.palli at intel.com>

I also tested setting different priority levels, querying them and 
setting invalid priority level where context creation fails. API works 
as expected.

On 10/28/2016 11:10 AM, Chris Wilson wrote:
> IMG_context_priority
> https://www.khronos.org/registry/egl/extensions/IMG/EGL_IMG_context_priority.txt
>
>      "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."
>
> The extension adds a new eglCreateContext attribute for choosing a
> priority hint. This stub parses the attribute and copies into the base
> struct _egl_context, and hooks up the query similarly.
>
> Since the attribute is purely a hint, I have no qualms about the lack of
> implementation before reporting back the value the user gave!
>
> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
> ---
>   src/egl/drivers/dri2/egl_dri2.c |  1 +
>   src/egl/main/eglapi.c           |  2 ++
>   src/egl/main/eglcontext.c       | 30 ++++++++++++++++++++++++++++++
>   src/egl/main/eglcontext.h       |  1 +
>   src/egl/main/egldisplay.h       |  2 ++
>   5 files changed, 36 insertions(+)
>
> diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
> index d9e2ad7..5cd073e 100644
> --- a/src/egl/drivers/dri2/egl_dri2.c
> +++ b/src/egl/drivers/dri2/egl_dri2.c
> @@ -638,6 +638,7 @@ dri2_setup_screen(_EGLDisplay *disp)
>      assert(dri2_dpy->image_driver || dri2_dpy->dri2 || dri2_dpy->swrast);
>      disp->Extensions.KHR_no_config_context = EGL_TRUE;
>      disp->Extensions.KHR_surfaceless_context = EGL_TRUE;
> +   disp->Extensions.IMG_context_priority = EGL_TRUE; /* only a hint */
>   
>      if (dri2_renderer_query_integer(dri2_dpy,
>                                      __DRI2_RENDERER_HAS_FRAMEBUFFER_SRGB))
> diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
> index 04cac03..63705e6 100644
> --- a/src/egl/main/eglapi.c
> +++ b/src/egl/main/eglapi.c
> @@ -483,6 +483,8 @@ _eglCreateExtensionsString(_EGLDisplay *dpy)
>      _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import);
>      _EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage);
>   
> +   _EGL_CHECK_EXTENSION(IMG_context_priority);
> +
>      _EGL_CHECK_EXTENSION(KHR_cl_event2);
>      _EGL_CHECK_EXTENSION(KHR_create_context);
>      _EGL_CHECK_EXTENSION(KHR_fence_sync);
> diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c
> index 60625f6..fe9fdaa 100644
> --- a/src/egl/main/eglcontext.c
> +++ b/src/egl/main/eglcontext.c
> @@ -298,6 +298,33 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *dpy,
>               ctx->Flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
>            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."
> +          */
> +         if (!dpy->Extensions.IMG_context_priority) {
> +            err = EGL_BAD_ATTRIBUTE;
> +            break;
> +         }
> +         switch (val) {
> +         case EGL_CONTEXT_PRIORITY_HIGH_IMG:
> +         case EGL_CONTEXT_PRIORITY_MEDIUM_IMG:
> +         case EGL_CONTEXT_PRIORITY_LOW_IMG:
> +            ctx->ContextPriority = val;
> +            break;
> +         default:
> +            err = EGL_BAD_ATTRIBUTE;
> +            break;
> +         }
> +         break;
> +
>         default:
>            err = EGL_BAD_ATTRIBUTE;
>            break;
> @@ -556,6 +583,9 @@ _eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *c,
>      case EGL_RENDER_BUFFER:
>         *value = _eglQueryContextRenderBuffer(c);
>         break;
> +   case EGL_CONTEXT_PRIORITY_LEVEL_IMG:
> +      *value = c->ContextPriority;
> +      break;
>      default:
>         return _eglError(EGL_BAD_ATTRIBUTE, "eglQueryContext");
>      }
> diff --git a/src/egl/main/eglcontext.h b/src/egl/main/eglcontext.h
> index 69bf77d..ea57b77 100644
> --- a/src/egl/main/eglcontext.h
> +++ b/src/egl/main/eglcontext.h
> @@ -62,6 +62,7 @@ struct _egl_context
>      EGLint Flags;
>      EGLint Profile;
>      EGLint ResetNotificationStrategy;
> +   EGLint ContextPriority;
>   
>      /* The real render buffer when a window surface is bound */
>      EGLint WindowRenderBuffer;
> diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
> index 62d9a11..a7f2f97 100644
> --- a/src/egl/main/egldisplay.h
> +++ b/src/egl/main/egldisplay.h
> @@ -103,6 +103,8 @@ struct _egl_extensions
>      EGLBoolean EXT_image_dma_buf_import;
>      EGLBoolean EXT_swap_buffers_with_damage;
>   
> +   EGLBoolean IMG_context_priority;
> +
>      EGLBoolean KHR_cl_event2;
>      EGLBoolean KHR_create_context;
>      EGLBoolean KHR_fence_sync;




More information about the mesa-dev mailing list