vk_swapchain.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/vulkan_common/vulkan_wrapper.h"
  8. namespace Layout {
  9. struct FramebufferLayout;
  10. }
  11. namespace Vulkan {
  12. class Device;
  13. class VKScheduler;
  14. class VKSwapchain {
  15. public:
  16. explicit VKSwapchain(VkSurfaceKHR surface, const Device& device, VKScheduler& scheduler,
  17. u32 width, u32 height, bool srgb);
  18. ~VKSwapchain();
  19. /// Creates (or recreates) the swapchain with a given size.
  20. void Create(u32 width, u32 height, bool srgb);
  21. /// Acquires the next image in the swapchain, waits as needed.
  22. void AcquireNextImage();
  23. /// Presents the rendered image to the swapchain.
  24. void Present(VkSemaphore render_semaphore);
  25. /// Returns true when the color space has changed.
  26. bool HasColorSpaceChanged(bool is_srgb) const {
  27. return current_srgb != is_srgb;
  28. }
  29. /// Returns true when the swapchain is outdated.
  30. bool IsOutDated() const {
  31. return is_outdated;
  32. }
  33. /// Returns true when the swapchain is suboptimal.
  34. bool IsSubOptimal() const {
  35. return is_suboptimal;
  36. }
  37. VkExtent2D GetSize() const {
  38. return extent;
  39. }
  40. std::size_t GetImageCount() const {
  41. return image_count;
  42. }
  43. std::size_t GetImageIndex() const {
  44. return image_index;
  45. }
  46. VkImage GetImageIndex(std::size_t index) const {
  47. return images[index];
  48. }
  49. VkImageView GetImageViewIndex(std::size_t index) const {
  50. return *image_views[index];
  51. }
  52. VkFormat GetImageFormat() const {
  53. return image_format;
  54. }
  55. private:
  56. void CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, u32 width, u32 height,
  57. bool srgb);
  58. void CreateSemaphores();
  59. void CreateImageViews();
  60. void Destroy();
  61. const VkSurfaceKHR surface;
  62. const Device& device;
  63. VKScheduler& scheduler;
  64. vk::SwapchainKHR swapchain;
  65. std::size_t image_count{};
  66. std::vector<VkImage> images;
  67. std::vector<vk::ImageView> image_views;
  68. std::vector<vk::Framebuffer> framebuffers;
  69. std::vector<u64> resource_ticks;
  70. std::vector<vk::Semaphore> present_semaphores;
  71. u32 image_index{};
  72. u32 frame_index{};
  73. VkFormat image_format{};
  74. VkExtent2D extent{};
  75. bool current_srgb{};
  76. bool is_outdated{};
  77. bool is_suboptimal{};
  78. };
  79. } // namespace Vulkan