Workaround breaking API change in vkGetLatencyTimingsNV

The API of vkGetLatencyTimingsNV changed, which causes compilation failure due to
the generated code using the newer API while the Vulkan-Headers may be for the old
API.

The fix is to just disable the function if the headers are too old. While this does
limit the usage, because its from a new extension, there shouldn't be a huge impact.
This commit is contained in:
Charles Giessen 2023-11-29 14:20:10 -07:00
parent e5dd024a51
commit 6ab5669064
2 changed files with 33 additions and 43 deletions

View File

@ -102,6 +102,30 @@ commands = {}
INSTANCE = 'instance' INSTANCE = 'instance'
DEVICE = 'device' DEVICE = 'device'
def get_macro_guard(reqs_collection, command_name):
guard = ''
count = len(reqs_collection)
if count > 0:
while count > 0:
for reqs in reqs_collection:
reqs_count = len(reqs)
guard += '('
for req in reqs:
guard += f'defined({req})'
reqs_count -= 1
if reqs_count > 0:
guard += ' && '
guard += ')'
if count > 0:
count -= 1
if count > 0:
guard += ' || '
# API breaking change causes this function to fail compilation
if command_name == 'vkGetLatencyTimingsNV':
guard = f'({guard}) && VK_HEADER_VERSION >= 271'
return guard
aliased_types = {} aliased_types = {}
types_node = vk_xml['registry']['types']['type'] types_node = vk_xml['registry']['types']['type']
for type_node in types_node: for type_node in types_node:
@ -189,51 +213,17 @@ for extension_node in extensions_node:
# Generate macro templates # Generate macro templates
for command_name, command in commands.items(): for command_name, command in commands.items():
macro = '' if len(commands[command_name]['requirements']) > 0:
requirements_collection = commands[command_name]['requirements'] macro_guard = get_macro_guard(commands[command_name]['requirements'], command_name)
collection_count = len(requirements_collection) macro = f'#if {macro_guard}\n$body#endif\n'
if collection_count > 0:
macro = '#if '
while collection_count > 0:
for requirements in requirements_collection:
requirements_count = len(requirements)
macro += '('
for requirement in requirements:
macro += f'defined({requirement})'
requirements_count -= 1
if requirements_count > 0:
macro += ' && '
macro += ')'
if collection_count > 0:
collection_count -= 1
if collection_count > 0:
macro += ' || '
macro += '\n$body#endif\n'
else: else:
macro = '$body' macro = '$body'
commands[command_name]['macro_template'] = Template(macro) commands[command_name]['macro_template'] = Template(macro)
for command_name, command in commands.items(): for command_name, command in commands.items():
pfn_decl_macro = '' if len(commands[command_name]['requirements']) > 0:
requirements_collection = commands[command_name]['requirements'] macro_guard = get_macro_guard(commands[command_name]['requirements'], command_name)
collection_count = len(requirements_collection) pfn_decl_macro = f'#if {macro_guard}\n$body#else\n void * fp_{command_name}{{}};\n#endif\n'
if collection_count > 0:
pfn_decl_macro = '#if '
while collection_count > 0:
for requirements in requirements_collection:
requirements_count = len(requirements)
pfn_decl_macro += '('
for requirement in requirements:
pfn_decl_macro += f'defined({requirement})'
requirements_count -= 1
if requirements_count > 0:
pfn_decl_macro += ' && '
pfn_decl_macro += ')'
if collection_count > 0:
collection_count -= 1
if collection_count > 0:
pfn_decl_macro += ' || '
pfn_decl_macro += f'\n$body#else\n void * fp_{command_name}{{}};\n#endif\n'
else: else:
pfn_decl_macro = '$body' pfn_decl_macro = '$body'
commands[command_name]['pfn_decl_macro_template'] = Template(pfn_decl_macro) commands[command_name]['pfn_decl_macro_template'] = Template(pfn_decl_macro)

View File

@ -2430,7 +2430,7 @@ struct DispatchTable {
#if (defined(VK_NV_low_latency2)) #if (defined(VK_NV_low_latency2))
fp_vkSetLatencyMarkerNV = reinterpret_cast<PFN_vkSetLatencyMarkerNV>(procAddr(device, "vkSetLatencyMarkerNV")); fp_vkSetLatencyMarkerNV = reinterpret_cast<PFN_vkSetLatencyMarkerNV>(procAddr(device, "vkSetLatencyMarkerNV"));
#endif #endif
#if (defined(VK_NV_low_latency2)) #if ((defined(VK_NV_low_latency2))) && VK_HEADER_VERSION >= 271
fp_vkGetLatencyTimingsNV = reinterpret_cast<PFN_vkGetLatencyTimingsNV>(procAddr(device, "vkGetLatencyTimingsNV")); fp_vkGetLatencyTimingsNV = reinterpret_cast<PFN_vkGetLatencyTimingsNV>(procAddr(device, "vkGetLatencyTimingsNV"));
#endif #endif
#if (defined(VK_NV_low_latency2)) #if (defined(VK_NV_low_latency2))
@ -4684,7 +4684,7 @@ struct DispatchTable {
fp_vkSetLatencyMarkerNV(device, swapchain, pLatencyMarkerInfo); fp_vkSetLatencyMarkerNV(device, swapchain, pLatencyMarkerInfo);
} }
#endif #endif
#if (defined(VK_NV_low_latency2)) #if ((defined(VK_NV_low_latency2))) && VK_HEADER_VERSION >= 271
void getLatencyTimingsNV(VkSwapchainKHR swapchain, VkGetLatencyMarkerInfoNV* pLatencyMarkerInfo) const noexcept { void getLatencyTimingsNV(VkSwapchainKHR swapchain, VkGetLatencyMarkerInfoNV* pLatencyMarkerInfo) const noexcept {
fp_vkGetLatencyTimingsNV(device, swapchain, pLatencyMarkerInfo); fp_vkGetLatencyTimingsNV(device, swapchain, pLatencyMarkerInfo);
} }
@ -6703,7 +6703,7 @@ struct DispatchTable {
#else #else
void * fp_vkSetLatencyMarkerNV{}; void * fp_vkSetLatencyMarkerNV{};
#endif #endif
#if (defined(VK_NV_low_latency2)) #if ((defined(VK_NV_low_latency2))) && VK_HEADER_VERSION >= 271
PFN_vkGetLatencyTimingsNV fp_vkGetLatencyTimingsNV = nullptr; PFN_vkGetLatencyTimingsNV fp_vkGetLatencyTimingsNV = nullptr;
#else #else
void * fp_vkGetLatencyTimingsNV{}; void * fp_vkGetLatencyTimingsNV{};