<div dir="ltr">I'm adding Chad to the Cc.  At some point, it would be good to get Beignet playing well with mesa.  Personally, I have substantial reservations about getting the kernel involved in surface layout for anything more than 2-D non-mipmapped non-array surfaces.  Laying them out can be complicated, and committing to a stable API, or worse a kernel API seems a bit tricky.  But I'll let chad rant about that :-)<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Feb 6, 2016 at 2:55 AM, Marek Olšák <span dir="ltr"><<a href="mailto:maraeo@gmail.com" target="_blank">maraeo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Also, to clear up some confusion about libdrm_amdgpu, there is always<br>
one amdgpu_device instance per device (not per fd, reopened and dup'd<br>
fds are matched to one device and one instance). (Also, the uniqueness<br>
of amdgpu_device extends to amdgpu_winsys and pipe_screen, because the<br>
winsys only creates one instance of itself and one pipe_screen for<br>
each unique amdgpu_device_handle. This is a requirement for GL-VDPAU<br>
interop, which requires one pipe_screen per process, but I digress.)<br>
amdgpu_device also maintains a list of existing buffer handles, and<br>
buffer imports and exports are skipped if the handles are known. This<br>
means that amdgpu_bo instances aren't recreated when doing an export<br>
and then import to another client.<br>
<br>
Marek<br>
<div><div class="h5"><br>
On Fri, Feb 5, 2016 at 10:31 PM, Marek Olšák <<a href="mailto:maraeo@gmail.com">maraeo@gmail.com</a>> wrote:<br>
> On Fri, Feb 5, 2016 at 8:31 PM, Nicolai Hähnle <<a href="mailto:nhaehnle@gmail.com">nhaehnle@gmail.com</a>> wrote:<br>
>> Hi,<br>
>><br>
>><br>
>> On 04.02.2016 17:25, Marek Olšák wrote:<br>
>>><br>
>>> I would like to start a discussion about an OpenGL-OpenCL interop<br>
>>> interface where OpenCL is not part of Mesa.<br>
>>><br>
>>> I think the only way to do this is to have Mesa export functions that<br>
>>> convert Mesa OpenGL objects into DMABUF handles. Such functions can be<br>
>>> exported by DRI driver modules or libGL & libEGL, however, it's<br>
>>> possible that the OpenCL stack won't link against libGL & libEGL,<br>
>>> therefore it's not required to expose the interface as GLX/EGL<br>
>>> extensions.<br>
>>><br>
>>> The existing EGL extension for DMABUF exports only works with EGL<br>
>>> images, whereas this needs to work with OpenGL handles directly.<br>
>>><br>
>>> All functions should accept a context pointer, because that's what<br>
>>> OpenCL receives from the user and the context might not be current.<br>
>>><br>
>>> This is the proposed interface for sharing OpenGL buffers and<br>
>>> textures. This is just a draft and will most likely be changed. The<br>
>>> OpenCL stack is expected to obtain there via dlsym(RTLD_DEFAULT):<br>
>>><br>
>>> int glXBufferExportDMABUFHandle(GLXContext context, GLuint bufferObj,<br>
>>> unsigned flags);<br>
>>> int eglBufferExportDMABUFHandle(EGLContext context, GLuint bufferObj,<br>
>>> unsigned flags);<br>
>>> int glXTextureExportDMABUFHandle(GLXContext context, GLuint<br>
>>> textureObj, GLenum textureTarget, unsigned flags);<br>
>>> int eglTextureExportDMABUFHandle(EGLContext context, GLuint<br>
>>> textureObj, GLenum textureTarget, unsigned flags);<br>
>>><br>
>>> #define FLAG_CL_USAGE_READ_ONLY (1 << 0)<br>
>>><br>
>>> Mesa should return a value <= 0 if bufferObj, textureObj, or<br>
>>> textureTarget is invalid. (TBD)<br>
>>><br>
>>> The information about the texture format, texture layout (2D, 3D,<br>
>>> array, mipmap, ...), texture sizes, and hw-specific tiling parameters<br>
>>> is expected to be attached to the DMABUF handle using a<br>
>>> driver-specific ioctl (done by the Mesa driver), and likewise, the<br>
>>> OpenCL stack is expected to query it using a similar ioctl. Right now,<br>
>>> the DMABUF handle is the only piece of information that is publicly<br>
>>> returned to the OpenCL stack.<br>
>><br>
>><br>
>> Some thoughts: if this information must be queried via a driver-specific<br>
>> ioctl anyway, then does it really make sense to define a generic exporting<br>
>> interface for textures?<br>
><br>
> Yes, because the radeonsi driver can't translate a GL texture object<br>
> into a pipe_resource. This must be done in a component that has access<br>
> to struct gl_context.<br>
><br>
> Also, libGL is the only library that can convert GLXContext to<br>
> __DRIcontext. On the other hand, the *_dri.so module is the only one<br>
> that can convert __DRIcontext to gl_context, so multiple components<br>
> will have to be touched, most probably these:<br>
> - libGL (GLXContext -> __DRIcontext)<br>
> - libEGL (EGLContext -> __DRIcontext)<br>
> - dri_interface.h (receives __DRIcontext regardless of API)<br>
> - st/dri (__DRIcontext -> gl_context & pipe_context; GL handle -><br>
> pipe_resource; call resource_get_handle)<br>
> - gallium interface (passing the "flags" parameter to resource_get_handle)<br>
> - radeonsi (set buffer metadata via libdrm; eliminate CMASK; eliminate<br>
> DCC if flags != read-only, etc.)<br>
><br>
>><br>
>> If the consensus is yes, then I'd say the interface looks pretty reasonable.<br>
>> Having the textureTarget as a parameter seems to be redundant if the layout<br>
>> is attached to the DMABUF. I notice the OpenCL interface exposes it though,<br>
>> so I don't feel strongly about it.<br>
><br>
> The reason for that is that OpenCL can't check if the target is valid,<br>
> so Mesa has to do it and return an error accordingly.<br>
><br>
>><br>
>> If OpenCL lives outside of Mesa but still calls into the kernel via libdrm,<br>
>> then it could potentially be more efficient to do the sharing via libdrm<br>
>> structures. Should that be done with an additional interface? Since they are<br>
>> hw-specific, wiring up such an interface might end up being awkward. I think<br>
>> it'd nicer to have these functions return a void* which is interpreted<br>
>> depending on the flags.<br>
><br>
> We can't do that, because libdrm doesn't understand GL texture handles.<br>
><br>
>><br>
>> What's the error handling story? It seems most errors checked by these<br>
>> functions would result in CL_INVALID_GL_OBJECT, but perhaps some<br>
>> implementations want to signal CL_OUT_OF_HOST_MEMORY. How to distinguish<br>
>> between them?<br>
><br>
> Only ~1024 open DMABUF handles are allowed per process, which means we<br>
> can simply use all negative values for errors. The exact errors<br>
> returned by the functions are still to be determined.<br>
><br>
> Marek<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
</div></div><a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</blockquote></div><br></div>