Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2016 Valve Corporation |
| 3 | * Copyright (c) 2015-2016 LunarG, Inc. |
Ian Elliott | 8f78daa | 2016-01-26 10:51:10 -0700 | [diff] [blame] | 4 | * Copyright (C) 2015-2016 Google Inc. |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 5 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 9 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 11 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 17 | * |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 18 | * Author: Ian Elliott <ian@lunarg.com> |
Ian Elliott | 578e7e2 | 2016-01-05 14:03:16 -0700 | [diff] [blame] | 19 | * Author: Ian Elliott <ianelliott@google.com> |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #ifndef SWAPCHAIN_H |
| 23 | #define SWAPCHAIN_H |
| 24 | |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 25 | #include "vulkan/vk_layer.h" |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 26 | #include "vk_layer_config.h" |
| 27 | #include "vk_layer_logging.h" |
Courtney Goeltzenleuchter | cf60e0a | 2015-10-08 17:07:25 -0600 | [diff] [blame] | 28 | #include <vector> |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 29 | #include <unordered_map> |
Courtney Goeltzenleuchter | cf60e0a | 2015-10-08 17:07:25 -0600 | [diff] [blame] | 30 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 31 | using namespace std; |
| 32 | |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 33 | // Swapchain ERROR codes |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 34 | typedef enum _SWAPCHAIN_ERROR { |
| 35 | SWAPCHAIN_INVALID_HANDLE, // Handle used that isn't currently valid |
| 36 | SWAPCHAIN_NULL_POINTER, // Pointer set to NULL, instead of being a valid pointer |
| 37 | SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, // Did not enable WSI extension, but called WSI function |
| 38 | SWAPCHAIN_DEL_OBJECT_BEFORE_CHILDREN, // Called vkDestroyDevice() before vkDestroySwapchainKHR() |
| 39 | SWAPCHAIN_CREATE_UNSUPPORTED_SURFACE, // Called vkCreateSwapchainKHR() with a pCreateInfo->surface that wasn't seen as supported |
| 40 | // by vkGetPhysicalDeviceSurfaceSupportKHR for the device |
| 41 | SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY, // Called vkCreateSwapchainKHR() without calling a query (e.g. |
| 42 | // vkGetPhysicalDeviceSurfaceCapabilitiesKHR()) |
| 43 | SWAPCHAIN_CREATE_SWAP_BAD_MIN_IMG_COUNT, // Called vkCreateSwapchainKHR() with out-of-bounds minImageCount |
| 44 | SWAPCHAIN_CREATE_SWAP_OUT_OF_BOUNDS_EXTENTS, // Called vkCreateSwapchainKHR() with out-of-bounds imageExtent |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 45 | SWAPCHAIN_CREATE_SWAP_EXTENTS_NO_MATCH_WIN, // Called vkCreateSwapchainKHR() with imageExtent that doesn't match window's extent |
| 46 | SWAPCHAIN_CREATE_SWAP_BAD_PRE_TRANSFORM, // Called vkCreateSwapchainKHR() with a non-supported preTransform |
| 47 | SWAPCHAIN_CREATE_SWAP_BAD_COMPOSITE_ALPHA, // Called vkCreateSwapchainKHR() with a non-supported compositeAlpha |
| 48 | SWAPCHAIN_CREATE_SWAP_BAD_IMG_ARRAY_SIZE, // Called vkCreateSwapchainKHR() with a non-supported imageArraySize |
| 49 | SWAPCHAIN_CREATE_SWAP_BAD_IMG_USAGE_FLAGS, // Called vkCreateSwapchainKHR() with a non-supported imageUsageFlags |
| 50 | SWAPCHAIN_CREATE_SWAP_BAD_IMG_COLOR_SPACE, // Called vkCreateSwapchainKHR() with a non-supported imageColorSpace |
| 51 | SWAPCHAIN_CREATE_SWAP_BAD_IMG_FORMAT, // Called vkCreateSwapchainKHR() with a non-supported imageFormat |
| 52 | SWAPCHAIN_CREATE_SWAP_BAD_IMG_FMT_CLR_SP, // Called vkCreateSwapchainKHR() with a non-supported imageColorSpace |
| 53 | SWAPCHAIN_CREATE_SWAP_BAD_PRESENT_MODE, // Called vkCreateSwapchainKHR() with a non-supported presentMode |
| 54 | SWAPCHAIN_CREATE_SWAP_BAD_SHARING_MODE, // Called vkCreateSwapchainKHR() with a non-supported imageSharingMode |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 55 | SWAPCHAIN_CREATE_SWAP_BAD_SHARING_VALUES, // Called vkCreateSwapchainKHR() with bad values when imageSharingMode is |
| 56 | // VK_SHARING_MODE_CONCURRENT |
| 57 | SWAPCHAIN_CREATE_SWAP_DIFF_SURFACE, // Called vkCreateSwapchainKHR() with pCreateInfo->oldSwapchain that has a different surface |
| 58 | // than pCreateInfo->surface |
| 59 | SWAPCHAIN_DESTROY_SWAP_DIFF_DEVICE, // Called vkDestroySwapchainKHR() with a different VkDevice than vkCreateSwapchainKHR() |
Ian Elliott | 5c68028 | 2016-04-06 14:29:56 -0600 | [diff] [blame] | 60 | SWAPCHAIN_APP_ACQUIRES_TOO_MANY_IMAGES, // vkAcquireNextImageKHR() asked for more images than are available |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 61 | SWAPCHAIN_INDEX_TOO_LARGE, // Index is too large for swapchain |
Ian Elliott | a5d13a9 | 2016-04-07 09:05:45 -0600 | [diff] [blame] | 62 | SWAPCHAIN_INDEX_NOT_IN_USE, // vkQueuePresentKHR() given index that is not acquired by app |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 63 | SWAPCHAIN_BAD_BOOL, // VkBool32 that doesn't have value of VK_TRUE or VK_FALSE (e.g. is a non-zero form of true) |
| 64 | SWAPCHAIN_INVALID_COUNT, // Second time a query called, the pCount value didn't match first time |
| 65 | SWAPCHAIN_WRONG_STYPE, // The sType for a struct has the wrong value |
| 66 | SWAPCHAIN_WRONG_NEXT, // The pNext for a struct is not NULL |
| 67 | SWAPCHAIN_ZERO_VALUE, // A value should be non-zero |
| 68 | SWAPCHAIN_INCOMPATIBLE_ALLOCATOR, // pAllocator must be compatible (i.e. NULL or not) when object is created and destroyed |
| 69 | SWAPCHAIN_DID_NOT_QUERY_QUEUE_FAMILIES, // A function using a queueFamilyIndex was called before |
| 70 | // vkGetPhysicalDeviceQueueFamilyProperties() was called |
| 71 | SWAPCHAIN_QUEUE_FAMILY_INDEX_TOO_LARGE, // A queueFamilyIndex value is not less than pQueueFamilyPropertyCount returned by |
| 72 | // vkGetPhysicalDeviceQueueFamilyProperties() |
| 73 | SWAPCHAIN_SURFACE_NOT_SUPPORTED_WITH_QUEUE, // A surface is not supported by a given queueFamilyIndex, as seen by |
| 74 | // vkGetPhysicalDeviceSurfaceSupportKHR() |
Ian Elliott | fa8f032 | 2016-03-23 08:28:54 -0600 | [diff] [blame] | 75 | SWAPCHAIN_NO_SYNC_FOR_ACQUIRE, // vkAcquireNextImageKHR should be called with a valid semaphore and/or fence |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 76 | } SWAPCHAIN_ERROR; |
| 77 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 78 | // The following is for logging error messages: |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 79 | #define LAYER_NAME (char *) "Swapchain" |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 80 | #define LOG_ERROR_NON_VALID_OBJ(objType, type, obj) \ |
| 81 | (my_data) ? log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (objType), (uint64_t)(obj), __LINE__, \ |
| 82 | SWAPCHAIN_INVALID_HANDLE, LAYER_NAME, "%s() called with a non-valid %s.", __FUNCTION__, (obj)) \ |
| 83 | : VK_FALSE |
| 84 | #define LOG_ERROR_NULL_POINTER(objType, type, obj) \ |
| 85 | (my_data) ? log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (objType), (uint64_t)(obj), 0, \ |
| 86 | SWAPCHAIN_NULL_POINTER, LAYER_NAME, "%s() called with NULL pointer %s.", __FUNCTION__, (obj)) \ |
| 87 | : VK_FALSE |
| 88 | #define LOG_ERROR_INVALID_COUNT(objType, type, obj, obj2, val, val2) \ |
| 89 | (my_data) ? log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (objType), (uint64_t)(obj), 0, \ |
| 90 | SWAPCHAIN_INVALID_COUNT, LAYER_NAME, "%s() called with non-NULL %s, and with %s set to a " \ |
| 91 | "value (%d) that is greater than the value (%d) that " \ |
| 92 | "was returned when %s was NULL.", \ |
| 93 | __FUNCTION__, (obj2), (obj), (val), (val2), (obj2)) \ |
| 94 | : VK_FALSE |
| 95 | #define LOG_ERROR_WRONG_STYPE(objType, type, obj, val) \ |
| 96 | (my_data) ? log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (objType), (uint64_t)(obj), 0, SWAPCHAIN_WRONG_STYPE, \ |
| 97 | LAYER_NAME, "%s() called with the wrong value for %s->sType " \ |
| 98 | "(expected %s).", \ |
| 99 | __FUNCTION__, (obj), (val)) \ |
| 100 | : VK_FALSE |
| 101 | #define LOG_ERROR_ZERO_VALUE(objType, type, obj) \ |
| 102 | (my_data) ? log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (objType), (uint64_t)(obj), 0, SWAPCHAIN_ZERO_VALUE, \ |
| 103 | LAYER_NAME, "%s() called with a zero value for %s.", __FUNCTION__, (obj)) \ |
| 104 | : VK_FALSE |
| 105 | #define LOG_ERROR(objType, type, obj, enm, fmt, ...) \ |
| 106 | (my_data) ? log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (objType), (uint64_t)(obj), __LINE__, (enm), \ |
| 107 | LAYER_NAME, (fmt), __VA_ARGS__) \ |
| 108 | : VK_FALSE |
| 109 | #define LOG_ERROR_QUEUE_FAMILY_INDEX_TOO_LARGE(objType, type, obj, val1, val2) \ |
| 110 | (my_data) ? log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (objType), (uint64_t)(obj), 0, \ |
| 111 | SWAPCHAIN_QUEUE_FAMILY_INDEX_TOO_LARGE, LAYER_NAME, "%s() called with a queueFamilyIndex that is too " \ |
| 112 | "large (i.e. %d). The maximum value (returned " \ |
| 113 | "by vkGetPhysicalDeviceQueueFamilyProperties) is " \ |
| 114 | "only %d.\n", \ |
| 115 | __FUNCTION__, (val1), (val2)) \ |
| 116 | : VK_FALSE |
| 117 | #define LOG_PERF_WARNING(objType, type, obj, enm, fmt, ...) \ |
| 118 | (my_data) ? log_msg(my_data->report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, (objType), (uint64_t)(obj), __LINE__, \ |
| 119 | (enm), LAYER_NAME, (fmt), __VA_ARGS__) \ |
| 120 | : VK_FALSE |
Ian Elliott | fa8f032 | 2016-03-23 08:28:54 -0600 | [diff] [blame] | 121 | #define LOG_WARNING(objType, type, obj, enm, fmt, ...) \ |
| 122 | (my_data) ? log_msg(my_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (objType), (uint64_t)(obj), __LINE__, (enm), \ |
| 123 | LAYER_NAME, (fmt), __VA_ARGS__) \ |
| 124 | : VK_FALSE |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 125 | #define LOG_INFO_WRONG_NEXT(objType, type, obj) \ |
| 126 | (my_data) ? log_msg(my_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, (objType), (uint64_t)(obj), 0, \ |
| 127 | SWAPCHAIN_WRONG_NEXT, LAYER_NAME, "%s() called with non-NULL value for %s->pNext.", __FUNCTION__, (obj)) \ |
| 128 | : VK_FALSE |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 129 | |
| 130 | // NOTE: The following struct's/typedef's are for keeping track of |
| 131 | // info that is used for validating the WSI extensions. |
| 132 | |
| 133 | // Forward declarations: |
| 134 | struct _SwpInstance; |
Ian Elliott | 1f6bb80 | 2016-01-20 16:33:34 -0700 | [diff] [blame] | 135 | struct _SwpSurface; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 136 | struct _SwpPhysicalDevice; |
| 137 | struct _SwpDevice; |
| 138 | struct _SwpSwapchain; |
| 139 | struct _SwpImage; |
Ian Elliott | c4db695 | 2016-01-21 14:29:45 -0700 | [diff] [blame] | 140 | struct _SwpQueue; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 141 | |
| 142 | typedef _SwpInstance SwpInstance; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 143 | typedef _SwpSurface SwpSurface; |
| 144 | ; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 145 | typedef _SwpPhysicalDevice SwpPhysicalDevice; |
| 146 | typedef _SwpDevice SwpDevice; |
| 147 | typedef _SwpSwapchain SwpSwapchain; |
| 148 | typedef _SwpImage SwpImage; |
Ian Elliott | c4db695 | 2016-01-21 14:29:45 -0700 | [diff] [blame] | 149 | typedef _SwpQueue SwpQueue; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 150 | |
| 151 | // Create one of these for each VkInstance: |
| 152 | struct _SwpInstance { |
| 153 | // The actual handle for this VkInstance: |
| 154 | VkInstance instance; |
| 155 | |
Ian Elliott | 1f6bb80 | 2016-01-20 16:33:34 -0700 | [diff] [blame] | 156 | // Remember the VkSurfaceKHR's that are created for this VkInstance: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 157 | unordered_map<VkSurfaceKHR, SwpSurface *> surfaces; |
Ian Elliott | 1f6bb80 | 2016-01-20 16:33:34 -0700 | [diff] [blame] | 158 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 159 | // When vkEnumeratePhysicalDevices is called, the VkPhysicalDevice's are |
| 160 | // remembered: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 161 | unordered_map<const void *, SwpPhysicalDevice *> physicalDevices; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 162 | |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 163 | // Set to true if VK_KHR_SURFACE_EXTENSION_NAME was enabled for this VkInstance: |
Ian Elliott | 1cb77a6 | 2015-12-29 16:44:39 -0700 | [diff] [blame] | 164 | bool surfaceExtensionEnabled; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 165 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 166 | // TODO: Add additional booleans for platform-specific extensions: |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 167 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 168 | // Set to true if VK_KHR_ANDROID_SURFACE_EXTENSION_NAME was enabled for this VkInstance: |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 169 | bool androidSurfaceExtensionEnabled; |
| 170 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 171 | #ifdef VK_USE_PLATFORM_MIR_KHR |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 172 | // Set to true if VK_KHR_MIR_SURFACE_EXTENSION_NAME was enabled for this VkInstance: |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 173 | bool mirSurfaceExtensionEnabled; |
| 174 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 175 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 176 | // Set to true if VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME was enabled for this VkInstance: |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 177 | bool waylandSurfaceExtensionEnabled; |
| 178 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 179 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 180 | // Set to true if VK_KHR_WIN32_SURFACE_EXTENSION_NAME was enabled for this VkInstance: |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 181 | bool win32SurfaceExtensionEnabled; |
| 182 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 183 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 184 | // Set to true if VK_KHR_XCB_SURFACE_EXTENSION_NAME was enabled for this VkInstance: |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 185 | bool xcbSurfaceExtensionEnabled; |
| 186 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 187 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 188 | // Set to true if VK_KHR_XLIB_SURFACE_EXTENSION_NAME was enabled for this VkInstance: |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 189 | bool xlibSurfaceExtensionEnabled; |
| 190 | #endif // VK_USE_PLATFORM_XLIB_KHR |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 191 | }; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 192 | |
Ian Elliott | 1f6bb80 | 2016-01-20 16:33:34 -0700 | [diff] [blame] | 193 | // Create one of these for each VkSurfaceKHR: |
| 194 | struct _SwpSurface { |
| 195 | // The actual handle for this VkSurfaceKHR: |
| 196 | VkSurfaceKHR surface; |
| 197 | |
| 198 | // VkInstance that this VkSurfaceKHR is associated with: |
| 199 | SwpInstance *pInstance; |
| 200 | |
| 201 | // When vkCreateSwapchainKHR is called, the VkSwapchainKHR's are |
| 202 | // remembered: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 203 | unordered_map<VkSwapchainKHR, SwpSwapchain *> swapchains; |
Ian Elliott | 680825b | 2016-01-21 12:42:19 -0700 | [diff] [blame] | 204 | |
| 205 | // 'true' if pAllocator was non-NULL when vkCreate*SurfaceKHR was called: |
| 206 | bool usedAllocatorToCreate; |
Ian Elliott | c4db695 | 2016-01-21 14:29:45 -0700 | [diff] [blame] | 207 | |
| 208 | // Value of pQueueFamilyPropertyCount that was returned by the |
| 209 | // vkGetPhysicalDeviceQueueFamilyProperties() function: |
| 210 | uint32_t numQueueFamilyIndexSupport; |
| 211 | // Array of VkBool32's that is intialized by the |
| 212 | // vkGetPhysicalDeviceSurfaceSupportKHR() function. First call for a given |
| 213 | // surface allocates and initializes this array to false for all |
| 214 | // queueFamilyIndex's (and sets numQueueFamilyIndexSupport to non-zero). |
| 215 | // All calls set the entry for a given queueFamilyIndex: |
| 216 | VkBool32 *pQueueFamilyIndexSupport; |
Ian Elliott | 1f6bb80 | 2016-01-20 16:33:34 -0700 | [diff] [blame] | 217 | }; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 218 | |
| 219 | // Create one of these for each VkPhysicalDevice within a VkInstance: |
| 220 | struct _SwpPhysicalDevice { |
| 221 | // The actual handle for this VkPhysicalDevice: |
| 222 | VkPhysicalDevice physicalDevice; |
| 223 | |
| 224 | // Corresponding VkDevice (and info) to this VkPhysicalDevice: |
| 225 | SwpDevice *pDevice; |
| 226 | |
| 227 | // VkInstance that this VkPhysicalDevice is associated with: |
| 228 | SwpInstance *pInstance; |
| 229 | |
Ian Elliott | aeafe23 | 2016-01-20 10:50:33 -0700 | [diff] [blame] | 230 | // Records results of vkGetPhysicalDeviceQueueFamilyProperties()'s |
Ian Elliott | c4db695 | 2016-01-21 14:29:45 -0700 | [diff] [blame] | 231 | // numOfQueueFamilies parameter when pQueueFamilyProperties is NULL: |
Ian Elliott | aeafe23 | 2016-01-20 10:50:33 -0700 | [diff] [blame] | 232 | bool gotQueueFamilyPropertyCount; |
Ian Elliott | c4db695 | 2016-01-21 14:29:45 -0700 | [diff] [blame] | 233 | uint32_t numOfQueueFamilies; |
Ian Elliott | aeafe23 | 2016-01-20 10:50:33 -0700 | [diff] [blame] | 234 | |
Ian Elliott | c4db695 | 2016-01-21 14:29:45 -0700 | [diff] [blame] | 235 | // Record all surfaces that vkGetPhysicalDeviceSurfaceSupportKHR() was |
| 236 | // called for: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 237 | unordered_map<VkSurfaceKHR, SwpSurface *> supportedSurfaces; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 238 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 239 | // TODO: Record/use this info per-surface, not per-device, once a |
| 240 | // non-dispatchable surface object is added to WSI: |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 241 | // Results of vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 242 | bool gotSurfaceCapabilities; |
| 243 | VkSurfaceCapabilitiesKHR surfaceCapabilities; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 244 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 245 | // TODO: Record/use this info per-surface, not per-device, once a |
| 246 | // non-dispatchable surface object is added to WSI: |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 247 | // Count and VkSurfaceFormatKHR's returned by vkGetPhysicalDeviceSurfaceFormatsKHR(): |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 248 | uint32_t surfaceFormatCount; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 249 | VkSurfaceFormatKHR *pSurfaceFormats; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 250 | |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 251 | // TODO: Record/use this info per-surface, not per-device, once a |
| 252 | // non-dispatchable surface object is added to WSI: |
Mark Lobodzinski | 1ed594e | 2016-02-03 09:57:14 -0700 | [diff] [blame] | 253 | // Count and VkPresentModeKHR's returned by vkGetPhysicalDeviceSurfacePresentModesKHR(): |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 254 | uint32_t presentModeCount; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 255 | VkPresentModeKHR *pPresentModes; |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 256 | }; |
| 257 | |
| 258 | // Create one of these for each VkDevice within a VkInstance: |
| 259 | struct _SwpDevice { |
| 260 | // The actual handle for this VkDevice: |
| 261 | VkDevice device; |
| 262 | |
| 263 | // Corresponding VkPhysicalDevice (and info) to this VkDevice: |
| 264 | SwpPhysicalDevice *pPhysicalDevice; |
| 265 | |
| 266 | // Set to true if VK_KHR_SWAPCHAIN_EXTENSION_NAME was enabled: |
Ian Elliott | 427058f | 2015-12-29 16:45:49 -0700 | [diff] [blame] | 267 | bool swapchainExtensionEnabled; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 268 | |
| 269 | // When vkCreateSwapchainKHR is called, the VkSwapchainKHR's are |
| 270 | // remembered: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 271 | unordered_map<VkSwapchainKHR, SwpSwapchain *> swapchains; |
Ian Elliott | c4db695 | 2016-01-21 14:29:45 -0700 | [diff] [blame] | 272 | |
| 273 | // When vkGetDeviceQueue is called, the VkQueue's are remembered: |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 274 | unordered_map<VkQueue, SwpQueue *> queues; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 275 | }; |
| 276 | |
| 277 | // Create one of these for each VkImage within a VkSwapchainKHR: |
| 278 | struct _SwpImage { |
| 279 | // The actual handle for this VkImage: |
| 280 | VkImage image; |
| 281 | |
| 282 | // Corresponding VkSwapchainKHR (and info) to this VkImage: |
| 283 | SwpSwapchain *pSwapchain; |
| 284 | |
Ian Elliott | a5d13a9 | 2016-04-07 09:05:45 -0600 | [diff] [blame] | 285 | // true if application acquired this image from vkAcquireNextImageKHR(), |
| 286 | // and hasn't yet called vkQueuePresentKHR() for it; otherwise false: |
| 287 | bool acquiredByApp; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 288 | }; |
| 289 | |
| 290 | // Create one of these for each VkSwapchainKHR within a VkDevice: |
| 291 | struct _SwpSwapchain { |
| 292 | // The actual handle for this VkSwapchainKHR: |
| 293 | VkSwapchainKHR swapchain; |
| 294 | |
| 295 | // Corresponding VkDevice (and info) to this VkSwapchainKHR: |
| 296 | SwpDevice *pDevice; |
| 297 | |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 298 | // Corresponding VkSurfaceKHR to this VkSwapchainKHR: |
Ian Elliott | 1f6bb80 | 2016-01-20 16:33:34 -0700 | [diff] [blame] | 299 | SwpSurface *pSurface; |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 300 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 301 | // When vkGetSwapchainImagesKHR is called, the VkImage's are |
| 302 | // remembered: |
| 303 | uint32_t imageCount; |
| 304 | unordered_map<int, SwpImage> images; |
Ian Elliott | 680825b | 2016-01-21 12:42:19 -0700 | [diff] [blame] | 305 | |
| 306 | // 'true' if pAllocator was non-NULL when vkCreateSwapchainKHR was called: |
| 307 | bool usedAllocatorToCreate; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 308 | }; |
| 309 | |
Ian Elliott | c4db695 | 2016-01-21 14:29:45 -0700 | [diff] [blame] | 310 | // Create one of these for each VkQueue within a VkDevice: |
| 311 | struct _SwpQueue { |
| 312 | // The actual handle for this VkQueue: |
| 313 | VkQueue queue; |
| 314 | |
| 315 | // Corresponding VkDevice (and info) to this VkSwapchainKHR: |
| 316 | SwpDevice *pDevice; |
| 317 | |
| 318 | // Which queueFamilyIndex this VkQueue is associated with: |
| 319 | uint32_t queueFamilyIndex; |
| 320 | }; |
| 321 | |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 322 | struct layer_data { |
| 323 | debug_report_data *report_data; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 324 | std::vector<VkDebugReportCallbackEXT> logging_callback; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 325 | VkLayerDispatchTable *device_dispatch_table; |
| 326 | VkLayerInstanceDispatchTable *instance_dispatch_table; |
Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 327 | |
| 328 | // The following are for keeping track of the temporary callbacks that can |
| 329 | // be used in vkCreateInstance and vkDestroyInstance: |
| 330 | uint32_t num_tmp_callbacks; |
| 331 | VkDebugReportCallbackCreateInfoEXT *tmp_dbg_create_infos; |
| 332 | VkDebugReportCallbackEXT *tmp_callbacks; |
| 333 | |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 334 | // NOTE: The following are for keeping track of info that is used for |
| 335 | // validating the WSI extensions. |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 336 | std::unordered_map<void *, SwpInstance> instanceMap; |
| 337 | std::unordered_map<VkSurfaceKHR, SwpSurface> surfaceMap; |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 338 | std::unordered_map<void *, SwpPhysicalDevice> physicalDeviceMap; |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 339 | std::unordered_map<void *, SwpDevice> deviceMap; |
| 340 | std::unordered_map<VkSwapchainKHR, SwpSwapchain> swapchainMap; |
| 341 | std::unordered_map<void *, SwpQueue> queueMap; |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 342 | |
Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 343 | layer_data() |
| 344 | : report_data(nullptr), device_dispatch_table(nullptr), instance_dispatch_table(nullptr), num_tmp_callbacks(0), |
| 345 | tmp_dbg_create_infos(nullptr), tmp_callbacks(nullptr){}; |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 346 | }; |
| 347 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 348 | #endif // SWAPCHAIN_H |