<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, May 17, 2018 at 6:50 AM, Lucas Stach <span dir="ltr"><<a href="mailto:l.stach@pengutronix.de" target="_blank">l.stach@pengutronix.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Each time I have to touch the buffer import/export functions in the dri<br>
state tracker I get lost in the maze of functions converting between<br>
DRI_IMAGE_FOURCC, DRI_IMAGE_FORMAT, DRI_IMAGE_COMPONENTS and pipe format.<br>
<br>
Rip it out and replace by a single table, which defines the correspondence<br>
between the different representations.<br>
<br>
Also this now stores all the known representations in the __DRIimageRec,<br>
to avoid the loss of information we currently have when importing a buffer<br>
with a fourcc, which doesn't have a corresponding dri format.<br>
<br>
Signed-off-by: Lucas Stach <<a href="mailto:l.stach@pengutronix.de">l.stach@pengutronix.de</a>><br>
---<br>
 src/gallium/state_trackers/<wbr>dri/dri2.c       | 476 ++++++--------------<br>
 src/gallium/state_trackers/<wbr>dri/dri_screen.h |   1 +<br>
 2 files changed, 138 insertions(+), 339 deletions(-)<br>
<br>
diff --git a/src/gallium/state_trackers/<wbr>dri/dri2.c b/src/gallium/state_trackers/<wbr>dri/dri2.c<br>
index 859161fb87ac..9c74ca54fc89 100644<br>
--- a/src/gallium/state_trackers/<wbr>dri/dri2.c<br>
+++ b/src/gallium/state_trackers/<wbr>dri/dri2.c<br>
@@ -54,295 +54,72 @@<br>
 #define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)<br>
 #endif<br>
