[Mesa-dev] [PATCH v2 4/6] vulkan/util: Make the vk_format table creation scripts more reusable

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


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

Refactor the vk_format table creation scripts to allow other scripts to
easily reuse some of the provided functionality.
---
 src/vulkan/util/vk_format_parse.py |  4 +--
 src/vulkan/util/vk_format_table.py | 68 +++++++++++++++++++++-----------------
 2 files changed, 39 insertions(+), 33 deletions(-)

diff --git a/src/vulkan/util/vk_format_parse.py b/src/vulkan/util/vk_format_parse.py
index 00cf1adf5a..908dbbf158 100644
--- a/src/vulkan/util/vk_format_parse.py
+++ b/src/vulkan/util/vk_format_parse.py
@@ -328,7 +328,7 @@ def _parse_channels(fields, layout, colorspace, swizzles):
 
     return channels
 
-def parse(filename):
+def parse(filename, format_class=Format):
     '''Parse the format description in CSV format in terms of the
     Channel and Format classes above.'''
 
@@ -377,7 +377,7 @@ def parse(filename):
         for i in range(4):
             assert (le_swizzles[i] != SWIZZLE_NONE) == (be_swizzles[i] != SWIZZLE_NONE)
 
-        format = Format(name, layout, block_width, block_height, le_channels, le_swizzles, be_channels, be_swizzles, colorspace)
+        format = format_class(name, layout, block_width, block_height, le_channels, le_swizzles, be_channels, be_swizzles, colorspace)
         formats.append(format)
     return formats
 
diff --git a/src/vulkan/util/vk_format_table.py b/src/vulkan/util/vk_format_table.py
index 936666b23b..fd01bf0f2f 100644
--- a/src/vulkan/util/vk_format_table.py
+++ b/src/vulkan/util/vk_format_table.py
@@ -85,16 +85,7 @@ def print_channels(format, func):
         func(format.le_channels, format.le_swizzles)
         print '#endif'
 
-def write_format_table(formats):
-    print '/* This file is autogenerated by u_format_table.py from u_format.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 "vk_format.h"'
-    print
-    
+def print_format_description(format, name):
     def do_channel_array(channels, swizzles):
         print "   {"
         for i in range(4):
@@ -124,30 +115,45 @@ def write_format_table(formats):
             print "      %s%s\t/* %s */" % (swizzle_map[swizzle], sep, comment)
         print "   },"
 
+    print 'const struct %s_format_description' % (name,)
+    print '%s_format_%s_description = {' % (name, format.short_name(),)
+    print "   %s," % (format.name,)
+    print "   \"%s\"," % (format.name,)
+    print "   \"%s\"," % (format.short_name(),)
+    print "   {%u, %u, %u},\t/* block */" % (format.block_width, format.block_height, format.block_size())
+    print "   %s," % (layout_map(format.layout),)
+    print "   %u,\t/* nr_channels */" % (format.nr_channels(),)
+    print "   %s,\t/* is_array */" % (bool_map(format.is_array()),)
+    print "   %s,\t/* is_bitmask */" % (bool_map(format.is_bitmask()),)
+    print "   %s,\t/* is_mixed */" % (bool_map(format.is_mixed()),)
+    print_channels(format, do_channel_array)
+    print_channels(format, do_swizzle_array)
+    print "   %s," % (colorspace_map(format.colorspace),)
+    print "};"
+    print
+
+def print_format_table(formats, name):
+    print "const struct %s_format_description *%s_format_description_table[] = {" % (name, name)
     for format in formats:
-        print 'const struct vk_format_description'
-        print 'vk_format_%s_description = {' % (format.short_name(),)
-        print "   %s," % (format.name,)
-        print "   \"%s\"," % (format.name,)
-        print "   \"%s\"," % (format.short_name(),)
-        print "   {%u, %u, %u},\t/* block */" % (format.block_width, format.block_height, format.block_size())
-        print "   %s," % (layout_map(format.layout),)
-        print "   %u,\t/* nr_channels */" % (format.nr_channels(),)
-        print "   %s,\t/* is_array */" % (bool_map(format.is_array()),)
-        print "   %s,\t/* is_bitmask */" % (bool_map(format.is_bitmask()),)
-        print "   %s,\t/* is_mixed */" % (bool_map(format.is_mixed()),)
-        print_channels(format, do_channel_array)
-        print_channels(format, do_swizzle_array)
-        print "   %s," % (colorspace_map(format.colorspace),)
-        print "};"
-        print
-        
-    print "const struct vk_format_description *vk_format_description_table[] = {"
-    for format in formats:
-        print "   &vk_format_%s_description," % (format.short_name(),)
+        print "   &%s_format_%s_description," % (name, format.short_name(),)
     print "   NULL};"
     print
 
+def vk_write_format_table(formats):
+    print '/* This file is autogenerated by u_format_table.py from u_format.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 "vk_format.h"'
+    print
+
+    for format in formats:
+        print_format_description(format, name="vk")
+
+    print_format_table(formats, name="vk")
+
     print "const struct vk_format_description *"
     print "vk_format_description(VkFormat format)"
     print "{"
@@ -171,7 +177,7 @@ def main():
     formats = []
     for arg in sys.argv[1:]:
         formats.extend(parse(arg))
-    write_format_table(formats)
+    vk_write_format_table(formats)
 
 
 if __name__ == '__main__':
-- 
2.13.2



More information about the mesa-dev mailing list