diff --git a/base/VulkanDebug.cpp b/base/VulkanDebug.cpp index 8f642bfa..c18f1364 100644 --- a/base/VulkanDebug.cpp +++ b/base/VulkanDebug.cpp @@ -1,9 +1,7 @@ /* * Vulkan examples debug wrapper * -* Appendix for VK_EXT_Debug_Report can be found at https://github.com/KhronosGroup/Vulkan-Docs/blob/1.0-VK_EXT_debug_report/doc/specs/vulkan/appendices/debug_report.txt -* -* Copyright (C) 2016 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) */ @@ -15,25 +13,6 @@ namespace vks { namespace debug { -#if !defined(__ANDROID__) - // On desktop the LunarG loaders exposes a meta layer that contains all layers - int32_t validationLayerCount = 1; - const char *validationLayerNames[] = { - "VK_LAYER_LUNARG_standard_validation" - }; -#else - // On Android we need to explicitly select all layers - int32_t validationLayerCount = 6; - const char *validationLayerNames[] = { - "VK_LAYER_GOOGLE_threading", - "VK_LAYER_LUNARG_parameter_validation", - "VK_LAYER_LUNARG_object_tracker", - "VK_LAYER_LUNARG_core_validation", - "VK_LAYER_LUNARG_swapchain", - "VK_LAYER_GOOGLE_unique_objects" - }; -#endif - PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallback = VK_NULL_HANDLE; PFN_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallback = VK_NULL_HANDLE; PFN_vkDebugReportMessageEXT dbgBreakCallback = VK_NULL_HANDLE; diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index e695a910..a197c39f 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -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 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); }