<br>
-static const int fourcc_formats[] = {<br>
-   __DRI_IMAGE_FOURCC_<wbr>ARGB2101010,<br>
-   __DRI_IMAGE_FOURCC_<wbr>XRGB2101010,<br>
-   __DRI_IMAGE_FOURCC_<wbr>ABGR2101010,<br>
-   __DRI_IMAGE_FOURCC_<wbr>XBGR2101010,<br>
-   __DRI_IMAGE_FOURCC_ARGB8888,<br>
-   __DRI_IMAGE_FOURCC_ABGR8888,<br>
-   __DRI_IMAGE_FOURCC_SARGB8888,<br>
-   __DRI_IMAGE_FOURCC_XRGB8888,<br>
-   __DRI_IMAGE_FOURCC_XBGR8888,<br>
-   __DRI_IMAGE_FOURCC_ARGB1555,<br>
-   __DRI_IMAGE_FOURCC_RGB565,<br>
-   __DRI_IMAGE_FOURCC_R8,<br>
-   __DRI_IMAGE_FOURCC_R16,<br>
-   __DRI_IMAGE_FOURCC_GR88,<br>
-   __DRI_IMAGE_FOURCC_GR1616,<br>
-   __DRI_IMAGE_FOURCC_YUV410,<br>
-   __DRI_IMAGE_FOURCC_YUV411,<br>
-   __DRI_IMAGE_FOURCC_YUV420,<br>
-   __DRI_IMAGE_FOURCC_YUV422,<br>
-   __DRI_IMAGE_FOURCC_YUV444,<br>
-   __DRI_IMAGE_FOURCC_YVU410,<br>
-   __DRI_IMAGE_FOURCC_YVU411,<br>
-   __DRI_IMAGE_FOURCC_YVU420,<br>
-   __DRI_IMAGE_FOURCC_YVU422,<br>
-   __DRI_IMAGE_FOURCC_YVU444,<br>
-   __DRI_IMAGE_FOURCC_NV12,<br>
-   __DRI_IMAGE_FOURCC_NV16,<br>
-   __DRI_IMAGE_FOURCC_YUYV<br>
-};<br>
-<br>
-static int convert_fourcc(int format, int *dri_components_p)<br>
-{<br>
+struct dri2_format_mapping {<br>
+   int dri_fourcc;<br>
+   int dri_format;<br>
    int dri_components;<br>
-   switch(format) {<br>
-   case __DRI_IMAGE_FOURCC_RGB565:<br>
-      format = __DRI_IMAGE_FORMAT_RGB565;<br>
-      dri_components = __DRI_IMAGE_COMPONENTS_RGB;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_ARGB8888:<br>
-      format = __DRI_IMAGE_FORMAT_ARGB8888;<br>
-      dri_components = __DRI_IMAGE_COMPONENTS_RGBA;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_XRGB8888:<br>
-      format = __DRI_IMAGE_FORMAT_XRGB8888;<br>
-      dri_components = __DRI_IMAGE_COMPONENTS_RGB;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_ABGR8888:<br>
-      format = __DRI_IMAGE_FORMAT_ABGR8888;<br>
-      dri_components = __DRI_IMAGE_COMPONENTS_RGBA;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_XBGR8888:<br>
-      format = __DRI_IMAGE_FORMAT_XBGR8888;<br>
-      dri_components = __DRI_IMAGE_COMPONENTS_RGB;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_<wbr>ARGB2101010:<br>
-      format = __DRI_IMAGE_FORMAT_<wbr>ARGB2101010;<br>
-      dri_components = __DRI_IMAGE_COMPONENTS_RGBA;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_<wbr>XRGB2101010:<br>
-      format = __DRI_IMAGE_FORMAT_<wbr>XRGB2101010;<br>
-      dri_components = __DRI_IMAGE_COMPONENTS_RGB;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_<wbr>ABGR2101010:<br>
-      format = __DRI_IMAGE_FORMAT_<wbr>ABGR2101010;<br>
-      dri_components = __DRI_IMAGE_COMPONENTS_RGBA;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_<wbr>XBGR2101010:<br>
-      format = __DRI_IMAGE_FORMAT_<wbr>XBGR2101010;<br>
-      dri_components = __DRI_IMAGE_COMPONENTS_RGB;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_R8:<br>
-      format = __DRI_IMAGE_FORMAT_R8;<br>
-      dri_components = __DRI_IMAGE_COMPONENTS_R;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_GR88:<br>
-      format = __DRI_IMAGE_FORMAT_GR88;<br>
-      dri_components = __DRI_IMAGE_COMPONENTS_RG;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_R16:<br>
-      format = __DRI_IMAGE_FORMAT_R16;<br>
-      dri_components = __DRI_IMAGE_COMPONENTS_R;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_GR1616:<br>
-      format = __DRI_IMAGE_FORMAT_GR1616;<br>
-      dri_components = __DRI_IMAGE_COMPONENTS_RG;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_YUYV:<br>
-      format = __DRI_IMAGE_FORMAT_YUYV;<br>
-      dri_components = __DRI_IMAGE_COMPONENTS_Y_XUXV;<br>
-      break;<br>
-   /*<br>
-    * For multi-planar YUV formats, we return the format of the first<br>
-    * plane only.  Since there is only one caller which supports multi-<br>
-    * planar YUV it gets to figure out the remaining planes on it's<br>
-    * own.<br>
-    */<br>
-   case __DRI_IMAGE_FOURCC_YUV420:<br>
-   case __DRI_IMAGE_FOURCC_YVU420:<br>
-      format = __DRI_IMAGE_FORMAT_R8;<br>
-      dri_components = __DRI_IMAGE_COMPONENTS_Y_U_V;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_NV12:<br>
-      format = __DRI_IMAGE_FORMAT_R8;<br>
-      dri_components = __DRI_IMAGE_COMPONENTS_Y_UV;<br>
-      break;<br>
-   default:<br>
-      return -1;<br>
-   }<br>
-   *dri_components_p = dri_components;<br>
-   return format;<br>
-}<br>
-<br>
-/* NOTE this probably isn't going to do the right thing for YUV images<br>
- * (but I think the same can be said for intel_query_image()).  I think<br>
- * only needed for exporting dmabuf's, so I think I won't loose much<br>
- * sleep over it.<br>
- */<br>
-static int convert_to_fourcc(int format)<br>
-{<br>
-   switch(format) {<br>
-   case __DRI_IMAGE_FORMAT_RGB565:<br>
-      format = __DRI_IMAGE_FOURCC_RGB565;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_ARGB8888:<br>
-      format = __DRI_IMAGE_FOURCC_ARGB8888;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_XRGB8888:<br>
-      format = __DRI_IMAGE_FOURCC_XRGB8888;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_ABGR8888:<br>
-      format = __DRI_IMAGE_FOURCC_ABGR8888;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_XBGR8888:<br>
-      format = __DRI_IMAGE_FOURCC_XBGR8888;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_<wbr>ARGB2101010:<br>
-      format = __DRI_IMAGE_FOURCC_<wbr>ARGB2101010;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_<wbr>XRGB2101010:<br>
-      format = __DRI_IMAGE_FOURCC_<wbr>XRGB2101010;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_<wbr>ABGR2101010:<br>
-      format = __DRI_IMAGE_FOURCC_<wbr>ABGR2101010;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_<wbr>XBGR2101010:<br>
-      format = __DRI_IMAGE_FOURCC_<wbr>XBGR2101010;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_R8:<br>
-      format = __DRI_IMAGE_FOURCC_R8;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_GR88:<br>
-      format = __DRI_IMAGE_FOURCC_GR88;<br>
-      break;<br>
-   default:<br>
-      return -1;<br>
-   }<br>
-   return format;<br>
-}<br>
+   enum pipe_format pipe_format;<br>
+};<br>
<br>
-static enum pipe_format dri2_format_to_pipe_format (int format)<br>
-{<br>
-   enum pipe_format pf;<br>
+static const struct dri2_format_mapping dri2_format_table[] = {<br>
+      { __DRI_IMAGE_FOURCC_<wbr>ARGB2101010,   __DRI_IMAGE_FORMAT_<wbr>ARGB2101010,<br>
+        __DRI_IMAGE_COMPONENTS_RGBA,      PIPE_FORMAT_B10G10R10A2_UNORM },<br>
+      { __DRI_IMAGE_FOURCC_<wbr>XRGB2101010,   __DRI_IMAGE_FORMAT_<wbr>XRGB2101010,<br>
+        __DRI_IMAGE_COMPONENTS_RGB,       PIPE_FORMAT_B10G10R10X2_UNORM },<br>
+      { __DRI_IMAGE_FOURCC_<wbr>ABGR2101010,   __DRI_IMAGE_FORMAT_<wbr>ABGR2101010,<br>
+        __DRI_IMAGE_COMPONENTS_RGBA,      PIPE_FORMAT_R10G10B10A2_UNORM },<br>
+      { __DRI_IMAGE_FOURCC_<wbr>XBGR2101010,   __DRI_IMAGE_FORMAT_<wbr>XBGR2101010,<br>
+        __DRI_IMAGE_COMPONENTS_RGB,       PIPE_FORMAT_R10G10B10X2_UNORM },<br>
+      { __DRI_IMAGE_FOURCC_ARGB8888,      __DRI_IMAGE_FORMAT_ARGB8888,<br>
+        __DRI_IMAGE_COMPONENTS_RGBA,      PIPE_FORMAT_BGRA8888_UNORM },<br>
+      { __DRI_IMAGE_FOURCC_ABGR8888,      __DRI_IMAGE_FORMAT_ABGR8888,<br>
+        __DRI_IMAGE_COMPONENTS_RGBA,      PIPE_FORMAT_RGBA8888_UNORM },<br>
+      { __DRI_IMAGE_FOURCC_SARGB8888,     __DRI_IMAGE_FORMAT_SARGB8,<br>
+        __DRI_IMAGE_COMPONENTS_RGBA,      PIPE_FORMAT_BGRA8888_SRGB },<br>
+      { __DRI_IMAGE_FOURCC_XRGB8888,      __DRI_IMAGE_FORMAT_XRGB8888,<br>
+        __DRI_IMAGE_COMPONENTS_RGB,       PIPE_FORMAT_BGRX8888_UNORM },<br>
+      { __DRI_IMAGE_FOURCC_XBGR8888,      __DRI_IMAGE_FORMAT_XBGR8888,<br>
+        __DRI_IMAGE_COMPONENTS_RGB,       PIPE_FORMAT_RGBX8888_UNORM },<br>
+      { __DRI_IMAGE_FOURCC_ARGB1555,      __DRI_IMAGE_FORMAT_NONE,<br>
+        __DRI_IMAGE_COMPONENTS_RGBA,      PIPE_FORMAT_B5G5R5A1_UNORM },<br>
+      { __DRI_IMAGE_FOURCC_RGB565,        __DRI_IMAGE_FORMAT_RGB565,<br>
+        __DRI_IMAGE_COMPONENTS_RGB,       PIPE_FORMAT_B5G6R5_UNORM },<br>
+      { __DRI_IMAGE_FOURCC_R8,            __DRI_IMAGE_FORMAT_R8,<br>
+        __DRI_IMAGE_COMPONENTS_R,         PIPE_FORMAT_R8_UNORM },<br>
+      { __DRI_IMAGE_FOURCC_R16,           __DRI_IMAGE_FORMAT_R16,<br>
+        __DRI_IMAGE_COMPONENTS_R,         PIPE_FORMAT_R16_UNORM },<br>
+      { __DRI_IMAGE_FOURCC_GR88,          __DRI_IMAGE_FORMAT_GR88,<br>
+        __DRI_IMAGE_COMPONENTS_RG,        PIPE_FORMAT_RG88_UNORM },<br>
+      { __DRI_IMAGE_FOURCC_GR1616,        __DRI_IMAGE_FORMAT_GR88,<br>
+        __DRI_IMAGE_COMPONENTS_RG,        PIPE_FORMAT_RG1616_UNORM },<br>
+      { __DRI_IMAGE_FOURCC_YUV420,        __DRI_IMAGE_FORMAT_NONE,<br>
+        __DRI_IMAGE_COMPONENTS_Y_U_V,     PIPE_FORMAT_IYUV },<br>
+      { __DRI_IMAGE_FOURCC_YVU420,        __DRI_IMAGE_FORMAT_NONE,<br>
+        __DRI_IMAGE_COMPONENTS_Y_U_V,     PIPE_FORMAT_YV12 },<br>
+      { __DRI_IMAGE_FOURCC_NV12,          __DRI_IMAGE_FORMAT_NONE,<br>
+        __DRI_IMAGE_COMPONENTS_Y_UV,      PIPE_FORMAT_NV12 },<br>
+      { __DRI_IMAGE_FOURCC_YUYV,          __DRI_IMAGE_FORMAT_YUYV,<br>
+        __DRI_IMAGE_COMPONENTS_Y_XUXV,    PIPE_FORMAT_YUYV },<br>
+};<br>
<br>
-   switch (format) {<br>
-   case __DRI_IMAGE_FORMAT_RGB565:<br>
-      pf = PIPE_FORMAT_B5G6R5_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_XRGB8888:<br>
-      pf = PIPE_FORMAT_BGRX8888_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_ARGB8888:<br>
-      pf = PIPE_FORMAT_BGRA8888_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_XBGR8888:<br>
-      pf = PIPE_FORMAT_RGBX8888_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_ABGR8888:<br>
-      pf = PIPE_FORMAT_RGBA8888_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_<wbr>XRGB2101010:<br>
-      pf = PIPE_FORMAT_B10G10R10X2_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_<wbr>ARGB2101010:<br>
-      pf = PIPE_FORMAT_B10G10R10A2_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_<wbr>XBGR2101010:<br>
-      pf = PIPE_FORMAT_R10G10B10X2_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_<wbr>ABGR2101010:<br>
-      pf = PIPE_FORMAT_R10G10B10A2_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_R8:<br>
-      pf = PIPE_FORMAT_R8_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_GR88:<br>
-      pf = PIPE_FORMAT_RG88_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_R16:<br>
-      pf = PIPE_FORMAT_R16_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_GR1616:<br>
-      pf = PIPE_FORMAT_R16G16_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FORMAT_YUYV:<br>
-      pf = PIPE_FORMAT_YUYV;<br>
-      break;<br>
-   default:<br>
-      pf = PIPE_FORMAT_NONE;<br>
-      break;<br>
+static const struct dri2_format_mapping *<br>
+dri2_get_mapping_by_fourcc(<wbr>int fourcc) {<br>
+   for (unsigned i = 0; i < ARRAY_SIZE(dri2_format_table); i++) {<br>
+      if (dri2_format_table[i].dri_<wbr>fourcc == fourcc)<br>
+               return &dri2_format_table[i];<br>
    }<br>
<br>
-   return pf;<br>
+   return NULL;<br>
 }<br>
<br>
-static enum pipe_format fourcc_to_pipe_format(int fourcc)<br>
-{<br>
-   enum pipe_format pf;<br>
-<br>
-   switch (fourcc) {<br>
-   case __DRI_IMAGE_FOURCC_R8:<br>
-      pf = PIPE_FORMAT_R8_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_GR88:<br>
-      pf = PIPE_FORMAT_RG88_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_ARGB1555:<br>
-      pf = PIPE_FORMAT_B5G5R5A1_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_R16:<br>
-      pf = PIPE_FORMAT_R16_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_GR1616:<br>
-      pf = PIPE_FORMAT_RG1616_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_RGB565:<br>
-      pf = PIPE_FORMAT_B5G6R5_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_ARGB8888:<br>
-      pf = PIPE_FORMAT_BGRA8888_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_XRGB8888:<br>
-      pf = PIPE_FORMAT_BGRX8888_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_ABGR8888:<br>
-      pf = PIPE_FORMAT_RGBA8888_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_XBGR8888:<br>
-      pf = PIPE_FORMAT_RGBX8888_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_<wbr>ARGB2101010:<br>
-      pf = PIPE_FORMAT_B10G10R10A2_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_<wbr>XRGB2101010:<br>
-      pf = PIPE_FORMAT_B10G10R10X2_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_<wbr>ABGR2101010:<br>
-      pf = PIPE_FORMAT_R10G10B10A2_UNORM;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_<wbr>XBGR2101010:<br>
-      pf = PIPE_FORMAT_R10G10B10X2_UNORM;<br>
-      break;<br>
-<br>
-   case __DRI_IMAGE_FOURCC_NV12:<br>
-      pf = PIPE_FORMAT_NV12;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_YUYV:<br>
-      pf = PIPE_FORMAT_YUYV;<br>
-      break;<br>
-   case __DRI_IMAGE_FOURCC_YUV420:<br>
-   case __DRI_IMAGE_FOURCC_YVU420:<br>
-      pf = PIPE_FORMAT_YV12;<br>
-      break;<br>
-<br>
-   case __DRI_IMAGE_FOURCC_SARGB8888:<br>
-   case __DRI_IMAGE_FOURCC_YUV410:<br>
-   case __DRI_IMAGE_FOURCC_YUV411:<br>
-   case __DRI_IMAGE_FOURCC_YUV422:<br>
-   case __DRI_IMAGE_FOURCC_YUV444:<br>
-   case __DRI_IMAGE_FOURCC_NV16:<br>
-   case __DRI_IMAGE_FOURCC_YVU410:<br>
-   case __DRI_IMAGE_FOURCC_YVU411:<br>
-   case __DRI_IMAGE_FOURCC_YVU422:<br>
-   case __DRI_IMAGE_FOURCC_YVU444:<br>
-   default:<br>
-      pf = PIPE_FORMAT_NONE;<br>
+static const struct dri2_format_mapping *<br>
+dri2_get_mapping_by_format(<wbr>int format) {<br>
+   for (unsigned i = 0; i < ARRAY_SIZE(dri2_format_table); i++) {<br>
+      if (dri2_format_table[i].dri_<wbr>format == format)<br>
+               return &dri2_format_table[i];<br>
    }<br>
<br>
-   return pf;<br>
+   return NULL;<br>
 }<br>
<br>
 /**<br>
@@ -983,7 +760,7 @@ dri2_update_tex_buffer(struct dri_drawable *drawable,<br>
<br>
 static __DRIimage *<br>
 dri2_create_image_from_winsys(<wbr>__DRIscreen *_screen,<br>
-                              int width, int height, int format,<br>
+                              int width, int height, enum pipe_format pf,<br>
                               int num_handles, struct winsys_handle *whandle,<br>
                               void *loaderPrivate)<br>
 {<br>
@@ -992,13 +769,8 @@ dri2_create_image_from_winsys(<wbr>__DRIscreen *_screen,<br>
    __DRIimage *img;<br>
    struct pipe_resource templ;<br>
    unsigned tex_usage = 0;<br>
-   enum pipe_format pf;<br>
    int i;<br>
<br>
-   pf = dri2_format_to_pipe_format (format);<br>
-   if (pf == PIPE_FORMAT_NONE)<br>
-      return NULL;<br>
-<br>
    if (pscreen->is_format_supported(<wbr>pscreen, pf, screen->target, 0,<br>
                                     PIPE_BIND_RENDER_TARGET))<br>
       tex_usage |= PIPE_BIND_RENDER_TARGET;<br>
@@ -1006,6 +778,20 @@ dri2_create_image_from_winsys(<wbr>__DRIscreen *_screen,<br>
                                     PIPE_BIND_SAMPLER_VIEW))<br>
       tex_usage |= PIPE_BIND_SAMPLER_VIEW;<br>
<br>
+   if (!tex_usage && util_format_is_yuv(pf)) {<br>
+      /* YUV format sampling can be emulated by the Mesa state tracker by<br>
+       * using multiple R8/RG88 samplers. So try to rewrite the pipe format.<br>
+       */<br>
+      pf = PIPE_FORMAT_R8_UNORM;<br>
+<br>
+      if (pscreen->is_format_supported(<wbr>pscreen, pf, screen->target, 0,<br>
+                                       PIPE_BIND_SAMPLER_VIEW))<br>
+         tex_usage |= PIPE_BIND_SAMPLER_VIEW;<br>
+   }<br></blockquote><div><br></div><div>This doesn't seem to belong in this commit.</div><div><br></div><div>Other than that, the series is:</div><div><br></div><div>Reviewed-by: Marek Olšák <<a href="mailto:marek.olsak@amd.com">marek.olsak@amd.com</a>></div><div><br></div><div>Marek<br></div></div><br></div></div>