vk_swapchain.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2019 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <vector>
  6. #include "common/common_types.h"
  7. #include "video_core/renderer_vulkan/declarations.h"
  8. namespace Layout {
  9. struct FramebufferLayout;
  10. }
  11. namespace Vulkan {
  12. class VKDevice;
  13. class VKFence;
  14. class VKSwapchain {
  15. public:
  16. explicit VKSwapchain(vk::SurfaceKHR surface, const VKDevice& device);
  17. ~VKSwapchain();
  18. /// Creates (or recreates) the swapchain with a given size.
  19. void Create(u32 width, u32 height);
  20. /// Acquires the next image in the swapchain, waits as needed.
  21. void AcquireNextImage();
  22. /// Presents the rendered image to the swapchain. Returns true when the swapchains had to be
  23. /// recreated. Takes responsability for the ownership of fence.
  24. bool Present(vk::Semaphore render_semaphore, VKFence& fence);
  25. /// Returns true when the framebuffer layout has changed.
  26. bool HasFramebufferChanged(const Layout::FramebufferLayout& framebuffer) const;
  27. const vk::Extent2D& GetSize() const {
  28. return extent;
  29. }
  30. u32 GetImageCount() const {
  31. return image_count;
  32. }
  33. u32 GetImageIndex() const {
  34. return image_index;
  35. }
  36. vk::Image GetImageIndex(u32 index) const {
  37. return images[index];
  38. }
  39. vk::ImageView GetImageViewIndex(u32 index) const {
  40. return *image_views[index];
  41. }
  42. vk::Format GetImageFormat() const {
  43. return image_format;
  44. }
  45. private:
  46. void CreateSwapchain(const vk::SurfaceCapabilitiesKHR& capabilities, u32 width, u32 height);
  47. void CreateSemaphores();
  48. void CreateImageViews();
  49. void Destroy();
  50. const vk::SurfaceKHR surface;
  51. const VKDevice& device;
  52. UniqueSwapchainKHR swapchain;
  53. u32 image_count{};
  54. std::vector<vk::Image> images;
  55. std::vector<UniqueImageView> image_views;
  56. std::vector<UniqueFramebuffer> framebuffers;
  57. std::vector<VKFence*> fences;
  58. std::vector<UniqueSemaphore> present_semaphores;
  59. u32 image_index{};
  60. u32 frame_index{};
  61. vk::Format image_format{};
  62. vk::Extent2D extent{};
  63. u32 current_width{};
  64. u32 current_height{};
  65. };
  66. } // namespace Vulkan