vk_swapchain.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. VkSemaphore CurrentPresentSemaphore() const {
  56. return *present_semaphores[frame_index];
  57. }
  58. private:
  59. void CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, u32 width, u32 height,
  60. bool srgb);
  61. void CreateSemaphores();
  62. void CreateImageViews();
  63. void Destroy();
  64. const VkSurfaceKHR surface;
  65. const Device& device;
  66. VKScheduler& scheduler;
  67. vk::SwapchainKHR swapchain;
  68. std::size_t image_count{};
  69. std::vector<VkImage> images;
  70. std::vector<vk::ImageView> image_views;
  71. std::vector<vk::Framebuffer> framebuffers;
  72. std::vector<u64> resource_ticks;
  73. std::vector<vk::Semaphore> present_semaphores;
  74. u32 image_index{};
  75. u32 frame_index{};
  76. VkFormat image_format{};
  77. VkExtent2D extent{};
  78. bool current_srgb{};
  79. bool is_outdated{};
  80. bool is_suboptimal{};
  81. };
  82. } // namespace Vulkan