| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
| Mark Lobodzinski | 2af57ec | 2019-03-20 09:17:56 -0600 | [diff] [blame] | 3 | * Copyright 2014-2019 Valve Software |
| 4 | * Copyright 2015-2019 Google Inc. |
| 5 | * Copyright 2019 LunarG, Inc. |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 6 | * All Rights Reserved. |
| 7 | * |
| Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | * you may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 11 | * |
| Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 13 | * |
| Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 19 | * |
| Jon Ashburn | e922f71 | 2015-11-03 13:41:23 -0700 | [diff] [blame] | 20 | * Author: Jon Ashburn <jon@lunarg.com> |
| 21 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 22 | * Author: Tobin Ehlis <tobin@lunarg.com> |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 23 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 24 | **************************************************************************/ |
| Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 25 | #include "vk_layer_config.h" |
| David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 26 | #include "vulkan/vk_sdk_platform.h" |
| Lenny Komow | 807ebf0 | 2016-09-30 14:15:25 -0600 | [diff] [blame] | 27 | #include <fstream> |
| 28 | #include <iostream> |
| 29 | #include <map> |
| Lenny Komow | 5c57fcb | 2018-10-02 09:18:51 -0600 | [diff] [blame] | 30 | #include <sstream> |
| Lenny Komow | 807ebf0 | 2016-09-30 14:15:25 -0600 | [diff] [blame] | 31 | #include <string.h> |
| 32 | #include <string> |
| 33 | #include <sys/stat.h> |
| 34 | #include <vulkan/vk_layer.h> |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 35 | |
| Mark Lobodzinski | d5aa8de | 2018-02-02 13:58:41 -0700 | [diff] [blame] | 36 | #if defined(_WIN32) |
| Martin Herkt | 094130b | 2018-03-06 22:44:13 +0100 | [diff] [blame] | 37 | #include <windows.h> |
| Mark Lobodzinski | d5aa8de | 2018-02-02 13:58:41 -0700 | [diff] [blame] | 38 | #endif |
| 39 | |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 40 | #define MAX_CHARS_PER_LINE 4096 |
| 41 | |
| Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 42 | class ConfigFile { |
| Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 43 | public: |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 44 | ConfigFile(); |
| 45 | ~ConfigFile(); |
| 46 | |
| 47 | const char *getOption(const std::string &_option); |
| Jon Ashburn | dec6051 | 2015-01-13 17:24:01 -0700 | [diff] [blame] | 48 | void setOption(const std::string &_option, const std::string &_val); |
| Mark Lobodzinski | 2af57ec | 2019-03-20 09:17:56 -0600 | [diff] [blame] | 49 | std::string vk_layer_disables_env_var{}; |
| Jon Ashburn | dec6051 | 2015-01-13 17:24:01 -0700 | [diff] [blame] | 50 | |
| Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 51 | private: |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 52 | bool m_fileIsParsed; |
| 53 | std::map<std::string, std::string> m_valueMap; |
| 54 | |
| Lenny Komow | 5c57fcb | 2018-10-02 09:18:51 -0600 | [diff] [blame] | 55 | std::string FindSettings(); |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 56 | void parseFile(const char *filename); |
| 57 | }; |
| 58 | |
| 59 | static ConfigFile g_configFileObj; |
| Jon Ashburn | dec6051 | 2015-01-13 17:24:01 -0700 | [diff] [blame] | 60 | |
| Lenny Komow | 807ebf0 | 2016-09-30 14:15:25 -0600 | [diff] [blame] | 61 | std::string getEnvironment(const char *variable) { |
| 62 | #if !defined(__ANDROID__) && !defined(_WIN32) |
| 63 | const char *output = getenv(variable); |
| 64 | return output == NULL ? "" : output; |
| 65 | #elif defined(_WIN32) |
| 66 | int size = GetEnvironmentVariable(variable, NULL, 0); |
| 67 | if (size == 0) { |
| 68 | return ""; |
| 69 | } |
| 70 | char *buffer = new char[size]; |
| 71 | GetEnvironmentVariable(variable, buffer, size); |
| 72 | std::string output = buffer; |
| 73 | delete[] buffer; |
| 74 | return output; |
| 75 | #else |
| 76 | return ""; |
| 77 | #endif |
| 78 | } |
| 79 | |
| Mark Lobodzinski | 07954a5 | 2018-02-01 12:14:30 -0700 | [diff] [blame] | 80 | VK_LAYER_EXPORT const char *getLayerOption(const char *_option) { return g_configFileObj.getOption(_option); } |
| Mark Lobodzinski | 2af57ec | 2019-03-20 09:17:56 -0600 | [diff] [blame] | 81 | VK_LAYER_EXPORT const char *GetLayerEnvVar(const char *_option) { |
| 82 | g_configFileObj.vk_layer_disables_env_var = getEnvironment(_option); |
| 83 | return g_configFileObj.vk_layer_disables_env_var.c_str(); |
| 84 | } |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 85 | |
| Tobin Ehlis | b1df55e | 2015-09-15 09:55:54 -0600 | [diff] [blame] | 86 | // If option is NULL or stdout, return stdout, otherwise try to open option |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 87 | // as a filename. If successful, return file handle, otherwise stdout |
| Mark Lobodzinski | 07954a5 | 2018-02-01 12:14:30 -0700 | [diff] [blame] | 88 | VK_LAYER_EXPORT FILE *getLayerLogOutput(const char *_option, const char *layerName) { |
| Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 89 | FILE *log_output = NULL; |
| Tobin Ehlis | b1df55e | 2015-09-15 09:55:54 -0600 | [diff] [blame] | 90 | if (!_option || !strcmp("stdout", _option)) |
| 91 | log_output = stdout; |
| 92 | else { |
| 93 | log_output = fopen(_option, "w"); |
| 94 | if (log_output == NULL) { |
| 95 | if (_option) |
| Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 96 | std::cout << std::endl |
| 97 | << layerName << " ERROR: Bad output filename specified: " << _option << ". Writing to STDOUT instead" |
| 98 | << std::endl |
| 99 | << std::endl; |
| Tobin Ehlis | b1df55e | 2015-09-15 09:55:54 -0600 | [diff] [blame] | 100 | log_output = stdout; |
| 101 | } |
| 102 | } |
| Cody Northrop | e3e39ef | 2015-09-16 08:35:29 -0600 | [diff] [blame] | 103 | return log_output; |
| Tobin Ehlis | b1df55e | 2015-09-15 09:55:54 -0600 | [diff] [blame] | 104 | } |
| 105 | |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 106 | // Map option strings to flag enum values |
| Mark Lobodzinski | 07954a5 | 2018-02-01 12:14:30 -0700 | [diff] [blame] | 107 | VK_LAYER_EXPORT VkFlags GetLayerOptionFlags(std::string _option, std::unordered_map<std::string, VkFlags> const &enum_data, |
| 108 | uint32_t option_default) { |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 109 | VkDebugReportFlagsEXT flags = option_default; |
| 110 | std::string option_list = g_configFileObj.getOption(_option.c_str()); |
| Courtney Goeltzenleuchter | b874b8c | 2015-06-14 11:34:49 -0600 | [diff] [blame] | 111 | |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 112 | while (option_list.length() != 0) { |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 113 | // Find length of option string |
| 114 | std::size_t option_length = option_list.find(","); |
| 115 | if (option_length == option_list.npos) { |
| 116 | option_length = option_list.size(); |
| Courtney Goeltzenleuchter | b874b8c | 2015-06-14 11:34:49 -0600 | [diff] [blame] | 117 | } |
| 118 | |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 119 | // Get first option in list |
| 120 | const std::string option = option_list.substr(0, option_length); |
| Courtney Goeltzenleuchter | b874b8c | 2015-06-14 11:34:49 -0600 | [diff] [blame] | 121 | |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 122 | auto enum_value = enum_data.find(option); |
| 123 | if (enum_value != enum_data.end()) { |
| 124 | flags |= enum_value->second; |
| 125 | } |
| 126 | |
| 127 | // Remove first option from option_list |
| 128 | option_list.erase(0, option_length); |
| 129 | // Remove possible comma separator |
| 130 | std::size_t char_position = option_list.find(","); |
| 131 | if (char_position == 0) { |
| 132 | option_list.erase(char_position, 1); |
| 133 | } |
| 134 | // Remove possible space |
| 135 | char_position = option_list.find(" "); |
| 136 | if (char_position == 0) { |
| 137 | option_list.erase(char_position, 1); |
| 138 | } |
| Courtney Goeltzenleuchter | b874b8c | 2015-06-14 11:34:49 -0600 | [diff] [blame] | 139 | } |
| 140 | return flags; |
| 141 | } |
| 142 | |
| Mark Lobodzinski | 07954a5 | 2018-02-01 12:14:30 -0700 | [diff] [blame] | 143 | VK_LAYER_EXPORT void setLayerOption(const char *_option, const char *_val) { g_configFileObj.setOption(_option, _val); } |
| Jon Ashburn | dec6051 | 2015-01-13 17:24:01 -0700 | [diff] [blame] | 144 | |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 145 | // Constructor for ConfigFile. Initialize layers to log error messages to stdout by default. If a vk_layer_settings file is present, |
| 146 | // its settings will override the defaults. |
| 147 | ConfigFile::ConfigFile() : m_fileIsParsed(false) { |
| Mark Lobodzinski | 13500d3 | 2019-03-20 10:06:09 -0600 | [diff] [blame] | 148 | m_valueMap["khronos_validation.report_flags"] = "error"; |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 149 | m_valueMap["lunarg_core_validation.report_flags"] = "error"; |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 150 | m_valueMap["lunarg_object_tracker.report_flags"] = "error"; |
| 151 | m_valueMap["lunarg_parameter_validation.report_flags"] = "error"; |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 152 | m_valueMap["google_threading.report_flags"] = "error"; |
| Mark Lobodzinski | ad8448e | 2016-08-26 08:35:19 -0600 | [diff] [blame] | 153 | m_valueMap["google_unique_objects.report_flags"] = "error"; |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 154 | |
| 155 | #ifdef WIN32 |
| 156 | // For Windows, enable message logging AND OutputDebugString |
| Mark Lobodzinski | 13500d3 | 2019-03-20 10:06:09 -0600 | [diff] [blame] | 157 | m_valueMap["khronos_validation.debug_action"] = |
| 158 | "VK_DBG_LAYER_ACTION_DEFAULT,VK_DBG_LAYER_ACTION_LOG_MSG,VK_DBG_LAYER_ACTION_DEBUG_OUTPUT"; |
| Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 159 | m_valueMap["lunarg_core_validation.debug_action"] = |
| 160 | "VK_DBG_LAYER_ACTION_DEFAULT,VK_DBG_LAYER_ACTION_LOG_MSG,VK_DBG_LAYER_ACTION_DEBUG_OUTPUT"; |
| Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 161 | m_valueMap["lunarg_object_tracker.debug_action"] = |
| 162 | "VK_DBG_LAYER_ACTION_DEFAULT,VK_DBG_LAYER_ACTION_LOG_MSG,VK_DBG_LAYER_ACTION_DEBUG_OUTPUT"; |
| 163 | m_valueMap["lunarg_parameter_validation.debug_action"] = |
| 164 | "VK_DBG_LAYER_ACTION_DEFAULT,VK_DBG_LAYER_ACTION_LOG_MSG,VK_DBG_LAYER_ACTION_DEBUG_OUTPUT"; |
| Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 165 | m_valueMap["google_threading.debug_action"] = |
| 166 | "VK_DBG_LAYER_ACTION_DEFAULT,VK_DBG_LAYER_ACTION_LOG_MSG,VK_DBG_LAYER_ACTION_DEBUG_OUTPUT"; |
| 167 | m_valueMap["google_unique_objects.debug_action"] = |
| 168 | "VK_DBG_LAYER_ACTION_DEFAULT,VK_DBG_LAYER_ACTION_LOG_MSG,VK_DBG_LAYER_ACTION_DEBUG_OUTPUT"; |
| Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 169 | #else // WIN32 |
| Mark Lobodzinski | 13500d3 | 2019-03-20 10:06:09 -0600 | [diff] [blame] | 170 | m_valueMap["khronos_validation.debug_action"] = "VK_DBG_LAYER_ACTION_DEFAULT,VK_DBG_LAYER_ACTION_LOG_MSG"; |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 171 | m_valueMap["lunarg_core_validation.debug_action"] = "VK_DBG_LAYER_ACTION_DEFAULT,VK_DBG_LAYER_ACTION_LOG_MSG"; |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 172 | m_valueMap["lunarg_object_tracker.debug_action"] = "VK_DBG_LAYER_ACTION_DEFAULT,VK_DBG_LAYER_ACTION_LOG_MSG"; |
| 173 | m_valueMap["lunarg_parameter_validation.debug_action"] = "VK_DBG_LAYER_ACTION_DEFAULT,VK_DBG_LAYER_ACTION_LOG_MSG"; |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 174 | m_valueMap["google_threading.debug_action"] = "VK_DBG_LAYER_ACTION_DEFAULT,VK_DBG_LAYER_ACTION_LOG_MSG"; |
| Mark Lobodzinski | ad8448e | 2016-08-26 08:35:19 -0600 | [diff] [blame] | 175 | m_valueMap["google_unique_objects.debug_action"] = "VK_DBG_LAYER_ACTION_DEFAULT,VK_DBG_LAYER_ACTION_LOG_MSG"; |
| Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 176 | #endif // WIN32 |
| Mark Lobodzinski | 13500d3 | 2019-03-20 10:06:09 -0600 | [diff] [blame] | 177 | m_valueMap["khronos_validation.log_filename"] = "stdout"; |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 178 | m_valueMap["lunarg_core_validation.log_filename"] = "stdout"; |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 179 | m_valueMap["lunarg_object_tracker.log_filename"] = "stdout"; |
| 180 | m_valueMap["lunarg_parameter_validation.log_filename"] = "stdout"; |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 181 | m_valueMap["google_threading.log_filename"] = "stdout"; |
| Mark Lobodzinski | ad8448e | 2016-08-26 08:35:19 -0600 | [diff] [blame] | 182 | m_valueMap["google_unique_objects.log_filename"] = "stdout"; |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 183 | } |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 184 | |
| Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 185 | ConfigFile::~ConfigFile() {} |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 186 | |
| Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 187 | const char *ConfigFile::getOption(const std::string &_option) { |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 188 | std::map<std::string, std::string>::const_iterator it; |
| Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 189 | if (!m_fileIsParsed) { |
| Lenny Komow | 5c57fcb | 2018-10-02 09:18:51 -0600 | [diff] [blame] | 190 | std::string settings_file = FindSettings(); |
| 191 | parseFile(settings_file.c_str()); |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | if ((it = m_valueMap.find(_option)) == m_valueMap.end()) |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 195 | return ""; |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 196 | else |
| 197 | return it->second.c_str(); |
| 198 | } |
| 199 | |
| Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 200 | void ConfigFile::setOption(const std::string &_option, const std::string &_val) { |
| 201 | if (!m_fileIsParsed) { |
| Lenny Komow | 5c57fcb | 2018-10-02 09:18:51 -0600 | [diff] [blame] | 202 | std::string settings_file = FindSettings(); |
| 203 | parseFile(settings_file.c_str()); |
| Jon Ashburn | dec6051 | 2015-01-13 17:24:01 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | m_valueMap[_option] = _val; |
| 207 | } |
| 208 | |
| Lenny Komow | 5c57fcb | 2018-10-02 09:18:51 -0600 | [diff] [blame] | 209 | std::string ConfigFile::FindSettings() { |
| 210 | struct stat info; |
| 211 | |
| 212 | #if defined(WIN32) |
| 213 | HKEY hive; |
| 214 | LSTATUS err = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Khronos\\Vulkan\\Settings", 0, KEY_READ, &hive); |
| Lenny Komow | c7676c7 | 2018-11-20 18:35:22 -0700 | [diff] [blame] | 215 | if (err == ERROR_SUCCESS) { |
| Lenny Komow | 5c57fcb | 2018-10-02 09:18:51 -0600 | [diff] [blame] | 216 | char name[2048]; |
| 217 | DWORD i = 0, name_size = sizeof(name), type, value, value_size = sizeof(value); |
| 218 | while (ERROR_SUCCESS == |
| 219 | RegEnumValue(hive, i++, name, &name_size, nullptr, &type, reinterpret_cast<LPBYTE>(&value), &value_size)) { |
| 220 | // Check if the registry entry is a dword with a value of zero |
| 221 | if (type != REG_DWORD || value != 0) { |
| 222 | continue; |
| 223 | } |
| 224 | |
| 225 | // Check if this actually points to a file |
| Lenny Komow | c7676c7 | 2018-11-20 18:35:22 -0700 | [diff] [blame] | 226 | if ((stat(name, &info) != 0) || !(info.st_mode & S_IFREG)) { |
| Lenny Komow | 5c57fcb | 2018-10-02 09:18:51 -0600 | [diff] [blame] | 227 | continue; |
| 228 | } |
| 229 | |
| 230 | // Use this file |
| 231 | RegCloseKey(hive); |
| 232 | return name; |
| 233 | } |
| 234 | |
| 235 | RegCloseKey(hive); |
| 236 | } |
| 237 | #else |
| 238 | std::string search_path = getEnvironment("XDG_DATA_HOME"); |
| 239 | if (search_path == "") { |
| 240 | search_path = getEnvironment("HOME"); |
| 241 | if (search_path != "") { |
| 242 | search_path += "/.local/share"; |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | // Use the vk_layer_settings.txt file from here, if it is present |
| 247 | if (search_path != "") { |
| 248 | std::string home_file = search_path + "/vulkan/settings.d/vk_layer_settings.txt"; |
| 249 | if (stat(home_file.c_str(), &info) == 0) { |
| 250 | if (info.st_mode & S_IFREG) { |
| 251 | return home_file; |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | #endif |
| 257 | |
| 258 | std::string env_path = getEnvironment("VK_LAYER_SETTINGS_PATH"); |
| 259 | |
| 260 | // If the path exists use it, else use vk_layer_settings |
| 261 | if (stat(env_path.c_str(), &info) == 0) { |
| 262 | // If this is a directory, look for vk_layer_settings within the directory |
| 263 | if (info.st_mode & S_IFDIR) { |
| 264 | return env_path + "/vk_layer_settings.txt"; |
| 265 | } |
| 266 | return env_path; |
| 267 | } |
| 268 | return "vk_layer_settings.txt"; |
| 269 | } |
| 270 | |
| Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 271 | void ConfigFile::parseFile(const char *filename) { |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 272 | std::ifstream file; |
| 273 | char buf[MAX_CHARS_PER_LINE]; |
| 274 | |
| 275 | m_fileIsParsed = true; |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 276 | |
| 277 | file.open(filename); |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 278 | if (!file.good()) { |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 279 | return; |
| Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 280 | } |
| 281 | |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 282 | // read tokens from the file and form option, value pairs |
| 283 | file.getline(buf, MAX_CHARS_PER_LINE); |
| Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 284 | while (!file.eof()) { |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 285 | char option[512]; |
| 286 | char value[512]; |
| 287 | |
| 288 | char *pComment; |
| 289 | |
| Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 290 | // discard any comments delimited by '#' in the line |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 291 | pComment = strchr(buf, '#'); |
| Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 292 | if (pComment) *pComment = '\0'; |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 293 | |
| Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 294 | if (sscanf(buf, " %511[^\n\t =] = %511[^\n \t]", option, value) == 2) { |
| Jon Ashburn | be58264 | 2014-12-22 12:04:40 -0700 | [diff] [blame] | 295 | std::string optStr(option); |
| 296 | std::string valStr(value); |
| 297 | m_valueMap[optStr] = valStr; |
| 298 | } |
| 299 | file.getline(buf, MAX_CHARS_PER_LINE); |
| 300 | } |
| 301 | } |
| 302 | |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 303 | VK_LAYER_EXPORT void PrintMessageFlags(VkFlags vk_flags, char *msg_flags) { |
| Courtney Goeltzenleuchter | f85e361 | 2015-06-14 11:33:06 -0600 | [diff] [blame] | 304 | bool separator = false; |
| 305 | |
| 306 | msg_flags[0] = 0; |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 307 | if (vk_flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) { |
| Courtney Goeltzenleuchter | f85e361 | 2015-06-14 11:33:06 -0600 | [diff] [blame] | 308 | strcat(msg_flags, "DEBUG"); |
| 309 | separator = true; |
| 310 | } |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 311 | if (vk_flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) { |
| Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 312 | if (separator) strcat(msg_flags, ","); |
| Courtney Goeltzenleuchter | f85e361 | 2015-06-14 11:33:06 -0600 | [diff] [blame] | 313 | strcat(msg_flags, "INFO"); |
| 314 | separator = true; |
| 315 | } |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 316 | if (vk_flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) { |
| Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 317 | if (separator) strcat(msg_flags, ","); |
| Courtney Goeltzenleuchter | f85e361 | 2015-06-14 11:33:06 -0600 | [diff] [blame] | 318 | strcat(msg_flags, "WARN"); |
| 319 | separator = true; |
| 320 | } |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 321 | if (vk_flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) { |
| Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 322 | if (separator) strcat(msg_flags, ","); |
| Courtney Goeltzenleuchter | f85e361 | 2015-06-14 11:33:06 -0600 | [diff] [blame] | 323 | strcat(msg_flags, "PERF"); |
| 324 | separator = true; |
| 325 | } |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 326 | if (vk_flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) { |
| Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 327 | if (separator) strcat(msg_flags, ","); |
| Courtney Goeltzenleuchter | f85e361 | 2015-06-14 11:33:06 -0600 | [diff] [blame] | 328 | strcat(msg_flags, "ERROR"); |
| 329 | } |
| 330 | } |
| Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 331 | |
| 332 | VK_LAYER_EXPORT void PrintMessageSeverity(VkFlags vk_flags, char *msg_flags) { |
| 333 | bool separator = false; |
| 334 | |
| 335 | msg_flags[0] = 0; |
| 336 | if (vk_flags & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) { |
| 337 | strcat(msg_flags, "VERBOSE"); |
| 338 | separator = true; |
| 339 | } |
| 340 | if (vk_flags & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) { |
| 341 | if (separator) strcat(msg_flags, ","); |
| 342 | strcat(msg_flags, "INFO"); |
| 343 | separator = true; |
| 344 | } |
| 345 | if (vk_flags & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) { |
| 346 | if (separator) strcat(msg_flags, ","); |
| 347 | strcat(msg_flags, "WARN"); |
| 348 | separator = true; |
| 349 | } |
| 350 | if (vk_flags & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) { |
| 351 | if (separator) strcat(msg_flags, ","); |
| 352 | strcat(msg_flags, "ERROR"); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | VK_LAYER_EXPORT void PrintMessageType(VkFlags vk_flags, char *msg_flags) { |
| 357 | bool separator = false; |
| 358 | |
| 359 | msg_flags[0] = 0; |
| 360 | if (vk_flags & VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT) { |
| 361 | strcat(msg_flags, "GEN"); |
| 362 | separator = true; |
| 363 | } |
| 364 | if (vk_flags & VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT) { |
| 365 | strcat(msg_flags, "SPEC"); |
| 366 | separator = true; |
| 367 | } |
| 368 | if (vk_flags & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT) { |
| 369 | if (separator) strcat(msg_flags, ","); |
| 370 | strcat(msg_flags, "PERF"); |
| 371 | separator = true; |
| 372 | } |
| 373 | } |