Quoting Neil Roberts (2018-04-04 15:56:53) [snip] > diff --git a/tests/vulkan/vkrunner/make-formats.py > b/tests/vulkan/vkrunner/make-formats.py > new file mode 100755 > index 000000000..6bb1030c0 > --- /dev/null > +++ b/tests/vulkan/vkrunner/make-formats.py > @@ -0,0 +1,93 @@ > +#!/usr/bin/python3
Unfortunately python scripts in piglit need to be python 2/3 compatible, I've also got a few style nits. Please use all of the future imports like the other scripts do > + > +import re > +import sys > + > +format_re = re.compile(r'\bVK_FORMAT_([A-Z0-9_]+)\b') > +skip_re = re.compile(r'(?:_BLOCK(?:_IMG)?|_KHR|^UNDEFINED|' > + r'^RANGE_SIZE|^MAX_ENUM|_RANGE)$') > +component_re = re.compile('([A-Z]+)([0-9]+)') > +pack_re = re.compile('PACK([0-9]+)$') module constants should be ALL_CAPS > + > +swizzles = [ 'RGBA', 'BGRA', 'ARGB', 'ABGR' ] no spaces between [ and ' two newlines between toplevel classes and functions > + > +def get_formats(data): > + in_enum = False > + > + for line in data: > + if line.startswith('typedef enum VkFormat '): > + in_enum = True > + elif line.startswith('}'): > + in_enum = False > + if not in_enum: > + continue > + > + md = format_re.search(line) > + if md is None: > + continue > + name = md.group(1) > + if skip_re.search(name): > + continue > + yield(name) no parens around returns or yields uless they're returning a tuple please. > + > +def get_components(name): > + components = [(md.group(1), int(md.group(2))) > + for md in component_re.finditer(name)] > + for letter, size in components: > + if "RGBA".find(letter) == -1: if letter not in 'RGBA' > + return None > + return components > + > +def get_swizzle(components): > + component_letters = "".join((letter for letter, size in components)) > + for swizzle in swizzles: > + if swizzle.startswith(component_letters): > + return swizzle > + print("Unknown swizzle {}".format(component_letters), > + file=sys.stderr) > + sys.exit(1) > + > +formats = sorted(set(get_formats(sys.stdin))) > + > +print("""/* Automatically generated by make-formats.py */ > +static const struct vr_format > +formats[] = {""") mako is already a requirement for piglit, can we use it instead of printing a file? It's much easier to understand and edit after the fact. Also please use a main function and the if __name__ == "__main__" idiom. Dylan > + > +for name in formats: > + parts = name.split('_') > + > + components = get_components(parts[0]) > + > + if components is None: > + continue > + > + swizzle = get_swizzle(components) > + > + if len(parts) >= 3: > + md = pack_re.match(parts[2]) > + packed_size = int(md.group(1)) > + else: > + packed_size = 0 > + > + print(""" {{ > + .vk_format = VK_FORMAT_{}, > + .name = "{}", > + .packed_size = {}, > + .swizzle = VR_FORMAT_SWIZZLE_{}, > + .mode = VR_FORMAT_MODE_{}, > + .n_components = {}, > + .components = {{""".format( > + name, > + name, > + packed_size, > + swizzle, > + parts[1], > + len(components))) > + > + for letter, size in components: > + print("\t\t\t{{ .bits = {} }},".format(size)) > + > + print(""" } > + },""") > + > +print("};") [snip]
signature.asc
Description: signature
_______________________________________________ Piglit mailing list Piglit@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/piglit