From 746fb337bd40feef71fb90132b132a63a3bd49a4 Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Thu, 29 May 2025 19:32:50 +0200 Subject: [PATCH] Add option to save validation messages to a text file --- base/VulkanDebug.cpp | 10 +++++++++- base/VulkanDebug.h | 4 +++- base/vulkanexamplebase.cpp | 8 ++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/base/VulkanDebug.cpp b/base/VulkanDebug.cpp index a1e1b582..03d04bd5 100644 --- a/base/VulkanDebug.cpp +++ b/base/VulkanDebug.cpp @@ -1,7 +1,7 @@ /* * Vulkan examples debug wrapper * - * 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) */ @@ -13,6 +13,8 @@ namespace vks { namespace debug { + bool logToFile{ false }; + PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT; PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT; VkDebugUtilsMessengerEXT debugUtilsMessenger; @@ -73,6 +75,12 @@ namespace vks } else { std::cout << debugMessage.str() << "\n\n"; } + if (logToFile) { + std::ofstream logfile; + logfile.open("validation.txt", std::ios_base::app); + logfile << debugMessage.str() << std::endl; + logfile.close(); + } fflush(stdout); #endif diff --git a/base/VulkanDebug.h b/base/VulkanDebug.h index 87c5eb41..59801109 100644 --- a/base/VulkanDebug.h +++ b/base/VulkanDebug.h @@ -1,7 +1,7 @@ /* * Vulkan examples debug wrapper * - * 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) */ @@ -34,6 +34,8 @@ namespace vks { namespace debug { + extern bool logToFile; + // Default debug callback VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessageCallback( VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index 5ac19bb5..3584eddb 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -793,6 +793,7 @@ VulkanExampleBase::VulkanExampleBase() // Command line arguments commandLineParser.add("help", { "--help" }, 0, "Show help"); 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("vsync", { "-vs", "--vsync" }, 0, "Enable V-Sync"); commandLineParser.add("fullscreen", { "-f", "--fullscreen" }, 0, "Start in fullscreen mode"); commandLineParser.add("width", { "-w", "--width" }, 1, "Set window width"); @@ -821,6 +822,13 @@ VulkanExampleBase::VulkanExampleBase() if (commandLineParser.isSet("validation")) { settings.validation = true; } + if (commandLineParser.isSet("validationlog")) { + 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")) { settings.vsync = true; }