Skip to content

Commit

Permalink
added pool type traits,
Browse files Browse the repository at this point in the history
added special constructor for pool types
  • Loading branch information
Agrael1 committed Jul 23, 2024
1 parent 5f79a12 commit 85c2ae4
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 4 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
{
if( m_destroy && m_dispatch && m_pool )
if ( 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
37 changes: 36 additions & 1 deletion 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 Down

0 comments on commit 85c2ae4

Please sign in to comment.