<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Thu, Sep 29, 2016 at 7:33 AM Martin Peres <<a href="mailto:martin.peres@linux.intel.com">martin.peres@linux.intel.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 02/09/16 10:08, Martin Peres wrote:<br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
> On 25/08/16 21:49, Kristian Høgsberg wrote:<br class="gmail_msg">
>> On Thu, Aug 25, 2016 at 11:38 AM, Chad Versace<br class="gmail_msg">
>> <<a href="mailto:chadversary@chromium.org" class="gmail_msg" target="_blank">chadversary@chromium.org</a>> wrote:<br class="gmail_msg">
>>> On Thu 25 Aug 2016, Martin Peres wrote:<br class="gmail_msg">
>>>> This mirrors the codepath taken by DRI2 in IntelSetTexBuffer2() and<br class="gmail_msg">
>>>> fixes many applications when using DRI3:<br class="gmail_msg">
>>>> - Totem with libva on hw-accelerated decoding<br class="gmail_msg">
>>>> - obs-studio, using Window Capture (Xcomposite) as a Source<br class="gmail_msg">
>>>> - gstreamer with VAAPI<br class="gmail_msg">
>>>><br class="gmail_msg">
>>>> Bugzilla: <a href="https://bugs.freedesktop.org/show_bug.cgi?id=71759" rel="noreferrer" class="gmail_msg" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=71759</a><br class="gmail_msg">
>>>> Signed-off-by: Martin Peres <<a href="mailto:martin.peres@linux.intel.com" class="gmail_msg" target="_blank">martin.peres@linux.intel.com</a>><br class="gmail_msg">
>>>> ---<br class="gmail_msg">
>>>><br class="gmail_msg">
>>>> This patch supposedly prevents gnome from running for one Arch Linux<br class="gmail_msg">
>>>> maintainer. Kenneth Graunke and I failed to reproduce it so I am<br class="gmail_msg">
>>>> asking for your help/comments on this.<br class="gmail_msg">
>>>><br class="gmail_msg">
>>>> src/mesa/drivers/dri/i965/intel_screen.c | 24 ++++++++++++++++++++++--<br class="gmail_msg">
>>>> 1 file changed, 22 insertions(+), 2 deletions(-)<br class="gmail_msg">
>>>><br class="gmail_msg">
>>>> diff --git a/src/mesa/drivers/dri/i965/intel_screen.c<br class="gmail_msg">
>>>> b/src/mesa/drivers/dri/i965/intel_screen.c<br class="gmail_msg">
>>>> index 7876652..5c0d300 100644<br class="gmail_msg">
>>>> --- a/src/mesa/drivers/dri/i965/intel_screen.c<br class="gmail_msg">
>>>> +++ b/src/mesa/drivers/dri/i965/intel_screen.c<br class="gmail_msg">
>>>> @@ -698,8 +698,11 @@ intel_create_image_from_fds(__DRIscreen *screen,<br class="gmail_msg">
>>>> int *fds, int num_fds, int *strides,<br class="gmail_msg">
>>>> int *offsets,<br class="gmail_msg">
>>>> void *loaderPrivate)<br class="gmail_msg">
>>>> {<br class="gmail_msg">
>>>> + GET_CURRENT_CONTEXT(ctx);<br class="gmail_msg">
>>>> struct intel_screen *intelScreen = screen->driverPrivate;<br class="gmail_msg">
>>>> + struct brw_context *brw = brw_context(ctx);<br class="gmail_msg">
>>>> struct intel_image_format *f;<br class="gmail_msg">
>>>> + dri_bufmgr *bufmgr;<br class="gmail_msg">
>>>> __DRIimage *image;<br class="gmail_msg">
>>>> int i, index;<br class="gmail_msg">
>>>><br class="gmail_msg">
>>>> @@ -740,8 +743,25 @@ intel_create_image_from_fds(__DRIscreen *screen,<br class="gmail_msg">
>>>> size = end;<br class="gmail_msg">
>>>> }<br class="gmail_msg">
>>>><br class="gmail_msg">
>>>> - image->bo = drm_intel_bo_gem_create_from_prime(intelScreen->bufmgr,<br class="gmail_msg">
>>>> - fds[0], size);<br class="gmail_msg">
>>>> + /* Let's import the buffer into the current context instead of<br class="gmail_msg">
>>>> the current<br class="gmail_msg">
>>>> + * screen as some applications like gstreamer, totem, or obs<br class="gmail_msg">
>>>> create multiple<br class="gmail_msg">
>>>> + * X connections which end up creating multiple screens and thus<br class="gmail_msg">
>>>> multiple<br class="gmail_msg">
>>>> + * buffer managers. They then proceed to use a different X<br class="gmail_msg">
>>>> connection to call<br class="gmail_msg">
>>>> + * GLXBindTexImageExt() which should import the buffer in the<br class="gmail_msg">
>>>> current thread<br class="gmail_msg">
>>>> + * bound and not the current screen. This is done properly<br class="gmail_msg">
>>>> upstairs for<br class="gmail_msg">
>>>> + * texture management so we need to mirror this behaviour if we<br class="gmail_msg">
>>>> don't want<br class="gmail_msg">
>>>> + * the kernel rejecting our pushbuffers as the buffers have not<br class="gmail_msg">
>>>> been imported<br class="gmail_msg">
>>>> + * by the same bufmgr that sent the pushbuffer.<br class="gmail_msg">
>>>> + *<br class="gmail_msg">
>>>> + * If there is no context currently bound, then revert to using<br class="gmail_msg">
>>>> the screen's<br class="gmail_msg">
>>>> + * buffer manager and hope for the best...<br class="gmail_msg">
>>><br class="gmail_msg">
>>> Nope. This patch breaks EGL_EXT_image_dma_buf_import.<br class="gmail_msg">
>>><br class="gmail_msg">
>>> When the user calls eglCreateImageKHR(EGLDisplay, EGLContext, ...) with<br class="gmail_msg">
>>> image type EGL_LINUX_DMA_BUF_EXT, then the spec requires that context be<br class="gmail_msg">
>>> NULL. The EGLDisplay parameter determines the namespace of the newly<br class="gmail_msg">
>>> created<br class="gmail_msg">
>>> EGLImage. By design, the currently bound context (and its display) DO<br class="gmail_msg">
>>> NOT affect<br class="gmail_msg">
>>> eglCreateImage.<br class="gmail_msg">
>>><br class="gmail_msg">
>>> Problem Example:<br class="gmail_msg">
>>> eglMakeCurrent(dpyA, ..., ctxA);<br class="gmail_msg">
>>> img = eglCreateImage(dpyB, EGL_NO_CONTEXT, ...);<br class="gmail_msg">
><br class="gmail_msg">
> I see, that may explain the issue Ionut found with gnome. Thanks Chad!<br class="gmail_msg">
><br class="gmail_msg">
>><br class="gmail_msg">
>> The difference between DRI2 and DRI3 is that for DRI2 we'd get a<br class="gmail_msg">
>> DRI2Buffer back from getBuffers, and then open the flink name inside<br class="gmail_msg">
>> the driver with the current context's bufmgr. In the DRI3 world, we go<br class="gmail_msg">
>> from prime fd to drm_bo in dri3_get_pixmap_buffer() with the screen<br class="gmail_msg">
>> that's associated with the current drawable.<br class="gmail_msg">
><br class="gmail_msg">
> Yes, that is the problem indeed.<br class="gmail_msg">
><br class="gmail_msg">
>><br class="gmail_msg">
>> I think the fix we're looking for is to make<br class="gmail_msg">
>> draw->vtable->get_dri_context() also return the __DRIscreen, then use<br class="gmail_msg">
>> that in dri3_get_pixmap_buffer() to get the right __DRIscreen to pass<br class="gmail_msg">
>> to loader_dri3_create_image().<br class="gmail_msg">
><br class="gmail_msg">
> Seems sensible and wouldn't require changing the world! Thanks Kristian!<br class="gmail_msg">
> I will get to it when I come back from vacation!<br class="gmail_msg">
<br class="gmail_msg">
Hey,<br class="gmail_msg">
<br class="gmail_msg">
I am finally trying your approach but then I am not sure I understand<br class="gmail_msg">
what you are saying.<br class="gmail_msg">
<br class="gmail_msg">
My patch was changing the import to always happen in the currently-bound<br class="gmail_msg">
screen, and you said it violates the spec of EGL_EXT_image_dma_buf_import.<br class="gmail_msg">
<br class="gmail_msg">
eglCreateImage's dpy is passed all the way down to<br class="gmail_msg">
intel_create_image_from_fds, which is what the spec mandates.<br class="gmail_msg"></blockquote><div><br></div><div>The problem isn't eglCreateImage, it's when the DRI driver internally imports a prime fd in dri3_get_pixmap_buffer() in src/loader/loader_dri3_helper.c. We want the DRI screen passed to loader_dri3_create_image (line 1150) to come from the current context, not the drawable.</div><div><br></div><div>We don't have a way to get the DRI screen associated with the current context (__DRIcontext is opaque here), but my suggestion above is that we make draw->vtable->get_dri_context() return it along with the __DRIcontext or perhaps make a new vfunc to get the __DRIscreen for the current context. For platform_x11_dri3.c, egl_dri3_get_dri_context() can get the screen for the current context by following dri2_egl_display(dri2_ctx->base.Resource.Display)->dri_screen.</div><div><br></div><div>Kristian</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
So, what do we do? We cannot use one single buffer manager for everyone<br class="gmail_msg">
unless we always force the authentication dance :s<br class="gmail_msg">
<br class="gmail_msg">
Martin<br class="gmail_msg">
</blockquote></div></div>