layers: Fix several bugs in WSI extension handling in layers
authorJon Ashburn <jon@lunarg.com>
Thu, 17 Sep 2015 00:08:32 +0000 (18:08 -0600)
committerJon Ashburn <jon@lunarg.com>
Thu, 17 Sep 2015 21:29:28 +0000 (15:29 -0600)
Layers weren't intercepting the WSI device extensions proerly, or weren't
NOT intercepting them if the extension wasn't enabled.  Fixes to APIDump,
Generic, ScreenShot, MemTracker, ObjectTracker

layers/mem_tracker.cpp
layers/object_track.h
layers/screenshot.cpp
vk-generate.py
vk-layer-generate.py

index 7da466b2011e5a45f5cda9aa0855666b494d9290..f60754b587a4fe80482d8aac380335bce122c8d3 100644 (file)
@@ -1366,6 +1366,16 @@ VkResult VKAPI vkCreateInstance(
 static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
 {
     layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
+    VkLayerDispatchTable *pDisp = get_dispatch_table(mem_tracker_device_table_map, device);
+    PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
+    pDisp->GetSurfacePropertiesKHR = (PFN_vkGetSurfacePropertiesKHR) gpa(device, "vkGetSurfacePropertiesKHR");
+    pDisp->GetSurfaceFormatsKHR = (PFN_vkGetSurfaceFormatsKHR) gpa(device, "vkGetSurfaceFormatsKHR");
+    pDisp->GetSurfacePresentModesKHR = (PFN_vkGetSurfacePresentModesKHR) gpa(device, "vkGetSurfacePresentModesKHR");
+    pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
+    pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
+    pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
+    pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
+    pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
     my_device_data->wsi_enabled = false;
     for (uint32_t i = 0; i < pCreateInfo->extensionCount; i++) {
         if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_DEVICE_SWAPCHAIN_EXTENSION_NAME) == 0)
index ad997d273cceca17d4fe39ce72e4f1afee624c67..694aa93fe116f69bf667617670458d9f6d9a75b4 100644 (file)
@@ -178,6 +178,16 @@ static inline const char* string_VkDbgObjectType(VkDbgObjectType input_value)
 static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
 {
     layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
+    VkLayerDispatchTable *pDisp = get_dispatch_table(ObjectTracker_device_table_map, device);
+    PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
+    pDisp->GetSurfacePropertiesKHR = (PFN_vkGetSurfacePropertiesKHR) gpa(device, "vkGetSurfacePropertiesKHR");
+    pDisp->GetSurfaceFormatsKHR = (PFN_vkGetSurfaceFormatsKHR) gpa(device, "vkGetSurfaceFormatsKHR");
+    pDisp->GetSurfacePresentModesKHR = (PFN_vkGetSurfacePresentModesKHR) gpa(device, "vkGetSurfacePresentModesKHR");
+    pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
+    pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
+    pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
+    pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
+    pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
     my_device_data->wsi_enabled = false;
     for (uint32_t i = 0; i < pCreateInfo->extensionCount; i++) {
         if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_DEVICE_SWAPCHAIN_EXTENSION_NAME) == 0)
@@ -640,6 +650,7 @@ explicit_CreateDevice(
         layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
         my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
         create_obj(*pDevice, *pDevice, VK_OBJECT_TYPE_DEVICE);
+        createDeviceRegisterExtensions(pCreateInfo, *pDevice);
     }
 
     loader_platform_thread_unlock_mutex(&objLock);
index e8d4b6027de28e86f04dd521a798c0bf9b1ae9b3..bc2b8208adedb0f3de7f37111e704712fb6b8949 100644 (file)
@@ -312,6 +312,15 @@ static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo
 {
     uint32_t i;
     VkLayerDispatchTable *pDisp  = get_dispatch_table(screenshot_device_table_map, device);
+    PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
+    pDisp->GetSurfacePropertiesKHR = (PFN_vkGetSurfacePropertiesKHR) gpa(device, "vkGetSurfacePropertiesKHR");
+    pDisp->GetSurfaceFormatsKHR = (PFN_vkGetSurfaceFormatsKHR) gpa(device, "vkGetSurfaceFormatsKHR");
+    pDisp->GetSurfacePresentModesKHR = (PFN_vkGetSurfacePresentModesKHR) gpa(device, "vkGetSurfacePresentModesKHR");
+    pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
+    pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
+    pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
+    pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
+    pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
     deviceExtMap[pDisp].wsi_enabled = false;
     for (i = 0; i < pCreateInfo->extensionCount; i++) {
         if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_DEVICE_SWAPCHAIN_EXTENSION_NAME) == 0)
@@ -671,7 +680,7 @@ VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(
         return (PFN_vkVoidFunction) vkCreateCommandPool;
 
     VkLayerDispatchTable *pDisp =  get_dispatch_table(screenshot_device_table_map, dev);
-    if (deviceExtMap.size() == 0 || deviceExtMap[pDisp].wsi_enabled)
+    if (deviceExtMap.size() != 0 && deviceExtMap[pDisp].wsi_enabled)
     {
         if (!strcmp(funcName, "vkCreateSwapchainKHR"))
             return (PFN_vkVoidFunction) vkCreateSwapchainKHR;
index 9491ec12644c5f447ccb36bc74c6c8a7aefa40bb..c127ea228f50865f870bc3c24951208a1aa4ae16 100755 (executable)
@@ -124,7 +124,7 @@ class DispatchTableOpsSubcommand(Subcommand):
             for proto in self.protos:
                 if proto.name == "CreateInstance" or proto.name == "GetGlobalExtensionProperties" or proto.name == "GetGlobalLayerProperties" or proto.params[0].ty == "VkInstance" or (proto.params[0].ty == "VkPhysicalDevice" and proto.name != "CreateDevice"):
                     continue
-                if proto.name != "GetDeviceProcAddr":
+                if proto.name != "GetDeviceProcAddr" and 'KHR' not in proto.name:
                     stmts.append("table->%s = (PFN_vk%s) gpa(baseDevice, \"vk%s\");" %
                         (proto.name, proto.name, proto.name))
             func.append("static inline void %s_initialize_dispatch_table(VkLayerDispatchTable *table,"
@@ -143,7 +143,7 @@ class DispatchTableOpsSubcommand(Subcommand):
                     continue
                 if proto.name == "CreateDevice":
                     continue
-                if proto.name != "GetInstanceProcAddr":
+                if proto.name != "GetInstanceProcAddr" and 'KHR' not in proto.name:
                     stmts.append("table->%s = (PFN_vk%s) gpa(baseInstance, \"vk%s\");" %
                           (proto.name, proto.name, proto.name))
             func.append("static inline void %s_init_instance_dispatch_table(VkLayerInstanceDispatchTable *table,"
index a22d6ff97263b9fe1186950b24715de1080517a2..a7971edeb4c4e114c137b8191f051b10968a245b 100755 (executable)
@@ -435,7 +435,7 @@ class Subcommand(object):
                 extra_space = ""
                 for (ext_enable, ext_list) in extensions:
                     if 0 != len(ext_enable):
-                        func_body.append('    if (deviceExtMap.size() == 0 || deviceExtMap[pDisp].%s)' % ext_enable)
+                        func_body.append('    if (deviceExtMap.size() != 0 && deviceExtMap[pDisp].%s)' % ext_enable)
                         func_body.append('    {')
                         extra_space = "    "
                     for ext_name in ext_list:
@@ -593,6 +593,15 @@ class GenericLayerSubcommand(Subcommand):
         gen_header.append('{')
         gen_header.append('    uint32_t i;')
         gen_header.append('    VkLayerDispatchTable *pDisp  = device_dispatch_table(device);')
+        gen_header.append('    PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;')
+        gen_header.append('    pDisp->GetSurfacePropertiesKHR = (PFN_vkGetSurfacePropertiesKHR) gpa(device, "vkGetSurfacePropertiesKHR");')
+        gen_header.append('    pDisp->GetSurfaceFormatsKHR = (PFN_vkGetSurfaceFormatsKHR) gpa(device, "vkGetSurfaceFormatsKHR");')
+        gen_header.append('    pDisp->GetSurfacePresentModesKHR = (PFN_vkGetSurfacePresentModesKHR) gpa(device, "vkGetSurfacePresentModesKHR");')
+        gen_header.append('    pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");')
+        gen_header.append('    pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");')
+        gen_header.append('    pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");')
+        gen_header.append('    pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");')
+        gen_header.append('    pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");\n')
         gen_header.append('    deviceExtMap[pDisp].wsi_enabled = false;')
         gen_header.append('    for (i = 0; i < pCreateInfo->extensionCount; i++) {')
         gen_header.append('        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_DEVICE_SWAPCHAIN_EXTENSION_NAME) == 0)')
@@ -675,8 +684,10 @@ class GenericLayerSubcommand(Subcommand):
     def generate_body(self):
         self.layer_name = "Generic"
         extensions=[('wsi_enabled', 
-                     ['vkCreateSwapchainKHR', 'vkDestroySwapchainKHR',
-                      'vkGetSwapchainImagesKHR', 'vkQueuePresentKHR'])]
+                     ['vkGetSurfacePropertiesKHR', 'vkGetSurfaceFormatsKHR',
+                      'vkGetSurfacePresentModesKHR', 'vkCreateSwapchainKHR',
+                      'vkDestroySwapchainKHR', 'vkGetSwapchainImagesKHR',
+                      'vkAcquireNextImageKHR', 'vkQueuePresentKHR'])]
         body = [self._generate_layer_initialization(True),
                 self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"),
                 self._gen_create_msg_callback(),
@@ -773,6 +784,15 @@ class APIDumpSubcommand(Subcommand):
         header_txt.append('{')
         header_txt.append('    uint32_t i;')
         header_txt.append('    VkLayerDispatchTable *pDisp  = device_dispatch_table(device);')
+        header_txt.append('    PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;')
+        header_txt.append('    pDisp->GetSurfacePropertiesKHR = (PFN_vkGetSurfacePropertiesKHR) gpa(device, "vkGetSurfacePropertiesKHR");')
+        header_txt.append('    pDisp->GetSurfaceFormatsKHR = (PFN_vkGetSurfaceFormatsKHR) gpa(device, "vkGetSurfaceFormatsKHR");')
+        header_txt.append('    pDisp->GetSurfacePresentModesKHR = (PFN_vkGetSurfacePresentModesKHR) gpa(device, "vkGetSurfacePresentModesKHR");')
+        header_txt.append('    pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");')
+        header_txt.append('    pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");')
+        header_txt.append('    pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");')
+        header_txt.append('    pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");')
+        header_txt.append('    pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");\n')
         header_txt.append('    deviceExtMap[pDisp].wsi_enabled = false;')
         header_txt.append('    for (i = 0; i < pCreateInfo->extensionCount; i++) {')
         header_txt.append('        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_DEVICE_SWAPCHAIN_EXTENSION_NAME) == 0)')
@@ -928,8 +948,8 @@ class APIDumpSubcommand(Subcommand):
                     if p.name == proto.params[y].name:
                         cp = True
             (pft, pfi) = self._get_printf_params(p.ty, p.name, cp, cpp=True)
-            if p.name == "pSwapchain":
-                log_func += '%s = " << %s->handle << ", ' % (p.name, p.name)
+            if p.name == "pSwapchain" or p.name == "pSwapchainImages":
+                log_func += '%s = " << ((%s == NULL) ? 0 : %s->handle) << ", ' % (p.name, p.name, p.name)
             elif p.name == "swapchain":
                 log_func += '%s = " << %s.handle << ", ' % (p.name, p.name)
             else:
@@ -1085,8 +1105,10 @@ class APIDumpSubcommand(Subcommand):
     def generate_body(self):
         self.layer_name = "APIDump"
         extensions=[('wsi_enabled',
-                    ['vkCreateSwapchainKHR', 'vkDestroySwapchainKHR',
-                    'vkGetSwapchainImagesKHR', 'vkQueuePresentKHR'])]
+                     ['vkGetSurfacePropertiesKHR', 'vkGetSurfaceFormatsKHR',
+                      'vkGetSurfacePresentModesKHR', 'vkCreateSwapchainKHR',
+                      'vkDestroySwapchainKHR', 'vkGetSwapchainImagesKHR',
+                      'vkAcquireNextImageKHR', 'vkQueuePresentKHR'])]
         body = [self.generate_init(),
                 self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"),
                 self._generate_layer_gpa_function(extensions)]
@@ -1597,8 +1619,10 @@ class ObjectTrackerSubcommand(Subcommand):
     def generate_body(self):
         self.layer_name = "ObjectTracker"
         extensions=[('wsi_enabled',
-                    ['vkCreateSwapchainKHR', 'vkDestroySwapchainKHR',
-                     'vkGetSwapchainImagesKHR', 'vkQueuePresentKHR'])]
+                     ['vkGetSurfacePropertiesKHR', 'vkGetSurfaceFormatsKHR',
+                      'vkGetSurfacePresentModesKHR', 'vkCreateSwapchainKHR',
+                      'vkDestroySwapchainKHR', 'vkGetSwapchainImagesKHR',
+                      'vkAcquireNextImageKHR', 'vkQueuePresentKHR'])]
         body = [self.generate_maps(),
                 self.generate_procs(),
                 self.generate_destroy_instance(),