2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2019-03-29 03:58:43 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
2020-12-25 01:30:11 +01:00
|
|
|
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
2019-03-29 03:58:43 +01:00
|
|
|
|
|
|
|
namespace Layout {
|
|
|
|
struct FramebufferLayout;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Vulkan {
|
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
class Device;
|
2022-06-26 06:34:24 +02:00
|
|
|
class Scheduler;
|
2019-03-29 03:58:43 +01:00
|
|
|
|
|
|
|
class VKSwapchain {
|
|
|
|
public:
|
2022-06-26 06:34:24 +02:00
|
|
|
explicit VKSwapchain(VkSurfaceKHR surface, const Device& device, Scheduler& scheduler,
|
2021-01-05 08:09:39 +01:00
|
|
|
u32 width, u32 height, bool srgb);
|
2019-03-29 03:58:43 +01:00
|
|
|
~VKSwapchain();
|
|
|
|
|
|
|
|
/// Creates (or recreates) the swapchain with a given size.
|
2019-12-07 02:41:42 +01:00
|
|
|
void Create(u32 width, u32 height, bool srgb);
|
2019-03-29 03:58:43 +01:00
|
|
|
|
|
|
|
/// Acquires the next image in the swapchain, waits as needed.
|
2021-04-27 03:11:31 +02:00
|
|
|
void AcquireNextImage();
|
2019-03-29 03:58:43 +01:00
|
|
|
|
2021-04-27 03:11:31 +02:00
|
|
|
/// Presents the rendered image to the swapchain.
|
|
|
|
void Present(VkSemaphore render_semaphore);
|
2019-03-29 03:58:43 +01:00
|
|
|
|
2021-09-13 02:32:23 +02:00
|
|
|
/// Returns true when the swapchain needs to be recreated.
|
|
|
|
bool NeedsRecreation(bool is_srgb) const {
|
|
|
|
return HasColorSpaceChanged(is_srgb) || IsSubOptimal() || NeedsPresentModeUpdate();
|
|
|
|
}
|
|
|
|
|
2021-06-02 00:59:29 +02:00
|
|
|
/// Returns true when the color space has changed.
|
|
|
|
bool HasColorSpaceChanged(bool is_srgb) const {
|
|
|
|
return current_srgb != is_srgb;
|
2021-04-27 03:11:31 +02:00
|
|
|
}
|
|
|
|
|
2021-06-03 22:42:24 +02:00
|
|
|
/// Returns true when the swapchain is outdated.
|
|
|
|
bool IsOutDated() const {
|
|
|
|
return is_outdated;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true when the swapchain is suboptimal.
|
|
|
|
bool IsSubOptimal() const {
|
|
|
|
return is_suboptimal;
|
2021-04-27 03:11:31 +02:00
|
|
|
}
|
2019-03-29 03:58:43 +01:00
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
VkExtent2D GetSize() const {
|
2019-03-29 03:58:43 +01:00
|
|
|
return extent;
|
|
|
|
}
|
|
|
|
|
2020-01-20 22:29:54 +01:00
|
|
|
std::size_t GetImageCount() const {
|
2019-03-29 03:58:43 +01:00
|
|
|
return image_count;
|
|
|
|
}
|
|
|
|
|
2020-01-20 22:29:54 +01:00
|
|
|
std::size_t GetImageIndex() const {
|
2019-03-29 03:58:43 +01:00
|
|
|
return image_index;
|
|
|
|
}
|
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
VkImage GetImageIndex(std::size_t index) const {
|
2019-03-29 03:58:43 +01:00
|
|
|
return images[index];
|
|
|
|
}
|
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
VkImageView GetImageViewIndex(std::size_t index) const {
|
2019-03-29 03:58:43 +01:00
|
|
|
return *image_views[index];
|
|
|
|
}
|
|
|
|
|
2021-08-29 07:12:17 +02:00
|
|
|
VkFormat GetImageViewFormat() const {
|
|
|
|
return image_view_format;
|
2019-03-29 03:58:43 +01:00
|
|
|
}
|
|
|
|
|
2021-09-02 07:26:18 +02:00
|
|
|
VkSemaphore CurrentPresentSemaphore() const {
|
|
|
|
return *present_semaphores[frame_index];
|
|
|
|
}
|
|
|
|
|
2019-03-29 03:58:43 +01:00
|
|
|
private:
|
2020-03-27 05:33:21 +01:00
|
|
|
void CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, u32 width, u32 height,
|
2019-12-07 02:41:42 +01:00
|
|
|
bool srgb);
|
2019-03-29 03:58:43 +01:00
|
|
|
void CreateSemaphores();
|
|
|
|
void CreateImageViews();
|
|
|
|
|
|
|
|
void Destroy();
|
|
|
|
|
2021-09-13 02:32:23 +02:00
|
|
|
bool HasFpsUnlockChanged() const;
|
|
|
|
|
|
|
|
bool NeedsPresentModeUpdate() const;
|
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
const VkSurfaceKHR surface;
|
2020-12-26 05:10:53 +01:00
|
|
|
const Device& device;
|
2022-06-26 06:34:24 +02:00
|
|
|
Scheduler& scheduler;
|
2019-03-29 03:58:43 +01:00
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
vk::SwapchainKHR swapchain;
|
2019-03-29 03:58:43 +01:00
|
|
|
|
2020-01-20 22:29:54 +01:00
|
|
|
std::size_t image_count{};
|
2020-03-27 05:33:21 +01:00
|
|
|
std::vector<VkImage> images;
|
|
|
|
std::vector<vk::ImageView> image_views;
|
|
|
|
std::vector<vk::Framebuffer> framebuffers;
|
2020-09-10 08:43:30 +02:00
|
|
|
std::vector<u64> resource_ticks;
|
2020-03-27 05:33:21 +01:00
|
|
|
std::vector<vk::Semaphore> present_semaphores;
|
2019-03-29 03:58:43 +01:00
|
|
|
|
|
|
|
u32 image_index{};
|
|
|
|
u32 frame_index{};
|
|
|
|
|
2021-08-29 07:12:17 +02:00
|
|
|
VkFormat image_view_format{};
|
2020-03-27 05:33:21 +01:00
|
|
|
VkExtent2D extent{};
|
2021-09-13 02:32:23 +02:00
|
|
|
VkPresentModeKHR present_mode{};
|
2019-03-29 03:58:43 +01:00
|
|
|
|
2019-12-07 02:41:42 +01:00
|
|
|
bool current_srgb{};
|
2021-09-13 02:32:23 +02:00
|
|
|
bool current_fps_unlocked{};
|
2021-06-03 22:42:24 +02:00
|
|
|
bool is_outdated{};
|
|
|
|
bool is_suboptimal{};
|
2019-03-29 03:58:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Vulkan
|