Mesa (main): vulkan: Generate #defines with every bit in a given bitfield
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Oct 11 16:53:20 UTC 2021
Module: Mesa
Branch: main
Commit: 1d4d71057bf96630faf21256d7afa3617943886e
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=1d4d71057bf96630faf21256d7afa3617943886e
Author: Jason Ekstrand <jason at jlekstrand.net>
Date: Thu Oct 7 12:20:32 2021 -0500
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 at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13198>
---
src/vulkan/util/gen_enum_to_str.py | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/src/vulkan/util/gen_enum_to_str.py b/src/vulkan/util/gen_enum_to_str.py
index d244d5c405b..241f2c43d0b 100644
--- a/src/vulkan/util/gen_enum_to_str.py
+++ b/src/vulkan/util/gen_enum_to_str.py
@@ -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):
More information about the mesa-commit
mailing list