Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 347b326

Browse files
committed
render/vulkan: get only available validation layers
1 parent fb393dd commit 347b326

File tree

1 file changed

+74
-8
lines changed

1 file changed

+74
-8
lines changed

render/vulkan/vulkan.c

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,72 @@ static const char *find_extensions(const VkExtensionProperties *avail,
3333
return NULL;
3434
}
3535

36+
static const char* const *get_instance_layers(uint32_t *layer_count) {
37+
static const char * const layers[] = {
38+
"VK_LAYER_KHRONOS_validation",
39+
// "VK_LAYER_RENDERDOC_Capture",
40+
// "VK_LAYER_live_introspection",
41+
};
42+
43+
static const size_t layers_len = sizeof(layers) / sizeof(layers[0]);
44+
45+
VkLayerProperties *layer_props = NULL;
46+
47+
uint32_t count;
48+
if (vkEnumerateInstanceLayerProperties(&count, NULL) != VK_SUCCESS) {
49+
wlr_log(WLR_ERROR, "Failed to call vkEnumerateInstanceLayerProperties");
50+
goto layers_err;
51+
}
52+
53+
if (count == 0) {
54+
wlr_log(WLR_DEBUG, "No validation layers found");
55+
goto layers_err;
56+
}
57+
wlr_log(WLR_DEBUG, "%"PRIu32" instance layers available", count);
58+
59+
layer_props = calloc((size_t)count, sizeof(VkLayerProperties));
60+
if (layer_props == NULL) {
61+
wlr_log(WLR_ERROR, "Failed to allocate %"PRIu32" VkLayerProperties",
62+
count);
63+
goto layers_err;
64+
}
65+
66+
if (vkEnumerateInstanceLayerProperties(&count, layer_props) != VK_SUCCESS) {
67+
wlr_log(WLR_ERROR, "Failed to call vkEnumerateInstanceLayerProperties");
68+
goto layers_err;
69+
}
70+
71+
for (uint32_t i = 0; i < count; ++i) {
72+
wlr_log(WLR_DEBUG, "Vulkan instance validation layer %s v%"PRIu32,
73+
layer_props[i].layerName, layer_props[i].implementationVersion);
74+
}
75+
76+
for (uint32_t i = 0; i < layers_len; ++i) {
77+
bool found = false;
78+
for (size_t j = 0; j < count; ++j) {
79+
if (strcmp(layer_props[j].layerName, layers[i]) == 0) {
80+
found = true;
81+
break;
82+
}
83+
}
84+
85+
if (!found) {
86+
wlr_log(WLR_ERROR, "Vulkan instance layer %s not found", layers[i]);
87+
goto layers_err;
88+
}
89+
}
90+
91+
free(layer_props);
92+
93+
*layer_count = layers_len;
94+
return layers;
95+
96+
layers_err:
97+
free(layer_props);
98+
*layer_count = 0;
99+
return NULL;
100+
}
101+
36102
static VkBool32 debug_callback(VkDebugUtilsMessageSeverityFlagBitsEXT severity,
37103
VkDebugUtilsMessageTypeFlagsEXT type,
38104
const VkDebugUtilsMessengerCallbackDataEXT *debug_data,
@@ -163,21 +229,21 @@ struct wlr_vk_instance *vulkan_instance_create(size_t ext_count,
163229
application_info.engineVersion = WLR_VERSION_NUM;
164230
application_info.apiVersion = VK_API_VERSION_1_1;
165231

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]));
232+
uint32_t layer_count = 0;
233+
const char * const *layers = get_instance_layers(&layer_count);
234+
wlr_log(WLR_DEBUG, "Using %"PRIu32" instance validation layers",
235+
layer_count);
236+
for (uint32_t i = 0; i < layer_count; ++i) {
237+
wlr_log(WLR_DEBUG, "%s", layers[i]);
238+
}
173239

174240
VkInstanceCreateInfo instance_info = {0};
175241
instance_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
176242
instance_info.pApplicationInfo = &application_info;
177243
instance_info.enabledExtensionCount = ini->extension_count;
178244
instance_info.ppEnabledExtensionNames = ini->extensions;
179245
instance_info.enabledLayerCount = layer_count;
180-
instance_info.ppEnabledLayerNames = layers;
246+
instance_info.ppEnabledLayerNames = (const char *const *)layers;
181247

182248
VkDebugUtilsMessageSeverityFlagsEXT severity =
183249
// VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT |

0 commit comments

Comments
 (0)