| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <memory> |
| 7 |
#include <vector> |
| 8 |
|
| 9 |
#include "Common/CommonTypes.h" |
| 10 |
#include "Common/WindowSystemInfo.h" |
| 11 |
#include "VideoBackends/Vulkan/Constants.h" |
| 12 |
#include "VideoCommon/TextureConfig.h" |
| 13 |
|
| 14 |
namespace Vulkan |
| 15 |
{ |
| 16 |
class CommandBufferManager; |
| 17 |
class ObjectCache; |
| 18 |
class VKTexture; |
| 19 |
class VKFramebuffer; |
| 20 |
|
| 21 |
class SwapChain |
| 22 |
{ |
| 23 |
public: |
| 24 |
SwapChain(const WindowSystemInfo& wsi, VkSurfaceKHR surface, bool vsync); |
| 25 |
~SwapChain(); |
| 26 |
|
| 27 |
|
| 28 |
static VkSurfaceKHR CreateVulkanSurface(VkInstance instance, const WindowSystemInfo& wsi); |
| 29 |
|
| 30 |
|
| 31 |
static std::unique_ptr<SwapChain> Create(const WindowSystemInfo& wsi, VkSurfaceKHR surface, |
| 32 |
bool vsync); |
| 33 |
|
| 34 |
VkSurfaceKHR GetSurface() const { return m_surface; } |
| 35 |
VkSurfaceFormatKHR GetSurfaceFormat() const { return m_surface_format; } |
| 36 |
AbstractTextureFormat GetTextureFormat() const { return m_texture_format; } |
| 37 |
VkSwapchainKHR GetSwapChain() const { return m_swap_chain; } |
| 38 |
u32 GetWidth() const { return m_width; } |
| 39 |
u32 GetHeight() const { return m_height; } |
| 40 |
u32 GetCurrentImageIndex() const { return m_current_swap_chain_image_index; } |
| 41 |
bool IsCurrentImageValid() const { return m_current_swap_chain_image_is_valid; } |
| 42 |
size_t GetSwapChainImageCount() const { return m_swap_chain_images.size(); } |
| 43 |
VkImage GetCurrentImage() const |
| 44 |
{ |
| 45 |
return m_swap_chain_images[m_current_swap_chain_image_index].image; |
| 46 |
} |
| 47 |
VKTexture* GetCurrentTexture() const |
| 48 |
{ |
| 49 |
return m_swap_chain_images[m_current_swap_chain_image_index].texture.get(); |
| 50 |
} |
| 51 |
VKFramebuffer* GetCurrentFramebuffer() const |
| 52 |
{ |
| 53 |
return m_swap_chain_images[m_current_swap_chain_image_index].framebuffer.get(); |
| 54 |
} |
| 55 |
VkResult AcquireNextImage(); |
| 56 |
|
| 57 |
bool RecreateSurface(void* native_handle); |
| 58 |
bool ResizeSwapChain(); |
| 59 |
bool RecreateSwapChain(); |
| 60 |
|
| 61 |
|
| 62 |
bool SetVSync(bool enabled); |
| 63 |
|
| 64 |
|
| 65 |
bool IsFullscreenSupported() const { return m_fullscreen_supported; } |
| 66 |
|
| 67 |
|
| 68 |
bool GetCurrentFullscreenState() const { return m_current_fullscreen_state; } |
| 69 |
bool GetNextFullscreenState() const { return m_next_fullscreen_state; } |
| 70 |
void SetNextFullscreenState(bool state) { m_next_fullscreen_state = state; } |
| 71 |
|
| 72 |
|
| 73 |
bool SetFullscreenState(bool state); |
| 74 |
|
| 75 |
private: |
| 76 |
bool SelectSurfaceFormat(); |
| 77 |
bool SelectPresentMode(); |
| 78 |
|
| 79 |
bool CreateSwapChain(); |
| 80 |
void DestroySwapChain(); |
| 81 |
|
| 82 |
bool SetupSwapChainImages(); |
| 83 |
void DestroySwapChainImages(); |
| 84 |
|
| 85 |
void DestroySurface(); |
| 86 |
|
| 87 |
struct SwapChainImage |
| 88 |
{ |
| 89 |
VkImage image{}; |
| 90 |
std::unique_ptr<VKTexture> texture; |
| 91 |
std::unique_ptr<VKFramebuffer> framebuffer; |
| 92 |
}; |
| 93 |
|
| 94 |
WindowSystemInfo m_wsi; |
| 95 |
VkSurfaceKHR m_surface = VK_NULL_HANDLE; |
| 96 |
VkSurfaceFormatKHR m_surface_format = {}; |
| 97 |
VkPresentModeKHR m_present_mode = VK_PRESENT_MODE_IMMEDIATE_KHR; |
| 98 |
AbstractTextureFormat m_texture_format = AbstractTextureFormat::Undefined; |
| 99 |
bool m_vsync_enabled = false; |
| 100 |
bool m_fullscreen_supported = false; |
| 101 |
bool m_current_fullscreen_state = false; |
| 102 |
bool m_next_fullscreen_state = false; |
| 103 |
bool m_current_swap_chain_image_is_valid = false; |
| 104 |
|
| 105 |
VkSwapchainKHR m_swap_chain = VK_NULL_HANDLE; |
| 106 |
std::vector<SwapChainImage> m_swap_chain_images; |
| 107 |
u32 m_current_swap_chain_image_index = 0; |
| 108 |
|
| 109 |
u32 m_width = 0; |
| 110 |
u32 m_height = 0; |
| 111 |
u32 m_layers = 0; |
| 112 |
}; |
| 113 |
|
| 114 |
} |