2016-08-13 12:57:50 +00:00
|
|
|
// Copyright 2016 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2016-10-01 03:07:50 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2018-10-24 04:47:48 +00:00
|
|
|
#include "Common/WindowSystemInfo.h"
|
2016-08-13 12:57:50 +00:00
|
|
|
#include "VideoBackends/Vulkan/Constants.h"
|
|
|
|
#include "VideoBackends/Vulkan/Texture2D.h"
|
2017-09-09 06:09:24 +00:00
|
|
|
#include "VideoCommon/TextureConfig.h"
|
2016-08-13 12:57:50 +00:00
|
|
|
|
|
|
|
namespace Vulkan
|
|
|
|
{
|
|
|
|
class CommandBufferManager;
|
|
|
|
class ObjectCache;
|
|
|
|
|
|
|
|
class SwapChain
|
|
|
|
{
|
|
|
|
public:
|
2018-10-24 04:47:48 +00:00
|
|
|
SwapChain(const WindowSystemInfo& wsi, VkSurfaceKHR surface, bool vsync);
|
2016-08-13 12:57:50 +00:00
|
|
|
~SwapChain();
|
|
|
|
|
|
|
|
// Creates a vulkan-renderable surface for the specified window handle.
|
2018-10-24 04:47:48 +00:00
|
|
|
static VkSurfaceKHR CreateVulkanSurface(VkInstance instance, const WindowSystemInfo& wsi);
|
2016-08-13 12:57:50 +00:00
|
|
|
|
|
|
|
// Create a new swap chain from a pre-existing surface.
|
2018-10-24 04:47:48 +00:00
|
|
|
static std::unique_ptr<SwapChain> Create(const WindowSystemInfo& wsi, VkSurfaceKHR surface,
|
|
|
|
bool vsync);
|
2016-08-13 12:57:50 +00:00
|
|
|
|
|
|
|
VkSurfaceKHR GetSurface() const { return m_surface; }
|
|
|
|
VkSurfaceFormatKHR GetSurfaceFormat() const { return m_surface_format; }
|
2017-09-09 06:09:24 +00:00
|
|
|
AbstractTextureFormat GetTextureFormat() const { return m_texture_format; }
|
2016-10-02 12:09:19 +00:00
|
|
|
bool IsVSyncEnabled() const { return m_vsync_enabled; }
|
2017-06-26 19:08:21 +00:00
|
|
|
bool IsStereoEnabled() const { return m_layers == 2; }
|
2016-08-13 12:57:50 +00: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;
|
|
|
|
}
|
|
|
|
Texture2D* GetCurrentTexture() const
|
|
|
|
{
|
|
|
|
return m_swap_chain_images[m_current_swap_chain_image_index].texture.get();
|
|
|
|
}
|
|
|
|
VkFramebuffer GetCurrentFramebuffer() const
|
|
|
|
{
|
|
|
|
return m_swap_chain_images[m_current_swap_chain_image_index].framebuffer;
|
|
|
|
}
|
2019-01-27 02:59:57 +00:00
|
|
|
VkRenderPass GetLoadRenderPass() const { return m_render_pass; }
|
|
|
|
VkRenderPass GetClearRenderPass() const { return m_clear_render_pass; }
|
|
|
|
VkSemaphore GetImageAvailableSemaphore() const { return m_image_available_semaphore; }
|
|
|
|
VkSemaphore GetRenderingFinishedSemaphore() const { return m_rendering_finished_semaphore; }
|
2016-08-13 12:57:50 +00:00
|
|
|
|
2019-01-27 02:59:57 +00:00
|
|
|
VkResult AcquireNextImage();
|
2016-08-13 12:57:50 +00:00
|
|
|
|
|
|
|
bool RecreateSurface(void* native_handle);
|
|
|
|
bool ResizeSwapChain();
|
2017-09-16 06:15:20 +00:00
|
|
|
bool RecreateSwapChain();
|
2016-08-13 12:57:50 +00:00
|
|
|
|
2016-10-02 12:09:19 +00:00
|
|
|
// Change vsync enabled state. This may fail as it causes a swapchain recreation.
|
|
|
|
bool SetVSync(bool enabled);
|
|
|
|
|
2016-08-13 12:57:50 +00:00
|
|
|
private:
|
2019-01-27 02:59:57 +00:00
|
|
|
bool CreateSemaphores();
|
|
|
|
void DestroySemaphores();
|
|
|
|
|
2016-08-13 12:57:50 +00:00
|
|
|
bool SelectSurfaceFormat();
|
|
|
|
bool SelectPresentMode();
|
|
|
|
|
|
|
|
bool CreateSwapChain();
|
|
|
|
void DestroySwapChain();
|
|
|
|
|
|
|
|
bool SetupSwapChainImages();
|
|
|
|
void DestroySwapChainImages();
|
|
|
|
|
|
|
|
void DestroySurface();
|
|
|
|
|
|
|
|
struct SwapChainImage
|
|
|
|
{
|
|
|
|
VkImage image;
|
|
|
|
std::unique_ptr<Texture2D> texture;
|
|
|
|
VkFramebuffer framebuffer;
|
|
|
|
};
|
|
|
|
|
2018-10-24 04:47:48 +00:00
|
|
|
WindowSystemInfo m_wsi;
|
2016-10-01 00:40:44 +00:00
|
|
|
VkSurfaceKHR m_surface = VK_NULL_HANDLE;
|
2016-08-13 12:57:50 +00:00
|
|
|
VkSurfaceFormatKHR m_surface_format = {};
|
|
|
|
VkPresentModeKHR m_present_mode = VK_PRESENT_MODE_RANGE_SIZE_KHR;
|
2017-09-09 06:09:24 +00:00
|
|
|
AbstractTextureFormat m_texture_format = AbstractTextureFormat::Undefined;
|
2016-10-02 12:09:19 +00:00
|
|
|
bool m_vsync_enabled;
|
2016-08-13 12:57:50 +00:00
|
|
|
|
2016-10-01 00:40:44 +00:00
|
|
|
VkSwapchainKHR m_swap_chain = VK_NULL_HANDLE;
|
2016-08-13 12:57:50 +00:00
|
|
|
std::vector<SwapChainImage> m_swap_chain_images;
|
|
|
|
u32 m_current_swap_chain_image_index = 0;
|
|
|
|
|
2019-01-27 02:59:57 +00:00
|
|
|
VkSemaphore m_image_available_semaphore = VK_NULL_HANDLE;
|
|
|
|
VkSemaphore m_rendering_finished_semaphore = VK_NULL_HANDLE;
|
|
|
|
|
|
|
|
VkRenderPass m_render_pass = VK_NULL_HANDLE;
|
|
|
|
VkRenderPass m_clear_render_pass = VK_NULL_HANDLE;
|
|
|
|
|
2016-08-13 12:57:50 +00:00
|
|
|
u32 m_width = 0;
|
|
|
|
u32 m_height = 0;
|
2017-06-26 19:08:21 +00:00
|
|
|
u32 m_layers = 0;
|
2016-08-13 12:57:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Vulkan
|