util: Use designated initializers to clean up the format tables' pack/unpack.
authorEric Anholt <eric@anholt.net>
Wed, 1 Jul 2020 20:14:42 +0000 (13:14 -0700)
committerMarge Bot <eric+marge@anholt.net>
Tue, 7 Jul 2020 18:19:23 +0000 (18:19 +0000)
The generated .c had a bunch of NULLs and notes for what kind of function
was being skipped, when we can just skip them by filling in the fields
with names.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5728>

src/util/format/u_format_table.py

index 336de4b31b4871fcdb88649d75e4e14eb74ef502..b517788932d562e1c7f13bd87f0fe0d0c88609d3 100644 (file)
@@ -125,11 +125,13 @@ def write_format_table(formats):
         print("   },")
 
     for format in formats:
+        sn = format.short_name()
+
         print('const struct util_format_description')
-        print('util_format_%s_description = {' % (format.short_name(),))
+        print('util_format_%s_description = {' % (sn,))
         print("   %s," % (format.name,))
         print("   \"%s\"," % (format.name,))
-        print("   \"%s\"," % (format.short_name(),))
+        print("   \"%s\"," % (sn,))
         print("   {%u, %u, %u, %u},\t/* block */" % (format.block_width, format.block_height, format.block_depth, format.block_size()))
         print("   %s," % (layout_map(format.layout),))
         print("   %u,\t/* nr_channels */" % (format.nr_channels(),))
@@ -144,62 +146,37 @@ def write_format_table(formats):
         access = True
         if format.layout in ('astc', 'atc', 'fxt1'):
             access = False
-        if format.layout == 'etc' and format.short_name() != 'etc1_rgb8':
+        if format.layout == 'etc' and sn != 'etc1_rgb8':
             access = False
         if format.colorspace != ZS and not format.is_pure_color() and access:
-            print("   &util_format_%s_unpack_rgba_8unorm," % format.short_name())
-            print("   &util_format_%s_pack_rgba_8unorm," % format.short_name())
+            print("   .unpack_rgba_8unorm = &util_format_%s_unpack_rgba_8unorm," % sn)
+            print("   .pack_rgba_8unorm = &util_format_%s_pack_rgba_8unorm," % sn)
             if format.layout == 's3tc' or format.layout == 'rgtc':
-                print("   &util_format_%s_fetch_rgba_8unorm," % format.short_name())
-            else:
-                print("   NULL, /* fetch_rgba_8unorm */")
-            print("   &util_format_%s_unpack_rgba_float," % format.short_name())
-            print("   &util_format_%s_pack_rgba_float," % format.short_name())
-            print("   &util_format_%s_fetch_rgba_float," % format.short_name())
-        else:
-            print("   NULL, /* unpack_rgba_8unorm */")
-            print("   NULL, /* pack_rgba_8unorm */")
-            print("   NULL, /* fetch_rgba_8unorm */")
-            print("   NULL, /* unpack_rgba_float */")
-            print("   NULL, /* pack_rgba_float */")
-            print("   NULL, /* fetch_rgba_float */")
+                print("   .fetch_rgba_8unorm = &util_format_%s_fetch_rgba_8unorm," % sn)
+            print("   .unpack_rgba_float = &util_format_%s_unpack_rgba_float," % sn)
+            print("   .pack_rgba_float = &util_format_%s_pack_rgba_float," % sn)
+            print("   .fetch_rgba_float = &util_format_%s_fetch_rgba_float," % sn)
+
         if format.has_depth():
-            print("   &util_format_%s_unpack_z_32unorm," % format.short_name())
-            print("   &util_format_%s_pack_z_32unorm," % format.short_name())
-            print("   &util_format_%s_unpack_z_float," % format.short_name())
-            print("   &util_format_%s_pack_z_float," % format.short_name())
-        else:
-            print("   NULL, /* unpack_z_32unorm */")
-            print("   NULL, /* pack_z_32unorm */")
-            print("   NULL, /* unpack_z_float */")
-            print("   NULL, /* pack_z_float */")
+            print("   .unpack_z_32unorm = &util_format_%s_unpack_z_32unorm," % sn)
+            print("   .pack_z_32unorm = &util_format_%s_pack_z_32unorm," % sn)
+            print("   .unpack_z_float = &util_format_%s_unpack_z_float," % sn)
+            print("   .pack_z_float = &util_format_%s_pack_z_float," % sn)
+
         if format.has_stencil():
-            print("   &util_format_%s_unpack_s_8uint," % format.short_name())
-            print("   &util_format_%s_pack_s_8uint," % format.short_name())
-        else:
-            print("   NULL, /* unpack_s_8uint */")
-            print("   NULL, /* pack_s_8uint */")
+            print("   .unpack_s_8uint = &util_format_%s_unpack_s_8uint," % sn)
+            print("   .pack_s_8uint = &util_format_%s_pack_s_8uint," % sn)
+
         if format.is_pure_unsigned():
-            print("   &util_format_%s_unpack_unsigned, /* unpack_rgba_uint */" % format.short_name())
-            print("   &util_format_%s_pack_unsigned, /* pack_rgba_uint */" % format.short_name())
-            print("   NULL, /* unpack_rgba_sint */")
-            print("   &util_format_%s_pack_signed,  /* pack_rgba_sint */" % format.short_name())
-            print("   &util_format_%s_fetch_unsigned,  /* fetch_rgba_uint */" % format.short_name())
-            print("   NULL  /* fetch_rgba_sint */")
+            print("   .unpack_rgba_uint = &util_format_%s_unpack_unsigned," % sn)
+            print("   .pack_rgba_uint = &util_format_%s_pack_unsigned," % sn)
+            print("   .pack_rgba_sint = &util_format_%s_pack_signed," % sn)
+            print("   .fetch_rgba_uint = &util_format_%s_fetch_unsigned," % sn)
         elif format.is_pure_signed():
-            print("   NULL, /* unpack_rgba_uint */")
-            print("   &util_format_%s_pack_unsigned, /* pack_rgba_uint */" % format.short_name())
-            print("   &util_format_%s_unpack_signed, /* unpack_rgba_sint */" % format.short_name())
-            print("   &util_format_%s_pack_signed,  /* pack_rgba_sint */" % format.short_name())
-            print("   NULL,  /* fetch_rgba_uint */")
-            print("   &util_format_%s_fetch_signed  /* fetch_rgba_sint */" % format.short_name())
-        else:
-            print("   NULL, /* unpack_rgba_uint */")
-            print("   NULL, /* pack_rgba_uint */")
-            print("   NULL, /* unpack_rgba_sint */")
-            print("   NULL, /* pack_rgba_sint */")
-            print("   NULL, /* fetch_rgba_uint */")
-            print("   NULL  /* fetch_rgba_sint */")
+            print("   .pack_rgba_uint = &util_format_%s_pack_unsigned," % sn)
+            print("   .unpack_rgba_sint = &util_format_%s_unpack_signed," % sn)
+            print("   .pack_rgba_sint = &util_format_%s_pack_signed," % sn)
+            print("   .fetch_rgba_sint = &util_format_%s_fetch_signed," % sn)
         print("};")
         print()