2019-03-29 03:58:43 +01:00
|
|
|
// Copyright 2019 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#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;
|
2020-09-10 08:43:30 +02:00
|
|
|
class VKScheduler;
|
2019-03-29 03:58:43 +01:00
|
|
|
|
|
|
|
class VKSwapchain {
|
|
|
|
public:
|
2021-01-05 08:09:39 +01:00
|
|
|
explicit VKSwapchain(VkSurfaceKHR surface, const Device& device, VKScheduler& scheduler,
|
|
|
|
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
|
|
|
|
|
|
|
/// Returns true when the framebuffer layout has changed.
|
2021-04-27 03:11:31 +02:00
|
|
|
bool HasDifferentLayout(u32 width, u32 height, bool is_srgb) const {
|
|
|
|
return extent.width != width || extent.height != height || current_srgb != is_srgb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true when the image has to be recreated.
|
|
|
|
bool NeedsRecreate() const {
|
|
|
|
return needs_recreate;
|
|
|
|
}
|
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];
|
|
|
|
}
|
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
VkFormat GetImageFormat() const {
|
2019-03-29 03:58:43 +01:00
|
|
|
return image_format;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
const VkSurfaceKHR surface;
|
2020-12-26 05:10:53 +01:00
|
|
|
const Device& device;
|
2020-09-10 08:43:30 +02:00
|
|
|
VKScheduler& 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{};
|
|
|
|
|
2020-03-27 05:33:21 +01:00
|
|
|
VkFormat image_format{};
|
|
|
|
VkExtent2D extent{};
|
2019-03-29 03:58:43 +01:00
|
|
|
|
2019-12-07 02:41:42 +01:00
|
|
|
bool current_srgb{};
|
2021-04-27 03:11:31 +02:00
|
|
|
bool needs_recreate{};
|
2019-03-29 03:58:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Vulkan
|