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