Skip to content

Commit d344946

Browse files
committed
Sligthly rework validation layer logging to tet file
1 parent 2e6bf58 commit d344946

File tree

10 files changed

+47
-26
lines changed

10 files changed

+47
-26
lines changed

base/VulkanDebug.cpp

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace vks
1414
namespace debug
1515
{
1616
bool logToFile{ false };
17+
std::string logFileName{ "validation_output.txt" };
1718

1819
PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT;
1920
PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT;
@@ -31,25 +32,33 @@ namespace vks
3132
if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) {
3233
prefix = "VERBOSE: ";
3334
#if defined(_WIN32)
34-
prefix = "\033[32m" + prefix + "\033[0m";
35+
if (!logToFile) {
36+
prefix = "\033[32m" + prefix + "\033[0m";
37+
}
3538
#endif
3639
}
3740
else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) {
3841
prefix = "INFO: ";
3942
#if defined(_WIN32)
40-
prefix = "\033[36m" + prefix + "\033[0m";
43+
if (!logToFile) {
44+
prefix = "\033[36m" + prefix + "\033[0m";
45+
}
4146
#endif
4247
}
4348
else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) {
4449
prefix = "WARNING: ";
4550
#if defined(_WIN32)
46-
prefix = "\033[33m" + prefix + "\033[0m";
51+
if (!logToFile) {
52+
prefix = "\033[33m" + prefix + "\033[0m";
53+
}
4754
#endif
4855
}
4956
else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
5057
prefix = "ERROR: ";
5158
#if defined(_WIN32)
52-
prefix = "\033[31m" + prefix + "\033[0m";
59+
if (!logToFile) {
60+
prefix = "\033[31m" + prefix + "\033[0m";
61+
}
5362
#endif
5463
}
5564

@@ -76,10 +85,7 @@ namespace vks
7685
std::cout << debugMessage.str() << "\n\n";
7786
}
7887
if (logToFile) {
79-
std::ofstream logfile;
80-
logfile.open("validation.txt", std::ios_base::app);
81-
logfile << debugMessage.str() << std::endl;
82-
logfile.close();
88+
log(debugMessage.str());
8389
}
8490
fflush(stdout);
8591
#endif
@@ -99,6 +105,18 @@ namespace vks
99105
debugUtilsMessengerCI.pfnUserCallback = debugUtilsMessageCallback;
100106
}
101107

