scripts: Fix codegen to support VK_KHR_format_feature_flags2
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Thu, 9 Dec 2021 15:43:51 +0000 (17:43 +0200)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Sun, 12 Dec 2021 22:23:54 +0000 (15:23 -0700)
If the implementation reports that it supports this feature, it should
fill out VkFormatProperties3KHR properly.

icd/generated/mock_icd.cpp
icd/generated/vk_typemap_helper.h
scripts/mock_icd_generator.py
scripts/vulkan_tools_helper_file_generator.py

index c798832..f968e4d 100644 (file)
@@ -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<VkFormatProperties3KHR>(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(
index 525b469..6ec7429 100644 (file)
@@ -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 <typename T> const T *lvl_find_in_chain(const void *next) {
@@ -5858,6 +5862,20 @@ template <typename T> const T *lvl_find_in_chain(const void *next) {
     }
     return found;
 }
+// Find an entry of the given type in the pNext chain
+template <typename T> T *lvl_find_mod_in_chain(void *next) {
+    LvlGenericModHeader *current = reinterpret_cast<LvlGenericModHeader *>(next);
+    T *found = nullptr;
+    while (current) {
+        if (LvlTypeMap<T>::kSType == current->sType) {
+            found = reinterpret_cast<T*>(current);
+            current = nullptr;
+        } else {
+            current = current->pNext;
+        }
+    }
+    return found;
+}
 
 // Init the header of an sType struct with pNext
 template <typename T> T lvl_init_struct(void *p_next) {
index 8cc9462..a2360b5 100644 (file)
@@ -761,6 +761,12 @@ CUSTOM_C_INTERCEPTS = {
 ''',
 'vkGetPhysicalDeviceFormatProperties2KHR': '''
     GetPhysicalDeviceFormatProperties(physicalDevice, format, &pFormatProperties->formatProperties);
+    VkFormatProperties3KHR *props_3 = lvl_find_mod_in_chain<VkFormatProperties3KHR>(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
index 42ce019..b0e486e 100644 (file)
@@ -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 <typename T> 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 <typename T> T *{find_mod_func}(void *next) {{',
+            '    {mod_header} *current = reinterpret_cast<{mod_header} *>(next);',
+            '    T *found = nullptr;',
+            '    while (current) {{',
+            '        if ({type_map}<T>::{id_member} == current->sType) {{',
+            '            found = reinterpret_cast<T*>(current);',
+            '            current = nullptr;',
+            '        }} else {{',
+            '            current = current->pNext;',
+            '        }}',
+            '    }}',
+            '    return found;',
+            '}}',
             '',
             '// Init the header of an sType struct with pNext',
             'template <typename T> 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)