xref: /aosp_15_r20/external/vulkan-headers/include/vulkan/vulkan_shared.hpp (revision 902771965e4c6d39c75c62130a6a330c08b024db)
1 // Copyright 2015-2024 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   template <typename HandleType>
312   class SharedHandleTraits;
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 #  endif
319 
320   template <typename HandleType>
321   class ObjectDestroyShared
322   {
323   public:
324     using DestructorType = typename SharedHandleTraits<HandleType>::DestructorType;
325 
326     template <class Dispatcher>
327     using DestroyFunctionPointerType =
328       typename std::conditional<HasDestructor<HandleType>::value,
329                                 void ( DestructorType::* )( HandleType, const AllocationCallbacks *, const Dispatcher & ) const,
330                                 void ( HandleType::* )( const AllocationCallbacks *, const Dispatcher & ) const>::type;
331 
332     using SelectorType = typename std::conditional<HasDestructor<HandleType>::value, DestructorType, HandleType>::type;
333 
334     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)335     ObjectDestroyShared( Optional<const AllocationCallbacks> allocationCallbacks VULKAN_HPP_DEFAULT_ARGUMENT_NULLPTR_ASSIGNMENT,
336                          const Dispatcher & dispatch                             VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT )
337       : m_destroy( reinterpret_cast<decltype( m_destroy )>( static_cast<DestroyFunctionPointerType<Dispatcher>>( &SelectorType::destroy ) ) )
338       , m_dispatch( &dispatch )
339       , m_allocationCallbacks( allocationCallbacks )
340     {
341     }
342 
343   public:
344     template <typename T = HandleType>
destroy(DestructorType parent,HandleType handle) const345     typename std::enable_if<HasDestructor<T>::value, void>::type destroy( DestructorType parent, HandleType handle ) const VULKAN_HPP_NOEXCEPT
346     {
347       VULKAN_HPP_ASSERT( m_destroy && m_dispatch );
348       ( parent.*m_destroy )( handle, m_allocationCallbacks, *m_dispatch );
349     }
350 
351     template <typename T = HandleType>
destroy(HandleType handle) const352     typename std::enable_if<!HasDestructor<T>::value, void>::type destroy( HandleType handle ) const VULKAN_HPP_NOEXCEPT
353     {
354       VULKAN_HPP_ASSERT( m_destroy && m_dispatch );
355       ( handle.*m_destroy )( m_allocationCallbacks, *m_dispatch );
356     }
357 
358   private:
359     DestroyFunctionPointerType<DispatchLoaderBase> m_destroy             = nullptr;
360     const DispatchLoaderBase *                     m_dispatch            = nullptr;
361     Optional<const AllocationCallbacks>            m_allocationCallbacks = nullptr;
362   };
363 
364   template <typename HandleType>
365   class ObjectFreeShared
366   {
367   public:
368     using DestructorType = typename SharedHandleTraits<HandleType>::DestructorType;
369 
370     template <class Dispatcher>
371     using DestroyFunctionPointerType = void ( DestructorType::* )( HandleType, const AllocationCallbacks *, const Dispatcher & ) const;
372 
373     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)374     ObjectFreeShared( Optional<const AllocationCallbacks> allocationCallbacks VULKAN_HPP_DEFAULT_ARGUMENT_NULLPTR_ASSIGNMENT,
375                       const Dispatcher & dispatch                             VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT )
376       : m_destroy( reinterpret_cast<decltype( m_destroy )>( static_cast<DestroyFunctionPointerType<Dispatcher>>( &DestructorType::free ) ) )
377       , m_dispatch( &dispatch )
378       , m_allocationCallbacks( allocationCallbacks )
379     {
380     }
381 
382   public:
destroy(DestructorType parent,HandleType handle) const383     void destroy( DestructorType parent, HandleType handle ) const VULKAN_HPP_NOEXCEPT
384     {
385       VULKAN_HPP_ASSERT( m_destroy && m_dispatch );
386       ( parent.*m_destroy )( handle, m_allocationCallbacks, *m_dispatch );
387     }
388 
389   private:
390     DestroyFunctionPointerType<DispatchLoaderBase> m_destroy             = nullptr;
391     const DispatchLoaderBase *                     m_dispatch            = nullptr;
392     Optional<const AllocationCallbacks>            m_allocationCallbacks = nullptr;
393   };
394 
395   template <typename HandleType>
396   class ObjectReleaseShared
397   {
398   public:
399     using DestructorType = typename SharedHandleTraits<HandleType>::DestructorType;
400 
401     template <class Dispatcher>
402     using DestroyFunctionPointerType = void ( DestructorType::* )( HandleType, const Dispatcher & ) const;
403 
404     template <class Dispatcher = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
ObjectReleaseShared(const Dispatcher & dispatch VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT)405     ObjectReleaseShared( const Dispatcher & dispatch VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT )
406       : m_destroy( reinterpret_cast<decltype( m_destroy )>( static_cast<DestroyFunctionPointerType<Dispatcher>>( &DestructorType::release ) ) )
407       , m_dispatch( &dispatch )
408     {
409     }
410 
411   public:
destroy(DestructorType parent,HandleType handle) const412     void destroy( DestructorType parent, HandleType handle ) const VULKAN_HPP_NOEXCEPT
413     {
414       VULKAN_HPP_ASSERT( m_destroy && m_dispatch );
415       ( parent.*m_destroy )( handle, *m_dispatch );
416     }
417 
418   private:
419     DestroyFunctionPointerType<DispatchLoaderBase> m_destroy  = nullptr;
420     const DispatchLoaderBase *                     m_dispatch = nullptr;
421   };
422 
423   template <typename HandleType, typename PoolType>
424   class PoolFreeShared
425   {
426   public:
427     using DestructorType = typename SharedHandleTraits<HandleType>::DestructorType;
428 
429     using PoolTypeExport = PoolType;
430 
431     template <class Dispatcher>
432     using ReturnType = decltype( std::declval<DestructorType>().free( PoolType(), 0u, nullptr, Dispatcher() ) );
433 
434     template <class Dispatcher>
435     using DestroyFunctionPointerType = ReturnType<Dispatcher> ( DestructorType::* )( PoolType, uint32_t, const HandleType *, const Dispatcher & ) const;
436 
437     PoolFreeShared() = default;
438 
439     template <class Dispatcher = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
PoolFreeShared(SharedHandle<PoolType> pool,const Dispatcher & dispatch VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT)440     PoolFreeShared( SharedHandle<PoolType> pool, const Dispatcher & dispatch VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT )
441       : m_destroy( reinterpret_cast<decltype( m_destroy )>( static_cast<DestroyFunctionPointerType<Dispatcher>>( &DestructorType::free ) ) )
442       , m_dispatch( &dispatch )
443       , m_pool( std::move( pool ) )
444     {
445     }
446 
447   public:
destroy(DestructorType parent,HandleType handle) const448     void destroy( DestructorType parent, HandleType handle ) const VULKAN_HPP_NOEXCEPT
449     {
450       VULKAN_HPP_ASSERT( m_destroy && m_dispatch && m_pool );
451       ( parent.*m_destroy )( m_pool.get(), 1u, &handle, *m_dispatch );
452     }
453 
454   private:
455     DestroyFunctionPointerType<DispatchLoaderBase> m_destroy  = nullptr;
456     const DispatchLoaderBase *                     m_dispatch = nullptr;
457     SharedHandle<PoolType>                         m_pool{};
458   };
459 
460 #  if defined( __GNUC__ ) && !defined( __clang__ ) && !defined( __INTEL_COMPILER )
461 #    pragma GCC diagnostic pop
462 #  endif
463 
464   //======================
465   //=== SHARED HANDLEs ===
466   //======================
467 
468   //=== VK_VERSION_1_0 ===
469   template <>
470   class SharedHandleTraits<Instance>
471   {
472   public:
473     using DestructorType = NoDestructor;
474     using deleter        = ObjectDestroyShared<Instance>;
475   };
476 
477   using SharedInstance = SharedHandle<Instance>;
478 
479   template <>
480   class SharedHandleTraits<Device>
481   {
482   public:
483     using DestructorType = NoDestructor;
484     using deleter        = ObjectDestroyShared<Device>;
485   };
486 
487   using SharedDevice = SharedHandle<Device>;
488 
489   template <>
490   class SharedHandleTraits<DeviceMemory>
491   {
492   public:
493     using DestructorType = Device;
494     using deleter        = ObjectFreeShared<DeviceMemory>;
495   };
496 
497   using SharedDeviceMemory = SharedHandle<DeviceMemory>;
498 
499   template <>
500   class SharedHandleTraits<Fence>
501   {
502   public:
503     using DestructorType = Device;
504     using deleter        = ObjectDestroyShared<Fence>;
505   };
506 
507   using SharedFence = SharedHandle<Fence>;
508 
509   template <>
510   class SharedHandleTraits<Semaphore>
511   {
512   public:
513     using DestructorType = Device;
514     using deleter        = ObjectDestroyShared<Semaphore>;
515   };
516 
517   using SharedSemaphore = SharedHandle<Semaphore>;
518 
519   template <>
520   class SharedHandleTraits<Event>
521   {
522   public:
523     using DestructorType = Device;
524     using deleter        = ObjectDestroyShared<Event>;
525   };
526 
527   using SharedEvent = SharedHandle<Event>;
528 
529   template <>
530   class SharedHandleTraits<QueryPool>
531   {
532   public:
533     using DestructorType = Device;
534     using deleter        = ObjectDestroyShared<QueryPool>;
535   };
536 
537   using SharedQueryPool = SharedHandle<QueryPool>;
538 
539   template <>
540   class SharedHandleTraits<Buffer>
541   {
542   public:
543     using DestructorType = Device;
544     using deleter        = ObjectDestroyShared<Buffer>;
545   };
546 
547   using SharedBuffer = SharedHandle<Buffer>;
548 
549   template <>
550   class SharedHandleTraits<BufferView>
551   {
552   public:
553     using DestructorType = Device;
554     using deleter        = ObjectDestroyShared<BufferView>;
555   };
556 
557   using SharedBufferView = SharedHandle<BufferView>;
558 
559   template <>
560   class SharedHandleTraits<Image>
561   {
562   public:
563     using DestructorType = Device;
564     using deleter        = ObjectDestroyShared<Image>;
565   };
566 
567   using SharedImage = SharedHandle<Image>;
568 
569   template <>
570   class SharedHandleTraits<ImageView>
571   {
572   public:
573     using DestructorType = Device;
574     using deleter        = ObjectDestroyShared<ImageView>;
575   };
576 
577   using SharedImageView = SharedHandle<ImageView>;
578 
579   template <>
580   class SharedHandleTraits<ShaderModule>
581   {
582   public:
583     using DestructorType = Device;
584     using deleter        = ObjectDestroyShared<ShaderModule>;
585   };
586 
587   using SharedShaderModule = SharedHandle<ShaderModule>;
588 
589   template <>
590   class SharedHandleTraits<PipelineCache>
591   {
592   public:
593     using DestructorType = Device;
594     using deleter        = ObjectDestroyShared<PipelineCache>;
595   };
596 
597   using SharedPipelineCache = SharedHandle<PipelineCache>;
598 
599   template <>
600   class SharedHandleTraits<Pipeline>
601   {
602   public:
603     using DestructorType = Device;
604     using deleter        = ObjectDestroyShared<Pipeline>;
605   };
606 
607   using SharedPipeline = SharedHandle<Pipeline>;
608 
609   template <>
610   class SharedHandleTraits<PipelineLayout>
611   {
612   public:
613     using DestructorType = Device;
614     using deleter        = ObjectDestroyShared<PipelineLayout>;
615   };
616 
617   using SharedPipelineLayout = SharedHandle<PipelineLayout>;
618 
619   template <>
620   class SharedHandleTraits<Sampler>
621   {
622   public:
623     using DestructorType = Device;
624     using deleter        = ObjectDestroyShared<Sampler>;
625   };
626 
627   using SharedSampler = SharedHandle<Sampler>;
628 
629   template <>
630   class SharedHandleTraits<DescriptorPool>
631   {
632   public:
633     using DestructorType = Device;
634     using deleter        = ObjectDestroyShared<DescriptorPool>;
635   };
636 
637   using SharedDescriptorPool = SharedHandle<DescriptorPool>;
638 
639   template <>
640   class SharedHandleTraits<DescriptorSet>
641   {
642   public:
643     using DestructorType = Device;
644     using deleter        = PoolFreeShared<DescriptorSet, DescriptorPool>;
645   };
646 
647   using SharedDescriptorSet = SharedHandle<DescriptorSet>;
648 
649   template <>
650   class SharedHandleTraits<DescriptorSetLayout>
651   {
652   public:
653     using DestructorType = Device;
654     using deleter        = ObjectDestroyShared<DescriptorSetLayout>;
655   };
656 
657   using SharedDescriptorSetLayout = SharedHandle<DescriptorSetLayout>;
658 
659   template <>
660   class SharedHandleTraits<Framebuffer>
661   {
662   public:
663     using DestructorType = Device;
664     using deleter        = ObjectDestroyShared<Framebuffer>;
665   };
666 
667   using SharedFramebuffer = SharedHandle<Framebuffer>;
668 
669   template <>
670   class SharedHandleTraits<RenderPass>
671   {
672   public:
673     using DestructorType = Device;
674     using deleter        = ObjectDestroyShared<RenderPass>;
675   };
676 
677   using SharedRenderPass = SharedHandle<RenderPass>;
678 
679   template <>
680   class SharedHandleTraits<CommandPool>
681   {
682   public:
683     using DestructorType = Device;
684     using deleter        = ObjectDestroyShared<CommandPool>;
685   };
686 
687   using SharedCommandPool = SharedHandle<CommandPool>;
688 
689   template <>
690   class SharedHandleTraits<CommandBuffer>
691   {
692   public:
693     using DestructorType = Device;
694     using deleter        = PoolFreeShared<CommandBuffer, CommandPool>;
695   };
696 
697   using SharedCommandBuffer = SharedHandle<CommandBuffer>;
698 
699   //=== VK_VERSION_1_1 ===
700   template <>
701   class SharedHandleTraits<SamplerYcbcrConversion>
702   {
703   public:
704     using DestructorType = Device;
705     using deleter        = ObjectDestroyShared<SamplerYcbcrConversion>;
706   };
707 
708   using SharedSamplerYcbcrConversion    = SharedHandle<SamplerYcbcrConversion>;
709   using SharedSamplerYcbcrConversionKHR = SharedHandle<SamplerYcbcrConversion>;
710 
711   template <>
712   class SharedHandleTraits<DescriptorUpdateTemplate>
713   {
714   public:
715     using DestructorType = Device;
716     using deleter        = ObjectDestroyShared<DescriptorUpdateTemplate>;
717   };
718 
719   using SharedDescriptorUpdateTemplate    = SharedHandle<DescriptorUpdateTemplate>;
720   using SharedDescriptorUpdateTemplateKHR = SharedHandle<DescriptorUpdateTemplate>;
721 
722   //=== VK_VERSION_1_3 ===
723   template <>
724   class SharedHandleTraits<PrivateDataSlot>
725   {
726   public:
727     using DestructorType = Device;
728     using deleter        = ObjectDestroyShared<PrivateDataSlot>;
729   };
730 
731   using SharedPrivateDataSlot    = SharedHandle<PrivateDataSlot>;
732   using SharedPrivateDataSlotEXT = SharedHandle<PrivateDataSlot>;
733 
734   //=== VK_KHR_surface ===
735   template <>
736   class SharedHandleTraits<SurfaceKHR>
737   {
738   public:
739     using DestructorType = Instance;
740     using deleter        = ObjectDestroyShared<SurfaceKHR>;
741   };
742 
743   using SharedSurfaceKHR = SharedHandle<SurfaceKHR>;
744 
745   //=== VK_KHR_swapchain ===
746   template <>
747   class SharedHandleTraits<SwapchainKHR>
748   {
749   public:
750     using DestructorType = Device;
751     using deleter        = ObjectDestroyShared<SwapchainKHR>;
752   };
753 
754   using SharedSwapchainKHR = SharedHandle<SwapchainKHR>;
755 
756   //=== VK_KHR_display ===
757   template <>
758   class SharedHandleTraits<DisplayKHR>
759   {
760   public:
761     using DestructorType = PhysicalDevice;
762     using deleter        = ObjectDestroyShared<DisplayKHR>;
763   };
764 
765   using SharedDisplayKHR = SharedHandle<DisplayKHR>;
766 
767   //=== VK_EXT_debug_report ===
768   template <>
769   class SharedHandleTraits<DebugReportCallbackEXT>
770   {
771   public:
772     using DestructorType = Instance;
773     using deleter        = ObjectDestroyShared<DebugReportCallbackEXT>;
774   };
775 
776   using SharedDebugReportCallbackEXT = SharedHandle<DebugReportCallbackEXT>;
777 
778   //=== VK_KHR_video_queue ===
779   template <>
780   class SharedHandleTraits<VideoSessionKHR>
781   {
782   public:
783     using DestructorType = Device;
784     using deleter        = ObjectDestroyShared<VideoSessionKHR>;
785   };
786 
787   using SharedVideoSessionKHR = SharedHandle<VideoSessionKHR>;
788 
789   template <>
790   class SharedHandleTraits<VideoSessionParametersKHR>
791   {
792   public:
793     using DestructorType = Device;
794     using deleter        = ObjectDestroyShared<VideoSessionParametersKHR>;
795   };
796 
797   using SharedVideoSessionParametersKHR = SharedHandle<VideoSessionParametersKHR>;
798 
799   //=== VK_NVX_binary_import ===
800   template <>
801   class SharedHandleTraits<CuModuleNVX>
802   {
803   public:
804     using DestructorType = Device;
805     using deleter        = ObjectDestroyShared<CuModuleNVX>;
806   };
807 
808   using SharedCuModuleNVX = SharedHandle<CuModuleNVX>;
809 
810   template <>
811   class SharedHandleTraits<CuFunctionNVX>
812   {
813   public:
814     using DestructorType = Device;
815     using deleter        = ObjectDestroyShared<CuFunctionNVX>;
816   };
817 
818   using SharedCuFunctionNVX = SharedHandle<CuFunctionNVX>;
819 
820   //=== VK_EXT_debug_utils ===
821   template <>
822   class SharedHandleTraits<DebugUtilsMessengerEXT>
823   {
824   public:
825     using DestructorType = Instance;
826     using deleter        = ObjectDestroyShared<DebugUtilsMessengerEXT>;
827   };
828 
829   using SharedDebugUtilsMessengerEXT = SharedHandle<DebugUtilsMessengerEXT>;
830 
831   //=== VK_KHR_acceleration_structure ===
832   template <>
833   class SharedHandleTraits<AccelerationStructureKHR>
834   {
835   public:
836     using DestructorType = Device;
837     using deleter        = ObjectDestroyShared<AccelerationStructureKHR>;
838   };
839 
840   using SharedAccelerationStructureKHR = SharedHandle<AccelerationStructureKHR>;
841 
842   //=== VK_EXT_validation_cache ===
843   template <>
844   class SharedHandleTraits<ValidationCacheEXT>
845   {
846   public:
847     using DestructorType = Device;
848     using deleter        = ObjectDestroyShared<ValidationCacheEXT>;
849   };
850 
851   using SharedValidationCacheEXT = SharedHandle<ValidationCacheEXT>;
852 
853   //=== VK_NV_ray_tracing ===
854   template <>
855   class SharedHandleTraits<AccelerationStructureNV>
856   {
857   public:
858     using DestructorType = Device;
859     using deleter        = ObjectDestroyShared<AccelerationStructureNV>;
860   };
861 
862   using SharedAccelerationStructureNV = SharedHandle<AccelerationStructureNV>;
863 
864   //=== VK_INTEL_performance_query ===
865   template <>
866   class SharedHandleTraits<PerformanceConfigurationINTEL>
867   {
868   public:
869     using DestructorType = Device;
870     using deleter        = ObjectDestroyShared<PerformanceConfigurationINTEL>;
871   };
872 
873   using SharedPerformanceConfigurationINTEL = SharedHandle<PerformanceConfigurationINTEL>;
874 
875   //=== VK_KHR_deferred_host_operations ===
876   template <>
877   class SharedHandleTraits<DeferredOperationKHR>
878   {
879   public:
880     using DestructorType = Device;
881     using deleter        = ObjectDestroyShared<DeferredOperationKHR>;
882   };
883 
884   using SharedDeferredOperationKHR = SharedHandle<DeferredOperationKHR>;
885 
886   //=== VK_NV_device_generated_commands ===
887   template <>
888   class SharedHandleTraits<IndirectCommandsLayoutNV>
889   {
890   public:
891     using DestructorType = Device;
892     using deleter        = ObjectDestroyShared<IndirectCommandsLayoutNV>;
893   };
894 
895   using SharedIndirectCommandsLayoutNV = SharedHandle<IndirectCommandsLayoutNV>;
896 
897 #  if defined( VK_ENABLE_BETA_EXTENSIONS )
898   //=== VK_NV_cuda_kernel_launch ===
899   template <>
900   class SharedHandleTraits<CudaModuleNV>
901   {
902   public:
903     using DestructorType = Device;
904     using deleter        = ObjectDestroyShared<CudaModuleNV>;
905   };
906 
907   using SharedCudaModuleNV = SharedHandle<CudaModuleNV>;
908 
909   template <>
910   class SharedHandleTraits<CudaFunctionNV>
911   {
912   public:
913     using DestructorType = Device;
914     using deleter        = ObjectDestroyShared<CudaFunctionNV>;
915   };
916 
917   using SharedCudaFunctionNV = SharedHandle<CudaFunctionNV>;
918 #  endif /*VK_ENABLE_BETA_EXTENSIONS*/
919 
920 #  if defined( VK_USE_PLATFORM_FUCHSIA )
921   //=== VK_FUCHSIA_buffer_collection ===
922   template <>
923   class SharedHandleTraits<BufferCollectionFUCHSIA>
924   {
925   public:
926     using DestructorType = Device;
927     using deleter        = ObjectDestroyShared<BufferCollectionFUCHSIA>;
928   };
929 
930   using SharedBufferCollectionFUCHSIA = SharedHandle<BufferCollectionFUCHSIA>;
931 #  endif /*VK_USE_PLATFORM_FUCHSIA*/
932 
933   //=== VK_EXT_opacity_micromap ===
934   template <>
935   class SharedHandleTraits<MicromapEXT>
936   {
937   public:
938     using DestructorType = Device;
939     using deleter        = ObjectDestroyShared<MicromapEXT>;
940   };
941 
942   using SharedMicromapEXT = SharedHandle<MicromapEXT>;
943 
944   //=== VK_NV_optical_flow ===
945   template <>
946   class SharedHandleTraits<OpticalFlowSessionNV>
947   {
948   public:
949     using DestructorType = Device;
950     using deleter        = ObjectDestroyShared<OpticalFlowSessionNV>;
951   };
952 
953   using SharedOpticalFlowSessionNV = SharedHandle<OpticalFlowSessionNV>;
954 
955   //=== VK_EXT_shader_object ===
956   template <>
957   class SharedHandleTraits<ShaderEXT>
958   {
959   public:
960     using DestructorType = Device;
961     using deleter        = ObjectDestroyShared<ShaderEXT>;
962   };
963 
964   using SharedShaderEXT = SharedHandle<ShaderEXT>;
965 
966   //=== VK_KHR_pipeline_binary ===
967   template <>
968   class SharedHandleTraits<PipelineBinaryKHR>
969   {
970   public:
971     using DestructorType = Device;
972     using deleter        = ObjectDestroyShared<PipelineBinaryKHR>;
973   };
974 
975   using SharedPipelineBinaryKHR = SharedHandle<PipelineBinaryKHR>;
976 
977   enum class SwapchainOwns
978   {
979     no,
980     yes,
981   };
982 
983   struct ImageHeader : SharedHeader<DestructorTypeOf<VULKAN_HPP_NAMESPACE::Image>, typename SharedHandleTraits<VULKAN_HPP_NAMESPACE::Image>::deleter>
984   {
ImageHeaderVULKAN_HPP_NAMESPACE::ImageHeader985     ImageHeader(
986       SharedHandle<DestructorTypeOf<VULKAN_HPP_NAMESPACE::Image>>       parent,
987       typename SharedHandleTraits<VULKAN_HPP_NAMESPACE::Image>::deleter deleter        = typename SharedHandleTraits<VULKAN_HPP_NAMESPACE::Image>::deleter(),
988       SwapchainOwns                                                     swapchainOwned = SwapchainOwns::no ) VULKAN_HPP_NOEXCEPT
989       : SharedHeader<DestructorTypeOf<VULKAN_HPP_NAMESPACE::Image>, typename SharedHandleTraits<VULKAN_HPP_NAMESPACE::Image>::deleter>( std::move( parent ),
990                                                                                                                                         std::move( deleter ) )
991       , swapchainOwned( swapchainOwned )
992     {
993     }
994 
995     SwapchainOwns swapchainOwned = SwapchainOwns::no;
996   };
997 
998   template <>
999   class SharedHandle<VULKAN_HPP_NAMESPACE::Image> : public SharedHandleBase<VULKAN_HPP_NAMESPACE::Image, ImageHeader>
1000   {
1001     using BaseType    = SharedHandleBase<VULKAN_HPP_NAMESPACE::Image, ImageHeader>;
1002     using DeleterType = typename SharedHandleTraits<VULKAN_HPP_NAMESPACE::Image>::deleter;
1003     friend BaseType;
1004 
1005   public:
1006     SharedHandle() = default;
1007 
SharedHandle(VULKAN_HPP_NAMESPACE::Image handle,SharedHandle<DestructorTypeOf<VULKAN_HPP_NAMESPACE::Image>> parent,SwapchainOwns swapchain_owned=SwapchainOwns::no,DeleterType deleter=DeleterType ())1008     explicit SharedHandle( VULKAN_HPP_NAMESPACE::Image                                 handle,
1009                            SharedHandle<DestructorTypeOf<VULKAN_HPP_NAMESPACE::Image>> parent,
1010                            SwapchainOwns                                               swapchain_owned = SwapchainOwns::no,
1011                            DeleterType                                                 deleter         = DeleterType() ) VULKAN_HPP_NOEXCEPT
1012       : BaseType( handle, std::move( parent ), std::move( deleter ), swapchain_owned )
1013     {
1014     }
1015 
1016   protected:
internalDestroy(const ImageHeader & control,VULKAN_HPP_NAMESPACE::Image handle)1017     static void internalDestroy( const ImageHeader & control, VULKAN_HPP_NAMESPACE::Image handle ) VULKAN_HPP_NOEXCEPT
1018     {
1019       if ( control.swapchainOwned == SwapchainOwns::no )
1020       {
1021         control.deleter.destroy( control.parent.get(), handle );
1022       }
1023     }
1024   };
1025 
1026   struct SwapchainHeader
1027   {
SwapchainHeaderVULKAN_HPP_NAMESPACE::SwapchainHeader1028     SwapchainHeader( SharedHandle<VULKAN_HPP_NAMESPACE::SurfaceKHR>                           surface,
1029                      SharedHandle<DestructorTypeOf<VULKAN_HPP_NAMESPACE::SwapchainKHR>>       parent,
1030                      typename SharedHandleTraits<VULKAN_HPP_NAMESPACE::SwapchainKHR>::deleter deleter =
1031                        typename SharedHandleTraits<VULKAN_HPP_NAMESPACE::SwapchainKHR>::deleter() ) VULKAN_HPP_NOEXCEPT
1032       : surface( std::move( surface ) )
1033       , parent( std::move( parent ) )
1034       , deleter( std::move( deleter ) )
1035     {
1036     }
1037 
1038     SharedHandle<VULKAN_HPP_NAMESPACE::SurfaceKHR>                           surface{};
1039     SharedHandle<DestructorTypeOf<VULKAN_HPP_NAMESPACE::SwapchainKHR>>       parent{};
1040     typename SharedHandleTraits<VULKAN_HPP_NAMESPACE::SwapchainKHR>::deleter deleter{};
1041   };
1042 
1043   template <>
1044   class SharedHandle<VULKAN_HPP_NAMESPACE::SwapchainKHR> : public SharedHandleBase<VULKAN_HPP_NAMESPACE::SwapchainKHR, SwapchainHeader>
1045   {
1046     using BaseType    = SharedHandleBase<VULKAN_HPP_NAMESPACE::SwapchainKHR, SwapchainHeader>;
1047     using DeleterType = typename SharedHandleTraits<VULKAN_HPP_NAMESPACE::SwapchainKHR>::deleter;
1048     friend BaseType;
1049 
1050   public:
1051     SharedHandle() = default;
1052 
SharedHandle(VULKAN_HPP_NAMESPACE::SwapchainKHR handle,SharedHandle<DestructorTypeOf<VULKAN_HPP_NAMESPACE::SwapchainKHR>> parent,SharedHandle<VULKAN_HPP_NAMESPACE::SurfaceKHR> surface,DeleterType deleter=DeleterType ())1053     explicit SharedHandle( VULKAN_HPP_NAMESPACE::SwapchainKHR                                 handle,
1054                            SharedHandle<DestructorTypeOf<VULKAN_HPP_NAMESPACE::SwapchainKHR>> parent,
1055                            SharedHandle<VULKAN_HPP_NAMESPACE::SurfaceKHR>                     surface,
1056                            DeleterType                                                        deleter = DeleterType() ) VULKAN_HPP_NOEXCEPT
1057       : BaseType( handle, std::move( surface ), std::move( parent ), std::move( deleter ) )
1058     {
1059     }
1060 
1061   public:
getSurface() const1062     const SharedHandle<VULKAN_HPP_NAMESPACE::SurfaceKHR> & getSurface() const VULKAN_HPP_NOEXCEPT
1063     {
1064       return getHeader().surface;
1065     }
1066 
1067   protected:
1068     using BaseType::internalDestroy;
1069   };
1070 
1071   template <typename HandleType, typename DestructorType>
1072   class SharedHandleBaseNoDestroy : public SharedHandleBase<HandleType, DestructorType>
1073   {
1074   public:
1075     using SharedHandleBase<HandleType, DestructorType>::SharedHandleBase;
1076 
getDestructorType() const1077     const DestructorType & getDestructorType() const VULKAN_HPP_NOEXCEPT
1078     {
1079       return SharedHandleBase<HandleType, DestructorType>::getHeader();
1080     }
1081 
1082   protected:
internalDestroy(const DestructorType &,HandleType)1083     static void internalDestroy( const DestructorType &, HandleType ) VULKAN_HPP_NOEXCEPT {}
1084   };
1085 
1086   //=== VK_VERSION_1_0 ===
1087 
1088   template <>
1089   class SharedHandle<PhysicalDevice> : public SharedHandleBaseNoDestroy<PhysicalDevice, SharedInstance>
1090   {
1091     friend SharedHandleBase<PhysicalDevice, SharedInstance>;
1092 
1093   public:
1094     SharedHandle() = default;
1095 
SharedHandle(PhysicalDevice handle,SharedInstance parent)1096     explicit SharedHandle( PhysicalDevice handle, SharedInstance parent ) noexcept
1097       : SharedHandleBaseNoDestroy<PhysicalDevice, SharedInstance>( handle, std::move( parent ) )
1098     {
1099     }
1100   };
1101 
1102   using SharedPhysicalDevice = SharedHandle<PhysicalDevice>;
1103 
1104   template <>
1105   class SharedHandle<Queue> : public SharedHandleBaseNoDestroy<Queue, SharedDevice>
1106   {
1107     friend SharedHandleBase<Queue, SharedDevice>;
1108 
1109   public:
1110     SharedHandle() = default;
1111 
SharedHandle(Queue handle,SharedDevice parent)1112     explicit SharedHandle( Queue handle, SharedDevice parent ) noexcept : SharedHandleBaseNoDestroy<Queue, SharedDevice>( handle, std::move( parent ) ) {}
1113   };
1114 
1115   using SharedQueue = SharedHandle<Queue>;
1116 
1117   //=== VK_KHR_display ===
1118 
1119   template <>
1120   class SharedHandle<DisplayModeKHR> : public SharedHandleBaseNoDestroy<DisplayModeKHR, SharedDisplayKHR>
1121   {
1122     friend SharedHandleBase<DisplayModeKHR, SharedDisplayKHR>;
1123 
1124   public:
1125     SharedHandle() = default;
1126 
SharedHandle(DisplayModeKHR handle,SharedDisplayKHR parent)1127     explicit SharedHandle( DisplayModeKHR handle, SharedDisplayKHR parent ) noexcept
1128       : SharedHandleBaseNoDestroy<DisplayModeKHR, SharedDisplayKHR>( handle, std::move( parent ) )
1129     {
1130     }
1131   };
1132 
1133   using SharedDisplayModeKHR = SharedHandle<DisplayModeKHR>;
1134 #endif  // !VULKAN_HPP_NO_SMART_HANDLE
1135 }  // namespace VULKAN_HPP_NAMESPACE
1136 #endif  // VULKAN_SHARED_HPP
1137