Pyrogenesis  trunk
RenderPassManager.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_RENDERPASSMANAGER
19 #define INCLUDED_RENDERER_BACKEND_VULKAN_RENDERPASSMANAGER
20 
22 
23 #include <glad/vulkan.h>
24 #include <optional>
25 #include <unordered_map>
26 #include <vector>
27 
28 namespace Renderer
29 {
30 
31 namespace Backend
32 {
33 
34 namespace Vulkan
35 {
36 
37 class CDevice;
38 
39 /**
40  * A helper class to store unique render passes.
41  */
43 {
44 public:
45  CRenderPassManager(CDevice* device);
47 
48  /**
49  * @return a renderpass with required attachments. Currently we use only
50  * single subpass renderpasses.
51  * @note it should be called as rarely as possible.
52  */
53  VkRenderPass GetOrCreateRenderPass(
54  SColorAttachment* colorAttachment,
55  SDepthStencilAttachment* depthStencilAttachment);
56 
57 private:
58  CDevice* m_Device = nullptr;
59 
60  struct Attachment
61  {
62  VkFormat format;
65  };
66  struct Desc
67  {
69  std::optional<Attachment> colorAttachment;
70  std::optional<Attachment> depthStencilAttachment;
71  };
72  struct DescHash
73  {
74  size_t operator()(const Desc& desc) const;
75  };
76  struct DescEqual
77  {
78  bool operator()(const Desc& lhs, const Desc& rhs) const;
79  };
80  std::unordered_map<Desc, VkRenderPass, DescHash, DescEqual> m_RenderPassMap;
81 };
82 
83 } // namespace Vulkan
84 
85 } // namespace Backend
86 
87 } // namespace Renderer
88 
89 #endif // INCLUDED_RENDERER_BACKEND_VULKAN_RENDERPASSMANAGER
AttachmentLoadOp
Load operation is set for each attachment, what should be done with its content on BeginFramebufferPa...
Definition: IFramebuffer.h:36
VkFormat format
Definition: RenderPassManager.h:62
std::optional< Attachment > depthStencilAttachment
Definition: RenderPassManager.h:70
AttachmentStoreOp storeOp
Definition: RenderPassManager.h:64
AttachmentStoreOp
Store operation is set for each attachment, what should be done with its content on EndFramebufferPas...
Definition: IFramebuffer.h:51
CDevice * m_Device
Definition: RenderPassManager.h:58
VkRenderPass GetOrCreateRenderPass(SColorAttachment *colorAttachment, SDepthStencilAttachment *depthStencilAttachment)
Definition: RenderPassManager.cpp:100
AttachmentLoadOp loadOp
Definition: RenderPassManager.h:63
A helper class to store unique render passes.
Definition: RenderPassManager.h:42
Definition: Device.h:59
unsigned char uint8_t
Definition: wposix_types.h:51
std::optional< Attachment > colorAttachment
Definition: RenderPassManager.h:69
Definition: IFramebuffer.h:67
Backend
Definition: Backend.h:27
Definition: VideoMode.h:28
~CRenderPassManager()
Definition: RenderPassManager.cpp:89
CRenderPassManager(CDevice *device)
Definition: RenderPassManager.cpp:84
Definition: IFramebuffer.h:59
Definition: RenderPassManager.h:66
std::unordered_map< Desc, VkRenderPass, DescHash, DescEqual > m_RenderPassMap
Definition: RenderPassManager.h:80
uint8_t sampleCount
Definition: RenderPassManager.h:68