diff options
| author | Mark Lobodzinski <mark@lunarg.com> | 2017-06-09 17:12:48 -0600 |
|---|---|---|
| committer | Mark Lobodzinski <mark@lunarg.com> | 2017-06-12 07:32:50 -0600 |
| commit | 481891a8173f73b2fb8262ce9c67dca6cf8176fd (patch) | |
| tree | d87d7d4f47295c511deab2e4fd2e9a3d8538d215 | |
| parent | 3be3edffcd5324309fc43ef47ef4857214fd4883 (diff) | |
| download | usermoji-481891a8173f73b2fb8262ce9c67dca6cf8176fd.tar.xz | |
layers: Remove swapchain source and header files
Change-Id: Ifdaa3136883b1129cc435509bf9288b1b5ddf723
| -rw-r--r-- | layers/swapchain.cpp | 1180 | ||||
| -rw-r--r-- | layers/swapchain.h | 215 |
2 files changed, 0 insertions, 1395 deletions
diff --git a/layers/swapchain.cpp b/layers/swapchain.cpp deleted file mode 100644 index 334de132..00000000 --- a/layers/swapchain.cpp +++ /dev/null @@ -1,1180 +0,0 @@ -/* Copyright (c) 2015-2016 The Khronos Group Inc. - * Copyright (c) 2015-2016 Valve Corporation - * Copyright (c) 2015-2016 LunarG, Inc. - * Copyright (C) 2015-2016 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Author: Ian Elliott <ian@lunarg.com> - * Author: Ian Elliott <ianelliott@google.com> - */ - -// For Windows, this #include must come before other Vk headers. -#include <vk_loader_platform.h> - -#include "swapchain.h" -#include "vk_enum_string_helper.h" -#include "vk_layer_extension_utils.h" -#include "vk_layer_utils.h" -#include "vk_validation_error_messages.h" -#include <mutex> -#include <stdio.h> -#include <string.h> -#include <vulkan/vk_icd.h> - -namespace swapchain { - -static std::mutex global_lock; - -// The following is for logging error messages: -static std::unordered_map<void *, layer_data *> layer_data_map; - -static uint32_t loader_layer_if_version = CURRENT_LOADER_LAYER_INTERFACE_VERSION; - -static const VkExtensionProperties instance_extensions[] = {{VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION}}; - -static const VkLayerProperties swapchain_layer = { - "VK_LAYER_LUNARG_swapchain", VK_LAYER_API_VERSION, 1, "LunarG Validation Layer", -}; - -static void checkDeviceRegisterExtensions(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, VkDevice device) { - layer_data *my_device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); - layer_data *my_instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); - - SwpPhysicalDevice *pPhysicalDevice = NULL; - { - auto it = my_instance_data->physicalDeviceMap.find(physicalDevice); - pPhysicalDevice = (it == my_instance_data->physicalDeviceMap.end()) ? NULL : &it->second; - } - if (pPhysicalDevice) { - my_device_data->deviceMap[device].pPhysicalDevice = pPhysicalDevice; - pPhysicalDevice->pDevice = &my_device_data->deviceMap[device]; - } else { - // TBD: Should we leave error in (since Swapchain really needs this - // link)? - log_msg(my_instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, - HandleToUint64(physicalDevice), __LINE__, VALIDATION_ERROR_1fc27a01, "Swapchain", - "vkCreateDevice() called with a non-valid VkPhysicalDevice. %s", validation_error_map[VALIDATION_ERROR_1fc27a01]); - } - my_device_data->deviceMap[device].device = device; -} - -static void checkInstanceRegisterExtensions(const VkInstanceCreateInfo *pCreateInfo, VkInstance instance) { - uint32_t i; - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); - - // Remember this instance, and whether the VK_KHR_surface extension - // was enabled for it: - my_data->instanceMap[instance].instance = instance; - my_data->instanceMap[instance].displayExtensionEnabled = false; - - // Look for one or more debug report create info structures, and copy the - // callback(s) for each one found (for use by vkDestroyInstance) - layer_copy_tmp_callbacks(pCreateInfo->pNext, &my_data->num_tmp_callbacks, &my_data->tmp_dbg_create_infos, - &my_data->tmp_callbacks); - - // Record whether the WSI instance extension was enabled for this - // VkInstance. No need to check if the extension was advertised by - // vkEnumerateInstanceExtensionProperties(), since the loader handles that. - for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) { - if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_DISPLAY_EXTENSION_NAME) == 0) { - my_data->instanceMap[instance].displayExtensionEnabled = true; - } - } -} - -#include "vk_dispatch_table_helper.h" -static void init_swapchain(layer_data *my_data, const VkAllocationCallbacks *pAllocator) { - layer_debug_actions(my_data->report_data, my_data->logging_callback, pAllocator, "lunarg_swapchain"); -} - -static const char *presentModeStr(VkPresentModeKHR value) { - // Return a string corresponding to the value: - return string_VkPresentModeKHR(value); -} - -static const char *sharingModeStr(VkSharingMode value) { - // Return a string corresponding to the value: - return string_VkSharingMode(value); -} - -VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, - VkInstance *pInstance) { - VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); - - assert(chain_info->u.pLayerInfo); - PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; - PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance"); - if (fpCreateInstance == NULL) { - return VK_ERROR_INITIALIZATION_FAILED; - } - - // Advance the link info for the next element on the chain - chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; - - VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance); - if (result != VK_SUCCESS) { - return result; - } - - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(*pInstance), layer_data_map); - my_data->instance = *pInstance; - my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable; - layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr); - my_data->report_data = debug_report_create_instance(my_data->instance_dispatch_table, *pInstance, - pCreateInfo->enabledExtensionCount, pCreateInfo->ppEnabledExtensionNames); - - // Call the following function after my_data is initialized: - checkInstanceRegisterExtensions(pCreateInfo, *pInstance); - init_swapchain(my_data, pAllocator); - - return result; -} - -VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) { - dispatch_key key = get_dispatch_key(instance); - layer_data *my_data = GetLayerDataPtr(key, layer_data_map); - SwpInstance *pInstance = NULL; - { - auto it = my_data->instanceMap.find(instance); - pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; - } - - // Call down the call chain: - my_data->instance_dispatch_table->DestroyInstance(instance, pAllocator); - - std::lock_guard<std::mutex> lock(global_lock); - - // Enable the temporary callback(s) here to catch cleanup issues: - bool callback_setup = false; - if (my_data->num_tmp_callbacks > 0) { - if (!layer_enable_tmp_callbacks(my_data->report_data, my_data->num_tmp_callbacks, my_data->tmp_dbg_create_infos, - my_data->tmp_callbacks)) { - callback_setup = true; - } - } - - // Do additional internal cleanup: - if (pInstance) { - // Delete all of the SwpPhysicalDevice's, SwpSurface's, and the - // SwpInstance associated with this instance: - for (auto it = pInstance->physicalDevices.begin(); it != pInstance->physicalDevices.end(); it++) { - // Free memory that was allocated for/by this SwpPhysicalDevice: - SwpPhysicalDevice *pPhysicalDevice = it->second; - if (pPhysicalDevice) { - if (pPhysicalDevice->pDevice) { - log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, - HandleToUint64(pPhysicalDevice->pDevice->device), __LINE__, VALIDATION_ERROR_258004ea, - swapchain_layer_name, - "VkDestroyInstance() called before all of its associated VkDevices were destroyed. %s", - validation_error_map[VALIDATION_ERROR_258004ea]); - } - } - - // Erase the SwpPhysicalDevice's from the my_data->physicalDeviceMap (which - // are simply pointed to by the SwpInstance): - my_data->physicalDeviceMap.erase(it->second->physicalDevice); - } - for (auto it = pInstance->surfaces.begin(); it != pInstance->surfaces.end(); it++) { - // Free memory that was allocated for/by this SwpPhysicalDevice: - SwpSurface *pSurface = it->second; - if (pSurface) { - log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, - HandleToUint64(pInstance->instance), __LINE__, VALIDATION_ERROR_258004ea, swapchain_layer_name, - "VkDestroyInstance() called before all of its associated VkSurfaceKHRs were destroyed. %s", - validation_error_map[VALIDATION_ERROR_258004ea]); - } - } - my_data->instanceMap.erase(instance); - } - - // Disable and cleanup the temporary callback(s): - if (callback_setup) { - layer_disable_tmp_callbacks(my_data->report_data, my_data->num_tmp_callbacks, my_data->tmp_callbacks); - } - if (my_data->num_tmp_callbacks > 0) { - layer_free_tmp_callbacks(my_data->tmp_dbg_create_infos, my_data->tmp_callbacks); - my_data->num_tmp_callbacks = 0; - } - - // Clean up logging callback, if any - while (my_data->logging_callback.size() > 0) { - VkDebugReportCallbackEXT callback = my_data->logging_callback.back(); - layer_destroy_msg_callback(my_data->report_data, callback, pAllocator); - my_data->logging_callback.pop_back(); - } - layer_debug_report_destroy_instance(my_data->report_data); - - delete my_data->instance_dispatch_table; - FreeLayerDataPtr(key, layer_data_map); -} - -#ifdef VK_USE_PLATFORM_ANDROID_KHR -VKAPI_ATTR VkResult VKAPI_CALL CreateAndroidSurfaceKHR(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR *pCreateInfo, - const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { - VkResult result = VK_SUCCESS; - bool skip_call = false; - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); - std::unique_lock<std::mutex> lock(global_lock); - SwpInstance *pInstance = NULL; - { - auto it = my_data->instanceMap.find(instance); - pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; - } - - lock.unlock(); - - if (!skip_call) { - // Call down the call chain: - result = my_data->instance_dispatch_table->CreateAndroidSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); - lock.lock(); - - // Obtain this pointer again after locking: - { - auto it = my_data->instanceMap.find(instance); - pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; - } - if ((result == VK_SUCCESS) && pInstance && pSurface) { - // Record the VkSurfaceKHR returned by the ICD: - my_data->surfaceMap[*pSurface].surface = *pSurface; - my_data->surfaceMap[*pSurface].pInstance = pInstance; - // Point to the associated SwpInstance: - pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; - } - lock.unlock(); - - return result; - } - return VK_ERROR_VALIDATION_FAILED_EXT; -} -#endif // VK_USE_PLATFORM_ANDROID_KHR - -#ifdef VK_USE_PLATFORM_MIR_KHR -VKAPI_ATTR VkResult VKAPI_CALL CreateMirSurfaceKHR(VkInstance instance, const VkMirSurfaceCreateInfoKHR *pCreateInfo, - const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { - VkResult result = VK_SUCCESS; - bool skip_call = false; - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); - std::unique_lock<std::mutex> lock(global_lock); - SwpInstance *pInstance = NULL; - { - auto it = my_data->instanceMap.find(instance); - pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; - } - - lock.unlock(); - - if (!skip_call) { - // Call down the call chain: - result = my_data->instance_dispatch_table->CreateMirSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); - lock.lock(); - - // Obtain this pointer again after locking: - { - auto it = my_data->instanceMap.find(instance); - pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; - } - if ((result == VK_SUCCESS) && pInstance && pSurface) { - // Record the VkSurfaceKHR returned by the ICD: - my_data->surfaceMap[*pSurface].surface = *pSurface; - my_data->surfaceMap[*pSurface].pInstance = pInstance; - // Point to the associated SwpInstance: - pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; - } - lock.unlock(); - - return result; - } - return VK_ERROR_VALIDATION_FAILED_EXT; -} -#endif // VK_USE_PLATFORM_MIR_KHR - -#ifdef VK_USE_PLATFORM_WAYLAND_KHR -VKAPI_ATTR VkResult VKAPI_CALL CreateWaylandSurfaceKHR(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo, - const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { - VkResult result = VK_SUCCESS; - bool skip_call = false; - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); - std::unique_lock<std::mutex> lock(global_lock); - SwpInstance *pInstance = NULL; - { - auto it = my_data->instanceMap.find(instance); - pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; - } - - lock.unlock(); - - if (!skip_call) { - // Call down the call chain: - result = my_data->instance_dispatch_table->CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); - lock.lock(); - - // Obtain this pointer again after locking: - { - auto it = my_data->instanceMap.find(instance); - pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; - } - if ((result == VK_SUCCESS) && pInstance && pSurface) { - // Record the VkSurfaceKHR returned by the ICD: - my_data->surfaceMap[*pSurface].surface = *pSurface; - my_data->surfaceMap[*pSurface].pInstance = pInstance; - // Point to the associated SwpInstance: - pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; - } - lock.unlock(); - - return result; - } - return VK_ERROR_VALIDATION_FAILED_EXT; -} -#endif // VK_USE_PLATFORM_WAYLAND_KHR - -#ifdef VK_USE_PLATFORM_WIN32_KHR -VKAPI_ATTR VkResult VKAPI_CALL CreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo, - const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { - VkResult result = VK_SUCCESS; - bool skip_call = false; - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); - std::unique_lock<std::mutex> lock(global_lock); - SwpInstance *pInstance = NULL; - { - auto it = my_data->instanceMap.find(instance); - pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; - } - - lock.unlock(); - - if (!skip_call) { - // Call down the call chain: - result = my_data->instance_dispatch_table->CreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); - lock.lock(); - - // Obtain this pointer again after locking: - { - auto it = my_data->instanceMap.find(instance); - pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; - } - if ((result == VK_SUCCESS) && pInstance && pSurface) { - // Record the VkSurfaceKHR returned by the ICD: - my_data->surfaceMap[*pSurface].surface = *pSurface; - my_data->surfaceMap[*pSurface].pInstance = pInstance; - // Point to the associated SwpInstance: - pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; - } - lock.unlock(); - - return result; - } - return VK_ERROR_VALIDATION_FAILED_EXT; -} -#endif // VK_USE_PLATFORM_WIN32_KHR - -#ifdef VK_USE_PLATFORM_XCB_KHR -VKAPI_ATTR VkResult VKAPI_CALL CreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo, - const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { - VkResult result = VK_SUCCESS; - bool skip_call = false; - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); - std::unique_lock<std::mutex> lock(global_lock); - SwpInstance *pInstance = NULL; - { - auto it = my_data->instanceMap.find(instance); - pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; - } - - lock.unlock(); - - if (!skip_call) { - // Call down the call chain: - result = my_data->instance_dispatch_table->CreateXcbSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); - lock.lock(); - - // Obtain this pointer again after locking: - { - auto it = my_data->instanceMap.find(instance); - pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; - } - if ((result == VK_SUCCESS) && pInstance && pSurface) { - // Record the VkSurfaceKHR returned by the ICD: - my_data->surfaceMap[*pSurface].surface = *pSurface; - my_data->surfaceMap[*pSurface].pInstance = pInstance; - // Point to the associated SwpInstance: - pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; - } - lock.unlock(); - - return result; - } - return VK_ERROR_VALIDATION_FAILED_EXT; -} -#endif // VK_USE_PLATFORM_XCB_KHR - -#ifdef VK_USE_PLATFORM_XLIB_KHR -VKAPI_ATTR VkResult VKAPI_CALL CreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo, - const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { - VkResult result = VK_SUCCESS; - bool skip_call = false; - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); - std::unique_lock<std::mutex> lock(global_lock); - SwpInstance *pInstance = NULL; - { - auto it = my_data->instanceMap.find(instance); - pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; - } - - lock.unlock(); - - if (!skip_call) { - // Call down the call chain: - result = my_data->instance_dispatch_table->CreateXlibSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); - lock.lock(); - - // Obtain this pointer again after locking: - { - auto it = my_data->instanceMap.find(instance); - pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; - } - if ((result == VK_SUCCESS) && pInstance && pSurface) { - // Record the VkSurfaceKHR returned by the ICD: - my_data->surfaceMap[*pSurface].surface = *pSurface; - my_data->surfaceMap[*pSurface].pInstance = pInstance; - // Point to the associated SwpInstance: - pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; - } - lock.unlock(); - - return result; - } - return VK_ERROR_VALIDATION_FAILED_EXT; -} -#endif // VK_USE_PLATFORM_XLIB_KHR - -VKAPI_ATTR VkResult VKAPI_CALL GetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, - VkDisplayPlanePropertiesKHR *pProperties) { - VkResult result = VK_SUCCESS; - bool skip_call = false; - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); - std::unique_lock<std::mutex> lock(global_lock); - SwpPhysicalDevice *pPhysicalDevice = NULL; - { - auto it = my_data->physicalDeviceMap.find(physicalDevice); - pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; - } - lock.unlock(); - - if (!skip_call) { - result = my_data->instance_dispatch_table->GetPhysicalDeviceDisplayPlanePropertiesKHR(physicalDevice, pPropertyCount, - pProperties); - - lock.lock(); - if (!pPhysicalDevice->gotDisplayPlanePropertyCount) { - pPhysicalDevice->displayPlanePropertyCount = *pPropertyCount; - pPhysicalDevice->gotDisplayPlanePropertyCount = true; - } - // TODO store the properties for later checks - lock.unlock(); - - return result; - } - return VK_ERROR_VALIDATION_FAILED_EXT; -} - -VKAPI_ATTR VkResult VKAPI_CALL GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex, - uint32_t *pDisplayCount, VkDisplayKHR *pDisplays) { - VkResult result = VK_SUCCESS; - bool skip_call = false; - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); - std::unique_lock<std::mutex> lock(global_lock); - SwpPhysicalDevice *pPhysicalDevice = NULL; - { - auto it = my_data->physicalDeviceMap.find(physicalDevice); - pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; - } - - if (!pPhysicalDevice->gotDisplayPlanePropertyCount) { - skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, - HandleToUint64(pPhysicalDevice->pInstance->instance), __LINE__, - SWAPCHAIN_GET_SUPPORTED_DISPLAYS_WITHOUT_QUERY, swapchain_layer_name, - "Potential problem with calling vkGetDisplayPlaneSupportedDisplaysKHR() without first " - "querying vkGetPhysicalDeviceDisplayPlanePropertiesKHR."); - } - - if (pPhysicalDevice->gotDisplayPlanePropertyCount && planeIndex >= pPhysicalDevice->displayPlanePropertyCount) { - skip_call |= - log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, - HandleToUint64(pPhysicalDevice->pInstance->instance), __LINE__, VALIDATION_ERROR_29c009c2, swapchain_layer_name, - "vkGetDisplayPlaneSupportedDisplaysKHR(): planeIndex must be in the range [0, %d] that was returned by " - "vkGetPhysicalDeviceDisplayPlanePropertiesKHR. Do you have the plane index hardcoded? %s", - pPhysicalDevice->displayPlanePropertyCount - 1, validation_error_map[VALIDATION_ERROR_29c009c2]); - } - lock.unlock(); - - if (!skip_call) { - result = my_data->instance_dispatch_table->GetDisplayPlaneSupportedDisplaysKHR(physicalDevice, planeIndex, pDisplayCount, - pDisplays); - - return result; - } - // TODO validate the returned display objects - return VK_ERROR_VALIDATION_FAILED_EXT; -} - -VKAPI_ATTR VkResult VKAPI_CALL GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, - uint32_t planeIndex, VkDisplayPlaneCapabilitiesKHR *pCapabilities) { - VkResult result = VK_SUCCESS; - bool skip_call = false; - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); - std::unique_lock<std::mutex> lock(global_lock); - SwpPhysicalDevice *pPhysicalDevice = NULL; - { - auto it = my_data->physicalDeviceMap.find(physicalDevice); - pPhysicalDevice = (it == my_data->physicalDeviceMap.end()) ? NULL : &it->second; - } - - if (!pPhysicalDevice->gotDisplayPlanePropertyCount) { - skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, - HandleToUint64(pPhysicalDevice->pInstance->instance), __LINE__, - SWAPCHAIN_GET_SUPPORTED_DISPLAYS_WITHOUT_QUERY, swapchain_layer_name, - "Potential problem with calling vkGetDisplayPlaneCapabilitiesKHR() without first " - "querying vkGetPhysicalDeviceDisplayPlanePropertiesKHR."); - } - - if (pPhysicalDevice->gotDisplayPlanePropertyCount && planeIndex >= pPhysicalDevice->displayPlanePropertyCount) { - skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, - HandleToUint64(pPhysicalDevice->pInstance->instance), __LINE__, SWAPCHAIN_PLANE_INDEX_TOO_LARGE, - swapchain_layer_name, - "vkGetDisplayPlaneCapabilitiesKHR(): planeIndex must be in the range [0, %d] that was returned by " - "vkGetPhysicalDeviceDisplayPlanePropertiesKHR. Do you have the plane index hardcoded?", - pPhysicalDevice->displayPlanePropertyCount - 1); - } - - lock.unlock(); - - if (!skip_call) { - result = my_data->instance_dispatch_table->GetDisplayPlaneCapabilitiesKHR(physicalDevice, mode, planeIndex, pCapabilities); - return result; - } - - return VK_ERROR_VALIDATION_FAILED_EXT; -} - -VKAPI_ATTR VkResult VKAPI_CALL CreateDisplayPlaneSurfaceKHR(VkInstance instance, const VkDisplaySurfaceCreateInfoKHR *pCreateInfo, - const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { - VkResult result = VK_SUCCESS; - bool skip_call = false; - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); - std::unique_lock<std::mutex> lock(global_lock); - SwpInstance *pInstance = &(my_data->instanceMap[instance]); - - // TODO more validation checks - if (!skip_call) { - // Call down the call chain: - lock.unlock(); - result = my_data->instance_dispatch_table->CreateDisplayPlaneSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); - lock.lock(); - - // Obtain this pointer again after locking: - pInstance = &(my_data->instanceMap[instance]); - if ((result == VK_SUCCESS) && pInstance && pSurface) { - // Record the VkSurfaceKHR returned by the ICD: - my_data->surfaceMap[*pSurface].surface = *pSurface; - my_data->surfaceMap[*pSurface].pInstance = pInstance; - // Point to the associated SwpInstance: - pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface]; - } - lock.unlock(); - return result; - } - return VK_ERROR_VALIDATION_FAILED_EXT; -} - -VKAPI_ATTR void VKAPI_CALL DestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks *pAllocator) { - bool skip_call = false; - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); - std::unique_lock<std::mutex> lock(global_lock); - SwpSurface *pSurface = NULL; - { - auto it = my_data->surfaceMap.find(surface); - pSurface = (it == my_data->surfaceMap.end()) ? NULL : &it->second; - } - - // Regardless of skip_call value, do some internal cleanup: - if (pSurface) { - // Delete the SwpSurface associated with this surface: - if (pSurface->pInstance) { - pSurface->pInstance->surfaces.erase(surface); - } - if (!pSurface->swapchains.empty()) { - skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, - HandleToUint64(instance), __LINE__, VALIDATION_ERROR_26c009e4, swapchain_layer_name, - "vkDestroySurfaceKHR() called before all of its associated VkSwapchainKHRs were destroyed. %s", - validation_error_map[VALIDATION_ERROR_26c009e4]); - - // Empty and then delete all SwpSwapchains - for (auto it = pSurface->swapchains.begin(); it != pSurface->swapchains.end(); it++) { - // Delete all SwpImage's - // In case the swapchain's device hasn't been destroyed yet - // (which isn't likely, but is possible), delete its - // association with this swapchain (i.e. so we can't point to - // this swpchain from that device, later on): - if (it->second->pDevice) { - it->second->pDevice->swapchains.clear(); - } - } - pSurface->swapchains.clear(); - } - my_data->surfaceMap.erase(surface); - } - lock.unlock(); - - if (!skip_call) { - // Call down the call chain: - my_data->instance_dispatch_table->DestroySurfaceKHR(instance, surface, pAllocator); - } -} - -VKAPI_ATTR VkResult VKAPI_CALL EnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, - VkPhysicalDevice *pPhysicalDevices) { - VkResult result = VK_SUCCESS; - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); - - // Call down the call chain: - result = my_data->instance_dispatch_table->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices); - - std::lock_guard<std::mutex> lock(global_lock); - SwpInstance *pInstance = NULL; - { - auto it = my_data->instanceMap.find(instance); - pInstance = (it == my_data->instanceMap.end()) ? NULL : &it->second; - } - if ((result == VK_SUCCESS) && pInstance && pPhysicalDevices && (*pPhysicalDeviceCount > 0)) { - // Record the VkPhysicalDevices returned by the ICD: - for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) { - my_data->physicalDeviceMap[pPhysicalDevices[i]].physicalDevice = pPhysicalDevices[i]; - my_data->physicalDeviceMap[pPhysicalDevices[i]].pInstance = pInstance; - my_data->physicalDeviceMap[pPhysicalDevices[i]].pDevice = NULL; - // Point to the associated SwpInstance: - if (pInstance) { - pInstance->physicalDevices[pPhysicalDevices[i]] = &my_data->physicalDeviceMap[pPhysicalDevices[i]]; - } - } - } - return result; -} - -VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, - const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) { - layer_data *my_instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); - VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); - - assert(chain_info->u.pLayerInfo); - PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; - PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr; - PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(my_instance_data->instance, "vkCreateDevice"); - if (fpCreateDevice == NULL) { - return VK_ERROR_INITIALIZATION_FAILED; - } - - // Advance the link info for the next element on the chain - chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; - - VkResult result = fpCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice); - if (result != VK_SUCCESS) { - return result; - } - - std::lock_guard<std::mutex> lock(global_lock); - layer_data *my_device_data = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map); - - // Setup device dispatch table - my_device_data->device_dispatch_table = new VkLayerDispatchTable; - layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr); - - my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice); - checkDeviceRegisterExtensions(physicalDevice, pCreateInfo, *pDevice); - - return result; -} - -VKAPI_ATTR void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) { - dispatch_key key = get_dispatch_key(device); - layer_data *my_data = GetLayerDataPtr(key, layer_data_map); - - // Call down the call chain: - my_data->device_dispatch_table->DestroyDevice(device, pAllocator); - - // Do some internal cleanup: - std::lock_guard<std::mutex> lock(global_lock); - SwpDevice *pDevice = NULL; - { - auto it = my_data->deviceMap.find(device); - pDevice = (it == my_data->deviceMap.end()) ? NULL : &it->second; - } - if (pDevice) { - // Delete the SwpDevice associated with this device: - if (pDevice->pPhysicalDevice) { - pDevice->pPhysicalDevice->pDevice = NULL; - } - if (!pDevice->swapchains.empty()) { - - // Empty and then delete all SwpSwapchain's - for (auto it = pDevice->swapchains.begin(); it != pDevice->swapchains.end(); it++) { - // Delete all SwpImage's - // In case the swapchain's surface hasn't been destroyed yet - // (which is likely) delete its association with this swapchain - // (i.e. so we can't point to this swpchain from that surface, - // later on): - if (it->second->pSurface) { - it->second->pSurface->swapchains.clear(); - } - } - pDevice->swapchains.clear(); - } - my_data->deviceMap.erase(device); - } - delete my_data->device_dispatch_table; - FreeLayerDataPtr(key, layer_data_map); -} - -VKAPI_ATTR VkResult VKAPI_CALL CreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, - const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain) { - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); - - // Call down the call chain: - VkResult result = my_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain); - std::unique_lock<std::mutex> lock(global_lock); - - if (result == VK_SUCCESS) { - // Remember the swapchain's handle, and link it to the device: - SwpDevice *pDevice = NULL; - { - auto it = my_data->deviceMap.find(device); - pDevice = (it == my_data->deviceMap.end()) ? NULL : &it->second; - } - - my_data->swapchainMap[*pSwapchain].swapchain = *pSwapchain; - if (pDevice) { - pDevice->swapchains[*pSwapchain] = &my_data->swapchainMap[*pSwapchain]; - } - my_data->swapchainMap[*pSwapchain].pDevice = pDevice; - my_data->swapchainMap[*pSwapchain].imageCount = 0; - // Store a pointer to the surface - SwpPhysicalDevice *pPhysicalDevice = pDevice->pPhysicalDevice; - SwpInstance *pInstance = (pPhysicalDevice) ? pPhysicalDevice->pInstance : NULL; - layer_data *my_instance_data = - ((pInstance) ? GetLayerDataPtr(get_dispatch_key(pInstance->instance), layer_data_map) : NULL); - SwpSurface *pSurface = ((my_data && pCreateInfo) ? &my_instance_data->surfaceMap[pCreateInfo->surface] : NULL); - my_data->swapchainMap[*pSwapchain].pSurface = pSurface; - if (pSurface) { - pSurface->swapchains[*pSwapchain] = &my_data->swapchainMap[*pSwapchain]; - } - } - lock.unlock(); - - return result; -} - -VKAPI_ATTR void VKAPI_CALL DestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator) { - // TODOs: - // - // - Implement a check for validity language that reads: All uses of - // presentable images acquired from pname:swapchain must: have completed - // execution - bool skip_call = false; - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); - std::unique_lock<std::mutex> lock(global_lock); - - // Regardless of skip_call value, do some internal cleanup: - SwpSwapchain *pSwapchain = NULL; - { - auto it = my_data->swapchainMap.find(swapchain); - pSwapchain = (it == my_data->swapchainMap.end()) ? NULL : &it->second; - } - if (pSwapchain) { - // Delete the SwpSwapchain associated with this swapchain: - if (pSwapchain->pDevice) { - pSwapchain->pDevice->swapchains.erase(swapchain); - } - if (pSwapchain->pSurface) { - pSwapchain->pSurface->swapchains.erase(swapchain); - } - my_data->swapchainMap.erase(swapchain); - } - lock.unlock(); - - if (!skip_call) { - // Call down the call chain: - my_data->device_dispatch_table->DestroySwapchainKHR(device, swapchain, pAllocator); - } -} - -VKAPI_ATTR VkResult VKAPI_CALL GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount, - VkImage *pSwapchainImages) { - VkResult result = VK_SUCCESS; - bool skip_call = false; - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); - std::unique_lock<std::mutex> lock(global_lock); - - SwpSwapchain *pSwapchain = NULL; - { - auto it = my_data->swapchainMap.find(swapchain); - pSwapchain = (it == my_data->swapchainMap.end()) ? NULL : &it->second; - } - if (pSwapchain && pSwapchainImages) { - // Compare the preliminary value of *pSwapchainImageCount with the value this time: - if (pSwapchain->imageCount == 0) { - // Since we haven't recorded a preliminary value of *pSwapchainImageCount, that likely means that the application didn't - // previously call this function with a NULL value of pSwapchainImages: - skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, - HandleToUint64(device), __LINE__, SWAPCHAIN_PRIOR_COUNT, swapchain_layer_name, - "vkGetSwapchainImagesKHR() called with non-NULL pSwapchainImageCount; but no prior positive " - "value has been seen for pSwapchainImages."); - } else if (*pSwapchainImageCount > pSwapchain->imageCount) { - skip_call |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, - HandleToUint64(device), __LINE__, SWAPCHAIN_INVALID_COUNT, swapchain_layer_name, - "vkGetSwapchainImagesKHR() called with non-NULL pSwapchainImageCount, and with " - "pSwapchainImages set to a value (%d) that is greater than the value (%d) that was returned when " - "pSwapchainImageCount was NULL.", - *pSwapchainImageCount, pSwapchain->imageCount); - } - } - lock.unlock(); - - if (!skip_call) { - // Call down the call chain: - result = my_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages); - lock.lock(); - - // Obtain this pointer again after locking: - { - auto it = my_data->swapchainMap.find(swapchain); - pSwapchain = (it == my_data->swapchainMap.end()) ? NULL : &it->second; - } - if ((result == VK_SUCCESS) && pSwapchain && !pSwapchainImages && pSwapchainImageCount) { - // Record the result of this preliminary query: - pSwapchain->imageCount = *pSwapchainImageCount; - } else if ((result == VK_SUCCESS) && pSwapchain && pSwapchainImages && pSwapchainImageCount && - (*pSwapchainImageCount > 0)) { - // Record the images and their state: - pSwapchain->imageCount = *pSwapchainImageCount; - } - lock.unlock(); - - return result; - } - return VK_ERROR_VALIDATION_FAILED_EXT; -} - -VKAPI_ATTR VkResult VKAPI_CALL CreateDebugReportCallbackEXT(VkInstance instance, - const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, - const VkAllocationCallbacks *pAllocator, - VkDebugReportCallbackEXT *pMsgCallback) { - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); - VkResult result = - my_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback); - if (VK_SUCCESS == result) { - std::lock_guard<std::mutex> lock(global_lock); - result = layer_create_msg_callback(my_data->report_data, false, pCreateInfo, pAllocator, pMsgCallback); - } - return result; -} - -VKAPI_ATTR void VKAPI_CALL DestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback, - const VkAllocationCallbacks *pAllocator) { - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); - my_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator); - std::lock_guard<std::mutex> lock(global_lock); - layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator); -} - -VKAPI_ATTR void VKAPI_CALL DebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, - VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location, - int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { - layer_data *my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); - my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, - pMsg); -} - -VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) { - return util_GetLayerProperties(1, &swapchain_layer, pCount, pProperties); -} - -VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, - VkLayerProperties *pProperties) { - return util_GetLayerProperties(1, &swapchain_layer, pCount, pProperties); -} - -VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, - VkExtensionProperties *pProperties) { - if (pLayerName && !strcmp(pLayerName, swapchain_layer.layerName)) - return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties); - - return VK_ERROR_LAYER_NOT_PRESENT; -} - -VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName, - uint32_t *pCount, VkExtensionProperties *pProperties) { - if (pLayerName && !strcmp(pLayerName, swapchain_layer.layerName)) - return util_GetExtensionProperties(0, nullptr, pCount, pProperties); - - assert(physicalDevice); - - dispatch_key key = get_dispatch_key(physicalDevice); - layer_data *my_data = GetLayerDataPtr(key, layer_data_map); - return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(physicalDevice, NULL, pCount, pProperties); -} - -static PFN_vkVoidFunction intercept_core_instance_command(const char *name); - -static PFN_vkVoidFunction intercept_khr_surface_command(const char *name, VkInstance instance); - -static PFN_vkVoidFunction intercept_extension_instance_commands(const char *name); - -static PFN_vkVoidFunction intercept_core_device_command(const char *name); - -static PFN_vkVoidFunction intercept_khr_swapchain_command(const char *name, VkDevice dev); - -VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *funcName) { - PFN_vkVoidFunction proc = intercept_core_device_command(funcName); - if (proc) return proc; - - assert(device); - - layer_data *my_data; - - my_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); - VkLayerDispatchTable *pDisp = my_data->device_dispatch_table; - - proc = intercept_khr_swapchain_command(funcName, device); - if (proc) return proc; - - if (pDisp->GetDeviceProcAddr == NULL) return NULL; - return pDisp->GetDeviceProcAddr(device, funcName); -} - -VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char *funcName) { - PFN_vkVoidFunction proc = intercept_core_instance_command(funcName); - if (!proc) proc = intercept_core_device_command(funcName); - if (!proc) proc = intercept_khr_swapchain_command(funcName, VK_NULL_HANDLE); - if (proc) return proc; - - assert(instance); - - layer_data *my_data; - my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); - VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table; - - proc = debug_report_get_instance_proc_addr(my_data->report_data, funcName); - if (!proc) proc = intercept_khr_surface_command(funcName, instance); - if (!proc) proc = intercept_extension_instance_commands(funcName); - if (proc) return proc; - - if (pTable->GetInstanceProcAddr == NULL) return NULL; - return pTable->GetInstanceProcAddr(instance, funcName); -} - -VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) { - assert(instance); - - layer_data *my_data; - my_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); - VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table; - - if (pTable->GetPhysicalDeviceProcAddr == NULL) return NULL; - return pTable->GetPhysicalDeviceProcAddr(instance, funcName); -} - -static PFN_vkVoidFunction intercept_core_instance_command(const char *name) { - static const struct { - const char *name; - PFN_vkVoidFunction proc; - } core_instance_commands[] = { - {"vkGetInstanceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetInstanceProcAddr)}, - {"vkCreateInstance", reinterpret_cast<PFN_vkVoidFunction>(CreateInstance)}, - {"vkDestroyInstance", reinterpret_cast<PFN_vkVoidFunction>(DestroyInstance)}, - {"vkCreateDevice", reinterpret_cast<PFN_vkVoidFunction>(CreateDevice)}, - {"vkEnumeratePhysicalDevices", reinterpret_cast<PFN_vkVoidFunction>(EnumeratePhysicalDevices)}, - {"vk_layerGetPhysicalDeviceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceProcAddr)}, - {"vkEnumerateInstanceLayerProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateInstanceLayerProperties)}, - {"vkEnumerateDeviceLayerProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateDeviceLayerProperties)}, - {"vkEnumerateInstanceExtensionProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateInstanceExtensionProperties)}, - {"vkEnumerateDeviceExtensionProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateDeviceExtensionProperties)}, - }; - - for (size_t i = 0; i < ARRAY_SIZE(core_instance_commands); i++) { - if (!strcmp(core_instance_commands[i].name, name)) return core_instance_commands[i].proc; - } - - return nullptr; -} - -static PFN_vkVoidFunction intercept_khr_surface_command(const char *name, VkInstance instance) { - static const struct { - const char *name; - PFN_vkVoidFunction proc; - } khr_surface_commands[] = { -#ifdef VK_USE_PLATFORM_ANDROID_KHR - {"vkCreateAndroidSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateAndroidSurfaceKHR)}, -#endif // VK_USE_PLATFORM_ANDROID_KHR -#ifdef VK_USE_PLATFORM_MIR_KHR - {"vkCreateMirSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateMirSurfaceKHR)}, -#endif // VK_USE_PLATFORM_MIR_KHR -#ifdef VK_USE_PLATFORM_WAYLAND_KHR - {"vkCreateWaylandSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateWaylandSurfaceKHR)}, -#endif // VK_USE_PLATFORM_WAYLAND_KHR -#ifdef VK_USE_PLATFORM_WIN32_KHR - {"vkCreateWin32SurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateWin32SurfaceKHR)}, -#endif // VK_USE_PLATFORM_WIN32_KHR -#ifdef VK_USE_PLATFORM_XCB_KHR - {"vkCreateXcbSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateXcbSurfaceKHR)}, -#endif // VK_USE_PLATFORM_XCB_KHR -#ifdef VK_USE_PLATFORM_XLIB_KHR - {"vkCreateXlibSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateXlibSurfaceKHR)}, -#endif // VK_USE_PLATFORM_XLIB_KHR - {"vkDestroySurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(DestroySurfaceKHR)}, - {"vkGetPhysicalDeviceDisplayPlanePropertiesKHR", - reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceDisplayPlanePropertiesKHR)}, - {"vkGetDisplayPlaneSupportedDisplaysKHR", reinterpret_cast<PFN_vkVoidFunction>(GetDisplayPlaneSupportedDisplaysKHR)}, - {"vkGetDisplayPlaneCapabilitiesKHR", reinterpret_cast<PFN_vkVoidFunction>(GetDisplayPlaneCapabilitiesKHR)}, - {"vkCreateDisplayPlaneSurfaceKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateDisplayPlaneSurfaceKHR)}, - }; - - // do not check if VK_KHR_*_surface is enabled (why?) - - for (size_t i = 0; i < ARRAY_SIZE(khr_surface_commands); i++) { - if (!strcmp(khr_surface_commands[i].name, name)) return khr_surface_commands[i].proc; - } - - return nullptr; -} - -static PFN_vkVoidFunction intercept_extension_instance_commands(const char *name) { - return nullptr; -} - -static PFN_vkVoidFunction intercept_core_device_command(const char *name) { - static const struct { - const char *name; - PFN_vkVoidFunction proc; - } core_device_commands[] = { - {"vkGetDeviceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetDeviceProcAddr)}, - {"vkDestroyDevice", reinterpret_cast<PFN_vkVoidFunction>(DestroyDevice)}, - }; - - for (size_t i = 0; i < ARRAY_SIZE(core_device_commands); i++) { - if (!strcmp(core_device_commands[i].name, name)) return core_device_commands[i].proc; - } - - return nullptr; -} - -static PFN_vkVoidFunction intercept_khr_swapchain_command(const char *name, VkDevice dev) { - static const struct { - const char *name; - PFN_vkVoidFunction proc; - } khr_swapchain_commands[] = { - {"vkCreateSwapchainKHR", reinterpret_cast<PFN_vkVoidFunction>(CreateSwapchainKHR)}, - {"vkDestroySwapchainKHR", reinterpret_cast<PFN_vkVoidFunction>(DestroySwapchainKHR)}, - {"vkGetSwapchainImagesKHR", reinterpret_cast<PFN_vkVoidFunction>(GetSwapchainImagesKHR)}, - }; - - // do not check if VK_KHR_swapchain is enabled (why?) - - for (size_t i = 0; i < ARRAY_SIZE(khr_swapchain_commands); i++) { - if (!strcmp(khr_swapchain_commands[i].name, name)) return khr_swapchain_commands[i].proc; - } - - return nullptr; -} - -} // namespace swapchain - -// vk_layer_logging.h expects these to be defined - -VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(VkInstance instance, - const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, - const VkAllocationCallbacks *pAllocator, - VkDebugReportCallbackEXT *pMsgCallback) { - return swapchain::CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback); -} - -VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback, - const VkAllocationCallbacks *pAllocator) { - swapchain::DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator); -} - -VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, - VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location, - int32_t msgCode, const char *pLayerPrefix, const char *pMsg) { - swapchain::DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg); -} - -// loader-layer interface v0, just wrappers since there is only a layer - -VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, - VkExtensionProperties *pProperties) { - return swapchain::EnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties); -} - -VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, - VkLayerProperties *pProperties) { - return swapchain::EnumerateInstanceLayerProperties(pCount, pProperties); -} - -VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, - VkLayerProperties *pProperties) { - // the layer command handles VK_NULL_HANDLE just fine internally - assert(physicalDevice == VK_NULL_HANDLE); - return swapchain::EnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties); -} - -VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, - const char *pLayerName, uint32_t *pCount, - VkExtensionProperties *pProperties) { - // the layer command handles VK_NULL_HANDLE just fine internally - assert(physicalDevice == VK_NULL_HANDLE); - return swapchain::EnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties); -} - -VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) { - return swapchain::GetDeviceProcAddr(dev, funcName); -} - -VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) { - return swapchain::GetInstanceProcAddr(instance, funcName); -} - -VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance, - const char *funcName) { - return swapchain::GetPhysicalDeviceProcAddr(instance, funcName); -} - -VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) { - assert(pVersionStruct != NULL); - assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT); - - // Fill in the function pointers if our version is at least capable of having the structure contain them. - if (pVersionStruct->loaderLayerInterfaceVersion >= 2) { - pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr; - pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr; - pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr; - } - - if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) { - swapchain::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion; - } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) { - pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION; - } - - return VK_SUCCESS; -} diff --git a/layers/swapchain.h b/layers/swapchain.h deleted file mode 100644 index 5949a3f3..00000000 --- a/layers/swapchain.h +++ /dev/null @@ -1,215 +0,0 @@ -/* Copyright (c) 2015-2016 The Khronos Group Inc. - * Copyright (c) 2015-2016 Valve Corporation - * Copyright (c) 2015-2016 LunarG, Inc. - * Copyright (C) 2015-2016 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Author: Ian Elliott <ian@lunarg.com> - * Author: Ian Elliott <ianelliott@google.com> - */ - -#ifndef SWAPCHAIN_H -#define SWAPCHAIN_H - -#include "vulkan/vk_layer.h" -#include "vk_layer_config.h" -#include "vk_layer_logging.h" -#include <vector> -#include <unordered_map> - -// Swapchain ERROR codes -enum SWAPCHAIN_ERROR { - SWAPCHAIN_INVALID_HANDLE, // Handle used that isn't currently valid - SWAPCHAIN_NULL_POINTER, // Pointer set to NULL, instead of being a valid pointer - SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, // Did not enable WSI extension, but called WSI function - SWAPCHAIN_DEL_OBJECT_BEFORE_CHILDREN, // Called vkDestroyDevice() before vkDestroySwapchainKHR() - SWAPCHAIN_CREATE_UNSUPPORTED_SURFACE, // Called vkCreateSwapchainKHR() with a pCreateInfo->surface that wasn't seen as - // supported - // by vkGetPhysicalDeviceSurfaceSupportKHR for the device - SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY, // Called vkCreateSwapchainKHR() without calling a query (e.g. - // vkGetPhysicalDeviceSurfaceCapabilitiesKHR()) - SWAPCHAIN_CREATE_SWAP_OUT_OF_BOUNDS_EXTENTS, // Called vkCreateSwapchainKHR() with out-of-bounds imageExtent - SWAPCHAIN_CREATE_SWAP_EXTENTS_NO_MATCH_WIN, // Called vkCreateSwapchainKHR() with imageExtent that doesn't match window's - // extent - SWAPCHAIN_CREATE_SWAP_BAD_PRE_TRANSFORM, // Called vkCreateSwapchainKHR() with a non-supported preTransform - SWAPCHAIN_CREATE_SWAP_BAD_COMPOSITE_ALPHA, // Called vkCreateSwapchainKHR() with a non-supported compositeAlpha - SWAPCHAIN_CREATE_SWAP_BAD_IMG_ARRAY_LAYERS, // Called vkCreateSwapchainKHR() with a non-supported imageArrayLayers - SWAPCHAIN_CREATE_SWAP_BAD_IMG_USAGE_FLAGS, // Called vkCreateSwapchainKHR() with a non-supported imageUsageFlags - SWAPCHAIN_CREATE_SWAP_BAD_IMG_COLOR_SPACE, // Called vkCreateSwapchainKHR() with a non-supported imageColorSpace - SWAPCHAIN_CREATE_SWAP_BAD_IMG_FORMAT, // Called vkCreateSwapchainKHR() with a non-supported imageFormat - SWAPCHAIN_CREATE_SWAP_BAD_IMG_FMT_CLR_SP, // Called vkCreateSwapchainKHR() with a non-supported imageColorSpace - SWAPCHAIN_CREATE_SWAP_BAD_PRESENT_MODE, // Called vkCreateSwapchainKHR() with a non-supported presentMode - SWAPCHAIN_CREATE_SWAP_BAD_SHARING_MODE, // Called vkCreateSwapchainKHR() with a non-supported imageSharingMode - SWAPCHAIN_CREATE_SWAP_BAD_SHARING_VALUES, // Called vkCreateSwapchainKHR() with bad values when imageSharingMode is - // VK_SHARING_MODE_CONCURRENT - SWAPCHAIN_BAD_BOOL, // VkBool32 that doesn't have value of VK_TRUE or VK_FALSE (e.g. is a non-zero form of true) - SWAPCHAIN_PRIOR_COUNT, // Query must be called first to get value of pCount, then called second time - SWAPCHAIN_INVALID_COUNT, // Second time a query called, the pCount value didn't match first time - SWAPCHAIN_WRONG_STYPE, // The sType for a struct has the wrong value - SWAPCHAIN_WRONG_NEXT, // The pNext for a struct is not NULL - SWAPCHAIN_ZERO_VALUE, // A value should be non-zero - SWAPCHAIN_GET_SUPPORTED_DISPLAYS_WITHOUT_QUERY, // vkGetDisplayPlaneSupportedDisplaysKHR should be called after querying - // device display plane properties - SWAPCHAIN_PLANE_INDEX_TOO_LARGE, // a planeIndex value is larger than what vkGetDisplayPlaneSupportedDisplaysKHR returns -}; - -// The following is for logging error messages: -const char *swapchain_layer_name = "Swapchain"; - -#define LAYER_NAME (char *)"Swapchain" - -// NOTE: The following struct's/typedef's are for keeping track of -// info that is used for validating the WSI extensions. - -// Forward declarations: -struct SwpInstance; -struct SwpSurface; -struct SwpPhysicalDevice; -struct SwpDevice; -struct SwpSwapchain; -struct SwpImage; -struct SwpQueue; - -// Create one of these for each VkInstance: -struct SwpInstance { - // The actual handle for this VkInstance: - VkInstance instance; - - // Remember the VkSurfaceKHR's that are created for this VkInstance: - std::unordered_map<VkSurfaceKHR, SwpSurface *> surfaces; - - // When vkEnumeratePhysicalDevices is called, the VkPhysicalDevice's are - // remembered: - std::unordered_map<const void *, SwpPhysicalDevice *> physicalDevices; - - // Set to true if VK_KHR_DISPLAY_EXTENSION_NAME was enabled for this VkInstance: - bool displayExtensionEnabled; -}; - -// Create one of these for each VkSurfaceKHR: -struct SwpSurface { - // The actual handle for this VkSurfaceKHR: - VkSurfaceKHR surface; - - // VkInstance that this VkSurfaceKHR is associated with: - SwpInstance *pInstance; - - // When vkCreateSwapchainKHR is called, the VkSwapchainKHR's are - // remembered: - std::unordered_map<VkSwapchainKHR, SwpSwapchain *> swapchains; -}; - -// Create one of these for each VkPhysicalDevice within a VkInstance: -struct SwpPhysicalDevice { - // The actual handle for this VkPhysicalDevice: - VkPhysicalDevice physicalDevice; - - // Corresponding VkDevice (and info) to this VkPhysicalDevice: - SwpDevice *pDevice; - - // VkInstance that this VkPhysicalDevice is associated with: - SwpInstance *pInstance; - - // Count returned by vkGetPhysicalDeviceDisplayPlanePropertiesKHR(): - uint32_t displayPlanePropertyCount; - bool gotDisplayPlanePropertyCount; -}; - -// Create one of these for each VkDevice within a VkInstance: -struct SwpDevice { - // The actual handle for this VkDevice: - VkDevice device; - - // Corresponding VkPhysicalDevice (and info) to this VkDevice: - SwpPhysicalDevice *pPhysicalDevice; - - // When vkCreateSwapchainKHR is called, the VkSwapchainKHR's are - // remembered: - std::unordered_map<VkSwapchainKHR, SwpSwapchain *> swapchains; -}; - -// Create one of these for each VkImage within a VkSwapchainKHR: -struct SwpImage { - // The actual handle for this VkImage: - VkImage image; - - // Corresponding VkSwapchainKHR (and info) to this VkImage: - SwpSwapchain *pSwapchain; - - // true if application acquired this image from vkAcquireNextImageKHR(), - // and hasn't yet called vkQueuePresentKHR() for it; otherwise false: - bool acquiredByApp; -}; - -// Create one of these for each VkSwapchainKHR within a VkDevice: -struct SwpSwapchain { - // The actual handle for this VkSwapchainKHR: - VkSwapchainKHR swapchain; - - // Corresponding VkDevice (and info) to this VkSwapchainKHR: - SwpDevice *pDevice; - - // Corresponding VkSurfaceKHR to this VkSwapchainKHR: - SwpSurface *pSurface; - - // When vkGetSwapchainImagesKHR is called, the VkImage's are - // remembered: - uint32_t imageCount; -}; - -// Create one of these for each VkQueue within a VkDevice: -struct SwpQueue { - // The actual handle for this VkQueue: - VkQueue queue; - - // Corresponding VkDevice (and info) to this VkSwapchainKHR: - SwpDevice *pDevice; - - // Which queueFamilyIndex this VkQueue is associated with: - uint32_t queueFamilyIndex; -}; - -struct layer_data { - VkInstance instance; - - debug_report_data *report_data; - std::vector<VkDebugReportCallbackEXT> logging_callback; - VkLayerDispatchTable *device_dispatch_table; - VkLayerInstanceDispatchTable *instance_dispatch_table; - - // The following are for keeping track of the temporary callbacks that can - // be used in vkCreateInstance and vkDestroyInstance: - uint32_t num_tmp_callbacks; - VkDebugReportCallbackCreateInfoEXT *tmp_dbg_create_infos; - VkDebugReportCallbackEXT *tmp_callbacks; - - // NOTE: The following are for keeping track of info that is used for - // validating the WSI extensions. - std::unordered_map<void *, SwpInstance> instanceMap; - std::unordered_map<VkSurfaceKHR, SwpSurface> surfaceMap; - std::unordered_map<void *, SwpPhysicalDevice> physicalDeviceMap; - std::unordered_map<void *, SwpDevice> deviceMap; - std::unordered_map<VkSwapchainKHR, SwpSwapchain> swapchainMap; - std::unordered_map<void *, SwpQueue> queueMap; - - layer_data() - : report_data(nullptr), - device_dispatch_table(nullptr), - instance_dispatch_table(nullptr), - num_tmp_callbacks(0), - tmp_dbg_create_infos(nullptr), - tmp_callbacks(nullptr){}; -}; - -#endif // SWAPCHAIN_H |
