blob: 482f27aea8cb1a10a847602685f9993c1113fb56 [file] [log] [blame]
Chia-I Wu46c29dd2014-12-02 21:09:20 +08001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Chia-I Wu46c29dd2014-12-02 21:09:20 +08003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
Chia-I Wud4bae362014-07-29 11:15:00 +080024#include <stdlib.h>
25#include <stdio.h>
26#include <stdbool.h>
27#include <string.h>
Chia-I Wu46c29dd2014-12-02 21:09:20 +080028#include <assert.h>
Mark Lobodzinski825cc512015-08-14 10:30:30 -060029#include <inttypes.h>
Chia-I Wud4bae362014-07-29 11:15:00 +080030
Ian Elliottea95f5c2015-04-17 21:23:34 -060031#ifdef _WIN32
32#include <Windows.h>
David Pinedo18fb9232015-04-21 14:45:16 -060033#include <fcntl.h>
34#include <io.h>
Ian Elliottea95f5c2015-04-17 21:23:34 -060035#endif
36
Ian Elliott338dedb2015-08-21 15:09:33 -060037#include "vk_ext_khr_swapchain.h"
38#include "vk_ext_khr_device_swapchain.h"
Ian Elliotte36b2082015-07-06 14:27:58 -060039
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060040#include <vulkan.h>
Chia-I Wu46c29dd2014-12-02 21:09:20 +080041
42#define ERR(err) printf("%s:%d: failed with %s\n", \
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060043 __FILE__, __LINE__, vk_result_string(err));
Chia-I Wu46c29dd2014-12-02 21:09:20 +080044
David Pinedo18fb9232015-04-21 14:45:16 -060045#ifdef _WIN32
46
Ian Elliott7c83aa22015-07-08 17:09:54 -060047#define snprintf _snprintf
48
David Pinedo18fb9232015-04-21 14:45:16 -060049bool consoleCreated = false;
50
51#define WAIT_FOR_CONSOLE_DESTROY \
52 do { \
53 if (consoleCreated) \
54 Sleep(INFINITE); \
55 } while (0)
56#else
57 #define WAIT_FOR_CONSOLE_DESTROY
58#endif
59
60
61#define ERR_EXIT(err) \
62 do { \
63 ERR(err); \
64 fflush(stdout); \
65 WAIT_FOR_CONSOLE_DESTROY; \
66 exit(-1); \
67 } while (0)
Chia-I Wu46c29dd2014-12-02 21:09:20 +080068
Tony Barbour22a30862015-04-22 09:02:32 -060069#if defined(NDEBUG) && defined(__GNUC__)
70#define U_ASSERT_ONLY __attribute__((unused))
71#else
72#define U_ASSERT_ONLY
73#endif
74
Chia-I Wu46c29dd2014-12-02 21:09:20 +080075#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
76
77#define MAX_GPUS 8
78
79#define MAX_QUEUE_TYPES 5
Ian Elliott4e19ed02015-04-28 10:52:52 -060080#define APP_SHORT_NAME "vulkaninfo"
Chia-I Wu46c29dd2014-12-02 21:09:20 +080081
82struct app_gpu;
83
84struct app_dev {
85 struct app_gpu *gpu; /* point back to the GPU */
86
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060087 VkDevice obj;
Chia-I Wu46c29dd2014-12-02 21:09:20 +080088
Chia-I Wu46c29dd2014-12-02 21:09:20 +080089
Courtney Goeltzenleuchterab36aa62015-07-12 12:40:29 -060090 VkFormatProperties format_props[VK_FORMAT_NUM];
Chia-I Wu46c29dd2014-12-02 21:09:20 +080091};
92
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -060093struct layer_extension_list {
94 VkLayerProperties layer_properties;
95 uint32_t extension_count;
96 VkExtensionProperties *extension_properties;
97};
98
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -060099struct app_instance {
100 VkInstance instance;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600101 uint32_t global_layer_count;
102 struct layer_extension_list *global_layers;
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600103 uint32_t global_extension_count;
104 VkExtensionProperties *global_extensions;
105};
106
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800107struct app_gpu {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600108 uint32_t id;
Tony Barbour8205d902015-04-16 15:59:00 -0600109 VkPhysicalDevice obj;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800110
Tony Barbour8205d902015-04-16 15:59:00 -0600111 VkPhysicalDeviceProperties props;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800112
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600113 uint32_t queue_count;
Cody Northropef72e2a2015-08-03 17:04:53 -0600114 VkQueueFamilyProperties *queue_props;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600115 VkDeviceQueueCreateInfo *queue_reqs;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800116
Tony Barbour8205d902015-04-16 15:59:00 -0600117 VkPhysicalDeviceMemoryProperties memory_props;
Chris Forbesa048b312015-06-21 20:09:12 +1200118 VkPhysicalDeviceFeatures features;
Mark Lobodzinski7dae6862015-09-07 12:56:17 -0600119 VkPhysicalDevice limits;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800120
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600121 uint32_t device_layer_count;
122 struct layer_extension_list *device_layers;
123
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600124 uint32_t device_extension_count;
125 VkExtensionProperties *device_extensions;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800126
127 struct app_dev dev;
128};
129
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600130static const char *vk_result_string(VkResult err)
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800131{
132 switch (err) {
133#define STR(r) case r: return #r
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600134 STR(VK_SUCCESS);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600135 STR(VK_NOT_READY);
136 STR(VK_TIMEOUT);
137 STR(VK_EVENT_SET);
138 STR(VK_EVENT_RESET);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600139 STR(VK_ERROR_INITIALIZATION_FAILED);
Tony Barbour8205d902015-04-16 15:59:00 -0600140 STR(VK_ERROR_OUT_OF_HOST_MEMORY);
141 STR(VK_ERROR_OUT_OF_DEVICE_MEMORY);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600142 STR(VK_ERROR_DEVICE_LOST);
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -0600143 STR(VK_ERROR_LAYER_NOT_PRESENT);
144 STR(VK_ERROR_EXTENSION_NOT_PRESENT);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600145 STR(VK_ERROR_MEMORY_MAP_FAILED);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600146 STR(VK_ERROR_INCOMPATIBLE_DRIVER);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800147#undef STR
148 default: return "UNKNOWN_RESULT";
149 }
150}
Chia-I Wud4bae362014-07-29 11:15:00 +0800151
Tony Barbour8205d902015-04-16 15:59:00 -0600152static const char *vk_physical_device_type_string(VkPhysicalDeviceType type)
Chia-I Wud4bae362014-07-29 11:15:00 +0800153{
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800154 switch (type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600155#define STR(r) case VK_PHYSICAL_DEVICE_TYPE_ ##r: return #r
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800156 STR(OTHER);
Tony Barbour8205d902015-04-16 15:59:00 -0600157 STR(INTEGRATED_GPU);
158 STR(DISCRETE_GPU);
159 STR(VIRTUAL_GPU);
Chia-I Wud4bae362014-07-29 11:15:00 +0800160#undef STR
Tony Barbour8205d902015-04-16 15:59:00 -0600161 default: return "UNKNOWN_DEVICE";
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800162 }
Chia-I Wud4bae362014-07-29 11:15:00 +0800163}
164
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600165static const char *vk_format_string(VkFormat fmt)
Chia-I Wud4bae362014-07-29 11:15:00 +0800166{
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700167 switch (fmt) {
Tony Barbour8205d902015-04-16 15:59:00 -0600168#define STR(r) case VK_FORMAT_ ##r: return #r
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800169 STR(UNDEFINED);
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700170 STR(R4G4_UNORM);
171 STR(R4G4_USCALED);
172 STR(R4G4B4A4_UNORM);
173 STR(R4G4B4A4_USCALED);
174 STR(R5G6B5_UNORM);
175 STR(R5G6B5_USCALED);
176 STR(R5G5B5A1_UNORM);
177 STR(R5G5B5A1_USCALED);
178 STR(R8_UNORM);
179 STR(R8_SNORM);
180 STR(R8_USCALED);
181 STR(R8_SSCALED);
182 STR(R8_UINT);
183 STR(R8_SINT);
184 STR(R8_SRGB);
185 STR(R8G8_UNORM);
186 STR(R8G8_SNORM);
187 STR(R8G8_USCALED);
188 STR(R8G8_SSCALED);
189 STR(R8G8_UINT);
190 STR(R8G8_SINT);
191 STR(R8G8_SRGB);
192 STR(R8G8B8_UNORM);
193 STR(R8G8B8_SNORM);
194 STR(R8G8B8_USCALED);
195 STR(R8G8B8_SSCALED);
196 STR(R8G8B8_UINT);
197 STR(R8G8B8_SINT);
198 STR(R8G8B8_SRGB);
199 STR(R8G8B8A8_UNORM);
200 STR(R8G8B8A8_SNORM);
201 STR(R8G8B8A8_USCALED);
202 STR(R8G8B8A8_SSCALED);
203 STR(R8G8B8A8_UINT);
204 STR(R8G8B8A8_SINT);
205 STR(R8G8B8A8_SRGB);
206 STR(R10G10B10A2_UNORM);
207 STR(R10G10B10A2_SNORM);
208 STR(R10G10B10A2_USCALED);
209 STR(R10G10B10A2_SSCALED);
210 STR(R10G10B10A2_UINT);
211 STR(R10G10B10A2_SINT);
212 STR(R16_UNORM);
213 STR(R16_SNORM);
214 STR(R16_USCALED);
215 STR(R16_SSCALED);
216 STR(R16_UINT);
217 STR(R16_SINT);
218 STR(R16_SFLOAT);
219 STR(R16G16_UNORM);
220 STR(R16G16_SNORM);
221 STR(R16G16_USCALED);
222 STR(R16G16_SSCALED);
223 STR(R16G16_UINT);
224 STR(R16G16_SINT);
225 STR(R16G16_SFLOAT);
226 STR(R16G16B16_UNORM);
227 STR(R16G16B16_SNORM);
228 STR(R16G16B16_USCALED);
229 STR(R16G16B16_SSCALED);
230 STR(R16G16B16_UINT);
231 STR(R16G16B16_SINT);
232 STR(R16G16B16_SFLOAT);
233 STR(R16G16B16A16_UNORM);
234 STR(R16G16B16A16_SNORM);
235 STR(R16G16B16A16_USCALED);
236 STR(R16G16B16A16_SSCALED);
237 STR(R16G16B16A16_UINT);
238 STR(R16G16B16A16_SINT);
239 STR(R16G16B16A16_SFLOAT);
240 STR(R32_UINT);
241 STR(R32_SINT);
242 STR(R32_SFLOAT);
243 STR(R32G32_UINT);
244 STR(R32G32_SINT);
245 STR(R32G32_SFLOAT);
246 STR(R32G32B32_UINT);
247 STR(R32G32B32_SINT);
248 STR(R32G32B32_SFLOAT);
249 STR(R32G32B32A32_UINT);
250 STR(R32G32B32A32_SINT);
251 STR(R32G32B32A32_SFLOAT);
252 STR(R64_SFLOAT);
253 STR(R64G64_SFLOAT);
254 STR(R64G64B64_SFLOAT);
255 STR(R64G64B64A64_SFLOAT);
256 STR(R11G11B10_UFLOAT);
257 STR(R9G9B9E5_UFLOAT);
258 STR(D16_UNORM);
Courtney Goeltzenleuchter7ed10592015-09-10 17:17:43 -0600259 STR(D24_UNORM_X8);
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700260 STR(D32_SFLOAT);
261 STR(S8_UINT);
262 STR(D16_UNORM_S8_UINT);
263 STR(D24_UNORM_S8_UINT);
264 STR(D32_SFLOAT_S8_UINT);
Courtney Goeltzenleuchterfe8a2e12015-03-03 11:30:36 -0700265 STR(BC1_RGB_UNORM);
266 STR(BC1_RGB_SRGB);
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700267 STR(BC2_UNORM);
268 STR(BC2_SRGB);
269 STR(BC3_UNORM);
270 STR(BC3_SRGB);
271 STR(BC4_UNORM);
272 STR(BC4_SNORM);
273 STR(BC5_UNORM);
274 STR(BC5_SNORM);
275 STR(BC6H_UFLOAT);
276 STR(BC6H_SFLOAT);
277 STR(BC7_UNORM);
278 STR(BC7_SRGB);
279 STR(ETC2_R8G8B8_UNORM);
280 STR(ETC2_R8G8B8A1_UNORM);
281 STR(ETC2_R8G8B8A8_UNORM);
282 STR(EAC_R11_UNORM);
283 STR(EAC_R11_SNORM);
284 STR(EAC_R11G11_UNORM);
285 STR(EAC_R11G11_SNORM);
286 STR(ASTC_4x4_UNORM);
287 STR(ASTC_4x4_SRGB);
Courtney Goeltzenleuchterfe8a2e12015-03-03 11:30:36 -0700288 STR(ASTC_5x4_UNORM);
289 STR(ASTC_5x4_SRGB);
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700290 STR(ASTC_5x5_UNORM);
291 STR(ASTC_5x5_SRGB);
292 STR(ASTC_6x5_UNORM);
293 STR(ASTC_6x5_SRGB);
294 STR(ASTC_6x6_UNORM);
295 STR(ASTC_6x6_SRGB);
296 STR(ASTC_8x5_UNORM);
297 STR(ASTC_8x5_SRGB);
298 STR(ASTC_8x6_UNORM);
299 STR(ASTC_8x6_SRGB);
300 STR(ASTC_8x8_UNORM);
301 STR(ASTC_8x8_SRGB);
302 STR(ASTC_10x5_UNORM);
303 STR(ASTC_10x5_SRGB);
304 STR(ASTC_10x6_UNORM);
305 STR(ASTC_10x6_SRGB);
306 STR(ASTC_10x8_UNORM);
307 STR(ASTC_10x8_SRGB);
308 STR(ASTC_10x10_UNORM);
309 STR(ASTC_10x10_SRGB);
310 STR(ASTC_12x10_UNORM);
311 STR(ASTC_12x10_SRGB);
312 STR(ASTC_12x12_UNORM);
313 STR(ASTC_12x12_SRGB);
314 STR(B5G6R5_UNORM);
315 STR(B5G6R5_USCALED);
316 STR(B8G8R8_UNORM);
317 STR(B8G8R8_SNORM);
318 STR(B8G8R8_USCALED);
319 STR(B8G8R8_SSCALED);
320 STR(B8G8R8_UINT);
321 STR(B8G8R8_SINT);
322 STR(B8G8R8_SRGB);
323 STR(B8G8R8A8_UNORM);
324 STR(B8G8R8A8_SNORM);
325 STR(B8G8R8A8_USCALED);
326 STR(B8G8R8A8_SSCALED);
327 STR(B8G8R8A8_UINT);
328 STR(B8G8R8A8_SINT);
329 STR(B8G8R8A8_SRGB);
330 STR(B10G10R10A2_UNORM);
331 STR(B10G10R10A2_SNORM);
332 STR(B10G10R10A2_USCALED);
333 STR(B10G10R10A2_SSCALED);
334 STR(B10G10R10A2_UINT);
335 STR(B10G10R10A2_SINT);
Chia-I Wud4bae362014-07-29 11:15:00 +0800336#undef STR
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700337 default: return "UNKNOWN_FORMAT";
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800338 }
Chia-I Wud4bae362014-07-29 11:15:00 +0800339}
340
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800341static void app_dev_init_formats(struct app_dev *dev)
342{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600343 VkFormat f;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800344
Courtney Goeltzenleuchterab36aa62015-07-12 12:40:29 -0600345 for (f = 0; f < VK_FORMAT_NUM; f++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600346 const VkFormat fmt = f;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800347
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600348 vkGetPhysicalDeviceFormatProperties(dev->gpu->obj, fmt, &dev->format_props[f]);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800349 }
350}
351
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600352static void extract_version(uint32_t version, uint32_t *major, uint32_t *minor, uint32_t *patch)
353{
354 *major = version >> 22;
355 *minor = (version >> 12) & 0x3ff;
356 *patch = version & 0xfff;
357}
358
359static void app_get_physical_device_layer_extensions(
360 struct app_gpu *gpu,
361 char *layer_name,
362 uint32_t *extension_count,
363 VkExtensionProperties **extension_properties)
364{
365 VkResult err;
366 uint32_t ext_count = 0;
367 VkExtensionProperties *ext_ptr = NULL;
368
369 /* repeat get until VK_INCOMPLETE goes away */
370 do {
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -0600371 err = vkEnumerateDeviceExtensionProperties(gpu->obj, layer_name, &ext_count, NULL);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600372 assert(!err);
373
374 if (ext_ptr) {
375 free(ext_ptr);
376 }
377 ext_ptr = malloc(ext_count * sizeof(VkExtensionProperties));
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -0600378 err = vkEnumerateDeviceExtensionProperties(gpu->obj, layer_name, &ext_count, ext_ptr);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600379 } while (err == VK_INCOMPLETE);
380 assert(!err);
381
382 *extension_count = ext_count;
383 *extension_properties = ext_ptr;
384}
385
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800386static void app_dev_init(struct app_dev *dev, struct app_gpu *gpu)
387{
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600388 VkDeviceCreateInfo info = {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600389 .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800390 .pNext = NULL,
Courtney Goeltzenleuchterdfd53f52015-10-15 16:58:44 -0600391 .requestedQueueCount = 0,
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800392 .pRequestedQueues = NULL,
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600393 .layerCount = 0,
394 .ppEnabledLayerNames = NULL,
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800395 .extensionCount = 0,
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600396 .ppEnabledExtensionNames = NULL,
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800397 };
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600398 VkResult U_ASSERT_ONLY err;
399 // Extensions to enable
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600400 static const char *known_extensions[] = {
Ian Elliott338dedb2015-08-21 15:09:33 -0600401 VK_EXT_KHR_DEVICE_SWAPCHAIN_EXTENSION_NAME,
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600402 };
Tony Barbour426b9052015-06-24 16:06:58 -0600403
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600404 uint32_t count = 0;
405
406 /* Scan layers */
407 VkLayerProperties *device_layer_properties = NULL;
408 struct layer_extension_list *device_layers = NULL;
409
410 do {
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -0600411 err = vkEnumerateDeviceLayerProperties(gpu->obj, &count, NULL);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600412 assert(!err);
413
414 if (device_layer_properties) {
415 free(device_layer_properties);
416 }
417 device_layer_properties = malloc(sizeof(VkLayerProperties) * count);
418 assert(device_layer_properties);
419
420 if (device_layers) {
421 free(device_layers);
422 }
423 device_layers = malloc(sizeof(struct layer_extension_list) * count);
424 assert(device_layers);
425
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -0600426 err = vkEnumerateDeviceLayerProperties(gpu->obj, &count, device_layer_properties);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600427 } while (err == VK_INCOMPLETE);
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600428 assert(!err);
429
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600430 gpu->device_layer_count = count;
431 gpu->device_layers = device_layers;
432
433 for (uint32_t i = 0; i < gpu->device_layer_count; i++) {
434 VkLayerProperties *src_info = &device_layer_properties[i];
435 struct layer_extension_list *dst_info = &gpu->device_layers[i];
436 memcpy(&dst_info->layer_properties, src_info, sizeof(VkLayerProperties));
437
438 /* Save away layer extension info for report */
439 app_get_physical_device_layer_extensions(
440 gpu,
441 src_info->layerName,
442 &dst_info->extension_count,
443 &dst_info->extension_properties);
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600444 }
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600445 free(device_layer_properties);
446
447 app_get_physical_device_layer_extensions(
448 gpu,
449 NULL,
450 &gpu->device_extension_count,
451 &gpu->device_extensions);
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600452
Courtney Goeltzenleuchter9e42b882015-06-25 16:24:36 -0600453 fflush(stdout);
454
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600455 uint32_t enabled_extension_count = 0;
Courtney Goeltzenleuchter67a07412015-07-10 10:10:27 -0600456 uint32_t known_extension_count = ARRAY_SIZE(known_extensions);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600457
Courtney Goeltzenleuchter67a07412015-07-10 10:10:27 -0600458 for (uint32_t i = 0; i < known_extension_count; i++) {
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600459 VkBool32 extension_found = 0;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600460 for (uint32_t j = 0; j < gpu->device_extension_count; j++) {
461 VkExtensionProperties *ext_prop = &gpu->device_extensions[j];
462 if (!strcmp(known_extensions[i], ext_prop->extName)) {
463
464 extension_found = 1;
465 enabled_extension_count++;
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600466 }
467 }
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600468 if (!extension_found) {
469 printf("Cannot find extension: %s\n", known_extensions[i]);
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -0600470 ERR_EXIT(VK_ERROR_EXTENSION_NOT_PRESENT);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600471 }
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600472 }
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800473
474 /* request all queues */
Courtney Goeltzenleuchterdfd53f52015-10-15 16:58:44 -0600475 info.requestedQueueCount = gpu->queue_count;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800476 info.pRequestedQueues = gpu->queue_reqs;
477
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600478 info.layerCount = 0;
479 info.ppEnabledLayerNames = NULL;
480 info.extensionCount = enabled_extension_count;
481 info.ppEnabledExtensionNames = (const char*const*) known_extensions;
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600482 dev->gpu = gpu;
483 err = vkCreateDevice(gpu->obj, &info, &dev->obj);
484 if (err)
485 ERR_EXIT(err);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800486
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800487}
488
489static void app_dev_destroy(struct app_dev *dev)
490{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600491 vkDestroyDevice(dev->obj);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800492}
493
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600494static void app_get_global_layer_extensions(
495 char *layer_name,
496 uint32_t *extension_count,
497 VkExtensionProperties **extension_properties)
498{
499 VkResult err;
500 uint32_t ext_count = 0;
501 VkExtensionProperties *ext_ptr = NULL;
502
503 /* repeat get until VK_INCOMPLETE goes away */
504 do {
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -0600505 err = vkEnumerateInstanceExtensionProperties(layer_name, &ext_count, NULL);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600506 assert(!err);
507
508 if (ext_ptr) {
509 free(ext_ptr);
510 }
511 ext_ptr = malloc(ext_count * sizeof(VkExtensionProperties));
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -0600512 err = vkEnumerateInstanceExtensionProperties(layer_name, &ext_count, ext_ptr);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600513 } while (err == VK_INCOMPLETE);
514 assert(!err);
515
516 *extension_count = ext_count;
517 *extension_properties = ext_ptr;
518}
519
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600520static void app_create_instance(struct app_instance *inst)
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800521{
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600522 const VkApplicationInfo app_info = {
523 .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
524 .pNext = NULL,
525 .pAppName = APP_SHORT_NAME,
526 .appVersion = 1,
527 .pEngineName = APP_SHORT_NAME,
528 .engineVersion = 1,
529 .apiVersion = VK_API_VERSION,
530 };
531 VkInstanceCreateInfo inst_info = {
532 .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
533 .pNext = NULL,
534 .pAppInfo = &app_info,
535 .pAllocCb = NULL,
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600536 .layerCount = 0,
537 .ppEnabledLayerNames = NULL,
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600538 .extensionCount = 0,
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600539 .ppEnabledExtensionNames = NULL,
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600540 };
Tony Barbour22a30862015-04-22 09:02:32 -0600541 VkResult U_ASSERT_ONLY err;
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600542 // Global Extensions to enable
Ian Elliottaae1a572015-02-04 16:48:37 -0700543 static char *known_extensions[] = {
Ian Elliott338dedb2015-08-21 15:09:33 -0600544 "VK_EXT_KHR_swapchain",
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800545 };
Tony Barbour426b9052015-06-24 16:06:58 -0600546
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600547 uint32_t global_extension_count = 0;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600548 uint32_t count = 0;
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600549
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600550 /* Scan layers */
551 VkLayerProperties *global_layer_properties = NULL;
552 struct layer_extension_list *global_layers = NULL;
553
554 do {
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -0600555 err = vkEnumerateInstanceLayerProperties(&count, NULL);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600556 assert(!err);
557
558 if (global_layer_properties) {
559 free(global_layer_properties);
560 }
561 global_layer_properties = malloc(sizeof(VkLayerProperties) * count);
562 assert(global_layer_properties);
563
564 if (global_layers) {
565 free(global_layers);
566 }
567 global_layers = malloc(sizeof(struct layer_extension_list) * count);
568 assert(global_layers);
569
Courtney Goeltzenleuchter74c4ce92015-09-14 17:22:16 -0600570 err = vkEnumerateInstanceLayerProperties(&count, global_layer_properties);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600571 } while (err == VK_INCOMPLETE);
Tobin Ehlis3536b442015-04-16 18:04:57 -0600572 assert(!err);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800573
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600574 inst->global_layer_count = count;
575 inst->global_layers = global_layers;
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600576
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600577 for (uint32_t i = 0; i < inst->global_layer_count; i++) {
578 VkLayerProperties *src_info = &global_layer_properties[i];
579 struct layer_extension_list *dst_info = &inst->global_layers[i];
580 memcpy(&dst_info->layer_properties, src_info, sizeof(VkLayerProperties));
581
582 /* Save away layer extension info for report */
583 app_get_global_layer_extensions(
584 src_info->layerName,
585 &dst_info->extension_count,
586 &dst_info->extension_properties);
587 }
588 free(global_layer_properties);
589
590 /* Collect global extensions */
591 inst->global_extension_count = 0;
592 app_get_global_layer_extensions(
593 NULL,
594 &inst->global_extension_count,
595 &inst->global_extensions);
596
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600597 for (uint32_t i = 0; i < ARRAY_SIZE(known_extensions); i++) {
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600598 VkBool32 extension_found = 0;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600599 for (uint32_t j = 0; j < inst->global_extension_count; j++) {
600 VkExtensionProperties *extension_prop = &inst->global_extensions[j];
601 if (!strcmp(known_extensions[i], extension_prop->extName)) {
602
603 extension_found = 1;
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600604 global_extension_count++;
605 }
Tobin Ehlis3536b442015-04-16 18:04:57 -0600606 }
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600607 if (!extension_found) {
608 printf("Cannot find extension: %s\n", known_extensions[i]);
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -0600609 ERR_EXIT(VK_ERROR_EXTENSION_NOT_PRESENT);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600610 }
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800611 }
612
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600613 inst_info.extensionCount = global_extension_count;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600614 inst_info.ppEnabledExtensionNames = (const char * const *) known_extensions;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800615
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600616 err = vkCreateInstance(&inst_info, &inst->instance);
617 if (err == VK_ERROR_INCOMPATIBLE_DRIVER) {
618 printf("Cannot create Vulkan instance.\n");
619 ERR_EXIT(err);
620 } else if (err) {
621 ERR_EXIT(err);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800622 }
623}
624
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600625static void app_destroy_instance(struct app_instance *inst)
626{
627 free(inst->global_extensions);
628 vkDestroyInstance(inst->instance);
629}
630
631
Tony Barbour8205d902015-04-16 15:59:00 -0600632static void app_gpu_init(struct app_gpu *gpu, uint32_t id, VkPhysicalDevice obj)
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800633{
Ian Elliottaae1a572015-02-04 16:48:37 -0700634 uint32_t i;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800635
636 memset(gpu, 0, sizeof(*gpu));
637
638 gpu->id = id;
639 gpu->obj = obj;
Tony Barbour426b9052015-06-24 16:06:58 -0600640
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600641 vkGetPhysicalDeviceProperties(gpu->obj, &gpu->props);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800642
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800643 /* get queue count */
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600644 vkGetPhysicalDeviceQueueFamilyProperties(gpu->obj, &gpu->queue_count, NULL);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800645
646 gpu->queue_props =
647 malloc(sizeof(gpu->queue_props[0]) * gpu->queue_count);
Tony Barbour426b9052015-06-24 16:06:58 -0600648
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800649 if (!gpu->queue_props)
Tony Barbour8205d902015-04-16 15:59:00 -0600650 ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600651 vkGetPhysicalDeviceQueueFamilyProperties(gpu->obj, &gpu->queue_count, gpu->queue_props);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800652
653 /* set up queue requests */
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800654 gpu->queue_reqs = malloc(sizeof(*gpu->queue_reqs) * gpu->queue_count);
655 if (!gpu->queue_reqs)
Tony Barbour8205d902015-04-16 15:59:00 -0600656 ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800657 for (i = 0; i < gpu->queue_count; i++) {
Courtney Goeltzenleuchterea975642015-09-16 16:23:55 -0600658 gpu->queue_reqs[i].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
659 gpu->queue_reqs[i].pNext = NULL;
Chris Forbesfa6d36e2015-07-11 19:11:39 +1200660 gpu->queue_reqs[i].queueFamilyIndex = i;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800661 gpu->queue_reqs[i].queueCount = gpu->queue_props[i].queueCount;
662 }
663
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600664 vkGetPhysicalDeviceMemoryProperties(gpu->obj, &gpu->memory_props);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800665
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600666 vkGetPhysicalDeviceFeatures(gpu->obj, &gpu->features);
Chris Forbesa048b312015-06-21 20:09:12 +1200667
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800668 app_dev_init(&gpu->dev, gpu);
669 app_dev_init_formats(&gpu->dev);
670}
671
672static void app_gpu_destroy(struct app_gpu *gpu)
673{
674 app_dev_destroy(&gpu->dev);
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600675 free(gpu->device_extensions);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800676 free(gpu->queue_reqs);
677 free(gpu->queue_props);
678}
679
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600680static void app_dev_dump_format_props(const struct app_dev *dev, VkFormat fmt)
Chia-I Wud4bae362014-07-29 11:15:00 +0800681{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600682 const VkFormatProperties *props = &dev->format_props[fmt];
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800683 struct {
684 const char *name;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600685 VkFlags flags;
Mark Lobodzinski4b36dd42015-09-03 15:21:52 -0600686 } features[3];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600687 uint32_t i;
Chia-I Wud4bae362014-07-29 11:15:00 +0800688
Mark Lobodzinski4b36dd42015-09-03 15:21:52 -0600689 features[0].name = "linearTiling FormatFeatureFlags";
690 features[0].flags = props->linearTilingFeatures;
691 features[1].name = "optimalTiling FormatFeatureFlags";
692 features[1].flags = props->optimalTilingFeatures;
693 features[2].name = "bufferFeatures FormatFeatureFlags";
694 features[2].flags = props->bufferFeatures;
Chia-I Wud4bae362014-07-29 11:15:00 +0800695
Mark Lobodzinski4b36dd42015-09-03 15:21:52 -0600696 printf("\nFORMAT_%s:", vk_format_string(fmt));
697 for (i = 0; i < ARRAY_SIZE(features); i++) {
698 printf("\n\t%s:", features[i].name);
699 if (features[i].flags == 0) {
700 printf("\n\t\tNone");
701 } else {
Courtney Goeltzenleuchter75295792015-09-10 16:25:49 -0600702 printf("%s%s%s%s%s%s%s%s%s%s%s%s",
Mark Lobodzinski4b36dd42015-09-03 15:21:52 -0600703 ((features[i].flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) ? "\n\t\tVK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT" : ""),
704 ((features[i].flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) ? "\n\t\tVK_FORMAT_FEATURE_STORAGE_IMAGE_BIT" : ""),
705 ((features[i].flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT) ? "\n\t\tVK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT" : ""),
706 ((features[i].flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) ? "\n\t\tVK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT" : ""),
707 ((features[i].flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT) ? "\n\t\tVK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT" : ""),
708 ((features[i].flags & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) ? "\n\t\tVK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT" : ""),
Mark Lobodzinski4b36dd42015-09-03 15:21:52 -0600709 ((features[i].flags & VK_FORMAT_FEATURE_BLIT_SOURCE_BIT) ? "\n\t\tVK_FORMAT_FEATURE_BLIT_SOURCE_BIT" : ""),
710 ((features[i].flags & VK_FORMAT_FEATURE_BLIT_DESTINATION_BIT) ? "\n\t\tVK_FORMAT_FEATURE_BLIT_DESTINATION_BIT" : ""),
711 ((features[i].flags & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT) ? "\n\t\tVK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT" : ""),
712 ((features[i].flags & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT) ? "\n\t\tVK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT" : ""),
713 ((features[i].flags & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT) ? "\n\t\tVK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT" : ""),
714 ((features[i].flags & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) ? "\n\t\tVK_FORMAT_FEATURE_VERTEX_BUFFER_BIT" : ""));
715 }
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800716 }
Mark Lobodzinski4b36dd42015-09-03 15:21:52 -0600717 printf("\n");
Chia-I Wud4bae362014-07-29 11:15:00 +0800718}
719
Chia-I Wud4bae362014-07-29 11:15:00 +0800720
721static void
722app_dev_dump(const struct app_dev *dev)
723{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600724 VkFormat fmt;
Chia-I Wud4bae362014-07-29 11:15:00 +0800725
Courtney Goeltzenleuchterab36aa62015-07-12 12:40:29 -0600726 for (fmt = 0; fmt < VK_FORMAT_NUM; fmt++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700727 app_dev_dump_format_props(dev, fmt);
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800728 }
Chia-I Wud4bae362014-07-29 11:15:00 +0800729}
730
Mike Stroyan009d8ca2015-05-27 13:09:15 -0600731#ifdef _WIN32
732#define PRINTF_SIZE_T_SPECIFIER "%Iu"
733#else
734#define PRINTF_SIZE_T_SPECIFIER "%zu"
735#endif
736
Chris Forbesa048b312015-06-21 20:09:12 +1200737static void app_gpu_dump_features(const struct app_gpu *gpu)
738{
739 const VkPhysicalDeviceFeatures *features = &gpu->features;
740
Mark Lobodzinski825cc512015-08-14 10:30:30 -0600741 printf("VkPhysicalDeviceFeatures:\n");
742 printf("=========================\n");
743
744 printf("\trobustBufferAccess = %u\n", features->robustBufferAccess );
745 printf("\tfullDrawIndexUint32 = %u\n", features->fullDrawIndexUint32 );
746 printf("\timageCubeArray = %u\n", features->imageCubeArray );
747 printf("\tindependentBlend = %u\n", features->independentBlend );
748 printf("\tgeometryShader = %u\n", features->geometryShader );
749 printf("\ttessellationShader = %u\n", features->tessellationShader );
750 printf("\tsampleRateShading = %u\n", features->sampleRateShading );
751 printf("\tdualSourceBlend = %u\n", features->dualSourceBlend );
752 printf("\tlogicOp = %u\n", features->logicOp );
753 printf("\tmultiDrawIndirect = %u\n", features->multiDrawIndirect );
Courtney Goeltzenleuchterc0f9fa72015-10-15 12:57:38 -0600754 printf("\tdepthClip = %u\n", features->depthClamp );
Mark Lobodzinski825cc512015-08-14 10:30:30 -0600755 printf("\tdepthBiasClamp = %u\n", features->depthBiasClamp );
756 printf("\tfillModeNonSolid = %u\n", features->fillModeNonSolid );
757 printf("\tdepthBounds = %u\n", features->depthBounds );
758 printf("\twideLines = %u\n", features->wideLines );
759 printf("\tlargePoints = %u\n", features->largePoints );
760 printf("\ttextureCompressionETC2 = %u\n", features->textureCompressionETC2 );
761 printf("\ttextureCompressionASTC_LDR = %u\n", features->textureCompressionASTC_LDR );
762 printf("\ttextureCompressionBC = %u\n", features->textureCompressionBC );
763 printf("\tpipelineStatisticsQuery = %u\n", features->pipelineStatisticsQuery );
764 printf("\tvertexSideEffects = %u\n", features->vertexSideEffects );
765 printf("\ttessellationSideEffects = %u\n", features->tessellationSideEffects );
766 printf("\tgeometrySideEffects = %u\n", features->geometrySideEffects );
767 printf("\tfragmentSideEffects = %u\n", features->fragmentSideEffects );
768 printf("\tshaderTessellationPointSize = %u\n", features->shaderTessellationPointSize );
769 printf("\tshaderGeometryPointSize = %u\n", features->shaderGeometryPointSize );
770 printf("\tshaderImageGatherExtended = %u\n", features->shaderImageGatherExtended );
771 printf("\tshaderStorageImageExtendedFormats = %u\n", features->shaderStorageImageExtendedFormats );
772 printf("\tshaderStorageImageMultisample = %u\n", features->shaderStorageImageMultisample );
773 printf("\tshaderUniformBufferArrayDynamicIndexing = %u\n", features->shaderUniformBufferArrayDynamicIndexing);
774 printf("\tshaderSampledImageArrayDynamicIndexing = %u\n", features->shaderSampledImageArrayDynamicIndexing );
775 printf("\tshaderStorageBufferArrayDynamicIndexing = %u\n", features->shaderStorageBufferArrayDynamicIndexing);
776 printf("\tshaderStorageImageArrayDynamicIndexing = %u\n", features->shaderStorageImageArrayDynamicIndexing );
777 printf("\tshaderClipDistance = %u\n", features->shaderClipDistance );
778 printf("\tshaderCullDistance = %u\n", features->shaderCullDistance );
779 printf("\tshaderFloat64 = %u\n", features->shaderFloat64 );
780 printf("\tshaderInt64 = %u\n", features->shaderInt64 );
Mark Lobodzinski825cc512015-08-14 10:30:30 -0600781 printf("\tshaderInt16 = %u\n", features->shaderInt16 );
782 printf("\tshaderResourceResidency = %u\n", features->shaderResourceResidency );
783 printf("\tshaderResourceMinLOD = %u\n", features->shaderResourceMinLOD );
784 printf("\talphaToOne = %u\n", features->alphaToOne );
Mark Lobodzinski7dae6862015-09-07 12:56:17 -0600785 printf("\tsparseBinding = %u\n", features->sparseBinding );
Mark Lobodzinski825cc512015-08-14 10:30:30 -0600786 printf("\tsparseResidencyBuffer = %u\n", features->sparseResidencyBuffer );
787 printf("\tsparseResidencyImage2D = %u\n", features->sparseResidencyImage2D );
788 printf("\tsparseResidencyImage3D = %u\n", features->sparseResidencyImage3D );
789 printf("\tsparseResidency2Samples = %u\n", features->sparseResidency2Samples );
790 printf("\tsparseResidency4Samples = %u\n", features->sparseResidency4Samples );
791 printf("\tsparseResidency8Samples = %u\n", features->sparseResidency8Samples );
792 printf("\tsparseResidency16Samples = %u\n", features->sparseResidency16Samples );
Mark Lobodzinski825cc512015-08-14 10:30:30 -0600793 printf("\tsparseResidencyAliased = %u\n", features->sparseResidencyAliased );
Chris Forbesa048b312015-06-21 20:09:12 +1200794}
795
Mark Lobodzinski7dae6862015-09-07 12:56:17 -0600796static void app_dump_sparse_props(const VkPhysicalDeviceSparseProperties *sparseProps)
Chris Forbesa048b312015-06-21 20:09:12 +1200797{
Chris Forbesa048b312015-06-21 20:09:12 +1200798
Mark Lobodzinski7dae6862015-09-07 12:56:17 -0600799 printf("\tVkPhysicalDeviceSparseProperties:\n");
800 printf("\t---------------------------------\n");
Mark Lobodzinski825cc512015-08-14 10:30:30 -0600801
Courtney Goeltzenleuchter00c8c982015-09-10 12:54:32 -0600802 printf("\t\tresidencyStandard2DBlockShape = %u\n", sparseProps->residencyStandard2DBlockShape );
803 printf("\t\tresidencyStandard2DMSBlockShape = %u\n", sparseProps->residencyStandard2DMSBlockShape );
804 printf("\t\tresidencyStandard3DBlockShape = %u\n", sparseProps->residencyStandard3DBlockShape );
805 printf("\t\tresidencyAlignedMipSize = %u\n", sparseProps->residencyAlignedMipSize );
806 printf("\t\tresidencyNonResident = %u\n", sparseProps->residencyNonResident );
807 printf("\t\tresidencyNonResidentStrict = %u\n", sparseProps->residencyNonResidentStrict );
Mark Lobodzinski7dae6862015-09-07 12:56:17 -0600808}
809
810static void app_dump_limits(const VkPhysicalDeviceLimits *limits)
811{
812 printf("\tVkPhysicalDeviceLimits:\n");
813 printf("\t-----------------------\n");
814
815 printf("\t\tmaxImageDimension1D = 0x%" PRIxLEAST32 "\n", limits->maxImageDimension1D );
816 printf("\t\tmaxImageDimension2D = 0x%" PRIxLEAST32 "\n", limits->maxImageDimension2D );
817 printf("\t\tmaxImageDimension3D = 0x%" PRIxLEAST32 "\n", limits->maxImageDimension3D );
818 printf("\t\tmaxImageDimensionCube = 0x%" PRIxLEAST32 "\n", limits->maxImageDimensionCube );
819 printf("\t\tmaxImageArrayLayers = 0x%" PRIxLEAST32 "\n", limits->maxImageArrayLayers );
820 printf("\t\tmaxTexelBufferSize = 0x%" PRIxLEAST32 "\n", limits->maxTexelBufferSize );
Courtney Goeltzenleuchterd6633e22015-10-22 15:47:21 -0600821 printf("\t\tmaxUniformBufferRange = 0x%" PRIxLEAST32 "\n", limits->maxUniformBufferRange );
822 printf("\t\tmaxStorageBufferRange = 0x%" PRIxLEAST32 "\n", limits->maxStorageBufferRange );
Mark Lobodzinski7dae6862015-09-07 12:56:17 -0600823 printf("\t\tmaxPushConstantsSize = 0x%" PRIxLEAST32 "\n", limits->maxPushConstantsSize );
824 printf("\t\tmaxMemoryAllocationCount = 0x%" PRIxLEAST32 "\n", limits->maxMemoryAllocationCount );
825 printf("\t\tbufferImageGranularity = 0x%" PRIxLEAST64 "\n", limits->bufferImageGranularity );
826 printf("\t\tmaxBoundDescriptorSets = 0x%" PRIxLEAST32 "\n", limits->maxBoundDescriptorSets );
Mark Lobodzinski7dae6862015-09-07 12:56:17 -0600827 printf("\t\tmaxPerStageDescriptorSamplers = 0x%" PRIxLEAST32 "\n", limits->maxPerStageDescriptorSamplers );
828 printf("\t\tmaxPerStageDescriptorUniformBuffers = 0x%" PRIxLEAST32 "\n", limits->maxPerStageDescriptorUniformBuffers );
829 printf("\t\tmaxPerStageDescriptorStorageBuffers = 0x%" PRIxLEAST32 "\n", limits->maxPerStageDescriptorStorageBuffers );
830 printf("\t\tmaxPerStageDescriptorSampledImages = 0x%" PRIxLEAST32 "\n", limits->maxPerStageDescriptorSampledImages );
831 printf("\t\tmaxPerStageDescriptorStorageImages = 0x%" PRIxLEAST32 "\n", limits->maxPerStageDescriptorStorageImages );
832 printf("\t\tmaxDescriptorSetSamplers = 0x%" PRIxLEAST32 "\n", limits->maxDescriptorSetSamplers );
833 printf("\t\tmaxDescriptorSetUniformBuffers = 0x%" PRIxLEAST32 "\n", limits->maxDescriptorSetUniformBuffers );
834 printf("\t\tmaxDescriptorSetStorageBuffers = 0x%" PRIxLEAST32 "\n", limits->maxDescriptorSetStorageBuffers );
835 printf("\t\tmaxDescriptorSetSampledImages = 0x%" PRIxLEAST32 "\n", limits->maxDescriptorSetSampledImages );
836 printf("\t\tmaxDescriptorSetStorageImages = 0x%" PRIxLEAST32 "\n", limits->maxDescriptorSetStorageImages );
837 printf("\t\tmaxVertexInputAttributes = 0x%" PRIxLEAST32 "\n", limits->maxVertexInputAttributes );
838 printf("\t\tmaxVertexInputAttributeOffset = 0x%" PRIxLEAST32 "\n", limits->maxVertexInputAttributeOffset );
839 printf("\t\tmaxVertexInputBindingStride = 0x%" PRIxLEAST32 "\n", limits->maxVertexInputBindingStride );
840 printf("\t\tmaxVertexOutputComponents = 0x%" PRIxLEAST32 "\n", limits->maxVertexOutputComponents );
Courtney Goeltzenleuchterc6fd2262015-10-15 17:35:38 -0600841 printf("\t\tmaxTessellationGenLevel = 0x%" PRIxLEAST32 "\n", limits->maxTessellationGenLevel );
842 printf("\t\tmaxTessellationPatchSize = 0x%" PRIxLEAST32 "\n", limits->maxTessellationPatchSize );
843 printf("\t\tmaxTessellationControlPerVertexInputComponents = 0x%" PRIxLEAST32 "\n", limits->maxTessellationControlPerVertexInputComponents );
844 printf("\t\tmaxTessellationControlPerVertexOutputComponents = 0x%" PRIxLEAST32 "\n", limits->maxTessellationControlPerVertexOutputComponents);
845 printf("\t\tmaxTessellationControlPerPatchOutputComponents = 0x%" PRIxLEAST32 "\n", limits->maxTessellationControlPerPatchOutputComponents );
846 printf("\t\tmaxTessellationControlTotalOutputComponents = 0x%" PRIxLEAST32 "\n", limits->maxTessellationControlTotalOutputComponents );
847 printf("\t\tmaxTessellationEvaluationInputComponents = 0x%" PRIxLEAST32 "\n", limits->maxTessellationEvaluationInputComponents );
848 printf("\t\tmaxTessellationEvaluationOutputComponents = 0x%" PRIxLEAST32 "\n", limits->maxTessellationEvaluationOutputComponents );
Mark Lobodzinski7dae6862015-09-07 12:56:17 -0600849 printf("\t\tmaxGeometryShaderInvocations = 0x%" PRIxLEAST32 "\n", limits->maxGeometryShaderInvocations );
850 printf("\t\tmaxGeometryInputComponents = 0x%" PRIxLEAST32 "\n", limits->maxGeometryInputComponents );
851 printf("\t\tmaxGeometryOutputComponents = 0x%" PRIxLEAST32 "\n", limits->maxGeometryOutputComponents );
852 printf("\t\tmaxGeometryOutputVertices = 0x%" PRIxLEAST32 "\n", limits->maxGeometryOutputVertices );
853 printf("\t\tmaxGeometryTotalOutputComponents = 0x%" PRIxLEAST32 "\n", limits->maxGeometryTotalOutputComponents );
854 printf("\t\tmaxFragmentInputComponents = 0x%" PRIxLEAST32 "\n", limits->maxFragmentInputComponents );
Courtney Goeltzenleuchterd6633e22015-10-22 15:47:21 -0600855 printf("\t\tmaxFragmentOutputAttachments = 0x%" PRIxLEAST32 "\n", limits->maxFragmentOutputAttachments );
856 printf("\t\tmaxFragmentDualSourceAttachments = 0x%" PRIxLEAST32 "\n", limits->maxFragmentDualSourceAttachments );
Mark Lobodzinski7dae6862015-09-07 12:56:17 -0600857 printf("\t\tmaxFragmentCombinedOutputResources = 0x%" PRIxLEAST32 "\n", limits->maxFragmentCombinedOutputResources );
858 printf("\t\tmaxComputeSharedMemorySize = 0x%" PRIxLEAST32 "\n", limits->maxComputeSharedMemorySize );
859 printf("\t\tmaxComputeWorkGroupCount[0] = 0x%" PRIxLEAST32 "\n", limits->maxComputeWorkGroupCount[0] );
860 printf("\t\tmaxComputeWorkGroupCount[1] = 0x%" PRIxLEAST32 "\n", limits->maxComputeWorkGroupCount[1] );
861 printf("\t\tmaxComputeWorkGroupCount[2] = 0x%" PRIxLEAST32 "\n", limits->maxComputeWorkGroupCount[2] );
862 printf("\t\tmaxComputeWorkGroupInvocations = 0x%" PRIxLEAST32 "\n", limits->maxComputeWorkGroupInvocations );
863 printf("\t\tmaxComputeWorkGroupSize[0] = 0x%" PRIxLEAST32 "\n", limits->maxComputeWorkGroupSize[0] );
864 printf("\t\tmaxComputeWorkGroupSize[1] = 0x%" PRIxLEAST32 "\n", limits->maxComputeWorkGroupSize[1] );
865 printf("\t\tmaxComputeWorkGroupSize[2] = 0x%" PRIxLEAST32 "\n", limits->maxComputeWorkGroupSize[2] );
866 printf("\t\tsubPixelPrecisionBits = 0x%" PRIxLEAST32 "\n", limits->subPixelPrecisionBits );
867 printf("\t\tsubTexelPrecisionBits = 0x%" PRIxLEAST32 "\n", limits->subTexelPrecisionBits );
868 printf("\t\tmipmapPrecisionBits = 0x%" PRIxLEAST32 "\n", limits->mipmapPrecisionBits );
869 printf("\t\tmaxDrawIndexedIndexValue = 0x%" PRIxLEAST32 "\n", limits->maxDrawIndexedIndexValue );
870 printf("\t\tmaxDrawIndirectInstanceCount = 0x%" PRIxLEAST32 "\n", limits->maxDrawIndirectInstanceCount );
871 printf("\t\tprimitiveRestartForPatches = 0x%" PRIxLEAST32 "\n", limits->primitiveRestartForPatches );
872 printf("\t\tmaxSamplerLodBias = %f\n", limits->maxSamplerLodBias );
873 printf("\t\tmaxSamplerAnisotropy = %f\n", limits->maxSamplerAnisotropy );
874 printf("\t\tmaxViewports = 0x%" PRIxLEAST32 "\n", limits->maxViewports );
Mark Lobodzinski7dae6862015-09-07 12:56:17 -0600875 printf("\t\tmaxViewportDimensions[0] = 0x%" PRIxLEAST32 "\n", limits->maxViewportDimensions[0] );
876 printf("\t\tmaxViewportDimensions[1] = 0x%" PRIxLEAST32 "\n", limits->maxViewportDimensions[1] );
877 printf("\t\tviewportBoundsRange[0] = %f\n", limits->viewportBoundsRange[0] );
878 printf("\t\tviewportBoundsRange[1] = %f\n", limits->viewportBoundsRange[1] );
879 printf("\t\tviewportSubPixelBits = 0x%" PRIxLEAST32 "\n", limits->viewportSubPixelBits );
880 printf("\t\tminMemoryMapAlignment = 0x%" PRIxLEAST32 "\n", limits->minMemoryMapAlignment );
881 printf("\t\tminTexelBufferOffsetAlignment = 0x%" PRIxLEAST32 "\n", limits->minTexelBufferOffsetAlignment );
882 printf("\t\tminUniformBufferOffsetAlignment = 0x%" PRIxLEAST32 "\n", limits->minUniformBufferOffsetAlignment );
883 printf("\t\tminStorageBufferOffsetAlignment = 0x%" PRIxLEAST32 "\n", limits->minStorageBufferOffsetAlignment );
884 printf("\t\tminTexelOffset = 0x%" PRIxLEAST32 "\n", limits->minTexelOffset );
885 printf("\t\tmaxTexelOffset = 0x%" PRIxLEAST32 "\n", limits->maxTexelOffset );
886 printf("\t\tminTexelGatherOffset = 0x%" PRIxLEAST32 "\n", limits->minTexelGatherOffset );
887 printf("\t\tmaxTexelGatherOffset = 0x%" PRIxLEAST32 "\n", limits->maxTexelGatherOffset );
888 printf("\t\tminInterpolationOffset = %f\n", limits->minInterpolationOffset );
889 printf("\t\tmaxInterpolationOffset = %f\n", limits->maxInterpolationOffset );
890 printf("\t\tsubPixelInterpolationOffsetBits = 0x%" PRIxLEAST32 "\n", limits->subPixelInterpolationOffsetBits );
891 printf("\t\tmaxFramebufferWidth = 0x%" PRIxLEAST32 "\n", limits->maxFramebufferWidth );
892 printf("\t\tmaxFramebufferHeight = 0x%" PRIxLEAST32 "\n", limits->maxFramebufferHeight );
893 printf("\t\tmaxFramebufferLayers = 0x%" PRIxLEAST32 "\n", limits->maxFramebufferLayers );
894 printf("\t\tmaxFramebufferColorSamples = 0x%" PRIxLEAST32 "\n", limits->maxFramebufferColorSamples );
895 printf("\t\tmaxFramebufferDepthSamples = 0x%" PRIxLEAST32 "\n", limits->maxFramebufferDepthSamples );
896 printf("\t\tmaxFramebufferStencilSamples = 0x%" PRIxLEAST32 "\n", limits->maxFramebufferStencilSamples );
897 printf("\t\tmaxColorAttachments = 0x%" PRIxLEAST32 "\n", limits->maxColorAttachments );
898 printf("\t\tmaxSampledImageColorSamples = 0x%" PRIxLEAST32 "\n", limits->maxSampledImageColorSamples );
899 printf("\t\tmaxSampledImageDepthSamples = 0x%" PRIxLEAST32 "\n", limits->maxSampledImageDepthSamples );
900 printf("\t\tmaxSampledImageIntegerSamples = 0x%" PRIxLEAST32 "\n", limits->maxSampledImageIntegerSamples );
901 printf("\t\tmaxStorageImageSamples = 0x%" PRIxLEAST32 "\n", limits->maxStorageImageSamples );
902 printf("\t\tmaxSampleMaskWords = 0x%" PRIxLEAST32 "\n", limits->maxSampleMaskWords );
903 printf("\t\ttimestampFrequency = 0x%" PRIxLEAST64 "\n", limits->timestampFrequency );
904 printf("\t\tmaxClipDistances = 0x%" PRIxLEAST32 "\n", limits->maxClipDistances );
905 printf("\t\tmaxCullDistances = 0x%" PRIxLEAST32 "\n", limits->maxCullDistances );
906 printf("\t\tmaxCombinedClipAndCullDistances = 0x%" PRIxLEAST32 "\n", limits->maxCombinedClipAndCullDistances );
907 printf("\t\tpointSizeRange[0] = %f\n", limits->pointSizeRange[0] );
908 printf("\t\tpointSizeRange[1] = %f\n", limits->pointSizeRange[1] );
909 printf("\t\tlineWidthRange[0] = %f\n", limits->lineWidthRange[0] );
910 printf("\t\tlineWidthRange[1] = %f\n", limits->lineWidthRange[1] );
911 printf("\t\tpointSizeGranularity = %f\n", limits->pointSizeGranularity );
912 printf("\t\tlineWidthGranularity = %f\n", limits->lineWidthGranularity );
Chia-I Wud4bae362014-07-29 11:15:00 +0800913}
914
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600915static void app_gpu_dump_props(const struct app_gpu *gpu)
916{
917 const VkPhysicalDeviceProperties *props = &gpu->props;
918
Mark Lobodzinski825cc512015-08-14 10:30:30 -0600919 printf("VkPhysicalDeviceProperties:\n");
920 printf("===========================\n");
921 printf("\tapiVersion = %u\n", props->apiVersion);
922 printf("\tdriverVersion = %u\n", props->driverVersion);
923 printf("\tvendorId = 0x%04x\n", props->vendorId);
924 printf("\tdeviceId = 0x%04x\n", props->deviceId);
925 printf("\tdeviceType = %s\n", vk_physical_device_type_string(props->deviceType));
926 printf("\tdeviceName = %s\n", props->deviceName);
Mark Lobodzinski7dae6862015-09-07 12:56:17 -0600927
928 app_dump_limits(&gpu->props.limits);
929 app_dump_sparse_props(&gpu->props.sparseProperties);
930
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600931 fflush(stdout);
932}
933
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600934static void app_dump_extensions(
935 const char *indent,
936 const char *layer_name,
937 const uint32_t extension_count,
938 const VkExtensionProperties *extension_properties)
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600939{
940 uint32_t i;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600941 if (layer_name && (strlen(layer_name) > 0)) {
942 printf("%s%s Extensions", indent, layer_name);
943 } else {
944 printf("Extensions");
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600945 }
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600946 printf("\tcount = %d\n", extension_count);
947 for (i=0; i< extension_count; i++) {
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600948 VkExtensionProperties const *ext_prop = &extension_properties[i];
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600949
Courtney Goeltzenleuchterff87c822014-10-03 18:05:10 -0600950 if (i>0)
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600951 printf("\n"); // separator between extensions
952
953 printf("%s\t", indent);
Ian Elliottd5b6e892015-09-04 14:14:35 -0600954 printf("%-32s: extension revision %2d",
955 ext_prop->extName, ext_prop->specVersion);
Courtney Goeltzenleuchterff87c822014-10-03 18:05:10 -0600956 }
957 printf("\n");
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600958 fflush(stdout);
Courtney Goeltzenleuchterff87c822014-10-03 18:05:10 -0600959}
960
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600961static void app_gpu_dump_queue_props(const struct app_gpu *gpu, uint32_t id)
Chia-I Wud4bae362014-07-29 11:15:00 +0800962{
Cody Northropef72e2a2015-08-03 17:04:53 -0600963 const VkQueueFamilyProperties *props = &gpu->queue_props[id];
Chia-I Wud4bae362014-07-29 11:15:00 +0800964
Mark Lobodzinski825cc512015-08-14 10:30:30 -0600965 printf("VkQueueFamilyProperties[%d]:\n", id);
966 printf("============================\n");
967 printf("\tqueueFlags = %c%c%c%c\n",
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600968 (props->queueFlags & VK_QUEUE_GRAPHICS_BIT) ? 'G' : '.',
969 (props->queueFlags & VK_QUEUE_COMPUTE_BIT) ? 'C' : '.',
970 (props->queueFlags & VK_QUEUE_DMA_BIT) ? 'D' : '.',
971 (props->queueFlags & VK_QUEUE_EXTENDED_BIT) ? 'X' : '.');
Mark Lobodzinski825cc512015-08-14 10:30:30 -0600972 printf("\tqueueCount = %u\n", props->queueCount);
Courtney Goeltzenleuchter68535a62015-10-19 16:03:32 -0600973 printf("\ttimestampValidBits = %u\n", props->timestampValidBits);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600974 fflush(stdout);
Chia-I Wud4bae362014-07-29 11:15:00 +0800975}
976
977static void app_gpu_dump_memory_props(const struct app_gpu *gpu)
978{
Tony Barbour8205d902015-04-16 15:59:00 -0600979 const VkPhysicalDeviceMemoryProperties *props = &gpu->memory_props;
Chia-I Wud4bae362014-07-29 11:15:00 +0800980
Mark Lobodzinski825cc512015-08-14 10:30:30 -0600981 printf("VkPhysicalDeviceMemoryProperties:\n");
982 printf("=================================\n");
983 printf("\tmemoryTypeCount = %u\n", props->memoryTypeCount);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600984 for (uint32_t i = 0; i < props->memoryTypeCount; i++) {
985 printf("\tmemoryTypes[%u] : \n", i);
986 printf("\t\tpropertyFlags = %u\n", props->memoryTypes[i].propertyFlags);
987 printf("\t\theapIndex = %u\n", props->memoryTypes[i].heapIndex);
988 }
Mark Lobodzinski825cc512015-08-14 10:30:30 -0600989 printf("\tmemoryHeapCount = %u\n", props->memoryHeapCount);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600990 for (uint32_t i = 0; i < props->memoryHeapCount; i++) {
991 printf("\tmemoryHeaps[%u] : \n", i);
Mark Lobodzinski825cc512015-08-14 10:30:30 -0600992 printf("\t\tsize = " PRINTF_SIZE_T_SPECIFIER "\n", props->memoryHeaps[i].size);
Mark Lobodzinski72346292015-07-02 16:49:40 -0600993 }
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600994 fflush(stdout);
Chia-I Wud4bae362014-07-29 11:15:00 +0800995}
996
997static void app_gpu_dump(const struct app_gpu *gpu)
998{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600999 uint32_t i;
Chia-I Wuf5c46f42014-08-05 15:33:40 +08001000
Mark Lobodzinski825cc512015-08-14 10:30:30 -06001001 printf("Device Extensions and layers:\n");
1002 printf("=============================\n");
Chia-I Wu190ebdc2014-08-06 12:04:13 +08001003 printf("GPU%u\n", gpu->id);
1004 app_gpu_dump_props(gpu);
1005 printf("\n");
Mark Lobodzinski825cc512015-08-14 10:30:30 -06001006 app_dump_extensions("", "Device", gpu->device_extension_count, gpu->device_extensions);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -06001007 printf("\n");
1008 printf("Layers\tcount = %d\n", gpu->device_layer_count);
1009 for (uint32_t i = 0; i < gpu->device_layer_count; i++) {
1010 uint32_t major, minor, patch;
1011 char spec_version[64], layer_version[64];
1012 struct layer_extension_list const *layer_info = &gpu->device_layers[i];
1013
1014 extract_version(layer_info->layer_properties.specVersion, &major, &minor, &patch);
1015 snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", major, minor, patch);
1016 extract_version(layer_info->layer_properties.implVersion, &major, &minor, &patch);
1017 snprintf(layer_version, sizeof(layer_version), "%d.%d.%d", major, minor, patch);
1018 printf("\t%s (%s) Vulkan version %s, layer version %s\n",
1019 layer_info->layer_properties.layerName,
Ian Elliott3f26dee2015-07-13 11:09:59 -06001020 (char*) layer_info->layer_properties.description,
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -06001021 spec_version, layer_version);
1022
1023 app_dump_extensions("\t",
1024 layer_info->layer_properties.layerName,
1025 layer_info->extension_count,
1026 layer_info->extension_properties);
1027 fflush(stdout);
1028 }
Courtney Goeltzenleuchterff87c822014-10-03 18:05:10 -06001029 printf("\n");
Chia-I Wu190ebdc2014-08-06 12:04:13 +08001030 for (i = 0; i < gpu->queue_count; i++) {
1031 app_gpu_dump_queue_props(gpu, i);
1032 printf("\n");
1033 }
1034 app_gpu_dump_memory_props(gpu);
1035 printf("\n");
Chris Forbesa048b312015-06-21 20:09:12 +12001036 app_gpu_dump_features(gpu);
1037 printf("\n");
Chia-I Wu190ebdc2014-08-06 12:04:13 +08001038 app_dev_dump(&gpu->dev);
Chia-I Wud4bae362014-07-29 11:15:00 +08001039}
1040
Chia-I Wud4bae362014-07-29 11:15:00 +08001041int main(int argc, char **argv)
1042{
David Pinedo7b4e9ec2015-10-19 15:22:28 -06001043 unsigned int major, minor, patch;
1044 struct app_gpu gpus[MAX_GPUS];
Tony Barbour8205d902015-04-16 15:59:00 -06001045 VkPhysicalDevice objs[MAX_GPUS];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001046 uint32_t gpu_count, i;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001047 VkResult err;
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -06001048 struct app_instance inst;
Chia-I Wud4bae362014-07-29 11:15:00 +08001049
David Pinedo7b4e9ec2015-10-19 15:22:28 -06001050 major = VK_API_VERSION >> 22;
1051 minor = (VK_API_VERSION >> 12) & 0x4ff;
1052 patch = VK_API_VERSION & 0xfff;
1053 printf("===========\n");
David Pinedob5ec4c22015-10-19 15:15:34 -06001054 printf("VULKAN INFO\n");
1055 printf("===========\n\n");
1056 printf("Vulkan API Version: %d %d %d\n\n", major, minor, patch);
1057
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -06001058 app_create_instance(&inst);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -06001059
Mark Lobodzinski825cc512015-08-14 10:30:30 -06001060 printf("Instance Extensions and layers:\n");
1061 printf("===============================\n");
1062 app_dump_extensions("", "Instance", inst.global_extension_count, inst.global_extensions);
1063
1064 printf("Instance Layers\tcount = %d\n", inst.global_layer_count);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -06001065 for (uint32_t i = 0; i < inst.global_layer_count; i++) {
1066 uint32_t major, minor, patch;
1067 char spec_version[64], layer_version[64];
1068 VkLayerProperties const *layer_prop = &inst.global_layers[i].layer_properties;
1069
1070 extract_version(layer_prop->specVersion, &major, &minor, &patch);
1071 snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", major, minor, patch);
1072 extract_version(layer_prop->implVersion, &major, &minor, &patch);
1073 snprintf(layer_version, sizeof(layer_version), "%d.%d.%d", major, minor, patch);
1074 printf("\t%s (%s) Vulkan version %s, layer version %s\n",
Ian Elliott3f26dee2015-07-13 11:09:59 -06001075 layer_prop->layerName, (char*) layer_prop->description, spec_version, layer_version);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -06001076
1077 app_dump_extensions("\t",
1078 inst.global_layers[i].layer_properties.layerName,
1079 inst.global_layers[i].extension_count,
1080 inst.global_layers[i].extension_properties);
1081 }
Jon Ashburn29669a42015-04-04 14:52:07 -06001082
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -06001083 err = vkEnumeratePhysicalDevices(inst.instance, &gpu_count, NULL);
Jon Ashburn07b309a2015-04-15 11:31:12 -06001084 if (err)
1085 ERR_EXIT(err);
1086 if (gpu_count > MAX_GPUS) {
David Pinedo18fb9232015-04-21 14:45:16 -06001087 printf("Too many GPUS found \n");
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06001088 ERR_EXIT(-1);
Jon Ashburn07b309a2015-04-15 11:31:12 -06001089 }
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -06001090 err = vkEnumeratePhysicalDevices(inst.instance, &gpu_count, objs);
Chia-I Wu190ebdc2014-08-06 12:04:13 +08001091 if (err)
1092 ERR_EXIT(err);
Chia-I Wud4bae362014-07-29 11:15:00 +08001093
Chia-I Wu190ebdc2014-08-06 12:04:13 +08001094 for (i = 0; i < gpu_count; i++) {
1095 app_gpu_init(&gpus[i], i, objs[i]);
1096 app_gpu_dump(&gpus[i]);
1097 printf("\n\n");
1098 }
Chia-I Wud4bae362014-07-29 11:15:00 +08001099
Chia-I Wu190ebdc2014-08-06 12:04:13 +08001100 for (i = 0; i < gpu_count; i++)
1101 app_gpu_destroy(&gpus[i]);
Chia-I Wud4bae362014-07-29 11:15:00 +08001102
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -06001103 app_destroy_instance(&inst);
Chia-I Wu0b9a7372014-08-06 12:09:19 +08001104
Chia-I Wu190ebdc2014-08-06 12:04:13 +08001105 return 0;
Chia-I Wud4bae362014-07-29 11:15:00 +08001106}
Ian Elliottea95f5c2015-04-17 21:23:34 -06001107
1108#ifdef _WIN32
David Pinedo18fb9232015-04-21 14:45:16 -06001109
1110// Create a console window with a large scrollback size to which to send stdout.
1111// Returns true if console window was successfully created, false otherwise.
1112bool SetStdOutToNewConsole()
1113{
1114 // don't do anything if we already have a console
1115 if (GetStdHandle(STD_OUTPUT_HANDLE))
1116 return false;
1117
1118 // allocate a console for this app
1119 AllocConsole();
1120
1121 // redirect unbuffered STDOUT to the console
1122 HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
1123 int fileDescriptor = _open_osfhandle((intptr_t)consoleHandle, _O_TEXT);
1124 FILE *fp = _fdopen( fileDescriptor, "w" );
1125 *stdout = *fp;
1126 setvbuf( stdout, NULL, _IONBF, 0 );
1127
1128 // make the console window bigger
1129 CONSOLE_SCREEN_BUFFER_INFO csbi;
1130 SMALL_RECT r;
1131 COORD bufferSize;
1132 if (!GetConsoleScreenBufferInfo(consoleHandle, &csbi))
1133 return false;
David Pinedod1887572015-10-09 11:31:15 -06001134 bufferSize.X = csbi.dwSize.X+30;
David Pinedoe1b115f2015-10-02 16:49:43 -06001135 bufferSize.Y = 20000;
David Pinedo18fb9232015-04-21 14:45:16 -06001136 if (!SetConsoleScreenBufferSize(consoleHandle, bufferSize))
1137 return false;
1138 r.Left = r.Top = 0;
David Pinedod1887572015-10-09 11:31:15 -06001139 r.Right = csbi.dwSize.X-1+30;
David Pinedo3bf020c2015-09-29 16:56:02 -06001140 r.Bottom = 50;
David Pinedo18fb9232015-04-21 14:45:16 -06001141 if (!SetConsoleWindowInfo(consoleHandle, true, &r))
1142 return false;
1143
1144 // change the console window title
Ian Elliott4e19ed02015-04-28 10:52:52 -06001145 if (!SetConsoleTitle(TEXT(APP_SHORT_NAME)))
David Pinedo18fb9232015-04-21 14:45:16 -06001146 return false;
1147
1148 return true;
1149}
1150
Ian Elliottea95f5c2015-04-17 21:23:34 -06001151int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int nCmdShow)
1152{
1153 char *argv = pCmdLine;
David Pinedo18fb9232015-04-21 14:45:16 -06001154 consoleCreated = SetStdOutToNewConsole();
Ian Elliottea95f5c2015-04-17 21:23:34 -06001155 main(1, &argv);
1156 fflush(stdout);
David Pinedo18fb9232015-04-21 14:45:16 -06001157 if (consoleCreated)
1158 Sleep(INFINITE);
Ian Elliottea95f5c2015-04-17 21:23:34 -06001159}
1160#endif