From d3cdb64f2ef5e806f2b3ac43c5428105514ae838 Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Thu, 9 Dec 2021 17:43:51 +0200 Subject: scripts: Fix codegen to support VK_KHR_format_feature_flags2 If the implementation reports that it supports this feature, it should fill out VkFormatProperties3KHR properly. --- icd/generated/mock_icd.cpp | 6 ++++++ icd/generated/vk_typemap_helper.h | 18 ++++++++++++++++++ scripts/mock_icd_generator.py | 6 ++++++ scripts/vulkan_tools_helper_file_generator.py | 25 +++++++++++++++++++++++-- 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/icd/generated/mock_icd.cpp b/icd/generated/mock_icd.cpp index c7988320..f968e4dc 100644 --- a/icd/generated/mock_icd.cpp +++ b/icd/generated/mock_icd.cpp @@ -2707,6 +2707,12 @@ static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceFormatProperties2KHR( VkFormatProperties2* pFormatProperties) { GetPhysicalDeviceFormatProperties(physicalDevice, format, &pFormatProperties->formatProperties); + VkFormatProperties3KHR *props_3 = lvl_find_mod_in_chain(pFormatProperties->pNext); + if (props_3) { + props_3->linearTilingFeatures = pFormatProperties->formatProperties.linearTilingFeatures; + props_3->optimalTilingFeatures = pFormatProperties->formatProperties.optimalTilingFeatures; + props_3->bufferFeatures = pFormatProperties->formatProperties.bufferFeatures; + } } static VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceImageFormatProperties2KHR( diff --git a/icd/generated/vk_typemap_helper.h b/icd/generated/vk_typemap_helper.h index 525b469e..6ec74296 100644 --- a/icd/generated/vk_typemap_helper.h +++ b/icd/generated/vk_typemap_helper.h @@ -5843,6 +5843,10 @@ struct LvlGenericHeader { VkStructureType sType; const LvlGenericHeader *pNext; }; +struct LvlGenericModHeader { + VkStructureType sType; + LvlGenericModHeader *pNext; +}; // Find an entry of the given type in the pNext chain template const T *lvl_find_in_chain(const void *next) { @@ -5858,6 +5862,20 @@ template const T *lvl_find_in_chain(const void *next) { } return found; } +// Find an entry of the given type in the pNext chain +template T *lvl_find_mod_in_chain(void *next) { + LvlGenericModHeader *current = reinterpret_cast(next); + T *found = nullptr; + while (current) { + if (LvlTypeMap::kSType == current->sType) { + found = reinterpret_cast(current); + current = nullptr; + } else { + current = current->pNext; + } + } + return found; +} // Init the header of an sType struct with pNext template T lvl_init_struct(void *p_next) { diff --git a/scripts/mock_icd_generator.py b/scripts/mock_icd_generator.py index 8cc94621..a2360b5f 100644 --- a/scripts/mock_icd_generator.py +++ b/scripts/mock_icd_generator.py @@ -761,6 +761,12 @@ CUSTOM_C_INTERCEPTS = { ''', 'vkGetPhysicalDeviceFormatProperties2KHR': ''' GetPhysicalDeviceFormatProperties(physicalDevice, format, &pFormatProperties->formatProperties); + VkFormatProperties3KHR *props_3 = lvl_find_mod_in_chain(pFormatProperties->pNext); + if (props_3) { + props_3->linearTilingFeatures = pFormatProperties->formatProperties.linearTilingFeatures; + props_3->optimalTilingFeatures = pFormatProperties->formatProperties.optimalTilingFeatures; + props_3->bufferFeatures = pFormatProperties->formatProperties.bufferFeatures; + } ''', 'vkGetPhysicalDeviceImageFormatProperties': ''' // A hardcoded unsupported format diff --git a/scripts/vulkan_tools_helper_file_generator.py b/scripts/vulkan_tools_helper_file_generator.py index 42ce0199..b0e486ef 100644 --- a/scripts/vulkan_tools_helper_file_generator.py +++ b/scripts/vulkan_tools_helper_file_generator.py @@ -1102,9 +1102,11 @@ class HelperFileOutputGenerator(OutputGenerator): id_member = 'kSType' id_decl = 'static const VkStructureType ' generic_header = prefix + 'GenericHeader' + generic_mod_header = prefix + 'GenericModHeader' typename_func = fprefix + 'typename' idname_func = fprefix + 'stype_name' find_func = fprefix + 'find_in_chain' + find_mod_func = fprefix + 'find_mod_in_chain' init_func = fprefix + 'init_struct' explanatory_comment = '\n'.join(( @@ -1130,6 +1132,10 @@ class HelperFileOutputGenerator(OutputGenerator): ' VkStructureType sType;', ' const {header} *pNext;', '}};', + 'struct {mod_header} {{', + ' VkStructureType sType;', + ' {mod_header} *pNext;', + '}};', '', '// Find an entry of the given type in the pNext chain', 'template const T *{find_func}(const void *next) {{', @@ -1145,6 +1151,20 @@ class HelperFileOutputGenerator(OutputGenerator): ' }}', ' return found;', '}}', + '// Find an entry of the given type in the pNext chain', + 'template T *{find_mod_func}(void *next) {{', + ' {mod_header} *current = reinterpret_cast<{mod_header} *>(next);', + ' T *found = nullptr;', + ' while (current) {{', + ' if ({type_map}::{id_member} == current->sType) {{', + ' found = reinterpret_cast(current);', + ' current = nullptr;', + ' }} else {{', + ' current = current->pNext;', + ' }}', + ' }}', + ' return found;', + '}}', '', '// Init the header of an sType struct with pNext', 'template T {init_func}(void *p_next) {{', @@ -1194,8 +1214,9 @@ class HelperFileOutputGenerator(OutputGenerator): # Generate utilities for all types code.append('\n'.join(( utilities_format.format(id_member=id_member, id_map=idmap, type_map=typemap, - type_member=type_member, header=generic_header, typename_func=typename_func, idname_func=idname_func, - find_func=find_func, init_func=init_func), '' + type_member=type_member, header=generic_header, mod_header=generic_mod_header, + typename_func=typename_func, idname_func=idname_func, find_func=find_func, + find_mod_func=find_mod_func, init_func=init_func), '' ))) return "\n".join(code) -- cgit v1.2.3