108+
void log(std::string message)
109+
{
110+
if (logToFile) {
111+
time_t timestamp;
112+
time(&timestamp);
113+
std::ofstream logfile;
114+
logfile.open(logFileName, std::ios_base::app);
115+
logfile << strtok(ctime(&timestamp), "\n") << ": " << message << std::endl;
116+
logfile.close();
117+
}
118+
}
119+
102120
void setupDebugging(VkInstance instance)
103121
{
104122
vkCreateDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT"));

base/VulkanDebug.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace vks
3535
namespace debug
3636
{
3737
extern bool logToFile;
38+
extern std::string logFileName;
3839

3940
// Default debug callback
4041
VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessageCallback(
@@ -49,6 +50,7 @@ namespace vks
4950
void freeDebugCallback(VkInstance instance);
5051
// Used to populate a VkDebugUtilsMessengerCreateInfoEXT with our example messenger function and desired flags
5152
void setupDebugingMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& debugUtilsMessengerCI);
53+
void log(std::string message);
5254
}
5355

5456
// Wrapper for the VK_EXT_debug_utils extension

base/vulkanexamplebase.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ VulkanExampleBase::VulkanExampleBase()
802802
// Command line arguments
803803
commandLineParser.add("help", { "--help" }, 0, "Show help");
804804
commandLineParser.add("validation", { "-v", "--validation" }, 0, "Enable validation layers");
805-
commandLineParser.add("validationlog", { "-vl", "--validationlog" }, 0, "Log validation messages to a textfile (validation.txt)");
805+
commandLineParser.add("validationlogfile", { "-vl", "--validationlogfile" }, 0, "Log validation messages to a textfile");
806806
commandLineParser.add("vsync", { "-vs", "--vsync" }, 0, "Enable V-Sync");
807807
commandLineParser.add("fullscreen", { "-f", "--fullscreen" }, 0, "Start in fullscreen mode");
808808
commandLineParser.add("width", { "-w", "--width" }, 1, "Set window width");
@@ -831,12 +831,8 @@ VulkanExampleBase::VulkanExampleBase()
831831
if (commandLineParser.isSet("validation")) {
832832
settings.validation = true;
833833
}
834-
if (commandLineParser.isSet("validationlog")) {
834+
if (commandLineParser.isSet("validationlogfile")) {
835835
vks::debug::logToFile = true;
836-
std::ofstream logfile;
837-
logfile.open("validation.txt", std::ios_base::app);
838-
logfile << std::endl << "Sample: " << name << std::endl;
839-
logfile.close();
840836
}
841837
if (commandLineParser.isSet("vsync")) {
842838
settings.vsync = true;
@@ -1034,6 +1030,11 @@ bool VulkanExampleBase::initVulkan()
10341030
this->settings.validation = true;
10351031
#endif
10361032

1033+
// Validation messages can be stored, e.g. to be used in external tools like CI/CD
1034+
if (commandLineParser.isSet("validationlogfile")) {
1035+
vks::debug::log("Sample: " + title);
1036+
}
1037+
10371038
// Create the instance
10381039
VkResult result = createInstance();
10391040
if (result != VK_SUCCESS) {

examples/computecullandlod/computecullandlod.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class VulkanExample : public VulkanExampleBase
8787

8888
VulkanExample() : VulkanExampleBase()
8989
{
90-
title = "Vulkan Example - Compute cull and lod";
90+
title = "Compute cull and lod";
9191
camera.type = Camera::CameraType::firstperson;
9292
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 512.0f);
9393
camera.setTranslation(glm::vec3(0.5f, 0.0f, 0.0f));

examples/imgui/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Vulkan Example - imGui (https://github.com/ocornut/imgui)
33
*
4-
* Copyright (C) 2017-2024 by Sascha Willems - www.saschawillems.de
4+
* Copyright (C) 2017-2025 by Sascha Willems - www.saschawillems.de
55
*
66
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
77
*/
@@ -567,7 +567,7 @@ class VulkanExample : public VulkanExampleBase
567567

568568
VulkanExample() : VulkanExampleBase()
569569
{
570-
title = "Vulkan Example - ImGui";
570+
title = "User interfaces with ImGui";
571571
camera.type = Camera::CameraType::lookat;
572572
camera.setPosition(glm::vec3(0.0f, 0.0f, -4.8f));
573573
camera.setRotation(glm::vec3(4.5f, -380.0f, 0.0f));

examples/textoverlay/textoverlay.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This sample renders a basic text overlay on top of a 3D scene that can be used e.g. for debug purposes
55
* For a more complete GUI sample see the ImGui sample
66
*
7-
* Copyright (C) 2016-2024 by Sascha Willems - www.saschawillems.de
7+
* Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
88
*
99
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
1010
*/
@@ -462,7 +462,7 @@ class VulkanExample : public VulkanExampleBase
462462

463463
VulkanExample() : VulkanExampleBase()
464464
{
465-
title = "Vulkan Example - Text overlay";
465+
title = "Text overlay";
466466
camera.type = Camera::CameraType::lookat;
467467
camera.setPosition(glm::vec3(0.0f, 0.0f, -2.5f));
468468
camera.setRotation(glm::vec3(-25.0f, -0.0f, 0.0f));

examples/texturecubemaparray/texturecubemaparray.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This sample shows how load and render an cubemap array texture. A single image contains multiple cube maps.
55
* The cubemap to be displayed is selected in the fragment shader
66
*
7-
* Copyright (C) 2020-2023 by Sascha Willems - www.saschawillems.de
7+
* Copyright (C) 2020-2025 by Sascha Willems - www.saschawillems.de
88
*
99
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
1010
*/
@@ -50,7 +50,7 @@ class VulkanExample : public VulkanExampleBase
5050

5151
VulkanExample() : VulkanExampleBase()
5252
{
53-
title = "Cube map textures";
53+
title = "Cube map texture arrays";
5454
camera.type = Camera::CameraType::lookat;
5555
camera.setPosition(glm::vec3(0.0f, 0.0f, -4.0f));
5656
camera.setRotationSpeed(0.25f);

examples/triangle/triangle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class VulkanExample : public VulkanExampleBase
116116

117117
VulkanExample() : VulkanExampleBase()
118118
{
119-
title = "Vulkan Example - Basic indexed triangle";
119+
title = "Basic indexed triangle";
120120
// To keep things simple, we don't use the UI overlay from the framework
121121
settings.overlay = false;
122122
// Setup a default look-at camera

examples/trianglevulkan13/trianglevulkan13.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class VulkanExample : public VulkanExampleBase
103103

104104
VulkanExample() : VulkanExampleBase()
105105
{
106-
title = "Vulkan Example - Basic indexed triangle using Vulkan 1.3";
106+
title = "Basic indexed triangle using Vulkan 1.3";
107107
// To keep things simple, we don't use the UI overlay from the framework
108108
settings.overlay = false;
109109
// Setup a default look-at camera

examples/vulkanscene/vulkanscene.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
22
* Vulkan Demo Scene
33
*
4-
* Don't take this a an example, it's more of a personal playground
4+
* Don't take this a an example, it's more of a playground
55
*
6-
* Copyright (C) 2016-2023 by Sascha Willems - www.saschawillems.de
6+
* Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
77
*
88
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
99
*/
@@ -44,7 +44,7 @@ class VulkanExample : public VulkanExampleBase
4444

4545
VulkanExample() : VulkanExampleBase()
4646
{
47-
title = "Vulkan Demo Scene (c) by Sascha Willems";
47+
title = "Vulkan Demo Scene";
4848
camera.type = Camera::CameraType::lookat;
4949
//camera.flipY = true;
5050
camera.setPosition(glm::vec3(0.0f, 0.0f, -3.75f));

0 commit comments

Comments
 (0)