Skip to content

Commit

Permalink
Fix for shared handles for pool deleter (#1925)
Browse files Browse the repository at this point in the history
* Fix for shared handles for pool deleter

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

* return of assert
  • Loading branch information
Agrael1 authored Aug 5, 2024
1 parent 763e5bf commit 0f4e59b
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 6 deletions.
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
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

0 comments on commit 0f4e59b

Please sign in to comment.