Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
RenderPassManager.h
Go to the documentation of this file.
1/* Copyright (C) 2026 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 <cstddef>
24#include <cstdint>
25#include <glad/vulkan.h>
26#include <optional>
27#include <unordered_map>
28
29namespace Renderer::Backend { enum class AttachmentLoadOp; }
30namespace Renderer::Backend { enum class AttachmentStoreOp; }
31namespace Renderer::Backend { struct SColorAttachment; }
32namespace Renderer::Backend { struct SDepthStencilAttachment; }
33namespace Renderer::Backend::Vulkan { class CDevice; }
34
35namespace Renderer
36{
37
38namespace Backend
39{
40
41namespace Vulkan
42{
43
44/**
45 * A helper class to store unique render passes.
46 */
48{
49public:
52
53 /**
54 * @return a renderpass with required attachments. Currently we use only
55 * single subpass renderpasses.
56 * @note it should be called as rarely as possible.
57 */
58 VkRenderPass GetOrCreateRenderPass(
59 SColorAttachment* colorAttachment,
60 SDepthStencilAttachment* depthStencilAttachment);
61
62 void CollectStatistics(IDevice::StatisticsVector& statistics) const;
63
64private:
65 CDevice* m_Device = nullptr;
66
68 {
69 VkFormat format;
72 };
73 struct Desc
74 {
75 uint8_t sampleCount;
76 std::optional<Attachment> colorAttachment;
77 std::optional<Attachment> depthStencilAttachment;
78 };
79 struct DescHash
80 {
81 size_t operator()(const Desc& desc) const;
82 };
83 struct DescEqual
84 {
85 bool operator()(const Desc& lhs, const Desc& rhs) const;
86 };
87 std::unordered_map<Desc, VkRenderPass, DescHash, DescEqual> m_RenderPassMap;
88};
89
90} // namespace Vulkan
91
92} // namespace Backend
93
94} // namespace Renderer
95
96#endif // INCLUDED_RENDERER_BACKEND_VULKAN_RENDERPASSMANAGER
std::vector< StatisticsItem > StatisticsVector
Definition: IDevice.h:228
Definition: Device.h:67
A helper class to store unique render passes.
Definition: RenderPassManager.h:48
CDevice * m_Device
Definition: RenderPassManager.h:65
CRenderPassManager(CDevice *device)
Definition: RenderPassManager.cpp:89
VkRenderPass GetOrCreateRenderPass(SColorAttachment *colorAttachment, SDepthStencilAttachment *depthStencilAttachment)
Definition: RenderPassManager.cpp:105
~CRenderPassManager()
Definition: RenderPassManager.cpp:94
std::unordered_map< Desc, VkRenderPass, DescHash, DescEqual > m_RenderPassMap
Definition: RenderPassManager.h:87
void CollectStatistics(IDevice::StatisticsVector &statistics) const
Definition: RenderPassManager.cpp:201
Definition: Buffer.cpp:37
Definition: Canvas2D.h:30
AttachmentStoreOp
Store operation is set for each attachment, what should be done with its content on EndFramebufferPas...
Definition: IFramebuffer.h:54
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:39
Definition: Canvas2D.h:30
Definition: IFramebuffer.h:62
Definition: IFramebuffer.h:70
VkFormat format
Definition: RenderPassManager.h:69
AttachmentStoreOp storeOp
Definition: RenderPassManager.h:71
AttachmentLoadOp loadOp
Definition: RenderPassManager.h:70
bool operator()(const Desc &lhs, const Desc &rhs) const
Definition: RenderPassManager.cpp:69
size_t operator()(const Desc &desc) const
Definition: RenderPassManager.cpp:43
Definition: RenderPassManager.h:74
std::optional< Attachment > colorAttachment
Definition: RenderPassManager.h:76
std::optional< Attachment > depthStencilAttachment
Definition: RenderPassManager.h:77
uint8_t sampleCount
Definition: RenderPassManager.h:75