blob: 6fc3819a3738a5da91a99cd4975d6cd6a96ac8ef [file] [log] [blame]
Ian Elliott0b4d6242015-09-22 10:51:24 -06001/*
Ian Elliott0b4d6242015-09-22 10:51:24 -06002 *
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Michael Lentine03107b42015-12-11 10:49:51 -08004 * Copyright (C) 2015 Google Inc.
Ian Elliott0b4d6242015-09-22 10:51:24 -06005 *
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 Goeltzenleuchter05559522015-10-30 11:14:30 -060024 * Author: Ian Elliott <ian@lunarg.com>
Ian Elliott578e7e22016-01-05 14:03:16 -070025 * Author: Ian Elliott <ianelliott@google.com>
Ian Elliott0b4d6242015-09-22 10:51:24 -060026 */
27
28#ifndef SWAPCHAIN_H
29#define SWAPCHAIN_H
30
David Pinedo9316d3b2015-11-06 12:54:48 -070031#include "vulkan/vk_layer.h"
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070032#include "vulkan/vk_ext_debug_report.h"
Tobin Ehlis711ff312015-10-29 12:58:13 -060033#include "vk_layer_config.h"
34#include "vk_layer_logging.h"
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -060035#include <vector>
Tobin Ehlis711ff312015-10-29 12:58:13 -060036#include <unordered_map>
Courtney Goeltzenleuchtercf60e0a2015-10-08 17:07:25 -060037
Ian Elliottd8c5db12015-10-07 11:32:31 -060038static const VkLayerProperties globalLayerProps[] = {
39 {
Michael Lentine03107b42015-12-11 10:49:51 -080040 "VK_LAYER_LUNARG_swapchain",
Ian Elliottd8c5db12015-10-07 11:32:31 -060041 VK_API_VERSION, // specVersion
Chia-I Wu3432a0c2015-10-27 18:04:07 +080042 VK_MAKE_VERSION(0, 1, 0), // implementationVersion
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -070043 "layer: swapchain",
Ian Elliottd8c5db12015-10-07 11:32:31 -060044 }
45};
46
47static const VkLayerProperties deviceLayerProps[] = {
48 {
Michael Lentine03107b42015-12-11 10:49:51 -080049 "VK_LAYER_LUNARG_swapchain",
Ian Elliottd8c5db12015-10-07 11:32:31 -060050 VK_API_VERSION, // specVersion
Chia-I Wu3432a0c2015-10-27 18:04:07 +080051 VK_MAKE_VERSION(0, 1, 0), // implementationVersion
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -070052 "layer: swapchain",
Ian Elliottd8c5db12015-10-07 11:32:31 -060053 }
54};
55
Ian Elliott0b4d6242015-09-22 10:51:24 -060056
57using namespace std;
58
Ian Elliottb0f474c2015-09-25 15:50:55 -060059
60// Swapchain ERROR codes
61typedef enum _SWAPCHAIN_ERROR
62{
63 SWAPCHAIN_INVALID_HANDLE, // Handle used that isn't currently valid
Ian Elliottf955d682015-12-30 12:00:54 -070064 SWAPCHAIN_NULL_POINTER, // Pointer set to NULL, instead of being a valid pointer
Ian Elliottb0f474c2015-09-25 15:50:55 -060065 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, // Did not enable WSI extension, but called WSI function
Ian Elliott80b3b142016-01-21 12:57:20 -070066 SWAPCHAIN_DEL_OBJECT_BEFORE_CHILDREN, // Called vkDestroyDevice() before vkDestroySwapchainKHR()
Ian Elliott4f147fc2016-01-20 08:52:08 -070067 SWAPCHAIN_CREATE_UNSUPPORTED_SURFACE, // Called vkCreateSwapchainKHR() with a pCreateInfo->surface that wasn't seen as supported by vkGetPhysicalDeviceSurfaceSupportKHR for the device
Ian Elliott1dcd1092015-11-17 17:29:40 -070068 SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY, // Called vkCreateSwapchainKHR() without calling a query (e.g. vkGetPhysicalDeviceSurfaceCapabilitiesKHR())
Ian Elliottb0f474c2015-09-25 15:50:55 -060069 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 Elliotta2a89c52015-12-28 15:23:57 -070073 SWAPCHAIN_CREATE_SWAP_BAD_COMPOSITE_ALPHA, // Called vkCreateSwapchainKHR() with a non-supported compositeAlpha
Ian Elliottb0f474c2015-09-25 15:50:55 -060074 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 Elliotta2a89c52015-12-28 15:23:57 -070080 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 Elliottf7f8ff02015-12-30 14:55:41 -070082 SWAPCHAIN_CREATE_SWAP_DIFF_SURFACE, // Called vkCreateSwapchainKHR() with pCreateInfo->oldSwapchain that has a different surface than pCreateInfo->surface
Ian Elliottb0f474c2015-09-25 15:50:55 -060083 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 Elliottb0f474c2015-09-25 15:50:55 -060086 SWAPCHAIN_INDEX_NOT_IN_USE, // vkQueuePresentKHR() given index that is not owned by app
Ian Elliotta2a89c52015-12-28 15:23:57 -070087 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 Elliottf955d682015-12-30 12:00:54 -070088 SWAPCHAIN_INVALID_COUNT, // Second time a query called, the pCount value didn't match first time
Ian Elliottf7f8ff02015-12-30 14:55:41 -070089 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 Elliott046ed2c2015-12-30 17:07:17 -070091 SWAPCHAIN_ZERO_VALUE, // A value should be non-zero
Ian Elliottaeafe232016-01-20 10:50:33 -070092 SWAPCHAIN_QUEUE_FAMILY_INDEX_TOO_LARGE, // A queueFamilyIndex value is not less than pQueueFamilyPropertyCount returned by vkGetPhysicalDeviceQueueFamilyProperties()
Ian Elliott680825b2016-01-21 12:42:19 -070093 SWAPCHAIN_INCOMPATIBLE_ALLOCATOR, // pAllocator must be compatible (i.e. NULL or not) when object is created and destroyed
Ian Elliottb0f474c2015-09-25 15:50:55 -060094} SWAPCHAIN_ERROR;
95
96
Ian Elliott0b4d6242015-09-22 10:51:24 -060097// The following is for logging error messages:
Ian Elliott0b4d6242015-09-22 10:51:24 -060098#define LAYER_NAME (char *) "Swapchain"
99#define LOG_ERROR_NON_VALID_OBJ(objType, type, obj) \
Ian Elliott68124ac2015-10-07 16:18:35 -0600100 (my_data) ? \
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700101 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (objType), \
Mark Lobodzinski80e774f2016-01-04 15:54:59 -0700102 (uint64_t) (obj), __LINE__, SWAPCHAIN_INVALID_HANDLE, LAYER_NAME, \
Ian Elliott68124ac2015-10-07 16:18:35 -0600103 "%s() called with a non-valid %s.", __FUNCTION__, (obj)) \
104 : VK_FALSE
Ian Elliottf955d682015-12-30 12:00:54 -0700105#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 Elliottdcf8eca2016-01-05 14:28:32 -0700111#define LOG_ERROR_INVALID_COUNT(objType, type, obj, obj2, val, val2) \
Ian Elliottf955d682015-12-30 12:00:54 -0700112 (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 Elliottdcf8eca2016-01-05 14:28:32 -0700115 "%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 Elliottf955d682015-12-30 12:00:54 -0700119 : VK_FALSE
Ian Elliottf7f8ff02015-12-30 14:55:41 -0700120#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 Elliott046ed2c2015-12-30 17:07:17 -0700128#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 Elliottb0f474c2015-09-25 15:50:55 -0600135#define LOG_ERROR(objType, type, obj, enm, fmt, ...) \
Ian Elliott68124ac2015-10-07 16:18:35 -0600136 (my_data) ? \
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700137 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (objType), \
Mark Lobodzinski80e774f2016-01-04 15:54:59 -0700138 (uint64_t) (obj), __LINE__, (enm), LAYER_NAME, (fmt), __VA_ARGS__) \
Ian Elliott68124ac2015-10-07 16:18:35 -0600139 : VK_FALSE
Ian Elliottaeafe232016-01-20 10:50:33 -0700140#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 Elliottb0f474c2015-09-25 15:50:55 -0600150#define LOG_PERF_WARNING(objType, type, obj, enm, fmt, ...) \
Ian Elliott68124ac2015-10-07 16:18:35 -0600151 (my_data) ? \
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700152 log_msg(my_data->report_data, VK_DEBUG_REPORT_PERF_WARN_BIT_EXT, (objType), \
Mark Lobodzinski80e774f2016-01-04 15:54:59 -0700153 (uint64_t) (obj), __LINE__, (enm), LAYER_NAME, (fmt), __VA_ARGS__) \
Ian Elliott68124ac2015-10-07 16:18:35 -0600154 : VK_FALSE
Ian Elliott31edb922016-01-05 14:41:45 -0700155#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 Elliott0b4d6242015-09-22 10:51:24 -0600162
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:
168struct _SwpInstance;
Ian Elliott1f6bb802016-01-20 16:33:34 -0700169struct _SwpSurface;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600170struct _SwpPhysicalDevice;
171struct _SwpDevice;
172struct _SwpSwapchain;
173struct _SwpImage;
174
175typedef _SwpInstance SwpInstance;
Ian Elliott1f6bb802016-01-20 16:33:34 -0700176typedef _SwpSurface SwpSurface;;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600177typedef _SwpPhysicalDevice SwpPhysicalDevice;
178typedef _SwpDevice SwpDevice;
179typedef _SwpSwapchain SwpSwapchain;
180typedef _SwpImage SwpImage;
181
182// Create one of these for each VkInstance:
183struct _SwpInstance {
184 // The actual handle for this VkInstance:
185 VkInstance instance;
186
Ian Elliott1f6bb802016-01-20 16:33:34 -0700187 // Remember the VkSurfaceKHR's that are created for this VkInstance:
188 unordered_map<const void*, SwpSurface*> surfaces;
189
Ian Elliott0b4d6242015-09-22 10:51:24 -0600190 // When vkEnumeratePhysicalDevices is called, the VkPhysicalDevice's are
191 // remembered:
192 unordered_map<const void*, SwpPhysicalDevice*> physicalDevices;
193
Ian Elliott1dcd1092015-11-17 17:29:40 -0700194 // Set to true if VK_KHR_SURFACE_EXTENSION_NAME was enabled for this VkInstance:
Ian Elliott1cb77a62015-12-29 16:44:39 -0700195 bool surfaceExtensionEnabled;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600196
197 // TODO: Add additional booleans for platform-specific extensions:
Ian Elliott8dffaf32016-01-04 14:10:30 -0700198#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 Elliott0b4d6242015-09-22 10:51:24 -0600222};
Ian Elliott1f6bb802016-01-20 16:33:34 -0700223
224// Create one of these for each VkSurfaceKHR:
225struct _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 Elliott680825b2016-01-21 12:42:19 -0700235
236 // 'true' if pAllocator was non-NULL when vkCreate*SurfaceKHR was called:
237 bool usedAllocatorToCreate;
Ian Elliott1f6bb802016-01-20 16:33:34 -0700238};
Ian Elliott0b4d6242015-09-22 10:51:24 -0600239
240// Create one of these for each VkPhysicalDevice within a VkInstance:
241struct _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 Elliottaeafe232016-01-20 10:50:33 -0700251 // Records results of vkGetPhysicalDeviceQueueFamilyProperties()'s
252 // pQueueFamilyPropertyCount parameter when pQueueFamilyProperties is NULL:
253 bool gotQueueFamilyPropertyCount;
254 uint32_t pQueueFamilyPropertyCount;
255
Ian Elliott4f147fc2016-01-20 08:52:08 -0700256 // 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 Elliott0b4d6242015-09-22 10:51:24 -0600263
264// TODO: Record/use this info per-surface, not per-device, once a
265// non-dispatchable surface object is added to WSI:
Ian Elliott1dcd1092015-11-17 17:29:40 -0700266 // Results of vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
Ian Elliott27d39c72015-11-20 16:39:34 -0700267 bool gotSurfaceCapabilities;
268 VkSurfaceCapabilitiesKHR surfaceCapabilities;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600269
270// TODO: Record/use this info per-surface, not per-device, once a
271// non-dispatchable surface object is added to WSI:
Ian Elliott1dcd1092015-11-17 17:29:40 -0700272 // Count and VkSurfaceFormatKHR's returned by vkGetPhysicalDeviceSurfaceFormatsKHR():
Ian Elliott0b4d6242015-09-22 10:51:24 -0600273 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 Elliott1dcd1092015-11-17 17:29:40 -0700278 // Count and VkPresentModeKHR's returned by vkGetPhysicalDeviceSurfacePresentModesKHR():
Ian Elliott0b4d6242015-09-22 10:51:24 -0600279 uint32_t presentModeCount;
280 VkPresentModeKHR* pPresentModes;
Ian Elliott27d39c72015-11-20 16:39:34 -0700281};
282
283// Create one of these for each VkDevice within a VkInstance:
284struct _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 Elliott427058f2015-12-29 16:45:49 -0700292 bool swapchainExtensionEnabled;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600293
294 // When vkCreateSwapchainKHR is called, the VkSwapchainKHR's are
295 // remembered:
Chia-I Wue2fc5522015-10-26 20:04:44 +0800296 unordered_map<VkSwapchainKHR, SwpSwapchain*> swapchains;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600297};
298
299// Create one of these for each VkImage within a VkSwapchainKHR:
300struct _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:
313struct _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 Elliottf7f8ff02015-12-30 14:55:41 -0700320 // Corresponding VkSurfaceKHR to this VkSwapchainKHR:
Ian Elliott1f6bb802016-01-20 16:33:34 -0700321 SwpSurface *pSurface;
Ian Elliottf7f8ff02015-12-30 14:55:41 -0700322
Ian Elliott0b4d6242015-09-22 10:51:24 -0600323 // When vkGetSwapchainImagesKHR is called, the VkImage's are
324 // remembered:
325 uint32_t imageCount;
326 unordered_map<int, SwpImage> images;
Ian Elliott680825b2016-01-21 12:42:19 -0700327
328 // 'true' if pAllocator was non-NULL when vkCreateSwapchainKHR was called:
329 bool usedAllocatorToCreate;
Ian Elliott0b4d6242015-09-22 10:51:24 -0600330};
331
Tobin Ehlis711ff312015-10-29 12:58:13 -0600332struct layer_data {
333 debug_report_data *report_data;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700334 std::vector<VkDebugReportCallbackEXT> logging_callback;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600335 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 Elliott1f6bb802016-01-20 16:33:34 -0700340 std::unordered_map<void *, SwpSurface> surfaceMap;
Tobin Ehlis711ff312015-10-29 12:58:13 -0600341 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 Elliott0b4d6242015-09-22 10:51:24 -0600352#endif // SWAPCHAIN_H