Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 1 | /* |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 2 | * |
Courtney Goeltzenleuchter | fcbe16f | 2015-10-29 13:50:34 -0600 | [diff] [blame] | 3 | * Copyright (C) 2015 Valve Corporation |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 4 | * Copyright (C) 2015 Google Inc. |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | * |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 24 | * Author: Ian Elliott <ian@lunarg.com> |
Ian Elliott | 578e7e2 | 2016-01-05 14:03:16 -0700 | [diff] [blame] | 25 | * Author: Ian Elliott <ianelliott@google.com> |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #ifndef SWAPCHAIN_H |
| 29 | #define SWAPCHAIN_H |
| 30 | |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 31 | #include "vulkan/vk_layer.h" |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 32 | #include "vulkan/vk_ext_debug_report.h" |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 33 | #include "vk_layer_config.h" |
| 34 | #include "vk_layer_logging.h" |
Courtney Goeltzenleuchter | cf60e0a | 2015-10-08 17:07:25 -0600 | [diff] [blame] | 35 | #include <vector> |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 36 | #include <unordered_map> |
Courtney Goeltzenleuchter | cf60e0a | 2015-10-08 17:07:25 -0600 | [diff] [blame] | 37 | |
Ian Elliott | d8c5db1 | 2015-10-07 11:32:31 -0600 | [diff] [blame] | 38 | static const VkLayerProperties globalLayerProps[] = { |
| 39 | { |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 40 | "VK_LAYER_LUNARG_swapchain", |
Ian Elliott | d8c5db1 | 2015-10-07 11:32:31 -0600 | [diff] [blame] | 41 | VK_API_VERSION, // specVersion |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 42 | VK_MAKE_VERSION(0, 1, 0), // implementationVersion |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 43 | "layer: swapchain", |
Ian Elliott | d8c5db1 | 2015-10-07 11:32:31 -0600 | [diff] [blame] | 44 | } |
| 45 | }; |
| 46 | |
| 47 | static const VkLayerProperties deviceLayerProps[] = { |
| 48 | { |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 49 | "VK_LAYER_LUNARG_swapchain", |
Ian Elliott | d8c5db1 | 2015-10-07 11:32:31 -0600 | [diff] [blame] | 50 | VK_API_VERSION, // specVersion |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 51 | VK_MAKE_VERSION(0, 1, 0), // implementationVersion |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 52 | "layer: swapchain", |
Ian Elliott | d8c5db1 | 2015-10-07 11:32:31 -0600 | [diff] [blame] | 53 | } |
| 54 | }; |
| 55 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 56 | |
| 57 | using namespace std; |
| 58 | |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 59 | |
| 60 | // Swapchain ERROR codes |
| 61 | typedef enum _SWAPCHAIN_ERROR |
| 62 | { |
| 63 | SWAPCHAIN_INVALID_HANDLE, // Handle used that isn't currently valid |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 64 | SWAPCHAIN_NULL_POINTER, // Pointer set to NULL, instead of being a valid pointer |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 65 | SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, // Did not enable WSI extension, but called WSI function |
Ian Elliott | 80b3b14 | 2016-01-21 12:57:20 -0700 | [diff] [blame^] | 66 | SWAPCHAIN_DEL_OBJECT_BEFORE_CHILDREN, // Called vkDestroyDevice() before vkDestroySwapchainKHR() |
Ian Elliott | 4f147fc | 2016-01-20 08:52:08 -0700 | [diff] [blame] | 67 | SWAPCHAIN_CREATE_UNSUPPORTED_SURFACE, // Called vkCreateSwapchainKHR() with a pCreateInfo->surface that wasn't seen as supported by vkGetPhysicalDeviceSurfaceSupportKHR for the device |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 68 | SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY, // Called vkCreateSwapchainKHR() without calling a query (e.g. vkGetPhysicalDeviceSurfaceCapabilitiesKHR()) |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 69 | SWAPCHAIN_CREATE_SWAP_BAD_MIN_IMG_COUNT, // Called vkCreateSwapchainKHR() with out-of-bounds minImageCount |
| 70 | SWAPCHAIN_CREATE_SWAP_OUT_OF_BOUNDS_EXTENTS,// Called vkCreateSwapchainKHR() with out-of-bounds imageExtent |
| 71 | SWAPCHAIN_CREATE_SWAP_EXTENTS_NO_MATCH_WIN, // Called vkCreateSwapchainKHR() with imageExtent that doesn't match window's extent |
| 72 | SWAPCHAIN_CREATE_SWAP_BAD_PRE_TRANSFORM, // Called vkCreateSwapchainKHR() with a non-supported preTransform |
Ian Elliott | a2a89c5 | 2015-12-28 15:23:57 -0700 | [diff] [blame] | 73 | SWAPCHAIN_CREATE_SWAP_BAD_COMPOSITE_ALPHA, // Called vkCreateSwapchainKHR() with a non-supported compositeAlpha |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 74 | SWAPCHAIN_CREATE_SWAP_BAD_IMG_ARRAY_SIZE, // Called vkCreateSwapchainKHR() with a non-supported imageArraySize |
| 75 | SWAPCHAIN_CREATE_SWAP_BAD_IMG_USAGE_FLAGS, // Called vkCreateSwapchainKHR() with a non-supported imageUsageFlags |
| 76 | SWAPCHAIN_CREATE_SWAP_BAD_IMG_COLOR_SPACE, // Called vkCreateSwapchainKHR() with a non-supported imageColorSpace |
| 77 | SWAPCHAIN_CREATE_SWAP_BAD_IMG_FORMAT, // Called vkCreateSwapchainKHR() with a non-supported imageFormat |
| 78 | SWAPCHAIN_CREATE_SWAP_BAD_IMG_FMT_CLR_SP, // Called vkCreateSwapchainKHR() with a non-supported imageColorSpace |
| 79 | SWAPCHAIN_CREATE_SWAP_BAD_PRESENT_MODE, // Called vkCreateSwapchainKHR() with a non-supported presentMode |
Ian Elliott | a2a89c5 | 2015-12-28 15:23:57 -0700 | [diff] [blame] | 80 | SWAPCHAIN_CREATE_SWAP_BAD_SHARING_MODE, // Called vkCreateSwapchainKHR() with a non-supported imageSharingMode |
| 81 | SWAPCHAIN_CREATE_SWAP_BAD_SHARING_VALUES, // Called vkCreateSwapchainKHR() with bad values when imageSharingMode is VK_SHARING_MODE_CONCURRENT |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 82 | SWAPCHAIN_CREATE_SWAP_DIFF_SURFACE, // Called vkCreateSwapchainKHR() with pCreateInfo->oldSwapchain that has a different surface than pCreateInfo->surface |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 83 | SWAPCHAIN_DESTROY_SWAP_DIFF_DEVICE, // Called vkDestroySwapchainKHR() with a different VkDevice than vkCreateSwapchainKHR() |
| 84 | SWAPCHAIN_APP_OWNS_TOO_MANY_IMAGES, // vkAcquireNextImageKHR() asked for more images than are available |
| 85 | SWAPCHAIN_INDEX_TOO_LARGE, // Index is too large for swapchain |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 86 | SWAPCHAIN_INDEX_NOT_IN_USE, // vkQueuePresentKHR() given index that is not owned by app |
Ian Elliott | a2a89c5 | 2015-12-28 15:23:57 -0700 | [diff] [blame] | 87 | SWAPCHAIN_BAD_BOOL, // VkBool32 that doesn't have value of VK_TRUE or VK_FALSE (e.g. is a non-zero form of true) |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 88 | SWAPCHAIN_INVALID_COUNT, // Second time a query called, the pCount value didn't match first time |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 89 | SWAPCHAIN_WRONG_STYPE, // The sType for a struct has the wrong value |
| 90 | SWAPCHAIN_WRONG_NEXT, // The pNext for a struct is not NULL |
Ian Elliott | 046ed2c | 2015-12-30 17:07:17 -0700 | [diff] [blame] | 91 | SWAPCHAIN_ZERO_VALUE, // A value should be non-zero |
Ian Elliott | aeafe23 | 2016-01-20 10:50:33 -0700 | [diff] [blame] | 92 | SWAPCHAIN_QUEUE_FAMILY_INDEX_TOO_LARGE, // A queueFamilyIndex value is not less than pQueueFamilyPropertyCount returned by vkGetPhysicalDeviceQueueFamilyProperties() |
Ian Elliott | 680825b | 2016-01-21 12:42:19 -0700 | [diff] [blame] | 93 | SWAPCHAIN_INCOMPATIBLE_ALLOCATOR, // pAllocator must be compatible (i.e. NULL or not) when object is created and destroyed |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 94 | } SWAPCHAIN_ERROR; |
| 95 | |
| 96 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 97 | // The following is for logging error messages: |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 98 | #define LAYER_NAME (char *) "Swapchain" |
| 99 | #define LOG_ERROR_NON_VALID_OBJ(objType, type, obj) \ |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 100 | (my_data) ? \ |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 101 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (objType), \ |
Mark Lobodzinski | 80e774f | 2016-01-04 15:54:59 -0700 | [diff] [blame] | 102 | (uint64_t) (obj), __LINE__, SWAPCHAIN_INVALID_HANDLE, LAYER_NAME, \ |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 103 | "%s() called with a non-valid %s.", __FUNCTION__, (obj)) \ |
| 104 | : VK_FALSE |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 105 | #define LOG_ERROR_NULL_POINTER(objType, type, obj) \ |
| 106 | (my_data) ? \ |
| 107 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (objType), \ |
| 108 | (uint64_t) (obj), 0, SWAPCHAIN_NULL_POINTER, LAYER_NAME, \ |
| 109 | "%s() called with NULL pointer %s.", __FUNCTION__, (obj)) \ |
| 110 | : VK_FALSE |
Ian Elliott | dcf8eca | 2016-01-05 14:28:32 -0700 | [diff] [blame] | 111 | #define LOG_ERROR_INVALID_COUNT(objType, type, obj, obj2, val, val2) \ |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 112 | (my_data) ? \ |
| 113 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (objType), \ |
| 114 | (uint64_t) (obj), 0, SWAPCHAIN_INVALID_COUNT, LAYER_NAME, \ |
Ian Elliott | dcf8eca | 2016-01-05 14:28:32 -0700 | [diff] [blame] | 115 | "%s() called with non-NULL %s, and with %s set to a " \ |
| 116 | "value (%d) that is greater than the value (%d) that " \ |
| 117 | "was returned when %s was NULL.", \ |
| 118 | __FUNCTION__, (obj2), (obj), (val), (val2), (obj2)) \ |
Ian Elliott | f955d68 | 2015-12-30 12:00:54 -0700 | [diff] [blame] | 119 | : VK_FALSE |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 120 | #define LOG_ERROR_WRONG_STYPE(objType, type, obj, val) \ |
| 121 | (my_data) ? \ |
| 122 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (objType), \ |
| 123 | (uint64_t) (obj), 0, SWAPCHAIN_WRONG_STYPE, LAYER_NAME, \ |
| 124 | "%s() called with the wrong value for %s->sType " \ |
| 125 | "(expected %s).", \ |
| 126 | __FUNCTION__, (obj), (val)) \ |
| 127 | : VK_FALSE |
Ian Elliott | 046ed2c | 2015-12-30 17:07:17 -0700 | [diff] [blame] | 128 | #define LOG_ERROR_ZERO_VALUE(objType, type, obj) \ |
| 129 | (my_data) ? \ |
| 130 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (objType), \ |
| 131 | (uint64_t) (obj), 0, SWAPCHAIN_ZERO_VALUE, LAYER_NAME, \ |
| 132 | "%s() called with a zero value for %s.", \ |
| 133 | __FUNCTION__, (obj)) \ |
| 134 | : VK_FALSE |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 135 | #define LOG_ERROR(objType, type, obj, enm, fmt, ...) \ |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 136 | (my_data) ? \ |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 137 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (objType), \ |
Mark Lobodzinski | 80e774f | 2016-01-04 15:54:59 -0700 | [diff] [blame] | 138 | (uint64_t) (obj), __LINE__, (enm), LAYER_NAME, (fmt), __VA_ARGS__) \ |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 139 | : VK_FALSE |
Ian Elliott | aeafe23 | 2016-01-20 10:50:33 -0700 | [diff] [blame] | 140 | #define LOG_ERROR_QUEUE_FAMILY_INDEX_TOO_LARGE(objType, type, obj, val1, val2) \ |
| 141 | (my_data) ? \ |
| 142 | log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (objType), \ |
| 143 | (uint64_t) (obj), 0, SWAPCHAIN_QUEUE_FAMILY_INDEX_TOO_LARGE, LAYER_NAME, \ |
| 144 | "%s() called with a queueFamilyIndex that is too " \ |
| 145 | "large (i.e. %d). The maximum value (returned " \ |
| 146 | "by vkGetPhysicalDeviceQueueFamilyProperties) is " \ |
| 147 | "only %d.\n", \ |
| 148 | __FUNCTION__, (val1), (val2)) \ |
| 149 | : VK_FALSE |
Ian Elliott | b0f474c | 2015-09-25 15:50:55 -0600 | [diff] [blame] | 150 | #define LOG_PERF_WARNING(objType, type, obj, enm, fmt, ...) \ |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 151 | (my_data) ? \ |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 152 | log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (objType), \ |
Mark Lobodzinski | 80e774f | 2016-01-04 15:54:59 -0700 | [diff] [blame] | 153 | (uint64_t) (obj), __LINE__, (enm), LAYER_NAME, (fmt), __VA_ARGS__) \ |
Ian Elliott | 68124ac | 2015-10-07 16:18:35 -0600 | [diff] [blame] | 154 | : VK_FALSE |
Ian Elliott | 31edb92 | 2016-01-05 14:41:45 -0700 | [diff] [blame] | 155 | #define LOG_INFO_WRONG_NEXT(objType, type, obj) \ |
| 156 | (my_data) ? \ |
| 157 | log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (objType), \ |
| 158 | (uint64_t) (obj), 0, SWAPCHAIN_WRONG_NEXT, LAYER_NAME, \ |
| 159 | "%s() called with non-NULL value for %s->pNext.", \ |
| 160 | __FUNCTION__, (obj)) \ |
| 161 | : VK_FALSE |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 162 | |
| 163 | |
| 164 | // NOTE: The following struct's/typedef's are for keeping track of |
| 165 | // info that is used for validating the WSI extensions. |
| 166 | |
| 167 | // Forward declarations: |
| 168 | struct _SwpInstance; |
Ian Elliott | 1f6bb80 | 2016-01-20 16:33:34 -0700 | [diff] [blame] | 169 | struct _SwpSurface; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 170 | struct _SwpPhysicalDevice; |
| 171 | struct _SwpDevice; |
| 172 | struct _SwpSwapchain; |
| 173 | struct _SwpImage; |
| 174 | |
| 175 | typedef _SwpInstance SwpInstance; |
Ian Elliott | 1f6bb80 | 2016-01-20 16:33:34 -0700 | [diff] [blame] | 176 | typedef _SwpSurface SwpSurface;; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 177 | typedef _SwpPhysicalDevice SwpPhysicalDevice; |
| 178 | typedef _SwpDevice SwpDevice; |
| 179 | typedef _SwpSwapchain SwpSwapchain; |
| 180 | typedef _SwpImage SwpImage; |
| 181 | |
| 182 | // Create one of these for each VkInstance: |
| 183 | struct _SwpInstance { |
| 184 | // The actual handle for this VkInstance: |
| 185 | VkInstance instance; |
| 186 | |
Ian Elliott | 1f6bb80 | 2016-01-20 16:33:34 -0700 | [diff] [blame] | 187 | // Remember the VkSurfaceKHR's that are created for this VkInstance: |
| 188 | unordered_map<const void*, SwpSurface*> surfaces; |
| 189 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 190 | // When vkEnumeratePhysicalDevices is called, the VkPhysicalDevice's are |
| 191 | // remembered: |
| 192 | unordered_map<const void*, SwpPhysicalDevice*> physicalDevices; |
| 193 | |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 194 | // 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] | 195 | bool surfaceExtensionEnabled; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 196 | |
| 197 | // TODO: Add additional booleans for platform-specific extensions: |
Ian Elliott | 8dffaf3 | 2016-01-04 14:10:30 -0700 | [diff] [blame] | 198 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 199 | // Set to true if VK_KHR_ANDROID_SURFACE_EXTENSION_NAME was enabled for this VkInstance: |
| 200 | bool androidSurfaceExtensionEnabled; |
| 201 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 202 | #ifdef VK_USE_PLATFORM_MIR_KHR |
| 203 | // Set to true if VK_KHR_MIR_SURFACE_EXTENSION_NAME was enabled for this VkInstance: |
| 204 | bool mirSurfaceExtensionEnabled; |
| 205 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 206 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
| 207 | // Set to true if VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME was enabled for this VkInstance: |
| 208 | bool waylandSurfaceExtensionEnabled; |
| 209 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 210 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 211 | // Set to true if VK_KHR_WIN32_SURFACE_EXTENSION_NAME was enabled for this VkInstance: |
| 212 | bool win32SurfaceExtensionEnabled; |
| 213 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 214 | #ifdef VK_USE_PLATFORM_XCB_KHR |
| 215 | // Set to true if VK_KHR_XCB_SURFACE_EXTENSION_NAME was enabled for this VkInstance: |
| 216 | bool xcbSurfaceExtensionEnabled; |
| 217 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 218 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
| 219 | // Set to true if VK_KHR_XLIB_SURFACE_EXTENSION_NAME was enabled for this VkInstance: |
| 220 | bool xlibSurfaceExtensionEnabled; |
| 221 | #endif // VK_USE_PLATFORM_XLIB_KHR |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 222 | }; |
Ian Elliott | 1f6bb80 | 2016-01-20 16:33:34 -0700 | [diff] [blame] | 223 | |
| 224 | // Create one of these for each VkSurfaceKHR: |
| 225 | struct _SwpSurface { |
| 226 | // The actual handle for this VkSurfaceKHR: |
| 227 | VkSurfaceKHR surface; |
| 228 | |
| 229 | // VkInstance that this VkSurfaceKHR is associated with: |
| 230 | SwpInstance *pInstance; |
| 231 | |
| 232 | // When vkCreateSwapchainKHR is called, the VkSwapchainKHR's are |
| 233 | // remembered: |
| 234 | unordered_map<VkSwapchainKHR, SwpSwapchain*> swapchains; |
Ian Elliott | 680825b | 2016-01-21 12:42:19 -0700 | [diff] [blame] | 235 | |
| 236 | // 'true' if pAllocator was non-NULL when vkCreate*SurfaceKHR was called: |
| 237 | bool usedAllocatorToCreate; |
Ian Elliott | 1f6bb80 | 2016-01-20 16:33:34 -0700 | [diff] [blame] | 238 | }; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 239 | |
| 240 | // Create one of these for each VkPhysicalDevice within a VkInstance: |
| 241 | struct _SwpPhysicalDevice { |
| 242 | // The actual handle for this VkPhysicalDevice: |
| 243 | VkPhysicalDevice physicalDevice; |
| 244 | |
| 245 | // Corresponding VkDevice (and info) to this VkPhysicalDevice: |
| 246 | SwpDevice *pDevice; |
| 247 | |
| 248 | // VkInstance that this VkPhysicalDevice is associated with: |
| 249 | SwpInstance *pInstance; |
| 250 | |
Ian Elliott | aeafe23 | 2016-01-20 10:50:33 -0700 | [diff] [blame] | 251 | // Records results of vkGetPhysicalDeviceQueueFamilyProperties()'s |
| 252 | // pQueueFamilyPropertyCount parameter when pQueueFamilyProperties is NULL: |
| 253 | bool gotQueueFamilyPropertyCount; |
| 254 | uint32_t pQueueFamilyPropertyCount; |
| 255 | |
Ian Elliott | 4f147fc | 2016-01-20 08:52:08 -0700 | [diff] [blame] | 256 | // Record all supported queueFamilyIndex-surface pairs that support |
| 257 | // presenting with WSI swapchains: |
| 258 | unordered_map<uint32_t, VkSurfaceKHR> queueFamilyIndexSupport; |
| 259 | |
| 260 | // Record all supported surface-queueFamilyIndex pairs that support |
| 261 | // presenting with WSI swapchains: |
| 262 | unordered_map<VkSurfaceKHR, uint32_t> surfaceSupport; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 263 | |
| 264 | // TODO: Record/use this info per-surface, not per-device, once a |
| 265 | // non-dispatchable surface object is added to WSI: |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 266 | // Results of vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 267 | bool gotSurfaceCapabilities; |
| 268 | VkSurfaceCapabilitiesKHR surfaceCapabilities; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 269 | |
| 270 | // TODO: Record/use this info per-surface, not per-device, once a |
| 271 | // non-dispatchable surface object is added to WSI: |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 272 | // Count and VkSurfaceFormatKHR's returned by vkGetPhysicalDeviceSurfaceFormatsKHR(): |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 273 | uint32_t surfaceFormatCount; |
| 274 | VkSurfaceFormatKHR* pSurfaceFormats; |
| 275 | |
| 276 | // TODO: Record/use this info per-surface, not per-device, once a |
| 277 | // non-dispatchable surface object is added to WSI: |
Ian Elliott | 1dcd109 | 2015-11-17 17:29:40 -0700 | [diff] [blame] | 278 | // Count and VkPresentModeKHR's returned by vkGetPhysicalDeviceSurfacePresentModesKHR(): |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 279 | uint32_t presentModeCount; |
| 280 | VkPresentModeKHR* pPresentModes; |
Ian Elliott | 27d39c7 | 2015-11-20 16:39:34 -0700 | [diff] [blame] | 281 | }; |
| 282 | |
| 283 | // Create one of these for each VkDevice within a VkInstance: |
| 284 | struct _SwpDevice { |
| 285 | // The actual handle for this VkDevice: |
| 286 | VkDevice device; |
| 287 | |
| 288 | // Corresponding VkPhysicalDevice (and info) to this VkDevice: |
| 289 | SwpPhysicalDevice *pPhysicalDevice; |
| 290 | |
| 291 | // Set to true if VK_KHR_SWAPCHAIN_EXTENSION_NAME was enabled: |
Ian Elliott | 427058f | 2015-12-29 16:45:49 -0700 | [diff] [blame] | 292 | bool swapchainExtensionEnabled; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 293 | |
| 294 | // When vkCreateSwapchainKHR is called, the VkSwapchainKHR's are |
| 295 | // remembered: |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 296 | unordered_map<VkSwapchainKHR, SwpSwapchain*> swapchains; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 297 | }; |
| 298 | |
| 299 | // Create one of these for each VkImage within a VkSwapchainKHR: |
| 300 | struct _SwpImage { |
| 301 | // The actual handle for this VkImage: |
| 302 | VkImage image; |
| 303 | |
| 304 | // Corresponding VkSwapchainKHR (and info) to this VkImage: |
| 305 | SwpSwapchain *pSwapchain; |
| 306 | |
| 307 | // true if application got this image from vkAcquireNextImageKHR(), and |
| 308 | // hasn't yet called vkQueuePresentKHR() for it; otherwise false: |
| 309 | bool ownedByApp; |
| 310 | }; |
| 311 | |
| 312 | // Create one of these for each VkSwapchainKHR within a VkDevice: |
| 313 | struct _SwpSwapchain { |
| 314 | // The actual handle for this VkSwapchainKHR: |
| 315 | VkSwapchainKHR swapchain; |
| 316 | |
| 317 | // Corresponding VkDevice (and info) to this VkSwapchainKHR: |
| 318 | SwpDevice *pDevice; |
| 319 | |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 320 | // Corresponding VkSurfaceKHR to this VkSwapchainKHR: |
Ian Elliott | 1f6bb80 | 2016-01-20 16:33:34 -0700 | [diff] [blame] | 321 | SwpSurface *pSurface; |
Ian Elliott | f7f8ff0 | 2015-12-30 14:55:41 -0700 | [diff] [blame] | 322 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 323 | // When vkGetSwapchainImagesKHR is called, the VkImage's are |
| 324 | // remembered: |
| 325 | uint32_t imageCount; |
| 326 | unordered_map<int, SwpImage> images; |
Ian Elliott | 680825b | 2016-01-21 12:42:19 -0700 | [diff] [blame] | 327 | |
| 328 | // 'true' if pAllocator was non-NULL when vkCreateSwapchainKHR was called: |
| 329 | bool usedAllocatorToCreate; |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 330 | }; |
| 331 | |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 332 | struct layer_data { |
| 333 | debug_report_data *report_data; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 334 | std::vector<VkDebugReportCallbackEXT> logging_callback; |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 335 | VkLayerDispatchTable* device_dispatch_table; |
| 336 | VkLayerInstanceDispatchTable* instance_dispatch_table; |
| 337 | // NOTE: The following are for keeping track of info that is used for |
| 338 | // validating the WSI extensions. |
| 339 | std::unordered_map<void *, SwpInstance> instanceMap; |
Ian Elliott | 1f6bb80 | 2016-01-20 16:33:34 -0700 | [diff] [blame] | 340 | std::unordered_map<void *, SwpSurface> surfaceMap; |
Tobin Ehlis | 711ff31 | 2015-10-29 12:58:13 -0600 | [diff] [blame] | 341 | std::unordered_map<void *, SwpPhysicalDevice> physicalDeviceMap; |
| 342 | std::unordered_map<void *, SwpDevice> deviceMap; |
| 343 | std::unordered_map<VkSwapchainKHR, SwpSwapchain> swapchainMap; |
| 344 | |
| 345 | layer_data() : |
| 346 | report_data(nullptr), |
| 347 | device_dispatch_table(nullptr), |
| 348 | instance_dispatch_table(nullptr) |
| 349 | {}; |
| 350 | }; |
| 351 | |
Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 352 | #endif // SWAPCHAIN_H |