2022-07-28 15:09:08 +00:00
|
|
|
#if VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL
|
|
|
|
class DynamicLoader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
# ifdef VULKAN_HPP_NO_EXCEPTIONS
|
|
|
|
DynamicLoader( std::string const & vulkanLibraryName = {} ) VULKAN_HPP_NOEXCEPT
|
|
|
|
# else
|
|
|
|
DynamicLoader( std::string const & vulkanLibraryName = {} )
|
|
|
|
# endif
|
|
|
|
{
|
|
|
|
if ( !vulkanLibraryName.empty() )
|
|
|
|
{
|
2023-08-30 10:26:18 +00:00
|
|
|
# if defined( __unix__ ) || defined( __APPLE__ ) || defined( __QNX__ ) || defined(__Fuchsia__)
|
2022-07-28 15:09:08 +00:00
|
|
|
m_library = dlopen( vulkanLibraryName.c_str(), RTLD_NOW | RTLD_LOCAL );
|
|
|
|
# elif defined( _WIN32 )
|
|
|
|
m_library = ::LoadLibraryA( vulkanLibraryName.c_str() );
|
|
|
|
# else
|
|
|
|
# error unsupported platform
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-30 10:26:18 +00:00
|
|
|
# if defined( __unix__ ) || defined( __QNX__ ) || defined(__Fuchsia__)
|
2022-07-28 15:09:08 +00:00
|
|
|
m_library = dlopen( "libvulkan.so", RTLD_NOW | RTLD_LOCAL );
|
|
|
|
if ( m_library == nullptr )
|
|
|
|
{
|
|
|
|
m_library = dlopen( "libvulkan.so.1", RTLD_NOW | RTLD_LOCAL );
|
|
|
|
}
|
|
|
|
# elif defined( __APPLE__ )
|
|
|
|
m_library = dlopen( "libvulkan.dylib", RTLD_NOW | RTLD_LOCAL );
|
2024-01-02 12:56:05 +00:00
|
|
|
if (m_library == nullptr)
|
|
|
|
{
|
|
|
|
m_library = dlopen("libvulkan.1.dylib", RTLD_NOW | RTLD_LOCAL);
|
|
|
|
}
|
2022-07-28 15:09:08 +00:00
|
|
|
# elif defined( _WIN32 )
|
|
|
|
m_library = ::LoadLibraryA( "vulkan-1.dll" );
|
|
|
|
# else
|
|
|
|
# error unsupported platform
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef VULKAN_HPP_NO_EXCEPTIONS
|
|
|
|
if ( m_library == nullptr )
|
|
|
|
{
|
|
|
|
// NOTE there should be an InitializationFailedError, but msvc insists on the symbol does not exist within the scope of this function.
|
|
|
|
throw std::runtime_error( "Failed to load vulkan library!" );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
DynamicLoader( DynamicLoader const & ) = delete;
|
|
|
|
|
|
|
|
DynamicLoader( DynamicLoader && other ) VULKAN_HPP_NOEXCEPT : m_library(other.m_library)
|
|
|
|
{
|
|
|
|
other.m_library = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
DynamicLoader &operator=( DynamicLoader const & ) = delete;
|
|
|
|
|
|
|
|
DynamicLoader &operator=( DynamicLoader && other ) VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
|
|
|
std::swap(m_library, other.m_library);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
~DynamicLoader() VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
|
|
|
if ( m_library )
|
|
|
|
{
|
2023-08-30 10:26:18 +00:00
|
|
|
# if defined( __unix__ ) || defined( __APPLE__ ) || defined( __QNX__ ) || defined(__Fuchsia__)
|
2022-07-28 15:09:08 +00:00
|
|
|
dlclose( m_library );
|
|
|
|
# elif defined( _WIN32 )
|
|
|
|
::FreeLibrary( m_library );
|
|
|
|
# else
|
|
|
|
# error unsupported platform
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T getProcAddress( const char* function ) const VULKAN_HPP_NOEXCEPT
|
|
|
|
{
|
2023-08-30 10:26:18 +00:00
|
|
|
# if defined( __unix__ ) || defined( __APPLE__ ) || defined( __QNX__ ) || defined(__Fuchsia__)
|
2022-07-28 15:09:08 +00:00
|
|
|
return (T)dlsym( m_library, function );
|
|
|
|
# elif defined( _WIN32 )
|
|
|
|
return (T)::GetProcAddress( m_library, function );
|
|
|
|
# else
|
|
|
|
# error unsupported platform
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool success() const VULKAN_HPP_NOEXCEPT { return m_library != nullptr; }
|
|
|
|
|
|
|
|
private:
|
2023-08-30 10:26:18 +00:00
|
|
|
# if defined( __unix__ ) || defined( __APPLE__ ) || defined( __QNX__ ) || defined(__Fuchsia__)
|
2022-07-28 15:09:08 +00:00
|
|
|
void * m_library;
|
|
|
|
# elif defined( _WIN32 )
|
|
|
|
::HINSTANCE m_library;
|
|
|
|
# else
|
|
|
|
# error unsupported platform
|
|
|
|
# endif
|
|
|
|
};
|
|
|
|
#endif
|