Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
RenderGraphBuilderPass.hpp
1#pragma once
2
3#include <vector>
4#include <functional>
5
6#include <Common/HashedString.hpp>
7#include "RenderGraphContext.hpp"
8#include "RenderGraphPass.hpp"
9#include "GpuPassType.hpp"
10#include "AttachmentInfo.hpp"
11#include "BufferInfo.hpp"
12
13namespace Grindstone::GraphicsAPI {
14 class Sampler;
15}
16
17namespace Grindstone::Renderer {
19
21 public:
22 Grindstone::String name;
23 PassId passIndex;
24 GpuPassType type;
25
26 Grindstone::Renderer::RenderGraphBuilder* renderGraphBuilder = nullptr;
27
28 std::vector<GraphicsAPI::Sampler*> samplers;
29 std::vector<PassBufferDesc> bufferRefs;
30 std::vector<PassImageDesc> imageRefs;
31
32 virtual Grindstone::UniquePtr<RenderGraphPass> ConstructExecutionPass() const = 0;
33 };
34
36 public:
37 void ReadExternalSampler(Grindstone::GraphicsAPI::Sampler* sampler);
38 void ReadSampledImage(RenderGraphBuilderResourceRef inputHandle);
39 void ReadBuffer(RenderGraphBuilderResourceRef inputHandle);
42 };
43
45 public:
46 RenderGraphBuilderResourceRef ReadWriteColorAttachment(RenderGraphBuilderResourceRef inputHandle);
47 RenderGraphBuilderResourceRef WriteColorAttachment(ImageDescription resource, Grindstone::GraphicsAPI::LoadOp loadOp, Grindstone::GraphicsAPI::ClearColor clearValue);
48 RenderGraphBuilderResourceRef WriteColorAttachment(RenderGraphBuilderResourceRef ref, Grindstone::GraphicsAPI::LoadOp loadOp, Grindstone::GraphicsAPI::ClearColor clearValue);
49
50 void ReadDepthAttachment(RenderGraphBuilderResourceRef inputHandle);
51 void ReadDepthAttachmentSampled(RenderGraphBuilderResourceRef inputHandle);
52 RenderGraphBuilderResourceRef ReadWriteDepthStencilAttachment(RenderGraphBuilderResourceRef inputHandle);
53 RenderGraphBuilderResourceRef WriteDepthStencilAttachment(ImageDescription resource, Grindstone::GraphicsAPI::LoadOp loadOp, Grindstone::GraphicsAPI::ClearDepthStencil clearValue);
54 Grindstone::Renderer::RenderGraphBuilderResourceRef WriteDepthStencilAttachment(RenderGraphBuilderResourceRef resource, Grindstone::GraphicsAPI::LoadOp loadOp, Grindstone::GraphicsAPI::ClearDepthStencil clearValue);
55
56 protected:
57
58 MetaRect renderingArea;
59
60 };
61
62 template<typename ReturnType>
64 public:
65 using ExecutionCallbackFn = std::function<void(Grindstone::Math::IntRect2D, Grindstone::Renderer::RenderGraphContext&, const Grindstone::Renderer::RenderGraphFrameResources&, ReturnType&)>;
66
67 void SetRenderingArea(
68 MetaRect renderingArea
69 ) {
70 this->renderingArea = renderingArea;
71 }
72
73 void SetExecutionCallback(ExecutionCallbackFn callback) {
74 executionCallback = callback;
75 }
76
77 virtual Grindstone::UniquePtr<RenderGraphPass> ConstructExecutionPass() const override {
78 auto pass = Grindstone::Memory::AllocatorCore::AllocateUnique<GraphicsRenderGraphPass<ReturnType>>();
79 pass->name = name;
80 pass->type = type;
81 pass->executionCallback = executionCallback;
82 pass->metaRenderingArea = renderingArea;
83 pass->samplers = samplers;
84 pass->returnData = returnData;
85 pass->imageDescs = imageRefs;
86 pass->bufferDescs = bufferRefs;
87 return pass;
88 }
89
90 ReturnType returnData;
91 ExecutionCallbackFn executionCallback;
92
93 };
94
96 public:
97
98 void ReadStorageImage(RenderGraphBuilderResourceRef inputHandle);
99 RenderGraphBuilderResourceRef ReadWriteStorageImage(RenderGraphBuilderResourceRef inputHandle);
100 RenderGraphBuilderResourceRef WriteStorageImage(ImageDescription resource);
101
102 };
103
104 template<typename ReturnType>
106 public:
107 using ExecutionCallbackFn = std::function<void(Grindstone::Renderer::RenderGraphContext&, const Grindstone::Renderer::RenderGraphFrameResources& frameResources, ReturnType&)>;
108
109 void SetExecutionCallback(ExecutionCallbackFn callback) {
110 executionCallback = callback;
111 }
112
113 virtual Grindstone::UniquePtr<RenderGraphPass> ConstructExecutionPass() const override {
114 auto pass = Grindstone::Memory::AllocatorCore::AllocateUnique<ComputeRenderGraphPass<ReturnType>>();
115 pass->name = name;
116 pass->type = type;
117 pass->executionCallback = executionCallback;
118 pass->samplers = samplers;
119 pass->returnData = returnData;
120 pass->imageDescs = imageRefs;
121 pass->bufferDescs = bufferRefs;
122 return pass;
123 }
124
125 ReturnType returnData;
126 ExecutionCallbackFn executionCallback;
127
128 };
129
133 GraphicsAPI::TextureFilter filter;
136 };
137
141 uint64_t dstOffset;
142 uint64_t srcOffset;
143 uint64_t size;
144 };
145
147 public:
148 virtual void AddImageTransfer(BuilderImageTransfer transfer);
149 virtual void AddBufferTransfer(BuilderBufferTransfer transfer);
150
151 virtual Grindstone::UniquePtr<RenderGraphPass> ConstructExecutionPass() const override {
152 auto pass = Grindstone::Memory::AllocatorCore::AllocateUnique<TransferRenderGraphPass>();
153 pass->name = name;
154 pass->type = type;
155 return pass;
156 }
157
158 std::vector<BuilderImageTransfer> imageTransfers;
159 std::vector<BuilderBufferTransfer> bufferTransfers;
160 };
161
163 public:
164 virtual void SetPresentationImage(RenderGraphBuilderResourceRef targetImage);
165
166 virtual Grindstone::UniquePtr<RenderGraphPass> ConstructExecutionPass() const override {
167 auto pass = Grindstone::Memory::AllocatorCore::AllocateUnique<PresentRenderGraphPass>();
168 pass->name = name;
169 pass->type = type;
170 return pass;
171 }
172
173 protected:
175
176 };
177
178}
Definition Sampler.hpp:49
Definition RenderGraphBuilderPass.hpp:95
Definition RenderGraphBuilderPass.hpp:105
Definition RenderGraphBuilderPass.hpp:44
Definition RenderGraphBuilderPass.hpp:63
Definition RenderGraphBuilderPass.hpp:35
Definition RenderGraphBuilderPass.hpp:162
Definition RenderGraphBuilderPass.hpp:20
Definition RenderGraphBuilder.hpp:12
Definition RenderGraphBuilderPass.hpp:146
Definition UniquePtr.hpp:7
Definition Rect.hpp:77
Definition Rect.hpp:33
Definition BufferInfo.hpp:12
Definition RenderGraphBuilderPass.hpp:138
Definition RenderGraphBuilderPass.hpp:130
Definition AttachmentInfo.hpp:226
Definition AttachmentInfo.hpp:131
Definition RenderGraphResourceRef.hpp:51
Definition RenderGraphContext.hpp:24
Definition RenderGraphFrameResources.hpp:8
Definition Formats.hpp:14