Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading