@@ -33,6 +33,73 @@ static const char *find_extensions(const VkExtensionProperties *avail,
33
33
return NULL ;
34
34
}
35
35
36
+ static const char * const * get_instance_layers (uint32_t * layer_count ) {
37
+ // TODO request layer via env var WLR_VK_INSTANCE_LAYER
38
+ static const char * const layers [] = {
39
+ "VK_LAYER_KHRONOS_validation" ,
40
+ // "VK_LAYER_RENDERDOC_Capture",
41
+ // "VK_LAYER_live_introspection",
42
+ };
43
+
44
+ static const size_t layers_len = sizeof (layers ) / sizeof (layers [0 ]);
45
+
46
+ VkLayerProperties * layer_props = NULL ;
47
+
48
+ uint32_t count ;
49
+ if (vkEnumerateInstanceLayerProperties (& count , NULL ) != VK_SUCCESS ) {
50
+ wlr_log (WLR_ERROR , "Failed to call vkEnumerateInstanceLayerProperties" );
51
+ goto layers_err ;
52
+ }
53
+
54
+ if (count == 0 ) {
55
+ wlr_log (WLR_DEBUG , "No validation layers found" );
56
+ goto layers_err ;
57
+ }
58
+ wlr_log (WLR_DEBUG , "%" PRIu32 " instance layers available" , count );
59
+
60
+ layer_props = calloc ((size_t )count , sizeof (VkLayerProperties ));
61
+ if (layer_props == NULL ) {
62
+ wlr_log (WLR_ERROR , "Failed to allocate %" PRIu32 " VkLayerProperties" ,
63
+ count );
64
+ goto layers_err ;
65
+ }
66
+
67
+ if (vkEnumerateInstanceLayerProperties (& count , layer_props ) != VK_SUCCESS ) {
68
+ wlr_log (WLR_ERROR , "Failed to call vkEnumerateInstanceLayerProperties" );
69
+ goto layers_err ;
70
+ }
71
+
72
+ for (uint32_t i = 0 ; i < count ; ++ i ) {
73
+ wlr_log (WLR_DEBUG , "Vulkan instance validation layer %s v%" PRIu32 ,
74
+ layer_props [i ].layerName , layer_props [i ].implementationVersion );
75
+ }
76
+
77
+ for (uint32_t i = 0 ; i < layers_len ; ++ i ) {
78
+ bool found ;
79
+ for (size_t j = 0 ; j < count ; ++ j ) {
80
+ if (strcmp (layer_props [j ].layerName , layers [i ]) == 0 ) {
81
+ found = true;
82
+ break ;
83
+ }
84
+ }
85
+
86
+ if (!found ) {
87
+ wlr_log (WLR_ERROR , "Vulkan instance layer %s not found" , layers [i ]);
88
+ goto layers_err ;
89
+ }
90
+ }
91
+
92
+ free (layer_props );
93
+
94
+ * layer_count = layers_len ;
95
+ return layers ;
96
+
97
+ layers_err :
98
+ free (layer_props );
99
+ * layer_count = 0 ;
100
+ return NULL ;
101
+ }
102
+
36
103
static VkBool32 debug_callback (VkDebugUtilsMessageSeverityFlagBitsEXT severity ,
37
104
VkDebugUtilsMessageTypeFlagsEXT type ,
38
105
const VkDebugUtilsMessengerCallbackDataEXT * debug_data ,
@@ -163,21 +230,21 @@ struct wlr_vk_instance *vulkan_instance_create(size_t ext_count,
163
230
application_info .engineVersion = WLR_VERSION_NUM ;
164
231
application_info .apiVersion = VK_API_VERSION_1_1 ;
165
232
166
- const char * layers [] = {
167
- "VK_LAYER_KHRONOS_validation" ,
168
- // "VK_LAYER_RENDERDOC_Capture ",
169
- // "VK_LAYER_live_introspection",
170
- };
171
-
172
- unsigned layer_count = debug * ( sizeof ( layers ) / sizeof ( layers [ 0 ]));
233
+ uint32_t layer_count = 0 ;
234
+ const char * const * layers = get_instance_layers ( & layer_count );
235
+ wlr_log ( WLR_DEBUG , "Using %" PRIu32 " instance validation layers " ,
236
+ layer_count );
237
+ for ( uint32_t i = 0 ; i < layer_count ; ++ i ) {
238
+ wlr_log ( WLR_DEBUG , "%s" , layers [ i ]);
239
+ }
173
240
174
241
VkInstanceCreateInfo instance_info = {0 };
175
242
instance_info .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO ;
176
243
instance_info .pApplicationInfo = & application_info ;
177
244
instance_info .enabledExtensionCount = ini -> extension_count ;
178
245
instance_info .ppEnabledExtensionNames = ini -> extensions ;
179
246
instance_info .enabledLayerCount = layer_count ;
180
- instance_info .ppEnabledLayerNames = layers ;
247
+ instance_info .ppEnabledLayerNames = ( const char * const * ) layers ;
181
248
182
249
VkDebugUtilsMessageSeverityFlagsEXT severity =
183
250
// VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT |
0 commit comments