<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jun 7, 2017 at 4:45 PM, Chad Versace <span dir="ltr"><<a href="mailto:chadversary@chromium.org" target="_blank">chadversary@chromium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Tue 06 Jun 2017, Daniel Stone wrote:<br>
> Hi Chad,<br>
><br>
> On 6 June 2017 at 21:36, Chad Versace <<a href="mailto:chadversary@chromium.org">chadversary@chromium.org</a>> wrote:<br>
> > @@ -254,8 +255,22 @@ create_mt_for_dri_image(struct brw_context *brw,<br>
> >     struct gl_context *ctx = &brw->ctx;<br>
> >     struct intel_mipmap_tree *mt;<br>
> >     uint32_t draw_x, draw_y;<br>
> > +   mesa_format format = image->format;<br>
> > +<br>
> > +   if (!ctx->TextureFormatSupported[<wbr>format]) {<br>
> > +      /* The texture storage paths in core Mesa detect if the driver does not<br>
> > +       * support the user-requested format, and then searches for a<br>
> > +       * fallback format. The DRIimage code bypasses core Mesa, though. So we<br>
> > +       * do the fallbacks here for important formats.<br>
> > +       *<br>
> > +       * We must support DRM_FOURCC_XBGR8888 textures because the Android<br>
> > +       * framework produces HAL_PIXEL_FORMAT_RGBX8888 winsys surfaces, which<br>
> > +       * the Chrome OS compositor consumes as dma_buf EGLImages.<br>
> > +       */<br>
> > +      format = _mesa_format_fallback_rgbx_to_<wbr>rgba(format);<br>
> > +   }<br>
> ><br>
> > -   if (!ctx->TextureFormatSupported[<wbr>image->format])<br>
> > +   if (!ctx->TextureFormatSupported[<wbr>format])<br>
> >        return NULL;<br>
<br>
</span>I dislike what I wrote above. There's a much better way to do the<br>
fallback, a way that handles more types of fallback than rgbx->rgba and<br>
that's the same as the fallback used by glTexStorage2D(). The better way<br>
is to re-use the core Mesa code that the comment refers to, like this:<br>
<br>
    mesa_format format = ctx->Driver.<wbr>ChooseTextureFormat(ctx, GL_TEXTURE_2D,<br>
                                                         internalFormat, GL_NONE, GL_NONE);<br>
<br>
As precedent, that's exactly what intel_renderbuffer_format() does.<span class=""><br></span></blockquote><div><br></div><div>Does this mean we're dropping patch 1?  If not, I sent out a new version which I find much easier to comprehend.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
> ><br>
> >     /* Disable creation of the texture's aux buffers because the driver exposes<br>
> > @@ -263,7 +278,7 @@ create_mt_for_dri_image(struct brw_context *brw,<br>
> >      * buffer's content to the main buffer nor for invalidating the aux buffer's<br>
> >      * content.<br>
> >      */<br>
> > -   mt = intel_miptree_create_for_bo(<wbr>brw, image->bo, image->format,<br>
> > +   mt = intel_miptree_create_for_bo(<wbr>brw, image->bo, format,<br>
> >                                      0, image->width, image->height, 1,<br>
> >                                      image->pitch,<br>
> >                                      MIPTREE_LAYOUT_DISABLE_AUX);<br>
><br>
> I wonder if it wouldn't be better to do this in<br>
> intel_create_image_from_name. That way it would be more obvious<br>
> up-front what's happening,<br>
<br>
</span>I agree that the intent would become more obvious if the format fallback<br>
were done at time of import instead of gl*Storage. But I see two<br>
arguments against it:<br>
<br>
    1. First, the weaker argument.<br>
<br>
       The chosen fallback format,<br>
       and even the choice to do a fallback at all, is a property of the<br>
       image's usage and not a property of the image itself. A single<br>
       image can have multiple uses during its lifetime, and the driver<br>
       may need a different fallback or no fallback for each. I'm<br>
       defining "image usage" here in terms of<br>
       glEGLImageTargetTexture2DOES, glEGLImageTargetRenderbufferSt<wbr>orageOES, and<br>
       GL_TEXURE_EXTERNAL_OES vs GL_TEXTURE_2D.<br>
<br>
       Which reminds me... I should have submitted an analgous patch for<br>
       glEGLImageTargetRenderbufferSt<wbr>orageOES().<br>
<br>
       Since the driver may support a given format for texturing but not<br>
       rendering, or for rendering but not texturing, we would need to do at<br>
       least two format fallbacks during image import, and cache the fallback<br>
       results in the image struct. This approach is possible, but...<br>
       onto the next bullet.<br></blockquote><div><br></div><div>I don't think that argument is all that weak<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
    2. A more practical argument.<br>
<br>
       If possible, it's better to do the fallback for<br>
       glEGLImageTextureTarget2DOES() in the same way as for<br>
       glTexStorage2D(), as I explained above. But that requires access<br>
       to a GL context; eglCreateImage may be called without<br>
       a context. [EGL_EXT_image_dma_buf_import explicitly requires that<br>
       eglCreateImage(context=EGL_<wbr>CONTEXT_NONE)]; and therefore<br>
       intel_create_image_name() and friends also have no context.<span class=""><br></span></blockquote><div><br></div><div>But this one really sets it.  Let's have the image have the "correct" format and fix it in miptree_create_for_dri_image.  Speaking of such, I just rewrote that function and I'm not sure how this fits in.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
> and also it'd be easy to add the analogue<br>
> to intel_create_image_from_fds for the explicit dmabuf (as opposed to<br>
> ANativeBuffer; your description of 'from dmabufs' threw me because the<br>
> dmabuf fd import path would fail immediately on FourCC lookup) import<br>
> path.<br>
<br>
</span>I did mean dma_buf, not AHardwareBuffer or ANativeBuffer, in this patch.<br>
<br>
The patch series is secretly crazy. It's implicitly partitioned into<br>
3 sets of patches: patches that touch code that will run only on<br>
Android; that will run only on Chrome OS; and that will run on both.<br>
<br>
  - The patch "i965/dri: Support R8G8B8A8 and R8G8B8X8 configs" falls<br>
    into the "runs only on Android category". It deals with creating an<br>
    EGLSurface from a AHardwareBuffer with HAL_PIXEL_FORMAT_RGBX_8888.<br>
<br>
  - This patch falls into the "runs only on Chrome OS" category. It<br>
    helps the Chrome OS compositor import the above-mentioned client's<br>
    R8G8B8X8 EGLSurface through eglCreateImage(EGL_LINUX_DMA_<wbr>BUF) and<br>
    glEGLImageTextureTarget2DOES. Outside the Android container, there's<br>
    no AHardwareBuffer; it's all dma_bufs here.<br>
<br>
Anyway, why would it fail during fourcc lookup?  The table<br>
intel_screen.c:intel_image_<wbr>formats[] contains an entry for<br>
__DRI_IMAGE_FOURCC_XBGR8888. And egl_dri2.c:dri2_check_dma_buf_<wbr>format()<br>
knows about DRM_FORMAT_XBGR8888 too.<br>
<span class=""><br>
> As an aside, it's safe to enable in Wayland (IMO anyway), because we<br>
> only use the DRM format there; there's no concept of a 'surface<br>
> format' or visuals inside the Wayland client EGL platform, just direct<br>
> sampling from whichever buffer was last attached. EGL_NATIVE_VISUAL_ID<br>
> is empty, because we don't have anything to expose to the client.<br>
> Probably famous last words tho.<br>
<br>
</span>Good to know. That's one less thing my patches may break.<br>
<div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</div></div></blockquote></div><br></div></div>