From 5a92513f570ecd8af387ee10823518b82083ec24 Mon Sep 17 00:00:00 2001 From: Jeremy Gebben Date: Tue, 7 Jan 2025 16:18:43 -0700 Subject: [PATCH] cdl: Better handling for missing settings Distinguish between unset settings and those set to an empty string. This mostly affects message_severity, so that an empty string can turn all messages off. However there's a few messages that have to come out before the layer settings are read and those can't really be turned off. --- src/cdl.cpp | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/cdl.cpp b/src/cdl.cpp index c41e255..d2b1239 100644 --- a/src/cdl.cpp +++ b/src/cdl.cpp @@ -1,6 +1,6 @@ /* Copyright 2018 Google Inc. - Copyright (c) 2023-2024 LunarG, Inc. + Copyright (c) 2023-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. @@ -93,17 +93,21 @@ const char* kSyncAfterCommands = "sync_after_commands"; const char* kLogTimeTag = "%Y-%m-%d-%H%M%S"; template -void GetEnvVal(VkuLayerSettingSet settings, const char* name, T& value) { +bool GetEnvVal(VkuLayerSettingSet settings, const char* name, T& value) { if (vkuHasLayerSetting(settings, name)) { vkuGetLayerSettingValue(settings, name, value); + return true; } + return false; } template -void GetEnumVal(Logger& log, VkuLayerSettingSet settings, const char* name, T& value, +bool GetEnumVal(Logger& log, VkuLayerSettingSet settings, const char* name, T& value, const std::unordered_map& value_map) { std::string value_string; - GetEnvVal(settings, name, value_string); + if (!GetEnvVal(settings, name, value_string)) { + return false; + } if (!value_string.empty()) { auto iter = value_map.find(value_string); if (iter != value_map.end()) { @@ -112,6 +116,7 @@ void GetEnumVal(Logger& log, VkuLayerSettingSet settings, const char* name, T& v log.Error("Bad value for %s setting: \"%s\"", name, value_string.c_str()); } } + return true; } Settings::Settings(VkuLayerSettingSet layer_settings, Logger& log) { @@ -219,21 +224,22 @@ Context::Context(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCall // logging { std::string severity; - GetEnvVal(layer_setting_set, settings::kMessageSeverity, severity); - if (!severity.empty()) { + if (GetEnvVal(layer_setting_set, settings::kMessageSeverity, severity)) { VkDebugUtilsMessageSeverityFlagsEXT mask{0}; - std::regex re("[\\s,]+"); - std::sregex_token_iterator re_iter(severity.begin(), severity.end(), re, -1); - std::sregex_token_iterator re_end; bool bad_value = false; - for (; re_iter != re_end; ++re_iter) { - auto iter = settings::kSeverityValues.find(*re_iter); - if (iter != settings::kSeverityValues.end()) { - mask |= iter->second; - } else { - bad_value = true; - std::string value = *re_iter; - Log().Error("Bad value for message_severity setting: \"%s\"", value.c_str()); + if (!severity.empty()) { + std::regex re("[\\s,]+"); + std::sregex_token_iterator re_iter(severity.begin(), severity.end(), re, -1); + std::sregex_token_iterator re_end; + for (; re_iter != re_end; ++re_iter) { + auto iter = settings::kSeverityValues.find(*re_iter); + if (iter != settings::kSeverityValues.end()) { + mask |= iter->second; + } else { + bad_value = true; + std::string value = *re_iter; + Log().Error("Bad value for message_severity setting: \"%s\"", value.c_str()); + } } } if (!bad_value) { @@ -242,8 +248,7 @@ Context::Context(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCall } std::string log_file; - GetEnvVal(layer_setting_set, settings::kLogFile, log_file); - if (!log_file.empty()) { + if (GetEnvVal(layer_setting_set, settings::kLogFile, log_file)) { auto iter = settings::kLogFileValues.find(log_file); if (iter != settings::kLogFileValues.end()) { switch (iter->second) {