blob: 24774c1ce7753e96324c0c9891ac3fc60b772e29 [file] [log] [blame]
Ian Elliott329da012015-09-22 10:51:24 -06001/*
2 * Vulkan
3 *
4 * Copyright (C) 2015 LunarG, Inc.
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 *
24 * Authors:
25 * Ian Elliott <ian@lunarg.com>
26 */
27
28#ifndef SWAPCHAIN_H
29#define SWAPCHAIN_H
30
Ian Elliotte75a4b52015-10-07 11:32:31 -060031static const VkLayerProperties globalLayerProps[] = {
32 {
33 "Swapchain",
34 VK_API_VERSION, // specVersion
35 VK_MAKE_VERSION(0, 1, 0), // implVersion
36 "layer: Swapchain",
37 }
38};
39
40static const VkLayerProperties deviceLayerProps[] = {
41 {
42 "Swapchain",
43 VK_API_VERSION, // specVersion
44 VK_MAKE_VERSION(0, 1, 0), // implVersion
45 "layer: Swapchain",
46 }
47};
48
Ian Elliott329da012015-09-22 10:51:24 -060049
50using namespace std;
51
Ian Elliottf81c2562015-09-25 15:50:55 -060052
53// Swapchain ERROR codes
54typedef enum _SWAPCHAIN_ERROR
55{
56 SWAPCHAIN_INVALID_HANDLE, // Handle used that isn't currently valid
57 SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED, // Did not enable WSI extension, but called WSI function
58 SWAPCHAIN_DEL_DEVICE_BEFORE_SWAPCHAINS, // Called vkDestroyDevice() before vkDestroySwapchainKHR()
59 SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY, // Called vkCreateSwapchainKHR() without calling a query (e.g. vkGetSurfacePropertiesKHR())
60 SWAPCHAIN_CREATE_SWAP_BAD_MIN_IMG_COUNT, // Called vkCreateSwapchainKHR() with out-of-bounds minImageCount
61 SWAPCHAIN_CREATE_SWAP_OUT_OF_BOUNDS_EXTENTS,// Called vkCreateSwapchainKHR() with out-of-bounds imageExtent
62 SWAPCHAIN_CREATE_SWAP_EXTENTS_NO_MATCH_WIN, // Called vkCreateSwapchainKHR() with imageExtent that doesn't match window's extent
63 SWAPCHAIN_CREATE_SWAP_BAD_PRE_TRANSFORM, // Called vkCreateSwapchainKHR() with a non-supported preTransform
64 SWAPCHAIN_CREATE_SWAP_BAD_IMG_ARRAY_SIZE, // Called vkCreateSwapchainKHR() with a non-supported imageArraySize
65 SWAPCHAIN_CREATE_SWAP_BAD_IMG_USAGE_FLAGS, // Called vkCreateSwapchainKHR() with a non-supported imageUsageFlags
66 SWAPCHAIN_CREATE_SWAP_BAD_IMG_COLOR_SPACE, // Called vkCreateSwapchainKHR() with a non-supported imageColorSpace
67 SWAPCHAIN_CREATE_SWAP_BAD_IMG_FORMAT, // Called vkCreateSwapchainKHR() with a non-supported imageFormat
68 SWAPCHAIN_CREATE_SWAP_BAD_IMG_FMT_CLR_SP, // Called vkCreateSwapchainKHR() with a non-supported imageColorSpace
69 SWAPCHAIN_CREATE_SWAP_BAD_PRESENT_MODE, // Called vkCreateSwapchainKHR() with a non-supported presentMode
70 SWAPCHAIN_DESTROY_SWAP_DIFF_DEVICE, // Called vkDestroySwapchainKHR() with a different VkDevice than vkCreateSwapchainKHR()
71 SWAPCHAIN_APP_OWNS_TOO_MANY_IMAGES, // vkAcquireNextImageKHR() asked for more images than are available
72 SWAPCHAIN_INDEX_TOO_LARGE, // Index is too large for swapchain
Ian Elliottf81c2562015-09-25 15:50:55 -060073 SWAPCHAIN_INDEX_NOT_IN_USE, // vkQueuePresentKHR() given index that is not owned by app
74} SWAPCHAIN_ERROR;
75
76
Ian Elliott329da012015-09-22 10:51:24 -060077// The following is for logging error messages:
Cody Northrop73bb6572015-09-28 15:09:32 -060078struct layer_data {
79 debug_report_data *report_data;
Ian Elliott329da012015-09-22 10:51:24 -060080 VkDbgMsgCallback logging_callback;
Cody Northrop73bb6572015-09-28 15:09:32 -060081
82 layer_data() :
83 report_data(nullptr),
84 logging_callback(nullptr)
85 {};
86};
87
Ian Elliott329da012015-09-22 10:51:24 -060088#define LAYER_NAME (char *) "Swapchain"
89#define LOG_ERROR_NON_VALID_OBJ(objType, type, obj) \
Cody Northrop73bb6572015-09-28 15:09:32 -060090 log_msg(mydata.report_data, VK_DBG_REPORT_ERROR_BIT, (objType), \
Ian Elliottf81c2562015-09-25 15:50:55 -060091 (uint64_t) (obj), 0, SWAPCHAIN_INVALID_HANDLE, LAYER_NAME, \
Ian Elliott329da012015-09-22 10:51:24 -060092 "%s() called with a non-valid %s.", __FUNCTION__, (obj))
93
Ian Elliottf81c2562015-09-25 15:50:55 -060094#define LOG_ERROR(objType, type, obj, enm, fmt, ...) \
Cody Northrop73bb6572015-09-28 15:09:32 -060095 log_msg(mydata.report_data, VK_DBG_REPORT_ERROR_BIT, (objType), \
Ian Elliottf81c2562015-09-25 15:50:55 -060096 (uint64_t) (obj), 0, (enm), LAYER_NAME, (fmt), __VA_ARGS__)
97#define LOG_PERF_WARNING(objType, type, obj, enm, fmt, ...) \
Cody Northrop73bb6572015-09-28 15:09:32 -060098 log_msg(mydata.report_data, VK_DBG_REPORT_PERF_WARN_BIT, (objType), \
Ian Elliottf81c2562015-09-25 15:50:55 -060099 (uint64_t) (obj), 0, (enm), LAYER_NAME, (fmt), __VA_ARGS__)
Ian Elliott329da012015-09-22 10:51:24 -0600100
101
102// NOTE: The following struct's/typedef's are for keeping track of
103// info that is used for validating the WSI extensions.
104
105// Forward declarations:
106struct _SwpInstance;
107struct _SwpPhysicalDevice;
108struct _SwpDevice;
109struct _SwpSwapchain;
110struct _SwpImage;
111
112typedef _SwpInstance SwpInstance;
113typedef _SwpPhysicalDevice SwpPhysicalDevice;
114typedef _SwpDevice SwpDevice;
115typedef _SwpSwapchain SwpSwapchain;
116typedef _SwpImage SwpImage;
117
118// Create one of these for each VkInstance:
119struct _SwpInstance {
120 // The actual handle for this VkInstance:
121 VkInstance instance;
122
123 // When vkEnumeratePhysicalDevices is called, the VkPhysicalDevice's are
124 // remembered:
125 unordered_map<const void*, SwpPhysicalDevice*> physicalDevices;
126
127 // Set to true if "VK_EXT_KHR_swapchain" was enabled for this VkInstance:
128 bool swapchainExtensionEnabled;
129
130 // TODO: Add additional booleans for platform-specific extensions:
131};
132
133// Create one of these for each VkPhysicalDevice within a VkInstance:
134struct _SwpPhysicalDevice {
135 // The actual handle for this VkPhysicalDevice:
136 VkPhysicalDevice physicalDevice;
137
138 // Corresponding VkDevice (and info) to this VkPhysicalDevice:
139 SwpDevice *pDevice;
140
141 // VkInstance that this VkPhysicalDevice is associated with:
142 SwpInstance *pInstance;
143
144 // Which queueFamilyIndices support presenting with WSI swapchains:
145 unordered_map<uint32_t, VkBool32> queueFamilyIndexSupport;
146};
147
148// Create one of these for each VkDevice within a VkInstance:
149struct _SwpDevice {
150 // The actual handle for this VkDevice:
151 VkDevice device;
152
153 // Corresponding VkPhysicalDevice (and info) to this VkDevice:
154 SwpPhysicalDevice *pPhysicalDevice;
155
156 // Set to true if "VK_EXT_KHR_device_swapchain" was enabled:
157 bool deviceSwapchainExtensionEnabled;
158
159// TODO: Record/use this info per-surface, not per-device, once a
160// non-dispatchable surface object is added to WSI:
161 // Results of vkGetSurfacePropertiesKHR():
162 bool gotSurfaceProperties;
163 VkSurfacePropertiesKHR surfaceProperties;
164
165// TODO: Record/use this info per-surface, not per-device, once a
166// non-dispatchable surface object is added to WSI:
167 // Count and VkSurfaceFormatKHR's returned by vkGetSurfaceFormatsKHR():
168 uint32_t surfaceFormatCount;
169 VkSurfaceFormatKHR* pSurfaceFormats;
170
171// TODO: Record/use this info per-surface, not per-device, once a
172// non-dispatchable surface object is added to WSI:
173 // Count and VkPresentModeKHR's returned by vkGetSurfacePresentModesKHR():
174 uint32_t presentModeCount;
175 VkPresentModeKHR* pPresentModes;
176
177 // When vkCreateSwapchainKHR is called, the VkSwapchainKHR's are
178 // remembered:
179 unordered_map<uint64_t, SwpSwapchain*> swapchains;
180};
181
182// Create one of these for each VkImage within a VkSwapchainKHR:
183struct _SwpImage {
184 // The actual handle for this VkImage:
185 VkImage image;
186
187 // Corresponding VkSwapchainKHR (and info) to this VkImage:
188 SwpSwapchain *pSwapchain;
189
190 // true if application got this image from vkAcquireNextImageKHR(), and
191 // hasn't yet called vkQueuePresentKHR() for it; otherwise false:
192 bool ownedByApp;
193};
194
195// Create one of these for each VkSwapchainKHR within a VkDevice:
196struct _SwpSwapchain {
197 // The actual handle for this VkSwapchainKHR:
198 VkSwapchainKHR swapchain;
199
200 // Corresponding VkDevice (and info) to this VkSwapchainKHR:
201 SwpDevice *pDevice;
202
203 // When vkGetSwapchainImagesKHR is called, the VkImage's are
204 // remembered:
205 uint32_t imageCount;
206 unordered_map<int, SwpImage> images;
207};
208
209#endif // SWAPCHAIN_H