blob: 80a6ea462f45edf3a355c9ec3516dd5c28219195 [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) \
Ian Elliott960df282015-10-07 16:18:35 -060090 (my_data) ? \
91 log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (objType), \
92 (uint64_t) (obj), 0, SWAPCHAIN_INVALID_HANDLE, LAYER_NAME, \
93 "%s() called with a non-valid %s.", __FUNCTION__, (obj)) \
94 : VK_FALSE
Ian Elliott329da012015-09-22 10:51:24 -060095
Ian Elliottf81c2562015-09-25 15:50:55 -060096#define LOG_ERROR(objType, type, obj, enm, fmt, ...) \
Ian Elliott960df282015-10-07 16:18:35 -060097 (my_data) ? \
98 log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (objType), \
99 (uint64_t) (obj), 0, (enm), LAYER_NAME, (fmt), __VA_ARGS__) \
100 : VK_FALSE
Ian Elliottf81c2562015-09-25 15:50:55 -0600101#define LOG_PERF_WARNING(objType, type, obj, enm, fmt, ...) \
Ian Elliott960df282015-10-07 16:18:35 -0600102 (my_data) ? \
103 log_msg(my_data->report_data, VK_DBG_REPORT_PERF_WARN_BIT, (objType), \
104 (uint64_t) (obj), 0, (enm), LAYER_NAME, (fmt), __VA_ARGS__) \
105 : VK_FALSE
Ian Elliott329da012015-09-22 10:51:24 -0600106
107
108// NOTE: The following struct's/typedef's are for keeping track of
109// info that is used for validating the WSI extensions.
110
111// Forward declarations:
112struct _SwpInstance;
113struct _SwpPhysicalDevice;
114struct _SwpDevice;
115struct _SwpSwapchain;
116struct _SwpImage;
117
118typedef _SwpInstance SwpInstance;
119typedef _SwpPhysicalDevice SwpPhysicalDevice;
120typedef _SwpDevice SwpDevice;
121typedef _SwpSwapchain SwpSwapchain;
122typedef _SwpImage SwpImage;
123
124// Create one of these for each VkInstance:
125struct _SwpInstance {
126 // The actual handle for this VkInstance:
127 VkInstance instance;
128
129 // When vkEnumeratePhysicalDevices is called, the VkPhysicalDevice's are
130 // remembered:
131 unordered_map<const void*, SwpPhysicalDevice*> physicalDevices;
132
133 // Set to true if "VK_EXT_KHR_swapchain" was enabled for this VkInstance:
134 bool swapchainExtensionEnabled;
135
136 // TODO: Add additional booleans for platform-specific extensions:
137};
138
139// Create one of these for each VkPhysicalDevice within a VkInstance:
140struct _SwpPhysicalDevice {
141 // The actual handle for this VkPhysicalDevice:
142 VkPhysicalDevice physicalDevice;
143
144 // Corresponding VkDevice (and info) to this VkPhysicalDevice:
145 SwpDevice *pDevice;
146
147 // VkInstance that this VkPhysicalDevice is associated with:
148 SwpInstance *pInstance;
149
150 // Which queueFamilyIndices support presenting with WSI swapchains:
151 unordered_map<uint32_t, VkBool32> queueFamilyIndexSupport;
152};
153
154// Create one of these for each VkDevice within a VkInstance:
155struct _SwpDevice {
156 // The actual handle for this VkDevice:
157 VkDevice device;
158
159 // Corresponding VkPhysicalDevice (and info) to this VkDevice:
160 SwpPhysicalDevice *pPhysicalDevice;
161
162 // Set to true if "VK_EXT_KHR_device_swapchain" was enabled:
163 bool deviceSwapchainExtensionEnabled;
164
165// TODO: Record/use this info per-surface, not per-device, once a
166// non-dispatchable surface object is added to WSI:
167 // Results of vkGetSurfacePropertiesKHR():
168 bool gotSurfaceProperties;
169 VkSurfacePropertiesKHR surfaceProperties;
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 VkSurfaceFormatKHR's returned by vkGetSurfaceFormatsKHR():
174 uint32_t surfaceFormatCount;
175 VkSurfaceFormatKHR* pSurfaceFormats;
176
177// TODO: Record/use this info per-surface, not per-device, once a
178// non-dispatchable surface object is added to WSI:
179 // Count and VkPresentModeKHR's returned by vkGetSurfacePresentModesKHR():
180 uint32_t presentModeCount;
181 VkPresentModeKHR* pPresentModes;
182
183 // When vkCreateSwapchainKHR is called, the VkSwapchainKHR's are
184 // remembered:
185 unordered_map<uint64_t, SwpSwapchain*> swapchains;
186};
187
188// Create one of these for each VkImage within a VkSwapchainKHR:
189struct _SwpImage {
190 // The actual handle for this VkImage:
191 VkImage image;
192
193 // Corresponding VkSwapchainKHR (and info) to this VkImage:
194 SwpSwapchain *pSwapchain;
195
196 // true if application got this image from vkAcquireNextImageKHR(), and
197 // hasn't yet called vkQueuePresentKHR() for it; otherwise false:
198 bool ownedByApp;
199};
200
201// Create one of these for each VkSwapchainKHR within a VkDevice:
202struct _SwpSwapchain {
203 // The actual handle for this VkSwapchainKHR:
204 VkSwapchainKHR swapchain;
205
206 // Corresponding VkDevice (and info) to this VkSwapchainKHR:
207 SwpDevice *pDevice;
208
209 // When vkGetSwapchainImagesKHR is called, the VkImage's are
210 // remembered:
211 uint32_t imageCount;
212 unordered_map<int, SwpImage> images;
213};
214
215#endif // SWAPCHAIN_H