From 2da4badfe346d948fef5ed749a611eb599eb9d9f Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 1 Jul 2020 13:14:42 -0700 Subject: [PATCH] util: Use designated initializers to clean up the format tables' pack/unpack. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Part-of: --- src/util/format/u_format_table.py | 79 +++++++++++-------------------- 1 file changed, 28 insertions(+), 51 deletions(-) diff --git a/src/util/format/u_format_table.py b/src/util/format/u_format_table.py index 336de4b31b4..b517788932d 100644 --- a/src/util/format/u_format_table.py +++ b/src/util/format/u_format_table.py @@ -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() -- 2.30.2