[Mesa-dev] [PATCH v2 5/6] vulkan/wsi: Introduce wl_drm_format table creation utilities

alexandros.frantzis at collabora.com alexandros.frantzis at collabora.com
Wed Jul 12 10:16:05 UTC 2017


From: Alexandros Frantzis <alexandros.frantzis at collabora.com>

Reuse functionality from the vk_format table creation utilities to
write a similar utility for wl_drm formats. The description of
the wl_drm formats is compatible with that of vk_format.
---
 src/vulkan/Makefile.am                  | 11 ++++-
 src/vulkan/Makefile.sources             |  6 ++-
 src/vulkan/wsi/wl_drm_format.h          | 68 ++++++++++++++++++++++++++
 src/vulkan/wsi/wl_drm_format_layout.csv | 39 +++++++++++++++
 src/vulkan/wsi/wl_drm_format_table.py   | 84 +++++++++++++++++++++++++++++++++
 5 files changed, 205 insertions(+), 3 deletions(-)
 create mode 100644 src/vulkan/wsi/wl_drm_format.h
 create mode 100644 src/vulkan/wsi/wl_drm_format_layout.csv
 create mode 100644 src/vulkan/wsi/wl_drm_format_table.py

diff --git a/src/vulkan/Makefile.am b/src/vulkan/Makefile.am
index 4c96e353eb..a1daa13a20 100644
--- a/src/vulkan/Makefile.am
+++ b/src/vulkan/Makefile.am
@@ -12,7 +12,9 @@ EXTRA_DIST = \
 	util/gen_enum_to_str.py \
 	util/vk_format_layout.csv \
 	util/vk_format_parse.py \
-	util/vk_format_table.py
+	util/vk_format_table.py \
+	wsi/wl_drm_format_layout.csv \
+	wsi/wl_drm_format_table.py
 
 VULKAN_UTIL_SOURCES = \
 	$(VULKAN_UTIL_FILES) \
@@ -30,6 +32,13 @@ util/vk_format_table.c: util/vk_format_table.py \
                         util/vk_format_layout.csv
 	$(PYTHON2) $(srcdir)/util/vk_format_table.py $(srcdir)/util/vk_format_layout.csv > $@
 
+wsi/wl_drm_format_table.c: wsi/wl_drm_format_table.py \
+                           wsi/wl_drm_format_layout.csv \
+                           util/vk_format_table.py \
+                           util/vk_format_parse.py
+	PYTHONPATH=$(srcdir)/util $(PYTHON2) $(srcdir)/wsi/wl_drm_format_table.py \
+		$(srcdir)/wsi/wl_drm_format_layout.csv > $@
+
 libvulkan_util_la_SOURCES = $(VULKAN_UTIL_SOURCES)
 
 AM_CPPFLAGS = \
diff --git a/src/vulkan/Makefile.sources b/src/vulkan/Makefile.sources
index 526b382e32..70532cb349 100644
--- a/src/vulkan/Makefile.sources
+++ b/src/vulkan/Makefile.sources
@@ -5,11 +5,13 @@ VULKAN_WSI_FILES := \
 
 VULKAN_WSI_WAYLAND_FILES := \
 	wsi/wsi_common_wayland.c \
-	wsi/wsi_common_wayland.h
+	wsi/wsi_common_wayland.h \
+	wsi/wl_drm_format.h
 
 VULKAN_WSI_WAYLAND_GENERATED_FILES := \
 	wsi/wayland-drm-protocol.c \
-	wsi/wayland-drm-client-protocol.h
+	wsi/wayland-drm-client-protocol.h \
+	wsi/wl_drm_format_table.c
 
 VULKAN_WSI_X11_FILES := \
 	wsi/wsi_common_x11.c \
