Commit 046fa0ef by jchen10 Committed by Commit Bot

Vulkan: Prepend layer path to VK_LAYER_PATH

Directly setting this variable overwrites old value, as might be unexpected. Instead the path can be prepended to it, so that old value can still work. This is needed in order to use additional debugging layers, like the "api_dump" layer. See https://github.com/LunarG/VulkanTools for more. BUG=angleproject:2333 Change-Id: I5338a5b928ffa792cc9b6db5b69713320b5b0842 Reviewed-on: https://chromium-review.googlesource.com/898591 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 2f23f35a
//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// system_utils.cpp: Implementation of common functions
#include "system_utils.h"
namespace angle
{
bool PrependPathToEnvironmentVar(const char *variableName, const char *path)
{
std::string oldValue = GetEnvironmentVar(variableName);
const char *newValue = nullptr;
std::string buf;
if (oldValue.empty())
{
newValue = path;
}
else
{
buf = path;
buf += GetPathSeparator();
buf += oldValue;
newValue = buf.c_str();
}
return SetEnvironmentVar(variableName, newValue);
}
} // namespace angle
......@@ -21,6 +21,9 @@ const char *GetSharedLibraryExtension();
Optional<std::string> GetCWD();
bool SetCWD(const char *dirName);
bool SetEnvironmentVar(const char *variableName, const char *value);
std::string GetEnvironmentVar(const char *variableName);
const char *GetPathSeparator();
bool PrependPathToEnvironmentVar(const char *variableName, const char *path);
} // namespace angle
......
......@@ -86,4 +86,15 @@ bool SetEnvironmentVar(const char *variableName, const char *value)
return (setenv(variableName, value, 1) == 0);
}
std::string GetEnvironmentVar(const char *variableName)
{
const char *value = getenv(variableName);
return (value == nullptr ? std::string() : std::string(value));
}
const char *GetPathSeparator()
{
return ":";
}
} // namespace angle
......@@ -91,4 +91,15 @@ bool SetEnvironmentVar(const char *variableName, const char *value)
return (setenv(variableName, value, 1) == 0);
}
std::string GetEnvironmentVar(const char *variableName)
{
const char *value = getenv(variableName);
return (value == nullptr ? std::string() : std::string(value));
}
const char *GetPathSeparator()
{
return ":";
}
} // namespace angle
......@@ -76,4 +76,24 @@ bool SetEnvironmentVar(const char *variableName, const char *value)
return (SetEnvironmentVariableA(variableName, value) == TRUE);
}
std::string GetEnvironmentVar(const char *variableName)
{
std::array<char, MAX_PATH> oldValue;
DWORD result =
GetEnvironmentVariableA(variableName, oldValue.data(), static_cast<DWORD>(oldValue.size()));
if (result == 0)
{
return std::string();
}
else
{
return std::string(oldValue.data());
}
}
const char *GetPathSeparator()
{
return ";";
}
} // namespace angle
......@@ -122,7 +122,7 @@ class ScopedVkLoaderEnvironment : angle::NonCopyable
// Override environment variable to use the ANGLE layers.
if (mEnableValidationLayers)
{
if (!angle::SetEnvironmentVar(g_VkLoaderLayersPathEnv, ANGLE_VK_LAYERS_DIR))
if (!angle::PrependPathToEnvironmentVar(g_VkLoaderLayersPathEnv, ANGLE_VK_LAYERS_DIR))
{
ERR() << "Error setting environment for Vulkan layers init.";
mEnableValidationLayers = false;
......
......@@ -27,6 +27,8 @@
'common/platform.h',
'common/string_utils.cpp',
'common/string_utils.h',
'common/system_utils.cpp',
'common/system_utils.h',
'common/third_party/base/anglebase/base_export.h',
'common/third_party/base/anglebase/containers/mru_cache.h',
'common/third_party/base/anglebase/logging.h',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment