From 94decf7327ef2530cb7b623a2d261df21be4fa55 Mon Sep 17 00:00:00 2001 From: Lenny Komow Date: Fri, 30 Sep 2016 14:15:25 -0600 Subject: layers: Add environment var for settings file Change-Id: I8a614f915ab9b61eca5b3b94f4cf43a33cacf250 --- layers/vk_layer_config.cpp | 56 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 6 deletions(-) (limited to 'layers/vk_layer_config.cpp') diff --git a/layers/vk_layer_config.cpp b/layers/vk_layer_config.cpp index ec50744d..d8fe87d2 100644 --- a/layers/vk_layer_config.cpp +++ b/layers/vk_layer_config.cpp @@ -21,14 +21,15 @@ * Author: Tobin Ehlis * Author: Mark Lobodzinski **************************************************************************/ +#include "vk_layer_config.h" +#include "vulkan/vk_sdk_platform.h" #include -#include +#include #include #include +#include +#include #include -#include -#include "vk_layer_config.h" -#include "vulkan/vk_sdk_platform.h" #define MAX_CHARS_PER_LINE 4096 @@ -49,6 +50,25 @@ class ConfigFile { static ConfigFile g_configFileObj; +std::string getEnvironment(const char *variable) { +#if !defined(__ANDROID__) && !defined(_WIN32) + const char *output = getenv(variable); + return output == NULL ? "" : output; +#elif defined(_WIN32) + int size = GetEnvironmentVariable(variable, NULL, 0); + if (size == 0) { + return ""; + } + char *buffer = new char[size]; + GetEnvironmentVariable(variable, buffer, size); + std::string output = buffer; + delete[] buffer; + return output; +#else + return ""; +#endif +} + const char *getLayerOption(const char *_option) { return g_configFileObj.getOption(_option); } // If option is NULL or stdout, return stdout, otherwise try to open option @@ -155,7 +175,19 @@ ConfigFile::~ConfigFile() {} const char *ConfigFile::getOption(const std::string &_option) { std::map::const_iterator it; if (!m_fileIsParsed) { - parseFile("vk_layer_settings.txt"); + std::string envPath = getEnvironment("VK_LAYER_SETTINGS_PATH"); + + // If the path exists use it, else use vk_layer_settings + struct stat info; + if (stat(envPath.c_str(), &info) == 0) { + // If this is a directory, look for vk_layer_settings within the directory + if (info.st_mode & S_IFDIR) { + envPath += "/vk_layer_settings.txt"; + } + parseFile(envPath.c_str()); + } else { + parseFile("vk_layer_settings.txt"); + } } if ((it = m_valueMap.find(_option)) == m_valueMap.end()) @@ -166,7 +198,19 @@ const char *ConfigFile::getOption(const std::string &_option) { void ConfigFile::setOption(const std::string &_option, const std::string &_val) { if (!m_fileIsParsed) { - parseFile("vk_layer_settings.txt"); + std::string envPath = getEnvironment("VK_LAYER_SETTINGS_PATH"); + + // If the path exists use it, else use vk_layer_settings + struct stat info; + if (stat(envPath.c_str(), &info) == 0) { + // If this is a directory, look for vk_layer_settings within the directory + if (info.st_mode & S_IFDIR) { + envPath += "/vk_layer_settings.txt"; + } + parseFile(envPath.c_str()); + } else { + parseFile("vk_layer_settings.txt"); + } } m_valueMap[_option] = _val; -- cgit v1.2.3