Skip to content

Commit 746fb33

Browse files
committed
Add option to save validation messages to a text file
1 parent 82a4cdc commit 746fb33

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

base/VulkanDebug.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Vulkan examples debug wrapper
33
*
4-
* Copyright (C) 2016-2023 by Sascha Willems - www.saschawillems.de
4+
* Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
55
*
66
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
77
*/
@@ -13,6 +13,8 @@ namespace vks
1313
{
1414
namespace debug
1515
{
16+
bool logToFile{ false };
17+
1618
PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT;
1719
PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT;
1820
VkDebugUtilsMessengerEXT debugUtilsMessenger;
@@ -73,6 +75,12 @@ namespace vks
7375
} else {
7476
std::cout << debugMessage.str() << "\n\n";
7577
}
78+
if (logToFile) {
79+
std::ofstream logfile;
80+
logfile.open("validation.txt", std::ios_base::app);
81+
logfile << debugMessage.str() << std::endl;
82+
logfile.close();
83+
}
7684
fflush(stdout);
7785
#endif
7886

base/VulkanDebug.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Vulkan examples debug wrapper
33
*
4-
* Copyright (C) 2016-2023 by Sascha Willems - www.saschawillems.de
4+
* Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
55
*
66
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
77
*/
@@ -34,6 +34,8 @@ namespace vks
3434
{
3535
namespace debug
3636
{
37+
extern bool logToFile;
38+
3739
// Default debug callback
3840
VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessageCallback(
3941
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,

base/vulkanexamplebase.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ VulkanExampleBase::VulkanExampleBase()
793793
// Command line arguments
794794
commandLineParser.add("help", { "--help" }, 0, "Show help");
795795
commandLineParser.add("validation", { "-v", "--validation" }, 0, "Enable validation layers");
796+
commandLineParser.add("validationlog", { "-vl", "--validationlog" }, 0, "Log validation messages to a textfile (validation.txt)");
796797
commandLineParser.add("vsync", { "-vs", "--vsync" }, 0, "Enable V-Sync");
797798
commandLineParser.add("fullscreen", { "-f", "--fullscreen" }, 0, "Start in fullscreen mode");
798799
commandLineParser.add("width", { "-w", "--width" }, 1, "Set window width");
@@ -821,6 +822,13 @@ VulkanExampleBase::VulkanExampleBase()
821822
if (commandLineParser.isSet("validation")) {
822823
settings.validation = true;
823824
}
825+
if (commandLineParser.isSet("validationlog")) {
826+
vks::debug::logToFile = true;
827+
std::ofstream logfile;
828+
logfile.open("validation.txt", std::ios_base::app);
829+
logfile << std::endl << "Sample: " << name << std::endl;
830+
logfile.close();
831+
}
824832
if (commandLineParser.isSet("vsync")) {
825833
settings.vsync = true;
826834
}

0 commit comments

Comments
 (0)