Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
RenderGraph.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <list>
5#include <memory>
6#include <queue>
7#include <string>
8#include <unordered_map>
9#include <unordered_set>
10
11template <typename TRenderPass>
12concept CRenderPass = std::is_base_of_v<Graphic::Resource::ARenderPass, TRenderPass>;
13
14namespace Graphic::Resource {
15
17 private:
18 using ID = entt::hashed_string;
19
20 struct IDHash {
21 std::size_t operator()(const ID &id) const noexcept { return std::hash<std::size_t>{}(id.value()); }
22 };
23
24 public:
25 RenderGraph(void) = default;
26 ~RenderGraph() = default;
27
28 RenderGraph(const RenderGraph &) = delete;
29 RenderGraph &operator=(const RenderGraph &) = delete;
30
31 RenderGraph(RenderGraph &&) = default;
33
34 template <CRenderPass TRenderPass> void Add(std::string_view name, TRenderPass &&renderPass)
35 {
36 ID id = GetID(name);
37 if (_renderPasses.contains(id))
38 {
40 fmt::format("RenderGraph: Render pass with name '{}' already exists. Skipping addition.", name));
41 return;
42 }
43 Log::Debug(fmt::format("RenderGraph: Added render pass '{}'.", name));
44 _renderPasses[id] = std::make_shared<TRenderPass>(std::forward<TRenderPass>(renderPass));
45 _orderedIDs.push_back(id);
46 }
47
48 void Remove(std::string_view name);
49 void Execute(Engine::Core &core);
50 bool Contains(std::string_view name) const;
51 void SetDependency(std::string_view nameBefore, std::string_view nameAfter);
52
53 private:
54 static ID GetID(std::string_view name) { return entt::hashed_string(name.data(), name.size()); }
55
56 void Update(void);
57 void TopologicalSort(void);
58 void ProcessDependencies(ID current, std::queue<ID> &queue, std::unordered_map<ID, size_t, IDHash> &inDegree) const;
59
60 bool _dirty = false;
61 std::unordered_map<ID, std::shared_ptr<ARenderPass>, IDHash> _renderPasses;
62 std::unordered_map<ID, std::unordered_set<ID, IDHash>, IDHash> _dependencies;
63 std::list<ID> _orderedIDs;
64};
65
66} // namespace Graphic::Resource
The core is the place where all the data of the engine is stored. It contains the registry (entities)...
Definition Core.hpp:33
RenderGraph & operator=(const RenderGraph &)=delete
void ProcessDependencies(ID current, std::queue< ID > &queue, std::unordered_map< ID, size_t, IDHash > &inDegree) const
Definition RenderGraph.cpp:127
void Execute(Engine::Core &core)
Definition RenderGraph.cpp:25
void Update(void)
Definition RenderGraph.cpp:70
void SetDependency(std::string_view nameBefore, std::string_view nameAfter)
Definition RenderGraph.cpp:42
bool _dirty
Definition RenderGraph.hpp:60
void TopologicalSort(void)
Definition RenderGraph.cpp:77
RenderGraph(RenderGraph &&)=default
void Remove(std::string_view name)
Definition RenderGraph.cpp:7
RenderGraph & operator=(RenderGraph &&)=default
void Add(std::string_view name, TRenderPass &&renderPass)
Definition RenderGraph.hpp:34
std::list< ID > _orderedIDs
Definition RenderGraph.hpp:63
static ID GetID(std::string_view name)
Definition RenderGraph.hpp:54
entt::hashed_string ID
Definition RenderGraph.hpp:18
std::unordered_map< ID, std::shared_ptr< ARenderPass >, IDHash > _renderPasses
Definition RenderGraph.hpp:61
std::unordered_map< ID, std::unordered_set< ID, IDHash >, IDHash > _dependencies
Definition RenderGraph.hpp:62
RenderGraph(const RenderGraph &)=delete
bool Contains(std::string_view name) const
Definition RenderGraph.cpp:41
Definition RenderGraph.hpp:12
Definition AGPUBuffer.hpp:6
void Warning(const T &msg) noexcept
Definition Logger.hpp:49
void Debug(const T &msg) noexcept
Definition Logger.hpp:45
Definition RenderGraph.hpp:20
std::size_t operator()(const ID &id) const noexcept
Definition RenderGraph.hpp:21