diff options
| author | Ian Elliott <ianelliott@google.com> | 2016-01-20 16:33:34 -0700 |
|---|---|---|
| committer | Jon Ashburn <jon@lunarg.com> | 2016-01-28 11:18:56 -0700 |
| commit | 46b88bca67b586be0459fd01f38b50ed70746f0d (patch) | |
| tree | 0554fffc0290ebb4c66ba98a8a9d309118ac87b7 /layers/swapchain.cpp | |
| parent | f7d4210cf40e59fad6a1f1dad6a55aac6a546958 (diff) | |
| download | usermoji-46b88bca67b586be0459fd01f38b50ed70746f0d.tar.xz | |
Swapchain: Keep/check relationships between surfaces and swapchains.
Diffstat (limited to 'layers/swapchain.cpp')
| -rw-r--r-- | layers/swapchain.cpp | 103 |
1 files changed, 97 insertions, 6 deletions
diff --git a/layers/swapchain.cpp b/layers/swapchain.cpp index 4690e7fc..23388366 100644 --- a/layers/swapchain.cpp +++ b/layers/swapchain.cpp @@ -435,6 +435,15 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR( // Call down the call chain: result = my_data->instance_dispatch_table->CreateAndroidSurfaceKHR( instance, pCreateInfo, pAllocator, pSurface); + + 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]; + } + return result; } return VK_ERROR_VALIDATION_FAILED_EXT; @@ -485,6 +494,15 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateMirSurfaceKHR( // Call down the call chain: result = my_data->instance_dispatch_table->CreateMirSurfaceKHR( instance, pCreateInfo, pAllocator, pSurface); + + 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]; + } + return result; } return VK_ERROR_VALIDATION_FAILED_EXT; @@ -572,6 +590,15 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR( // Call down the call chain: result = my_data->instance_dispatch_table->CreateWaylandSurfaceKHR( instance, pCreateInfo, pAllocator, pSurface); + + 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]; + } + return result; } return VK_ERROR_VALIDATION_FAILED_EXT; @@ -659,6 +686,15 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR( // Call down the call chain: result = my_data->instance_dispatch_table->CreateWin32SurfaceKHR( instance, pCreateInfo, pAllocator, pSurface); + + 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]; + } + return result; } return VK_ERROR_VALIDATION_FAILED_EXT; @@ -745,6 +781,15 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR( // Call down the call chain: result = my_data->instance_dispatch_table->CreateXcbSurfaceKHR( instance, pCreateInfo, pAllocator, pSurface); + + 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]; + } + return result; } return VK_ERROR_VALIDATION_FAILED_EXT; @@ -833,6 +878,15 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR( // Call down the call chain: result = my_data->instance_dispatch_table->CreateXlibSurfaceKHR( instance, pCreateInfo, pAllocator, pSurface); + + 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]; + } + return result; } return VK_ERROR_VALIDATION_FAILED_EXT; @@ -881,14 +935,37 @@ VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(VkInstance insta { VkBool32 skipCall = VK_FALSE; layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map); + SwpInstance *pInstance = &(my_data->instanceMap[instance]); + SwpSurface *pSurface = &my_data->surfaceMap[surface]; + + // Regardless of skipCall 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()) { + LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, instance, "VkInstance", + SWAPCHAIN_DEL_OBJECT_BEFORE_SWAPCHAINS, + "%s() called before all of its associated " + "VkSwapchainKHRs were destroyed.", + __FUNCTION__); + // Empty and then delete all SwpSwapchain's + for (auto it = pSurface->swapchains.begin() ; + it != pSurface->swapchains.end() ; it++) { + // Delete all SwpImage's + it->second->images.clear(); + } + pSurface->swapchains.clear(); + } + my_data->surfaceMap.erase(surface); + } if (VK_FALSE == skipCall) { // Call down the call chain: my_data->instance_dispatch_table->DestroySurfaceKHR( instance, surface, pAllocator); } - - // No need to do any cleanup--rely on object_tracker to track VkSurfaceKHR } VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices) @@ -983,7 +1060,7 @@ VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, cons } if (!pDevice->swapchains.empty()) { LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", - SWAPCHAIN_DEL_DEVICE_BEFORE_SWAPCHAINS, + SWAPCHAIN_DEL_OBJECT_BEFORE_SWAPCHAINS, "%s() called before all of its associated " "VkSwapchainKHRs were destroyed.", __FUNCTION__); @@ -1605,7 +1682,7 @@ static VkBool32 validateCreateSwapchainKHR( "than the VkSwapchainKHR was created with.", __FUNCTION__); } - if (pCreateInfo->surface != pOldSwapchain->surface) { + if (pCreateInfo->surface != pOldSwapchain->pSurface->surface) { skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", SWAPCHAIN_CREATE_SWAP_DIFF_SURFACE, @@ -1649,9 +1726,23 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR( pDevice->swapchains[*pSwapchain] = &my_data->swapchainMap[*pSwapchain]; my_data->swapchainMap[*pSwapchain].pDevice = pDevice; - my_data->swapchainMap[*pSwapchain].surface = - (pCreateInfo) ? pCreateInfo->surface : 0; 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) ? + get_my_data_ptr(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]; + } } return result; |
