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 f5fa1c36..b4ad3a69 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -802,6 +802,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"); @@ -830,6 +831,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; }