vulkan_shared.hpp 32 KB

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