[Mesa-dev] [PATCH] __DRIimage: Add formats with implied swizzling

Kristian Høgsberg krh at bitplanet.net
Tue Jul 17 13:19:16 PDT 2012


When we sample U and V from YUYV buffers, U and V ends up in G and A
in the shader.  Instead of pushing this to the application, just swizzle
U and V to R and G and set B to 0 and A to 1.
---
 docs/WL_bind_wayland_display.spec            |   24 +++++++++++-------------
 include/EGL/eglmesaext.h                     |    1 -
 include/GL/internal/dri_interface.h          |    7 +++++++
 src/egl/drivers/dri2/egl_dri2.c              |    6 +++---
 src/mesa/drivers/dri/intel/intel_screen.c    |    2 ++
 src/mesa/drivers/dri/intel/intel_tex_image.c |   22 ++++++++++++++++++++++
 6 files changed, 45 insertions(+), 17 deletions(-)

diff --git a/docs/WL_bind_wayland_display.spec b/docs/WL_bind_wayland_display.spec
index e1aca53..9b84e91 100644
--- a/docs/WL_bind_wayland_display.spec
+++ b/docs/WL_bind_wayland_display.spec
@@ -122,15 +122,13 @@ Additions to the EGL 1.4 Specification:
     each EGLImage and how they map to rgba components in the shader.
     The naming conventions separates planes by _ and within each
     plane, the order or R, G, B, A, Y, U, and V indicates how those
-    components map to the rgba value returned by the sampler.  X
-    indicates that the corresponding component in the rgba value isn't
-    used.
+    components map to the rgba value returned by the sampler.
 
     RGB and RGBA buffer types:
 
         EGL_WAYLAND_BUFFER_RGB_WL
                 One plane, samples RGB from the texture to rgb in the
-                shader.  Alpha channel is not valid.
+                shader.  Alpha channel is one.
 
         EGL_WAYLAND_BUFFER_RGBA_WL              0x31D9
                 One plane, samples RGBA from the texture to rgba in the
@@ -139,17 +137,14 @@ Additions to the EGL 1.4 Specification:
     YUV buffer types:
 
         EGL_WAYLAND_BUFFER_Y_U_V_WL             0x31Da
-                Three planes, samples Y from the first plane to r in
-                the shader, U from the second plane to r, and V from
-                the third plane to r.
+                Three planes, samples Y from the first plane to r in the
+                shader, U from the second plane to r, and V from the third
+                plane to r.  Components g and b are zero, a is one.
 
         EGL_WAYLAND_BUFFER_Y_UV_WL              0x31Db
-                Two planes, samples Y from the first plane to r in
-                the shader, U and V from the second plane to rg.
-
-        EGL_WAYLAND_BUFFER_Y_XUXV_WL            0x31Dc
-                Two planes, samples Y from the first plane to r in
-                the shader, U and V from the second plane to g and a.
+                Two planes, samples Y from the first plane to r in the shader,
+                U and V from the second plane to rg.  Component b is zero, a
+                is one.
 
     After querying the wl_buffer layout, create EGLImages for the
     planes by calling eglCreateImageKHR with wl_buffer as
@@ -174,3 +169,6 @@ Revision History
     Version 3, July 10, 2012
         Add eglQueryWaylandBufferWL and the various buffer
         formats. (Kristian Høgsberg)
+    Version 4, July 10, 2012
+        Drop Y_XUXV format and just make the driver swizzle incoming values
+        so they map to rgba in that order. (Kristian Høgsberg)
diff --git a/include/EGL/eglmesaext.h b/include/EGL/eglmesaext.h
index 74d8ced..85b44e4 100644
--- a/include/EGL/eglmesaext.h
+++ b/include/EGL/eglmesaext.h
@@ -121,7 +121,6 @@ typedef EGLDisplay (EGLAPIENTRYP PFNEGLGETDRMDISPLAYMESA) (int fd);
 #define EGL_WAYLAND_BUFFER_RGBA_WL	0x31D9
 #define EGL_WAYLAND_BUFFER_Y_U_V_WL	0x31Da
 #define EGL_WAYLAND_BUFFER_Y_UV_WL	0x31Db
-#define EGL_WAYLAND_BUFFER_Y_XUXV_WL	0x31Dc
 
 struct wl_display;
 struct wl_buffer;
diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
index d3a66c5..29c0872 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -920,6 +920,11 @@ struct __DRIdri2ExtensionRec {
  * little endian __DRI_IMAGE_FORMAT_XRGB8888 corresponds to
  * MESA_FORMAT_XRGB8888, but MESA_FORMAT_XRGB8888_REV on big endian.
  *
+ * The 0R88 ang G0R08888 formats implies a swizzle to zero out the 0
+ * components and swizzle the R and G components into place.  The formats are
+ * native endian and thus, for G0R08888 on little endian, bits 8-15 (second
+ * byte) maps to red and bits 24-31 (fourth byte) maps to green.
+ *
  * __DRI_IMAGE_FORMAT_NONE is for images that aren't directly usable
  * by the driver (YUV planar formats) but serve as a base image for
  * creating sub-images for the different planes within the image.
@@ -932,6 +937,8 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_FORMAT_R8           0x1006 /* Since version 5 */
 #define __DRI_IMAGE_FORMAT_GR88         0x1007
 #define __DRI_IMAGE_FORMAT_NONE         0x1008
+#define __DRI_IMAGE_FORMAT_0R88         0x1009
+#define __DRI_IMAGE_FORMAT_G0R08888     0x100a
 
 #define __DRI_IMAGE_USE_SHARE		0x0001
 #define __DRI_IMAGE_USE_SCANOUT		0x0002
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index fcb2264..b396899 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1118,9 +1118,9 @@ static const struct wl_drm_format_descriptor {
     * texture sampler interpolate the Y components correctly when
     * sampling from plane 0, and interpolate U and V correctly when
     * sampling from plane 1. */
-   { WL_DRM_FORMAT_YUYV, EGL_WAYLAND_BUFFER_Y_XUXV_WL, 2,
-     { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 },
-       { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } }
+   { WL_DRM_FORMAT_YUYV, EGL_WAYLAND_BUFFER_Y_UV_WL, 2,
+     { { 0, 0, 0, __DRI_IMAGE_FORMAT_0R88, 2 },
+       { 0, 1, 0, __DRI_IMAGE_FORMAT_G0R08888, 4 } } }
 };
 
 static _EGLImage *
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
index e52bf13..7b7a9f7 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -195,6 +195,7 @@ intel_allocate_image(int dri_format, void *loaderPrivate)
        image->format = MESA_FORMAT_XRGB8888;
        break;
     case __DRI_IMAGE_FORMAT_ARGB8888:
+    case __DRI_IMAGE_FORMAT_G0R08888:
        image->format = MESA_FORMAT_ARGB8888;
        break;
     case __DRI_IMAGE_FORMAT_ABGR8888:
@@ -207,6 +208,7 @@ intel_allocate_image(int dri_format, void *loaderPrivate)
        image->format = MESA_FORMAT_R8;
        break;
     case __DRI_IMAGE_FORMAT_GR88:
+    case __DRI_IMAGE_FORMAT_0R88:
        image->format = MESA_FORMAT_GR88;
        break;
     case __DRI_IMAGE_FORMAT_NONE:
diff --git a/src/mesa/drivers/dri/intel/intel_tex_image.c b/src/mesa/drivers/dri/intel/intel_tex_image.c
index a023fef..90fa598 100644
--- a/src/mesa/drivers/dri/intel/intel_tex_image.c
+++ b/src/mesa/drivers/dri/intel/intel_tex_image.c
@@ -15,6 +15,8 @@
 #include "main/teximage.h"
 #include "main/texstore.h"
 
+#include "program/prog_instruction.h"
+
 #include "intel_context.h"
 #include "intel_mipmap_tree.h"
 #include "intel_buffer_objects.h"
@@ -351,6 +353,26 @@ intel_image_target_texture_2d(struct gl_context *ctx, GLenum target,
    intel_set_texture_image_region(ctx, texImage, image->region,
 				  target, image->internal_format,
                                   image->format, image->offset);
+
+   /* V sampled into A, U into G */
+   switch (image->dri_format) {
+   case __DRI_IMAGE_FORMAT_G0R08888:
+      texObj->Swizzle[0] = GL_GREEN;
+      texObj->Swizzle[1] = GL_ALPHA;
+      texObj->Swizzle[2] = GL_ZERO;
+      texObj->Swizzle[3] = GL_ONE;
+      texObj->_Swizzle =
+         MAKE_SWIZZLE4(SWIZZLE_Y, SWIZZLE_W, SWIZZLE_ZERO, SWIZZLE_ONE);
+      break;
+   case __DRI_IMAGE_FORMAT_0R88:
+      texObj->Swizzle[0] = GL_RED;
+      texObj->Swizzle[1] = GL_ZERO;
+      texObj->Swizzle[2] = GL_ZERO;
+      texObj->Swizzle[3] = GL_ONE;
+      texObj->_Swizzle =
+         MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ONE);
+      break;
+   }
 }
 #endif
 
-- 
1.7.10.2



More information about the mesa-dev mailing list