Adjust loading procedure of the vk::detail::DynamicLoader on MacOS (#1991)

This commit is contained in:
Andreas Süßenbach 2024-11-05 19:52:08 +01:00 committed by GitHub
parent 6902b578be
commit 43f7a18b02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 100 additions and 40 deletions

View File

@ -10,37 +10,57 @@
{
if ( !vulkanLibraryName.empty() )
{
# if defined( __unix__ ) || defined( __APPLE__ ) || defined( __QNX__ ) || defined(__Fuchsia__)
m_library = dlopen( vulkanLibraryName.c_str(), RTLD_NOW | RTLD_LOCAL );
# elif defined( _WIN32 )
# if defined( _WIN32 )
m_library = ::LoadLibraryA( vulkanLibraryName.c_str() );
# elif defined( __unix__ ) || defined( __APPLE__ ) || defined( __QNX__ ) || defined(__Fuchsia__)
m_library = dlopen( vulkanLibraryName.c_str(), RTLD_NOW | RTLD_LOCAL );
# else
# error unsupported platform
# endif
}
else
{
# if defined( __unix__ ) || defined( __QNX__ ) || defined(__Fuchsia__)
# if defined( _WIN32 )
m_library = ::LoadLibraryA( "vulkan-1.dll" );
# elif defined( __APPLE__ )
m_library = dlopen( "libvulkan.dylib", RTLD_NOW | RTLD_LOCAL );
if ( !m_library )
{
m_library = dlopen( "libvulkan.1.dylib", RTLD_NOW | RTLD_LOCAL );
}
if ( !m_library )
{
m_library = dlopen( "libMoltenVK.dylib", RTLD_NOW | RTLD_LOCAL );
}
// Add support for using Vulkan and MoltenVK in a Framework. App store rules for iOS
// strictly enforce no .dylib's. If they aren't found it just falls through
if ( !m_library )
{
m_library = dlopen( "vulkan.framework/vulkan", RTLD_NOW | RTLD_LOCAL );
}
if ( !m_library )
{
m_library = dlopen( "MoltenVK.framework/MoltenVK", RTLD_NOW | RTLD_LOCAL );
}
// modern versions of macOS don't search /usr/local/lib automatically contrary to what man dlopen says
// Vulkan SDK uses this as the system-wide installation location, so we're going to fallback to this if all else fails
if ( !m_library && ( getenv("DYLD_FALLBACK_LIBRARY_PATH") == NULL ) )
{
m_library = dlopen( "/usr/local/lib/libvulkan.dylib", RTLD_NOW | RTLD_LOCAL );
}
# elif defined( __unix__ ) || defined( __QNX__ ) || defined(__Fuchsia__)
m_library = dlopen( "libvulkan.so", RTLD_NOW | RTLD_LOCAL );
if ( m_library == nullptr )
if ( !m_library )
{
m_library = dlopen( "libvulkan.so.1", RTLD_NOW | RTLD_LOCAL );
}
# elif defined( __APPLE__ )
m_library = dlopen( "libvulkan.dylib", RTLD_NOW | RTLD_LOCAL );
if (m_library == nullptr)
{
m_library = dlopen("libvulkan.1.dylib", RTLD_NOW | RTLD_LOCAL);
}
# elif defined( _WIN32 )
m_library = ::LoadLibraryA( "vulkan-1.dll" );
# else
# error unsupported platform
# endif
}
#ifndef VULKAN_HPP_NO_EXCEPTIONS
if ( m_library == nullptr )
if ( !m_library )
{
// 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!" );

View File

@ -17175,37 +17175,57 @@ namespace VULKAN_HPP_NAMESPACE
{
if ( !vulkanLibraryName.empty() )
{
# if defined( __unix__ ) || defined( __APPLE__ ) || defined( __QNX__ ) || defined( __Fuchsia__ )
m_library = dlopen( vulkanLibraryName.c_str(), RTLD_NOW | RTLD_LOCAL );
# elif defined( _WIN32 )
# if defined( _WIN32 )
m_library = ::LoadLibraryA( vulkanLibraryName.c_str() );
# elif defined( __unix__ ) || defined( __APPLE__ ) || defined( __QNX__ ) || defined( __Fuchsia__ )
m_library = dlopen( vulkanLibraryName.c_str(), RTLD_NOW | RTLD_LOCAL );
# else
# error unsupported platform
# endif
}
else
{
# if defined( __unix__ ) || defined( __QNX__ ) || defined( __Fuchsia__ )
m_library = dlopen( "libvulkan.so", RTLD_NOW | RTLD_LOCAL );
if ( m_library == nullptr )
{
m_library = dlopen( "libvulkan.so.1", RTLD_NOW | RTLD_LOCAL );
}
# if defined( _WIN32 )
m_library = ::LoadLibraryA( "vulkan-1.dll" );
# elif defined( __APPLE__ )
m_library = dlopen( "libvulkan.dylib", RTLD_NOW | RTLD_LOCAL );
if ( m_library == nullptr )
if ( !m_library )
{
m_library = dlopen( "libvulkan.1.dylib", RTLD_NOW | RTLD_LOCAL );
}
# elif defined( _WIN32 )
m_library = ::LoadLibraryA( "vulkan-1.dll" );
if ( !m_library )
{
m_library = dlopen( "libMoltenVK.dylib", RTLD_NOW | RTLD_LOCAL );
}
// Add support for using Vulkan and MoltenVK in a Framework. App store rules for iOS
// strictly enforce no .dylib's. If they aren't found it just falls through
if ( !m_library )
{
m_library = dlopen( "vulkan.framework/vulkan", RTLD_NOW | RTLD_LOCAL );
}
if ( !m_library )
{
m_library = dlopen( "MoltenVK.framework/MoltenVK", RTLD_NOW | RTLD_LOCAL );
}
// modern versions of macOS don't search /usr/local/lib automatically contrary to what man dlopen says
// Vulkan SDK uses this as the system-wide installation location, so we're going to fallback to this if all else fails
if ( !m_library && ( getenv( "DYLD_FALLBACK_LIBRARY_PATH" ) == NULL ) )
{
m_library = dlopen( "/usr/local/lib/libvulkan.dylib", RTLD_NOW | RTLD_LOCAL );
}
# elif defined( __unix__ ) || defined( __QNX__ ) || defined( __Fuchsia__ )
m_library = dlopen( "libvulkan.so", RTLD_NOW | RTLD_LOCAL );
if ( !m_library )
{
m_library = dlopen( "libvulkan.so.1", RTLD_NOW | RTLD_LOCAL );
}
# else
# error unsupported platform
# endif
}
# ifndef VULKAN_HPP_NO_EXCEPTIONS
if ( m_library == nullptr )
if ( !m_library )
{
// 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!" );

View File

@ -7081,37 +7081,57 @@ namespace VULKAN_HPP_NAMESPACE
{
if ( !vulkanLibraryName.empty() )
{
# if defined( __unix__ ) || defined( __APPLE__ ) || defined( __QNX__ ) || defined( __Fuchsia__ )
m_library = dlopen( vulkanLibraryName.c_str(), RTLD_NOW | RTLD_LOCAL );
# elif defined( _WIN32 )
# if defined( _WIN32 )
m_library = ::LoadLibraryA( vulkanLibraryName.c_str() );
# elif defined( __unix__ ) || defined( __APPLE__ ) || defined( __QNX__ ) || defined( __Fuchsia__ )
m_library = dlopen( vulkanLibraryName.c_str(), RTLD_NOW | RTLD_LOCAL );
# else
# error unsupported platform
# endif
}
else
{
# if defined( __unix__ ) || defined( __QNX__ ) || defined( __Fuchsia__ )
m_library = dlopen( "libvulkan.so", RTLD_NOW | RTLD_LOCAL );
if ( m_library == nullptr )
{
m_library = dlopen( "libvulkan.so.1", RTLD_NOW | RTLD_LOCAL );
}
# if defined( _WIN32 )
m_library = ::LoadLibraryA( "vulkan-1.dll" );
# elif defined( __APPLE__ )
m_library = dlopen( "libvulkan.dylib", RTLD_NOW | RTLD_LOCAL );
if ( m_library == nullptr )
if ( !m_library )
{
m_library = dlopen( "libvulkan.1.dylib", RTLD_NOW | RTLD_LOCAL );
}
# elif defined( _WIN32 )
m_library = ::LoadLibraryA( "vulkan-1.dll" );
if ( !m_library )
{
m_library = dlopen( "libMoltenVK.dylib", RTLD_NOW | RTLD_LOCAL );
}
// Add support for using Vulkan and MoltenVK in a Framework. App store rules for iOS
// strictly enforce no .dylib's. If they aren't found it just falls through
if ( !m_library )
{
m_library = dlopen( "vulkan.framework/vulkan", RTLD_NOW | RTLD_LOCAL );
}
if ( !m_library )
{
m_library = dlopen( "MoltenVK.framework/MoltenVK", RTLD_NOW | RTLD_LOCAL );
}
// modern versions of macOS don't search /usr/local/lib automatically contrary to what man dlopen says
// Vulkan SDK uses this as the system-wide installation location, so we're going to fallback to this if all else fails
if ( !m_library && ( getenv( "DYLD_FALLBACK_LIBRARY_PATH" ) == NULL ) )
{
m_library = dlopen( "/usr/local/lib/libvulkan.dylib", RTLD_NOW | RTLD_LOCAL );
}
# elif defined( __unix__ ) || defined( __QNX__ ) || defined( __Fuchsia__ )
m_library = dlopen( "libvulkan.so", RTLD_NOW | RTLD_LOCAL );
if ( !m_library )
{
m_library = dlopen( "libvulkan.so.1", RTLD_NOW | RTLD_LOCAL );
}
# else
# error unsupported platform
# endif
}
# ifndef VULKAN_HPP_NO_EXCEPTIONS
if ( m_library == nullptr )
if ( !m_library )
{
// 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!" );