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
diff --git a/layers/object_tracker.h b/layers/object_tracker.h
index 333775a..7c00c24 100644
--- a/layers/object_tracker.h
+++ b/layers/object_tracker.h
@@ -89,11 +89,17 @@
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<void *, struct instExts> instanceExtMap;
+static std::unordered_map<void *, struct instance_extension_enables> instanceExtMap;
static std::unordered_map<void *, layer_data *> 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 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 @@
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 9abf240..942724f 100644
--- a/layers/unique_objects.h
+++ b/layers/unique_objects.h
@@ -54,7 +54,7 @@
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 @@
bool win32_enabled;
};
-static std::unordered_map<void *, struct instExts> instanceExtMap;
+static std::unordered_map<void *, struct instance_extension_enables> instanceExtMap;
static std::unordered_map<void *, layer_data *> 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 @@
#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 a645f4b..5a5e6a1 100755
--- a/vk-layer-generate.py
+++ b/vk-layer-generate.py
@@ -594,6 +594,14 @@
" 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 @@
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<PFN_vkVoidFunction>(%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<PFN_vkVoidFunction>(%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<PFN_vkVoidFunction>(%s);' % (ext_name, ext_name[2:]))
if wsi_name(ext_name):
func_body.append('%s' % wsi_endif(ext_name))