vulkaninfo: Fix VkShaderStageFlagBits expansion
authorMike Schuchardt <mikes@lunarg.com>
Tue, 1 Nov 2022 23:37:47 +0000 (16:37 -0700)
committerMike Schuchardt <mikes@lunarg.com>
Wed, 2 Nov 2022 21:33:35 +0000 (14:33 -0700)
Fix bug where SHADER_STAGE_ALL_GRAPHICS and SHADER_STAGE_ALL were
showing up in the list of set bits for
VkPhysicalDeviceSubgroupProperties::supportedStages. When expanding a
FlagBits value we should only consider the single-bit options.

scripts/vulkaninfo_generator.py
vulkaninfo/generated/vulkaninfo.hpp

index 4fac2cf..0834a2a 100644 (file)
@@ -441,10 +441,12 @@ def PrintGetFlagStrings(name, bitmask):
     out += f"    std::vector<const char *> strings;\n"
     # If a bitmask contains a field whose value is zero, we want to support printing the correct bitflag
     # Otherwise, use "None" for when there are not bits set in the bitmask
-    if bitmask.options[0].value != "0":
+    if bitmask.options[0].value != 0:
         out += f'    if (value == 0) {{ strings.push_back("None"); return strings; }}\n'
     for v in bitmask.options:
-        out += f'    if ({v.name} & value) strings.push_back("{v.name[3:]}");\n'
+        # only check single-bit flags
+        if (v.value & (v.value - 1)) == 0:
+            out += f'    if ({v.name} & value) strings.push_back("{v.name[3:]}");\n'
     out += f"    return strings;\n}}\n"
     return out
 
@@ -787,8 +789,13 @@ class VulkanEnum:
             self.name = name
             self.comment = comment
 
-            if value == 0 or value is None:
+            if bitpos is not None:
                 value = 1 << int(bitpos)
+            elif type(value) is str:
+                if value.lower().startswith('0x'):
+                    value = int(value, 16)
+                else:
+                    value = int(value)
 
             self.value = value
 
index 13bab86..58162b8 100644 (file)
@@ -986,8 +986,6 @@ std::vector<const char *> VkShaderStageFlagBitsGetStrings(VkShaderStageFlagBits
     if (VK_SHADER_STAGE_GEOMETRY_BIT & value) strings.push_back("SHADER_STAGE_GEOMETRY_BIT");
     if (VK_SHADER_STAGE_FRAGMENT_BIT & value) strings.push_back("SHADER_STAGE_FRAGMENT_BIT");
     if (VK_SHADER_STAGE_COMPUTE_BIT & value) strings.push_back("SHADER_STAGE_COMPUTE_BIT");
-    if (VK_SHADER_STAGE_ALL_GRAPHICS & value) strings.push_back("SHADER_STAGE_ALL_GRAPHICS");
-    if (VK_SHADER_STAGE_ALL & value) strings.push_back("SHADER_STAGE_ALL");
     if (VK_SHADER_STAGE_RAYGEN_BIT_KHR & value) strings.push_back("SHADER_STAGE_RAYGEN_BIT_KHR");
     if (VK_SHADER_STAGE_ANY_HIT_BIT_KHR & value) strings.push_back("SHADER_STAGE_ANY_HIT_BIT_KHR");
     if (VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR & value) strings.push_back("SHADER_STAGE_CLOSEST_HIT_BIT_KHR");