Commit ffb71dc2 by Jonah Ryan-Davis Committed by Geoff Lang

Revert "Reland Change to module directory when loading swiftshader ICD."

This reverts commit c8c414b0. Reason for revert: Breaking fuchsia_x64 and ANGLE autoroller Original change's description: > Reland Change to module directory when loading swiftshader ICD. > > This is a reland of commit 3b10dda6. > > Extra changes: > Be explicit about calling GetModuleHandleA > Do not use the general GetModuleHandle, which may use wide strings > > GetModuleDirectory should return the full path, not relative. > ANGLE wasn't able to locate the vulkan ICD file because it was > searching down an invalid relative path. This can be fixed by > ensuring the module directory is always the full path. > on some platforms. > > Original change's description: > > When loading vulkan, we can be running from any directory. We need > > to change to the module directory to ensure the swiftshader ICD is > > loaded properly. For example, in some Chrome releases, libGLESv2.dll > > and libvk_swiftshader.dll are in a subdirectory relative to chrome.exe > > > > Bug: chromium:1198567 > > Change-Id: I9e68927e512b239728fb2903d1a04702508a4948 > > Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2873452 > > Commit-Queue: Jonah Ryan-Davis <jonahr@google.com> > > Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> > > Reviewed-by: Jamie Madill <jmadill@chromium.org> > > Bug: chromium:1198567 > Bug: angleproject:5949 > Change-Id: Ib34067002c788f00b5ae2fa11d1e465f57bd7be8 > Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2893503 > Reviewed-by: Jamie Madill <jmadill@chromium.org> > Reviewed-by: Cody Northrop <cnorthrop@google.com> > Commit-Queue: Jonah Ryan-Davis <jonahr@google.com> Bug: chromium:1198567 Bug: angleproject:5949 Change-Id: Ic0be8949cc27b231be4f982ea6e22beed590d24d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2903786Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 4b92e089
...@@ -107,9 +107,6 @@ config("internal_config") { ...@@ -107,9 +107,6 @@ config("internal_config") {
if (is_win) { if (is_win) {
defines += [ "ANGLE_IS_WIN" ] defines += [ "ANGLE_IS_WIN" ]
if (angle_is_winuwp) {
defines += [ "ANGLE_IS_WINUWP" ]
}
} else if (is_linux || is_chromeos) { } else if (is_linux || is_chromeos) {
defines += [ "ANGLE_IS_LINUX" ] defines += [ "ANGLE_IS_LINUX" ]
} }
......
...@@ -19,7 +19,7 @@ namespace angle ...@@ -19,7 +19,7 @@ namespace angle
std::string GetExecutableName(); std::string GetExecutableName();
std::string GetExecutablePath(); std::string GetExecutablePath();
std::string GetExecutableDirectory(); std::string GetExecutableDirectory();
std::string GetModuleDirectory(); std::string GetHelperExecutableDir();
const char *GetSharedLibraryExtension(); const char *GetSharedLibraryExtension();
const char *GetExecutableExtension(); const char *GetExecutableExtension();
char GetPathSeparator(); char GetPathSeparator();
......
...@@ -56,7 +56,7 @@ const char *GetPathSeparatorForEnvironmentVar() ...@@ -56,7 +56,7 @@ const char *GetPathSeparatorForEnvironmentVar()
return ":"; return ":";
} }
std::string GetModuleDirectory() std::string GetHelperExecutableDir()
{ {
std::string directory; std::string directory;
static int placeholderSymbol = 0; static int placeholderSymbol = 0;
...@@ -66,12 +66,6 @@ std::string GetModuleDirectory() ...@@ -66,12 +66,6 @@ std::string GetModuleDirectory()
std::string moduleName = dlInfo.dli_fname; std::string moduleName = dlInfo.dli_fname;
directory = moduleName.substr(0, moduleName.find_last_of('/') + 1); directory = moduleName.substr(0, moduleName.find_last_of('/') + 1);
} }
// Ensure we return the full path to the module, not the relative path
Optional<std::string> cwd = GetCWD();
if (!directory.empty() && directory.at(0) != '/' && cwd.valid())
{
directory = cwd.value() + GetPathSeparator() + directory;
}
return directory; return directory;
} }
...@@ -113,7 +107,7 @@ Library *OpenSharedLibrary(const char *libraryName, SearchType searchType) ...@@ -113,7 +107,7 @@ Library *OpenSharedLibrary(const char *libraryName, SearchType searchType)
// On iOS, shared libraries must be loaded from within the app bundle. // On iOS, shared libraries must be loaded from within the app bundle.
directory = GetExecutableDirectory() + "/Frameworks/"; directory = GetExecutableDirectory() + "/Frameworks/";
#else #else
directory = GetModuleDirectory(); directory = GetHelperExecutableDir();
#endif #endif
} }
......
...@@ -15,37 +15,21 @@ ...@@ -15,37 +15,21 @@
namespace angle namespace angle
{ {
std::string GetExecutablePath()
namespace
{
std::string GetPath(HMODULE module)
{ {
std::array<char, MAX_PATH> executableFileBuf; std::array<char, MAX_PATH> executableFileBuf;
DWORD executablePathLen = GetModuleFileNameA(module, executableFileBuf.data(), DWORD executablePathLen = GetModuleFileNameA(nullptr, executableFileBuf.data(),
static_cast<DWORD>(executableFileBuf.size())); static_cast<DWORD>(executableFileBuf.size()));
return (executablePathLen > 0 ? std::string(executableFileBuf.data()) : ""); return (executablePathLen > 0 ? std::string(executableFileBuf.data()) : "");
} }
std::string GetDirectory(HMODULE module) std::string GetExecutableDirectory()
{ {
std::string executablePath = GetPath(module); std::string executablePath = GetExecutablePath();
size_t lastPathSepLoc = executablePath.find_last_of("\\/"); size_t lastPathSepLoc = executablePath.find_last_of("\\/");
return (lastPathSepLoc != std::string::npos) ? executablePath.substr(0, lastPathSepLoc) : ""; return (lastPathSepLoc != std::string::npos) ? executablePath.substr(0, lastPathSepLoc) : "";
} }
} // anonymous namespace
std::string GetExecutablePath()
{
return GetPath(nullptr);
}
std::string GetExecutableDirectory()
{
return GetDirectory(nullptr);
}
const char *GetSharedLibraryExtension() const char *GetSharedLibraryExtension()
{ {
return "dll"; return "dll";
...@@ -117,20 +101,8 @@ char GetPathSeparator() ...@@ -117,20 +101,8 @@ char GetPathSeparator()
return '\\'; return '\\';
} }
std::string GetModuleDirectory() std::string GetHelperExecutableDir()
{ {
// GetModuleHandleEx is unavailable on UWP return "";
#if !defined(ANGLE_IS_WINUWP)
static int placeholderSymbol = 0;
HMODULE module = nullptr;
if (GetModuleHandleExA(
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
reinterpret_cast<LPCSTR>(&placeholderSymbol), &module))
{
return GetDirectory(module);
}
#endif
return GetDirectory(nullptr);
} }
} // namespace angle } // namespace angle
...@@ -51,9 +51,12 @@ namespace ...@@ -51,9 +51,12 @@ namespace
!defined(ANGLE_PLATFORM_GGP) !defined(ANGLE_PLATFORM_GGP)
const std::string WrapICDEnvironment(const char *icdEnvironment) const std::string WrapICDEnvironment(const char *icdEnvironment)
{ {
// The libraries are bundled into the module directory # if defined(ANGLE_PLATFORM_APPLE)
std::string ret = angle::GetModuleDirectory() + GetPathSeparator() + icdEnvironment; // On MacOS the libraries are bundled into the application directory
std::string ret = angle::GetHelperExecutableDir() + icdEnvironment;
return ret; return ret;
# endif // defined(ANGLE_PLATFORM_APPLE)
return icdEnvironment;
} }
constexpr char kLoaderLayersPathEnv[] = "VK_LAYER_PATH"; constexpr char kLoaderLayersPathEnv[] = "VK_LAYER_PATH";
...@@ -143,9 +146,9 @@ ScopedVkLoaderEnvironment::ScopedVkLoaderEnvironment(bool enableValidationLayers ...@@ -143,9 +146,9 @@ ScopedVkLoaderEnvironment::ScopedVkLoaderEnvironment(bool enableValidationLayers
} }
else else
{ {
mPreviousCWD = cwd.value(); mPreviousCWD = cwd.value();
std::string moduleDir = angle::GetModuleDirectory(); std::string exeDir = angle::GetExecutableDirectory();
mChangedCWD = angle::SetCWD(moduleDir.c_str()); mChangedCWD = angle::SetCWD(exeDir.c_str());
if (!mChangedCWD) if (!mChangedCWD)
{ {
ERR() << "Error setting CWD for Vulkan layers init."; ERR() << "Error setting CWD for Vulkan layers init.";
......
...@@ -393,8 +393,8 @@ void CLPlatformCL::Initialize(const cl_icd_dispatch &dispatch, bool isIcd) ...@@ -393,8 +393,8 @@ void CLPlatformCL::Initialize(const cl_icd_dispatch &dispatch, bool isIcd)
} }
// The absolute path to ANGLE's OpenCL library is needed and it is assumed here that // The absolute path to ANGLE's OpenCL library is needed and it is assumed here that
// it is in the same directory as the shared library which contains this CL back end. // it is in the same directory as the executable which contains this CL back end.
std::string libPath = angle::GetModuleDirectory(); std::string libPath = angle::GetExecutableDirectory();
if (!libPath.empty() && libPath.back() != angle::GetPathSeparator()) if (!libPath.empty() && libPath.back() != angle::GetPathSeparator())
{ {
libPath += angle::GetPathSeparator(); libPath += angle::GetPathSeparator();
......
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