-
-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathFrameGraph.hpp
More file actions
175 lines (146 loc) · 5.86 KB
/
FrameGraph.hpp
File metadata and controls
175 lines (146 loc) · 5.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// Copyright (C) 2026 Jérôme "SirLynix" Leclercq ([email protected])
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Export.hpp
#pragma once
#ifndef NAZARA_GRAPHICS_FRAMEGRAPH_HPP
#define NAZARA_GRAPHICS_FRAMEGRAPH_HPP
#include <NazaraUtils/Prerequisites.hpp>
#include <Nazara/Graphics/BakedFrameGraph.hpp>
#include <Nazara/Graphics/Export.hpp>
#include <Nazara/Graphics/FrameGraphStructs.hpp>
#include <Nazara/Graphics/FramePass.hpp>
#include <Nazara/Graphics/FramePassAttachment.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Renderer/RenderPass.hpp>
#include <limits>
#include <optional>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <variant>
#include <vector>
namespace Nz
{
class NAZARA_GRAPHICS_API FrameGraph
{
friend class BakedFrameGraph;
public:
FrameGraph() = default;
FrameGraph(const FrameGraph&) = delete;
FrameGraph(FrameGraph&&) noexcept = default;
~FrameGraph() = default;
inline std::size_t AddAttachment(FramePassAttachment attachment);
inline std::size_t AddAttachmentArray(FramePassAttachment attachment, unsigned int layerCount);
inline std::size_t AddAttachmentArrayLayer(std::size_t attachmentId, std::size_t layerIndex);
inline std::size_t AddAttachmentCube(FramePassAttachment attachment);
inline std::size_t AddAttachmentCubeFace(std::size_t attachmentId, CubemapFace face);
inline std::size_t AddAttachmentProxy(std::string name, std::size_t attachmentId);
inline std::size_t AddAttachmentView(std::string name, std::size_t attachmentId, PixelFormat format, TexturePlaneFlags planes = {});
inline std::size_t AddDummyAttachment();
inline FramePass& AddPass(std::string name);
inline void AddOutput(std::size_t attachmentIndex);
BakedFrameGraph Bake();
inline void BindExternalTexture(std::size_t attachmentIndex, std::shared_ptr<Texture> texture);
FrameGraph& operator=(const FrameGraph&) = delete;
FrameGraph& operator=(FrameGraph&&) noexcept = default;
private:
struct PassBarriers;
inline TextureLayout GetWriteDepthStencilLayout(std::size_t attachmentIndex) const;
using BarrierList = std::vector<PassBarriers>;
using PassList = std::vector<std::size_t /*PassIndex*/>;
using AttachmentIdToPassMap = std::unordered_map<std::size_t /*resourceIndex*/, PassList /*passIndexes*/>;
using AttachmentIdToPassId = std::unordered_map<std::size_t /*attachmentId*/, std::size_t /*passId*/>;
using AttachmentIdToTextureId = std::unordered_map<std::size_t /*attachmentId*/, std::size_t /*textureId*/>;
using PassIdToPhysicalPassIndex = std::unordered_map<std::size_t /*passId*/, std::size_t /*physicalPassId*/>;
using TextureBarrier = BakedFrameGraph::TextureBarrier;
struct AttachmentArray : FramePassAttachment
{
unsigned int layerCount;
};
struct AttachmentCube : FramePassAttachment
{
};
struct AttachmentLayer
{
std::size_t attachmentId;
std::size_t layerIndex;
};
struct AttachmentProxy
{
std::size_t attachmentId;
std::string name;
};
struct AttachmentView
{
std::string name;
PixelFormat format;
TexturePlaneFlags planeFlags;
std::size_t attachmentId;
};
struct Barrier
{
std::size_t textureId;
MemoryAccessFlags access;
PipelineStageFlags stages;
TextureLayout layout;
};
struct DummyAttachment
{
};
struct PassBarriers
{
std::vector<Barrier> invalidationBarriers;
std::vector<Barrier> flushBarriers;
};
struct PhysicalPassData
{
struct Subpass
{
std::size_t passIndex;
};
std::string name;
std::vector<TextureBarrier> textureBarrier;
std::vector<Subpass> passes;
};
struct WorkData
{
std::vector<std::shared_ptr<RenderPass>> renderPasses;
std::vector<PhysicalPassData> physicalPasses;
std::vector<FrameGraphTextureData> textures;
std::vector<std::size_t> texture2DPool;
std::vector<std::size_t> texture2DArrayPool;
std::vector<std::size_t> textureCubePool;
AttachmentIdToPassId attachmentLastUse;
AttachmentIdToPassMap attachmentReadList;
AttachmentIdToPassMap attachmentWriteList;
AttachmentIdToTextureId attachmentToTextures;
BarrierList barrierList;
PassList passList;
PassIdToPhysicalPassIndex passIdToPhysicalPassIndex;
};
void AssignPhysicalPasses();
void AssignPhysicalTextures();
void BuildBarriers();
void BuildPhysicalBarriers();
void BuildPhysicalPassDependencies(std::size_t colorAttachmentCount, bool hasDepthStencilAttachment, std::vector<RenderPass::Attachment>& renderPassAttachments, std::vector<RenderPass::SubpassDescription>& subpasses, std::vector<RenderPass::SubpassDependency>& dependencies);
void BuildPhysicalPasses();
void BuildReadWriteList();
bool HasAttachment(const std::vector<FramePass::Input>& inputs, std::size_t attachmentIndex) const;
void RemoveDuplicatePasses();
std::size_t ResolveAttachmentIndex(std::size_t attachmentIndex) const;
void RegisterPassInput(std::size_t passIndex, std::size_t attachmentIndex);
std::size_t RegisterTexture(std::size_t attachmentIndex);
void ReorderPasses();
void TraverseGraph(std::size_t passIndex);
using AttachmentType = std::variant<FramePassAttachment, AttachmentProxy, AttachmentArray, AttachmentCube, AttachmentLayer, DummyAttachment, AttachmentView>;
static constexpr std::size_t InvalidAttachmentIndex = std::numeric_limits<std::size_t>::max();
static constexpr std::size_t InvalidTextureIndex = std::numeric_limits<std::size_t>::max();
std::vector<std::size_t> m_graphOutputs;
std::vector<FramePass> m_framePasses;
std::vector<AttachmentType> m_attachments;
std::unordered_map<std::size_t, std::shared_ptr<Texture>> m_externalTextures;
WorkData m_pending;
};
}
#include <Nazara/Graphics/FrameGraph.inl>
#endif // NAZARA_GRAPHICS_FRAMEGRAPH_HPP