blob: ddb5534748cb745df8c861867902cbd128e3852b [file] [log] [blame]
Chia-I Wu46c29dd2014-12-02 21:09:20 +08001/*
Karl Schultz481756e2016-02-02 15:37:51 -07002 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Chia-I Wu46c29dd2014-12-02 21:09:20 +08005 *
Jon Ashburn43b53e82016-04-19 11:30:31 -06006 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
Chia-I Wu46c29dd2014-12-02 21:09:20 +08009 *
Jon Ashburn43b53e82016-04-19 11:30:31 -060010 * http://www.apache.org/licenses/LICENSE-2.0
Chia-I Wu46c29dd2014-12-02 21:09:20 +080011 *
Jon Ashburn43b53e82016-04-19 11:30:31 -060012 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
Courtney Goeltzenleuchter96cd7952015-10-30 11:14:30 -060017 *
18 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
19 * Author: David Pinedo <david@lunarg.com>
20 * Author: Mark Lobodzinski <mark@lunarg.com>
Rene Lindsaya155d622016-06-10 08:26:26 -070021 * Author: Rene Lindsay <rene@lunarg.com>
Chia-I Wu46c29dd2014-12-02 21:09:20 +080022 */
Chia-I Wu46c29dd2014-12-02 21:09:20 +080023#include <assert.h>
Mark Lobodzinski825cc512015-08-14 10:30:30 -060024#include <inttypes.h>
Rene Lindsay7fb1e012016-06-10 15:33:08 -070025#include <stdbool.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
Chia-I Wud4bae362014-07-29 11:15:00 +080029
Ian Elliottea95f5c2015-04-17 21:23:34 -060030#ifdef _WIN32
David Pinedo18fb9232015-04-21 14:45:16 -060031#include <fcntl.h>
32#include <io.h>
Ian Elliottb5fad792015-11-20 11:55:46 -070033#endif // _WIN32
Ian Elliott64070a82015-11-17 17:29:40 -070034
Mun Gwan-gyeong787b6272016-08-20 14:46:22 +090035#if defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_XCB_KHR)
Rene Lindsaya155d622016-06-10 08:26:26 -070036#include <X11/Xutil.h>
37#endif
38
Tony Barbour03941912016-12-07 14:45:12 -070039#if defined(VK_USE_PLATFORM_MIR_KHR)
40#warning "Vulkaninfo does not have code for Mir at this time"
41#endif
42
David Pinedo329ca9e2015-11-06 12:54:48 -070043#include <vulkan/vulkan.h>
Chia-I Wu46c29dd2014-12-02 21:09:20 +080044
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -070045#define ERR(err) printf("%s:%d: failed with %s\n", __FILE__, __LINE__, VkResultString(err));
Chia-I Wu46c29dd2014-12-02 21:09:20 +080046
David Pinedo18fb9232015-04-21 14:45:16 -060047#ifdef _WIN32
48
Ian Elliott7c83aa22015-07-08 17:09:54 -060049#define snprintf _snprintf
50
Hugo Landaua3b71702016-02-16 15:44:03 +000051// Returns nonzero if the console is used only for this process. Will return
52// zero if another process (such as cmd.exe) is also attached.
53static int ConsoleIsExclusive(void) {
54 DWORD pids[2];
55 DWORD num_pids = GetConsoleProcessList(pids, ARRAYSIZE(pids));
56 return num_pids <= 1;
57}
David Pinedo18fb9232015-04-21 14:45:16 -060058
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -070059#define WAIT_FOR_CONSOLE_DESTROY \
60 do { \
61 if (ConsoleIsExclusive()) \
62 Sleep(INFINITE); \
David Pinedo18fb9232015-04-21 14:45:16 -060063 } while (0)
64#else
Karl Schultz481756e2016-02-02 15:37:51 -070065#define WAIT_FOR_CONSOLE_DESTROY
David Pinedo18fb9232015-04-21 14:45:16 -060066#endif
67
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -070068#define ERR_EXIT(err) \
69 do { \
70 ERR(err); \
71 fflush(stdout); \
72 WAIT_FOR_CONSOLE_DESTROY; \
73 exit(-1); \
Karl Schultz481756e2016-02-02 15:37:51 -070074 } while (0)
Chia-I Wu46c29dd2014-12-02 21:09:20 +080075
Tony Barbour22a30862015-04-22 09:02:32 -060076#if defined(NDEBUG) && defined(__GNUC__)
77#define U_ASSERT_ONLY __attribute__((unused))
78#else
79#define U_ASSERT_ONLY
80#endif
81
Chia-I Wu46c29dd2014-12-02 21:09:20 +080082#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
83
Chia-I Wu46c29dd2014-12-02 21:09:20 +080084#define MAX_QUEUE_TYPES 5
Ian Elliott4e19ed02015-04-28 10:52:52 -060085#define APP_SHORT_NAME "vulkaninfo"
Chia-I Wu46c29dd2014-12-02 21:09:20 +080086
joey-lunargf0743b02016-11-07 11:27:00 -070087struct AppGpu;
Chia-I Wu46c29dd2014-12-02 21:09:20 +080088
joey-lunargf0743b02016-11-07 11:27:00 -070089struct AppDev {
90 struct AppGpu *gpu; /* point back to the GPU */
Chia-I Wu46c29dd2014-12-02 21:09:20 +080091
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060092 VkDevice obj;
Chia-I Wu46c29dd2014-12-02 21:09:20 +080093
Chia-I Wu1f851912015-10-27 18:04:07 +080094 VkFormatProperties format_props[VK_FORMAT_RANGE_SIZE];
Chia-I Wu46c29dd2014-12-02 21:09:20 +080095};
96
joey-lunargf0743b02016-11-07 11:27:00 -070097struct LayerExtensionList {
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -060098 VkLayerProperties layer_properties;
99 uint32_t extension_count;
100 VkExtensionProperties *extension_properties;
101};
102
joey-lunargf0743b02016-11-07 11:27:00 -0700103struct AppInstance {
Karl Schultz481756e2016-02-02 15:37:51 -0700104 VkInstance instance;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600105 uint32_t global_layer_count;
joey-lunargf0743b02016-11-07 11:27:00 -0700106 struct LayerExtensionList *global_layers;
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600107 uint32_t global_extension_count;
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700108 VkExtensionProperties *global_extensions; // Instance Extensions
Rene Lindsaya155d622016-06-10 08:26:26 -0700109
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700110 PFN_vkGetPhysicalDeviceSurfaceSupportKHR vkGetPhysicalDeviceSurfaceSupportKHR;
111 PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR vkGetPhysicalDeviceSurfaceCapabilitiesKHR;
112 PFN_vkGetPhysicalDeviceSurfaceFormatsKHR vkGetPhysicalDeviceSurfaceFormatsKHR;
113 PFN_vkGetPhysicalDeviceSurfacePresentModesKHR vkGetPhysicalDeviceSurfacePresentModesKHR;
Rene Lindsaya155d622016-06-10 08:26:26 -0700114
115 VkSurfaceKHR surface;
116 int width, height;
117
118#ifdef VK_USE_PLATFORM_WIN32_KHR
joey-lunargf0743b02016-11-07 11:27:00 -0700119 HINSTANCE h_instance; // Windows Instance
120 HWND h_wnd; // window handle
Tony Barbourb6bbc992016-12-09 11:27:26 -0700121#elif VK_USE_PLATFORM_XCB_KHR
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700122 xcb_connection_t *xcb_connection;
123 xcb_screen_t *xcb_screen;
124 xcb_window_t xcb_window;
Tony Barbourb6bbc992016-12-09 11:27:26 -0700125#elif VK_USE_PLATFORM_XLIB_KHR
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700126 Display *xlib_display;
127 Window xlib_window;
Tony Barbourb6bbc992016-12-09 11:27:26 -0700128#elif VK_USE_PLATFORM_ANDROID_KHR // TODO
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700129 ANativeWindow *window;
Rene Lindsaya155d622016-06-10 08:26:26 -0700130#endif
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600131};
132
joey-lunargf0743b02016-11-07 11:27:00 -0700133struct AppGpu {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600134 uint32_t id;
Tony Barbour8205d902015-04-16 15:59:00 -0600135 VkPhysicalDevice obj;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800136
Tony Barbour8205d902015-04-16 15:59:00 -0600137 VkPhysicalDeviceProperties props;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800138
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600139 uint32_t queue_count;
Cody Northropef72e2a2015-08-03 17:04:53 -0600140 VkQueueFamilyProperties *queue_props;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600141 VkDeviceQueueCreateInfo *queue_reqs;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800142
Tony Barbour8205d902015-04-16 15:59:00 -0600143 VkPhysicalDeviceMemoryProperties memory_props;
Chris Forbesa048b312015-06-21 20:09:12 +1200144 VkPhysicalDeviceFeatures features;
Mark Lobodzinski7dae6862015-09-07 12:56:17 -0600145 VkPhysicalDevice limits;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800146
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600147 uint32_t device_extension_count;
148 VkExtensionProperties *device_extensions;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800149
joey-lunargf0743b02016-11-07 11:27:00 -0700150 struct AppDev dev;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800151};
152
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700153static VKAPI_ATTR VkBool32 VKAPI_CALL DbgCallback(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
154 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
155 void *pUserData) {
Karl Schultz481756e2016-02-02 15:37:51 -0700156 char *message = (char *)malloc(strlen(pMsg) + 100);
Courtney Goeltzenleuchterf412d572015-12-03 13:50:49 -0700157
Karl Schultz481756e2016-02-02 15:37:51 -0700158 assert(message);
Courtney Goeltzenleuchterf412d572015-12-03 13:50:49 -0700159
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700160 if (msgFlags & VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700161 sprintf(message, "ERROR: [%s] Code %d : %s", pLayerPrefix, msgCode, pMsg);
Mark Lobodzinski5c13d4d2016-02-11 09:26:16 -0700162 } else if (msgFlags & VK_DEBUG_REPORT_WARNING_BIT_EXT) {
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700163 sprintf(message, "WARNING: [%s] Code %d : %s", pLayerPrefix, msgCode, pMsg);
Mark Lobodzinski5c13d4d2016-02-11 09:26:16 -0700164 } else if (msgFlags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) {
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700165 sprintf(message, "INFO: [%s] Code %d : %s", pLayerPrefix, msgCode, pMsg);
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700166 } else if (msgFlags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) {
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700167 sprintf(message, "DEBUG: [%s] Code %d : %s", pLayerPrefix, msgCode, pMsg);
Courtney Goeltzenleuchterf412d572015-12-03 13:50:49 -0700168 }
169
Karl Schultz481756e2016-02-02 15:37:51 -0700170 printf("%s\n", message);
Courtney Goeltzenleuchterf412d572015-12-03 13:50:49 -0700171 fflush(stdout);
Courtney Goeltzenleuchterf412d572015-12-03 13:50:49 -0700172 free(message);
173
174 /*
175 * false indicates that layer should not bail-out of an
176 * API call that had validation failures. This may mean that the
177 * app dies inside the driver due to invalid parameter(s).
178 * That's what would happen without validation layers, so we'll
179 * keep that behavior here.
180 */
181 return false;
182}
183
joey-lunargf0743b02016-11-07 11:27:00 -0700184static const char *VkResultString(VkResult err) {
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800185 switch (err) {
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700186#define STR(r) \
187 case r: \
Karl Schultz481756e2016-02-02 15:37:51 -0700188 return #r
189 STR(VK_SUCCESS);
190 STR(VK_NOT_READY);
191 STR(VK_TIMEOUT);
192 STR(VK_EVENT_SET);
193 STR(VK_EVENT_RESET);
194 STR(VK_ERROR_INITIALIZATION_FAILED);
195 STR(VK_ERROR_OUT_OF_HOST_MEMORY);
196 STR(VK_ERROR_OUT_OF_DEVICE_MEMORY);
197 STR(VK_ERROR_DEVICE_LOST);
198 STR(VK_ERROR_LAYER_NOT_PRESENT);
199 STR(VK_ERROR_EXTENSION_NOT_PRESENT);
200 STR(VK_ERROR_MEMORY_MAP_FAILED);
201 STR(VK_ERROR_INCOMPATIBLE_DRIVER);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800202#undef STR
Karl Schultz481756e2016-02-02 15:37:51 -0700203 default:
204 return "UNKNOWN_RESULT";
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800205 }
206}
Chia-I Wud4bae362014-07-29 11:15:00 +0800207
joey-lunargf0743b02016-11-07 11:27:00 -0700208static const char *VkPhysicalDeviceTypeString(VkPhysicalDeviceType type) {
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800209 switch (type) {
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700210#define STR(r) \
211 case VK_PHYSICAL_DEVICE_TYPE_##r: \
Karl Schultz481756e2016-02-02 15:37:51 -0700212 return #r
213 STR(OTHER);
214 STR(INTEGRATED_GPU);
215 STR(DISCRETE_GPU);
216 STR(VIRTUAL_GPU);
Chia-I Wud4bae362014-07-29 11:15:00 +0800217#undef STR
Karl Schultz481756e2016-02-02 15:37:51 -0700218 default:
219 return "UNKNOWN_DEVICE";
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800220 }
Chia-I Wud4bae362014-07-29 11:15:00 +0800221}
222
joey-lunargf0743b02016-11-07 11:27:00 -0700223static const char *VkFormatString(VkFormat fmt) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700224 switch (fmt) {
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700225#define STR(r) \
226 case VK_FORMAT_##r: \
Karl Schultz481756e2016-02-02 15:37:51 -0700227 return #r
228 STR(UNDEFINED);
229 STR(R4G4_UNORM_PACK8);
230 STR(R4G4B4A4_UNORM_PACK16);
231 STR(B4G4R4A4_UNORM_PACK16);
232 STR(R5G6B5_UNORM_PACK16);
233 STR(B5G6R5_UNORM_PACK16);
234 STR(R5G5B5A1_UNORM_PACK16);
235 STR(B5G5R5A1_UNORM_PACK16);
236 STR(A1R5G5B5_UNORM_PACK16);
237 STR(R8_UNORM);
238 STR(R8_SNORM);
239 STR(R8_USCALED);
240 STR(R8_SSCALED);
241 STR(R8_UINT);
242 STR(R8_SINT);
243 STR(R8_SRGB);
244 STR(R8G8_UNORM);
245 STR(R8G8_SNORM);
246 STR(R8G8_USCALED);
247 STR(R8G8_SSCALED);
248 STR(R8G8_UINT);
249 STR(R8G8_SINT);
250 STR(R8G8_SRGB);
251 STR(R8G8B8_UNORM);
252 STR(R8G8B8_SNORM);
253 STR(R8G8B8_USCALED);
254 STR(R8G8B8_SSCALED);
255 STR(R8G8B8_UINT);
256 STR(R8G8B8_SINT);
257 STR(R8G8B8_SRGB);
258 STR(B8G8R8_UNORM);
259 STR(B8G8R8_SNORM);
260 STR(B8G8R8_USCALED);
261 STR(B8G8R8_SSCALED);
262 STR(B8G8R8_UINT);
263 STR(B8G8R8_SINT);
264 STR(B8G8R8_SRGB);
265 STR(R8G8B8A8_UNORM);
266 STR(R8G8B8A8_SNORM);
267 STR(R8G8B8A8_USCALED);
268 STR(R8G8B8A8_SSCALED);
269 STR(R8G8B8A8_UINT);
270 STR(R8G8B8A8_SINT);
271 STR(R8G8B8A8_SRGB);
272 STR(B8G8R8A8_UNORM);
273 STR(B8G8R8A8_SNORM);
274 STR(B8G8R8A8_USCALED);
275 STR(B8G8R8A8_SSCALED);
276 STR(B8G8R8A8_UINT);
277 STR(B8G8R8A8_SINT);
278 STR(B8G8R8A8_SRGB);
279 STR(A8B8G8R8_UNORM_PACK32);
280 STR(A8B8G8R8_SNORM_PACK32);
281 STR(A8B8G8R8_USCALED_PACK32);
282 STR(A8B8G8R8_SSCALED_PACK32);
283 STR(A8B8G8R8_UINT_PACK32);
284 STR(A8B8G8R8_SINT_PACK32);
285 STR(A8B8G8R8_SRGB_PACK32);
286 STR(A2R10G10B10_UNORM_PACK32);
287 STR(A2R10G10B10_SNORM_PACK32);
288 STR(A2R10G10B10_USCALED_PACK32);
289 STR(A2R10G10B10_SSCALED_PACK32);
290 STR(A2R10G10B10_UINT_PACK32);
291 STR(A2R10G10B10_SINT_PACK32);
292 STR(A2B10G10R10_UNORM_PACK32);
293 STR(A2B10G10R10_SNORM_PACK32);
294 STR(A2B10G10R10_USCALED_PACK32);
295 STR(A2B10G10R10_SSCALED_PACK32);
296 STR(A2B10G10R10_UINT_PACK32);
297 STR(A2B10G10R10_SINT_PACK32);
298 STR(R16_UNORM);
299 STR(R16_SNORM);
300 STR(R16_USCALED);
301 STR(R16_SSCALED);
302 STR(R16_UINT);
303 STR(R16_SINT);
304 STR(R16_SFLOAT);
305 STR(R16G16_UNORM);
306 STR(R16G16_SNORM);
307 STR(R16G16_USCALED);
308 STR(R16G16_SSCALED);
309 STR(R16G16_UINT);
310 STR(R16G16_SINT);
311 STR(R16G16_SFLOAT);
312 STR(R16G16B16_UNORM);
313 STR(R16G16B16_SNORM);
314 STR(R16G16B16_USCALED);
315 STR(R16G16B16_SSCALED);
316 STR(R16G16B16_UINT);
317 STR(R16G16B16_SINT);
318 STR(R16G16B16_SFLOAT);
319 STR(R16G16B16A16_UNORM);
320 STR(R16G16B16A16_SNORM);
321 STR(R16G16B16A16_USCALED);
322 STR(R16G16B16A16_SSCALED);
323 STR(R16G16B16A16_UINT);
324 STR(R16G16B16A16_SINT);
325 STR(R16G16B16A16_SFLOAT);
326 STR(R32_UINT);
327 STR(R32_SINT);
328 STR(R32_SFLOAT);
329 STR(R32G32_UINT);
330 STR(R32G32_SINT);
331 STR(R32G32_SFLOAT);
332 STR(R32G32B32_UINT);
333 STR(R32G32B32_SINT);
334 STR(R32G32B32_SFLOAT);
335 STR(R32G32B32A32_UINT);
336 STR(R32G32B32A32_SINT);
337 STR(R32G32B32A32_SFLOAT);
338 STR(R64_UINT);
339 STR(R64_SINT);
340 STR(R64_SFLOAT);
341 STR(R64G64_UINT);
342 STR(R64G64_SINT);
343 STR(R64G64_SFLOAT);
344 STR(R64G64B64_UINT);
345 STR(R64G64B64_SINT);
346 STR(R64G64B64_SFLOAT);
347 STR(R64G64B64A64_UINT);
348 STR(R64G64B64A64_SINT);
349 STR(R64G64B64A64_SFLOAT);
350 STR(B10G11R11_UFLOAT_PACK32);
351 STR(E5B9G9R9_UFLOAT_PACK32);
352 STR(D16_UNORM);
353 STR(X8_D24_UNORM_PACK32);
354 STR(D32_SFLOAT);
355 STR(S8_UINT);
356 STR(D16_UNORM_S8_UINT);
357 STR(D24_UNORM_S8_UINT);
358 STR(D32_SFLOAT_S8_UINT);
359 STR(BC1_RGB_UNORM_BLOCK);
360 STR(BC1_RGB_SRGB_BLOCK);
361 STR(BC2_UNORM_BLOCK);
362 STR(BC2_SRGB_BLOCK);
363 STR(BC3_UNORM_BLOCK);
364 STR(BC3_SRGB_BLOCK);
365 STR(BC4_UNORM_BLOCK);
366 STR(BC4_SNORM_BLOCK);
367 STR(BC5_UNORM_BLOCK);
368 STR(BC5_SNORM_BLOCK);
369 STR(BC6H_UFLOAT_BLOCK);
370 STR(BC6H_SFLOAT_BLOCK);
371 STR(BC7_UNORM_BLOCK);
372 STR(BC7_SRGB_BLOCK);
373 STR(ETC2_R8G8B8_UNORM_BLOCK);
374 STR(ETC2_R8G8B8A1_UNORM_BLOCK);
375 STR(ETC2_R8G8B8A8_UNORM_BLOCK);
376 STR(EAC_R11_UNORM_BLOCK);
377 STR(EAC_R11_SNORM_BLOCK);
378 STR(EAC_R11G11_UNORM_BLOCK);
379 STR(EAC_R11G11_SNORM_BLOCK);
380 STR(ASTC_4x4_UNORM_BLOCK);
381 STR(ASTC_4x4_SRGB_BLOCK);
382 STR(ASTC_5x4_UNORM_BLOCK);
383 STR(ASTC_5x4_SRGB_BLOCK);
384 STR(ASTC_5x5_UNORM_BLOCK);
385 STR(ASTC_5x5_SRGB_BLOCK);
386 STR(ASTC_6x5_UNORM_BLOCK);
387 STR(ASTC_6x5_SRGB_BLOCK);
388 STR(ASTC_6x6_UNORM_BLOCK);
389 STR(ASTC_6x6_SRGB_BLOCK);
390 STR(ASTC_8x5_UNORM_BLOCK);
391 STR(ASTC_8x5_SRGB_BLOCK);
392 STR(ASTC_8x6_UNORM_BLOCK);
393 STR(ASTC_8x6_SRGB_BLOCK);
394 STR(ASTC_8x8_UNORM_BLOCK);
395 STR(ASTC_8x8_SRGB_BLOCK);
396 STR(ASTC_10x5_UNORM_BLOCK);
397 STR(ASTC_10x5_SRGB_BLOCK);
398 STR(ASTC_10x6_UNORM_BLOCK);
399 STR(ASTC_10x6_SRGB_BLOCK);
400 STR(ASTC_10x8_UNORM_BLOCK);
401 STR(ASTC_10x8_SRGB_BLOCK);
402 STR(ASTC_10x10_UNORM_BLOCK);
403 STR(ASTC_10x10_SRGB_BLOCK);
404 STR(ASTC_12x10_UNORM_BLOCK);
405 STR(ASTC_12x10_SRGB_BLOCK);
406 STR(ASTC_12x12_UNORM_BLOCK);
407 STR(ASTC_12x12_SRGB_BLOCK);
Chia-I Wud4bae362014-07-29 11:15:00 +0800408#undef STR
Karl Schultz481756e2016-02-02 15:37:51 -0700409 default:
410 return "UNKNOWN_FORMAT";
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800411 }
Chia-I Wud4bae362014-07-29 11:15:00 +0800412}
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700413#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_WIN32_KHR)
joey-lunargf0743b02016-11-07 11:27:00 -0700414static const char *VkPresentModeString(VkPresentModeKHR mode) {
joey-lunarg7b3aade2016-11-02 14:36:19 -0600415 switch (mode) {
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700416#define STR(r) \
417 case VK_PRESENT_MODE_##r: \
joey-lunarg7b3aade2016-11-02 14:36:19 -0600418 return #r
419 STR(IMMEDIATE_KHR);
420 STR(MAILBOX_KHR);
421 STR(FIFO_KHR);
422 STR(FIFO_RELAXED_KHR);
423#undef STR
424 default:
425 return "UNKNOWN_FORMAT";
426 }
427}
Tony Barbourb6bbc992016-12-09 11:27:26 -0700428#endif
joey-lunarg7b3aade2016-11-02 14:36:19 -0600429
joey-lunargf0743b02016-11-07 11:27:00 -0700430static void AppDevInitFormats(struct AppDev *dev) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600431 VkFormat f;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800432
Chia-I Wu1f851912015-10-27 18:04:07 +0800433 for (f = 0; f < VK_FORMAT_RANGE_SIZE; f++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600434 const VkFormat fmt = f;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800435
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700436 vkGetPhysicalDeviceFormatProperties(dev->gpu->obj, fmt, &dev->format_props[f]);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800437 }
438}
439
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700440static void ExtractVersion(uint32_t version, uint32_t *major, uint32_t *minor, uint32_t *patch) {
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600441 *major = version >> 22;
442 *minor = (version >> 12) & 0x3ff;
443 *patch = version & 0xfff;
444}
445
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700446static void AppGetPhysicalDeviceLayerExtensions(struct AppGpu *gpu, char *layer_name, uint32_t *extension_count,
447 VkExtensionProperties **extension_properties) {
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600448 VkResult err;
449 uint32_t ext_count = 0;
450 VkExtensionProperties *ext_ptr = NULL;
451
452 /* repeat get until VK_INCOMPLETE goes away */
453 do {
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700454 err = vkEnumerateDeviceExtensionProperties(gpu->obj, layer_name, &ext_count, NULL);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600455 assert(!err);
456
457 if (ext_ptr) {
458 free(ext_ptr);
459 }
460 ext_ptr = malloc(ext_count * sizeof(VkExtensionProperties));
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700461 err = vkEnumerateDeviceExtensionProperties(gpu->obj, layer_name, &ext_count, ext_ptr);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600462 } while (err == VK_INCOMPLETE);
463 assert(!err);
464
465 *extension_count = ext_count;
466 *extension_properties = ext_ptr;
467}
468
joey-lunargf0743b02016-11-07 11:27:00 -0700469static void AppDevInit(struct AppDev *dev, struct AppGpu *gpu) {
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600470 VkDeviceCreateInfo info = {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600471 .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800472 .pNext = NULL,
Tony Barbour81730932016-10-28 13:52:29 -0600473 .flags = 0,
Chia-I Wu045654f2015-11-06 06:42:02 +0800474 .queueCreateInfoCount = 0,
475 .pQueueCreateInfos = NULL,
Jon Ashburna4ae48b2016-01-11 13:12:43 -0700476 .enabledLayerCount = 0,
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600477 .ppEnabledLayerNames = NULL,
Jon Ashburna4ae48b2016-01-11 13:12:43 -0700478 .enabledExtensionCount = 0,
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600479 .ppEnabledExtensionNames = NULL,
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800480 };
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600481 VkResult U_ASSERT_ONLY err;
Tony Barbour426b9052015-06-24 16:06:58 -0600482
Rene Lindsay9652e552016-06-22 15:46:48 -0700483 // Device extensions
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700484 AppGetPhysicalDeviceLayerExtensions(gpu, NULL, &gpu->device_extension_count, &gpu->device_extensions);
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600485
Courtney Goeltzenleuchter9e42b882015-06-25 16:24:36 -0600486 fflush(stdout);
487
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800488 /* request all queues */
Chia-I Wu045654f2015-11-06 06:42:02 +0800489 info.queueCreateInfoCount = gpu->queue_count;
490 info.pQueueCreateInfos = gpu->queue_reqs;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800491
Jon Ashburna4ae48b2016-01-11 13:12:43 -0700492 info.enabledLayerCount = 0;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600493 info.ppEnabledLayerNames = NULL;
Jon Ashburn4ead55c2016-03-25 12:47:06 -0600494 info.enabledExtensionCount = 0;
495 info.ppEnabledExtensionNames = NULL;
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600496 dev->gpu = gpu;
Chia-I Wu69f40122015-10-26 21:10:41 +0800497 err = vkCreateDevice(gpu->obj, &info, NULL, &dev->obj);
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600498 if (err)
499 ERR_EXIT(err);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800500}
501
joey-lunargf0743b02016-11-07 11:27:00 -0700502static void AppDevDestroy(struct AppDev *dev) {
Tony Barbourc7e3fbd2016-11-10 16:45:15 -0700503 vkDeviceWaitIdle(dev->obj);
Chia-I Wu69f40122015-10-26 21:10:41 +0800504 vkDestroyDevice(dev->obj, NULL);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800505}
506
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700507static void AppGetGlobalLayerExtensions(char *layer_name, uint32_t *extension_count, VkExtensionProperties **extension_properties) {
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600508 VkResult err;
509 uint32_t ext_count = 0;
510 VkExtensionProperties *ext_ptr = NULL;
511
512 /* repeat get until VK_INCOMPLETE goes away */
513 do {
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700514 // gets the extension count if the last parameter is NULL
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700515 err = vkEnumerateInstanceExtensionProperties(layer_name, &ext_count, NULL);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600516 assert(!err);
517
518 if (ext_ptr) {
519 free(ext_ptr);
520 }
521 ext_ptr = malloc(ext_count * sizeof(VkExtensionProperties));
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700522 // gets the extension properties if the last parameter is not NULL
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700523 err = vkEnumerateInstanceExtensionProperties(layer_name, &ext_count, ext_ptr);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600524 } while (err == VK_INCOMPLETE);
525 assert(!err);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600526 *extension_count = ext_count;
527 *extension_properties = ext_ptr;
528}
529
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700530/* Gets a list of layer and instance extensions */
joey-lunargf0743b02016-11-07 11:27:00 -0700531static void AppGetInstanceExtensions(struct AppInstance *inst) {
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700532 VkResult U_ASSERT_ONLY err;
Rene Lindsaya155d622016-06-10 08:26:26 -0700533
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700534 uint32_t count = 0;
Rene Lindsaya155d622016-06-10 08:26:26 -0700535
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700536 /* Scan layers */
537 VkLayerProperties *global_layer_properties = NULL;
joey-lunargf0743b02016-11-07 11:27:00 -0700538 struct LayerExtensionList *global_layers = NULL;
Rene Lindsaya155d622016-06-10 08:26:26 -0700539
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700540 do {
541 err = vkEnumerateInstanceLayerProperties(&count, NULL);
542 assert(!err);
Rene Lindsaya155d622016-06-10 08:26:26 -0700543
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700544 if (global_layer_properties) {
545 free(global_layer_properties);
546 }
547 global_layer_properties = malloc(sizeof(VkLayerProperties) * count);
548 assert(global_layer_properties);
Rene Lindsaya155d622016-06-10 08:26:26 -0700549
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700550 if (global_layers) {
551 free(global_layers);
552 }
joey-lunargf0743b02016-11-07 11:27:00 -0700553 global_layers = malloc(sizeof(struct LayerExtensionList) * count);
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700554 assert(global_layers);
Rene Lindsaya155d622016-06-10 08:26:26 -0700555
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700556 err = vkEnumerateInstanceLayerProperties(&count, global_layer_properties);
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700557 } while (err == VK_INCOMPLETE);
558 assert(!err);
Rene Lindsaya155d622016-06-10 08:26:26 -0700559
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700560 inst->global_layer_count = count;
561 inst->global_layers = global_layers;
Rene Lindsaya155d622016-06-10 08:26:26 -0700562
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700563 for (uint32_t i = 0; i < inst->global_layer_count; i++) {
564 VkLayerProperties *src_info = &global_layer_properties[i];
joey-lunargf0743b02016-11-07 11:27:00 -0700565 struct LayerExtensionList *dst_info = &inst->global_layers[i];
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700566 memcpy(&dst_info->layer_properties, src_info, sizeof(VkLayerProperties));
Rene Lindsaya155d622016-06-10 08:26:26 -0700567
Rene Lindsaycb6b5ca2016-06-21 15:02:10 -0700568 // Save away layer extension info for report
569 // Gets layer extensions, if first parameter is not NULL
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700570 AppGetGlobalLayerExtensions(src_info->layerName, &dst_info->extension_count, &dst_info->extension_properties);
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700571 }
572 free(global_layer_properties);
Rene Lindsaya155d622016-06-10 08:26:26 -0700573
Rene Lindsaycb6b5ca2016-06-21 15:02:10 -0700574 // Collect global extensions
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700575 inst->global_extension_count = 0;
Rene Lindsay9652e552016-06-22 15:46:48 -0700576 // Gets instance extensions, if no layer was specified in the first
577 // paramteter
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700578 AppGetGlobalLayerExtensions(NULL, &inst->global_extension_count, &inst->global_extensions);
Rene Lindsaya155d622016-06-10 08:26:26 -0700579}
580
joey-lunargf0743b02016-11-07 11:27:00 -0700581static void AppCreateInstance(struct AppInstance *inst) {
582 AppGetInstanceExtensions(inst);
Rene Lindsaya155d622016-06-10 08:26:26 -0700583
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700584//---Build a list of extensions to load---
585#define MAX_EXTENSIONS 4
586 uint32_t i = 0;
587 uint32_t ext_count = 0;
588 const char *ext_names[MAX_EXTENSIONS]; // array of string pointers to
589 // extension names
590 for (i = 0; (i < inst->global_extension_count); i++) {
591 const char *found_name = inst->global_extensions[i].extensionName;
Rene Lindsay9652e552016-06-22 15:46:48 -0700592 if (!strcmp(VK_KHR_SURFACE_EXTENSION_NAME, found_name)) {
593 ext_names[ext_count++] = VK_KHR_SURFACE_EXTENSION_NAME;
594 }
Rene Lindsaya155d622016-06-10 08:26:26 -0700595 }
596
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700597#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_WAYLAND_KHR) || \
598 defined(VK_USE_PLATFORM_WIN32_KHR) || defined(VK_USE_PLATFORM_ANDROID_KHR)
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700599 if (ext_count)
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700600 for (i = 0; ((i < inst->global_extension_count) && (ext_count < MAX_EXTENSIONS)); i++) {
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700601 const char *found_name = inst->global_extensions[i].extensionName;
602#ifdef VK_USE_PLATFORM_WIN32_KHR
Rene Lindsay9652e552016-06-22 15:46:48 -0700603 if (!strcmp(VK_KHR_WIN32_SURFACE_EXTENSION_NAME, found_name)) {
604 ext_names[ext_count++] = VK_KHR_WIN32_SURFACE_EXTENSION_NAME;
605 }
Tony Barbourb6bbc992016-12-09 11:27:26 -0700606#elif VK_USE_PLATFORM_XCB_KHR
Rene Lindsay9652e552016-06-22 15:46:48 -0700607 if (!strcmp(VK_KHR_XCB_SURFACE_EXTENSION_NAME, found_name)) {
608 ext_names[ext_count++] = VK_KHR_XCB_SURFACE_EXTENSION_NAME;
609 }
Tony Barbourb6bbc992016-12-09 11:27:26 -0700610#elif VK_USE_PLATFORM_XLIB_KHR
Rene Lindsay9652e552016-06-22 15:46:48 -0700611 if (!strcmp(VK_KHR_XLIB_SURFACE_EXTENSION_NAME, found_name)) {
612 ext_names[ext_count++] = VK_KHR_XLIB_SURFACE_EXTENSION_NAME;
613 }
Tony Barbourb6bbc992016-12-09 11:27:26 -0700614#elif VK_USE_PLATFORM_WAYLAND_KHR
615 if (!strcmp(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, found_name)) {
616 ext_names[ext_count++] = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME;
617 }
618#elif VK_USE_PLATFORM_ANDROID_KHR
Rene Lindsay9652e552016-06-22 15:46:48 -0700619 if (!strcmp(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, found_name)) {
620 ext_names[ext_count++] = VK_KHR_ANDROID_SURFACE_EXTENSION_NAME;
621 }
Rene Lindsaya155d622016-06-10 08:26:26 -0700622#endif
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700623 }
Karl Schultzfad114e2016-09-12 13:28:09 -0600624#endif
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700625 // If we don't find the KHR_SURFACE extension and at least one other
626 // device-specific extension,
627 // then give up on reporting presentable surface formats."
628 if (ext_count < 2)
629 ext_count = 0;
Rene Lindsaya155d622016-06-10 08:26:26 -0700630 //----------------------------------------
631
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600632 const VkApplicationInfo app_info = {
633 .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
634 .pNext = NULL,
Chia-I Wu1f851912015-10-27 18:04:07 +0800635 .pApplicationName = APP_SHORT_NAME,
636 .applicationVersion = 1,
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600637 .pEngineName = APP_SHORT_NAME,
638 .engineVersion = 1,
Jon Ashburnd3995c92016-03-22 13:57:46 -0600639 .apiVersion = VK_API_VERSION_1_0,
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600640 };
Rene Lindsaya155d622016-06-10 08:26:26 -0700641
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600642 VkInstanceCreateInfo inst_info = {
643 .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
644 .pNext = NULL,
Chia-I Wu1f851912015-10-27 18:04:07 +0800645 .pApplicationInfo = &app_info,
Jon Ashburna4ae48b2016-01-11 13:12:43 -0700646 .enabledLayerCount = 0,
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600647 .ppEnabledLayerNames = NULL,
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700648 .enabledExtensionCount = ext_count,
Rene Lindsaya155d622016-06-10 08:26:26 -0700649 .ppEnabledExtensionNames = ext_names,
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600650 };
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800651
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700652 VkDebugReportCallbackCreateInfoEXT dbg_info;
Courtney Goeltzenleuchterf412d572015-12-03 13:50:49 -0700653 memset(&dbg_info, 0, sizeof(dbg_info));
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700654 dbg_info.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700655 dbg_info.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
joey-lunargf0743b02016-11-07 11:27:00 -0700656 dbg_info.pfnCallback = DbgCallback;
Courtney Goeltzenleuchterf412d572015-12-03 13:50:49 -0700657 inst_info.pNext = &dbg_info;
658
Rene Lindsaya155d622016-06-10 08:26:26 -0700659 VkResult U_ASSERT_ONLY err;
Chia-I Wu69f40122015-10-26 21:10:41 +0800660 err = vkCreateInstance(&inst_info, NULL, &inst->instance);
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600661 if (err == VK_ERROR_INCOMPATIBLE_DRIVER) {
662 printf("Cannot create Vulkan instance.\n");
663 ERR_EXIT(err);
664 } else if (err) {
665 ERR_EXIT(err);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800666 }
Rene Lindsaya155d622016-06-10 08:26:26 -0700667
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700668 if (ext_count > 0) {
669//--Load Extensions--
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700670#define GET_INSTANCE_PROC_ADDR(ENTRYPOINT) \
671 { inst->ENTRYPOINT = (void *)vkGetInstanceProcAddr(inst->instance, #ENTRYPOINT); }
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700672 GET_INSTANCE_PROC_ADDR(vkGetPhysicalDeviceSurfaceSupportKHR)
Rene Lindsaya155d622016-06-10 08:26:26 -0700673 GET_INSTANCE_PROC_ADDR(vkGetPhysicalDeviceSurfaceCapabilitiesKHR)
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700674 GET_INSTANCE_PROC_ADDR(vkGetPhysicalDeviceSurfaceFormatsKHR)
Rene Lindsaya155d622016-06-10 08:26:26 -0700675 GET_INSTANCE_PROC_ADDR(vkGetPhysicalDeviceSurfacePresentModesKHR)
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700676#undef GET_INSTANCE_PROC_ADDR
Rene Lindsaya155d622016-06-10 08:26:26 -0700677 }
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800678}
679
Rene Lindsaya155d622016-06-10 08:26:26 -0700680//-----------------------------------------------------------
681
joey-lunargf0743b02016-11-07 11:27:00 -0700682static void AppDestroyInstance(struct AppInstance *inst) {
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600683 free(inst->global_extensions);
Chia-I Wu69f40122015-10-26 21:10:41 +0800684 vkDestroyInstance(inst->instance, NULL);
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600685}
686
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700687static void AppGpuInit(struct AppGpu *gpu, uint32_t id, VkPhysicalDevice obj) {
Ian Elliottaae1a572015-02-04 16:48:37 -0700688 uint32_t i;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800689
690 memset(gpu, 0, sizeof(*gpu));
691
692 gpu->id = id;
693 gpu->obj = obj;
Tony Barbour426b9052015-06-24 16:06:58 -0600694
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600695 vkGetPhysicalDeviceProperties(gpu->obj, &gpu->props);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800696
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800697 /* get queue count */
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600698 vkGetPhysicalDeviceQueueFamilyProperties(gpu->obj, &gpu->queue_count, NULL);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800699
Karl Schultz481756e2016-02-02 15:37:51 -0700700 gpu->queue_props = malloc(sizeof(gpu->queue_props[0]) * gpu->queue_count);
Tony Barbour426b9052015-06-24 16:06:58 -0600701
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800702 if (!gpu->queue_props)
Tony Barbour8205d902015-04-16 15:59:00 -0600703 ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700704 vkGetPhysicalDeviceQueueFamilyProperties(gpu->obj, &gpu->queue_count, gpu->queue_props);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800705
706 /* set up queue requests */
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800707 gpu->queue_reqs = malloc(sizeof(*gpu->queue_reqs) * gpu->queue_count);
708 if (!gpu->queue_reqs)
Tony Barbour8205d902015-04-16 15:59:00 -0600709 ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800710 for (i = 0; i < gpu->queue_count; i++) {
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700711 float *queue_priorities = malloc(gpu->queue_props[i].queueCount * sizeof(float));
Karl Schultz242a9c92017-01-11 12:15:58 -0700712 if (!queue_priorities)
713 ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -0700714 memset(queue_priorities, 0, gpu->queue_props[i].queueCount * sizeof(float));
Courtney Goeltzenleuchterea975642015-09-16 16:23:55 -0600715 gpu->queue_reqs[i].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
716 gpu->queue_reqs[i].pNext = NULL;
Tony Barbour81730932016-10-28 13:52:29 -0600717 gpu->queue_reqs[i].flags = 0;
Chris Forbesfa6d36e2015-07-11 19:11:39 +1200718 gpu->queue_reqs[i].queueFamilyIndex = i;
Chia-I Wu045654f2015-11-06 06:42:02 +0800719 gpu->queue_reqs[i].queueCount = gpu->queue_props[i].queueCount;
Courtney Goeltzenleuchterd3a8d362015-10-23 10:37:02 -0600720 gpu->queue_reqs[i].pQueuePriorities = queue_priorities;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800721 }
722
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600723 vkGetPhysicalDeviceMemoryProperties(gpu->obj, &gpu->memory_props);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800724
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600725 vkGetPhysicalDeviceFeatures(gpu->obj, &gpu->features);
Chris Forbesa048b312015-06-21 20:09:12 +1200726
joey-lunargf0743b02016-11-07 11:27:00 -0700727 AppDevInit(&gpu->dev, gpu);
728 AppDevInitFormats(&gpu->dev);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800729}
730
joey-lunargf0743b02016-11-07 11:27:00 -0700731static void AppGpuDestroy(struct AppGpu *gpu) {
732 AppDevDestroy(&gpu->dev);
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600733 free(gpu->device_extensions);
Jon Ashburn2c094832015-12-11 17:11:43 -0700734
Courtney Goeltzenleuchterd3a8d362015-10-23 10:37:02 -0600735 for (uint32_t i = 0; i < gpu->queue_count; i++) {
Karl Schultz481756e2016-02-02 15:37:51 -0700736 free((void *)gpu->queue_reqs[i].pQueuePriorities);
Courtney Goeltzenleuchterd3a8d362015-10-23 10:37:02 -0600737 }
Jon Ashburn2c094832015-12-11 17:11:43 -0700738 free(gpu->queue_reqs);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800739 free(gpu->queue_props);
740}
741
Karl Schultz481756e2016-02-02 15:37:51 -0700742// clang-format off
Rene Lindsaya155d622016-06-10 08:26:26 -0700743
744//-----------------------------------------------------------
745
746//---------------------------Win32---------------------------
747#ifdef VK_USE_PLATFORM_WIN32_KHR
748
749// MS-Windows event handling function:
750LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
Rene Lindsaya155d622016-06-10 08:26:26 -0700751 return (DefWindowProc(hWnd, uMsg, wParam, lParam));
752}
753
joey-lunargf0743b02016-11-07 11:27:00 -0700754static void AppCreateWin32Window(struct AppInstance *inst) {
755 inst->h_instance = GetModuleHandle(NULL);
Rene Lindsaya155d622016-06-10 08:26:26 -0700756
757 WNDCLASSEX win_class;
758
759 // Initialize the window class structure:
760 win_class.cbSize = sizeof(WNDCLASSEX);
761 win_class.style = CS_HREDRAW | CS_VREDRAW;
762 win_class.lpfnWndProc = WndProc;
763 win_class.cbClsExtra = 0;
764 win_class.cbWndExtra = 0;
joey-lunargf0743b02016-11-07 11:27:00 -0700765 win_class.hInstance = inst->h_instance;
Rene Lindsaya155d622016-06-10 08:26:26 -0700766 win_class.hIcon = LoadIcon(NULL, IDI_APPLICATION);
767 win_class.hCursor = LoadCursor(NULL, IDC_ARROW);
768 win_class.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
769 win_class.lpszMenuName = NULL;
770 win_class.lpszClassName = APP_SHORT_NAME;
joey-lunargf0743b02016-11-07 11:27:00 -0700771 win_class.hInstance = inst->h_instance;
Rene Lindsaya155d622016-06-10 08:26:26 -0700772 win_class.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
773 // Register window class:
774 if (!RegisterClassEx(&win_class)) {
775 // It didn't work, so try to give a useful error:
Rene Lindsay54cf48a2016-06-13 17:20:39 -0600776 printf("Failed to register the window class!\n");
Rene Lindsaya155d622016-06-10 08:26:26 -0700777 fflush(stdout);
778 exit(1);
779 }
780 // Create window with the registered class:
781 RECT wr = { 0, 0, inst->width, inst->height };
782 AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);
joey-lunargf0743b02016-11-07 11:27:00 -0700783 inst->h_wnd = CreateWindowEx(0,
Rene Lindsaya155d622016-06-10 08:26:26 -0700784 APP_SHORT_NAME, // class name
785 APP_SHORT_NAME, // app name
786 //WS_VISIBLE | WS_SYSMENU |
787 WS_OVERLAPPEDWINDOW, // window style
788 100, 100, // x/y coords
789 wr.right - wr.left, // width
790 wr.bottom - wr.top, // height
791 NULL, // handle to parent
792 NULL, // handle to menu
joey-lunargf0743b02016-11-07 11:27:00 -0700793 inst->h_instance, // hInstance
Rene Lindsaya155d622016-06-10 08:26:26 -0700794 NULL); // no extra parameters
joey-lunargf0743b02016-11-07 11:27:00 -0700795 if (!inst->h_wnd) {
Rene Lindsaya155d622016-06-10 08:26:26 -0700796 // It didn't work, so try to give a useful error:
Rene Lindsay54cf48a2016-06-13 17:20:39 -0600797 printf("Failed to create a window!\n");
Rene Lindsaya155d622016-06-10 08:26:26 -0700798 fflush(stdout);
799 exit(1);
800 }
801}
802
joey-lunargf0743b02016-11-07 11:27:00 -0700803static void AppCreateWin32Surface(struct AppInstance *inst) {
Rene Lindsaya155d622016-06-10 08:26:26 -0700804 VkResult U_ASSERT_ONLY err;
805 VkWin32SurfaceCreateInfoKHR createInfo;
806 createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
807 createInfo.pNext = NULL;
808 createInfo.flags = 0;
joey-lunargf0743b02016-11-07 11:27:00 -0700809 createInfo.hinstance = inst->h_instance;
810 createInfo.hwnd = inst->h_wnd;
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700811 err = vkCreateWin32SurfaceKHR(inst->instance, &createInfo, NULL, &inst->surface);
812 assert(!err);
Rene Lindsaya155d622016-06-10 08:26:26 -0700813}
814
joey-lunargf0743b02016-11-07 11:27:00 -0700815static void AppDestroyWin32Window(struct AppInstance *inst) {
816 DestroyWindow(inst->h_wnd);
Rene Lindsaya155d622016-06-10 08:26:26 -0700817}
818#endif //VK_USE_PLATFORM_WIN32_KHR
819//-----------------------------------------------------------
820
Tony Barbourb6bbc992016-12-09 11:27:26 -0700821#if defined(VK_USE_PLATFORM_XCB_KHR) || \
822 defined(VK_USE_PLATFORM_XLIB_KHR) || \
Karl Schultzfad114e2016-09-12 13:28:09 -0600823 defined(VK_USE_PLATFORM_WIN32_KHR)
joey-lunargf0743b02016-11-07 11:27:00 -0700824static void AppDestroySurface(struct AppInstance *inst) { //same for all platforms
Rene Lindsaya155d622016-06-10 08:26:26 -0700825 vkDestroySurfaceKHR(inst->instance, inst->surface, NULL);
826}
Karl Schultzfad114e2016-09-12 13:28:09 -0600827#endif
Rene Lindsaya155d622016-06-10 08:26:26 -0700828
829//----------------------------XCB----------------------------
Rene Lindsay54cf48a2016-06-13 17:20:39 -0600830
Rene Lindsaya155d622016-06-10 08:26:26 -0700831#ifdef VK_USE_PLATFORM_XCB_KHR
joey-lunargf0743b02016-11-07 11:27:00 -0700832static void AppCreateXcbWindow(struct AppInstance *inst) {
Mark Lobodzinskice165d82016-08-18 08:50:16 -0600833 //--Init Connection--
834 const xcb_setup_t *setup;
835 xcb_screen_iterator_t iter;
836 int scr;
Rene Lindsaya155d622016-06-10 08:26:26 -0700837
Mark Lobodzinskice165d82016-08-18 08:50:16 -0600838 inst->xcb_connection = xcb_connect(NULL, &scr);
839 if (inst->xcb_connection == NULL) {
840 printf("XCB failed to connect to the X server.\nExiting ...\n");
841 fflush(stdout);
842 exit(1);
843 }
Rene Lindsaya155d622016-06-10 08:26:26 -0700844
Arda Coskunsesc18eb542017-01-19 10:41:27 -0700845 int conn_error = xcb_connection_has_error(inst->xcb_connection);
846 if (conn_error) {
847 printf("XCB failed to connect to the X server due to error:%d.\nExiting ...\n", conn_error);
848 fflush(stdout);
849 exit(1);
850 }
851
Mark Lobodzinskice165d82016-08-18 08:50:16 -0600852 setup = xcb_get_setup(inst->xcb_connection);
853 iter = xcb_setup_roots_iterator(setup);
854 while (scr-- > 0) {
855 xcb_screen_next(&iter);
856 }
Rene Lindsaya155d622016-06-10 08:26:26 -0700857
Mark Lobodzinskice165d82016-08-18 08:50:16 -0600858 inst->xcb_screen = iter.data;
859 //-------------------
Rene Lindsaya155d622016-06-10 08:26:26 -0700860
Mark Lobodzinskice165d82016-08-18 08:50:16 -0600861 inst->xcb_window = xcb_generate_id(inst->xcb_connection);
862 xcb_create_window(inst->xcb_connection, XCB_COPY_FROM_PARENT, inst->xcb_window,
863 inst->xcb_screen->root, 0, 0, inst->width, inst->height, 0,
864 XCB_WINDOW_CLASS_INPUT_OUTPUT, inst->xcb_screen->root_visual,
865 0, NULL);
Rene Lindsaya155d622016-06-10 08:26:26 -0700866
Mark Lobodzinskice165d82016-08-18 08:50:16 -0600867 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(inst->xcb_connection, 1, 12, "WM_PROTOCOLS");
868 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(inst->xcb_connection, cookie, 0);
869 free(reply);
Rene Lindsaya155d622016-06-10 08:26:26 -0700870}
871
joey-lunargf0743b02016-11-07 11:27:00 -0700872static void AppCreateXcbSurface(struct AppInstance *inst) {
Rene Lindsaya155d622016-06-10 08:26:26 -0700873 VkResult U_ASSERT_ONLY err;
874 VkXcbSurfaceCreateInfoKHR xcb_createInfo;
875 xcb_createInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
876 xcb_createInfo.pNext = NULL;
877 xcb_createInfo.flags = 0;
878 xcb_createInfo.connection = inst->xcb_connection;
879 xcb_createInfo.window = inst->xcb_window;
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700880 err = vkCreateXcbSurfaceKHR(inst->instance, &xcb_createInfo, NULL, &inst->surface);
881 assert(!err);
Rene Lindsaya155d622016-06-10 08:26:26 -0700882}
883
joey-lunargf0743b02016-11-07 11:27:00 -0700884static void AppDestroyXcbWindow(struct AppInstance *inst) {
Rene Lindsaya155d622016-06-10 08:26:26 -0700885 xcb_destroy_window(inst->xcb_connection, inst->xcb_window);
886 xcb_disconnect(inst->xcb_connection);
Rene Lindsaya155d622016-06-10 08:26:26 -0700887}
Tony Barbourb6bbc992016-12-09 11:27:26 -0700888//VK_USE_PLATFORM_XCB_KHR
Rene Lindsaya155d622016-06-10 08:26:26 -0700889//-----------------------------------------------------------
890
891//----------------------------XLib---------------------------
Tony Barbourb6bbc992016-12-09 11:27:26 -0700892#elif VK_USE_PLATFORM_XLIB_KHR
joey-lunargf0743b02016-11-07 11:27:00 -0700893static void AppCreateXlibWindow(struct AppInstance *inst) {
Rene Lindsaya155d622016-06-10 08:26:26 -0700894 long visualMask = VisualScreenMask;
895 int numberOfVisuals;
Rene Lindsay54cf48a2016-06-13 17:20:39 -0600896
Karl Schultz60007872016-11-14 11:53:08 -0700897 inst->xlib_display = XOpenDisplay(NULL);
898 if (inst->xlib_display == NULL) {
899 printf("XLib failed to connect to the X server.\nExiting ...\n");
900 fflush(stdout);
901 exit(1);
902 }
Awais Belalf231a172016-11-11 15:13:40 +0500903
Rene Lindsay54cf48a2016-06-13 17:20:39 -0600904 XVisualInfo vInfoTemplate={};
Rene Lindsaya155d622016-06-10 08:26:26 -0700905 vInfoTemplate.screen = DefaultScreen(inst->xlib_display);
906 XVisualInfo *visualInfo = XGetVisualInfo(inst->xlib_display, visualMask,
907 &vInfoTemplate, &numberOfVisuals);
Rene Lindsaya155d622016-06-10 08:26:26 -0700908 inst->xlib_window = XCreateWindow(
909 inst->xlib_display, RootWindow(inst->xlib_display, vInfoTemplate.screen), 0, 0,
910 inst->width, inst->height, 0, visualInfo->depth, InputOutput,
Rene Lindsay54cf48a2016-06-13 17:20:39 -0600911 visualInfo->visual, 0, NULL);
Rene Lindsaya155d622016-06-10 08:26:26 -0700912
Rene Lindsayaad516e2016-06-21 16:42:19 -0600913 XSync(inst->xlib_display,false);
Rene Lindsaya155d622016-06-10 08:26:26 -0700914}
915
joey-lunargf0743b02016-11-07 11:27:00 -0700916static void AppCreateXlibSurface(struct AppInstance *inst) {
Rene Lindsaya155d622016-06-10 08:26:26 -0700917 VkResult U_ASSERT_ONLY err;
918 VkXlibSurfaceCreateInfoKHR createInfo;
919 createInfo.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
920 createInfo.pNext = NULL;
921 createInfo.flags = 0;
922 createInfo.dpy = inst->xlib_display;
923 createInfo.window = inst->xlib_window;
Rene Lindsay7fb1e012016-06-10 15:33:08 -0700924 err = vkCreateXlibSurfaceKHR(inst->instance, &createInfo, NULL, &inst->surface);
925 assert(!err);
Rene Lindsaya155d622016-06-10 08:26:26 -0700926}
927
joey-lunargf0743b02016-11-07 11:27:00 -0700928static void AppDestroyXlibWindow(struct AppInstance *inst) {
Rene Lindsaya155d622016-06-10 08:26:26 -0700929 XDestroyWindow(inst->xlib_display, inst->xlib_window);
930 XCloseDisplay(inst->xlib_display);
931}
932#endif //VK_USE_PLATFORM_XLIB_KHR
933//-----------------------------------------------------------
934
Tony Barbourb6bbc992016-12-09 11:27:26 -0700935#if defined(VK_USE_PLATFORM_XCB_KHR) || \
936 defined(VK_USE_PLATFORM_XLIB_KHR) || \
Karl Schultzfad114e2016-09-12 13:28:09 -0600937 defined(VK_USE_PLATFORM_WIN32_KHR)
joey-lunargf0743b02016-11-07 11:27:00 -0700938static int AppDumpSurfaceFormats(struct AppInstance *inst, struct AppGpu *gpu){
Rene Lindsaya155d622016-06-10 08:26:26 -0700939 // Get the list of VkFormat's that are supported:
Mark Lobodzinskice165d82016-08-18 08:50:16 -0600940 VkResult U_ASSERT_ONLY err;
joey-lunargf0743b02016-11-07 11:27:00 -0700941 uint32_t format_count = 0;
942 err = inst->vkGetPhysicalDeviceSurfaceFormatsKHR(gpu->obj, inst->surface, &format_count, NULL);
Mark Lobodzinskice165d82016-08-18 08:50:16 -0600943 assert(!err);
944
joey-lunargf0743b02016-11-07 11:27:00 -0700945 VkSurfaceFormatKHR *surf_formats = (VkSurfaceFormatKHR *)malloc(format_count * sizeof(VkSurfaceFormatKHR));
Karl Schultz242a9c92017-01-11 12:15:58 -0700946 if (!surf_formats)
947 ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
joey-lunargf0743b02016-11-07 11:27:00 -0700948 err = inst->vkGetPhysicalDeviceSurfaceFormatsKHR(gpu->obj, inst->surface, &format_count, surf_formats);
Mark Lobodzinskice165d82016-08-18 08:50:16 -0600949 assert(!err);
joey-lunargf0743b02016-11-07 11:27:00 -0700950 printf("Formats:\t\tcount = %d\n", format_count);
Mark Lobodzinskice165d82016-08-18 08:50:16 -0600951
joey-lunargf0743b02016-11-07 11:27:00 -0700952 for (uint32_t i = 0; i < format_count; i++) {
953 printf("\t%s\n", VkFormatString(surf_formats[i].format));
Mark Lobodzinskice165d82016-08-18 08:50:16 -0600954 }
Mark Lobodzinskice165d82016-08-18 08:50:16 -0600955 fflush(stdout);
joey-lunargf0743b02016-11-07 11:27:00 -0700956 return format_count;
Rene Lindsaya155d622016-06-10 08:26:26 -0700957}
joey-lunarg7b3aade2016-11-02 14:36:19 -0600958
joey-lunargf0743b02016-11-07 11:27:00 -0700959static int AppDumpSurfacePresentModes(struct AppInstance *inst, struct AppGpu *gpu) {
joey-lunarg7b3aade2016-11-02 14:36:19 -0600960 // Get the list of VkPresentMode's that are supported:
961 VkResult U_ASSERT_ONLY err;
joey-lunargf0743b02016-11-07 11:27:00 -0700962 uint32_t present_mode_count = 0;
963 err = inst->vkGetPhysicalDeviceSurfacePresentModesKHR(gpu->obj, inst->surface, &present_mode_count, NULL);
joey-lunarg7b3aade2016-11-02 14:36:19 -0600964 assert(!err);
965
joey-lunargf0743b02016-11-07 11:27:00 -0700966 VkPresentModeKHR *surf_present_modes = (VkPresentModeKHR *)malloc(present_mode_count * sizeof(VkPresentInfoKHR));
Karl Schultz242a9c92017-01-11 12:15:58 -0700967 if (!surf_present_modes)
968 ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
joey-lunargf0743b02016-11-07 11:27:00 -0700969 err = inst->vkGetPhysicalDeviceSurfacePresentModesKHR(gpu->obj, inst->surface, &present_mode_count, surf_present_modes);
joey-lunarg7b3aade2016-11-02 14:36:19 -0600970 assert(!err);
joey-lunargf0743b02016-11-07 11:27:00 -0700971 printf("Present Modes:\t\tcount = %d\n", present_mode_count);
joey-lunarg7b3aade2016-11-02 14:36:19 -0600972
joey-lunargf0743b02016-11-07 11:27:00 -0700973 for (uint32_t i = 0; i < present_mode_count; i++) {
974 printf("\t%s\n", VkPresentModeString(surf_present_modes[i]));
joey-lunarg7b3aade2016-11-02 14:36:19 -0600975 }
976 printf("\n");
977 fflush(stdout);
joey-lunargf0743b02016-11-07 11:27:00 -0700978 return present_mode_count;
joey-lunarg7b3aade2016-11-02 14:36:19 -0600979}
Karl Schultzfad114e2016-09-12 13:28:09 -0600980#endif
Rene Lindsaya155d622016-06-10 08:26:26 -0700981
joey-lunargf0743b02016-11-07 11:27:00 -0700982static void AppDevDumpFormatProps(const struct AppDev *dev, VkFormat fmt)
Chia-I Wud4bae362014-07-29 11:15:00 +0800983{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600984 const VkFormatProperties *props = &dev->format_props[fmt];
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800985 struct {
986 const char *name;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600987 VkFlags flags;
Mark Lobodzinski4b36dd42015-09-03 15:21:52 -0600988 } features[3];
Chia-I Wud4bae362014-07-29 11:15:00 +0800989
Mark Lobodzinski4b36dd42015-09-03 15:21:52 -0600990 features[0].name = "linearTiling FormatFeatureFlags";
991 features[0].flags = props->linearTilingFeatures;
992 features[1].name = "optimalTiling FormatFeatureFlags";
993 features[1].flags = props->optimalTilingFeatures;
994 features[2].name = "bufferFeatures FormatFeatureFlags";
995 features[2].flags = props->bufferFeatures;
Chia-I Wud4bae362014-07-29 11:15:00 +0800996
joey-lunargf0743b02016-11-07 11:27:00 -0700997 printf("\nFORMAT_%s:", VkFormatString(fmt));
Mark Lobodzinskice165d82016-08-18 08:50:16 -0600998 for (uint32_t i = 0; i < ARRAY_SIZE(features); i++) {
Mark Lobodzinski4b36dd42015-09-03 15:21:52 -0600999 printf("\n\t%s:", features[i].name);
1000 if (features[i].flags == 0) {
1001 printf("\n\t\tNone");
1002 } else {
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001003 printf("%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1004 ((features[i].flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) ? "\n\t\tVK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT" : ""), //0x0001
1005 ((features[i].flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) ? "\n\t\tVK_FORMAT_FEATURE_STORAGE_IMAGE_BIT" : ""), //0x0002
1006 ((features[i].flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT) ? "\n\t\tVK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT" : ""), //0x0004
1007 ((features[i].flags & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT) ? "\n\t\tVK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT" : ""), //0x0008
1008 ((features[i].flags & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT) ? "\n\t\tVK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT" : ""), //0x0010
1009 ((features[i].flags & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT) ? "\n\t\tVK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT" : ""), //0x0020
1010 ((features[i].flags & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) ? "\n\t\tVK_FORMAT_FEATURE_VERTEX_BUFFER_BIT" : ""), //0x0040
1011 ((features[i].flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) ? "\n\t\tVK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT" : ""), //0x0080
1012 ((features[i].flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT) ? "\n\t\tVK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT" : ""), //0x0100
1013 ((features[i].flags & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) ? "\n\t\tVK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT" : ""), //0x0200
1014 ((features[i].flags & VK_FORMAT_FEATURE_BLIT_SRC_BIT) ? "\n\t\tVK_FORMAT_FEATURE_BLIT_SRC_BIT" : ""), //0x0400
1015 ((features[i].flags & VK_FORMAT_FEATURE_BLIT_DST_BIT) ? "\n\t\tVK_FORMAT_FEATURE_BLIT_DST_BIT" : ""), //0x0800
1016 ((features[i].flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT) ? "\n\t\tVK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT" : ""), //0x1000
1017 ((features[i].flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG) ? "\n\t\tVK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG" : "")); //0x2000
Mark Lobodzinski4b36dd42015-09-03 15:21:52 -06001018 }
Chia-I Wu190ebdc2014-08-06 12:04:13 +08001019 }
Mark Lobodzinski4b36dd42015-09-03 15:21:52 -06001020 printf("\n");
Chia-I Wud4bae362014-07-29 11:15:00 +08001021}
1022
Chia-I Wud4bae362014-07-29 11:15:00 +08001023
1024static void
joey-lunargf0743b02016-11-07 11:27:00 -07001025AppDevDump(const struct AppDev *dev)
Chia-I Wud4bae362014-07-29 11:15:00 +08001026{
Rene Lindsay78503442016-06-21 17:37:26 -06001027 printf("Format Properties:\n");
1028 printf("==================");
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001029 VkFormat fmt;
Chia-I Wud4bae362014-07-29 11:15:00 +08001030
Chia-I Wu1f851912015-10-27 18:04:07 +08001031 for (fmt = 0; fmt < VK_FORMAT_RANGE_SIZE; fmt++) {
joey-lunargf0743b02016-11-07 11:27:00 -07001032 AppDevDumpFormatProps(dev, fmt);
Chia-I Wu190ebdc2014-08-06 12:04:13 +08001033 }
Chia-I Wud4bae362014-07-29 11:15:00 +08001034}
1035
Mike Stroyan009d8ca2015-05-27 13:09:15 -06001036#ifdef _WIN32
1037#define PRINTF_SIZE_T_SPECIFIER "%Iu"
1038#else
1039#define PRINTF_SIZE_T_SPECIFIER "%zu"
1040#endif
1041
joey-lunargf0743b02016-11-07 11:27:00 -07001042static void AppGpuDumpFeatures(const struct AppGpu *gpu)
Chris Forbesa048b312015-06-21 20:09:12 +12001043{
1044 const VkPhysicalDeviceFeatures *features = &gpu->features;
1045
Mark Lobodzinski825cc512015-08-14 10:30:30 -06001046 printf("VkPhysicalDeviceFeatures:\n");
1047 printf("=========================\n");
1048
1049 printf("\trobustBufferAccess = %u\n", features->robustBufferAccess );
1050 printf("\tfullDrawIndexUint32 = %u\n", features->fullDrawIndexUint32 );
1051 printf("\timageCubeArray = %u\n", features->imageCubeArray );
1052 printf("\tindependentBlend = %u\n", features->independentBlend );
1053 printf("\tgeometryShader = %u\n", features->geometryShader );
1054 printf("\ttessellationShader = %u\n", features->tessellationShader );
1055 printf("\tsampleRateShading = %u\n", features->sampleRateShading );
Chia-I Wuc04519c2015-10-27 17:53:18 +08001056 printf("\tdualSrcBlend = %u\n", features->dualSrcBlend );
Mark Lobodzinski825cc512015-08-14 10:30:30 -06001057 printf("\tlogicOp = %u\n", features->logicOp );
1058 printf("\tmultiDrawIndirect = %u\n", features->multiDrawIndirect );
Jon Ashburn0bdccbb2015-12-31 12:47:52 -07001059 printf("\tdrawIndirectFirstInstance = %u\n", features->drawIndirectFirstInstance );
Chia-I Wuc04519c2015-10-27 17:53:18 +08001060 printf("\tdepthClamp = %u\n", features->depthClamp );
Mark Lobodzinski825cc512015-08-14 10:30:30 -06001061 printf("\tdepthBiasClamp = %u\n", features->depthBiasClamp );
Chia-I Wu4291d882015-10-27 19:00:15 +08001062 printf("\tfillModeNonSolid = %u\n", features->fillModeNonSolid );
Mark Lobodzinski825cc512015-08-14 10:30:30 -06001063 printf("\tdepthBounds = %u\n", features->depthBounds );
1064 printf("\twideLines = %u\n", features->wideLines );
1065 printf("\tlargePoints = %u\n", features->largePoints );
1066 printf("\ttextureCompressionETC2 = %u\n", features->textureCompressionETC2 );
1067 printf("\ttextureCompressionASTC_LDR = %u\n", features->textureCompressionASTC_LDR );
1068 printf("\ttextureCompressionBC = %u\n", features->textureCompressionBC );
Karl Schultz481756e2016-02-02 15:37:51 -07001069 printf("\tocclusionQueryPrecise = %u\n", features->occlusionQueryPrecise );
Mark Lobodzinski825cc512015-08-14 10:30:30 -06001070 printf("\tpipelineStatisticsQuery = %u\n", features->pipelineStatisticsQuery );
Chia-I Wufd4bfc42015-10-26 17:04:32 +08001071 printf("\tvertexSideEffects = %u\n", features->vertexPipelineStoresAndAtomics );
1072 printf("\ttessellationSideEffects = %u\n", features->fragmentStoresAndAtomics );
1073 printf("\tgeometrySideEffects = %u\n", features->shaderTessellationAndGeometryPointSize );
Mark Lobodzinski825cc512015-08-14 10:30:30 -06001074 printf("\tshaderImageGatherExtended = %u\n", features->shaderImageGatherExtended );
1075 printf("\tshaderStorageImageExtendedFormats = %u\n", features->shaderStorageImageExtendedFormats );
1076 printf("\tshaderStorageImageMultisample = %u\n", features->shaderStorageImageMultisample );
Chia-I Wu221f2f22015-10-27 18:52:05 +08001077 printf("\tshaderStorageImageReadWithoutFormat = %u\n", features->shaderStorageImageReadWithoutFormat );
1078 printf("\tshaderStorageImageWriteWithoutFormat = %u\n", features->shaderStorageImageWriteWithoutFormat );
Mark Lobodzinski825cc512015-08-14 10:30:30 -06001079 printf("\tshaderUniformBufferArrayDynamicIndexing = %u\n", features->shaderUniformBufferArrayDynamicIndexing);
1080 printf("\tshaderSampledImageArrayDynamicIndexing = %u\n", features->shaderSampledImageArrayDynamicIndexing );
1081 printf("\tshaderStorageBufferArrayDynamicIndexing = %u\n", features->shaderStorageBufferArrayDynamicIndexing);
1082 printf("\tshaderStorageImageArrayDynamicIndexing = %u\n", features->shaderStorageImageArrayDynamicIndexing );
1083 printf("\tshaderClipDistance = %u\n", features->shaderClipDistance );
1084 printf("\tshaderCullDistance = %u\n", features->shaderCullDistance );
1085 printf("\tshaderFloat64 = %u\n", features->shaderFloat64 );
1086 printf("\tshaderInt64 = %u\n", features->shaderInt64 );
Mark Lobodzinski825cc512015-08-14 10:30:30 -06001087 printf("\tshaderInt16 = %u\n", features->shaderInt16 );
1088 printf("\tshaderResourceResidency = %u\n", features->shaderResourceResidency );
Chia-I Wud3f99342015-10-27 18:58:00 +08001089 printf("\tshaderResourceMinLod = %u\n", features->shaderResourceMinLod );
Mark Lobodzinski825cc512015-08-14 10:30:30 -06001090 printf("\talphaToOne = %u\n", features->alphaToOne );
Mark Lobodzinski7dae6862015-09-07 12:56:17 -06001091 printf("\tsparseBinding = %u\n", features->sparseBinding );
Mark Lobodzinski825cc512015-08-14 10:30:30 -06001092 printf("\tsparseResidencyBuffer = %u\n", features->sparseResidencyBuffer );
1093 printf("\tsparseResidencyImage2D = %u\n", features->sparseResidencyImage2D );
1094 printf("\tsparseResidencyImage3D = %u\n", features->sparseResidencyImage3D );
1095 printf("\tsparseResidency2Samples = %u\n", features->sparseResidency2Samples );
1096 printf("\tsparseResidency4Samples = %u\n", features->sparseResidency4Samples );
1097 printf("\tsparseResidency8Samples = %u\n", features->sparseResidency8Samples );
1098 printf("\tsparseResidency16Samples = %u\n", features->sparseResidency16Samples );
Mark Lobodzinski825cc512015-08-14 10:30:30 -06001099 printf("\tsparseResidencyAliased = %u\n", features->sparseResidencyAliased );
Chia-I Wud5072612015-10-27 18:52:46 +08001100 printf("\tvariableMultisampleRate = %u\n", features->variableMultisampleRate );
Karl Schultzc1838402016-10-07 08:51:59 -06001101 printf("\tinheritedQueries = %u\n", features->inheritedQueries );
Chris Forbesa048b312015-06-21 20:09:12 +12001102}
1103
joey-lunargf0743b02016-11-07 11:27:00 -07001104static void AppDumpSparseProps(const VkPhysicalDeviceSparseProperties *sparse_props)
Chris Forbesa048b312015-06-21 20:09:12 +12001105{
Chris Forbesa048b312015-06-21 20:09:12 +12001106
Mark Lobodzinski7dae6862015-09-07 12:56:17 -06001107 printf("\tVkPhysicalDeviceSparseProperties:\n");
1108 printf("\t---------------------------------\n");
Mark Lobodzinski825cc512015-08-14 10:30:30 -06001109
joey-lunargf0743b02016-11-07 11:27:00 -07001110 printf("\t\tresidencyStandard2DBlockShape = %u\n", sparse_props->residencyStandard2DBlockShape );
1111 printf("\t\tresidencyStandard2DMultisampleBlockShape = %u\n", sparse_props->residencyStandard2DMultisampleBlockShape);
1112 printf("\t\tresidencyStandard3DBlockShape = %u\n", sparse_props->residencyStandard3DBlockShape );
1113 printf("\t\tresidencyAlignedMipSize = %u\n", sparse_props->residencyAlignedMipSize );
1114 printf("\t\tresidencyNonResidentStrict = %u\n", sparse_props->residencyNonResidentStrict );
Mark Lobodzinski7dae6862015-09-07 12:56:17 -06001115}
1116
joey-lunargf0743b02016-11-07 11:27:00 -07001117static void AppDumpLimits(const VkPhysicalDeviceLimits *limits)
Mark Lobodzinski7dae6862015-09-07 12:56:17 -06001118{
1119 printf("\tVkPhysicalDeviceLimits:\n");
1120 printf("\t-----------------------\n");
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001121 printf("\t\tmaxImageDimension1D = %u\n", limits->maxImageDimension1D );
1122 printf("\t\tmaxImageDimension2D = %u\n", limits->maxImageDimension2D );
1123 printf("\t\tmaxImageDimension3D = %u\n", limits->maxImageDimension3D );
1124 printf("\t\tmaxImageDimensionCube = %u\n", limits->maxImageDimensionCube );
1125 printf("\t\tmaxImageArrayLayers = %u\n", limits->maxImageArrayLayers );
Chia-I Wu7e470702015-10-26 17:24:52 +08001126 printf("\t\tmaxTexelBufferElements = 0x%" PRIxLEAST32 "\n", limits->maxTexelBufferElements );
Karl Schultz481756e2016-02-02 15:37:51 -07001127 printf("\t\tmaxUniformBufferRange = 0x%" PRIxLEAST32 "\n", limits->maxUniformBufferRange );
1128 printf("\t\tmaxStorageBufferRange = 0x%" PRIxLEAST32 "\n", limits->maxStorageBufferRange );
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001129 printf("\t\tmaxPushConstantsSize = %u\n", limits->maxPushConstantsSize );
1130 printf("\t\tmaxMemoryAllocationCount = %u\n", limits->maxMemoryAllocationCount );
1131 printf("\t\tmaxSamplerAllocationCount = %u\n", limits->maxSamplerAllocationCount );
Mark Lobodzinski7dae6862015-09-07 12:56:17 -06001132 printf("\t\tbufferImageGranularity = 0x%" PRIxLEAST64 "\n", limits->bufferImageGranularity );
Tony Barboura0258a52015-10-27 11:01:20 -06001133 printf("\t\tsparseAddressSpaceSize = 0x%" PRIxLEAST64 "\n", limits->sparseAddressSpaceSize );
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001134 printf("\t\tmaxBoundDescriptorSets = %u\n", limits->maxBoundDescriptorSets );
1135 printf("\t\tmaxPerStageDescriptorSamplers = %u\n", limits->maxPerStageDescriptorSamplers );
1136 printf("\t\tmaxPerStageDescriptorUniformBuffers = %u\n", limits->maxPerStageDescriptorUniformBuffers );
1137 printf("\t\tmaxPerStageDescriptorStorageBuffers = %u\n", limits->maxPerStageDescriptorStorageBuffers );
1138 printf("\t\tmaxPerStageDescriptorSampledImages = %u\n", limits->maxPerStageDescriptorSampledImages );
1139 printf("\t\tmaxPerStageDescriptorStorageImages = %u\n", limits->maxPerStageDescriptorStorageImages );
1140 printf("\t\tmaxPerStageDescriptorInputAttachments = %u\n", limits->maxPerStageDescriptorInputAttachments );
1141 printf("\t\tmaxPerStageResources = %u\n", limits->maxPerStageResources );
1142 printf("\t\tmaxDescriptorSetSamplers = %u\n", limits->maxDescriptorSetSamplers );
1143 printf("\t\tmaxDescriptorSetUniformBuffers = %u\n", limits->maxDescriptorSetUniformBuffers );
1144 printf("\t\tmaxDescriptorSetUniformBuffersDynamic = %u\n", limits->maxDescriptorSetUniformBuffersDynamic );
1145 printf("\t\tmaxDescriptorSetStorageBuffers = %u\n", limits->maxDescriptorSetStorageBuffers );
1146 printf("\t\tmaxDescriptorSetStorageBuffersDynamic = %u\n", limits->maxDescriptorSetStorageBuffersDynamic );
1147 printf("\t\tmaxDescriptorSetSampledImages = %u\n", limits->maxDescriptorSetSampledImages );
1148 printf("\t\tmaxDescriptorSetStorageImages = %u\n", limits->maxDescriptorSetStorageImages );
1149 printf("\t\tmaxDescriptorSetInputAttachments = %u\n", limits->maxDescriptorSetInputAttachments );
1150 printf("\t\tmaxVertexInputAttributes = %u\n", limits->maxVertexInputAttributes );
1151 printf("\t\tmaxVertexInputBindings = %u\n", limits->maxVertexInputBindings );
Mark Lobodzinski7dae6862015-09-07 12:56:17 -06001152 printf("\t\tmaxVertexInputAttributeOffset = 0x%" PRIxLEAST32 "\n", limits->maxVertexInputAttributeOffset );
1153 printf("\t\tmaxVertexInputBindingStride = 0x%" PRIxLEAST32 "\n", limits->maxVertexInputBindingStride );
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001154 printf("\t\tmaxVertexOutputComponents = %u\n", limits->maxVertexOutputComponents );
1155 printf("\t\tmaxTessellationGenerationLevel = %u\n", limits->maxTessellationGenerationLevel );
1156 printf("\t\tmaxTessellationPatchSize = %u\n", limits->maxTessellationPatchSize );
1157 printf("\t\tmaxTessellationControlPerVertexInputComponents = %u\n", limits->maxTessellationControlPerVertexInputComponents );
1158 printf("\t\tmaxTessellationControlPerVertexOutputComponents = %u\n", limits->maxTessellationControlPerVertexOutputComponents);
1159 printf("\t\tmaxTessellationControlPerPatchOutputComponents = %u\n", limits->maxTessellationControlPerPatchOutputComponents );
1160 printf("\t\tmaxTessellationControlTotalOutputComponents = %u\n", limits->maxTessellationControlTotalOutputComponents );
1161 printf("\t\tmaxTessellationEvaluationInputComponents = %u\n", limits->maxTessellationEvaluationInputComponents );
1162 printf("\t\tmaxTessellationEvaluationOutputComponents = %u\n", limits->maxTessellationEvaluationOutputComponents );
1163 printf("\t\tmaxGeometryShaderInvocations = %u\n", limits->maxGeometryShaderInvocations );
1164 printf("\t\tmaxGeometryInputComponents = %u\n", limits->maxGeometryInputComponents );
1165 printf("\t\tmaxGeometryOutputComponents = %u\n", limits->maxGeometryOutputComponents );
1166 printf("\t\tmaxGeometryOutputVertices = %u\n", limits->maxGeometryOutputVertices );
1167 printf("\t\tmaxGeometryTotalOutputComponents = %u\n", limits->maxGeometryTotalOutputComponents );
1168 printf("\t\tmaxFragmentInputComponents = %u\n", limits->maxFragmentInputComponents );
1169 printf("\t\tmaxFragmentOutputAttachments = %u\n", limits->maxFragmentOutputAttachments );
1170 printf("\t\tmaxFragmentDualSrcAttachments = %u\n", limits->maxFragmentDualSrcAttachments );
1171 printf("\t\tmaxFragmentCombinedOutputResources = %u\n", limits->maxFragmentCombinedOutputResources );
Mark Lobodzinski7dae6862015-09-07 12:56:17 -06001172 printf("\t\tmaxComputeSharedMemorySize = 0x%" PRIxLEAST32 "\n", limits->maxComputeSharedMemorySize );
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001173 printf("\t\tmaxComputeWorkGroupCount[0] = %u\n", limits->maxComputeWorkGroupCount[0] );
1174 printf("\t\tmaxComputeWorkGroupCount[1] = %u\n", limits->maxComputeWorkGroupCount[1] );
1175 printf("\t\tmaxComputeWorkGroupCount[2] = %u\n", limits->maxComputeWorkGroupCount[2] );
1176 printf("\t\tmaxComputeWorkGroupInvocations = %u\n", limits->maxComputeWorkGroupInvocations );
1177 printf("\t\tmaxComputeWorkGroupSize[0] = %u\n", limits->maxComputeWorkGroupSize[0] );
1178 printf("\t\tmaxComputeWorkGroupSize[1] = %u\n", limits->maxComputeWorkGroupSize[1] );
1179 printf("\t\tmaxComputeWorkGroupSize[2] = %u\n", limits->maxComputeWorkGroupSize[2] );
1180 printf("\t\tsubPixelPrecisionBits = %u\n", limits->subPixelPrecisionBits );
1181 printf("\t\tsubTexelPrecisionBits = %u\n", limits->subTexelPrecisionBits );
1182 printf("\t\tmipmapPrecisionBits = %u\n", limits->mipmapPrecisionBits );
1183 printf("\t\tmaxDrawIndexedIndexValue = %u\n", limits->maxDrawIndexedIndexValue );
1184 printf("\t\tmaxDrawIndirectCount = %u\n", limits->maxDrawIndirectCount );
Mark Lobodzinski7dae6862015-09-07 12:56:17 -06001185 printf("\t\tmaxSamplerLodBias = %f\n", limits->maxSamplerLodBias );
1186 printf("\t\tmaxSamplerAnisotropy = %f\n", limits->maxSamplerAnisotropy );
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001187 printf("\t\tmaxViewports = %u\n", limits->maxViewports );
1188 printf("\t\tmaxViewportDimensions[0] = %u\n", limits->maxViewportDimensions[0] );
1189 printf("\t\tmaxViewportDimensions[1] = %u\n", limits->maxViewportDimensions[1] );
Rene Lindsay8a0cc4b2016-06-15 08:55:32 -07001190 printf("\t\tviewportBoundsRange[0] =%13f\n", limits->viewportBoundsRange[0] );
1191 printf("\t\tviewportBoundsRange[1] =%13f\n", limits->viewportBoundsRange[1] );
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001192 printf("\t\tviewportSubPixelBits = %u\n", limits->viewportSubPixelBits );
Chia-I Wu3ffcd732015-10-26 17:08:33 +08001193 printf("\t\tminMemoryMapAlignment = " PRINTF_SIZE_T_SPECIFIER "\n", limits->minMemoryMapAlignment );
1194 printf("\t\tminTexelBufferOffsetAlignment = 0x%" PRIxLEAST64 "\n", limits->minTexelBufferOffsetAlignment );
1195 printf("\t\tminUniformBufferOffsetAlignment = 0x%" PRIxLEAST64 "\n", limits->minUniformBufferOffsetAlignment );
1196 printf("\t\tminStorageBufferOffsetAlignment = 0x%" PRIxLEAST64 "\n", limits->minStorageBufferOffsetAlignment );
Rene Lindsay8a0cc4b2016-06-15 08:55:32 -07001197 printf("\t\tminTexelOffset =%3d\n", limits->minTexelOffset );
1198 printf("\t\tmaxTexelOffset =%3d\n", limits->maxTexelOffset );
1199 printf("\t\tminTexelGatherOffset =%3d\n", limits->minTexelGatherOffset );
1200 printf("\t\tmaxTexelGatherOffset =%3d\n", limits->maxTexelGatherOffset );
1201 printf("\t\tminInterpolationOffset =%9f\n", limits->minInterpolationOffset );
1202 printf("\t\tmaxInterpolationOffset =%9f\n", limits->maxInterpolationOffset );
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001203 printf("\t\tsubPixelInterpolationOffsetBits = %u\n", limits->subPixelInterpolationOffsetBits );
1204 printf("\t\tmaxFramebufferWidth = %u\n", limits->maxFramebufferWidth );
1205 printf("\t\tmaxFramebufferHeight = %u\n", limits->maxFramebufferHeight );
1206 printf("\t\tmaxFramebufferLayers = %u\n", limits->maxFramebufferLayers );
1207 printf("\t\tframebufferColorSampleCounts = %u\n", limits->framebufferColorSampleCounts );
1208 printf("\t\tframebufferDepthSampleCounts = %u\n", limits->framebufferDepthSampleCounts );
1209 printf("\t\tframebufferStencilSampleCounts = %u\n", limits->framebufferStencilSampleCounts );
1210 printf("\t\tframebufferNoAttachmentsSampleCounts = %u\n", limits->framebufferNoAttachmentsSampleCounts );
1211 printf("\t\tmaxColorAttachments = %u\n", limits->maxColorAttachments );
1212 printf("\t\tsampledImageColorSampleCounts = %u\n", limits->sampledImageColorSampleCounts );
1213 printf("\t\tsampledImageDepthSampleCounts = %u\n", limits->sampledImageDepthSampleCounts );
1214 printf("\t\tsampledImageStencilSampleCounts = %u\n", limits->sampledImageStencilSampleCounts );
1215 printf("\t\tsampledImageIntegerSampleCounts = %u\n", limits->sampledImageIntegerSampleCounts );
1216 printf("\t\tstorageImageSampleCounts = %u\n", limits->storageImageSampleCounts );
1217 printf("\t\tmaxSampleMaskWords = %u\n", limits->maxSampleMaskWords );
Jon Ashburnfef7f082015-12-29 14:57:48 -07001218 printf("\t\ttimestampComputeAndGraphics = %u\n", limits->timestampComputeAndGraphics );
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001219 printf("\t\ttimestampPeriod = %f\n", limits->timestampPeriod );
1220 printf("\t\tmaxClipDistances = %u\n", limits->maxClipDistances );
1221 printf("\t\tmaxCullDistances = %u\n", limits->maxCullDistances );
1222 printf("\t\tmaxCombinedClipAndCullDistances = %u\n", limits->maxCombinedClipAndCullDistances );
1223 printf("\t\tdiscreteQueuePriorities = %u\n", limits->discreteQueuePriorities );
Mark Lobodzinski7dae6862015-09-07 12:56:17 -06001224 printf("\t\tpointSizeRange[0] = %f\n", limits->pointSizeRange[0] );
1225 printf("\t\tpointSizeRange[1] = %f\n", limits->pointSizeRange[1] );
1226 printf("\t\tlineWidthRange[0] = %f\n", limits->lineWidthRange[0] );
1227 printf("\t\tlineWidthRange[1] = %f\n", limits->lineWidthRange[1] );
1228 printf("\t\tpointSizeGranularity = %f\n", limits->pointSizeGranularity );
1229 printf("\t\tlineWidthGranularity = %f\n", limits->lineWidthGranularity );
Chia-I Wu3c332102015-10-26 16:47:26 +08001230 printf("\t\tstrictLines = %u\n", limits->strictLines );
Chia-I Wua3939fc2015-10-31 00:31:16 +08001231 printf("\t\tstandardSampleLocations = %u\n", limits->standardSampleLocations );
Chia-I Wuee0eaa12015-11-06 10:37:51 +08001232 printf("\t\toptimalBufferCopyOffsetAlignment = 0x%" PRIxLEAST64 "\n", limits->optimalBufferCopyOffsetAlignment );
1233 printf("\t\toptimalBufferCopyRowPitchAlignment = 0x%" PRIxLEAST64 "\n", limits->optimalBufferCopyRowPitchAlignment );
1234 printf("\t\tnonCoherentAtomSize = 0x%" PRIxLEAST64 "\n", limits->nonCoherentAtomSize );
Chia-I Wud4bae362014-07-29 11:15:00 +08001235}
1236
joey-lunargf0743b02016-11-07 11:27:00 -07001237static void AppGpuDumpProps(const struct AppGpu *gpu)
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -06001238{
1239 const VkPhysicalDeviceProperties *props = &gpu->props;
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001240 const uint32_t apiVersion=props->apiVersion;
1241 const uint32_t major = VK_VERSION_MAJOR(apiVersion);
1242 const uint32_t minor = VK_VERSION_MINOR(apiVersion);
1243 const uint32_t patch = VK_VERSION_PATCH(apiVersion);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -06001244
Mark Lobodzinski825cc512015-08-14 10:30:30 -06001245 printf("VkPhysicalDeviceProperties:\n");
1246 printf("===========================\n");
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001247 printf("\tapiVersion = 0x%" PRIxLEAST32 " (%d.%d.%d)\n", apiVersion, major, minor, patch);
1248 printf("\tdriverVersion = %u (0x%" PRIxLEAST32 ")\n",props->driverVersion, props->driverVersion);
1249 printf("\tvendorID = 0x%04x\n", props->vendorID);
1250 printf("\tdeviceID = 0x%04x\n", props->deviceID);
joey-lunargf0743b02016-11-07 11:27:00 -07001251 printf("\tdeviceType = %s\n", VkPhysicalDeviceTypeString(props->deviceType));
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001252 printf("\tdeviceName = %s\n", props->deviceName);
Mark Lobodzinski7dae6862015-09-07 12:56:17 -06001253
joey-lunargf0743b02016-11-07 11:27:00 -07001254 AppDumpLimits(&gpu->props.limits);
1255 AppDumpSparseProps(&gpu->props.sparseProperties);
Mark Lobodzinski7dae6862015-09-07 12:56:17 -06001256
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -06001257 fflush(stdout);
1258}
Karl Schultz481756e2016-02-02 15:37:51 -07001259// clang-format on
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -06001260
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -07001261static void AppDumpExtensions(const char *indent, const char *layer_name, const uint32_t extension_count,
1262 const VkExtensionProperties *extension_properties) {
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -06001263 uint32_t i;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -06001264 if (layer_name && (strlen(layer_name) > 0)) {
1265 printf("%s%s Extensions", indent, layer_name);
1266 } else {
Rene Lindsaycb6b5ca2016-06-21 15:02:10 -07001267 printf("%sExtensions", indent);
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -06001268 }
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -06001269 printf("\tcount = %d\n", extension_count);
Karl Schultz481756e2016-02-02 15:37:51 -07001270 for (i = 0; i < extension_count; i++) {
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -06001271 VkExtensionProperties const *ext_prop = &extension_properties[i];
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -06001272
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -06001273 printf("%s\t", indent);
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -07001274 printf("%-36s: extension revision %2d\n", ext_prop->extensionName, ext_prop->specVersion);
Courtney Goeltzenleuchterff87c822014-10-03 18:05:10 -06001275 }
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -06001276 fflush(stdout);
Courtney Goeltzenleuchterff87c822014-10-03 18:05:10 -06001277}
1278
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -07001279#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_WIN32_KHR)
Rene Lindsay9652e552016-06-22 15:46:48 -07001280// Returns true if the named extension is in the list of extensions.
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -07001281static bool HasExtension(const char *extension_name, const uint32_t extension_count,
1282 const VkExtensionProperties *extension_properties) {
Rene Lindsay9652e552016-06-22 15:46:48 -07001283 for (uint32_t i = 0; i < extension_count; i++) {
1284 if (!strcmp(extension_name, extension_properties[i].extensionName))
1285 return true;
1286 }
1287 return false;
1288}
Karl Schultzfad114e2016-09-12 13:28:09 -06001289#endif
Rene Lindsay9652e552016-06-22 15:46:48 -07001290
joey-lunargf0743b02016-11-07 11:27:00 -07001291static void AppGpuDumpQueueProps(const struct AppGpu *gpu, uint32_t id) {
Cody Northropef72e2a2015-08-03 17:04:53 -06001292 const VkQueueFamilyProperties *props = &gpu->queue_props[id];
Chia-I Wud4bae362014-07-29 11:15:00 +08001293
Mark Lobodzinski825cc512015-08-14 10:30:30 -06001294 printf("VkQueueFamilyProperties[%d]:\n", id);
Rene Lindsaya155d622016-06-10 08:26:26 -07001295 printf("===========================\n");
Rene Lindsay7fb1e012016-06-10 15:33:08 -07001296 char *sep = ""; // separator character
Rene Lindsaya155d622016-06-10 08:26:26 -07001297 printf("\tqueueFlags = ");
Rene Lindsay7fb1e012016-06-10 15:33:08 -07001298 if (props->queueFlags & VK_QUEUE_GRAPHICS_BIT) {
1299 printf("GRAPHICS");
1300 sep = " | ";
1301 }
1302 if (props->queueFlags & VK_QUEUE_COMPUTE_BIT) {
1303 printf("%sCOMPUTE", sep);
1304 sep = " | ";
1305 }
1306 if (props->queueFlags & VK_QUEUE_TRANSFER_BIT) {
1307 printf("%sTRANSFER", sep);
1308 sep = " | ";
1309 }
1310 if (props->queueFlags & VK_QUEUE_SPARSE_BINDING_BIT) {
1311 printf("%sSPARSE", sep);
1312 }
Rene Lindsaya155d622016-06-10 08:26:26 -07001313 printf("\n");
1314
Karl Schultz481756e2016-02-02 15:37:51 -07001315 printf("\tqueueCount = %u\n", props->queueCount);
1316 printf("\ttimestampValidBits = %u\n", props->timestampValidBits);
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -07001317 printf("\tminImageTransferGranularity = (%d, %d, %d)\n", props->minImageTransferGranularity.width,
1318 props->minImageTransferGranularity.height, props->minImageTransferGranularity.depth);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -06001319 fflush(stdout);
Chia-I Wud4bae362014-07-29 11:15:00 +08001320}
1321
joey-lunargf0743b02016-11-07 11:27:00 -07001322static void AppGpuDumpMemoryProps(const struct AppGpu *gpu) {
Tony Barbour8205d902015-04-16 15:59:00 -06001323 const VkPhysicalDeviceMemoryProperties *props = &gpu->memory_props;
Chia-I Wud4bae362014-07-29 11:15:00 +08001324
Mark Lobodzinski825cc512015-08-14 10:30:30 -06001325 printf("VkPhysicalDeviceMemoryProperties:\n");
1326 printf("=================================\n");
1327 printf("\tmemoryTypeCount = %u\n", props->memoryTypeCount);
Mark Lobodzinski72346292015-07-02 16:49:40 -06001328 for (uint32_t i = 0; i < props->memoryTypeCount; i++) {
1329 printf("\tmemoryTypes[%u] : \n", i);
Mark Lobodzinski72346292015-07-02 16:49:40 -06001330 printf("\t\theapIndex = %u\n", props->memoryTypes[i].heapIndex);
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -07001331 printf("\t\tpropertyFlags = 0x%" PRIxLEAST32 ":\n", props->memoryTypes[i].propertyFlags);
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001332
Rene Lindsay7fb1e012016-06-10 15:33:08 -07001333 // Print each named flag, if it is set.
1334 VkFlags flags = props->memoryTypes[i].propertyFlags;
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -07001335#define PRINT_FLAG(FLAG) \
1336 if (flags & FLAG) \
Rene Lindsay7fb1e012016-06-10 15:33:08 -07001337 printf("\t\t\t" #FLAG "\n");
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001338 PRINT_FLAG(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
1339 PRINT_FLAG(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
1340 PRINT_FLAG(VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
1341 PRINT_FLAG(VK_MEMORY_PROPERTY_HOST_CACHED_BIT)
1342 PRINT_FLAG(VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT)
Rene Lindsay7fb1e012016-06-10 15:33:08 -07001343#undef PRINT_FLAG
Mark Lobodzinski72346292015-07-02 16:49:40 -06001344 }
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001345 printf("\n");
Karl Schultz481756e2016-02-02 15:37:51 -07001346 printf("\tmemoryHeapCount = %u\n", props->memoryHeapCount);
Mark Lobodzinski72346292015-07-02 16:49:40 -06001347 for (uint32_t i = 0; i < props->memoryHeapCount; i++) {
1348 printf("\tmemoryHeaps[%u] : \n", i);
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001349 const VkDeviceSize memSize = props->memoryHeaps[i].size;
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -07001350 printf("\t\tsize = " PRINTF_SIZE_T_SPECIFIER " (0x%" PRIxLEAST64 ")\n", (size_t)memSize, memSize);
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001351
joey-lunargf0743b02016-11-07 11:27:00 -07001352 VkMemoryHeapFlags heap_flags = props->memoryHeaps[i].flags;
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001353 printf("\t\tflags: \n\t\t\t");
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -07001354 printf((heap_flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) ? "VK_MEMORY_HEAP_DEVICE_LOCAL_BIT\n" : "None\n");
Mark Lobodzinski72346292015-07-02 16:49:40 -06001355 }
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -06001356 fflush(stdout);
Chia-I Wud4bae362014-07-29 11:15:00 +08001357}
1358
joey-lunargf0743b02016-11-07 11:27:00 -07001359static void AppGpuDump(const struct AppGpu *gpu) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001360 uint32_t i;
Chia-I Wuf5c46f42014-08-05 15:33:40 +08001361
Rene Lindsaycb6b5ca2016-06-21 15:02:10 -07001362 printf("\nDevice Properties and Extensions :\n");
Rene Lindsay9652e552016-06-22 15:46:48 -07001363 printf("==================================\n");
Chia-I Wu190ebdc2014-08-06 12:04:13 +08001364 printf("GPU%u\n", gpu->id);
joey-lunargf0743b02016-11-07 11:27:00 -07001365 AppGpuDumpProps(gpu);
Chia-I Wu190ebdc2014-08-06 12:04:13 +08001366 printf("\n");
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -07001367 AppDumpExtensions("", "Device", gpu->device_extension_count, gpu->device_extensions);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -06001368 printf("\n");
Chia-I Wu190ebdc2014-08-06 12:04:13 +08001369 for (i = 0; i < gpu->queue_count; i++) {
joey-lunargf0743b02016-11-07 11:27:00 -07001370 AppGpuDumpQueueProps(gpu, i);
Chia-I Wu190ebdc2014-08-06 12:04:13 +08001371 printf("\n");
1372 }
joey-lunargf0743b02016-11-07 11:27:00 -07001373 AppGpuDumpMemoryProps(gpu);
Chia-I Wu190ebdc2014-08-06 12:04:13 +08001374 printf("\n");
joey-lunargf0743b02016-11-07 11:27:00 -07001375 AppGpuDumpFeatures(gpu);
Chris Forbesa048b312015-06-21 20:09:12 +12001376 printf("\n");
joey-lunargf0743b02016-11-07 11:27:00 -07001377 AppDevDump(&gpu->dev);
Chia-I Wud4bae362014-07-29 11:15:00 +08001378}
1379
Hugo Landaua3b71702016-02-16 15:44:03 +00001380#ifdef _WIN32
1381// Enlarges the console window to have a large scrollback size.
1382static void ConsoleEnlarge() {
joey-lunargf0743b02016-11-07 11:27:00 -07001383 HANDLE console_handle = GetStdHandle(STD_OUTPUT_HANDLE);
Hugo Landaua3b71702016-02-16 15:44:03 +00001384
1385 // make the console window bigger
1386 CONSOLE_SCREEN_BUFFER_INFO csbi;
joey-lunargf0743b02016-11-07 11:27:00 -07001387 COORD buffer_size;
1388 if (GetConsoleScreenBufferInfo(console_handle, &csbi)) {
1389 buffer_size.X = csbi.dwSize.X + 30;
1390 buffer_size.Y = 20000;
1391 SetConsoleScreenBufferSize(console_handle, buffer_size);
Hugo Landaua3b71702016-02-16 15:44:03 +00001392 }
1393
1394 SMALL_RECT r;
1395 r.Left = r.Top = 0;
1396 r.Right = csbi.dwSize.X - 1 + 30;
1397 r.Bottom = 50;
joey-lunargf0743b02016-11-07 11:27:00 -07001398 SetConsoleWindowInfo(console_handle, true, &r);
Hugo Landaua3b71702016-02-16 15:44:03 +00001399
1400 // change the console window title
1401 SetConsoleTitle(TEXT(APP_SHORT_NAME));
1402}
1403#endif
1404
Karl Schultz481756e2016-02-02 15:37:51 -07001405int main(int argc, char **argv) {
David Pinedo7b4e9ec2015-10-19 15:22:28 -06001406 unsigned int major, minor, patch;
Karl Schultz242a9c92017-01-11 12:15:58 -07001407 struct AppGpu *gpus;
1408 VkPhysicalDevice *objs;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001409 uint32_t gpu_count, i;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001410 VkResult err;
joey-lunargf0743b02016-11-07 11:27:00 -07001411 struct AppInstance inst;
Chia-I Wud4bae362014-07-29 11:15:00 +08001412
Hugo Landaua3b71702016-02-16 15:44:03 +00001413#ifdef _WIN32
1414 if (ConsoleIsExclusive())
1415 ConsoleEnlarge();
1416#endif
1417
Rene Lindsay3c877cd2016-05-23 13:00:53 -07001418 major = VK_VERSION_MAJOR(VK_API_VERSION_1_0);
1419 minor = VK_VERSION_MINOR(VK_API_VERSION_1_0);
1420 patch = VK_VERSION_PATCH(VK_HEADER_VERSION);
1421
David Pinedo7b4e9ec2015-10-19 15:22:28 -06001422 printf("===========\n");
Karl Schultz481756e2016-02-02 15:37:51 -07001423 printf("VULKAN INFO\n");
David Pinedob5ec4c22015-10-19 15:15:34 -06001424 printf("===========\n\n");
Mark Lobodzinskiab5e3be2016-01-13 10:36:44 -07001425 printf("Vulkan API Version: %d.%d.%d\n\n", major, minor, patch);
David Pinedob5ec4c22015-10-19 15:15:34 -06001426
joey-lunargf0743b02016-11-07 11:27:00 -07001427 AppCreateInstance(&inst);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -06001428
Rene Lindsaycb6b5ca2016-06-21 15:02:10 -07001429 printf("\nInstance Extensions:\n");
Rene Lindsay9652e552016-06-22 15:46:48 -07001430 printf("====================\n");
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -07001431 AppDumpExtensions("", "Instance", inst.global_extension_count, inst.global_extensions);
Mark Lobodzinski825cc512015-08-14 10:30:30 -06001432
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -06001433 err = vkEnumeratePhysicalDevices(inst.instance, &gpu_count, NULL);
Jon Ashburn07b309a2015-04-15 11:31:12 -06001434 if (err)
1435 ERR_EXIT(err);
Karl Schultz242a9c92017-01-11 12:15:58 -07001436 objs = malloc(sizeof(objs[0]) * gpu_count);
1437 if (!objs)
1438 ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -06001439 err = vkEnumeratePhysicalDevices(inst.instance, &gpu_count, objs);
Chia-I Wu190ebdc2014-08-06 12:04:13 +08001440 if (err)
1441 ERR_EXIT(err);
Chia-I Wud4bae362014-07-29 11:15:00 +08001442
Karl Schultz242a9c92017-01-11 12:15:58 -07001443 gpus = malloc(sizeof(gpus[0]) * gpu_count);
1444 if (!gpus)
1445 ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu190ebdc2014-08-06 12:04:13 +08001446 for (i = 0; i < gpu_count; i++) {
joey-lunargf0743b02016-11-07 11:27:00 -07001447 AppGpuInit(&gpus[i], i, objs[i]);
Chia-I Wu190ebdc2014-08-06 12:04:13 +08001448 printf("\n\n");
1449 }
Chia-I Wud4bae362014-07-29 11:15:00 +08001450
Rene Lindsaycb6b5ca2016-06-21 15:02:10 -07001451 //---Layer-Device-Extensions---
1452 printf("Layers: count = %d\n", inst.global_layer_count);
1453 printf("=======\n");
1454 for (uint32_t i = 0; i < inst.global_layer_count; i++) {
1455 uint32_t major, minor, patch;
1456 char spec_version[64], layer_version[64];
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -07001457 VkLayerProperties const *layer_prop = &inst.global_layers[i].layer_properties;
Rene Lindsaycb6b5ca2016-06-21 15:02:10 -07001458
joey-lunargf0743b02016-11-07 11:27:00 -07001459 ExtractVersion(layer_prop->specVersion, &major, &minor, &patch);
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -07001460 snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", major, minor, patch);
1461 snprintf(layer_version, sizeof(layer_version), "%d", layer_prop->implementationVersion);
1462 printf("%s (%s) Vulkan version %s, layer version %s\n", layer_prop->layerName, (char *)layer_prop->description,
Rene Lindsaycb6b5ca2016-06-21 15:02:10 -07001463 spec_version, layer_version);
1464
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -07001465 AppDumpExtensions("\t", "Layer", inst.global_layers[i].extension_count, inst.global_layers[i].extension_properties);
Rene Lindsaycb6b5ca2016-06-21 15:02:10 -07001466
joey-lunargf0743b02016-11-07 11:27:00 -07001467 char *layer_name = inst.global_layers[i].layer_properties.layerName;
Rene Lindsay9652e552016-06-22 15:46:48 -07001468 printf("\tDevices \tcount = %d\n", gpu_count);
Rene Lindsaycb6b5ca2016-06-21 15:02:10 -07001469 for (uint32_t j = 0; j < gpu_count; j++) {
1470 printf("\t\tGPU id : %u (%s)\n", j, gpus[j].props.deviceName);
Rene Lindsay9652e552016-06-22 15:46:48 -07001471 uint32_t count = 0;
1472 VkExtensionProperties *props;
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -07001473 AppGetPhysicalDeviceLayerExtensions(&gpus[j], layer_name, &count, &props);
joey-lunargf0743b02016-11-07 11:27:00 -07001474 AppDumpExtensions("\t\t", "Layer-Device", count, props);
Rene Lindsaycb6b5ca2016-06-21 15:02:10 -07001475 free(props);
1476 }
1477 printf("\n");
1478 }
1479 fflush(stdout);
1480 //-----------------------------
1481
joey-lunarg7b3aade2016-11-02 14:36:19 -06001482 printf("Presentable Surfaces:\n");
1483 printf("=====================\n");
Rene Lindsay7fb1e012016-06-10 15:33:08 -07001484 inst.width = 256;
1485 inst.height = 256;
joey-lunargf0743b02016-11-07 11:27:00 -07001486 int format_count = 0;
1487 int present_mode_count = 0;
Rene Lindsaya155d622016-06-10 08:26:26 -07001488
Tony Barbourb6bbc992016-12-09 11:27:26 -07001489#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
1490 if (getenv("DISPLAY") == NULL) {
1491 printf("'DISPLAY' environment variable not set... Exiting!\n");
1492 fflush(stdout);
1493 exit(1);
1494 }
1495#endif
Rene Lindsay7fb1e012016-06-10 15:33:08 -07001496//--WIN32--
Rene Lindsaya155d622016-06-10 08:26:26 -07001497#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -07001498 if (HasExtension(VK_KHR_WIN32_SURFACE_EXTENSION_NAME, inst.global_extension_count, inst.global_extensions)) {
joey-lunargf0743b02016-11-07 11:27:00 -07001499 AppCreateWin32Window(&inst);
Rene Lindsay9652e552016-06-22 15:46:48 -07001500 for (i = 0; i < gpu_count; i++) {
joey-lunargf0743b02016-11-07 11:27:00 -07001501 AppCreateWin32Surface(&inst);
Rene Lindsay9652e552016-06-22 15:46:48 -07001502 printf("GPU id : %u (%s)\n", i, gpus[i].props.deviceName);
1503 printf("Surface type : %s\n", VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
joey-lunargf0743b02016-11-07 11:27:00 -07001504 format_count += AppDumpSurfaceFormats(&inst, &gpus[i]);
1505 present_mode_count += AppDumpSurfacePresentModes(&inst, &gpus[i]);
1506 AppDestroySurface(&inst);
Rene Lindsay9652e552016-06-22 15:46:48 -07001507 }
joey-lunargf0743b02016-11-07 11:27:00 -07001508 AppDestroyWin32Window(&inst);
Rene Lindsaya155d622016-06-10 08:26:26 -07001509 }
Rene Lindsay7fb1e012016-06-10 15:33:08 -07001510//--XCB--
Tony Barbourb6bbc992016-12-09 11:27:26 -07001511#elif VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -07001512 if (HasExtension(VK_KHR_XCB_SURFACE_EXTENSION_NAME, inst.global_extension_count, inst.global_extensions)) {
joey-lunargf0743b02016-11-07 11:27:00 -07001513 AppCreateXcbWindow(&inst);
Rene Lindsay9652e552016-06-22 15:46:48 -07001514 for (i = 0; i < gpu_count; i++) {
joey-lunargf0743b02016-11-07 11:27:00 -07001515 AppCreateXcbSurface(&inst);
Rene Lindsay9652e552016-06-22 15:46:48 -07001516 printf("GPU id : %u (%s)\n", i, gpus[i].props.deviceName);
1517 printf("Surface type : %s\n", VK_KHR_XCB_SURFACE_EXTENSION_NAME);
joey-lunargf0743b02016-11-07 11:27:00 -07001518 format_count += AppDumpSurfaceFormats(&inst, &gpus[i]);
1519 present_mode_count += AppDumpSurfacePresentModes(&inst, &gpus[i]);
1520 AppDestroySurface(&inst);
Rene Lindsay9652e552016-06-22 15:46:48 -07001521 }
joey-lunargf0743b02016-11-07 11:27:00 -07001522 AppDestroyXcbWindow(&inst);
Rene Lindsaya155d622016-06-10 08:26:26 -07001523 }
Rene Lindsay7fb1e012016-06-10 15:33:08 -07001524//--XLIB--
Tony Barbourb6bbc992016-12-09 11:27:26 -07001525#elif VK_USE_PLATFORM_XLIB_KHR
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -07001526 if (HasExtension(VK_KHR_XLIB_SURFACE_EXTENSION_NAME, inst.global_extension_count, inst.global_extensions)) {
joey-lunargf0743b02016-11-07 11:27:00 -07001527 AppCreateXlibWindow(&inst);
Rene Lindsay9652e552016-06-22 15:46:48 -07001528 for (i = 0; i < gpu_count; i++) {
joey-lunargf0743b02016-11-07 11:27:00 -07001529 AppCreateXlibSurface(&inst);
Rene Lindsay9652e552016-06-22 15:46:48 -07001530 printf("GPU id : %u (%s)\n", i, gpus[i].props.deviceName);
1531 printf("Surface type : %s\n", VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
joey-lunargf0743b02016-11-07 11:27:00 -07001532 format_count += AppDumpSurfaceFormats(&inst, &gpus[i]);
1533 present_mode_count += AppDumpSurfacePresentModes(&inst, &gpus[i]);
1534 AppDestroySurface(&inst);
Rene Lindsay9652e552016-06-22 15:46:48 -07001535 }
joey-lunargf0743b02016-11-07 11:27:00 -07001536 AppDestroyXlibWindow(&inst);
Rene Lindsaya155d622016-06-10 08:26:26 -07001537 }
Rene Lindsaya155d622016-06-10 08:26:26 -07001538#endif
Rene Lindsay7fb1e012016-06-10 15:33:08 -07001539 // TODO: Android / Wayland / MIR
joey-lunargf0743b02016-11-07 11:27:00 -07001540 if (!format_count && !present_mode_count)
Rene Lindsay7fb1e012016-06-10 15:33:08 -07001541 printf("None found\n");
Rene Lindsaya155d622016-06-10 08:26:26 -07001542 //---------
1543
Rene Lindsaycb6b5ca2016-06-21 15:02:10 -07001544 for (i = 0; i < gpu_count; i++) {
joey-lunargf0743b02016-11-07 11:27:00 -07001545 AppGpuDump(&gpus[i]);
Rene Lindsaycb6b5ca2016-06-21 15:02:10 -07001546 printf("\n\n");
1547 }
1548
Chia-I Wu190ebdc2014-08-06 12:04:13 +08001549 for (i = 0; i < gpu_count; i++)
joey-lunargf0743b02016-11-07 11:27:00 -07001550 AppGpuDestroy(&gpus[i]);
Karl Schultz242a9c92017-01-11 12:15:58 -07001551 free(gpus);
1552 free(objs);
Chia-I Wud4bae362014-07-29 11:15:00 +08001553
joey-lunargf0743b02016-11-07 11:27:00 -07001554 AppDestroyInstance(&inst);
Chia-I Wu0b9a7372014-08-06 12:09:19 +08001555
Hugo Landaua3b71702016-02-16 15:44:03 +00001556 fflush(stdout);
1557#ifdef _WIN32
1558 if (ConsoleIsExclusive())
1559 Sleep(INFINITE);
1560#endif
1561
Chia-I Wu190ebdc2014-08-06 12:04:13 +08001562 return 0;
Chia-I Wud4bae362014-07-29 11:15:00 +08001563}