Skip to content

Commit

Permalink
Adjust loading procedure of the vk::detail::DynamicLoader on MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
asuessenbach committed Nov 5, 2024
1 parent 6902b57 commit 45d047c
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 40 deletions.
48 changes: 34 additions & 14 deletions snippets/DynamicLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
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);
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 )
{
m_library = dlopen( "libvulkan.so.1", 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!" );
Expand Down
46 changes: 33 additions & 13 deletions vulkan/vulkan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!" );
Expand Down
46 changes: 33 additions & 13 deletions vulkan/vulkansc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!" );
Expand Down

0 comments on commit 45d047c

Please sign in to comment.