From 0f4e59bd95316ac76c8d40ea58736c0da0145e3d Mon Sep 17 00:00:00 2001 From: Ilya Doroshenko Date: Mon, 5 Aug 2024 14:21:44 +0200 Subject: [PATCH] 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 --- snippets/SharedDestroy.hpp | 4 +++- snippets/SharedHandle.hpp | 35 +++++++++++++++++++++++++++++++++- vulkan/vulkan_shared.hpp | 39 ++++++++++++++++++++++++++++++++++++-- vulkan/vulkansc_shared.hpp | 39 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 111 insertions(+), 6 deletions(-) diff --git a/snippets/SharedDestroy.hpp b/snippets/SharedDestroy.hpp index 912015f..645c0fd 100644 --- a/snippets/SharedDestroy.hpp +++ b/snippets/SharedDestroy.hpp @@ -116,6 +116,8 @@ class PoolFreeShared public: using DestructorType = typename SharedHandleTraits::DestructorType; + using PoolTypeExport = PoolType; + template using ReturnType = decltype( std::declval().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 ); } diff --git a/snippets/SharedHandle.hpp b/snippets/SharedHandle.hpp index 336d079..339c99f 100644 --- a/snippets/SharedHandle.hpp +++ b/snippets/SharedHandle.hpp @@ -36,6 +36,28 @@ struct HasDestructor : std::integral_constant +struct HasPoolType : std::false_type +{ +}; + +template +struct HasPoolType::deleter::PoolTypeExport() )> : std::true_type +{ +}; + +template +struct GetPoolType +{ + using type = NoDestructor; +}; + +template +struct GetPoolType::value>::type> +{ + using type = typename SharedHandleTraits::deleter::PoolTypeExport; +}; + //===================================================================================================================== template @@ -241,12 +263,23 @@ private: public: SharedHandle() = default; - template ::value>::type> + template ::value && !HasPoolType::value>::type> explicit SharedHandle( HandleType handle, SharedHandle> parent, DeleterType deleter = DeleterType() ) VULKAN_HPP_NOEXCEPT : BaseType( handle, std::move( parent ), std::move( deleter ) ) { } + template ::value && HasPoolType::value>::type> + explicit SharedHandle( HandleType handle, + SharedHandle> parent, + SharedHandle::type> pool, + const Dispatcher & dispatch VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) VULKAN_HPP_NOEXCEPT + : BaseType( handle, std::move( parent ), DeleterType{ std::move( pool ), dispatch } ) + { + } + template ::value>::type> explicit SharedHandle( HandleType handle, DeleterType deleter = DeleterType() ) VULKAN_HPP_NOEXCEPT : BaseType( handle, std::move( deleter ) ) { diff --git a/vulkan/vulkan_shared.hpp b/vulkan/vulkan_shared.hpp index 8b2697a..78256fd 100644 --- a/vulkan/vulkan_shared.hpp +++ b/vulkan/vulkan_shared.hpp @@ -52,6 +52,28 @@ namespace VULKAN_HPP_NAMESPACE { }; + template + struct HasPoolType : std::false_type + { + }; + + template + struct HasPoolType::deleter::PoolTypeExport() )> : std::true_type + { + }; + + template + struct GetPoolType + { + using type = NoDestructor; + }; + + template + struct GetPoolType::value>::type> + { + using type = typename SharedHandleTraits::deleter::PoolTypeExport; + }; + //===================================================================================================================== template @@ -257,12 +279,23 @@ namespace VULKAN_HPP_NAMESPACE public: SharedHandle() = default; - template ::value>::type> + template ::value && !HasPoolType::value>::type> explicit SharedHandle( HandleType handle, SharedHandle> parent, DeleterType deleter = DeleterType() ) VULKAN_HPP_NOEXCEPT : BaseType( handle, std::move( parent ), std::move( deleter ) ) { } + template ::value && HasPoolType::value>::type> + explicit SharedHandle( HandleType handle, + SharedHandle> parent, + SharedHandle::type> pool, + const Dispatcher & dispatch VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) VULKAN_HPP_NOEXCEPT + : BaseType( handle, std::move( parent ), DeleterType{ std::move( pool ), dispatch } ) + { + } + template ::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::DestructorType; + using PoolTypeExport = PoolType; + template using ReturnType = decltype( std::declval().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 ); } diff --git a/vulkan/vulkansc_shared.hpp b/vulkan/vulkansc_shared.hpp index 7a8bc56..2034790 100644 --- a/vulkan/vulkansc_shared.hpp +++ b/vulkan/vulkansc_shared.hpp @@ -52,6 +52,28 @@ namespace VULKAN_HPP_NAMESPACE { }; + template + struct HasPoolType : std::false_type + { + }; + + template + struct HasPoolType::deleter::PoolTypeExport() )> : std::true_type + { + }; + + template + struct GetPoolType + { + using type = NoDestructor; + }; + + template + struct GetPoolType::value>::type> + { + using type = typename SharedHandleTraits::deleter::PoolTypeExport; + }; + //===================================================================================================================== template @@ -257,12 +279,23 @@ namespace VULKAN_HPP_NAMESPACE public: SharedHandle() = default; - template ::value>::type> + template ::value && !HasPoolType::value>::type> explicit SharedHandle( HandleType handle, SharedHandle> parent, DeleterType deleter = DeleterType() ) VULKAN_HPP_NOEXCEPT : BaseType( handle, std::move( parent ), std::move( deleter ) ) { } + template ::value && HasPoolType::value>::type> + explicit SharedHandle( HandleType handle, + SharedHandle> parent, + SharedHandle::type> pool, + const Dispatcher & dispatch VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) VULKAN_HPP_NOEXCEPT + : BaseType( handle, std::move( parent ), DeleterType{ std::move( pool ), dispatch } ) + { + } + template ::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::DestructorType; + using PoolTypeExport = PoolType; + template using ReturnType = decltype( std::declval().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 ); }