Add GetObjectType helper to struct_helper

This utility converst Vulkan handle types to VkObjectType enums, which is used
by the debug utils set name & tag functions.
This commit is contained in:
unknown 2023-10-03 11:15:04 -06:00 committed by Juan Ramos
parent 2169a0849e
commit cf011e717a
3 changed files with 77 additions and 720 deletions

File diff suppressed because it is too large Load diff

View file

@ -49,9 +49,8 @@ VkStructureType GetSType() {
}\n''')
for struct in [x for x in self.vk.structs.values() if x.sType]:
out.extend([f'#ifdef {struct.protect}'] if struct.protect else [])
out.append(f'''
template <> inline VkStructureType GetSType<{struct.name}>() {{ return {struct.sType}; }}\n''')
out.extend([f'#ifdef {struct.protect}\n'] if struct.protect else [])
out.append(f'template <> inline VkStructureType GetSType<{struct.name}>() {{ return {struct.sType}; }}\n')
out.extend([f'#endif // {struct.protect}\n'] if struct.protect else [])
out.append('''
@ -122,6 +121,17 @@ class InitStructHelper {
}
};
template<typename T> VkObjectType GetObjectType() {
static_assert(sizeof(T) == 0, "GetObjectType() is being used with an unsupported Type! Is the code-gen up to date?");
return VK_OBJECT_TYPE_UNKNOWN;
}
''')
for handle in self.vk.handles.values():
out.extend([f'#ifdef {handle.protect}\n'] if handle.protect else [])
out.append(f'template<> VkObjectType GetObjectType<{handle.name}>() {{ return {handle.type}; }}\n')
out.extend([f'#endif // {handle.protect}\n'] if handle.protect else [])
out.append('''
} // namespace vku
\n''')

View file

@ -89,3 +89,11 @@ TEST(struct_helper, struct_defaults_correct) {
ASSERT_EQ(s.t3.sType, VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO);
ASSERT_EQ(s.t4.sType, VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO);
}
TEST(struct_helper, get_object_type) {
ASSERT_EQ(vku::GetObjectType<VkInstance>(), VK_OBJECT_TYPE_INSTANCE);
ASSERT_EQ(vku::GetObjectType<VkPerformanceConfigurationINTEL>(), VK_OBJECT_TYPE_PERFORMANCE_CONFIGURATION_INTEL);
ASSERT_EQ(vku::GetObjectType<VkSwapchainKHR>(), VK_OBJECT_TYPE_SWAPCHAIN_KHR);
ASSERT_EQ(vku::GetObjectType<VkAccelerationStructureKHR>(), VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR);
ASSERT_EQ(vku::GetObjectType<VkAccelerationStructureNV>(), VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_NV);
}