2016-08-13 06:57:50 -06:00
|
|
|
// Copyright 2016 Dolphin Emulator Project
|
2021-07-04 19:22:19 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2016-08-13 06:57:50 -06:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2016-09-30 21:07:50 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2018-10-23 22:47:48 -06:00
|
|
|
#include "Common/WindowSystemInfo.h"
|
2016-08-13 06:57:50 -06:00
|
|
|
#include "VideoBackends/Vulkan/Constants.h"
|
2017-09-09 00:09:24 -06:00
|
|
|
#include "VideoCommon/TextureConfig.h"
|
2016-08-13 06:57:50 -06:00
|
|
|
|
|
|
|
namespace Vulkan
|
|
|
|
{
|
|
|
|
class CommandBufferManager;
|
|
|
|
class ObjectCache;
|
2019-02-14 18:59:50 -07:00
|
|
|
class VKTexture;
|
|
|
|
class VKFramebuffer;
|
2016-08-13 06:57:50 -06:00
|
|
|
|
|
|
|
class SwapChain
|
|
|
|
{
|
|
|
|
public:
|
2018-10-23 22:47:48 -06:00
|
|
|
SwapChain(const WindowSystemInfo& wsi, VkSurfaceKHR surface, bool vsync);
|
2016-08-13 06:57:50 -06:00
|
|
|
~SwapChain();
|
|
|
|
|
|
|
|
// Creates a vulkan-renderable surface for the specified window handle.
|
2018-10-23 22:47:48 -06:00
|
|
|
static VkSurfaceKHR CreateVulkanSurface(VkInstance instance, const WindowSystemInfo& wsi);
|
2016-08-13 06:57:50 -06:00
|
|
|
|
|
|
|
// Create a new swap chain from a pre-existing surface.
|
2018-10-23 22:47:48 -06:00
|
|
|
static std::unique_ptr<SwapChain> Create(const WindowSystemInfo& wsi, VkSurfaceKHR surface,
|
|
|
|
bool vsync);
|
2016-08-13 06:57:50 -06:00
|
|
|
|
|
|
|
VkSurfaceKHR GetSurface() const { return m_surface; }
|
|
|
|
VkSurfaceFormatKHR GetSurfaceFormat() const { return m_surface_format; }
|
2017-09-09 00:09:24 -06:00
|
|
|
AbstractTextureFormat GetTextureFormat() const { return m_texture_format; }
|
2016-08-13 06:57:50 -06:00
|
|
|
VkSwapchainKHR GetSwapChain() const { return m_swap_chain; }
|
|
|
|
u32 GetWidth() const { return m_width; }
|
|
|
|
u32 GetHeight() const { return m_height; }
|
|
|
|
u32 GetCurrentImageIndex() const { return m_current_swap_chain_image_index; }
|
|
|
|
VkImage GetCurrentImage() const
|
|
|
|
{
|
|
|
|
return m_swap_chain_images[m_current_swap_chain_image_index].image;
|
|
|
|
}
|
2019-02-14 18:59:50 -07:00
|
|
|
VKTexture* GetCurrentTexture() const
|
2016-08-13 06:57:50 -06:00
|
|
|
{
|
|
|
|
return m_swap_chain_images[m_current_swap_chain_image_index].texture.get();
|
|
|
|
}
|
2019-02-14 18:59:50 -07:00
|
|
|
VKFramebuffer* GetCurrentFramebuffer() const
|
2016-08-13 06:57:50 -06:00
|
|
|
{
|
2019-02-14 18:59:50 -07:00
|
|
|
return m_swap_chain_images[m_current_swap_chain_image_index].framebuffer.get();
|
2016-08-13 06:57:50 -06:00
|
|
|
}
|
2019-01-26 19:59:57 -07:00
|
|
|
VkResult AcquireNextImage();
|
2016-08-13 06:57:50 -06:00
|
|
|
|
|
|
|
bool RecreateSurface(void* native_handle);
|
|
|
|
bool ResizeSwapChain();
|
2017-09-16 00:15:20 -06:00
|
|
|
bool RecreateSwapChain();
|
2016-08-13 06:57:50 -06:00
|
|
|
|
2016-10-02 06:09:19 -06:00
|
|
|
// Change vsync enabled state. This may fail as it causes a swapchain recreation.
|
|
|
|
bool SetVSync(bool enabled);
|
|
|
|
|
2019-09-30 09:10:08 -06:00
|
|
|
// Is exclusive fullscreen supported?
|
|
|
|
bool IsFullscreenSupported() const { return m_fullscreen_supported; }
|
|
|
|
|
|
|
|
// Retrieves the "next" fullscreen state. Safe to call off-thread.
|
|
|
|
bool GetCurrentFullscreenState() const { return m_current_fullscreen_state; }
|
|
|
|
bool GetNextFullscreenState() const { return m_next_fullscreen_state; }
|
|
|
|
void SetNextFullscreenState(bool state) { m_next_fullscreen_state = state; }
|
|
|
|
|
|
|
|
// Updates the fullscreen state. Must call on-thread.
|
|
|
|
bool SetFullscreenState(bool state);
|
|
|
|
|
2016-08-13 06:57:50 -06:00
|
|
|
private:
|
|
|
|
bool SelectSurfaceFormat();
|
|
|
|
bool SelectPresentMode();
|
|
|
|
|
|
|
|
bool CreateSwapChain();
|
|
|
|
void DestroySwapChain();
|
|
|
|
|
|
|
|
bool SetupSwapChainImages();
|
|
|
|
void DestroySwapChainImages();
|
|
|
|
|
|
|
|
void DestroySurface();
|
|
|
|
|
|
|
|
struct SwapChainImage
|
|
|
|
{
|
2021-09-03 22:43:19 -06:00
|
|
|
VkImage image{};
|
2019-02-14 18:59:50 -07:00
|
|
|
std::unique_ptr<VKTexture> texture;
|
|
|
|
std::unique_ptr<VKFramebuffer> framebuffer;
|
2016-08-13 06:57:50 -06:00
|
|
|
};
|
|
|
|
|
2018-10-23 22:47:48 -06:00
|
|
|
WindowSystemInfo m_wsi;
|
2016-09-30 18:40:44 -06:00
|
|
|
VkSurfaceKHR m_surface = VK_NULL_HANDLE;
|
2016-08-13 06:57:50 -06:00
|
|
|
VkSurfaceFormatKHR m_surface_format = {};
|
2022-01-28 23:47:27 -07:00
|
|
|
VkPresentModeKHR m_present_mode = VK_PRESENT_MODE_IMMEDIATE_KHR;
|
2017-09-09 00:09:24 -06:00
|
|
|
AbstractTextureFormat m_texture_format = AbstractTextureFormat::Undefined;
|
2019-09-30 09:10:08 -06:00
|
|
|
bool m_vsync_enabled = false;
|
|
|
|
bool m_fullscreen_supported = false;
|
|
|
|
bool m_current_fullscreen_state = false;
|
|
|
|
bool m_next_fullscreen_state = false;
|
2016-08-13 06:57:50 -06:00
|
|
|
|
2016-09-30 18:40:44 -06:00
|
|
|
VkSwapchainKHR m_swap_chain = VK_NULL_HANDLE;
|
2016-08-13 06:57:50 -06:00
|
|
|
std::vector<SwapChainImage> m_swap_chain_images;
|
|
|
|
u32 m_current_swap_chain_image_index = 0;
|
|
|
|
|
|
|
|
u32 m_width = 0;
|
|
|
|
u32 m_height = 0;
|
2017-06-26 13:08:21 -06:00
|
|
|
u32 m_layers = 0;
|
2016-08-13 06:57:50 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Vulkan
|