Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
SwapChain.h
Go to the documentation of this file.
1/* Copyright (C) 2023 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_RENDERER_BACKEND_VULKAN_SWAPCHAIN
19#define INCLUDED_RENDERER_BACKEND_VULKAN_SWAPCHAIN
20
22
23#include <glad/vulkan.h>
24#include <memory>
25#include <tuple>
26#include <unordered_map>
27#include <vector>
28
29namespace Renderer
30{
31
32namespace Backend
33{
34
35namespace Vulkan
36{
37
38class CDevice;
39class CFramebuffer;
40class CRingCommandContext;
41class CTexture;
42
43class CSwapChain final
44{
45public:
47
48 VkSwapchainKHR GetVkSwapchain() { return m_SwapChain; }
49
50 bool IsValid() const { return m_IsValid; }
51
52 bool AcquireNextImage(VkSemaphore acquireImageSemaphore);
54 CRingCommandContext& commandContext);
56 CRingCommandContext& commandContext);
57 void Present(VkSemaphore submitDone, VkQueue queue);
58
60 const AttachmentLoadOp colorAttachmentLoadOp,
61 const AttachmentStoreOp colorAttachmentStoreOp,
62 const AttachmentLoadOp depthStencilAttachmentLoadOp,
63 const AttachmentStoreOp depthStencilAttachmentStoreOp);
64
66
68
69private:
70 friend class CDevice;
71
72 static std::unique_ptr<CSwapChain> Create(
73 CDevice* device, VkSurfaceKHR surface, int surfaceDrawableWidth, int surfaceDrawableHeight,
74 std::unique_ptr<CSwapChain> oldSwapChain);
75
77
78 CDevice* m_Device = nullptr;
79
80 bool m_IsValid = false;
81 VkSwapchainKHR m_SwapChain = VK_NULL_HANDLE;
82
83 uint32_t m_CurrentImageIndex = std::numeric_limits<uint32_t>::max();
84
85 std::vector<VkImage> m_Images;
86 std::vector<std::unique_ptr<CTexture>> m_Textures;
87 std::unique_ptr<CTexture> m_DepthTexture;
88 VkFormat m_ImageFormat = VK_FORMAT_UNDEFINED;
89
91 {
92 using BackbufferKey = std::tuple<
96 {
97 size_t operator()(const BackbufferKey& key) const;
98 };
99 std::unordered_map<
100 BackbufferKey, std::unique_ptr<CFramebuffer>, BackbufferKeyHash> backbuffers;
101
103
106
109 };
110 std::vector<SwapChainBackbuffer> m_Backbuffers;
111};
112
113} // namespace Vulkan
114
115} // namespace Backend
116
117} // namespace Renderer
118
119#endif // INCLUDED_RENDERER_BACKEND_VULKAN_SWAPCHAIN
Represents a texture object.
Definition: TextureManager.h:262
Definition: Device.h:60
Definition: Framebuffer.h:41
A simple helper class to decouple command buffers rotation from frames presenting.
Definition: RingCommandContext.h:48
Definition: SwapChain.h:44
bool m_IsValid
Definition: SwapChain.h:80
std::unique_ptr< CTexture > m_DepthTexture
Definition: SwapChain.h:87
VkSwapchainKHR GetVkSwapchain()
Definition: SwapChain.h:48
CTexture * GetDepthTexture()
Definition: SwapChain.h:67
CDevice * m_Device
Definition: SwapChain.h:78
void Present(VkSemaphore submitDone, VkQueue queue)
Definition: SwapChain.cpp:325
bool IsValid() const
Definition: SwapChain.h:50
std::vector< VkImage > m_Images
Definition: SwapChain.h:85
void SubmitCommandsAfterAcquireNextImage(CRingCommandContext &commandContext)
Definition: SwapChain.cpp:289
CFramebuffer * GetCurrentBackbuffer(const AttachmentLoadOp colorAttachmentLoadOp, const AttachmentStoreOp colorAttachmentStoreOp, const AttachmentLoadOp depthStencilAttachmentLoadOp, const AttachmentStoreOp depthStencilAttachmentStoreOp)
Definition: SwapChain.cpp:354
std::vector< SwapChainBackbuffer > m_Backbuffers
Definition: SwapChain.h:110
VkSwapchainKHR m_SwapChain
Definition: SwapChain.h:81
VkFormat m_ImageFormat
Definition: SwapChain.h:88
bool AcquireNextImage(VkSemaphore acquireImageSemaphore)
Definition: SwapChain.cpp:267
~CSwapChain()
Definition: SwapChain.cpp:240
void SubmitCommandsBeforePresent(CRingCommandContext &commandContext)
Definition: SwapChain.cpp:313
std::vector< std::unique_ptr< CTexture > > m_Textures
Definition: SwapChain.h:86
CTexture * GetCurrentBackbufferTexture()
Definition: SwapChain.cpp:388
static std::unique_ptr< CSwapChain > Create(CDevice *device, VkSurfaceKHR surface, int surfaceDrawableWidth, int surfaceDrawableHeight, std::unique_ptr< CSwapChain > oldSwapChain)
Definition: SwapChain.cpp:45
uint32_t m_CurrentImageIndex
Definition: SwapChain.h:83
Definition: Texture.h:41
AttachmentStoreOp
Store operation is set for each attachment, what should be done with its content on EndFramebufferPas...
Definition: IFramebuffer.h:52
Backend
Definition: Backend.h:28
AttachmentLoadOp
Load operation is set for each attachment, what should be done with its content on BeginFramebufferPa...
Definition: IFramebuffer.h:37
Definition: VideoMode.h:29
size_t operator()(const BackbufferKey &key) const
Definition: SwapChain.cpp:251
SwapChainBackbuffer & operator=(SwapChainBackbuffer &&other)
SwapChainBackbuffer(const SwapChainBackbuffer &)=delete
SwapChainBackbuffer & operator=(const SwapChainBackbuffer &)=delete
std::unordered_map< BackbufferKey, std::unique_ptr< CFramebuffer >, BackbufferKeyHash > backbuffers
Definition: SwapChain.h:100
std::tuple< AttachmentLoadOp, AttachmentStoreOp, AttachmentLoadOp, AttachmentStoreOp > BackbufferKey
Definition: SwapChain.h:94
unsigned int uint32_t
Definition: wposix_types.h:53
pthread_key_t key
Definition: wpthread.cpp:140