Layers: GH674: Improve locking in swapchain layer.
This fixes cases where the swapchain layer wasn't always unlocking before
returning from a function.
diff --git a/layers/swapchain.cpp b/layers/swapchain.cpp
index 440c6d0..4271120 100644
--- a/layers/swapchain.cpp
+++ b/layers/swapchain.cpp
@@ -400,10 +400,10 @@
skipCall |= LOG_INFO_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "pCreateInfo");
}
}
+ lock.unlock();
if (!skipCall) {
// Call down the call chain:
- lock.unlock();
result = my_data->instance_dispatch_table->CreateAndroidSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
lock.lock();
@@ -422,6 +422,8 @@
// Point to the associated SwpInstance:
pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
}
+ lock.unlock();
+
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
@@ -460,10 +462,10 @@
skipCall |= LOG_INFO_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "pCreateInfo");
}
}
+ lock.unlock();
if (!skipCall) {
// Call down the call chain:
- lock.unlock();
result = my_data->instance_dispatch_table->CreateMirSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
lock.lock();
@@ -482,6 +484,8 @@
// Point to the associated SwpInstance:
pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
}
+ lock.unlock();
+
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
@@ -555,10 +559,10 @@
skipCall |= LOG_INFO_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "pCreateInfo");
}
}
+ lock.unlock();
if (!skipCall) {
// Call down the call chain:
- lock.unlock();
result = my_data->instance_dispatch_table->CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
lock.lock();
@@ -577,6 +581,8 @@
// Point to the associated SwpInstance:
pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
}
+ lock.unlock();
+
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
@@ -650,10 +656,10 @@
skipCall |= LOG_INFO_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "pCreateInfo");
}
}
+ lock.unlock();
if (!skipCall) {
// Call down the call chain:
- lock.unlock();
result = my_data->instance_dispatch_table->CreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
lock.lock();
@@ -672,6 +678,8 @@
// Point to the associated SwpInstance:
pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
}
+ lock.unlock();
+
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
@@ -743,10 +751,10 @@
skipCall |= LOG_INFO_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "pCreateInfo");
}
}
+ lock.unlock();
if (!skipCall) {
// Call down the call chain:
- lock.unlock();
result = my_data->instance_dispatch_table->CreateXcbSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
lock.lock();
@@ -765,6 +773,8 @@
// Point to the associated SwpInstance:
pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
}
+ lock.unlock();
+
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
@@ -838,10 +848,10 @@
skipCall |= LOG_INFO_WRONG_NEXT(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "pCreateInfo");
}
}
+ lock.unlock();
if (!skipCall) {
// Call down the call chain:
- lock.unlock();
result = my_data->instance_dispatch_table->CreateXlibSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
lock.lock();
@@ -860,6 +870,8 @@
// Point to the associated SwpInstance:
pInstance->surfaces[*pSurface] = &my_data->surfaceMap[*pSurface];
}
+ lock.unlock();
+
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
@@ -1113,10 +1125,10 @@
if (!pSupported) {
skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, physicalDevice, "pSupported");
}
+ lock.unlock();
if (!skipCall) {
// Call down the call chain:
- lock.unlock();
result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, surface,
pSupported);
lock.lock();
@@ -1146,6 +1158,8 @@
}
}
}
+ lock.unlock();
+
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
@@ -1174,10 +1188,10 @@
if (!pSurfaceCapabilities) {
skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, physicalDevice, "pSurfaceCapabilities");
}
+ lock.unlock();
if (!skipCall) {
// Call down the call chain:
- lock.unlock();
result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface,
pSurfaceCapabilities);
lock.lock();
@@ -1193,6 +1207,8 @@
// FIXME: NEED TO COPY THIS DATA, BECAUSE pSurfaceCapabilities POINTS TO APP-ALLOCATED DATA
pPhysicalDevice->surfaceCapabilities = *pSurfaceCapabilities;
}
+ lock.unlock();
+
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
@@ -1238,10 +1254,10 @@
*pSurfaceFormatCount, pPhysicalDevice->surfaceFormatCount);
}
}
+ lock.unlock();
if (!skipCall) {
// Call down the call chain:
- lock.unlock();
result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, pSurfaceFormatCount,
pSurfaceFormats);
lock.lock();
@@ -1268,6 +1284,8 @@
pPhysicalDevice->surfaceFormatCount = 0;
}
}
+ lock.unlock();
+
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
@@ -1313,10 +1331,10 @@
*pPresentModeCount, pPhysicalDevice->presentModeCount);
}
}
+ lock.unlock();
if (!skipCall) {
// Call down the call chain:
- lock.unlock();
result = my_data->instance_dispatch_table->GetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface,
pPresentModeCount, pPresentModes);
lock.lock();
@@ -1343,6 +1361,8 @@
pPhysicalDevice->presentModeCount = 0;
}
}
+ lock.unlock();
+
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
@@ -1684,10 +1704,10 @@
layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
std::unique_lock<std::mutex> lock(global_lock);
bool skipCall = validateCreateSwapchainKHR(device, pCreateInfo, pSwapchain);
+ lock.unlock();
if (!skipCall) {
// Call down the call chain:
- lock.unlock();
result = my_data->device_dispatch_table->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
lock.lock();
@@ -1717,6 +1737,8 @@
pSurface->swapchains[*pSwapchain] = &my_data->swapchainMap[*pSwapchain];
}
}
+ lock.unlock();
+
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
@@ -1827,10 +1849,10 @@
*pSwapchainImageCount, pSwapchain->imageCount);
}
}
+ lock.unlock();
if (!skipCall) {
// Call down the call chain:
- lock.unlock();
result = my_data->device_dispatch_table->GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages);
lock.lock();
@@ -1852,6 +1874,8 @@
pSwapchain->images[i].acquiredByApp = false;
}
}
+ lock.unlock();
+
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
@@ -1929,10 +1953,10 @@
if (!pImageIndex) {
skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "pImageIndex");
}
+ lock.unlock();
if (!skipCall) {
// Call down the call chain:
- lock.unlock();
result = my_data->device_dispatch_table->AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
lock.lock();
@@ -1945,6 +1969,8 @@
// Change the state of the image (now acquired by the application):
pSwapchain->images[*pImageIndex].acquiredByApp = true;
}
+ lock.unlock();
+
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
@@ -2039,10 +2065,10 @@
}
}
}
+ lock.unlock();
if (!skipCall) {
// Call down the call chain:
- lock.unlock();
result = my_data->device_dispatch_table->QueuePresentKHR(queue, pPresentInfo);
lock.lock();
@@ -2061,6 +2087,8 @@
}
}
}
+ lock.unlock();
+
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;