u_format: Rewrite format table to use YAML

u_format has always had its format table in CSV. This is kind of nice
for some things, but is a serious pain to extend, especially with
optional fields.

In going through our many (many, many) duplicated tables of format
mappings, it would've been nice to add some descriptions to our central
u_format table, such as mapping to DRM FourCC, to EGLImage mappings, and
to GL internalformats for EGLImage imports. Unfortunately, doing so with
more additional fields would just make the CSV totally unreadable.

Move the CSV table to a YAML-based table and adjust the Python parsers
to suit. The resulting generated files are identical before and after
the transition.

The new parser also has a significant amount of format validation to
make it easier to catch common errors.

Signed-off-by: Daniel Stone <daniels@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29649>
This commit is contained in:
Daniel Stone
2024-06-06 12:36:00 +01:00
committed by Marge Bot
parent 12a33ecd0f
commit ccc6442d6f
11 changed files with 3000 additions and 706 deletions
+12 -8
View File
@@ -43,10 +43,10 @@ def colorspace_map(colorspace):
colorspace_channels_map = {
'rgb': ['r', 'g', 'b', 'a'],
'srgb': ['sr', 'sg', 'sb', 'a'],
'zs': ['z', 's'],
'yuv': ['y', 'u', 'v'],
'RGB': ['r', 'g', 'b', 'a'],
'SRGB': ['sr', 'sg', 'sb', 'a'],
'ZS': ['z', 's'],
'YUV': ['y', 'u', 'v'],
}
@@ -133,7 +133,7 @@ def has_access(format):
return True
def write_format_table_header(file):
print('/* This file is autogenerated by u_format_table.py from u_format.csv. Do not edit directly. */', file=file)
print('/* This file is autogenerated by u_format_table.py from u_format.yaml. Do not edit directly. */', file=file)
print(file=file)
# This will print the copyright message on the top of this file
print(CopyRight.strip(), file=file)
@@ -324,7 +324,7 @@ def write_format_table(formats):
generate_function_getter("fetch_rgba")
def main():
formats = []
formats = {}
sys.stdout2 = open(os.devnull, "w")
@@ -334,9 +334,13 @@ def main():
sys.stdout = open(os.devnull, "w")
continue
formats.extend(parse(arg))
to_add = parse(arg)
duplicates = [x.name for x in to_add if x.name in formats]
if len(duplicates):
raise RuntimeError(f"Duplicate format entries {', '.join(duplicates)}")
formats.update({ x.name: x for x in to_add })
write_format_table(formats)
write_format_table(formats.values())
if __name__ == '__main__':
main()