Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layers: Update spec link to use new URL #9016

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 28 additions & 45 deletions layers/error_message/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,101 +564,84 @@ bool DebugReport::LogMsg(VkFlags msg_flags, const LogObjectList &objects, const

// Best guess at an upper bound for message length. At least some of the extra space
// should get used to store the VUID URL and text in the common case, without additional allocations.
std::string str_plus_spec_text(1024, '\0');
std::string full_message(1024, '\0');

// vsnprintf() returns the number of characters that *would* have been printed, if there was
// enough space. If we have a huge message, reallocate the string and try again.
int result;
size_t old_size = str_plus_spec_text.size();
size_t old_size = full_message.size();
// The va_list will be destroyed by the call to vsnprintf(), so use a copy in case we need
// to try again.
va_list arg_copy;
va_copy(arg_copy, argptr);
result = vsnprintf(str_plus_spec_text.data(), str_plus_spec_text.size(), format, arg_copy);
result = vsnprintf(full_message.data(), full_message.size(), format, arg_copy);
va_end(arg_copy);

assert(result >= 0);
if (result < 0) {
str_plus_spec_text = "Message generation failure";
full_message = "Message generation failure";
} else if (static_cast<size_t>(result) <= old_size) {
// Shrink the string to exactly fit the successfully printed string
str_plus_spec_text.resize(result);
full_message.resize(result);
} else {
// Grow buffer to fit needed size. Note that the input size to vsnprintf() must
// include space for the trailing '\0' character, but the return value DOES NOT
// include the `\0' character.
str_plus_spec_text.resize(result + 1);
full_message.resize(result + 1);
// consume the va_list passed to us by the caller
result = vsnprintf(str_plus_spec_text.data(), str_plus_spec_text.size(), format, argptr);
result = vsnprintf(full_message.data(), full_message.size(), format, argptr);
// remove the `\0' character from the string
str_plus_spec_text.resize(result);
full_message.resize(result);
}

str_plus_spec_text = loc.Message() + " " + str_plus_spec_text;
full_message = loc.Message() + " " + full_message;

// Append the spec error text to the error message, unless it contains a word treated as special
if ((vuid_text.find("VUID-") != std::string::npos)) {
// Linear search makes no assumptions about the layout of the string table. This is not fast, but it does not need to be at
// this point in the error reporting path
uint32_t num_vuids = sizeof(vuid_spec_text) / sizeof(vuid_spec_text_pair);
const char *spec_text = nullptr;
std::string spec_type;
std::string spec_url_section;
for (uint32_t i = 0; i < num_vuids; i++) {
if (0 == strncmp(vuid_text.data(), vuid_spec_text[i].vuid, vuid_text.size())) {
spec_text = vuid_spec_text[i].spec_text;
spec_type = vuid_spec_text[i].url_id;
spec_url_section = vuid_spec_text[i].url_id;
break;
}
}

// Construct and append the specification text and link to the appropriate version of the spec
if (nullptr != spec_text) {
std::string spec_link = "https://www.khronos.org/registry/vulkan/specs/_MAGIC_KHRONOS_SPEC_TYPE_/html/vkspec.html";
#ifdef ANNOTATED_SPEC_LINK
spec_link = ANNOTATED_SPEC_LINK;
std::string spec_url_base = ANNOTATED_SPEC_LINK;
#else
std::string spec_url_base = "https://docs.vulkan.org/spec/latest/";
#endif
static std::string kAtToken = "_MAGIC_ANNOTATED_SPEC_TYPE_";
static std::string kKtToken = "_MAGIC_KHRONOS_SPEC_TYPE_";
static std::string kVeToken = "_MAGIC_VERSION_ID_";
auto Replace = [](std::string &dest_string, const std::string &to_replace, const std::string &replace_with) {
if (dest_string.find(to_replace) != std::string::npos) {
dest_string.replace(dest_string.find(to_replace), to_replace.size(), replace_with);
}
};

// Add period at end if forgotten
// This provides better seperation between error message and spec text
if (str_plus_spec_text.back() != '.' && str_plus_spec_text.back() != '\n') {
str_plus_spec_text.append(".");
if (full_message.back() != '.' && full_message.back() != '\n') {
full_message.append(".");
}

// Start Vulkan spec text with a new line to make it easier visually
if (str_plus_spec_text.back() != '\n') {
str_plus_spec_text.append("\n");
}
str_plus_spec_text.append("The Vulkan spec states: ");
str_plus_spec_text.append(spec_text);
if (0 == spec_type.compare("default")) {
str_plus_spec_text.append(" (https://github.com/KhronosGroup/Vulkan-Docs/search?q=)");
} else {
str_plus_spec_text.append(" (");
str_plus_spec_text.append(spec_link);
std::string major_version = std::to_string(VK_VERSION_MAJOR(VK_HEADER_VERSION_COMPLETE));
std::string minor_version = std::to_string(VK_VERSION_MINOR(VK_HEADER_VERSION_COMPLETE));
std::string patch_version = std::to_string(VK_VERSION_PATCH(VK_HEADER_VERSION_COMPLETE));
std::string header_version = major_version + "." + minor_version + "." + patch_version;
std::string annotated_spec_type = major_version + "." + minor_version + "-extensions";
Replace(str_plus_spec_text, kKtToken, spec_type);
Replace(str_plus_spec_text, kAtToken, annotated_spec_type);
Replace(str_plus_spec_text, kVeToken, header_version);
str_plus_spec_text.append("#"); // CMake hates hashes
if (full_message.back() != '\n') {
full_message.append("\n");
}
str_plus_spec_text.append(vuid_text);
str_plus_spec_text.append(")");

full_message.append("The Vulkan spec states: ");
full_message.append(spec_text);
full_message.append(" (");
full_message.append(spec_url_base);
full_message.append(spec_url_section);
full_message.append("#"); // CMake hates hashes
full_message.append(vuid_text);
full_message.append(")");
}
}

return DebugLogMsg(msg_flags, objects, str_plus_spec_text.c_str(), vuid_text.data());
return DebugLogMsg(msg_flags, objects, full_message.c_str(), vuid_text.data());
}

VKAPI_ATTR VkBool32 VKAPI_CALL MessengerBreakCallback([[maybe_unused]] VkDebugUtilsMessageSeverityFlagBitsEXT message_severity,
Expand Down
Loading
Loading