vulkan: Generate #defines with every bit in a given bitfield

This is useful when trying to restrict from VkFoo2 to VkFoo.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13198>
This commit is contained in:
Jason Ekstrand 2021-10-07 12:20:32 -05:00
parent 2741762ca9
commit 1d4d71057b

View file

@ -22,7 +22,9 @@
"""Create enum to string functions for vulkan using vk.xml."""
import argparse
import functools
import os
import re
import textwrap
import xml.etree.ElementTree as et
@ -178,6 +180,19 @@ H_DEFINE_TEMPLATE = Template(textwrap.dedent(u"""\
#define _${ext.name}_number (${ext.number})
% endfor
% for enum in bitmasks:
% if enum.bitwidth > 32:
<% continue %>
% endif
% if enum.guard:
#ifdef ${enum.guard}
% endif
#define ${enum.all_bits_name()} ${hex(enum.all_bits_value())}u
% if enum.guard:
#endif
% endif
% endfor
% for enum in bitmasks:
% if enum.bitwidth < 64:
<% continue %>
@ -228,6 +243,10 @@ class VkExtension(object):
self.define = define
def CamelCase_to_SHOUT_CASE(s):
return (s[:1] + re.sub(r'(?<![A-Z])([A-Z])', r'_\1', s[1:])).upper()
class VkEnum(object):
"""Simple struct-like class representing a single Vulkan Enum."""
@ -241,6 +260,15 @@ class VkEnum(object):
self.guard = None
self.name_to_alias_list = {}
def all_bits_name(self):
assert self.name.startswith('Vk')
assert re.search(r'FlagBits[A-Z]*$', self.name)
return 'VK_ALL_' + CamelCase_to_SHOUT_CASE(self.name[2:])
def all_bits_value(self):
return functools.reduce(lambda a,b: a | b, self.values.keys(), 0)
def add_value(self, name, value=None,
extnum=None, offset=None, alias=None,
error=False):