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

Fix for shared handles for pool deleter #1925

Merged
merged 3 commits into from
Aug 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
4 changes: 3 additions & 1 deletion snippets/SharedDestroy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class PoolFreeShared
public:
using DestructorType = typename SharedHandleTraits<HandleType>::DestructorType;

using PoolTypeExport = PoolType;

template <class Dispatcher>
using ReturnType = decltype( std::declval<DestructorType>().free( PoolType(), 0u, nullptr, Dispatcher() ) );

Expand All @@ -135,7 +137,7 @@ class PoolFreeShared
public:
void destroy( DestructorType parent, HandleType handle ) const VULKAN_HPP_NOEXCEPT
{
VULKAN_HPP_ASSERT( m_destroy && m_dispatch );
VULKAN_HPP_ASSERT( m_destroy && m_dispatch && m_pool );
( parent.*m_destroy )( m_pool.get(), 1u, &handle, *m_dispatch );
}

Expand Down
35 changes: 34 additions & 1 deletion snippets/SharedHandle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ struct HasDestructor : std::integral_constant<bool, !std::is_same<DestructorType
{
};

template <typename HandleType, typename = void>
struct HasPoolType : std::false_type
{
};

template <typename HandleType>
struct HasPoolType<HandleType, decltype( (void)typename SharedHandleTraits<HandleType>::deleter::PoolTypeExport() )> : std::true_type
{
};

template <typename HandleType, typename Enable = void>
struct GetPoolType
{
using type = NoDestructor;
};

template <typename HandleType>
struct GetPoolType<HandleType, typename std::enable_if<HasPoolType<HandleType>::value>::type>
{
using type = typename SharedHandleTraits<HandleType>::deleter::PoolTypeExport;
};

//=====================================================================================================================

template <typename HandleType>
Expand Down Expand Up @@ -241,12 +263,23 @@ class SharedHandle : public SharedHandleBase<HandleType, SharedHeader<Destructor
public:
SharedHandle() = default;

template <typename T = HandleType, typename = typename std::enable_if<HasDestructor<T>::value>::type>
template <typename T = HandleType, typename = typename std::enable_if<HasDestructor<T>::value && !HasPoolType<T>::value>::type>
explicit SharedHandle( HandleType handle, SharedHandle<DestructorTypeOf<HandleType>> parent, DeleterType deleter = DeleterType() ) VULKAN_HPP_NOEXCEPT
: BaseType( handle, std::move( parent ), std::move( deleter ) )
{
}

template <typename Dispatcher = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE,
typename T = HandleType,
typename = typename std::enable_if<HasDestructor<T>::value && HasPoolType<T>::value>::type>
explicit SharedHandle( HandleType handle,
SharedHandle<DestructorTypeOf<HandleType>> parent,
SharedHandle<typename GetPoolType<HandleType>::type> pool,
const Dispatcher & dispatch VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) VULKAN_HPP_NOEXCEPT
: BaseType( handle, std::move( parent ), DeleterType{ std::move( pool ), dispatch } )
{
}

template <typename T = HandleType, typename = typename std::enable_if<!HasDestructor<T>::value>::type>
explicit SharedHandle( HandleType handle, DeleterType deleter = DeleterType() ) VULKAN_HPP_NOEXCEPT : BaseType( handle, std::move( deleter ) )
{
Expand Down
2 changes: 1 addition & 1 deletion vulkan/vulkan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16851,7 +16851,7 @@ namespace VULKAN_HPP_NAMESPACE
m_library = dlopen( "libvulkan.1.dylib", RTLD_NOW | RTLD_LOCAL );
}
# elif defined( _WIN32 )
m_library = ::LoadLibraryA( "vulkan-1.dll" );
m_library = ::LoadLibraryA( "vulkan-1.dll" );
# else
# error unsupported platform
# endif
Expand Down
39 changes: 37 additions & 2 deletions vulkan/vulkan_shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ namespace VULKAN_HPP_NAMESPACE
{
};

template <typename HandleType, typename = void>
struct HasPoolType : std::false_type
{
};

template <typename HandleType>
struct HasPoolType<HandleType, decltype( (void)typename SharedHandleTraits<HandleType>::deleter::PoolTypeExport() )> : std::true_type
{
};

template <typename HandleType, typename Enable = void>
struct GetPoolType
{
using type = NoDestructor;
};

template <typename HandleType>
struct GetPoolType<HandleType, typename std::enable_if<HasPoolType<HandleType>::value>::type>
{
using type = typename SharedHandleTraits<HandleType>::deleter::PoolTypeExport;
};

//=====================================================================================================================

template <typename HandleType>
Expand Down Expand Up @@ -257,12 +279,23 @@ namespace VULKAN_HPP_NAMESPACE
public:
SharedHandle() = default;

template <typename T = HandleType, typename = typename std::enable_if<HasDestructor<T>::value>::type>
template <typename T = HandleType, typename = typename std::enable_if<HasDestructor<T>::value && !HasPoolType<T>::value>::type>
explicit SharedHandle( HandleType handle, SharedHandle<DestructorTypeOf<HandleType>> parent, DeleterType deleter = DeleterType() ) VULKAN_HPP_NOEXCEPT
: BaseType( handle, std::move( parent ), std::move( deleter ) )
{
}

