[Mesa-dev] [PATCH v2 1/4] egl: Support IMG_context_priority

Chris Wilson chris at chris-wilson.co.uk
Wed Apr 12 09:54:49 UTC 2017


On Tue, Apr 11, 2017 at 05:11:54PM +0100, 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!
> 
> v2: Remember to set the default ContextPriority value to medium.
> v3: Use the driRendererQuery interface to probe the backend for
> supported priority values and use those to mask the EGL interface.
> 
> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
> Cc: Rob Clark <robdclark at gmail.com>
> ---
>  include/GL/internal/dri_interface.h |  8 +++++++
>  src/egl/drivers/dri2/egl_dri2.c     |  5 +++++
>  src/egl/main/eglapi.c               |  2 ++
>  src/egl/main/eglcontext.c           | 43 +++++++++++++++++++++++++++++++++++++
>  src/egl/main/eglcontext.h           |  1 +
>  src/egl/main/egldisplay.h           |  5 +++++
>  6 files changed, 64 insertions(+)
> 
> diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
> index 86efd1bdc9..9881ddcbb0 100644
> --- a/include/GL/internal/dri_interface.h
> +++ b/include/GL/internal/dri_interface.h
> @@ -1604,6 +1604,14 @@ typedef struct __DRIDriverVtableExtensionRec {
>   */
>  #define __DRI2_RENDERER_HAS_FRAMEBUFFER_SRGB                  0x000c
>  
> +/* Bitmaks of supported/available context priorities - must match
> + * __EGL_CONTEXT_PRIORITY_LOW_BIT et al
> + */
> +#define __DRI2_RENDERER_HAS_CONTEXT_PRIORITY                  0x000d
> +#define   __DRI2_RENDERER_HAS_CONTEXT_PRIORITY_LOW            (1 << 0)
> +#define   __DRI2_RENDERER_HAS_CONTEXT_PRIORITY_MEDIUM         (1 << 1)
> +#define   __DRI2_RENDERER_HAS_CONTEXT_PRIORITY_HIGH           (1 << 2)
> +
>  typedef struct __DRI2rendererQueryExtensionRec __DRI2rendererQueryExtension;
>  struct __DRI2rendererQueryExtensionRec {
>     __DRIextension base;
> diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
> index 2cab7d00c1..0c2fdc1cc2 100644
> --- a/src/egl/drivers/dri2/egl_dri2.c
> +++ b/src/egl/drivers/dri2/egl_dri2.c
> @@ -663,6 +663,11 @@ dri2_setup_screen(_EGLDisplay *disp)
>     disp->Extensions.KHR_no_config_context = EGL_TRUE;
>     disp->Extensions.KHR_surfaceless_context = EGL_TRUE;
>  
> +   /* Report back to EGL the bitmask of priorities supported */
> +   disp->Extensions.IMG_context_priority =
> +      dri2_renderer_query_integer(dri2_dpy,
> +                                  __DRI2_RENDERER_HAS_CONTEXT_PRIORITY);
> +
>     if (dri2_renderer_query_integer(dri2_dpy,
>                                     __DRI2_RENDERER_HAS_FRAMEBUFFER_SRGB))
>        disp->Extensions.KHR_gl_colorspace = EGL_TRUE;
> diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
> index 5694b5a4ca..9ed65b1bba 100644
> --- a/src/egl/main/eglapi.c
> +++ b/src/egl/main/eglapi.c
> @@ -490,6 +490,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_config_attribs);
>     _EGL_CHECK_EXTENSION(KHR_create_context);
> diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c
> index 05cc523c8d..efe63f3ae4 100644
> --- a/src/egl/main/eglcontext.c
> +++ b/src/egl/main/eglcontext.c
> @@ -312,6 +312,45 @@ _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."
> +          */
> +         {
> +            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 ||
> +                !(dpy->Extensions.IMG_context_priority & (1 << bit)) ){
> +               err = EGL_BAD_ATTRIBUTE;

Hmm, rejecting an unavailable priority with BAD_ATTRIBUTE sounds
overkill wrt

     "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."

That suggests something more like:

if (bit < 0) {
	err = EGL_BAD_ATTRIBUTE;
	break;
}

if (dpy->Extensions.IMG_context_priority & (1 << bit))
	ctx->ContextPriority = val;

Is that a better interpretation?
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the mesa-dev mailing list