<div dir="auto"><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Dec 6, 2017 12:34 PM, "Nicolai Hähnle" <<a href="mailto:nhaehnle@gmail.com">nhaehnle@gmail.com</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="elided-text">On 05.12.2017 20:05, Marek Olšák wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
From: Marek Olšák <<a href="mailto:marek.olsak@amd.com" target="_blank">marek.olsak@amd.com</a>><br>
<br>
Cc: 17.3 <<a href="mailto:mesa-stable@lists.freedesktop.org" target="_blank">mesa-stable@lists.freedesktop<wbr>.org</a>><br>
---<br>
  src/gallium/drivers/radeon/r60<wbr>0_texture.c | 6 +++++-<br>
  1 file changed, 5 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/src/gallium/drivers/radeon/r<wbr>600_texture.c b/src/gallium/drivers/radeon/r<wbr>600_texture.c<br>
index 2aa47b5..07f7c33 100644<br>
--- a/src/gallium/drivers/radeon/r<wbr>600_texture.c<br>
+++ b/src/gallium/drivers/radeon/r<wbr>600_texture.c<br>
@@ -739,22 +739,26 @@ static boolean r600_texture_get_handle(struct pipe_screen* screen,<br>
                        stride = rtex->surface.u.gfx9.surf_pitc<wbr>h *<br>
                                 rtex->surface.bpe;<br>
                        slice_size = rtex->surface.u.gfx9.surf_slic<wbr>e_size;<br>
                } else {<br>
                        offset = rtex->surface.u.legacy.level[0<wbr>].offset;<br>
                        stride = rtex->surface.u.legacy.level[0<wbr>].nblk_x *<br>
                                 rtex->surface.bpe;<br>
                        slice_size = (uint64_t)rtex->surface.u.lega<wbr>cy.level[0].slice_size_dw * 4;<br>
                }<br>
        } else {<br>
+               /* Buffer exports are for the OpenCL interop. */<br>
                /* Move a suballocated buffer into a non-suballocated allocation. */<br>
-               if (sscreen->ws->buffer_is_suball<wbr>ocated(res->buf)) {<br>
+               if (sscreen->ws->buffer_is_suball<wbr>ocated(res->buf) ||<br>
+                   /* A DMABUF export always fails if the BO is local. */<br>
+                   (rtex->resource.flags & RADEON_FLAG_NO_INTERPROCESS_SH<wbr>ARING &&<br>
+                    whandle->type != DRM_API_HANDLE_TYPE_KMS)) {<br>
</blockquote>
<br></div>
I still don't think this is right. Or at least, it's bound to blow up in our faces at some point. Though I think we may have talked past each other, apologies that I haven't made myself clear.<br>
<br>
The issues I have in mind are scenarios like this:<br>
<br>
1. Buffer allocated in OpenGL.<br>
2. Buffer exported as KMS handle for importing to OpenCL in the same process.<br>
3. Buffer exported as an FD <-- at this point, the OpenGL and OpenCL buffers go out of sync because OpenGL re-allocates the buffer but OpenCL isn't informed.<br>
<br>
Or:<br>
<br>
1. Buffer allocated in OpenGL.<br>
2. Buffer exported as KMS handle for importing to OpenCL in the same process.<br>
3. Buffer attempted to be exported as an FD from OpenCL <-- fails because the buffer is local (has NO_INTERPROCESS_SHARING), and people will be utterly clueless as to what's going on.<br>
<br>
FWIW, I think the patch is good if you drop the whandle->type check so that we re-allocate unconditionally.<br></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">I can remove the check, but buffers are only exported as DMABUF. This patch isn't just random - it does fix OpenCL interop.</div><div dir="auto"><br></div><div dir="auto">Marek</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Cheers,<br>
Nicolai<div class="quoted-text"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
                        assert(!res->b.is_shared);<br>
                        /* Allocate a new buffer with PIPE_BIND_SHARED. */<br>
                        struct pipe_resource templ = res->b.b;<br>
                        templ.bind |= PIPE_BIND_SHARED;<br>
                        struct pipe_resource *newb =<br>
                                screen->resource_create(screen<wbr>, &templ);<br>
                        if (!newb)<br>
                                return false;<br>
<br>
</blockquote>
<br>
<br>
-- <br></div>
Lerne, wie die Welt wirklich ist,<br>
Aber vergiss niemals, wie sie sein sollte.<br>
</blockquote></div><br></div></div></div>