VkSwapchainFactory.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Gr/Vulkan/VkCommon.h>
  7. #include <AnKi/Gr/BackendCommon/MicroObjectRecycler.h>
  8. #include <AnKi/Gr/Vulkan/VkSemaphoreFactory.h>
  9. #include <AnKi/Util/Ptr.h>
  10. namespace anki {
  11. /// @addtogroup vulkan
  12. /// @{
  13. /// A wrapper for the swapchain.
  14. class MicroSwapchain
  15. {
  16. friend class MicroSwapchainPtrDeleter;
  17. friend class SwapchainFactory;
  18. public:
  19. VkSwapchainKHR m_swapchain = {};
  20. GrDynamicArray<TextureInternalPtr> m_textures;
  21. GrDynamicArray<MicroSemaphorePtr> m_acquireSemaphores;
  22. GrDynamicArray<MicroSemaphorePtr> m_renderSemaphores; ///< Signaled by the operation that renders to a presentable image.
  23. MicroSwapchain();
  24. ~MicroSwapchain();
  25. void retain() const
  26. {
  27. m_refcount.fetchAdd(1);
  28. }
  29. void release()
  30. {
  31. if(m_refcount.fetchSub(1) == 1)
  32. {
  33. releaseInternal();
  34. }
  35. }
  36. I32 getRefcount() const
  37. {
  38. return m_refcount.load();
  39. }
  40. private:
  41. mutable Atomic<I32> m_refcount = {0};
  42. Error initInternal();
  43. void releaseInternal();
  44. };
  45. /// MicroSwapchain smart pointer.
  46. using MicroSwapchainPtr = IntrusiveNoDelPtr<MicroSwapchain>;
  47. /// Swapchain factory.
  48. class SwapchainFactory : public MakeSingleton<SwapchainFactory>
  49. {
  50. friend class MicroSwapchain;
  51. public:
  52. SwapchainFactory(Bool vsync)
  53. {
  54. m_vsync = vsync;
  55. }
  56. ~SwapchainFactory()
  57. {
  58. m_recycler.destroy();
  59. }
  60. MicroSwapchainPtr newInstance();
  61. private:
  62. Bool m_vsync = false;
  63. MicroObjectRecycler<MicroSwapchain> m_recycler;
  64. };
  65. /// @}
  66. } // end namespace anki