Sligthly rework validation layer logging to tet file
This commit is contained in:
parent
2e6bf58914
commit
d34494602c
10 changed files with 47 additions and 26 deletions
|
|
@ -14,6 +14,7 @@ namespace vks
|
||||||
namespace debug
|
namespace debug
|
||||||
{
|
{
|
||||||
bool logToFile{ false };
|
bool logToFile{ false };
|
||||||
|
std::string logFileName{ "validation_output.txt" };
|
||||||
|
|
||||||
PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT;
|
PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT;
|
||||||
PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT;
|
PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT;
|
||||||
|
|
@ -31,25 +32,33 @@ namespace vks
|
||||||
if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) {
|
if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) {
|
||||||
prefix = "VERBOSE: ";
|
prefix = "VERBOSE: ";
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
if (!logToFile) {
|
||||||
prefix = "\033[32m" + prefix + "\033[0m";
|
prefix = "\033[32m" + prefix + "\033[0m";
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) {
|
else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) {
|
||||||
prefix = "INFO: ";
|
prefix = "INFO: ";
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
if (!logToFile) {
|
||||||
prefix = "\033[36m" + prefix + "\033[0m";
|
prefix = "\033[36m" + prefix + "\033[0m";
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) {
|
else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) {
|
||||||
prefix = "WARNING: ";
|
prefix = "WARNING: ";
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
if (!logToFile) {
|
||||||
prefix = "\033[33m" + prefix + "\033[0m";
|
prefix = "\033[33m" + prefix + "\033[0m";
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
|
else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
|
||||||
prefix = "ERROR: ";
|
prefix = "ERROR: ";
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
if (!logToFile) {
|
||||||
prefix = "\033[31m" + prefix + "\033[0m";
|
prefix = "\033[31m" + prefix + "\033[0m";
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,10 +85,7 @@ namespace vks
|
||||||
std::cout << debugMessage.str() << "\n\n";
|
std::cout << debugMessage.str() << "\n\n";
|
||||||
}
|
}
|
||||||
if (logToFile) {
|
if (logToFile) {
|
||||||
std::ofstream logfile;
|
log(debugMessage.str());
|
||||||
logfile.open("validation.txt", std::ios_base::app);
|
|
||||||
logfile << debugMessage.str() << std::endl;
|
|
||||||
logfile.close();
|
|
||||||
}
|
}
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -99,6 +105,18 @@ namespace vks
|
||||||
debugUtilsMessengerCI.pfnUserCallback = debugUtilsMessageCallback;
|
debugUtilsMessengerCI.pfnUserCallback = debugUtilsMessageCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void log(std::string message)
|
||||||
|
{
|
||||||
|
if (logToFile) {
|
||||||
|
time_t timestamp;
|
||||||
|
time(×tamp);
|
||||||
|
std::ofstream logfile;
|
||||||
|
logfile.open(logFileName, std::ios_base::app);
|
||||||
|
logfile << strtok(ctime(×tamp), "\n") << ": " << message << std::endl;
|
||||||
|
logfile.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void setupDebugging(VkInstance instance)
|
void setupDebugging(VkInstance instance)
|
||||||
{
|
{
|
||||||
vkCreateDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT"));
|
vkCreateDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT"));
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ namespace vks
|
||||||
namespace debug
|
namespace debug
|
||||||
{
|
{
|
||||||
extern bool logToFile;
|
extern bool logToFile;
|
||||||
|
extern std::string logFileName;
|
||||||
|
|
||||||
// Default debug callback
|
// Default debug callback
|
||||||
VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessageCallback(
|
VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessageCallback(
|
||||||
|
|
@ -49,6 +50,7 @@ namespace vks
|
||||||
void freeDebugCallback(VkInstance instance);
|
void freeDebugCallback(VkInstance instance);
|
||||||
// Used to populate a VkDebugUtilsMessengerCreateInfoEXT with our example messenger function and desired flags
|
// Used to populate a VkDebugUtilsMessengerCreateInfoEXT with our example messenger function and desired flags
|
||||||
void setupDebugingMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& debugUtilsMessengerCI);
|
void setupDebugingMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& debugUtilsMessengerCI);
|
||||||
|
void log(std::string message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrapper for the VK_EXT_debug_utils extension
|
// Wrapper for the VK_EXT_debug_utils extension
|
||||||
|
|
|
||||||
|
|
@ -802,7 +802,7 @@ VulkanExampleBase::VulkanExampleBase()
|
||||||
// Command line arguments
|
// Command line arguments
|
||||||
commandLineParser.add("help", { "--help" }, 0, "Show help");
|
commandLineParser.add("help", { "--help" }, 0, "Show help");
|
||||||
commandLineParser.add("validation", { "-v", "--validation" }, 0, "Enable validation layers");
|
commandLineParser.add("validation", { "-v", "--validation" }, 0, "Enable validation layers");
|
||||||
commandLineParser.add("validationlog", { "-vl", "--validationlog" }, 0, "Log validation messages to a textfile (validation.txt)");
|
commandLineParser.add("validationlogfile", { "-vl", "--validationlogfile" }, 0, "Log validation messages to a textfile");
|
||||||
commandLineParser.add("vsync", { "-vs", "--vsync" }, 0, "Enable V-Sync");
|
commandLineParser.add("vsync", { "-vs", "--vsync" }, 0, "Enable V-Sync");
|
||||||
commandLineParser.add("fullscreen", { "-f", "--fullscreen" }, 0, "Start in fullscreen mode");
|
commandLineParser.add("fullscreen", { "-f", "--fullscreen" }, 0, "Start in fullscreen mode");
|
||||||
commandLineParser.add("width", { "-w", "--width" }, 1, "Set window width");
|
commandLineParser.add("width", { "-w", "--width" }, 1, "Set window width");
|
||||||
|
|
@ -831,12 +831,8 @@ VulkanExampleBase::VulkanExampleBase()
|
||||||
if (commandLineParser.isSet("validation")) {
|
if (commandLineParser.isSet("validation")) {
|
||||||
settings.validation = true;
|
settings.validation = true;
|
||||||
}
|
}
|
||||||
if (commandLineParser.isSet("validationlog")) {
|
if (commandLineParser.isSet("validationlogfile")) {
|
||||||
vks::debug::logToFile = true;
|
vks::debug::logToFile = true;
|
||||||
std::ofstream logfile;
|
|
||||||
logfile.open("validation.txt", std::ios_base::app);
|
|
||||||
logfile << std::endl << "Sample: " << name << std::endl;
|
|
||||||
logfile.close();
|
|
||||||
}
|
}
|
||||||
if (commandLineParser.isSet("vsync")) {
|
if (commandLineParser.isSet("vsync")) {
|
||||||
settings.vsync = true;
|
settings.vsync = true;
|
||||||
|
|
@ -1034,6 +1030,11 @@ bool VulkanExampleBase::initVulkan()
|
||||||
this->settings.validation = true;
|
this->settings.validation = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Validation messages can be stored, e.g. to be used in external tools like CI/CD
|
||||||
|
if (commandLineParser.isSet("validationlogfile")) {
|
||||||
|
vks::debug::log("Sample: " + title);
|
||||||
|
}
|
||||||
|
|
||||||
// Create the instance
|
// Create the instance
|
||||||
VkResult result = createInstance();
|
VkResult result = createInstance();
|
||||||
if (result != VK_SUCCESS) {
|
if (result != VK_SUCCESS) {
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ public:
|
||||||
|
|
||||||
VulkanExample() : VulkanExampleBase()
|
VulkanExample() : VulkanExampleBase()
|
||||||
{
|
{
|
||||||
title = "Vulkan Example - Compute cull and lod";
|
title = "Compute cull and lod";
|
||||||
camera.type = Camera::CameraType::firstperson;
|
camera.type = Camera::CameraType::firstperson;
|
||||||
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 512.0f);
|
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 512.0f);
|
||||||
camera.setTranslation(glm::vec3(0.5f, 0.0f, 0.0f));
|
camera.setTranslation(glm::vec3(0.5f, 0.0f, 0.0f));
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Vulkan Example - imGui (https://github.com/ocornut/imgui)
|
* Vulkan Example - imGui (https://github.com/ocornut/imgui)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2017-2024 by Sascha Willems - www.saschawillems.de
|
* Copyright (C) 2017-2025 by Sascha Willems - www.saschawillems.de
|
||||||
*
|
*
|
||||||
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
||||||
*/
|
*/
|
||||||
|
|
@ -567,7 +567,7 @@ public:
|
||||||
|
|
||||||
VulkanExample() : VulkanExampleBase()
|
VulkanExample() : VulkanExampleBase()
|
||||||
{
|
{
|
||||||
title = "Vulkan Example - ImGui";
|
title = "User interfaces with ImGui";
|
||||||
camera.type = Camera::CameraType::lookat;
|
camera.type = Camera::CameraType::lookat;
|
||||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -4.8f));
|
camera.setPosition(glm::vec3(0.0f, 0.0f, -4.8f));
|
||||||
camera.setRotation(glm::vec3(4.5f, -380.0f, 0.0f));
|
camera.setRotation(glm::vec3(4.5f, -380.0f, 0.0f));
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
* This sample renders a basic text overlay on top of a 3D scene that can be used e.g. for debug purposes
|
* This sample renders a basic text overlay on top of a 3D scene that can be used e.g. for debug purposes
|
||||||
* For a more complete GUI sample see the ImGui sample
|
* For a more complete GUI sample see the ImGui sample
|
||||||
*
|
*
|
||||||
* Copyright (C) 2016-2024 by Sascha Willems - www.saschawillems.de
|
* Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
|
||||||
*
|
*
|
||||||
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
||||||
*/
|
*/
|
||||||
|
|
@ -462,7 +462,7 @@ public:
|
||||||
|
|
||||||
VulkanExample() : VulkanExampleBase()
|
VulkanExample() : VulkanExampleBase()
|
||||||
{
|
{
|
||||||
title = "Vulkan Example - Text overlay";
|
title = "Text overlay";
|
||||||
camera.type = Camera::CameraType::lookat;
|
camera.type = Camera::CameraType::lookat;
|
||||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -2.5f));
|
camera.setPosition(glm::vec3(0.0f, 0.0f, -2.5f));
|
||||||
camera.setRotation(glm::vec3(-25.0f, -0.0f, 0.0f));
|
camera.setRotation(glm::vec3(-25.0f, -0.0f, 0.0f));
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
* This sample shows how load and render an cubemap array texture. A single image contains multiple cube maps.
|
* This sample shows how load and render an cubemap array texture. A single image contains multiple cube maps.
|
||||||
* The cubemap to be displayed is selected in the fragment shader
|
* The cubemap to be displayed is selected in the fragment shader
|
||||||
*
|
*
|
||||||
* Copyright (C) 2020-2023 by Sascha Willems - www.saschawillems.de
|
* Copyright (C) 2020-2025 by Sascha Willems - www.saschawillems.de
|
||||||
*
|
*
|
||||||
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
||||||
*/
|
*/
|
||||||
|
|
@ -50,7 +50,7 @@ public:
|
||||||
|
|
||||||
VulkanExample() : VulkanExampleBase()
|
VulkanExample() : VulkanExampleBase()
|
||||||
{
|
{
|
||||||
title = "Cube map textures";
|
title = "Cube map texture arrays";
|
||||||
camera.type = Camera::CameraType::lookat;
|
camera.type = Camera::CameraType::lookat;
|
||||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -4.0f));
|
camera.setPosition(glm::vec3(0.0f, 0.0f, -4.0f));
|
||||||
camera.setRotationSpeed(0.25f);
|
camera.setRotationSpeed(0.25f);
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ public:
|
||||||
|
|
||||||
VulkanExample() : VulkanExampleBase()
|
VulkanExample() : VulkanExampleBase()
|
||||||
{
|
{
|
||||||
title = "Vulkan Example - Basic indexed triangle";
|
title = "Basic indexed triangle";
|
||||||
// To keep things simple, we don't use the UI overlay from the framework
|
// To keep things simple, we don't use the UI overlay from the framework
|
||||||
settings.overlay = false;
|
settings.overlay = false;
|
||||||
// Setup a default look-at camera
|
// Setup a default look-at camera
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ public:
|
||||||
|
|
||||||
VulkanExample() : VulkanExampleBase()
|
VulkanExample() : VulkanExampleBase()
|
||||||
{
|
{
|
||||||
title = "Vulkan Example - Basic indexed triangle using Vulkan 1.3";
|
title = "Basic indexed triangle using Vulkan 1.3";
|
||||||
// To keep things simple, we don't use the UI overlay from the framework
|
// To keep things simple, we don't use the UI overlay from the framework
|
||||||
settings.overlay = false;
|
settings.overlay = false;
|
||||||
// Setup a default look-at camera
|
// Setup a default look-at camera
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
/*
|
/*
|
||||||
* Vulkan Demo Scene
|
* Vulkan Demo Scene
|
||||||
*
|
*
|
||||||
* Don't take this a an example, it's more of a personal playground
|
* Don't take this a an example, it's more of a playground
|
||||||
*
|
*
|
||||||
* Copyright (C) 2016-2023 by Sascha Willems - www.saschawillems.de
|
* Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
|
||||||
*
|
*
|
||||||
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
||||||
*/
|
*/
|
||||||
|
|
@ -44,7 +44,7 @@ public:
|
||||||
|
|
||||||
VulkanExample() : VulkanExampleBase()
|
VulkanExample() : VulkanExampleBase()
|
||||||
{
|
{
|
||||||
title = "Vulkan Demo Scene (c) by Sascha Willems";
|
title = "Vulkan Demo Scene";
|
||||||
camera.type = Camera::CameraType::lookat;
|
camera.type = Camera::CameraType::lookat;
|
||||||
//camera.flipY = true;
|
//camera.flipY = true;
|
||||||
camera.setPosition(glm::vec3(0.0f, 0.0f, -3.75f));
|
camera.setPosition(glm::vec3(0.0f, 0.0f, -3.75f));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue