Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
RenderGraphPass.hpp
1#pragma once
2
3#include <vector>
4#include <variant>
5#include <functional>
6
7#include <Common/HashedString.hpp>
8#include <Common/Graphics/CommandBuffer.hpp>
9
10#include "GpuPassType.hpp"
11#include "RenderGraphContext.hpp"
12#include "AttachmentInfo.hpp"
13#include "BufferInfo.hpp"
14#include "RenderGraphFrameResources.hpp"
15
16namespace Grindstone::GraphicsAPI {
17 class Sampler;
18}
19
20namespace Grindstone::Renderer {
21 using UnionResourceDescription = std::variant<Grindstone::Renderer::ImageDescription, Grindstone::Renderer::BufferDescription>;
22
24 public:
25 virtual void RealizeResources(
28 ) = 0;
29 virtual void Execute(
32 ) = 0;
33
34 Grindstone::String name;
35 GpuPassType type;
36
37 std::vector<Grindstone::GraphicsAPI::ImageBarrier> imageBarriers;
38 std::vector<Grindstone::GraphicsAPI::BufferBarrier> bufferBarriers;
39
40 protected:
41
42 void SubmitBarriers(Grindstone::Renderer::RenderGraphContext& context);
43
44 };
45
47 public:
48
49 std::vector<GraphicsAPI::Sampler*> samplers;
50 std::vector<PassImageDesc> imageDescs;
51 std::vector<PassBufferDesc> bufferDescs;
52 Grindstone::GraphicsAPI::DescriptorSet* passDescriptorSet = nullptr;
53 Grindstone::GraphicsAPI::PipelineLayout* pipelineLayout = nullptr;
54
55 virtual void RealizeResources(
58 ) override;
59
60 };
61
63 public:
64
65 Grindstone::Renderer::MetaRect metaRenderingArea;
66
67 virtual Grindstone::Math::IntRect2D PrepareGraphicsPass(
70 );
71 virtual void EndGraphicsPass(Grindstone::Renderer::RenderGraphContext& context);
72
73 };
74
75 template<typename ReturnType>
77 public:
78 using ExecutionCallbackFn = std::function<void(Grindstone::Math::IntRect2D, Grindstone::Renderer::RenderGraphContext&, const Grindstone::Renderer::RenderGraphFrameResources&, ReturnType&)>;
79 ExecutionCallbackFn executionCallback;
80 ReturnType returnData;
81
82 virtual void Execute(
85 ) override {
86 GS_ASSERT_ENGINE_WITH_MESSAGE(executionCallback != nullptr, "Execution callback for rendergraph pass %s is not set.", name.c_str());
87
88 Grindstone::Math::IntRect2D renderingArea = PrepareGraphicsPass(context, frameResources);
89 executionCallback(renderingArea, context, frameResources, returnData);
90 EndGraphicsPass(context);
91 }
92
93 };
94
96 public:
97
98 protected:
99
100 void PrepareComputePass(Grindstone::Renderer::RenderGraphContext& context);
101
102 };
103
104 template<typename ReturnType>
106 public:
107 using ExecutionCallbackFn = std::function<void(Grindstone::Renderer::RenderGraphContext&, const Grindstone::Renderer::RenderGraphFrameResources&, ReturnType&)>;
108 ExecutionCallbackFn executionCallback;
109 ReturnType returnData;
110
111 virtual void Execute(
114 ) override {
115 GS_ASSERT_ENGINE_WITH_MESSAGE(executionCallback != nullptr, "Execution callback for rendergraph pass %s is not set.", name.c_str());
116
117 context.commandBuffer->BeginDebugLabelSection(name.c_str());
118 PrepareComputePass(context);
119 executionCallback(context, frameResources, returnData);
120 context.commandBuffer->EndDebugLabelSection();
121 }
122
123 };
124
128 GraphicsAPI::TextureFilter filter;
131 };
132
136 uint64_t dstOffset;
137 uint64_t srcOffset;
138 uint64_t size;
139 };
140
142 public:
143
144 virtual void RealizeResources(
147 ) override;
148 virtual void Execute(
151 ) override;
152
153 protected:
154 std::vector<ImageTransfer> imageTransfers;
155 std::vector<BufferTransfer> bufferTransfers;
156 };
157
159 public:
160 virtual void RealizeResources(
163 ) override;
164 virtual void Execute(
167 ) override;
168
169 };
170}
Definition Buffer.hpp:49
Definition DescriptorSet.hpp:15
Definition Image.hpp:49
Definition PipelineLayout.hpp:18
Definition Sampler.hpp:49
Definition RenderGraphPass.hpp:95
Definition RenderGraphPass.hpp:105
Definition RenderGraphPass.hpp:62
Definition RenderGraphPass.hpp:76
Definition RenderGraphPass.hpp:46
Definition RenderGraphPass.hpp:158
Definition RenderGraphPass.hpp:23
Definition RenderGraphPass.hpp:141
Definition Rect.hpp:77
Definition Rect.hpp:33
Definition RenderGraphPass.hpp:133
Definition RenderGraphPass.hpp:125
Definition AttachmentInfo.hpp:131
Definition RenderGraphContext.hpp:24
Definition RenderGraphFrameResources.hpp:8