pCount, pProperties);
}
-// This function validates a VkSurfaceKHR object:
-static VkBool32 validateSurface(layer_data *my_data, VkSurfaceKHR surface, char *fn)
-{
- VkBool32 skipCall = VK_FALSE;
- SwpSurface *pSurface = &my_data->surfaceMap[surface];
-
- if ((pSurface == NULL) || (pSurface->surface != surface)) {
- skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT, surface, "VkSurfaceKHR",
- SWAPCHAIN_INVALID_HANDLE,
- "%s() called with an invalid surface object.",
- fn);
- }
- return skipCall;
-}
-
static void createDeviceRegisterExtensions(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
{
uint32_t i;
// 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];
- skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__);
- }
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
// 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];
- skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__);
- }
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
// 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];
- skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__);
- }
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
// 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];
- skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__);
- }
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
// 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];
- skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__);
- }
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
// 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];
- skipCall |= validateSurface(my_data, *pSurface, (char *) __FUNCTION__);
- }
return result;
}
return VK_ERROR_VALIDATION_FAILED_EXT;
}
if (VK_FALSE == skipCall) {
- // Validate that a valid VkSurfaceKHR was used:
- skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__);
- }
-
- if (VK_FALSE == skipCall) {
// Call down the call chain:
my_data->instance_dispatch_table->DestroySurfaceKHR(
instance, surface, pAllocator);
}
- // Regardless of skipCall value, do some internal cleanup:
- SwpSurface *pSurface = &my_data->surfaceMap[surface];
- if (pSurface && pSurface->pInstance) {
- pSurface->pInstance->surfaces.erase(surface);
- }
- my_data->surfaceMap.erase(surface);
+ // 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)
"%s() called even though the %s extension was not enabled for this VkInstance.",
__FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
}
- skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__);
if (!pSupported) {
skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
physicalDevice,
"%s() called even though the %s extension was not enabled for this VkInstance.",
__FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
}
- skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__);
if (!pSurfaceCapabilities) {
skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
physicalDevice,
"%s() called even though the %s extension was not enabled for this VkInstance.",
__FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
}
- skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__);
if (!pSurfaceFormatCount) {
skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
physicalDevice,
"%s() called even though the %s extension was not enabled for this VkInstance.",
__FUNCTION__, VK_KHR_SURFACE_EXTENSION_NAME);
}
- skipCall |= validateSurface(my_data, surface, (char *) __FUNCTION__);
if (!pPresentModeCount) {
skipCall |= LOG_ERROR_NULL_POINTER(VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
physicalDevice,
// Keep around a useful pointer to pPhysicalDevice:
SwpPhysicalDevice *pPhysicalDevice = pDevice->pPhysicalDevice;
- // Validate pCreateInfo->surface:
- if (pPhysicalDevice) {
- // Note: in order to validate, we must lookup layer_data based on the
- // VkInstance associated with this VkDevice:
- 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;
- skipCall |= validateSurface(my_instance_data,
- pCreateInfo->surface,
- (char *) "vkCreateSwapchainKHR");
- }
-
// Validate pCreateInfo values with the results of
// vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
if (!pPhysicalDevice || !pPhysicalDevice->gotSurfaceCapabilities) {
// Forward declarations:
struct _SwpInstance;
-struct _SwpSurface;
struct _SwpPhysicalDevice;
struct _SwpDevice;
struct _SwpSwapchain;
struct _SwpImage;
typedef _SwpInstance SwpInstance;
-typedef _SwpSurface SwpSurface;
typedef _SwpPhysicalDevice SwpPhysicalDevice;
typedef _SwpDevice SwpDevice;
typedef _SwpSwapchain SwpSwapchain;
// The actual handle for this VkInstance:
VkInstance instance;
- // Remember the VkSurfaceKHR's that are created for this VkInstance:
- unordered_map<const void*, SwpSurface*> surfaces;
-
// When vkEnumeratePhysicalDevices is called, the VkPhysicalDevice's are
// remembered:
unordered_map<const void*, SwpPhysicalDevice*> physicalDevices;
#endif // VK_USE_PLATFORM_XLIB_KHR
};
-// 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;
-
- // TODO: Add additional platform-specific info:
-};
-
// Create one of these for each VkPhysicalDevice within a VkInstance:
struct _SwpPhysicalDevice {
// The actual handle for this VkPhysicalDevice:
// 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<void *, SwpSurface> surfaceMap;
std::unordered_map<void *, SwpPhysicalDevice> physicalDeviceMap;
std::unordered_map<void *, SwpDevice> deviceMap;
std::unordered_map<VkSwapchainKHR, SwpSwapchain> swapchainMap;