diff --git a/src/vulkan/wsi/wl_drm_format.h b/src/vulkan/wsi/wl_drm_format.h
new file mode 100644
index 0000000000..bff9f69e28
--- /dev/null
+++ b/src/vulkan/wsi/wl_drm_format.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright © 2016 Red Hat.
+ * Copyright © 2016 Bas Nieuwenhuizen
+ * Copyright © 2017 Collabora Ltd
+ *
+ * Based on u_format.h which is:
+ * Copyright 2009-2010 Vmware, Inc.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef WL_DRM_FORMAT_H
+#define WL_DRM_FORMAT_H
+
+#include "vk_format.h"
+
+struct wl_drm_format_description
+{
+   uint32_t format;
+   const char *name;
+   const char *short_name;
+
+   struct vk_format_block block;
+   enum vk_format_layout layout;
+
+   unsigned nr_channels:3;
+   unsigned is_array:1;
+   unsigned is_bitmask:1;
+   unsigned is_mixed:1;
+
+   struct vk_format_channel_description channel[4];
+
+   unsigned char swizzle[4];
+
+   enum vk_format_colorspace colorspace;
+};
+
+/* NULL-terminated array with pointers to all format descriptions */
+extern const struct wl_drm_format_description *wl_drm_format_description_table[];
+
+const struct wl_drm_format_description *wl_drm_format_description(uint32_t format);
+
+static inline bool
+wl_drm_format_has_alpha(const struct wl_drm_format_description *desc)
+{
+   return desc->swizzle[3] == VK_SWIZZLE_X ||
+          desc->swizzle[3] == VK_SWIZZLE_Y ||
+          desc->swizzle[3] == VK_SWIZZLE_Z ||
+          desc->swizzle[3] == VK_SWIZZLE_W;
+}
+
+#endif
diff --git a/src/vulkan/wsi/wl_drm_format_layout.csv b/src/vulkan/wsi/wl_drm_format_layout.csv
new file mode 100644
index 0000000000..35ebe86cda
--- /dev/null
+++ b/src/vulkan/wsi/wl_drm_format_layout.csv
@@ -0,0 +1,39 @@
+WL_DRM_FORMAT_C8         , plain, 1, 1, un8 ,     ,     ,     , x001, rgb
+WL_DRM_FORMAT_RGB332     , plain, 1, 1, un2 , un3 , un3 ,     , zyx1, rgb
+WL_DRM_FORMAT_BGR233     , plain, 1, 1, un3 , un3 , un2 ,     , xyz1, rgb
+WL_DRM_FORMAT_XRGB4444   , plain, 1, 1, un4 , un4 , un4 ,  x4 , zyx1, rgb
+WL_DRM_FORMAT_XBGR4444   , plain, 1, 1, un4 , un4 , un4 ,  x4 , xyz1, rgb
+WL_DRM_FORMAT_RGBX4444   , plain, 1, 1,  x4 , un4 , un4 , un4 , wzy1, rgb
+WL_DRM_FORMAT_BGRX4444   , plain, 1, 1,  x4 , un4 , un4 , un4 , yzw1, rgb
+WL_DRM_FORMAT_ARGB4444   , plain, 1, 1, un4 , un4 , un4 , un4 , zyxw, rgb
+WL_DRM_FORMAT_ABGR4444   , plain, 1, 1, un4 , un4 , un4 , un4 , xyzw, rgb
+WL_DRM_FORMAT_RGBA4444   , plain, 1, 1, un4 , un4 , un4 , un4 , wzyx, rgb
+WL_DRM_FORMAT_BGRA4444   , plain, 1, 1, un4 , un4 , un4 , un4 , yzwx, rgb
+WL_DRM_FORMAT_XRGB1555   , plain, 1, 1, un5 , un5 , un5 ,  x1 , zyx1, rgb
+WL_DRM_FORMAT_XBGR1555   , plain, 1, 1, un5 , un5 , un5 ,  x1 , xyz1, rgb
+WL_DRM_FORMAT_RGBX5551   , plain, 1, 1,  x1 , un5 , un5 , un5 , wzy1, rgb
+WL_DRM_FORMAT_BGRX5551   , plain, 1, 1,  x1 , un5 , un5 , un5 , yzw1, rgb
+WL_DRM_FORMAT_ARGB1555   , plain, 1, 1, un5 , un5 , un5 , un1 , zyxw, rgb
+WL_DRM_FORMAT_ABGR1555   , plain, 1, 1, un5 , un5 , un5 , un1 , xyzw, rgb
+WL_DRM_FORMAT_RGBA5551   , plain, 1, 1, un1 , un5 , un5 , un5 , wzyx, rgb
+WL_DRM_FORMAT_BGRA5551   , plain, 1, 1, un1 , un5 , un5 , un5 , yzwx, rgb
+WL_DRM_FORMAT_RGB565     , plain, 1, 1, un5 , un6 , un5 ,     , zyx1, rgb
+WL_DRM_FORMAT_BGR565     , plain, 1, 1, un5 , un6 , un5 ,     , xyz1, rgb
+WL_DRM_FORMAT_RGB888     , plain, 1, 1, un8 , un8 , un8 ,     , zyx1, rgb
+WL_DRM_FORMAT_BGR888     , plain, 1, 1, un8 , un8 , un8 ,     , xyz1, rgb
+WL_DRM_FORMAT_XRGB8888   , plain, 1, 1, un8 , un8 , un8 ,  x8 , zyx1, rgb
+WL_DRM_FORMAT_XBGR8888   , plain, 1, 1, un8 , un8 , un8 ,  x8 , xyz1, rgb
+WL_DRM_FORMAT_RGBX8888   , plain, 1, 1,  x8 , un8 , un8 , un8 , wzy1, rgb
+WL_DRM_FORMAT_BGRX8888   , plain, 1, 1,  x8 , un8 , un8 , un8 , yzw1, rgb
+WL_DRM_FORMAT_ARGB8888   , plain, 1, 1, un8 , un8 , un8 , un8 , zyxw, rgb
+WL_DRM_FORMAT_ABGR8888   , plain, 1, 1, un8 , un8 , un8 , un8 , xyzw, rgb
+WL_DRM_FORMAT_RGBA8888   , plain, 1, 1, un8 , un8 , un8 , un8 , wzyx, rgb
+WL_DRM_FORMAT_BGRA8888   , plain, 1, 1, un8 , un8 , un8 , un8 , yzwx, rgb
+WL_DRM_FORMAT_XRGB2101010, plain, 1, 1, un10, un10, un10,  x2 , zyx1, rgb
+WL_DRM_FORMAT_XBGR2101010, plain, 1, 1, un10, un10, un10,  x2 , xyz1, rgb
+WL_DRM_FORMAT_RGBX1010102, plain, 1, 1,  x2 , un10, un10, un10, wzy1, rgb
+WL_DRM_FORMAT_BGRX1010102, plain, 1, 1,  x2 , un10, un10, un10, yzw1, rgb
+WL_DRM_FORMAT_ARGB2101010, plain, 1, 1, un10, un10, un10, un2 , zyxw, rgb
+WL_DRM_FORMAT_ABGR2101010, plain, 1, 1, un10, un10, un10, un2 , xyzw, rgb
+WL_DRM_FORMAT_RGBA1010102, plain, 1, 1, un2 , un10, un10, un10, wzyx, rgb
+WL_DRM_FORMAT_BGRA1010102, plain, 1, 1, un2 , un10, un10, un10, yzwx, rgb
diff --git a/src/vulkan/wsi/wl_drm_format_table.py b/src/vulkan/wsi/wl_drm_format_table.py
new file mode 100644
index 0000000000..c55e77648f
--- /dev/null
+++ b/src/vulkan/wsi/wl_drm_format_table.py
@@ -0,0 +1,84 @@
+
+CopyRight = '''
+/**************************************************************************
+ *
+ * Copyright 2010 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+'''
+
+
+import sys
+from vk_format_parse import parse, Format
+from vk_format_table import print_format_table, print_format_description
+
+class WlDrmFormat(Format):
+    def short_name(self):
+        name = self.name
+        if name.startswith('WL_DRM_FORMAT_'):
+            name = name[len('WL_DRM_FORMAT_'):]
+        name = name.lower()
+        return name
+
+
+def wl_drm_write_format_table(formats):
+    print '/* This file is autogenerated by wl_drm_format_table.py from wl_drm_format_layout.csv. Do not edit directly. */'
+    print
+    # This will print the copyright message on the top of this file
+    print CopyRight.strip()
+    print
+    print '#include "stdbool.h"'
+    print '#include "wayland-drm-client-protocol.h"'
+    print '#include "vulkan/wsi/wl_drm_format.h"'
+    print
+
+    for format in formats:
+        print_format_description(format, name="wl_drm")
+
+    print_format_table(formats, name="wl_drm");
+
+    print "const struct wl_drm_format_description *"
+    print "wl_drm_format_description(uint32_t format)"
+    print "{"
+    print "   switch (format) {"
+    for format in formats:
+        print "   case %s:" % format.name
+        print "      return &wl_drm_format_%s_description;" % (format.short_name(),)
+    print "   default:"
+    print "      return NULL;"
+    print "   }"
+    print "}"
+    print
+
+
+def main():
+    formats = []
+    for arg in sys.argv[1:]:
+        formats.extend(parse(arg, WlDrmFormat))
+
+    wl_drm_write_format_table(formats)
+
+
+if __name__ == '__main__':
+    main()
-- 
2.13.2



More information about the mesa-dev mailing list