Commit 71d86223 authored by Carlos Garnacho's avatar Carlos Garnacho
Browse files

egl: Query available priorities at context creation time

Querying those once at screen setup time might yield the wrong results
if there are EGLContexts being created at a separate thread with differing
capabilities than the one calling eglInitialize().

There's two ways in which it may go wrong:
- The eglCreateContext thread has capabilities, but the thread where
  eglInitialize was called did not: The priority will be silently ignored,
  despite the ioctl still being able to succeed there.
- The eglInitialize thread had capabilities at the time of being called,
  but the eglCreateContext thread does not preserve them: The context will
  try to set the ioctl, but fail hard, and result on no context being created.
  This seems to go against EGL_IMG_context_priority extension.

It seems a better way that would provide the right results on mixed threads
with different capabilities is to query the allowed values at context
creation time. At this moment we can still reset the user-set priority on
failure (as future queries should return the assigned priority), and be sure
that the value is handled relative to the calling thread.

Also, drop a comment that no longer really applies after this change.
parent 084431ce
Pipeline #77663 passed with stages
in 39 minutes and 19 seconds
......@@ -744,8 +744,9 @@ dri2_setup_screen(_EGLDisplay *disp)
/* 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);
__DRI2_RENDERER_HAS_CONTEXT_PRIORITY_HIGH |
__DRI2_RENDERER_HAS_CONTEXT_PRIORITY_MEDIUM |
__DRI2_RENDERER_HAS_CONTEXT_PRIORITY_LOW;
disp->Extensions.EXT_pixel_format_float = EGL_TRUE;
......@@ -1245,16 +1246,19 @@ dri2_fill_context_attribs(struct dri2_egl_context *dri2_ctx,
}
if (dri2_ctx->base.ContextPriority != EGL_CONTEXT_PRIORITY_MEDIUM_IMG) {
int allowed, check;
unsigned val;
allowed = dri2_renderer_query_integer(dri2_dpy,
__DRI2_RENDERER_HAS_CONTEXT_PRIORITY);
switch (dri2_ctx->base.ContextPriority) {
case EGL_CONTEXT_PRIORITY_HIGH_IMG:
check = __DRI2_RENDERER_HAS_CONTEXT_PRIORITY_HIGH;
val = __DRI_CTX_PRIORITY_HIGH;
break;
case EGL_CONTEXT_PRIORITY_MEDIUM_IMG:
val = __DRI_CTX_PRIORITY_MEDIUM;
break;
case EGL_CONTEXT_PRIORITY_LOW_IMG:
check = __DRI2_RENDERER_HAS_CONTEXT_PRIORITY_LOW;
val = __DRI_CTX_PRIORITY_LOW;
break;
default:
......@@ -1262,8 +1266,15 @@ dri2_fill_context_attribs(struct dri2_egl_context *dri2_ctx,
return false;
}
ctx_attribs[pos++] = __DRI_CTX_ATTRIB_PRIORITY;
ctx_attribs[pos++] = val;
if (allowed & check) {
ctx_attribs[pos++] = __DRI_CTX_ATTRIB_PRIORITY;
ctx_attribs[pos++] = val;
} else {
/* The priority cannot be honored, restore it to the default
* value for future context queries.
*/
dri2_ctx->base.ContextPriority = EGL_CONTEXT_PRIORITY_MEDIUM_IMG;
}
}
if (dri2_ctx->base.ReleaseBehavior == EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR) {
......
......@@ -385,12 +385,6 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp,
* 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 (disp->Extensions.IMG_context_priority & (1 << bit))
ctx->ContextPriority = val;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment