blob: 15e9c8f9e17fa44f68268e03dfa52d7d7ea945d7 [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>
Chia-I Wud4bae362014-07-29 11:15:00 +080029
Ian Elliottea95f5c2015-04-17 21:23:34 -060030#ifdef _WIN32
31#include <Windows.h>
David Pinedo18fb9232015-04-21 14:45:16 -060032#include <fcntl.h>
33#include <io.h>
Ian Elliottea95f5c2015-04-17 21:23:34 -060034#endif
35
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060036#include <vulkan.h>
Chia-I Wu46c29dd2014-12-02 21:09:20 +080037
38#define ERR(err) printf("%s:%d: failed with %s\n", \
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060039 __FILE__, __LINE__, vk_result_string(err));
Chia-I Wu46c29dd2014-12-02 21:09:20 +080040
David Pinedo18fb9232015-04-21 14:45:16 -060041#ifdef _WIN32
42
Ian Elliott7c83aa22015-07-08 17:09:54 -060043#define snprintf _snprintf
44
David Pinedo18fb9232015-04-21 14:45:16 -060045bool consoleCreated = false;
46
47#define WAIT_FOR_CONSOLE_DESTROY \
48 do { \
49 if (consoleCreated) \
50 Sleep(INFINITE); \
51 } while (0)
52#else
53 #define WAIT_FOR_CONSOLE_DESTROY
54#endif
55
56
57#define ERR_EXIT(err) \
58 do { \
59 ERR(err); \
60 fflush(stdout); \
61 WAIT_FOR_CONSOLE_DESTROY; \
62 exit(-1); \
63 } while (0)
Chia-I Wu46c29dd2014-12-02 21:09:20 +080064
Tony Barbour22a30862015-04-22 09:02:32 -060065#if defined(NDEBUG) && defined(__GNUC__)
66#define U_ASSERT_ONLY __attribute__((unused))
67#else
68#define U_ASSERT_ONLY
69#endif
70
Chia-I Wu46c29dd2014-12-02 21:09:20 +080071#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
72
73#define MAX_GPUS 8
74
75#define MAX_QUEUE_TYPES 5
Ian Elliott4e19ed02015-04-28 10:52:52 -060076#define APP_SHORT_NAME "vulkaninfo"
Chia-I Wu46c29dd2014-12-02 21:09:20 +080077
78struct app_gpu;
79
80struct app_dev {
81 struct app_gpu *gpu; /* point back to the GPU */
82
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060083 VkDevice obj;
Chia-I Wu46c29dd2014-12-02 21:09:20 +080084
Chia-I Wu46c29dd2014-12-02 21:09:20 +080085
Tony Barbour8205d902015-04-16 15:59:00 -060086 VkFormatProperties format_props[VK_NUM_FORMAT];
Chia-I Wu46c29dd2014-12-02 21:09:20 +080087};
88
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -060089struct layer_extension_list {
90 VkLayerProperties layer_properties;
91 uint32_t extension_count;
92 VkExtensionProperties *extension_properties;
93};
94
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -060095struct app_instance {
96 VkInstance instance;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -060097 uint32_t global_layer_count;
98 struct layer_extension_list *global_layers;
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -060099 uint32_t global_extension_count;
100 VkExtensionProperties *global_extensions;
101};
102
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800103struct app_gpu {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600104 uint32_t id;
Tony Barbour8205d902015-04-16 15:59:00 -0600105 VkPhysicalDevice obj;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800106
Tony Barbour8205d902015-04-16 15:59:00 -0600107 VkPhysicalDeviceProperties props;
108 VkPhysicalDevicePerformance perf;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800109
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600110 uint32_t queue_count;
Tony Barbour8205d902015-04-16 15:59:00 -0600111 VkPhysicalDeviceQueueProperties *queue_props;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600112 VkDeviceQueueCreateInfo *queue_reqs;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800113
Tony Barbour8205d902015-04-16 15:59:00 -0600114 VkPhysicalDeviceMemoryProperties memory_props;
Chris Forbesa048b312015-06-21 20:09:12 +1200115 VkPhysicalDeviceFeatures features;
116 VkPhysicalDeviceLimits limits;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800117
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600118 uint32_t device_layer_count;
119 struct layer_extension_list *device_layers;
120
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600121 uint32_t device_extension_count;
122 VkExtensionProperties *device_extensions;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800123
124 struct app_dev dev;
125};
126
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600127static const char *vk_result_string(VkResult err)
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800128{
129 switch (err) {
130#define STR(r) case r: return #r
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600131 STR(VK_SUCCESS);
132 STR(VK_UNSUPPORTED);
133 STR(VK_NOT_READY);
134 STR(VK_TIMEOUT);
135 STR(VK_EVENT_SET);
136 STR(VK_EVENT_RESET);
137 STR(VK_ERROR_UNKNOWN);
138 STR(VK_ERROR_UNAVAILABLE);
139 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_ALREADY_CREATED);
143 STR(VK_ERROR_DEVICE_LOST);
144 STR(VK_ERROR_INVALID_POINTER);
145 STR(VK_ERROR_INVALID_VALUE);
146 STR(VK_ERROR_INVALID_HANDLE);
147 STR(VK_ERROR_INVALID_ORDINAL);
148 STR(VK_ERROR_INVALID_MEMORY_SIZE);
149 STR(VK_ERROR_INVALID_EXTENSION);
150 STR(VK_ERROR_INVALID_FLAGS);
151 STR(VK_ERROR_INVALID_ALIGNMENT);
152 STR(VK_ERROR_INVALID_FORMAT);
153 STR(VK_ERROR_INVALID_IMAGE);
154 STR(VK_ERROR_INVALID_DESCRIPTOR_SET_DATA);
155 STR(VK_ERROR_INVALID_QUEUE_TYPE);
156 STR(VK_ERROR_INVALID_OBJECT_TYPE);
157 STR(VK_ERROR_UNSUPPORTED_SHADER_IL_VERSION);
158 STR(VK_ERROR_BAD_SHADER_CODE);
159 STR(VK_ERROR_BAD_PIPELINE_DATA);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600160 STR(VK_ERROR_NOT_MAPPABLE);
161 STR(VK_ERROR_MEMORY_MAP_FAILED);
162 STR(VK_ERROR_MEMORY_UNMAP_FAILED);
163 STR(VK_ERROR_INCOMPATIBLE_DEVICE);
164 STR(VK_ERROR_INCOMPATIBLE_DRIVER);
165 STR(VK_ERROR_INCOMPLETE_COMMAND_BUFFER);
166 STR(VK_ERROR_BUILDING_COMMAND_BUFFER);
167 STR(VK_ERROR_MEMORY_NOT_BOUND);
168 STR(VK_ERROR_INCOMPATIBLE_QUEUE);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800169#undef STR
170 default: return "UNKNOWN_RESULT";
171 }
172}
Chia-I Wud4bae362014-07-29 11:15:00 +0800173
Tony Barbour8205d902015-04-16 15:59:00 -0600174static const char *vk_physical_device_type_string(VkPhysicalDeviceType type)
Chia-I Wud4bae362014-07-29 11:15:00 +0800175{
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800176 switch (type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600177#define STR(r) case VK_PHYSICAL_DEVICE_TYPE_ ##r: return #r
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800178 STR(OTHER);
Tony Barbour8205d902015-04-16 15:59:00 -0600179 STR(INTEGRATED_GPU);
180 STR(DISCRETE_GPU);
181 STR(VIRTUAL_GPU);
Chia-I Wud4bae362014-07-29 11:15:00 +0800182#undef STR
Tony Barbour8205d902015-04-16 15:59:00 -0600183 default: return "UNKNOWN_DEVICE";
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800184 }
Chia-I Wud4bae362014-07-29 11:15:00 +0800185}
186
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600187static const char *vk_format_string(VkFormat fmt)
Chia-I Wud4bae362014-07-29 11:15:00 +0800188{
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700189 switch (fmt) {
Tony Barbour8205d902015-04-16 15:59:00 -0600190#define STR(r) case VK_FORMAT_ ##r: return #r
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800191 STR(UNDEFINED);
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700192 STR(R4G4_UNORM);
193 STR(R4G4_USCALED);
194 STR(R4G4B4A4_UNORM);
195 STR(R4G4B4A4_USCALED);
196 STR(R5G6B5_UNORM);
197 STR(R5G6B5_USCALED);
198 STR(R5G5B5A1_UNORM);
199 STR(R5G5B5A1_USCALED);
200 STR(R8_UNORM);
201 STR(R8_SNORM);
202 STR(R8_USCALED);
203 STR(R8_SSCALED);
204 STR(R8_UINT);
205 STR(R8_SINT);
206 STR(R8_SRGB);
207 STR(R8G8_UNORM);
208 STR(R8G8_SNORM);
209 STR(R8G8_USCALED);
210 STR(R8G8_SSCALED);
211 STR(R8G8_UINT);
212 STR(R8G8_SINT);
213 STR(R8G8_SRGB);
214 STR(R8G8B8_UNORM);
215 STR(R8G8B8_SNORM);
216 STR(R8G8B8_USCALED);
217 STR(R8G8B8_SSCALED);
218 STR(R8G8B8_UINT);
219 STR(R8G8B8_SINT);
220 STR(R8G8B8_SRGB);
221 STR(R8G8B8A8_UNORM);
222 STR(R8G8B8A8_SNORM);
223 STR(R8G8B8A8_USCALED);
224 STR(R8G8B8A8_SSCALED);
225 STR(R8G8B8A8_UINT);
226 STR(R8G8B8A8_SINT);
227 STR(R8G8B8A8_SRGB);
228 STR(R10G10B10A2_UNORM);
229 STR(R10G10B10A2_SNORM);
230 STR(R10G10B10A2_USCALED);
231 STR(R10G10B10A2_SSCALED);
232 STR(R10G10B10A2_UINT);
233 STR(R10G10B10A2_SINT);
234 STR(R16_UNORM);
235 STR(R16_SNORM);
236 STR(R16_USCALED);
237 STR(R16_SSCALED);
238 STR(R16_UINT);
239 STR(R16_SINT);
240 STR(R16_SFLOAT);
241 STR(R16G16_UNORM);
242 STR(R16G16_SNORM);
243 STR(R16G16_USCALED);
244 STR(R16G16_SSCALED);
245 STR(R16G16_UINT);
246 STR(R16G16_SINT);
247 STR(R16G16_SFLOAT);
248 STR(R16G16B16_UNORM);
249 STR(R16G16B16_SNORM);
250 STR(R16G16B16_USCALED);
251 STR(R16G16B16_SSCALED);
252 STR(R16G16B16_UINT);
253 STR(R16G16B16_SINT);
254 STR(R16G16B16_SFLOAT);
255 STR(R16G16B16A16_UNORM);
256 STR(R16G16B16A16_SNORM);
257 STR(R16G16B16A16_USCALED);
258 STR(R16G16B16A16_SSCALED);
259 STR(R16G16B16A16_UINT);
260 STR(R16G16B16A16_SINT);
261 STR(R16G16B16A16_SFLOAT);
262 STR(R32_UINT);
263 STR(R32_SINT);
264 STR(R32_SFLOAT);
265 STR(R32G32_UINT);
266 STR(R32G32_SINT);
267 STR(R32G32_SFLOAT);
268 STR(R32G32B32_UINT);
269 STR(R32G32B32_SINT);
270 STR(R32G32B32_SFLOAT);
271 STR(R32G32B32A32_UINT);
272 STR(R32G32B32A32_SINT);
273 STR(R32G32B32A32_SFLOAT);
274 STR(R64_SFLOAT);
275 STR(R64G64_SFLOAT);
276 STR(R64G64B64_SFLOAT);
277 STR(R64G64B64A64_SFLOAT);
278 STR(R11G11B10_UFLOAT);
279 STR(R9G9B9E5_UFLOAT);
280 STR(D16_UNORM);
281 STR(D24_UNORM);
282 STR(D32_SFLOAT);
283 STR(S8_UINT);
284 STR(D16_UNORM_S8_UINT);
285 STR(D24_UNORM_S8_UINT);
286 STR(D32_SFLOAT_S8_UINT);
Courtney Goeltzenleuchterfe8a2e12015-03-03 11:30:36 -0700287 STR(BC1_RGB_UNORM);
288 STR(BC1_RGB_SRGB);
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700289 STR(BC2_UNORM);
290 STR(BC2_SRGB);
291 STR(BC3_UNORM);
292 STR(BC3_SRGB);
293 STR(BC4_UNORM);
294 STR(BC4_SNORM);
295 STR(BC5_UNORM);
296 STR(BC5_SNORM);
297 STR(BC6H_UFLOAT);
298 STR(BC6H_SFLOAT);
299 STR(BC7_UNORM);
300 STR(BC7_SRGB);
301 STR(ETC2_R8G8B8_UNORM);
302 STR(ETC2_R8G8B8A1_UNORM);
303 STR(ETC2_R8G8B8A8_UNORM);
304 STR(EAC_R11_UNORM);
305 STR(EAC_R11_SNORM);
306 STR(EAC_R11G11_UNORM);
307 STR(EAC_R11G11_SNORM);
308 STR(ASTC_4x4_UNORM);
309 STR(ASTC_4x4_SRGB);
Courtney Goeltzenleuchterfe8a2e12015-03-03 11:30:36 -0700310 STR(ASTC_5x4_UNORM);
311 STR(ASTC_5x4_SRGB);
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700312 STR(ASTC_5x5_UNORM);
313 STR(ASTC_5x5_SRGB);
314 STR(ASTC_6x5_UNORM);
315 STR(ASTC_6x5_SRGB);
316 STR(ASTC_6x6_UNORM);
317 STR(ASTC_6x6_SRGB);
318 STR(ASTC_8x5_UNORM);
319 STR(ASTC_8x5_SRGB);
320 STR(ASTC_8x6_UNORM);
321 STR(ASTC_8x6_SRGB);
322 STR(ASTC_8x8_UNORM);
323 STR(ASTC_8x8_SRGB);
324 STR(ASTC_10x5_UNORM);
325 STR(ASTC_10x5_SRGB);
326 STR(ASTC_10x6_UNORM);
327 STR(ASTC_10x6_SRGB);
328 STR(ASTC_10x8_UNORM);
329 STR(ASTC_10x8_SRGB);
330 STR(ASTC_10x10_UNORM);
331 STR(ASTC_10x10_SRGB);
332 STR(ASTC_12x10_UNORM);
333 STR(ASTC_12x10_SRGB);
334 STR(ASTC_12x12_UNORM);
335 STR(ASTC_12x12_SRGB);
336 STR(B5G6R5_UNORM);
337 STR(B5G6R5_USCALED);
338 STR(B8G8R8_UNORM);
339 STR(B8G8R8_SNORM);
340 STR(B8G8R8_USCALED);
341 STR(B8G8R8_SSCALED);
342 STR(B8G8R8_UINT);
343 STR(B8G8R8_SINT);
344 STR(B8G8R8_SRGB);
345 STR(B8G8R8A8_UNORM);
346 STR(B8G8R8A8_SNORM);
347 STR(B8G8R8A8_USCALED);
348 STR(B8G8R8A8_SSCALED);
349 STR(B8G8R8A8_UINT);
350 STR(B8G8R8A8_SINT);
351 STR(B8G8R8A8_SRGB);
352 STR(B10G10R10A2_UNORM);
353 STR(B10G10R10A2_SNORM);
354 STR(B10G10R10A2_USCALED);
355 STR(B10G10R10A2_SSCALED);
356 STR(B10G10R10A2_UINT);
357 STR(B10G10R10A2_SINT);
Chia-I Wud4bae362014-07-29 11:15:00 +0800358#undef STR
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700359 default: return "UNKNOWN_FORMAT";
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800360 }
Chia-I Wud4bae362014-07-29 11:15:00 +0800361}
362
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800363static void app_dev_init_formats(struct app_dev *dev)
364{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600365 VkFormat f;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800366
Tony Barbour8205d902015-04-16 15:59:00 -0600367 for (f = 0; f < VK_NUM_FORMAT; f++) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600368 const VkFormat fmt = f;
369 VkResult err;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800370
Chris Forbesd7576302015-06-21 22:55:02 +1200371 err = vkGetPhysicalDeviceFormatInfo(dev->gpu->obj, fmt, &dev->format_props[f]);
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700372 if (err) {
373 memset(&dev->format_props[f], 0,
374 sizeof(dev->format_props[f]));
375 }
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800376 }
377}
378
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600379static void extract_version(uint32_t version, uint32_t *major, uint32_t *minor, uint32_t *patch)
380{
381 *major = version >> 22;
382 *minor = (version >> 12) & 0x3ff;
383 *patch = version & 0xfff;
384}
385
386static void app_get_physical_device_layer_extensions(
387 struct app_gpu *gpu,
388 char *layer_name,
389 uint32_t *extension_count,
390 VkExtensionProperties **extension_properties)
391{
392 VkResult err;
393 uint32_t ext_count = 0;
394 VkExtensionProperties *ext_ptr = NULL;
395
396 /* repeat get until VK_INCOMPLETE goes away */
397 do {
398 err = vkGetPhysicalDeviceExtensionProperties(gpu->obj, layer_name, &ext_count, NULL);
399 assert(!err);
400
401 if (ext_ptr) {
402 free(ext_ptr);
403 }
404 ext_ptr = malloc(ext_count * sizeof(VkExtensionProperties));
405 err = vkGetPhysicalDeviceExtensionProperties(gpu->obj, layer_name, &ext_count, ext_ptr);
406 } while (err == VK_INCOMPLETE);
407 assert(!err);
408
409 *extension_count = ext_count;
410 *extension_properties = ext_ptr;
411}
412
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800413static void app_dev_init(struct app_dev *dev, struct app_gpu *gpu)
414{
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600415 VkDeviceCreateInfo info = {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600416 .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800417 .pNext = NULL,
418 .queueRecordCount = 0,
419 .pRequestedQueues = NULL,
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600420 .layerCount = 0,
421 .ppEnabledLayerNames = NULL,
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800422 .extensionCount = 0,
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600423 .ppEnabledExtensionNames = NULL,
Jon Ashburn80d3b712015-05-18 09:06:15 -0600424 .flags = 0,
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800425 };
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600426 VkResult U_ASSERT_ONLY err;
427 // Extensions to enable
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600428 static const char *known_extensions[] = {
Ian Elliott7c83aa22015-07-08 17:09:54 -0600429 "VK_WSI_LunarG",
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600430 };
Tony Barbour426b9052015-06-24 16:06:58 -0600431
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600432 uint32_t count = 0;
433
434 /* Scan layers */
435 VkLayerProperties *device_layer_properties = NULL;
436 struct layer_extension_list *device_layers = NULL;
437
438 do {
439 err = vkGetPhysicalDeviceLayerProperties(gpu->obj, &count, NULL);
440 assert(!err);
441
442 if (device_layer_properties) {
443 free(device_layer_properties);
444 }
445 device_layer_properties = malloc(sizeof(VkLayerProperties) * count);
446 assert(device_layer_properties);
447
448 if (device_layers) {
449 free(device_layers);
450 }
451 device_layers = malloc(sizeof(struct layer_extension_list) * count);
452 assert(device_layers);
453
454 err = vkGetPhysicalDeviceLayerProperties(gpu->obj, &count, device_layer_properties);
455 } while (err == VK_INCOMPLETE);
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600456 assert(!err);
457
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600458 gpu->device_layer_count = count;
459 gpu->device_layers = device_layers;
460
461 for (uint32_t i = 0; i < gpu->device_layer_count; i++) {
462 VkLayerProperties *src_info = &device_layer_properties[i];
463 struct layer_extension_list *dst_info = &gpu->device_layers[i];
464 memcpy(&dst_info->layer_properties, src_info, sizeof(VkLayerProperties));
465
466 /* Save away layer extension info for report */
467 app_get_physical_device_layer_extensions(
468 gpu,
469 src_info->layerName,
470 &dst_info->extension_count,
471 &dst_info->extension_properties);
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600472 }
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600473 free(device_layer_properties);
474
475 app_get_physical_device_layer_extensions(
476 gpu,
477 NULL,
478 &gpu->device_extension_count,
479 &gpu->device_extensions);
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600480
Courtney Goeltzenleuchter9e42b882015-06-25 16:24:36 -0600481 fflush(stdout);
482
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600483 uint32_t enabled_extension_count = 0;
484
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600485 for (uint32_t i = 0; i < ARRAY_SIZE(known_extensions); i++) {
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600486 VkBool32 extension_found = 0;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600487 for (uint32_t j = 0; j < gpu->device_extension_count; j++) {
488 VkExtensionProperties *ext_prop = &gpu->device_extensions[j];
489 if (!strcmp(known_extensions[i], ext_prop->extName)) {
490
491 extension_found = 1;
492 enabled_extension_count++;
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600493 }
494 }
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600495 if (!extension_found) {
496 printf("Cannot find extension: %s\n", known_extensions[i]);
497 ERR_EXIT(VK_ERROR_INVALID_EXTENSION);
498 }
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600499 }
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800500
501 /* request all queues */
502 info.queueRecordCount = gpu->queue_count;
503 info.pRequestedQueues = gpu->queue_reqs;
504
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600505 info.layerCount = 0;
506 info.ppEnabledLayerNames = NULL;
507 info.extensionCount = enabled_extension_count;
508 info.ppEnabledExtensionNames = (const char*const*) known_extensions;
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600509 dev->gpu = gpu;
510 err = vkCreateDevice(gpu->obj, &info, &dev->obj);
511 if (err)
512 ERR_EXIT(err);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800513
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800514}
515
516static void app_dev_destroy(struct app_dev *dev)
517{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600518 vkDestroyDevice(dev->obj);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800519}
520
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600521static void app_get_global_layer_extensions(
522 char *layer_name,
523 uint32_t *extension_count,
524 VkExtensionProperties **extension_properties)
525{
526 VkResult err;
527 uint32_t ext_count = 0;
528 VkExtensionProperties *ext_ptr = NULL;
529
530 /* repeat get until VK_INCOMPLETE goes away */
531 do {
532 err = vkGetGlobalExtensionProperties(layer_name, &ext_count, NULL);
533 assert(!err);
534
535 if (ext_ptr) {
536 free(ext_ptr);
537 }
538 ext_ptr = malloc(ext_count * sizeof(VkExtensionProperties));
539 err = vkGetGlobalExtensionProperties(layer_name, &ext_count, ext_ptr);
540 } while (err == VK_INCOMPLETE);
541 assert(!err);
542
543 *extension_count = ext_count;
544 *extension_properties = ext_ptr;
545}
546
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600547static void app_create_instance(struct app_instance *inst)
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800548{
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600549 const VkApplicationInfo app_info = {
550 .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
551 .pNext = NULL,
552 .pAppName = APP_SHORT_NAME,
553 .appVersion = 1,
554 .pEngineName = APP_SHORT_NAME,
555 .engineVersion = 1,
556 .apiVersion = VK_API_VERSION,
557 };
558 VkInstanceCreateInfo inst_info = {
559 .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
560 .pNext = NULL,
561 .pAppInfo = &app_info,
562 .pAllocCb = NULL,
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600563 .layerCount = 0,
564 .ppEnabledLayerNames = NULL,
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600565 .extensionCount = 0,
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600566 .ppEnabledExtensionNames = NULL,
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600567 };
Tony Barbour22a30862015-04-22 09:02:32 -0600568 VkResult U_ASSERT_ONLY err;
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600569 // Global Extensions to enable
Ian Elliottaae1a572015-02-04 16:48:37 -0700570 static char *known_extensions[] = {
Tobin Ehlis97b4c5d2015-04-17 14:05:23 -0600571 "VK_WSI_LunarG",
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800572 };
Tony Barbour426b9052015-06-24 16:06:58 -0600573
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600574 uint32_t global_extension_count = 0;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600575 uint32_t count = 0;
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600576
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600577 /* Scan layers */
578 VkLayerProperties *global_layer_properties = NULL;
579 struct layer_extension_list *global_layers = NULL;
580
581 do {
582 err = vkGetGlobalLayerProperties(&count, NULL);
583 assert(!err);
584
585 if (global_layer_properties) {
586 free(global_layer_properties);
587 }
588 global_layer_properties = malloc(sizeof(VkLayerProperties) * count);
589 assert(global_layer_properties);
590
591 if (global_layers) {
592 free(global_layers);
593 }
594 global_layers = malloc(sizeof(struct layer_extension_list) * count);
595 assert(global_layers);
596
597 err = vkGetGlobalLayerProperties(&count, global_layer_properties);
598 } while (err == VK_INCOMPLETE);
Tobin Ehlis3536b442015-04-16 18:04:57 -0600599 assert(!err);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800600
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600601 inst->global_layer_count = count;
602 inst->global_layers = global_layers;
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600603
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600604 for (uint32_t i = 0; i < inst->global_layer_count; i++) {
605 VkLayerProperties *src_info = &global_layer_properties[i];
606 struct layer_extension_list *dst_info = &inst->global_layers[i];
607 memcpy(&dst_info->layer_properties, src_info, sizeof(VkLayerProperties));
608
609 /* Save away layer extension info for report */
610 app_get_global_layer_extensions(
611 src_info->layerName,
612 &dst_info->extension_count,
613 &dst_info->extension_properties);
614 }
615 free(global_layer_properties);
616
617 /* Collect global extensions */
618 inst->global_extension_count = 0;
619 app_get_global_layer_extensions(
620 NULL,
621 &inst->global_extension_count,
622 &inst->global_extensions);
623
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600624 for (uint32_t i = 0; i < ARRAY_SIZE(known_extensions); i++) {
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600625 VkBool32 extension_found = 0;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600626 for (uint32_t j = 0; j < inst->global_extension_count; j++) {
627 VkExtensionProperties *extension_prop = &inst->global_extensions[j];
628 if (!strcmp(known_extensions[i], extension_prop->extName)) {
629
630 extension_found = 1;
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600631 global_extension_count++;
632 }
Tobin Ehlis3536b442015-04-16 18:04:57 -0600633 }
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600634 if (!extension_found) {
635 printf("Cannot find extension: %s\n", known_extensions[i]);
636 ERR_EXIT(VK_ERROR_INVALID_EXTENSION);
637 }
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800638 }
639
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600640 inst_info.extensionCount = global_extension_count;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600641 inst_info.ppEnabledExtensionNames = (const char * const *) known_extensions;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800642
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600643 err = vkCreateInstance(&inst_info, &inst->instance);
644 if (err == VK_ERROR_INCOMPATIBLE_DRIVER) {
645 printf("Cannot create Vulkan instance.\n");
646 ERR_EXIT(err);
647 } else if (err) {
648 ERR_EXIT(err);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800649 }
650}
651
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600652static void app_destroy_instance(struct app_instance *inst)
653{
654 free(inst->global_extensions);
655 vkDestroyInstance(inst->instance);
656}
657
658
Tony Barbour8205d902015-04-16 15:59:00 -0600659static void app_gpu_init(struct app_gpu *gpu, uint32_t id, VkPhysicalDevice obj)
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800660{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600661 VkResult err;
Ian Elliottaae1a572015-02-04 16:48:37 -0700662 uint32_t i;
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800663
664 memset(gpu, 0, sizeof(*gpu));
665
666 gpu->id = id;
667 gpu->obj = obj;
Tony Barbour426b9052015-06-24 16:06:58 -0600668
669 err = vkGetPhysicalDeviceProperties(gpu->obj, &gpu->props);
670 if (err)
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800671 ERR_EXIT(err);
672
Tony Barbour426b9052015-06-24 16:06:58 -0600673 err = vkGetPhysicalDevicePerformance(gpu->obj, &gpu->perf);
674 if (err)
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800675 ERR_EXIT(err);
676
677 /* get queue count */
Tony Barbour426b9052015-06-24 16:06:58 -0600678 err = vkGetPhysicalDeviceQueueCount(gpu->obj, &gpu->queue_count);
679 if (err)
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800680 ERR_EXIT(err);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800681
682 gpu->queue_props =
683 malloc(sizeof(gpu->queue_props[0]) * gpu->queue_count);
Tony Barbour426b9052015-06-24 16:06:58 -0600684
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800685 if (!gpu->queue_props)
Tony Barbour8205d902015-04-16 15:59:00 -0600686 ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
Tony Barbour426b9052015-06-24 16:06:58 -0600687 err = vkGetPhysicalDeviceQueueProperties(gpu->obj, gpu->queue_count, gpu->queue_props);
688 if (err)
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800689 ERR_EXIT(err);
690
691 /* set up queue requests */
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800692 gpu->queue_reqs = malloc(sizeof(*gpu->queue_reqs) * gpu->queue_count);
693 if (!gpu->queue_reqs)
Tony Barbour8205d902015-04-16 15:59:00 -0600694 ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800695 for (i = 0; i < gpu->queue_count; i++) {
696 gpu->queue_reqs[i].queueNodeIndex = i;
697 gpu->queue_reqs[i].queueCount = gpu->queue_props[i].queueCount;
698 }
699
Tony Barbour426b9052015-06-24 16:06:58 -0600700 err = vkGetPhysicalDeviceMemoryProperties(gpu->obj, &gpu->memory_props);
701 if (err)
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800702 ERR_EXIT(err);
703
Chris Forbesa048b312015-06-21 20:09:12 +1200704 err = vkGetPhysicalDeviceFeatures(gpu->obj, &gpu->features);
705 if (err)
706 ERR_EXIT(err);
707
708 err = vkGetPhysicalDeviceLimits(gpu->obj, &gpu->limits);
709 if (err)
710 ERR_EXIT(err);
711
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800712 app_dev_init(&gpu->dev, gpu);
713 app_dev_init_formats(&gpu->dev);
714}
715
716static void app_gpu_destroy(struct app_gpu *gpu)
717{
718 app_dev_destroy(&gpu->dev);
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600719 free(gpu->device_extensions);
Chia-I Wu46c29dd2014-12-02 21:09:20 +0800720 free(gpu->queue_reqs);
721 free(gpu->queue_props);
722}
723
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600724static void app_dev_dump_format_props(const struct app_dev *dev, VkFormat fmt)
Chia-I Wud4bae362014-07-29 11:15:00 +0800725{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600726 const VkFormatProperties *props = &dev->format_props[fmt];
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800727 struct {
728 const char *name;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600729 VkFlags flags;
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800730 } tilings[2];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600731 uint32_t i;
Chia-I Wud4bae362014-07-29 11:15:00 +0800732
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800733 if (!props->linearTilingFeatures && !props->optimalTilingFeatures)
734 return;
Chia-I Wud4bae362014-07-29 11:15:00 +0800735
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800736 tilings[0].name = "linear";
737 tilings[0].flags = props->linearTilingFeatures;
738 tilings[1].name = "optimal";
739 tilings[1].flags = props->optimalTilingFeatures;
Chia-I Wud4bae362014-07-29 11:15:00 +0800740
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600741 printf("FORMAT_%s\n", vk_format_string(fmt));
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800742 for (i = 0; i < ARRAY_SIZE(tilings); i++) {
743 if (!tilings[i].flags)
744 continue;
Chia-I Wud4bae362014-07-29 11:15:00 +0800745
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800746 printf("\t%s tiling image =%s%s%s\n", tilings[i].name,
Tony Barbour8205d902015-04-16 15:59:00 -0600747 (tilings[i].flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) ? " sampled" : "",
748 (tilings[i].flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) ? " storage" : "",
749 (tilings[i].flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT) ? " atomic" : "");
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600750 printf("\t%s tiling texel =%s%s%s\n", tilings[i].name,
Tony Barbour8205d902015-04-16 15:59:00 -0600751 (tilings[i].flags & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT) ? " TBO" : "",
752 (tilings[i].flags & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT) ? " IBO" : "",
753 (tilings[i].flags & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT) ? " atomic" : "");
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600754 printf("\t%s tiling attachment =%s%s%s\n", tilings[i].name,
Tony Barbour8205d902015-04-16 15:59:00 -0600755 (tilings[i].flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) ? " color" : "",
756 (tilings[i].flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT) ? " blend" : "",
757 (tilings[i].flags & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) ? " depth/stencil" : "");
Courtney Goeltzenleuchterad870812015-04-15 15:29:59 -0600758 printf("\t%s tiling vertex = %u\n", tilings[i].name,
Tony Barbour8205d902015-04-16 15:59:00 -0600759 (bool) (tilings[i].flags & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT));
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800760 printf("\t%s tiling conversion = %u\n", tilings[i].name,
Tony Barbour8205d902015-04-16 15:59:00 -0600761 (bool) (tilings[i].flags & VK_FORMAT_FEATURE_CONVERSION_BIT));
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800762 }
Chia-I Wud4bae362014-07-29 11:15:00 +0800763}
764
Chia-I Wud4bae362014-07-29 11:15:00 +0800765
766static void
767app_dev_dump(const struct app_dev *dev)
768{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600769 VkFormat fmt;
Chia-I Wud4bae362014-07-29 11:15:00 +0800770
Tony Barbour8205d902015-04-16 15:59:00 -0600771 for (fmt = 0; fmt < VK_NUM_FORMAT; fmt++) {
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700772 app_dev_dump_format_props(dev, fmt);
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800773 }
Chia-I Wud4bae362014-07-29 11:15:00 +0800774}
775
Mike Stroyan009d8ca2015-05-27 13:09:15 -0600776#ifdef _WIN32
777#define PRINTF_SIZE_T_SPECIFIER "%Iu"
778#else
779#define PRINTF_SIZE_T_SPECIFIER "%zu"
780#endif
781
Chris Forbesa048b312015-06-21 20:09:12 +1200782static void app_gpu_dump_features(const struct app_gpu *gpu)
783{
784 const VkPhysicalDeviceFeatures *features = &gpu->features;
785
786 printf("VkPhysicalDeviceFeatures\n");
787 /* TODO: add interesting features */
788 printf("\tgeometryShader = %u\n", features->geometryShader);
789}
790
791static void app_gpu_dump_limits(const struct app_gpu *gpu)
792{
793 const VkPhysicalDeviceLimits *limits = &gpu->limits;
794
795 printf("VkPhysicalDeviceLimits\n");
796 /* TODO: add interesting limits */
797 printf("\tmaxInlineMemoryUpdateSize = " PRINTF_SIZE_T_SPECIFIER "\n", limits->maxInlineMemoryUpdateSize);
798 printf("\tmaxBoundDescriptorSets = %u\n", limits->maxBoundDescriptorSets);
799 printf("\tmaxComputeWorkGroupInvocations = %u\n", limits->maxComputeWorkGroupInvocations);
800 printf("\ttimestampFrequency = %lu\n", limits->timestampFrequency);
Chia-I Wud4bae362014-07-29 11:15:00 +0800801}
802
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600803static void app_gpu_dump_props(const struct app_gpu *gpu)
804{
805 const VkPhysicalDeviceProperties *props = &gpu->props;
806
807 printf("VkPhysicalDeviceProperties\n");
808 printf("\tapiVersion = %u\n", props->apiVersion);
809 printf("\tdriverVersion = %u\n", props->driverVersion);
810 printf("\tvendorId = 0x%04x\n", props->vendorId);
811 printf("\tdeviceId = 0x%04x\n", props->deviceId);
812 printf("\tdeviceType = %s\n", vk_physical_device_type_string(props->deviceType));
813 printf("\tdeviceName = %s\n", props->deviceName);
814 fflush(stdout);
815}
816
Chia-I Wud4bae362014-07-29 11:15:00 +0800817static void app_gpu_dump_perf(const struct app_gpu *gpu)
818{
Tony Barbour8205d902015-04-16 15:59:00 -0600819 const VkPhysicalDevicePerformance *perf = &gpu->perf;
Chia-I Wud4bae362014-07-29 11:15:00 +0800820
Tony Barbour8205d902015-04-16 15:59:00 -0600821 printf("VkPhysicalDevicePerformance\n");
822 printf("\tmaxGpuClock = %f\n", perf->maxDeviceClock);
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800823 printf("\taluPerClock = %f\n", perf->aluPerClock);
824 printf("\ttexPerClock = %f\n", perf->texPerClock);
825 printf("\tprimsPerClock = %f\n", perf->primsPerClock);
826 printf("\tpixelsPerClock = %f\n", perf->pixelsPerClock);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600827 fflush(stdout);
Chia-I Wud4bae362014-07-29 11:15:00 +0800828}
829
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600830static void app_dump_extensions(
831 const char *indent,
832 const char *layer_name,
833 const uint32_t extension_count,
834 const VkExtensionProperties *extension_properties)
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600835{
836 uint32_t i;
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600837 if (layer_name && (strlen(layer_name) > 0)) {
838 printf("%s%s Extensions", indent, layer_name);
839 } else {
840 printf("Extensions");
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600841 }
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600842 printf("\tcount = %d\n", extension_count);
843 for (i=0; i< extension_count; i++) {
844 uint32_t major, minor, patch;
845 char spec_version[64], extension_version[64];
846 VkExtensionProperties const *ext_prop = &extension_properties[i];
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600847
Courtney Goeltzenleuchterff87c822014-10-03 18:05:10 -0600848 if (i>0)
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600849 printf("\n"); // separator between extensions
850
851 printf("%s\t", indent);
852 extract_version(ext_prop->specVersion, &major, &minor, &patch);
853 snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", major, minor, patch);
854 extract_version(ext_prop->version, &major, &minor, &patch);
855 snprintf(extension_version, sizeof(extension_version), "%d.%d.%d", major, minor, patch);
856 printf("%s: Vulkan version %s, extension version %s",
857 ext_prop->extName, spec_version, extension_version);
Courtney Goeltzenleuchterff87c822014-10-03 18:05:10 -0600858 }
859 printf("\n");
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600860 fflush(stdout);
Courtney Goeltzenleuchterff87c822014-10-03 18:05:10 -0600861}
862
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600863static void app_gpu_dump_queue_props(const struct app_gpu *gpu, uint32_t id)
Chia-I Wud4bae362014-07-29 11:15:00 +0800864{
Tony Barbour8205d902015-04-16 15:59:00 -0600865 const VkPhysicalDeviceQueueProperties *props = &gpu->queue_props[id];
Chia-I Wud4bae362014-07-29 11:15:00 +0800866
Tony Barbour8205d902015-04-16 15:59:00 -0600867 printf("VkPhysicalDeviceQueueProperties[%d]\n", id);
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800868 printf("\tqueueFlags = %c%c%c%c\n",
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600869 (props->queueFlags & VK_QUEUE_GRAPHICS_BIT) ? 'G' : '.',
870 (props->queueFlags & VK_QUEUE_COMPUTE_BIT) ? 'C' : '.',
871 (props->queueFlags & VK_QUEUE_DMA_BIT) ? 'D' : '.',
872 (props->queueFlags & VK_QUEUE_EXTENDED_BIT) ? 'X' : '.');
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800873 printf("\tqueueCount = %u\n", props->queueCount);
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800874 printf("\tsupportsTimestamps = %u\n", props->supportsTimestamps);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600875 fflush(stdout);
Chia-I Wud4bae362014-07-29 11:15:00 +0800876}
877
878static void app_gpu_dump_memory_props(const struct app_gpu *gpu)
879{
Tony Barbour8205d902015-04-16 15:59:00 -0600880 const VkPhysicalDeviceMemoryProperties *props = &gpu->memory_props;
Chia-I Wud4bae362014-07-29 11:15:00 +0800881
Tony Barbour8205d902015-04-16 15:59:00 -0600882 printf("VkPhysicalDeviceMemoryProperties\n");
Mark Lobodzinski72346292015-07-02 16:49:40 -0600883 printf("\tmemoryTypeCount = %u\n", props->memoryTypeCount);
884 for (uint32_t i = 0; i < props->memoryTypeCount; i++) {
885 printf("\tmemoryTypes[%u] : \n", i);
886 printf("\t\tpropertyFlags = %u\n", props->memoryTypes[i].propertyFlags);
887 printf("\t\theapIndex = %u\n", props->memoryTypes[i].heapIndex);
888 }
889 printf("\tmemoryHeapCount = %u\n", props->memoryHeapCount);
890 for (uint32_t i = 0; i < props->memoryHeapCount; i++) {
891 printf("\tmemoryHeaps[%u] : \n", i);
892 printf("\t\tsize = " PRINTF_SIZE_T_SPECIFIER "\n", props->memoryHeaps[i].size);
893 }
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600894 fflush(stdout);
Chia-I Wud4bae362014-07-29 11:15:00 +0800895}
896
897static void app_gpu_dump(const struct app_gpu *gpu)
898{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600899 uint32_t i;
Chia-I Wuf5c46f42014-08-05 15:33:40 +0800900
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800901 printf("GPU%u\n", gpu->id);
902 app_gpu_dump_props(gpu);
903 printf("\n");
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600904 app_dump_extensions("", "", gpu->device_extension_count, gpu->device_extensions);
905 printf("\n");
906 printf("Layers\tcount = %d\n", gpu->device_layer_count);
907 for (uint32_t i = 0; i < gpu->device_layer_count; i++) {
908 uint32_t major, minor, patch;
909 char spec_version[64], layer_version[64];
910 struct layer_extension_list const *layer_info = &gpu->device_layers[i];
911
912 extract_version(layer_info->layer_properties.specVersion, &major, &minor, &patch);
913 snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", major, minor, patch);
914 extract_version(layer_info->layer_properties.implVersion, &major, &minor, &patch);
915 snprintf(layer_version, sizeof(layer_version), "%d.%d.%d", major, minor, patch);
916 printf("\t%s (%s) Vulkan version %s, layer version %s\n",
917 layer_info->layer_properties.layerName,
918 layer_info->layer_properties.description,
919 spec_version, layer_version);
920
921 app_dump_extensions("\t",
922 layer_info->layer_properties.layerName,
923 layer_info->extension_count,
924 layer_info->extension_properties);
925 fflush(stdout);
926 }
Courtney Goeltzenleuchterff87c822014-10-03 18:05:10 -0600927 printf("\n");
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800928 app_gpu_dump_perf(gpu);
929 printf("\n");
930 for (i = 0; i < gpu->queue_count; i++) {
931 app_gpu_dump_queue_props(gpu, i);
932 printf("\n");
933 }
934 app_gpu_dump_memory_props(gpu);
935 printf("\n");
Chris Forbesa048b312015-06-21 20:09:12 +1200936 app_gpu_dump_features(gpu);
937 printf("\n");
938 app_gpu_dump_limits(gpu);
939 printf("\n");
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800940 app_dev_dump(&gpu->dev);
Chia-I Wud4bae362014-07-29 11:15:00 +0800941}
942
Chia-I Wud4bae362014-07-29 11:15:00 +0800943int main(int argc, char **argv)
944{
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800945 struct app_gpu gpus[MAX_GPUS];
Tony Barbour8205d902015-04-16 15:59:00 -0600946 VkPhysicalDevice objs[MAX_GPUS];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600947 uint32_t gpu_count, i;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600948 VkResult err;
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600949 struct app_instance inst;
Chia-I Wud4bae362014-07-29 11:15:00 +0800950
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600951 app_create_instance(&inst);
Courtney Goeltzenleuchter18061cd2015-06-29 15:39:26 -0600952 app_dump_extensions("", "Global", inst.global_extension_count, inst.global_extensions);
953
954 printf("Global Layers\tcount = %d\n", inst.global_layer_count);
955 for (uint32_t i = 0; i < inst.global_layer_count; i++) {
956 uint32_t major, minor, patch;
957 char spec_version[64], layer_version[64];
958 VkLayerProperties const *layer_prop = &inst.global_layers[i].layer_properties;
959
960 extract_version(layer_prop->specVersion, &major, &minor, &patch);
961 snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", major, minor, patch);
962 extract_version(layer_prop->implVersion, &major, &minor, &patch);
963 snprintf(layer_version, sizeof(layer_version), "%d.%d.%d", major, minor, patch);
964 printf("\t%s (%s) Vulkan version %s, layer version %s\n",
965 layer_prop->layerName, layer_prop->description, spec_version, layer_version);
966
967 app_dump_extensions("\t",
968 inst.global_layers[i].layer_properties.layerName,
969 inst.global_layers[i].extension_count,
970 inst.global_layers[i].extension_properties);
971 }
Jon Ashburn29669a42015-04-04 14:52:07 -0600972
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600973 err = vkEnumeratePhysicalDevices(inst.instance, &gpu_count, NULL);
Jon Ashburn07b309a2015-04-15 11:31:12 -0600974 if (err)
975 ERR_EXIT(err);
976 if (gpu_count > MAX_GPUS) {
David Pinedo18fb9232015-04-21 14:45:16 -0600977 printf("Too many GPUS found \n");
978 ERR_EXIT(VK_ERROR_UNKNOWN);
Jon Ashburn07b309a2015-04-15 11:31:12 -0600979 }
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600980 err = vkEnumeratePhysicalDevices(inst.instance, &gpu_count, objs);
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800981 if (err)
982 ERR_EXIT(err);
Chia-I Wud4bae362014-07-29 11:15:00 +0800983
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800984 for (i = 0; i < gpu_count; i++) {
985 app_gpu_init(&gpus[i], i, objs[i]);
986 app_gpu_dump(&gpus[i]);
987 printf("\n\n");
988 }
Chia-I Wud4bae362014-07-29 11:15:00 +0800989
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800990 for (i = 0; i < gpu_count; i++)
991 app_gpu_destroy(&gpus[i]);
Chia-I Wud4bae362014-07-29 11:15:00 +0800992
Courtney Goeltzenleuchter3c1ccf52015-06-04 16:20:06 -0600993 app_destroy_instance(&inst);
Chia-I Wu0b9a7372014-08-06 12:09:19 +0800994
Chia-I Wu190ebdc2014-08-06 12:04:13 +0800995 return 0;
Chia-I Wud4bae362014-07-29 11:15:00 +0800996}
Ian Elliottea95f5c2015-04-17 21:23:34 -0600997
998#ifdef _WIN32
David Pinedo18fb9232015-04-21 14:45:16 -0600999
1000// Create a console window with a large scrollback size to which to send stdout.
1001// Returns true if console window was successfully created, false otherwise.
1002bool SetStdOutToNewConsole()
1003{
1004 // don't do anything if we already have a console
1005 if (GetStdHandle(STD_OUTPUT_HANDLE))
1006 return false;
1007
1008 // allocate a console for this app
1009 AllocConsole();
1010
1011 // redirect unbuffered STDOUT to the console
1012 HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
1013 int fileDescriptor = _open_osfhandle((intptr_t)consoleHandle, _O_TEXT);
1014 FILE *fp = _fdopen( fileDescriptor, "w" );
1015 *stdout = *fp;
1016 setvbuf( stdout, NULL, _IONBF, 0 );
1017
1018 // make the console window bigger
1019 CONSOLE_SCREEN_BUFFER_INFO csbi;
1020 SMALL_RECT r;
1021 COORD bufferSize;
1022 if (!GetConsoleScreenBufferInfo(consoleHandle, &csbi))
1023 return false;
1024 bufferSize.X = csbi.dwSize.X;
1025 bufferSize.Y = 1000;
1026 if (!SetConsoleScreenBufferSize(consoleHandle, bufferSize))
1027 return false;
1028 r.Left = r.Top = 0;
1029 r.Right = csbi.dwSize.X-1;
1030 r.Bottom = 60;
1031 if (!SetConsoleWindowInfo(consoleHandle, true, &r))
1032 return false;
1033
1034 // change the console window title
Ian Elliott4e19ed02015-04-28 10:52:52 -06001035 if (!SetConsoleTitle(TEXT(APP_SHORT_NAME)))
David Pinedo18fb9232015-04-21 14:45:16 -06001036 return false;
1037
1038 return true;
1039}
1040
Ian Elliottea95f5c2015-04-17 21:23:34 -06001041int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int nCmdShow)
1042{
1043 char *argv = pCmdLine;
David Pinedo18fb9232015-04-21 14:45:16 -06001044 consoleCreated = SetStdOutToNewConsole();
Ian Elliottea95f5c2015-04-17 21:23:34 -06001045 main(1, &argv);
1046 fflush(stdout);
David Pinedo18fb9232015-04-21 14:45:16 -06001047 if (consoleCreated)
1048 Sleep(INFINITE);
Ian Elliottea95f5c2015-04-17 21:23:34 -06001049}
1050#endif