Skip to content

Commit

Permalink
layers: Add option to help compare error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-lunarg committed Jan 17, 2025
1 parent 711f416 commit a80bafc
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
8 changes: 8 additions & 0 deletions layers/VkLayer_khronos_validation.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,14 @@
"type": "BOOL",
"default": false,
"platforms": [ "WINDOWS", "LINUX", "MACOS", "ANDROID" ]
},
{
"key": "debug_stable_messages",
"label": "Stable messages",
"view": "ADVANCED",
"description": "Improves the reproducibility of error messages by removing fields that can vary between application runs (e.g., dispatchable handles) for comparison purposes.",
"type": "BOOL",
"default": false
}
]
},
Expand Down
31 changes: 24 additions & 7 deletions layers/error_message/logging.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Copyright (c) 2015-2024 The Khronos Group Inc.
* Copyright (c) 2015-2024 Valve Corporation
* Copyright (c) 2015-2024 LunarG, Inc.
/* Copyright (c) 2015-2025 The Khronos Group Inc.
* Copyright (c) 2015-2025 Valve Corporation
* Copyright (c) 2015-2025 LunarG, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -214,11 +214,14 @@ bool DebugReport::DebugLogMsg(VkFlags msg_flags, const LogObjectList &objects, c
uint32_t index = 0;
for (const auto &src_object : object_name_infos) {
if (0 != src_object.objectHandle) {
oss << "Object " << index++ << ": handle = 0x" << std::hex << src_object.objectHandle;
oss << "Object " << index++ << ": ";
if (!debug_stable_messages) {
oss << "handle = 0x" << std::hex << src_object.objectHandle << ", ";
}
if (src_object.pObjectName) {
oss << ", name = " << src_object.pObjectName << ", type = ";
oss << "name = " << src_object.pObjectName << ", type = ";
} else {
oss << ", type = ";
oss << "type = ";
}
oss << string_VkObjectType(src_object.objectType) << "; ";
} else {
Expand Down Expand Up @@ -321,8 +324,22 @@ std::string DebugReport::FormatHandle(const char *handle_type_name, uint64_t han
handle_name = GetMarkerObjectNameNoLock(handle);
}

bool print_handle = true;
if (debug_stable_messages) {
if (!strcmp(handle_type_name, "VkInstance") || !strcmp(handle_type_name, "VkPhysicalDevice") ||
!strcmp(handle_type_name, "VkDevice") || !strcmp(handle_type_name, "VkQueue") ||
!strcmp(handle_type_name, "VkCommandBuffer")) {
// In stable message mode do not print dispatchable handles because they vary
print_handle = false;
}
}

std::ostringstream str;
str << handle_type_name << " 0x" << std::hex << handle << "[" << handle_name.c_str() << "]";
str << handle_type_name << " ";
if (print_handle) {
str << "0x" << std::hex << handle;
}
str << "[" << handle_name.c_str() << "]";
return str.str();
}

Expand Down
7 changes: 4 additions & 3 deletions layers/error_message/logging.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Copyright (c) 2015-2024 The Khronos Group Inc.
* Copyright (c) 2015-2024 Valve Corporation
* Copyright (c) 2015-2024 LunarG, Inc.
/* Copyright (c) 2015-2025 The Khronos Group Inc.
* Copyright (c) 2015-2025 Valve Corporation
* Copyright (c) 2015-2025 LunarG, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -199,6 +199,7 @@ class DebugReport {
bool force_default_log_callback{false};
uint32_t device_created = 0;
MessageFormatSettings message_format_settings;
bool debug_stable_messages{false};

void SetUtilsObjectName(const VkDebugUtilsObjectNameInfoEXT *pNameInfo);
void SetMarkerObjectName(const VkDebugMarkerObjectNameInfoEXT *pNameInfo);
Expand Down
12 changes: 9 additions & 3 deletions layers/layer_options.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Copyright (c) 2020-2024 The Khronos Group Inc.
* Copyright (c) 2020-2024 Valve Corporation
* Copyright (c) 2020-2024 LunarG, Inc.
/* Copyright (c) 2020-2025 The Khronos Group Inc.
* Copyright (c) 2020-2025 Valve Corporation
* Copyright (c) 2020-2025 LunarG, Inc.
* Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -173,6 +173,7 @@ const char *VK_LAYER_DUPLICATE_MESSAGE_LIMIT = "duplicate_message_limit";
const char *VK_LAYER_FINE_GRAINED_LOCKING = "fine_grained_locking";
// Debug settings used for internal development
const char *VK_LAYER_DEBUG_DISABLE_SPIRV_VAL = "debug_disable_spirv_val";
const char *VK_LAYER_DEBUG_STABLE_MESSAGES = "debug_stable_messages";

// DebugPrintf (which is now part of GPU-AV internally)
// ---
Expand Down Expand Up @@ -773,6 +774,11 @@ static void ProcessDebugReportSettings(ConfigAndEnvSettings *settings_data, VkuL
}
const bool is_stdout = log_filename.compare("stdout") == 0;

// Debug mode to simplify comparison of error messages between application runs
if (vkuHasLayerSetting(layer_setting_set, VK_LAYER_DEBUG_STABLE_MESSAGES)) {
vkuGetLayerSettingValue(layer_setting_set, VK_LAYER_DEBUG_STABLE_MESSAGES, debug_report->debug_stable_messages);
}

// Default
std::vector<std::string> debug_actions_list = {"VK_DBG_LAYER_ACTION_DEFAULT", "VK_DBG_LAYER_ACTION_LOG_MSG"};
#ifdef WIN32
Expand Down

0 comments on commit a80bafc

Please sign in to comment.