Module: Mesa Branch: main Commit: dea36fce6a445051063f28893866542b6d1b71eb URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=dea36fce6a445051063f28893866542b6d1b71eb
Author: Illia Abernikhin <[email protected]> Date: Mon Feb 6 18:36:19 2023 +0200 util: Extend vk_enum_to_str with bitmasks vk_enum_to_str only generates literals for enums with type: @type="enum", but many enums have type: @type="bitmask" and were not taken into account here. Main changes: Empty enums are now always skipped For bitmasks skipped *MAX_ENUM value Signed-off-by: Illia Abernikhin <[email protected]> Reviewed-by: Lionel Landwerlin <[email protected]> Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/8173 Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21146> --- src/vulkan/util/gen_enum_to_str.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/vulkan/util/gen_enum_to_str.py b/src/vulkan/util/gen_enum_to_str.py index a8e2197bd5b..f633f978f91 100644 --- a/src/vulkan/util/gen_enum_to_str.py +++ b/src/vulkan/util/gen_enum_to_str.py @@ -89,6 +89,29 @@ C_TEMPLATE = Template(textwrap.dedent(u"""\ % endif %endfor + % for enum in bitmasks: + + % if enum.guard: +#ifdef ${enum.guard} + % endif + const char * + vk_${enum.name[2:]}_to_str(${enum.name} input) + { + switch((int64_t)input) { + % for v in sorted(enum.values.keys()): + case ${v}: + return "${enum.values[v]}"; + % endfor + default: + return "Unknown ${enum.name} value."; + } + } + + % if enum.guard: +#endif + % endif + %endfor + size_t vk_structure_type_size(const struct VkBaseInStructure *item) { switch((int)item->sType) { @@ -149,6 +172,16 @@ H_TEMPLATE = Template(textwrap.dedent(u"""\ % endif % endfor + % for enum in bitmasks: + % if enum.guard: +#ifdef ${enum.guard} + % endif + const char * vk_${enum.name[2:]}_to_str(${enum.name} input); + % if enum.guard: +#endif + % endif + % endfor + size_t vk_structure_type_size(const struct VkBaseInStructure *item); const char * vk_ObjectType_to_ObjectName(VkObjectType type); @@ -248,6 +281,8 @@ def CamelCase_to_SHOUT_CASE(s): return (s[:1] + re.sub(r'(?<![A-Z])([A-Z])', r'_\1', s[1:])).upper() def compute_max_enum_name(s): + if s == "VkSwapchainImageUsageFlagBitsANDROID": + return "VK_SWAPCHAIN_IMAGE_USAGE_FLAG_BITS_MAX_ENUM" max_enum_name = CamelCase_to_SHOUT_CASE(s) last_prefix = max_enum_name.rsplit('_', 1)[-1] # Those special prefixes need to be always at the end @@ -465,6 +500,9 @@ def parse_xml(enum_factory, ext_factory, struct_factory, bitmask_factory, enum = enum_factory.get(value.attrib['name']) if enum is not None: enum.set_guard(define) + enum = bitmask_factory.get(value.attrib['name']) + if enum is not None: + enum.set_guard(define) obj_type_enum = enum_factory.get("VkObjectType") obj_types = obj_type_factory("VkObjectType")
