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