From 12e39c2ec5e5251bc02c20dc640b17bbcf073d17 Mon Sep 17 00:00:00 2001 From: Mark Lobodzinski Date: Fri, 24 Jun 2016 09:57:32 -0600 Subject: layers: GH618, Correct WSI exension flag usage Object_tracker had no notion of individual WSI extension flags, and unique_objects was not checking them. Change-Id: I93c1aa0c324aa602717f36e2975120dba8bc364e --- layers/object_tracker.h | 50 +++++++++++++++++++++++++++++++++++++++++++------ layers/unique_objects.h | 5 +++-- vk-layer-generate.py | 16 ++++++++++++++-- 3 files changed, 61 insertions(+), 10 deletions(-) diff --git a/layers/object_tracker.h b/layers/object_tracker.h index 333775ae..7c00c249 100644 --- a/layers/object_tracker.h +++ b/layers/object_tracker.h @@ -89,11 +89,17 @@ struct layer_data { tmp_dbg_create_infos(nullptr), tmp_callbacks(nullptr){}; }; -struct instExts { +struct instance_extension_enables { bool wsi_enabled; + bool xlib_enabled; + bool xcb_enabled; + bool wayland_enabled; + bool mir_enabled; + bool android_enabled; + bool win32_enabled; }; -static std::unordered_map instanceExtMap; +static std::unordered_map instanceExtMap; static std::unordered_map layer_data_map; static device_table_map object_tracker_device_table_map; static instance_table_map object_tracker_instance_table_map; @@ -135,7 +141,6 @@ static void createDeviceRegisterExtensions(const VkDeviceCreateInfo *pCreateInfo } static void createInstanceRegisterExtensions(const VkInstanceCreateInfo *pCreateInfo, VkInstance instance) { - uint32_t i; VkLayerInstanceDispatchTable *pDisp = get_dispatch_table(object_tracker_instance_table_map, instance); PFN_vkGetInstanceProcAddr gpa = pDisp->GetInstanceProcAddr; @@ -178,11 +183,44 @@ static void createInstanceRegisterExtensions(const VkInstanceCreateInfo *pCreate pDisp->CreateAndroidSurfaceKHR = (PFN_vkCreateAndroidSurfaceKHR)gpa(instance, "vkCreateAndroidSurfaceKHR"); #endif // VK_USE_PLATFORM_ANDROID_KHR - instanceExtMap[pDisp].wsi_enabled = false; - for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) { - if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) + instanceExtMap[pDisp] = {}; + + for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { + if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) { instanceExtMap[pDisp].wsi_enabled = true; + } +#ifdef VK_USE_PLATFORM_XLIB_KHR + if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) { + instanceExtMap[pDisp].xlib_enabled = true; + } +#endif +#ifdef VK_USE_PLATFORM_XCB_KHR + if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) { + instanceExtMap[pDisp].xcb_enabled = true; + } +#endif +#ifdef VK_USE_PLATFORM_WAYLAND_KHR + if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) { + instanceExtMap[pDisp].wayland_enabled = true; + } +#endif +#ifdef VK_USE_PLATFORM_MIR_KHR + if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0) { + instanceExtMap[pDisp].mir_enabled = true; + } +#endif +#ifdef VK_USE_PLATFORM_ANDROID_KHR + if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) == 0) { + instanceExtMap[pDisp].android_enabled = true; + } +#endif +#ifdef VK_USE_PLATFORM_WIN32_KHR + if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) { + instanceExtMap[pDisp].win32_enabled = true; + } +#endif } + } // Indicate device or instance dispatch table type diff --git a/layers/unique_objects.h b/layers/unique_objects.h index 9abf240c..942724f1 100644 --- a/layers/unique_objects.h +++ b/layers/unique_objects.h @@ -54,7 +54,7 @@ struct layer_data { layer_data() : wsi_enabled(false), gpu(VK_NULL_HANDLE){}; }; -struct instExts { +struct instance_extension_enables { bool wsi_enabled; bool xlib_enabled; bool xcb_enabled; @@ -64,7 +64,7 @@ struct instExts { bool win32_enabled; }; -static std::unordered_map instanceExtMap; +static std::unordered_map instanceExtMap; static std::unordered_map layer_data_map; static device_table_map unique_objects_device_table_map; static instance_table_map unique_objects_instance_table_map; @@ -115,6 +115,7 @@ static void createInstanceRegisterExtensions(const VkInstanceCreateInfo *pCreate #endif // VK_USE_PLATFORM_ANDROID_KHR instanceExtMap[pDisp] = {}; + for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) { if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) instanceExtMap[pDisp].wsi_enabled = true; diff --git a/vk-layer-generate.py b/vk-layer-generate.py index a645f4b4..5a5e6a12 100755 --- a/vk-layer-generate.py +++ b/vk-layer-generate.py @@ -594,6 +594,14 @@ class Subcommand(object): " return get_dispatch_table(%s_device_table_map, device)->GetDeviceProcAddr(device, funcName);\n" "}\n" % (self.layer_name, self.layer_name)) + # The WSI-related extensions have independent extension enables + wsi_sub_enables = {'WIN32': 'win32_enabled', + 'XLIB': 'xlib_enabled', + 'XCB': 'xcb_enabled', + 'MIR': 'mir_enabled', + 'WAYLAND': 'wayland_enabled', + 'ANDROID': 'android_enabled'} + for ext_enable, ext_list in instance_extensions: func_body.append('%s' % self.lineinfo.get()) func_body.append('static inline PFN_vkVoidFunction intercept_%s_command(const char *name, VkInstance instance)' % ext_enable) @@ -609,8 +617,12 @@ class Subcommand(object): for ext_name in ext_list: if wsi_name(ext_name): func_body.append('%s' % wsi_ifdef(ext_name)) - func_body.append(' if (!strcmp("%s", name))\n' - ' return reinterpret_cast(%s);' % (ext_name, ext_name[2:])) + if wsi_sub_enables[wsi_name(ext_name)]: + func_body.append(' if ((instanceExtMap[pTable].%s == true) && !strcmp("%s", name))\n' + ' return reinterpret_cast(%s);' % (wsi_sub_enables[wsi_name(ext_name)], ext_name, ext_name[2:])) + else: + func_body.append(' if (!strcmp("%s", name))\n' + ' return reinterpret_cast(%s);' % (ext_name, ext_name[2:])) if wsi_name(ext_name): func_body.append('%s' % wsi_endif(ext_name)) -- cgit v1.2.3