Merge branch 'master' into libktx
This commit is contained in:
commit
27ab72d73f
262 changed files with 1400 additions and 494 deletions
|
|
@ -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,127 +13,79 @@ 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_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT;
|
||||
PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT;
|
||||
VkDebugUtilsMessengerEXT debugUtilsMessenger;
|
||||
|
||||
PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallback = VK_NULL_HANDLE;
|
||||
PFN_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallback = VK_NULL_HANDLE;
|
||||
PFN_vkDebugReportMessageEXT dbgBreakCallback = VK_NULL_HANDLE;
|
||||
|
||||
VkDebugReportCallbackEXT msgCallback;
|
||||
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL messageCallback(
|
||||
VkDebugReportFlagsEXT flags,
|
||||
VkDebugReportObjectTypeEXT objType,
|
||||
uint64_t srcObject,
|
||||
size_t location,
|
||||
int32_t msgCode,
|
||||
const char* pLayerPrefix,
|
||||
const char* pMsg,
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessengerCallback(
|
||||
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||
VkDebugUtilsMessageTypeFlagsEXT messageType,
|
||||
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
|
||||
void* pUserData)
|
||||
{
|
||||
// Select prefix depending on flags passed to the callback
|
||||
// Note that multiple flags may be set for a single validation message
|
||||
std::string prefix("");
|
||||
|
||||
// Error that may result in undefined behaviour
|
||||
if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT)
|
||||
{
|
||||
prefix += "ERROR:";
|
||||
};
|
||||
// Warnings may hint at unexpected / non-spec API usage
|
||||
if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT)
|
||||
{
|
||||
prefix += "WARNING:";
|
||||
};
|
||||
// May indicate sub-optimal usage of the API
|
||||
if (flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT)
|
||||
{
|
||||
prefix += "PERFORMANCE:";
|
||||
};
|
||||
// Informal messages that may become handy during debugging
|
||||
if (flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT)
|
||||
{
|
||||
prefix += "INFO:";
|
||||
if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) {
|
||||
prefix = "VERBOSE: ";
|
||||
}
|
||||
// Diagnostic info from the Vulkan loader and layers
|
||||
// Usually not helpful in terms of API usage, but may help to debug layer and loader problems
|
||||
if (flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT)
|
||||
{
|
||||
prefix += "DEBUG:";
|
||||
else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) {
|
||||
prefix = "INFO: ";
|
||||
}
|
||||
else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) {
|
||||
prefix = "WARNING: ";
|
||||
}
|
||||
else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
|
||||
prefix = "ERROR: ";
|
||||
}
|
||||
|
||||
|
||||
// Display message to default output (console/logcat)
|
||||
std::stringstream debugMessage;
|
||||
debugMessage << prefix << " [" << pLayerPrefix << "] Code " << msgCode << " : " << pMsg;
|
||||
debugMessage << prefix << "[" << pCallbackData->messageIdNumber << "][" << pCallbackData->pMessageIdName << "] : " << pCallbackData->pMessage;
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) {
|
||||
if (messageSeverity >= VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
|
||||
LOGE("%s", debugMessage.str().c_str());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
LOGD("%s", debugMessage.str().c_str());
|
||||
}
|
||||
#else
|
||||
if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) {
|
||||
if (messageSeverity >= VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
|
||||
std::cerr << debugMessage.str() << "\n";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
std::cout << debugMessage.str() << "\n";
|
||||
}
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
// The return value of this callback controls wether the Vulkan call that caused
|
||||
// the validation message will be aborted or not
|
||||
// We return VK_FALSE as we DON'T want Vulkan calls that cause a validation message
|
||||
// (and return a VkResult) to abort
|
||||
// If you instead want to have calls abort, pass in VK_TRUE and the function will
|
||||
// return VK_ERROR_VALIDATION_FAILED_EXT
|
||||
// The return value of this callback controls wether the Vulkan call that caused the validation message will be aborted or not
|
||||
// We return VK_FALSE as we DON'T want Vulkan calls that cause a validation message to abort
|
||||
// If you instead want to have calls abort, pass in VK_TRUE and the function will return VK_ERROR_VALIDATION_FAILED_EXT
|
||||
return VK_FALSE;
|
||||
}
|
||||
|
||||
void setupDebugging(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportCallbackEXT callBack)
|
||||
{
|
||||
CreateDebugReportCallback = reinterpret_cast<PFN_vkCreateDebugReportCallbackEXT>(vkGetInstanceProcAddr(instance, "vkCreateDebugReportCallbackEXT"));
|
||||
DestroyDebugReportCallback = reinterpret_cast<PFN_vkDestroyDebugReportCallbackEXT>(vkGetInstanceProcAddr(instance, "vkDestroyDebugReportCallbackEXT"));
|
||||
dbgBreakCallback = reinterpret_cast<PFN_vkDebugReportMessageEXT>(vkGetInstanceProcAddr(instance, "vkDebugReportMessageEXT"));
|
||||
|
||||
VkDebugReportCallbackCreateInfoEXT dbgCreateInfo = {};
|
||||
dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
|
||||
dbgCreateInfo.pfnCallback = (PFN_vkDebugReportCallbackEXT)messageCallback;
|
||||
dbgCreateInfo.flags = flags;
|
||||
vkCreateDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT"));
|
||||
vkDestroyDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT"));
|
||||
|
||||
VkResult err = CreateDebugReportCallback(
|
||||
instance,
|
||||
&dbgCreateInfo,
|
||||
nullptr,
|
||||
(callBack != VK_NULL_HANDLE) ? &callBack : &msgCallback);
|
||||
assert(!err);
|
||||
VkDebugUtilsMessengerCreateInfoEXT debugUtilsMessengerCI{};
|
||||
debugUtilsMessengerCI.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
|
||||
debugUtilsMessengerCI.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
|
||||
debugUtilsMessengerCI.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT;
|
||||
debugUtilsMessengerCI.pfnUserCallback = debugUtilsMessengerCallback;
|
||||
VkResult result = vkCreateDebugUtilsMessengerEXT(instance, &debugUtilsMessengerCI, nullptr, &debugUtilsMessenger);
|
||||
assert(result == VK_SUCCESS);
|
||||
}
|
||||
|
||||
void freeDebugCallback(VkInstance instance)
|
||||
{
|
||||
if (msgCallback != VK_NULL_HANDLE)
|
||||
if (debugUtilsMessenger != VK_NULL_HANDLE)
|
||||
{
|
||||
DestroyDebugReportCallback(instance, msgCallback, nullptr);
|
||||
vkDestroyDebugUtilsMessengerEXT(instance, debugUtilsMessenger, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
*/
|
||||
|
|
@ -58,15 +58,34 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation)
|
|||
{
|
||||
if (settings.validation)
|
||||
{
|
||||
instanceExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
|
||||
instanceExtensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
||||
}
|
||||
instanceCreateInfo.enabledExtensionCount = (uint32_t)instanceExtensions.size();
|
||||
instanceCreateInfo.ppEnabledExtensionNames = instanceExtensions.data();
|
||||
}
|
||||
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 (VkLayerProperties layer : 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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue