• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015-2025 The Khronos Group Inc.
2 //
3 // SPDX-License-Identifier: Apache-2.0 OR MIT
4 //
5 
6 // This header is generated from the Khronos Vulkan XML API Registry.
7 
8 #ifndef VULKAN_SHARED_HPP
9 #define VULKAN_SHARED_HPP
10 
11 #include <vulkan/vulkan.hpp>
12 
13 #if !( defined( VULKAN_HPP_ENABLE_STD_MODULE ) && defined( VULKAN_HPP_STD_MODULE ) )
14 #  include <atomic>  // std::atomic_size_t
15 #endif
16 
17 namespace VULKAN_HPP_NAMESPACE
18 {
19 #if !defined( VULKAN_HPP_NO_SMART_HANDLE )
20 
21   template <typename HandleType>
22   class SharedHandleTraits;
23 
24   class NoDestructor
25   {
26   };
27 
28   template <typename HandleType, typename = void>
29   struct HasDestructorType : std::false_type
30   {
31   };
32 
33   template <typename HandleType>
34   struct HasDestructorType<HandleType, decltype( (void)typename SharedHandleTraits<HandleType>::DestructorType() )> : std::true_type
35   {
36   };
37 
38   template <typename HandleType, typename Enable = void>
39   struct GetDestructorType
40   {
41     using type = NoDestructor;
42   };
43 
44   template <typename HandleType>
45   struct GetDestructorType<HandleType, typename std::enable_if<HasDestructorType<HandleType>::value>::type>
46   {
47     using type = typename SharedHandleTraits<HandleType>::DestructorType;
48   };
49 
50   template <class HandleType>
51   using DestructorTypeOf = typename GetDestructorType<HandleType>::type;
52 
53   template <class HandleType>
54   struct HasDestructor : std::integral_constant<bool, !std::is_same<DestructorTypeOf<HandleType>, NoDestructor>::value>
55   {
56   };
57 
58   template <typename HandleType, typename = void>
59   struct HasPoolType : std::false_type
60   {
61   };
62 
63   template <typename HandleType>
64   struct HasPoolType<HandleType, decltype( (void)typename SharedHandleTraits<HandleType>::deleter::PoolTypeExport() )> : std::true_type
65   {
66   };
67 
68   template <typename HandleType, typename Enable = void>
69   struct GetPoolType
70   {
71     using type = NoDestructor;
72   };
73 
74   template <typename HandleType>
75   struct GetPoolType<HandleType, typename std::enable_if<HasPoolType<HandleType>::value>::type>
76   {
77     using type = typename SharedHandleTraits<HandleType>::deleter::PoolTypeExport;
78   };
79 
80   //=====================================================================================================================
81 
82   template <typename HandleType>
83   class SharedHandle;
84 
85   template <typename DestructorType, typename Deleter>
86   struct SharedHeader
87   {
SharedHeaderVULKAN_HPP_NAMESPACE::SharedHeader88     SharedHeader( SharedHandle<DestructorType> parent, Deleter deleter = Deleter() ) VULKAN_HPP_NOEXCEPT
89       : parent( std::move( parent ) )
90       , deleter( std::move( deleter ) )
91     {
92     }
93 
94     SharedHandle<DestructorType> parent;
95     Deleter                      deleter;
96   };
97 
98   template <typename Deleter>
99   struct SharedHeader<NoDestructor, Deleter>
100   {
SharedHeaderVULKAN_HPP_NAMESPACE::SharedHeader101     SharedHeader( Deleter deleter = Deleter() ) VULKAN_HPP_NOEXCEPT : deleter( std::move( deleter ) ) {}
102 
103     Deleter deleter;
104   };
105 
106   //=====================================================================================================================
107 
108   template <typename HeaderType>
109   class ReferenceCounter
110   {
111   public:
112     template <typename... Args>
ReferenceCounter(Args &&...control_args)113     ReferenceCounter( Args &&... control_args ) : m_header( std::forward<Args>( control_args )... )
114     {
115     }
116 
117     ReferenceCounter( const ReferenceCounter & )             = delete;
118     ReferenceCounter & operator=( const ReferenceCounter & ) = delete;
119 
120   public:
addRef()121     size_t addRef() VULKAN_HPP_NOEXCEPT
122     {
123       // Relaxed memory order is sufficient since this does not impose any ordering on other operations
124       return m_ref_cnt.fetch_add( 1, std::memory_order_relaxed );
125     }
126 
release()127     size_t release() VULKAN_HPP_NOEXCEPT
128     {
129       // A release memory order to ensure that all releases are ordered
130       return m_ref_cnt.fetch_sub( 1, std::memory_order_release );
131     }
132 
133   public:
134     std::atomic_size_t m_ref_cnt{ 1 };
135     HeaderType         m_header{};
136   };
137 
138   //=====================================================================================================================
139 
140   template <typename HandleType, typename HeaderType, typename ForwardType = SharedHandle<HandleType>>
141   class SharedHandleBase
142   {
143   public:
144     SharedHandleBase() = default;
145 
146     template <typename... Args>
SharedHandleBase(HandleType handle,Args &&...control_args)147     SharedHandleBase( HandleType handle, Args &&... control_args )
148       : m_control( new ReferenceCounter<HeaderType>( std::forward<Args>( control_args )... ) ), m_handle( handle )
149     {
150     }
151 
SharedHandleBase(const SharedHandleBase & o)152     SharedHandleBase( const SharedHandleBase & o ) VULKAN_HPP_NOEXCEPT
153     {
154       o.addRef();
155       m_handle  = o.m_handle;
156       m_control = o.m_control;
157     }
158 
SharedHandleBase(SharedHandleBase && o)159     SharedHandleBase( SharedHandleBase && o ) VULKAN_HPP_NOEXCEPT
160       : m_control( o.m_control )
161       , m_handle( o.m_handle )
162     {
163       o.m_handle  = nullptr;
164       o.m_control = nullptr;
165     }
166 
operator =(const SharedHandleBase & o)167     SharedHandleBase & operator=( const SharedHandleBase & o ) VULKAN_HPP_NOEXCEPT
168     {
169       SharedHandleBase( o ).swap( *this );
170       return *this;
171     }
172 
operator =(SharedHandleBase && o)173     SharedHandleBase & operator=( SharedHandleBase && o ) VULKAN_HPP_NOEXCEPT
174     {
175       SharedHandleBase( std::move( o ) ).swap( *this );
176       return *this;
177     }
178 
~SharedHandleBase()179     ~SharedHandleBase()
180     {
181       // only this function owns the last reference to the control block
182       // the same principle is used in the default deleter of std::shared_ptr
183       if ( m_control && ( m_control->release() == 1 ) )
184       {
185         // noop in x86, but does thread synchronization in ARM
186         // it is required to ensure that last thread is getting to destroy the control block
187         // by ordering all atomic operations before this fence
188         std::atomic_thread_fence( std::memory_order_acquire );
189         ForwardType::internalDestroy( getHeader(), m_handle );
190         delete m_control;
191       }
192     }
193 
194   public:
get() const195     HandleType get() const VULKAN_HPP_NOEXCEPT
196     {
197       return m_handle;
198     }
199 
operator *() const200     HandleType operator*() const VULKAN_HPP_NOEXCEPT
201     {
202       return m_handle;
203     }
204 
operator bool() const205     explicit operator bool() const VULKAN_HPP_NOEXCEPT
206     {
207       return bool( m_handle );
208     }
209 
210 #  if defined( VULKAN_HPP_SMART_HANDLE_IMPLICIT_CAST )
operator HandleType() const211     operator HandleType() const VULKAN_HPP_NOEXCEPT
212     {
213       return m_handle;
214     }
215 #  endif
216 
operator ->() const217     const HandleType * operator->() const VULKAN_HPP_NOEXCEPT
218     {
219       return &m_handle;
220     }
221 
operator ->()222     HandleType * operator->() VULKAN_HPP_NOEXCEPT
223     {
224       return &m_handle;
225     }
226 
reset()227     void reset() VULKAN_HPP_NOEXCEPT
228     {
229       SharedHandleBase().swap( *this );
230     }
231 
swap(SharedHandleBase & o)232     void swap( SharedHandleBase & o ) VULKAN_HPP_NOEXCEPT
233     {
234       std::swap( m_handle, o.m_handle );
235       std::swap( m_control, o.m_control );
236     }
237 
238     template <typename T = HandleType>
getDestructorType() const239     typename std::enable_if<HasDestructor<T>::value, const SharedHandle<DestructorTypeOf<HandleType>> &>::type getDestructorType() const VULKAN_HPP_NOEXCEPT
240     {
241       return getHeader().parent;
242     }
243 
244   protected:
245     template <typename T = HandleType>
internalDestroy(const HeaderType & control,HandleType handle)246     static typename std::enable_if<!HasDestructor<T>::value, void>::type internalDestroy( const HeaderType & control, HandleType handle ) VULKAN_HPP_NOEXCEPT
247     {
248       control.deleter.destroy( handle );
249     }
250 
251     template <typename T = HandleType>
internalDestroy(const HeaderType & control,HandleType handle)252     static typename std::enable_if<HasDestructor<T>::value, void>::type internalDestroy( const HeaderType & control, HandleType handle ) VULKAN_HPP_NOEXCEPT
253     {
254       control.deleter.destroy( control.parent.get(), handle );
255     }
256 
getHeader() const257     const HeaderType & getHeader() const VULKAN_HPP_NOEXCEPT
258     {
259       return m_control->m_header;
260     }
261 
262   private:
addRef() const263     void addRef() const VULKAN_HPP_NOEXCEPT
264     {
265       if ( m_control )
266         m_control->addRef();
267     }
268 
269   protected:
270     ReferenceCounter<HeaderType> * m_control = nullptr;
271     HandleType                     m_handle{};
272   };
273 
274   template <typename HandleType>
275   class SharedHandle : public SharedHandleBase<HandleType, SharedHeader<DestructorTypeOf<HandleType>, typename SharedHandleTraits<HandleType>::deleter>>
276   {
277   private:
278     using BaseType    = SharedHandleBase<HandleType, SharedHeader<DestructorTypeOf<HandleType>, typename SharedHandleTraits<HandleType>::deleter>>;
279     using DeleterType = typename SharedHandleTraits<HandleType>::deleter;
280     friend BaseType;
281 
282   public:
283     SharedHandle() = default;
284 
285     template <typename T = HandleType, typename = typename std::enable_if<HasDestructor<T>::value && !HasPoolType<T>::value>::type>
SharedHandle(HandleType handle,SharedHandle<DestructorTypeOf<HandleType>> parent,DeleterType deleter=DeleterType ())286     explicit SharedHandle( HandleType handle, SharedHandle<DestructorTypeOf<HandleType>> parent, DeleterType deleter = DeleterType() ) VULKAN_HPP_NOEXCEPT
287       : BaseType( handle, std::move( parent ), std::move( deleter ) )
288     {
289     }
290 
291     template <typename Dispatcher = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE,
292               typename T          = HandleType,
293               typename            = typename std::enable_if<HasDestructor<T>::value && HasPoolType<T>::value>::type>
SharedHandle(HandleType handle,SharedHandle<DestructorTypeOf<HandleType>> parent,SharedHandle<typename GetPoolType<HandleType>::type> pool,const Dispatcher & dispatch VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT)294     explicit SharedHandle( HandleType                                           handle,
295                            SharedHandle<DestructorTypeOf<HandleType>>           parent,
296                            SharedHandle<typename GetPoolType<HandleType>::type> pool,
297                            const Dispatcher & dispatch                          VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) VULKAN_HPP_NOEXCEPT
298       : BaseType( handle, std::move( parent ), DeleterType{ std::move( pool ), dispatch } )
299     {
300     }
301 
302     template <typename T = HandleType, typename = typename std::enable_if<!HasDestructor<T>::value>::type>
SharedHandle(HandleType handle,DeleterType deleter=DeleterType ())303     explicit SharedHandle( HandleType handle, DeleterType deleter = DeleterType() ) VULKAN_HPP_NOEXCEPT : BaseType( handle, std::move( deleter ) )
304     {
305     }
306 
307   protected:
308     using BaseType::internalDestroy;
309   };
310 
311   namespace detail
312   {
313 
314 // Silence the function cast warnings.
315 #  if defined( __GNUC__ ) && !defined( __clang__ ) && !defined( __INTEL_COMPILER )
316 #    pragma GCC diagnostic push
317 #    pragma GCC diagnostic ignored "-Wcast-function-type"
318 #  elif defined( __clang__ ) && ( __clang_major__ >= 13 ) && !defined( __INTEL_COMPILER )
319 #    pragma clang diagnostic push
320 #    pragma clang diagnostic ignored "-Wcast-function-type"
321 #  endif
322 
323     template <typename HandleType>
324     class ObjectDestroyShared
325     {
326     public:
327       using DestructorType = typename SharedHandleTraits<HandleType>::DestructorType;
328 
329       template <class Dispatcher>
330       using DestroyFunctionPointerType =
331         typename std::conditional<HasDestructor<HandleType>::value,
332                                   void ( DestructorType::* )( HandleType, const AllocationCallbacks *, const Dispatcher & ) const,
333                                   void ( HandleType::* )( const AllocationCallbacks *, const Dispatcher & ) const>::type;
334 
335       using SelectorType = typename std::conditional<HasDestructor<HandleType>::value, DestructorType, HandleType>::type;
336 
337       template <typename Dispatcher = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
ObjectDestroyShared(Optional<const AllocationCallbacks> allocationCallbacks VULKAN_HPP_DEFAULT_ARGUMENT_NULLPTR_ASSIGNMENT,const Dispatcher & dispatch VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT)338       ObjectDestroyShared( Optional<const AllocationCallbacks> allocationCallbacks VULKAN_HPP_DEFAULT_ARGUMENT_NULLPTR_ASSIGNMENT,
339                            const Dispatcher & dispatch                             VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT )
340         : m_destroy( reinterpret_cast<decltype( m_destroy )>( static_cast<DestroyFunctionPointerType<Dispatcher>>( &SelectorType::destroy ) ) )
341         , m_dispatch( &dispatch )
342         , m_allocationCallbacks( allocationCallbacks )
343       {
344       }
345 
346     public:
347       template <typename T = HandleType>
destroy(DestructorType parent,HandleType handle) const348       typename std::enable_if<HasDestructor<T>::value, void>::type destroy( DestructorType parent, HandleType handle ) const VULKAN_HPP_NOEXCEPT
349       {
350         VULKAN_HPP_ASSERT( m_destroy && m_dispatch );
351         ( parent.*m_destroy )( handle, m_allocationCallbacks, *m_dispatch );
352       }
353 
354       template <typename T = HandleType>
destroy(HandleType handle) const355       typename std::enable_if<!HasDestructor<T>::value, void>::type destroy( HandleType handle ) const VULKAN_HPP_NOEXCEPT
356       {
357         VULKAN_HPP_ASSERT( m_destroy && m_dispatch );
358         ( handle.*m_destroy )( m_allocationCallbacks, *m_dispatch );
359       }
360 
361     private:
362       DestroyFunctionPointerType<detail::DispatchLoaderBase> m_destroy             = nullptr;
363       const detail::DispatchLoaderBase *                     m_dispatch            = nullptr;
364       Optional<const AllocationCallbacks>                    m_allocationCallbacks = nullptr;
365     };
366 
367     template <typename HandleType>
368     class ObjectFreeShared
369     {
370     public:
371       using DestructorType = typename SharedHandleTraits<HandleType>::DestructorType;
372 
373       template <class Dispatcher>
374       using DestroyFunctionPointerType = void ( DestructorType::* )( HandleType, const AllocationCallbacks *, const Dispatcher & ) const;
375 
376       template <class Dispatcher = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
ObjectFreeShared(Optional<const AllocationCallbacks> allocationCallbacks VULKAN_HPP_DEFAULT_ARGUMENT_NULLPTR_ASSIGNMENT,const Dispatcher & dispatch VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT)377       ObjectFreeShared( Optional<const AllocationCallbacks> allocationCallbacks VULKAN_HPP_DEFAULT_ARGUMENT_NULLPTR_ASSIGNMENT,
378                         const Dispatcher & dispatch                             VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT )
379         : m_destroy( reinterpret_cast<decltype( m_destroy )>( static_cast<DestroyFunctionPointerType<Dispatcher>>( &DestructorType::free ) ) )
380         , m_dispatch( &dispatch )
381         , m_allocationCallbacks( allocationCallbacks )
382       {
383       }
384 
385     public:
destroy(DestructorType parent,HandleType handle) const386       void destroy( DestructorType parent, HandleType handle ) const VULKAN_HPP_NOEXCEPT
387       {
388         VULKAN_HPP_ASSERT( m_destroy && m_dispatch );
389         ( parent.*m_destroy )( handle, m_allocationCallbacks, *m_dispatch );
390       }
391 
392     private:
393       DestroyFunctionPointerType<detail::DispatchLoaderBase> m_destroy             = nullptr;
394       const detail::DispatchLoaderBase *                     m_dispatch            = nullptr;
395       Optional<const AllocationCallbacks>                    m_allocationCallbacks = nullptr;
396     };
397 
398     template <typename HandleType>
399     class ObjectReleaseShared
400     {
401     public:
402       using DestructorType = typename SharedHandleTraits<HandleType>::DestructorType;
403 
404       template <class Dispatcher>
405       using DestroyFunctionPointerType = void ( DestructorType::* )( HandleType, const Dispatcher & ) const;
406 
407       template <class Dispatcher = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
ObjectReleaseShared(const Dispatcher & dispatch VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT)408       ObjectReleaseShared( const Dispatcher & dispatch VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT )
409         : m_destroy( reinterpret_cast<decltype( m_destroy )>( static_cast<DestroyFunctionPointerType<Dispatcher>>( &DestructorType::release ) ) )
410         , m_dispatch( &dispatch )
411       {
412       }
413 
414     public:
destroy(DestructorType parent,HandleType handle) const415       void destroy( DestructorType parent, HandleType handle ) const VULKAN_HPP_NOEXCEPT
416       {
417         VULKAN_HPP_ASSERT( m_destroy && m_dispatch );
418         ( parent.*m_destroy )( handle, *m_dispatch );
419       }
420 
421     private:
422       DestroyFunctionPointerType<detail::DispatchLoaderBase> m_destroy  = nullptr;
423       const detail::DispatchLoaderBase *                     m_dispatch = nullptr;
424     };
425 
426     template <typename HandleType, typename PoolType>
427     class PoolFreeShared
428     {
429     public:
430       using DestructorType = typename SharedHandleTraits<HandleType>::DestructorType;
431 
432       using PoolTypeExport = PoolType;
433 
434       template <class Dispatcher>
435       using ReturnType = decltype( std::declval<DestructorType>().free( PoolType(), 0u, nullptr, Dispatcher() ) );
436 
437       template <class Dispatcher>
438       using DestroyFunctionPointerType = ReturnType<Dispatcher> ( DestructorType::* )( PoolType, uint32_t, const HandleType *, const Dispatcher & ) const;
439 
440       PoolFreeShared() = default;
441 
442       template <class Dispatcher = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
PoolFreeShared(SharedHandle<PoolType> pool,const Dispatcher & dispatch VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT)443       PoolFreeShared( SharedHandle<PoolType> pool, const Dispatcher & dispatch VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT )
444         : m_destroy( reinterpret_cast<decltype( m_destroy )>( static_cast<DestroyFunctionPointerType<Dispatcher>>( &DestructorType::free ) ) )
445         , m_dispatch( &dispatch )
446         , m_pool( std::move( pool ) )
447       {
448       }
449 
450     public:
destroy(DestructorType parent,HandleType handle) const451       void destroy( DestructorType parent, HandleType handle ) const VULKAN_HPP_NOEXCEPT
452       {
453         VULKAN_HPP_ASSERT( m_destroy && m_dispatch && m_pool );
454         ( parent.*m_destroy )( m_pool.get(), 1u, &handle, *m_dispatch );
455       }
456 
457     private:
458       DestroyFunctionPointerType<detail::DispatchLoaderBase> m_destroy  = nullptr;
459       const detail::DispatchLoaderBase *                     m_dispatch = nullptr;
460       SharedHandle<PoolType>                                 m_pool{};
461     };
462 
463 #  if defined( __GNUC__ ) && !defined( __clang__ ) && !defined( __INTEL_COMPILER )
464 #    pragma GCC diagnostic pop
465 #  elif defined( __clang__ ) && ( __clang_major__ >= 13 ) && !defined( __INTEL_COMPILER )
466 #    pragma clang diagnostic pop
467 #  endif
468 
469   }  // namespace detail
470 
471   //======================
472   //=== SHARED HANDLEs ===
473   //======================
474 
475   //=== VK_VERSION_1_0 ===
476   template <>
477   class SharedHandleTraits<Instance>
478   {
479   public:
480     using DestructorType = NoDestructor;
481     using deleter        = detail::ObjectDestroyShared<Instance>;
482   };
483 
484   using SharedInstance = SharedHandle<Instance>;
485 
486   template <>
487   class SharedHandleTraits<Device>
488   {
489   public:
490     using DestructorType = NoDestructor;
491     using deleter        = detail::ObjectDestroyShared<Device>;
492   };
493 
494   using SharedDevice = SharedHandle<Device>;
495 
496   template <>
497   class SharedHandleTraits<DeviceMemory>
498   {
499   public:
500     using DestructorType = Device;
501     using deleter        = detail::ObjectFreeShared<DeviceMemory>;
502   };
503 
504   using SharedDeviceMemory = SharedHandle<DeviceMemory>;
505 
506   template <>
507   class SharedHandleTraits<Fence>
508   {
509   public:
510     using DestructorType = Device;
511     using deleter        = detail::ObjectDestroyShared<Fence>;
512   };
513 
514   using SharedFence = SharedHandle<Fence>;
515 
516   template <>
517   class SharedHandleTraits<Semaphore>
518   {
519   public:
520     using DestructorType = Device;
521     using deleter        = detail::ObjectDestroyShared<Semaphore>;
522   };
523 
524   using SharedSemaphore = SharedHandle<Semaphore>;
525 
526   template <>
527   class SharedHandleTraits<Event>
528   {
529   public:
530     using DestructorType = Device;
531     using deleter        = detail::ObjectDestroyShared<Event>;
532   };
533 
534   using SharedEvent = SharedHandle<Event>;
535 
536   template <>
537   class SharedHandleTraits<QueryPool>
538   {
539   public:
540     using DestructorType = Device;
541     using deleter        = detail::ObjectDestroyShared<QueryPool>;
542   };
543 
544   using SharedQueryPool = SharedHandle<QueryPool>;
545 
546   template <>
547   class SharedHandleTraits<Buffer>
548   {
549   public:
550     using DestructorType = Device;
551     using deleter        = detail::ObjectDestroyShared<Buffer>;
552   };
553 
554   using SharedBuffer = SharedHandle<Buffer>;
555 
556   template <>
557   class SharedHandleTraits<BufferView>
558   {
559   public:
560     using DestructorType = Device;
561     using deleter        = detail::ObjectDestroyShared<BufferView>;
562   };
563 
564   using SharedBufferView = SharedHandle<BufferView>;
565 
566   template <>
567   class SharedHandleTraits<Image>
568   {
569   public:
570     using DestructorType = Device;
571     using deleter        = detail::ObjectDestroyShared<Image>;
572   };
573 
574   using SharedImage = SharedHandle<Image>;
575 
576   template <>
577   class SharedHandleTraits<ImageView>
578   {
579   public:
580     using DestructorType = Device;
581     using deleter        = detail::ObjectDestroyShared<ImageView>;
582   };
583 
584   using SharedImageView = SharedHandle<ImageView>;
585 
586   template <>
587   class SharedHandleTraits<ShaderModule>
588   {
589   public:
590     using DestructorType = Device;
591     using deleter        = detail::ObjectDestroyShared<ShaderModule>;
592   };
593 
594   using SharedShaderModule = SharedHandle<ShaderModule>;
595 
596   template <>
597   class SharedHandleTraits<PipelineCache>
598   {
599   public:
600     using DestructorType = Device;
601     using deleter        = detail::ObjectDestroyShared<PipelineCache>;
602   };
603 
604   using SharedPipelineCache = SharedHandle<PipelineCache>;
605 
606   template <>
607   class SharedHandleTraits<Pipeline>
608   {
609   public:
610     using DestructorType = Device;
611     using deleter        = detail::ObjectDestroyShared<Pipeline>;
612   };
613 
614   using SharedPipeline = SharedHandle<Pipeline>;
615 
616   template <>
617   class SharedHandleTraits<PipelineLayout>
618   {
619   public:
620     using DestructorType = Device;
621     using deleter        = detail::ObjectDestroyShared<PipelineLayout>;
622   };
623 
624   using SharedPipelineLayout = SharedHandle<PipelineLayout>;
625 
626   template <>
627   class SharedHandleTraits<Sampler>
628   {
629   public:
630     using DestructorType = Device;
631     using deleter        = detail::ObjectDestroyShared<Sampler>;
632   };
633 
634   using SharedSampler = SharedHandle<Sampler>;
635 
636   template <>
637   class SharedHandleTraits<DescriptorPool>
638   {
639   public:
640     using DestructorType = Device;
641     using deleter        = detail::ObjectDestroyShared<DescriptorPool>;
642   };
643 
644   using SharedDescriptorPool = SharedHandle<DescriptorPool>;
645 
646   template <>
647   class SharedHandleTraits<DescriptorSet>
648   {
649   public:
650     using DestructorType = Device;
651     using deleter        = detail::PoolFreeShared<DescriptorSet, DescriptorPool>;
652   };
653 
654   using SharedDescriptorSet = SharedHandle<DescriptorSet>;
655 
656   template <>
657   class SharedHandleTraits<DescriptorSetLayout>
658   {
659   public:
660     using DestructorType = Device;
661     using deleter        = detail::ObjectDestroyShared<DescriptorSetLayout>;
662   };
663 
664   using SharedDescriptorSetLayout = SharedHandle<DescriptorSetLayout>;
665 
666   template <>
667   class SharedHandleTraits<Framebuffer>
668   {
669   public:
670     using DestructorType = Device;
671     using deleter        = detail::ObjectDestroyShared<Framebuffer>;
672   };
673 
674   using SharedFramebuffer = SharedHandle<Framebuffer>;
675 
676   template <>
677   class SharedHandleTraits<RenderPass>
678   {
679   public:
680     using DestructorType = Device;
681     using deleter        = detail::ObjectDestroyShared<RenderPass>;
682   };
683 
684   using SharedRenderPass = SharedHandle<RenderPass>;
685 
686   template <>
687   class SharedHandleTraits<CommandPool>
688   {
689   public:
690     using DestructorType = Device;
691     using deleter        = detail::ObjectDestroyShared<CommandPool>;
692   };
693 
694   using SharedCommandPool = SharedHandle<CommandPool>;
695 
696   template <>
697   class SharedHandleTraits<CommandBuffer>
698   {
699   public:
700     using DestructorType = Device;
701     using deleter        = detail::PoolFreeShared<CommandBuffer, CommandPool>;
702   };
703 
704   using SharedCommandBuffer = SharedHandle<CommandBuffer>;
705 
706   //=== VK_VERSION_1_1 ===
707   template <>
708   class SharedHandleTraits<SamplerYcbcrConversion>
709   {
710   public:
711     using DestructorType = Device;
712     using deleter        = detail::ObjectDestroyShared<SamplerYcbcrConversion>;
713   };
714 
715   using SharedSamplerYcbcrConversion    = SharedHandle<SamplerYcbcrConversion>;
716   using SharedSamplerYcbcrConversionKHR = SharedHandle<SamplerYcbcrConversion>;
717 
718   template <>
719   class SharedHandleTraits<DescriptorUpdateTemplate>
720   {
721   public:
722     using DestructorType = Device;
723     using deleter        = detail::ObjectDestroyShared<DescriptorUpdateTemplate>;
724   };
725 
726   using SharedDescriptorUpdateTemplate    = SharedHandle<DescriptorUpdateTemplate>;
727   using SharedDescriptorUpdateTemplateKHR = SharedHandle<DescriptorUpdateTemplate>;
728 
729   //=== VK_VERSION_1_3 ===
730   template <>
731   class SharedHandleTraits<PrivateDataSlot>
732   {
733   public:
734     using DestructorType = Device;
735     using deleter        = detail::ObjectDestroyShared<PrivateDataSlot>;
736   };
737 
738   using SharedPrivateDataSlot    = SharedHandle<PrivateDataSlot>;
739   using SharedPrivateDataSlotEXT = SharedHandle<PrivateDataSlot>;
740 
741   //=== VK_KHR_surface ===
742   template <>
743   class SharedHandleTraits<SurfaceKHR>
744   {
745   public:
746     using DestructorType = Instance;
747     using deleter        = detail::ObjectDestroyShared<SurfaceKHR>;
748   };
749 
750   using SharedSurfaceKHR = SharedHandle<SurfaceKHR>;
751 
752   //=== VK_KHR_swapchain ===
753   template <>
754   class SharedHandleTraits<SwapchainKHR>
755   {
756   public:
757     using DestructorType = Device;
758     using deleter        = detail::ObjectDestroyShared<SwapchainKHR>;
759   };
760 
761   using SharedSwapchainKHR = SharedHandle<SwapchainKHR>;
762 
763   //=== VK_KHR_display ===
764   template <>
765   class SharedHandleTraits<DisplayKHR>
766   {
767   public:
768     using DestructorType = PhysicalDevice;
769     using deleter        = detail::ObjectDestroyShared<DisplayKHR>;
770   };
771 
772   using SharedDisplayKHR = SharedHandle<DisplayKHR>;
773 
774   //=== VK_EXT_debug_report ===
775   template <>
776   class SharedHandleTraits<DebugReportCallbackEXT>
777   {
778   public:
779     using DestructorType = Instance;
780     using deleter        = detail::ObjectDestroyShared<DebugReportCallbackEXT>;
781   };
782 
783   using SharedDebugReportCallbackEXT = SharedHandle<DebugReportCallbackEXT>;
784 
785   //=== VK_KHR_video_queue ===
786   template <>
787   class SharedHandleTraits<VideoSessionKHR>
788   {
789   public:
790     using DestructorType = Device;
791     using deleter        = detail::ObjectDestroyShared<VideoSessionKHR>;
792   };
793 
794   using SharedVideoSessionKHR = SharedHandle<VideoSessionKHR>;
795 
796   template <>
797   class SharedHandleTraits<VideoSessionParametersKHR>
798   {
799   public:
800     using DestructorType = Device;
801     using deleter        = detail::ObjectDestroyShared<VideoSessionParametersKHR>;
802   };
803 
804   using SharedVideoSessionParametersKHR = SharedHandle<VideoSessionParametersKHR>;
805 
806   //=== VK_NVX_binary_import ===
807   template <>
808   class SharedHandleTraits<CuModuleNVX>
809   {
810   public:
811     using DestructorType = Device;
812     using deleter        = detail::ObjectDestroyShared<CuModuleNVX>;
813   };
814 
815   using SharedCuModuleNVX = SharedHandle<CuModuleNVX>;
816 
817   template <>
818   class SharedHandleTraits<CuFunctionNVX>
819   {
820   public:
821     using DestructorType = Device;
822     using deleter        = detail::ObjectDestroyShared<CuFunctionNVX>;
823   };
824 
825   using SharedCuFunctionNVX = SharedHandle<CuFunctionNVX>;
826 
827   //=== VK_EXT_debug_utils ===
828   template <>
829   class SharedHandleTraits<DebugUtilsMessengerEXT>
830   {
831   public:
832     using DestructorType = Instance;
833     using deleter        = detail::ObjectDestroyShared<DebugUtilsMessengerEXT>;
834   };
835 
836   using SharedDebugUtilsMessengerEXT = SharedHandle<DebugUtilsMessengerEXT>;
837 
838   //=== VK_KHR_acceleration_structure ===
839   template <>
840   class SharedHandleTraits<AccelerationStructureKHR>
841   {
842   public:
843     using DestructorType = Device;
844     using deleter        = detail::ObjectDestroyShared<AccelerationStructureKHR>;
845   };
846 
847   using SharedAccelerationStructureKHR = SharedHandle<AccelerationStructureKHR>;
848 
849   //=== VK_EXT_validation_cache ===
850   template <>
851   class SharedHandleTraits<ValidationCacheEXT>
852   {
853   public:
854     using DestructorType = Device;
855     using deleter        = detail::ObjectDestroyShared<ValidationCacheEXT>;
856   };
857 
858   using SharedValidationCacheEXT = SharedHandle<ValidationCacheEXT>;
859 
860   //=== VK_NV_ray_tracing ===
861   template <>
862   class SharedHandleTraits<AccelerationStructureNV>
863   {
864   public:
865     using DestructorType = Device;
866     using deleter        = detail::ObjectDestroyShared<AccelerationStructureNV>;
867   };
868 
869   using SharedAccelerationStructureNV = SharedHandle<AccelerationStructureNV>;
870 
871   //=== VK_INTEL_performance_query ===
872   template <>
873   class SharedHandleTraits<PerformanceConfigurationINTEL>
874   {
875   public:
876     using DestructorType = Device;
877     using deleter        = detail::ObjectDestroyShared<PerformanceConfigurationINTEL>;
878   };
879 
880   using SharedPerformanceConfigurationINTEL = SharedHandle<PerformanceConfigurationINTEL>;
881 
882   //=== VK_KHR_deferred_host_operations ===
883   template <>
884   class SharedHandleTraits<DeferredOperationKHR>
885   {
886   public:
887     using DestructorType = Device;
888     using deleter        = detail::ObjectDestroyShared<DeferredOperationKHR>;
889   };
890 
891   using SharedDeferredOperationKHR = SharedHandle<DeferredOperationKHR>;
892 
893   //=== VK_NV_device_generated_commands ===
894   template <>
895   class SharedHandleTraits<IndirectCommandsLayoutNV>
896   {
897   public:
898     using DestructorType = Device;
899     using deleter        = detail::ObjectDestroyShared<IndirectCommandsLayoutNV>;
900   };
901 
902   using SharedIndirectCommandsLayoutNV = SharedHandle<IndirectCommandsLayoutNV>;
903 
904 #  if defined( VK_ENABLE_BETA_EXTENSIONS )
905   //=== VK_NV_cuda_kernel_launch ===
906   template <>
907   class SharedHandleTraits<CudaModuleNV>
908   {
909   public:
910     using DestructorType = Device;
911     using deleter        = detail::ObjectDestroyShared<CudaModuleNV>;
912   };
913 
914   using SharedCudaModuleNV = SharedHandle<CudaModuleNV>;
915 
916   template <>
917   class SharedHandleTraits<CudaFunctionNV>
918   {
919   public:
920     using DestructorType = Device;
921     using deleter        = detail::ObjectDestroyShared<CudaFunctionNV>;
922   };
923 
924   using SharedCudaFunctionNV = SharedHandle<CudaFunctionNV>;
925 #  endif /*VK_ENABLE_BETA_EXTENSIONS*/
926 
927 #  if defined( VK_USE_PLATFORM_FUCHSIA )
928   //=== VK_FUCHSIA_buffer_collection ===
929   template <>
930   class SharedHandleTraits<BufferCollectionFUCHSIA>
931   {
932   public:
933     using DestructorType = Device;
934     using deleter        = detail::ObjectDestroyShared<BufferCollectionFUCHSIA>;
935   };
936 
937   using SharedBufferCollectionFUCHSIA = SharedHandle<BufferCollectionFUCHSIA>;
938 #  endif /*VK_USE_PLATFORM_FUCHSIA*/
939 
940   //=== VK_EXT_opacity_micromap ===
941   template <>
942   class SharedHandleTraits<MicromapEXT>
943   {
944   public:
945     using DestructorType = Device;
946     using deleter        = detail::ObjectDestroyShared<MicromapEXT>;
947   };
948 
949   using SharedMicromapEXT = SharedHandle<MicromapEXT>;
950 
951   //=== VK_NV_optical_flow ===
952   template <>
953   class SharedHandleTraits<OpticalFlowSessionNV>
954   {
955   public:
956     using DestructorType = Device;
957     using deleter        = detail::ObjectDestroyShared<OpticalFlowSessionNV>;
958   };
959 
960   using SharedOpticalFlowSessionNV = SharedHandle<OpticalFlowSessionNV>;
961 
962   //=== VK_EXT_shader_object ===
963   template <>
964   class SharedHandleTraits<ShaderEXT>
965   {
966   public:
967     using DestructorType = Device;
968     using deleter        = detail::ObjectDestroyShared<ShaderEXT>;
969   };
970 
971   using SharedShaderEXT = SharedHandle<ShaderEXT>;
972 
973   //=== VK_KHR_pipeline_binary ===
974   template <>
975   class SharedHandleTraits<PipelineBinaryKHR>
976   {
977   public:
978     using DestructorType = Device;
979     using deleter        = detail::ObjectDestroyShared<PipelineBinaryKHR>;
980   };
981 
982   using SharedPipelineBinaryKHR = SharedHandle<PipelineBinaryKHR>;
983 
984   //=== VK_EXT_device_generated_commands ===
985   template <>
986   class SharedHandleTraits<IndirectCommandsLayoutEXT>
987   {
988   public:
989     using DestructorType = Device;
990     using deleter        = detail::ObjectDestroyShared<IndirectCommandsLayoutEXT>;
991   };
992 
993   using SharedIndirectCommandsLayoutEXT = SharedHandle<IndirectCommandsLayoutEXT>;
994 
995   template <>
996   class SharedHandleTraits<IndirectExecutionSetEXT>
997   {
998   public:
999     using DestructorType = Device;
1000     using deleter        = detail::ObjectDestroyShared<IndirectExecutionSetEXT>;
1001   };
1002 
1003   using SharedIndirectExecutionSetEXT = SharedHandle<IndirectExecutionSetEXT>;
1004 
1005   enum class SwapchainOwns
1006   {
1007     no,
1008     yes,
1009   };
1010 
1011   struct ImageHeader : SharedHeader<DestructorTypeOf<VULKAN_HPP_NAMESPACE::Image>, typename SharedHandleTraits<VULKAN_HPP_NAMESPACE::Image>::deleter>
1012   {
ImageHeaderVULKAN_HPP_NAMESPACE::ImageHeader1013     ImageHeader(
1014       SharedHandle<DestructorTypeOf<VULKAN_HPP_NAMESPACE::Image>>       parent,
1015       typename SharedHandleTraits<VULKAN_HPP_NAMESPACE::Image>::deleter deleter        = typename SharedHandleTraits<VULKAN_HPP_NAMESPACE::Image>::deleter(),
1016       SwapchainOwns                                                     swapchainOwned = SwapchainOwns::no ) VULKAN_HPP_NOEXCEPT
1017       : SharedHeader<DestructorTypeOf<VULKAN_HPP_NAMESPACE::Image>, typename SharedHandleTraits<VULKAN_HPP_NAMESPACE::Image>::deleter>( std::move( parent ),
1018                                                                                                                                         std::move( deleter ) )
1019       , swapchainOwned( swapchainOwned )
1020     {
1021     }
1022 
1023     SwapchainOwns swapchainOwned = SwapchainOwns::no;
1024   };
1025 
1026   template <>
1027   class SharedHandle<VULKAN_HPP_NAMESPACE::Image> : public SharedHandleBase<VULKAN_HPP_NAMESPACE::Image, ImageHeader>
1028   {
1029     using BaseType    = SharedHandleBase<VULKAN_HPP_NAMESPACE::Image, ImageHeader>;
1030     using DeleterType = typename SharedHandleTraits<VULKAN_HPP_NAMESPACE::Image>::deleter;
1031     friend BaseType;
1032 
1033   public:
1034     SharedHandle() = default;
1035 
SharedHandle(VULKAN_HPP_NAMESPACE::Image handle,SharedHandle<DestructorTypeOf<VULKAN_HPP_NAMESPACE::Image>> parent,SwapchainOwns swapchain_owned=SwapchainOwns::no,DeleterType deleter=DeleterType ())1036     explicit SharedHandle( VULKAN_HPP_NAMESPACE::Image                                 handle,
1037                            SharedHandle<DestructorTypeOf<VULKAN_HPP_NAMESPACE::Image>> parent,
1038                            SwapchainOwns                                               swapchain_owned = SwapchainOwns::no,
1039                            DeleterType                                                 deleter         = DeleterType() ) VULKAN_HPP_NOEXCEPT
1040       : BaseType( handle, std::move( parent ), std::move( deleter ), swapchain_owned )
1041     {
1042     }
1043 
1044   protected:
internalDestroy(const ImageHeader & control,VULKAN_HPP_NAMESPACE::Image handle)1045     static void internalDestroy( const ImageHeader & control, VULKAN_HPP_NAMESPACE::Image handle ) VULKAN_HPP_NOEXCEPT
1046     {
1047       if ( control.swapchainOwned == SwapchainOwns::no )
1048       {
1049         control.deleter.destroy( control.parent.get(), handle );
1050       }
1051     }
1052   };
1053 
1054   struct SwapchainHeader
1055   {
SwapchainHeaderVULKAN_HPP_NAMESPACE::SwapchainHeader1056     SwapchainHeader( SharedHandle<VULKAN_HPP_NAMESPACE::SurfaceKHR>                           surface,
1057                      SharedHandle<DestructorTypeOf<VULKAN_HPP_NAMESPACE::SwapchainKHR>>       parent,
1058                      typename SharedHandleTraits<VULKAN_HPP_NAMESPACE::SwapchainKHR>::deleter deleter =
1059                        typename SharedHandleTraits<VULKAN_HPP_NAMESPACE::SwapchainKHR>::deleter() ) VULKAN_HPP_NOEXCEPT
1060       : surface( std::move( surface ) )
1061       , parent( std::move( parent ) )
1062       , deleter( std::move( deleter ) )
1063     {
1064     }
1065 
1066     SharedHandle<VULKAN_HPP_NAMESPACE::SurfaceKHR>                           surface{};
1067     SharedHandle<DestructorTypeOf<VULKAN_HPP_NAMESPACE::SwapchainKHR>>       parent{};
1068     typename SharedHandleTraits<VULKAN_HPP_NAMESPACE::SwapchainKHR>::deleter deleter{};
1069   };
1070 
1071   template <>
1072   class SharedHandle<VULKAN_HPP_NAMESPACE::SwapchainKHR> : public SharedHandleBase<VULKAN_HPP_NAMESPACE::SwapchainKHR, SwapchainHeader>
1073   {
1074     using BaseType    = SharedHandleBase<VULKAN_HPP_NAMESPACE::SwapchainKHR, SwapchainHeader>;
1075     using DeleterType = typename SharedHandleTraits<VULKAN_HPP_NAMESPACE::SwapchainKHR>::deleter;
1076     friend BaseType;
1077 
1078   public:
1079     SharedHandle() = default;
1080 
SharedHandle(VULKAN_HPP_NAMESPACE::SwapchainKHR handle,SharedHandle<DestructorTypeOf<VULKAN_HPP_NAMESPACE::SwapchainKHR>> parent,SharedHandle<VULKAN_HPP_NAMESPACE::SurfaceKHR> surface,DeleterType deleter=DeleterType ())1081     explicit SharedHandle( VULKAN_HPP_NAMESPACE::SwapchainKHR                                 handle,
1082                            SharedHandle<DestructorTypeOf<VULKAN_HPP_NAMESPACE::SwapchainKHR>> parent,
1083                            SharedHandle<VULKAN_HPP_NAMESPACE::SurfaceKHR>                     surface,
1084                            DeleterType                                                        deleter = DeleterType() ) VULKAN_HPP_NOEXCEPT
1085       : BaseType( handle, std::move( surface ), std::move( parent ), std::move( deleter ) )
1086     {
1087     }
1088 
1089   public:
getSurface() const1090     const SharedHandle<VULKAN_HPP_NAMESPACE::SurfaceKHR> & getSurface() const VULKAN_HPP_NOEXCEPT
1091     {
1092       return getHeader().surface;
1093     }
1094 
1095   protected:
1096     using BaseType::internalDestroy;
1097   };
1098 
1099   template <typename HandleType, typename DestructorType>
1100   class SharedHandleBaseNoDestroy : public SharedHandleBase<HandleType, DestructorType>
1101   {
1102   public:
1103     using SharedHandleBase<HandleType, DestructorType>::SharedHandleBase;
1104 
getDestructorType() const1105     const DestructorType & getDestructorType() const VULKAN_HPP_NOEXCEPT
1106     {
1107       return SharedHandleBase<HandleType, DestructorType>::getHeader();
1108     }
1109 
1110   protected:
internalDestroy(const DestructorType &,HandleType)1111     static void internalDestroy( const DestructorType &, HandleType ) VULKAN_HPP_NOEXCEPT {}
1112   };
1113 
1114   //=== VK_VERSION_1_0 ===
1115 
1116   template <>
1117   class SharedHandle<PhysicalDevice> : public SharedHandleBaseNoDestroy<PhysicalDevice, SharedInstance>
1118   {
1119     friend SharedHandleBase<PhysicalDevice, SharedInstance>;
1120 
1121   public:
1122     SharedHandle() = default;
1123 
SharedHandle(PhysicalDevice handle,SharedInstance parent)1124     explicit SharedHandle( PhysicalDevice handle, SharedInstance parent ) noexcept
1125       : SharedHandleBaseNoDestroy<PhysicalDevice, SharedInstance>( handle, std::move( parent ) )
1126     {
1127     }
1128   };
1129 
1130   using SharedPhysicalDevice = SharedHandle<PhysicalDevice>;
1131 
1132   template <>
1133   class SharedHandle<Queue> : public SharedHandleBaseNoDestroy<Queue, SharedDevice>
1134   {
1135     friend SharedHandleBase<Queue, SharedDevice>;
1136 
1137   public:
1138     SharedHandle() = default;
1139 
SharedHandle(Queue handle,SharedDevice parent)1140     explicit SharedHandle( Queue handle, SharedDevice parent ) noexcept : SharedHandleBaseNoDestroy<Queue, SharedDevice>( handle, std::move( parent ) ) {}
1141   };
1142 
1143   using SharedQueue = SharedHandle<Queue>;
1144 
1145   //=== VK_KHR_display ===
1146 
1147   template <>
1148   class SharedHandle<DisplayModeKHR> : public SharedHandleBaseNoDestroy<DisplayModeKHR, SharedDisplayKHR>
1149   {
1150     friend SharedHandleBase<DisplayModeKHR, SharedDisplayKHR>;
1151 
1152   public:
1153     SharedHandle() = default;
1154 
SharedHandle(DisplayModeKHR handle,SharedDisplayKHR parent)1155     explicit SharedHandle( DisplayModeKHR handle, SharedDisplayKHR parent ) noexcept
1156       : SharedHandleBaseNoDestroy<DisplayModeKHR, SharedDisplayKHR>( handle, std::move( parent ) )
1157     {
1158     }
1159   };
1160 
1161   using SharedDisplayModeKHR = SharedHandle<DisplayModeKHR>;
1162 #endif  // !VULKAN_HPP_NO_SMART_HANDLE
1163 }  // namespace VULKAN_HPP_NAMESPACE
1164 #endif  // VULKAN_SHARED_HPP
1165