template <typename Dispatcher = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE,
typename T = HandleType,
typename = typename std::enable_if<HasDestructor<T>::value && HasPoolType<T>::value>::type>
explicit SharedHandle( HandleType handle,
SharedHandle<DestructorTypeOf<HandleType>> parent,
SharedHandle<typename GetPoolType<HandleType>::type> pool,
const Dispatcher & dispatch VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) VULKAN_HPP_NOEXCEPT
: BaseType( handle, std::move( parent ), DeleterType{ std::move( pool ), dispatch } )
{
}

template <typename T = HandleType, typename = typename std::enable_if<!HasDestructor<T>::value>::type>
explicit SharedHandle( HandleType handle, DeleterType deleter = DeleterType() ) VULKAN_HPP_NOEXCEPT : BaseType( handle, std::move( deleter ) )
{
Expand Down Expand Up @@ -390,6 +423,8 @@ namespace VULKAN_HPP_NAMESPACE
public:
using DestructorType = typename SharedHandleTraits<HandleType>::DestructorType;

using PoolTypeExport = PoolType;

template <class Dispatcher>
using ReturnType = decltype( std::declval<DestructorType>().free( PoolType(), 0u, nullptr, Dispatcher() ) );

Expand All @@ -409,7 +444,7 @@ namespace VULKAN_HPP_NAMESPACE
public:
void destroy( DestructorType parent, HandleType handle ) const VULKAN_HPP_NOEXCEPT
{
VULKAN_HPP_ASSERT( m_destroy && m_dispatch );
VULKAN_HPP_ASSERT( m_destroy && m_dispatch && m_pool );
( parent.*m_destroy )( m_pool.get(), 1u, &handle, *m_dispatch );
}

Expand Down
39 changes: 37 additions & 2 deletions vulkan/vulkansc_shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ namespace VULKAN_HPP_NAMESPACE
{
};

template <typename HandleType, typename = void>
struct HasPoolType : std::false_type
{
};

template <typename HandleType>
struct HasPoolType<HandleType, decltype( (void)typename SharedHandleTraits<HandleType>::deleter::PoolTypeExport() )> : std::true_type
{
};

template <typename HandleType, typename Enable = void>
struct GetPoolType
{
using type = NoDestructor;
};

template <typename HandleType>
struct GetPoolType<HandleType, typename std::enable_if<HasPoolType<HandleType>::value>::type>
{
using type = typename SharedHandleTraits<HandleType>::deleter::PoolTypeExport;
};

//=====================================================================================================================

template <typename HandleType>
Expand Down Expand Up @@ -257,12 +279,23 @@ namespace VULKAN_HPP_NAMESPACE
public:
SharedHandle() = default;

template <typename T = HandleType, typename = typename std::enable_if<HasDestructor<T>::value>::type>
template <typename T = HandleType, typename = typename std::enable_if<HasDestructor<T>::value && !HasPoolType<T>::value>::type>
explicit SharedHandle( HandleType handle, SharedHandle<DestructorTypeOf<HandleType>> parent, DeleterType deleter = DeleterType() ) VULKAN_HPP_NOEXCEPT
: BaseType( handle, std::move( parent ), std::move( deleter ) )
{
}

template <typename Dispatcher = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE,
typename T = HandleType,
typename = typename std::enable_if<HasDestructor<T>::value && HasPoolType<T>::value>::type>
explicit SharedHandle( HandleType handle,
SharedHandle<DestructorTypeOf<HandleType>> parent,
SharedHandle<typename GetPoolType<HandleType>::type> pool,
const Dispatcher & dispatch VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) VULKAN_HPP_NOEXCEPT
: BaseType( handle, std::move( parent ), DeleterType{ std::move( pool ), dispatch } )
{
}

template <typename T = HandleType, typename = typename std::enable_if<!HasDestructor<T>::value>::type>
explicit SharedHandle( HandleType handle, DeleterType deleter = DeleterType() ) VULKAN_HPP_NOEXCEPT : BaseType( handle, std::move( deleter ) )
{
Expand Down Expand Up @@ -390,6 +423,8 @@ namespace VULKAN_HPP_NAMESPACE
public:
using DestructorType = typename SharedHandleTraits<HandleType>::DestructorType;

using PoolTypeExport = PoolType;

template <class Dispatcher>
using ReturnType = decltype( std::declval<DestructorType>().free( PoolType(), 0u, nullptr, Dispatcher() ) );

Expand All @@ -409,7 +444,7 @@ namespace VULKAN_HPP_NAMESPACE
public:
void destroy( DestructorType parent, HandleType handle ) const VULKAN_HPP_NOEXCEPT
{
VULKAN_HPP_ASSERT( m_destroy && m_dispatch );
VULKAN_HPP_ASSERT( m_destroy && m_dispatch && m_pool );
( parent.*m_destroy )( m_pool.get(), 1u, &handle, *m_dispatch );
}

Expand Down
Loading