1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 *
7 */
8
9 //
10 //
11 //
12
13 #include <stdlib.h>
14 #include <stdio.h>
15
16 //
17 //
18 //
19
20 #include "assert_vk.h"
21
22 //
23 //
24 //
25
26 #define VK_RESULT_TO_STRING(result) case result: return #result
27
28 //
29 // FIXME -- results and errors
30 //
31
32 char const *
vk_get_result_string(VkResult const result)33 vk_get_result_string(VkResult const result)
34 {
35 switch (result)
36 {
37 //
38 // Results
39 //
40 VK_RESULT_TO_STRING(VK_SUCCESS);
41 VK_RESULT_TO_STRING(VK_NOT_READY);
42 VK_RESULT_TO_STRING(VK_TIMEOUT);
43 VK_RESULT_TO_STRING(VK_EVENT_SET);
44 VK_RESULT_TO_STRING(VK_EVENT_RESET);
45 VK_RESULT_TO_STRING(VK_INCOMPLETE);
46 //
47 // Errors
48 //
49 VK_RESULT_TO_STRING(VK_ERROR_OUT_OF_HOST_MEMORY);
50 VK_RESULT_TO_STRING(VK_ERROR_OUT_OF_DEVICE_MEMORY);
51 VK_RESULT_TO_STRING(VK_ERROR_INITIALIZATION_FAILED);
52 VK_RESULT_TO_STRING(VK_ERROR_DEVICE_LOST);
53 VK_RESULT_TO_STRING(VK_ERROR_MEMORY_MAP_FAILED);
54 VK_RESULT_TO_STRING(VK_ERROR_LAYER_NOT_PRESENT);
55 VK_RESULT_TO_STRING(VK_ERROR_EXTENSION_NOT_PRESENT);
56 VK_RESULT_TO_STRING(VK_ERROR_FEATURE_NOT_PRESENT);
57 VK_RESULT_TO_STRING(VK_ERROR_INCOMPATIBLE_DRIVER);
58 VK_RESULT_TO_STRING(VK_ERROR_TOO_MANY_OBJECTS);
59 VK_RESULT_TO_STRING(VK_ERROR_FORMAT_NOT_SUPPORTED);
60 VK_RESULT_TO_STRING(VK_ERROR_FRAGMENTED_POOL);
61 VK_RESULT_TO_STRING(VK_ERROR_OUT_OF_POOL_MEMORY);
62 VK_RESULT_TO_STRING(VK_ERROR_INVALID_EXTERNAL_HANDLE);
63 VK_RESULT_TO_STRING(VK_ERROR_SURFACE_LOST_KHR);
64 VK_RESULT_TO_STRING(VK_ERROR_NATIVE_WINDOW_IN_USE_KHR);
65 VK_RESULT_TO_STRING(VK_SUBOPTIMAL_KHR);
66 VK_RESULT_TO_STRING(VK_ERROR_OUT_OF_DATE_KHR);
67 VK_RESULT_TO_STRING(VK_ERROR_INCOMPATIBLE_DISPLAY_KHR);
68 VK_RESULT_TO_STRING(VK_ERROR_VALIDATION_FAILED_EXT);
69 VK_RESULT_TO_STRING(VK_ERROR_INVALID_SHADER_NV);
70 VK_RESULT_TO_STRING(VK_ERROR_FRAGMENTATION_EXT);
71 VK_RESULT_TO_STRING(VK_ERROR_NOT_PERMITTED_EXT);
72
73 //
74 // Extensions: vk_xyz
75 //
76 default:
77 return "UNKNOWN VULKAN RESULT";
78 }
79 }
80
81 //
82 //
83 //
84
85 VkResult
assert_vk(VkResult const result,char const * const file,int const line,bool const abort)86 assert_vk(VkResult const result, char const * const file, int const line, bool const abort)
87 {
88 if (result != VK_SUCCESS)
89 {
90 char const * const vk_result_str = vk_get_result_string(result);
91
92 fprintf(stderr,
93 "\"%s\", line %d: assert_vk( %d ) = \"%s\"",
94 file,line,result,vk_result_str);
95
96 if (abort)
97 {
98 // stop profiling and reset device here if necessary
99 exit(result);
100 }
101 }
102
103 return result;
104 }
105
106 //
107 //
108 //
109