[Mesa-stable] [Mesa-dev] [PATCH 4/4] i965: Use prepare_external instead of make_shareable in setTexBuffer2

Kenneth Graunke kenneth at whitecape.org
Tue Nov 14 00:56:09 UTC 2017


On Wednesday, November 8, 2017 3:20:47 PM PST Jason Ekstrand wrote:
> The setTexBuffer2 hook from GLX is used to implement glxBindTexImageEXT
> which has tighter restrictions than just "it's shared".  In particular,
> it says that any rendering to the image while it is bound causes the
> contents to become undefined.
> 
> The GLX_EXT_texture_from_pixmap extension provides us with an acquire
> and release in the form of glXBindTexImageEXT and glXReleaseTexImageEXT.
> The extension spec says,
> 
>     "Rendering to the drawable while it is bound to a texture will leave
>     the contents of the texture in an undefined state.  However, no
>     synchronization between rendering and texturing is done by GLX.  It
>     is the application's responsibility to implement any synchronization
>     required."
> 
> From the EGL 1.4 spec for eglBindTexImage:
> 
>     "After eglBindTexImage is called, the specified surface is no longer
>     available for reading or writing.  Any read operation, such as
>     glReadPixels or eglCopyBuffers, which reads values from any of the
>     surface’s color buffers or ancillary buffers will produce
>     indeterminate results.  In addition, draw operations that are done
>     to the surface before its color buffer is released from the texture
>     produce indeterminate results
> 
> In other words, between the bind and release calls, we effectively own
> those pixels and can assume, so long as we don't crash, that no one else
> is reading from/writing to the surface.  The GLX and EGL implementations
> call the setTexBuffer2 and releaseTexBuffer function pointers that the
> driver can hook.
> 
> In theory, this means that, between BindTexImage and ReleaseTexImage, we
> own the pixels and it should be safe to track aux usage so we
> can avoid redundant resolves so long as we start off with the right
> assumption at the start of the bind/release pair.
> 
> In practice, however, X11 has slightly different expectations.  It's
> expected that the server may be drawing to the image at the same time as
> the compositor is texturing from it.  In that case, the worst expected
> outcome should be tearing or partial rendering and not random corruption
> like we see when rendering races with scanout with CCS.  Fortunately,
> the GEM rules about texture/render dependencies save us here.  If X11
> submits work to write to a pixmap after the compositor has submitted
> work to texture from it, GEM inserts a dependency between the compositor
> and X11.  If X11 is using a high-priority context, this will cause the
> compositor to get a temporarily boosted priority while the batch from
> X11 is waiting on it.  This means that we will never have an actual race
> between X11 and the compositor so no corruption can happen.
> 
> Unfortunately, however, this means that X11 will likely be rendering to it
> between the compositor's BindTexImage and ReleaseTexImage calls.  If we
> want to avoid strange issues, we need to be a bit careful about
> resolves because we can't really transition it away from the "default"
> aux usage.  The only case where this would practically be a problem is
> with image_load_store where we have to do a full resolve in order to use
> the image via the data port.  Even there it would only be a problem if
> batches were split such that X11's rendering happens between the resolve
> and the use of it as a storage image.  However, the chances of this
> happening are very slim so we just emit a warning and hope for the best.
> 
> This commit adds a new helper intel_miptree_finish_external which resets
> all aux state to whatever ISL says is the right worst-case "default" for
> the given modifier.  It feels a little awkward to call it "finish"
> because it's actually an acquire from the perspective of the driver, but
> it matches the semantics of the other prepare/finish functions.  This
> new helper gets called in intelSetTexBuffer2 instead of make_shareable.
> We also add an intelReleaseTexBuffer (we passed NULL to releaseTexBuffer
> before) and call intel_miptree_prepare_external in it.  This probably
> does nothing most of the time but it means that the prepare/finish calls
> are properly matched.
> 
> Cc: "17.3" <mesa-stable at lists.freedesktop.org>
> Cc: Chad Versace <chadversary at chromium.org>
> Cc: Daniel Stone <daniels at collabora.com>
> Cc: Louis-Francis Ratté-Boulianne <lfrb at collabora.com>
> Cc: Adam Jackson <ajax at redhat.com>
> Cc: Chris Wilson <chris at chris-wilson.co.uk>
> Cc: Keith Packard <keithp at keithp.com>
> Cc: Eric Anholt <eric at anholt.net>

I'm going to go out on a limb and offer you a
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
for the series (assuming you fix the issue Emil caught).

Hopefully some of the other fine people in the CC list have looked
at it and are happy with it as well.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.freedesktop.org/archives/mesa-stable/attachments/20171113/f8573161/attachment-0001.sig>


More information about the mesa-stable mailing list