loader: Fix extension surface params
authorLenny Komow <lenny@lunarg.com>
Mon, 22 May 2017 22:17:05 +0000 (16:17 -0600)
committerLenny Komow <lenny@lunarg.com>
Tue, 23 May 2017 23:07:47 +0000 (17:07 -0600)
Change-Id: I310d6d356b5c9377ff8285ee123def989e95b142

scripts/loader_extension_generator.py

index 015e774..8aa52da 100644 (file)
@@ -865,19 +865,42 @@ class LoaderExtensionOutputGenerator(OutputGenerator):
             return_prefix = '    '
             base_name = ext_cmd.name[2:]
             has_surface = 0
+            update_structure_surface = 0
+            update_structure_string = ''
             requires_terminator = 0
             surface_var_name = ''
             phys_dev_var_name = ''
             has_return_type = False
+            always_use_param_name = True
+            surface_type_to_replace = ''
+            surface_name_replacement = ''
+            physdev_type_to_replace = ''
+            physdev_name_replacement = ''
 
             for param in ext_cmd.params:
                 if param.type == 'VkSurfaceKHR':
                     has_surface = 1
                     surface_var_name = param.name
                     requires_terminator = 1
+                    always_use_param_name = False
+                    surface_type_to_replace = 'VkSurfaceKHR'
+                    surface_name_replacement = 'icd_surface->real_icd_surfaces[icd_index]'
+                if param.type == 'VkPhysicalDeviceSurfaceInfo2KHR':
+                    has_surface = 1
+                    surface_var_name = param.name + '->surface'
+                    requires_terminator = 1
+                    update_structure_surface = 1
+                    update_structure_string = '        VkPhysicalDeviceSurfaceInfo2KHR info_copy = *pSurfaceInfo;\n'
+                    update_structure_string += '        info_copy.surface = icd_surface->real_icd_surfaces[icd_index];\n'
+                    always_use_param_name = False
+                    surface_type_to_replace = 'VkPhysicalDeviceSurfaceInfo2KHR'
+                    surface_name_replacement = '&info_copy'
                 if param.type == 'VkPhysicalDevice':
                     requires_terminator = 1
                     phys_dev_var_name = param.name
+                    always_use_param_name = False
+                    physdev_type_to_replace = 'VkPhysicalDevice'
+                    physdev_name_replacement = 'phys_dev_term->phys_dev'
 
             if (ext_cmd.return_type != None):
                 return_prefix += 'return '
@@ -942,9 +965,14 @@ class LoaderExtensionOutputGenerator(OutputGenerator):
                     funcs += '    }\n'
 
                     if has_surface == 1:
-                        funcs += '    VkIcdSurface *icd_surface = (VkIcdSurface *)(surface);\n'
+                        funcs += '    VkIcdSurface *icd_surface = (VkIcdSurface *)(%s);\n' % (surface_var_name)
                         funcs += '    uint8_t icd_index = phys_dev_term->icd_index;\n'
                         funcs += '    if (NULL != icd_surface->real_icd_surfaces && NULL != (void *)icd_surface->real_icd_surfaces[icd_index]) {\n'
+
+                        # If there's a structure with a surface, we need to update its internals with the correct surface for the ICD
+                        if update_structure_surface == 1:
+                            funcs += update_structure_string
+
                         funcs += '    ' + return_prefix + 'icd_term->dispatch.'
                         funcs += base_name
                         funcs += '('
@@ -953,10 +981,13 @@ class LoaderExtensionOutputGenerator(OutputGenerator):
                             if count != 0:
                                 funcs += ', '
 
-                            if param.type == 'VkPhysicalDevice':
-                                funcs += 'phys_dev_term->phys_dev'
-                            elif param.type == 'VkSurfaceKHR':
-                                funcs += 'icd_surface->real_icd_surfaces[icd_index]'
+                            if not always_use_param_name:
+                                if surface_type_to_replace and surface_type_to_replace == param.type:
+                                    funcs += surface_name_replacement
+                                elif physdev_type_to_replace and physdev_type_to_replace == param.type:
+                                    funcs += physdev_name_replacement
+                                else:
+                                    funcs += param.name
                             else:
                                 funcs += param.name