VulkanWrapper: fix loading driver when lib path can be resolved by dlopen

On Linux-based machines, a shared library's path may be resolved in multiple ways, such as from LD_LIBRARY_PATH. For these OSes, use dlopen to see if it exists. Note that trying to create a vk::DynamicLoader with an invalid path throws an exception, and enabling exceptions is not always possible, so we want to detect the error case beforehand. Bug: b/177624844 Change-Id: I5f27cfe485afbac0e4f6bda14eed2809669c2510 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/52629Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarAntonio Maiorano <amaiorano@google.com> Presubmit-Ready: Antonio Maiorano <amaiorano@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com>
parent 9d35d544
...@@ -106,7 +106,7 @@ void transitionImageLayout(vk::Device device, vk::CommandPool commandPool, vk::Q ...@@ -106,7 +106,7 @@ void transitionImageLayout(vk::Device device, vk::CommandPool commandPool, vk::Q
} }
else else
{ {
assert(!"unsupported layout transition!"); assert(false && "unsupported layout transition!");
} }
commandBuffer.pipelineBarrier(sourceStage, destinationStage, vk::DependencyFlags{}, 0, nullptr, 0, nullptr, 1, &barrier); commandBuffer.pipelineBarrier(sourceStage, destinationStage, vk::DependencyFlags{}, 0, nullptr, 0, nullptr, 1, &barrier);
......
...@@ -18,12 +18,16 @@ ...@@ -18,12 +18,16 @@
#if defined(_WIN32) #if defined(_WIN32)
# define OS_WINDOWS 1 # define OS_WINDOWS 1
#elif defined(__APPLE__) #elif defined(__APPLE__)
# include "dlfcn.h"
# define OS_MAC 1 # define OS_MAC 1
#elif defined(__ANDROID__) #elif defined(__ANDROID__)
# include "dlfcn.h"
# define OS_ANDROID 1 # define OS_ANDROID 1
#elif defined(__linux__) #elif defined(__linux__)
# include "dlfcn.h"
# define OS_LINUX 1 # define OS_LINUX 1
#elif defined(__Fuchsia__) #elif defined(__Fuchsia__)
# include <zircon/dlfcn.h>
# define OS_FUCHSIA 1 # define OS_FUCHSIA 1
#else #else
# error Unimplemented platform # error Unimplemented platform
...@@ -34,11 +38,11 @@ std::vector<const char *> getDriverPaths() ...@@ -34,11 +38,11 @@ std::vector<const char *> getDriverPaths()
{ {
#if OS_WINDOWS #if OS_WINDOWS
# if !defined(STANDALONE) # if !defined(STANDALONE)
// The DLL is delay loaded (see BUILD.gn), so we can load // The DLL is delay loaded (see BUILD.gn), so we can load
// the correct ones from Chrome's swiftshader subdirectory. // the correct ones from Chrome's swiftshader subdirectory.
// HMODULE libvulkan = LoadLibraryA("swiftshader\\libvulkan.dll"); // HMODULE libvulkan = LoadLibraryA("swiftshader\\libvulkan.dll");
// EXPECT_NE((HMODULE)NULL, libvulkan); // EXPECT_NE((HMODULE)NULL, libvulkan);
// return true; // return true;
# error TODO: !STANDALONE # error TODO: !STANDALONE
# elif defined(NDEBUG) # elif defined(NDEBUG)
# if defined(_WIN64) # if defined(_WIN64)
...@@ -95,6 +99,20 @@ std::unique_ptr<vk::DynamicLoader> loadDriver() ...@@ -95,6 +99,20 @@ std::unique_ptr<vk::DynamicLoader> loadDriver()
continue; continue;
return std::make_unique<vk::DynamicLoader>(p); return std::make_unique<vk::DynamicLoader>(p);
} }
#if(OS_MAC || OS_LINUX || OS_ANDROID || OS_FUCHSIA)
// On Linux-based OSes, the lib path may be resolved by dlopen
for(auto &p : getDriverPaths())
{
auto lib = dlopen(p, RTLD_LAZY | RTLD_LOCAL);
if(lib)
{
dlclose(lib);
return std::make_unique<vk::DynamicLoader>(p);
}
}
#endif
return {}; return {};
} }
......
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