Uee new VK_LAYER_KHRONOS_validation layer on all platforms

Check if validation layer is actually present
This commit is contained in:
Sascha Willems 2019-10-18 20:28:54 +02:00
parent 0356b62f81
commit 01bf10f9a8
2 changed files with 23 additions and 25 deletions

View file

@ -1,7 +1,7 @@
/*
* Vulkan Example base class
*
* Copyright (C) 2016-2017 by Sascha Willems - www.saschawillems.de
* Copyright (C) by Sascha Willems - www.saschawillems.de
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/
@ -65,8 +65,27 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation)
}
if (settings.validation)
{
instanceCreateInfo.enabledLayerCount = vks::debug::validationLayerCount;
instanceCreateInfo.ppEnabledLayerNames = vks::debug::validationLayerNames;
// The VK_LAYER_KHRONOS_validation contains all current validation functionality.
// Note that on Android this layer requires at least NDK r20
const char* validationLayerName = "VK_LAYER_KHRONOS_validation";
// Check if this layer is available at instance level
uint32_t instanceLayerCount;
vkEnumerateInstanceLayerProperties(&instanceLayerCount, nullptr);
std::vector<VkLayerProperties> instanceLayerProperties(instanceLayerCount);
vkEnumerateInstanceLayerProperties(&instanceLayerCount, instanceLayerProperties.data());
bool validationLayerPresent = false;
for each (VkLayerProperties layer in instanceLayerProperties) {
if (strcmp(layer.layerName, validationLayerName) == 0) {
validationLayerPresent = true;
break;
}
}
if (validationLayerPresent) {
instanceCreateInfo.ppEnabledLayerNames = &validationLayerName;
instanceCreateInfo.enabledLayerCount = 1;
} else {
std::cerr << "Validation layer VK_LAYER_KHRONOS_validation not present, validation is disabled";
}
}
return vkCreateInstance(&instanceCreateInfo, nullptr, &instance);
}