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