Fix for shared handles for pool deleter (#1925)

* Fix for shared handles for pool deleter

* added pool type traits,
added special constructor for pool types

* return of assert
This commit is contained in:
Ilya Doroshenko 2024-08-05 14:21:44 +02:00 committed by GitHub
parent 763e5bf88f
commit 0f4e59bd95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 111 additions and 6 deletions

View File

@ -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() ) );
@ -135,7 +137,7 @@ public:
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 );
}

View File

@ -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>
@ -241,12 +263,23 @@ private:
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 ) )
{

View File

@ -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>
@ -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 ) )
{
@ -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() ) );
@ -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 );
}

View File

@ -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>
@ -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 ) )
{
@ -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() ) );
@ -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 );
}