loader: Add checks for usage of wsi extensions
The loader really should validate that the WSI extensions are
enabled before being called. Additionally, I needed to add
more checks for the KHR_display_swapchain extension in the
parameter_validation and object_tracker layers.
Change-Id: I3d07d46baf551be6f5f07e5374d6c683e3f52e7e
diff --git a/layers/parameter_validation.cpp b/layers/parameter_validation.cpp
index bf45285..2bc8d38 100644
--- a/layers/parameter_validation.cpp
+++ b/layers/parameter_validation.cpp
@@ -73,10 +73,11 @@
VkPhysicalDevice physical_device;
bool wsi_enabled;
+ bool wsi_display_swapchain_enabled;
layer_data()
: report_data(nullptr), num_tmp_callbacks(0), tmp_dbg_create_infos(nullptr), tmp_callbacks(nullptr), device_limits{},
- physical_device_features{}, physical_device{}, wsi_enabled(false){};
+ physical_device_features{}, physical_device{}, wsi_enabled(false), wsi_display_swapchain_enabled(false) {};
};
static std::unordered_map<void *, struct instance_extension_enables> instance_extension_map;
@@ -1633,11 +1634,15 @@
static void CheckDeviceRegisterExtensions(const VkDeviceCreateInfo *pCreateInfo, VkDevice device) {
layer_data *device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
device_data->wsi_enabled = false;
+ device_data->wsi_display_swapchain_enabled = false;
for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
device_data->wsi_enabled = true;
}
+ if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_DISPLAY_SWAPCHAIN_EXTENSION_NAME) == 0) {
+ device_data->wsi_display_swapchain_enabled = true;
+ }
}
}
@@ -5051,6 +5056,27 @@
}
#endif // VK_USE_PLATFORM_ANDROID_KHR
+VKAPI_ATTR VkResult VKAPI_CALL CreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
+ const VkSwapchainCreateInfoKHR *pCreateInfos,
+ const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchains) {
+ VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
+ bool skip_call = false;
+ layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
+ assert(my_data != NULL);
+
+ skip_call |= parameter_validation_vkCreateSharedSwapchainsKHR(my_data->report_data, swapchainCount, pCreateInfos, pAllocator,
+ pSwapchains);
+
+ if (!skip_call) {
+ result = get_dispatch_table(pc_device_table_map, device)
+ ->CreateSharedSwapchainsKHR(device, swapchainCount, pCreateInfos, pAllocator, pSwapchains);
+
+ validate_result(my_data->report_data, "vkCreateSharedSwapchainsKHR", result);
+ }
+
+ return result;
+}
+
static PFN_vkVoidFunction intercept_core_instance_command(const char *name);
static PFN_vkVoidFunction intercept_core_device_command(const char *name);
@@ -5285,13 +5311,19 @@
if (device) {
layer_data *device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
- if (!device_data->wsi_enabled)
- return nullptr;
- }
- for (size_t i = 0; i < ARRAY_SIZE(wsi_device_commands); i++) {
- if (!strcmp(wsi_device_commands[i].name, name))
- return wsi_device_commands[i].proc;
+ if (device_data->wsi_enabled) {
+ for (size_t i = 0; i < ARRAY_SIZE(wsi_device_commands); i++) {
+ if (!strcmp(wsi_device_commands[i].name, name))
+ return wsi_device_commands[i].proc;
+ }
+ }
+
+ if (device_data->wsi_display_swapchain_enabled) {
+ if (!strcmp("vkCreateSharedSwapchainsKHR", name)) {
+ return reinterpret_cast<PFN_vkVoidFunction>(CreateSharedSwapchainsKHR);
+ }
+ }
}
return nullptr;