CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
RenderTask.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Forward.hpp"
13
14#include "RenderGraphSlot.hpp"
15
17
21
27
28namespace CeresEngine {
29
30 struct RenderTaskResourceUsage;
31 class RenderTaskCompiler;
32
39 };
40
43
46
66
69
72
75
81
84
90
93
94 public:
98 [[nodiscard]] bool uses(const RenderResource& resource) const;
99
103 [[nodiscard]] bool reads(const RenderResource& resource) const;
104
108 [[nodiscard]] bool writes(const RenderResource& resource) const;
109
114
119
123 [[nodiscard]] bool realizes(const RenderResource& resource) const;
124
128 [[nodiscard]] bool unrealizes(const RenderResource& resource) const;
129
131 [[nodiscard]] RenderResource& getResource(const Slot& slot) const;
132
133 // [[nodiscard]] ImageRenderResource& getImage(const Slot& slot) const {
134 // return static_cast<ImageRenderResource&>(getResource(slot));
135 // }
136 //
137 // [[nodiscard]] BufferRenderResource& getBuffer(const Slot& slot) const {
138 // return static_cast<BufferRenderResource&>(getResource(slot));
139 // }
140 };
141
157
163
164 class RenderTask : public RefCounted<RenderTask> {
165 friend class RenderGraph;
166 friend class Slot;
167 friend class InputSlot;
168 friend class OutputSlot;
169
170 private:
172
175
176 protected:
178
179 public:
181 virtual ~RenderTask();
182
183 public:
186
189 virtual void execute(RenderGraphContext& context, GPUCommandBuffer& commandBuffer) = 0;
190
192 [[nodiscard]] virtual StringView getName() const { return StringView(); }
193
196
197 protected:
200
201 public:
203 [[nodiscard]] virtual Any getSettings() const { return const_cast<RenderTask*>(this)->getSettings(); }
204
206 [[nodiscard]] virtual Any getSettings() { return {}; }
207
209 const Vector<InputSlot*>& getInputs() const { return mInputs; }
210
212 const Vector<OutputSlot*>& getOutputs() const { return mOutputs; }
213
214 protected:
217 [[nodiscard]] virtual bool shouldConnect(const Slot& slot, const Slot& targetSlot) const { return true; }
218
220 virtual void willConnect(Slot& slot, Slot& targetSlot) {}
221
223 virtual void didConnect(Slot& slot, Connection& connection);
224
227 [[nodiscard]] virtual bool shouldDisconnect(const Slot& slot, const Connection& connection) const { return true; }
228
230 virtual void willDisconnect(Slot& slot, Connection& connection) {}
231
233 virtual void didDisconnect(Slot& slot, Connection& connection);
234
235 public:
237
238 protected:
241 };
242
286
287 // ---------------------------------------------------------------------------------------------
288
290 protected:
293
296
297 public:
299
300 public:
302 void execute(RenderGraphContext& context, GPUCommandBuffer& commandBuffer) override;
303
304 protected:
308 virtual void execute(RenderGraphContext& context, GPUCommandBuffer& commandBuffer, GPURenderTarget& renderTarget) = 0;
309
310 protected:
315 [[nodiscard]] virtual bool isRenderPassDirty(GPURenderPass& renderPass) const;
316
320
321 protected:
329
335 };
336
339 private:
342
344 bool mInitialized = false;
345
346 protected:
349
350 public:
352
353 public:
355
357 void execute(RenderGraphContext& context, GPUCommandBuffer& commandBuffer, GPURenderTarget& renderTarget) override;
358
360 [[nodiscard]] StringView getName() const override { return mName; }
361
362 protected:
365 virtual void initialize(GPUDevice& device) {}
366
372
373 protected:
380 [[nodiscard]] virtual bool isGraphicsPipelineDirty(GPUGraphicsPipeline& graphicsPipeline, GPURenderPass& renderPass) const { return false; }
381
388 };
389
390 // ---------------------------------------------------------------------------------------------
391
394 private:
397
399 bool mInitialized = false;
400
401 protected:
404
407
408 public:
410
411 public:
413
415 void execute(RenderGraphContext& context, GPUCommandBuffer& commandBuffer, GPURenderTarget& renderTarget) override;
416
418 [[nodiscard]] StringView getName() const override { return mName; }
419
420 protected:
423 virtual void initialize(GPUDevice& device) {}
424
430
431 protected:
438 [[nodiscard]] virtual bool isShaderDirty(RendererShader& shader, GPURenderPass& renderPass) const { return false; }
439
447
454 [[nodiscard]] virtual bool isGraphicsPipelineDirty(RendererGraphicsPipeline& graphicsPipeline, GPURenderPass& renderPass) const { return false; }
455
463 RendererShader& shader, GPURenderPass& renderPass) = 0;
464 };
465
466 // ---------------------------------------------------------------------------------------------
467
469 public:
471 };
472
474 private:
477
480
482 bool mInitialized = false;
483
484 public:
486
487 public:
489 void execute(RenderGraphContext& context, GPUCommandBuffer& commandBuffer) override;
490
492 [[nodiscard]] StringView getName() const override { return mName; }
493
494 protected:
497 virtual void initialize(GPUDevice& device) {}
498
502 virtual void execute(RenderGraphContext& context, GPUCommandBuffer& commandBuffer, GPUComputePipeline& pipeline) = 0;
503
504 protected:
509 [[nodiscard]] virtual bool isComputePipelineDirty(GPUComputePipeline& computePipeline) const { return false; }
510
515 };
516
517 // ---------------------------------------------------------------------------------------------
518
520 public:
522 ImageInput image{this, "image"};
523
524 public:
527
530 void execute(RenderGraphContext& context, GPUCommandBuffer& commandBuffer) final;
531 };
532
533} // namespace CeresEngine
Definition Any.hpp:13
Definition RenderResource.hpp:193
Definition RenderTask.hpp:468
A class that describes the connection between an input and an output slot.
Definition RenderGraphSlot.hpp:188
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
Definition GPUCommandBuffer.hpp:77
Definition GPUComputePipeline.hpp:62
Definition GPUDevice.hpp:357
Definition GPUGraphicsPipeline.hpp:790
Definition GPURenderPass.hpp:149
Definition GPURenderTarget.hpp:105
Definition RenderTask.hpp:289
virtual GPURenderTargetPtr createRenderTarget(GPUDevice &device, GPURenderPass &renderPass)
Creates a new render target instance for the render task.
GPURenderPassPtr mRenderPass
The cached render pass instance.
Definition RenderTask.hpp:292
virtual bool isRenderTargetDirty(GPURenderTarget &renderTarget, GPURenderPass &renderPass) const
Checks if the render target is dirty and needs to be recreated.
virtual GPURenderPassPtr createRenderPass(GPUDevice &device)
Creates a new render pass instance for the render task.
GPURenderTargetPtr mRenderTarget
The cached render target instance.
Definition RenderTask.hpp:295
void execute(RenderGraphContext &context, GPUCommandBuffer &commandBuffer) override
virtual bool isRenderPassDirty(GPURenderPass &renderPass) const
Checks if the render pass is dirty and needs to be recreated.
virtual void execute(RenderGraphContext &context, GPUCommandBuffer &commandBuffer, GPURenderTarget &renderTarget)=0
Executes the graphics render task with the given commandBuffer and renderTarget.
Definition RenderResource.hpp:114
A slot that inputs a resource. Can be connected to a single output.
Definition RenderGraphSlot.hpp:127
A slot that outputs a resource. Can be connected to multiple input slots.
Definition RenderGraphSlot.hpp:159
Definition RenderTask.hpp:519
void execute(RenderGraphContext &context, GPUCommandBuffer &commandBuffer) final
Executes the render task with the given commandBuffer.
void compile(RenderTaskCompiler &compiler) final
Compiles the render task.
ImageInput image
The image to be presented by the task.
Definition RenderTask.hpp:522
A simple reference counter base class.
Definition SmartPtr.hpp:438
Definition RenderGraph.hpp:23
Definition RenderResource.hpp:27
Definition RenderTask.hpp:243
RenderTaskCompiler & addColorAttachment(ImageRenderResource &image, GPUAttachmentLoadOp loadOp=GPUAttachmentLoadOp::Load, GPUAttachmentStoreOp storeOp=GPUAttachmentStoreOp::Store)
Adds a new resource that will be used as a color attachment in a render pass.
RenderTaskCompiler & writes(RenderResource &resource)
Adds a new resource that will be used for writing in a shader.
RenderTaskResourceUsage & mResourceUsage
Definition RenderTask.hpp:245
RenderTaskCompiler(RenderTaskResourceUsage &resourceUsage)
Definition RenderTask.hpp:248
RenderTaskCompiler & setStencilAttachment(ImageRenderResource &image, GPUAttachmentLoadOp loadOp=GPUAttachmentLoadOp::Load, GPUAttachmentStoreOp storeOp=GPUAttachmentStoreOp::Store)
Sets a resource that will be used as stencil attachment in a render pass.
RenderTaskCompiler & setDepthAttachment(ImageRenderResource &image, GPUAttachmentLoadOp loadOp=GPUAttachmentLoadOp::Load, GPUAttachmentStoreOp storeOp=GPUAttachmentStoreOp::Store)
Sets a resource that will be used as depth attachment in a render pass.
RenderTaskCompiler & reads(RenderResource &resource)
Adds a new resource that will be used for reading in a shader.
Definition RenderTask.hpp:164
const RenderTaskResourceUsage & getResourceUsage() const
Definition RenderTask.hpp:236
const Vector< OutputSlot * > & getOutputs() const
Definition RenderTask.hpp:212
virtual void compile(RenderTaskCompiler &compiler)=0
Compiles the render task.
RenderTask(RenderGraph &renderGraph)
Definition RenderTask.hpp:180
virtual RenderTaskStatus check() const
Returns true if the task is dirty and needs to be run.
Definition RenderTask.hpp:195
virtual Any getSettings() const
Gets a const-reference to the render task settings.
Definition RenderTask.hpp:203
RenderTaskResourceUsage & compile()
Compiles the render task.
RenderGraph & mRenderGraph
Definition RenderTask.hpp:171
Vector< OutputSlot * > mOutputs
Definition RenderTask.hpp:174
virtual bool shouldConnect(const Slot &slot, const Slot &targetSlot) const
An internal method called whenever a new connection is being made.
Definition RenderTask.hpp:217
Vector< InputSlot * > mInputs
Definition RenderTask.hpp:173
virtual bool shouldDisconnect(const Slot &slot, const Connection &connection) const
An internal method called whenever a new disconnection is being made.
Definition RenderTask.hpp:227
ImageRenderResource & create(const GPUImageDescriptor &descriptor)
BufferRenderResource & create(const GPUBufferDescriptor &descriptor)
RenderTaskResourceUsage mResourceUsage
Definition RenderTask.hpp:177
virtual void didDisconnect(Slot &slot, Connection &connection)
An internal method called whenever the slot is disconnected.
const Vector< InputSlot * > & getInputs() const
Definition RenderTask.hpp:209
virtual void willDisconnect(Slot &slot, Connection &connection)
An internal method called before the slot is disconnected.
Definition RenderTask.hpp:230
virtual Any getSettings()
Gets a reference to the render task settings.
Definition RenderTask.hpp:206
virtual void willConnect(Slot &slot, Slot &targetSlot)
An internal method called before the slot is connected.
Definition RenderTask.hpp:220
virtual void didConnect(Slot &slot, Connection &connection)
An internal method called after the slot is connected.
virtual StringView getName() const
Returns a display name for the render task.
Definition RenderTask.hpp:192
virtual void execute(RenderGraphContext &context, GPUCommandBuffer &commandBuffer)=0
Executes the render task with the given commandBuffer.
A renderer graphics pipeline.
Definition RendererGraphicsPipeline.hpp:60
The renderer graphics pipeline manager that is responsible for managing and re-using GPU graphics pip...
Definition RendererGraphicsPipeline.hpp:182
The CeresEngine renderer.
Definition Renderer.hpp:35
A renderer shader.
Definition RendererShader.hpp:44
The renderer shader manager that is responsible for managing and re-using GPU shaders.
Definition RendererShader.hpp:85
Definition RenderTask.hpp:473
virtual bool isComputePipelineDirty(GPUComputePipeline &computePipeline) const
Checks if the compute pipeline is dirty and needs to be recreated.
Definition RenderTask.hpp:509
StringView getName() const override
Returns a display name for the render task.
Definition RenderTask.hpp:492
bool mInitialized
A flag that indicates if the render task initializer has been called.
Definition RenderTask.hpp:482
SimpleComputeRenderTask(RenderGraph &renderGraph, const String &name)
Definition RenderTask.hpp:485
virtual void execute(RenderGraphContext &context, GPUCommandBuffer &commandBuffer, GPUComputePipeline &pipeline)=0
Executes the compute render task with the given commandBuffer, pipeline and renderTarget.
void execute(RenderGraphContext &context, GPUCommandBuffer &commandBuffer) override
virtual void initialize(GPUDevice &device)
Perform a sequence of steps that initialize the compute render task.
Definition RenderTask.hpp:497
virtual GPUComputePipelinePtr createComputePipeline(GPUDevice &device)=0
Creates a new compute pipeline instance for the render task.
GPUComputePipelinePtr mPipeline
The cached compute pipeline instance.
Definition RenderTask.hpp:479
String mName
A display name for the render task.
Definition RenderTask.hpp:476
A simple graphics task that makes easier implementing tasks that use a single graphics pipeline.
Definition RenderTask.hpp:393
bool mInitialized
A flag that indicates if the render task initializer has been called.
Definition RenderTask.hpp:399
RendererGraphicsPipelinePtr mPipeline
The cached graphics pipeline instance.
Definition RenderTask.hpp:406
StringView getName() const override
Returns a display name for the render task.
Definition RenderTask.hpp:418
virtual RendererShaderPtr createShader(RendererShaderManager &shaderManager, GPURenderPass &renderPass)=0
Creates a new shader instance for the render task.
void execute(RenderGraphContext &context, GPUCommandBuffer &commandBuffer, GPURenderTarget &renderTarget) override
RendererShaderPtr mShader
The cached graphics pipeline instance.
Definition RenderTask.hpp:403
String mName
A display name for the render task.
Definition RenderTask.hpp:396
virtual RendererGraphicsPipelinePtr createGraphicsPipeline(RendererGraphicsPipelineManager &graphicsPipelineManager, RendererShader &shader, GPURenderPass &renderPass)=0
Creates a new graphics pipeline instance for the render task.
SimpleGraphicsRenderTask2(RenderGraph &renderGraph, const String &name)
Definition RenderTask.hpp:409
virtual bool isShaderDirty(RendererShader &shader, GPURenderPass &renderPass) const
Checks if the shader is dirty and needs to be recreated.
Definition RenderTask.hpp:438
virtual void initialize(GPUDevice &device)
Perform a sequence of steps that initialize the graphics render task.
Definition RenderTask.hpp:423
virtual bool isGraphicsPipelineDirty(RendererGraphicsPipeline &graphicsPipeline, GPURenderPass &renderPass) const
Checks if the graphics pipeline is dirty and needs to be recreated.
Definition RenderTask.hpp:454
virtual void execute(RenderGraphContext &context, GPUCommandBuffer &commandBuffer, GPURenderTarget &renderTarget, RendererGraphicsPipeline &pipeline)=0
Executes the graphics render task with the given commandBuffer, pipeline and renderTarget.
A simple graphics task that makes easier implementing tasks that use a single graphics pipeline.
Definition RenderTask.hpp:338
bool mInitialized
A flag that indicates if the render task initializer has been called.
Definition RenderTask.hpp:344
virtual GPUGraphicsPipelinePtr createGraphicsPipeline(GPUDevice &device, GPURenderPass &renderPass)=0
Creates a new graphics pipeline instance for the render task.
String mName
A display name for the render task.
Definition RenderTask.hpp:341
void execute(RenderGraphContext &context, GPUCommandBuffer &commandBuffer, GPURenderTarget &renderTarget) override
virtual void execute(RenderGraphContext &context, GPUCommandBuffer &commandBuffer, GPURenderTarget &renderTarget, GPUGraphicsPipeline &pipeline)=0
Executes the graphics render task with the given commandBuffer, pipeline and renderTarget.
virtual bool isGraphicsPipelineDirty(GPUGraphicsPipeline &graphicsPipeline, GPURenderPass &renderPass) const
Checks if the graphics pipeline is dirty and needs to be recreated.
Definition RenderTask.hpp:380
virtual void initialize(GPUDevice &device)
Perform a sequence of steps that initialize the graphics render task.
Definition RenderTask.hpp:365
StringView getName() const override
Returns a display name for the render task.
Definition RenderTask.hpp:360
SimpleGraphicsRenderTask(RenderGraph &renderGraph, const String &name)
Definition RenderTask.hpp:351
GPUGraphicsPipelinePtr mPipeline
The cached graphics pipeline instance.
Definition RenderTask.hpp:348
A render task slot.
Definition RenderGraphSlot.hpp:23
Definition Application.hpp:19
GPUAttachmentLoadOp
Enumeration for render pass attachment load operations.
Definition GPURenderPass.hpp:32
@ Clear
Clear the previous content of the respective render target attachment.
@ Load
Loads the previous content of the respective render target attachment.
BasicStringView< char > StringView
Narrow string view used for handling narrow encoded text in UTF-8.
Definition String.hpp:190
GPUImageLayout
Definition GPUImage.hpp:65
GPUAttachmentStoreOp
Enumeration for render pass attachment store operations.
Definition GPURenderPass.hpp:48
@ Store
Stores the outcome in the respective render target attachment.
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
RenderTaskStatus
Definition RenderTask.hpp:158
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Hardware buffer descriptor structure.
Definition GPUBuffer.hpp:92
Definition GPUImage.hpp:247
A context structure that holds context for a render graph pass.
Definition RenderTask.hpp:143
Renderer & renderer
The renderer that is executing the render graph.
Definition RenderTask.hpp:145
RenderGraphContext(Renderer &renderer, GPUDevice &device)
Creates a new context for a render graph execution.
Definition RenderTask.hpp:155
GPUStorageBufferPool storageBuffers
A storage buffer pool.
Definition RenderTask.hpp:151
GPUUniformBufferPool uniformBuffers
A uniform buffer pool.
Definition RenderTask.hpp:148
A structure that describes a attachment resource.
Definition RenderTask.hpp:48
ImageRenderResource * resource
The resource that will be used as an attachment.
Definition RenderTask.hpp:50
GPUImageLayout finalLayout
The required final layout for the attachment resource image.
Definition RenderTask.hpp:64
GPUImageLayout initialLayout
The required initial layout for the attachment resource image.
Definition RenderTask.hpp:60
GPUAttachmentStoreOp storeOp
The attachment store operation to be used for the render pass.
Definition RenderTask.hpp:56
GPUAttachmentLoadOp loadOp
The attachment load operation to be used for the render pass.
Definition RenderTask.hpp:53
A structure that describes a resource realization.
Definition RenderTask.hpp:77
RenderResource * resource
The resource that will be realized.
Definition RenderTask.hpp:79
A structure that describes a shader resource.
Definition RenderTask.hpp:36
RenderResource * resource
The resource that will be used by a shader.
Definition RenderTask.hpp:38
A structure that describes a resource unrealization.
Definition RenderTask.hpp:86
RenderResource * resource
The resource that will be unrealized.
Definition RenderTask.hpp:88
A structure that describes how and what resources are used by a render task.
Definition RenderTask.hpp:34
bool uses(const RenderResource &resource) const
Checks if the given resource is used by the render task.
bool writes(const RenderResource &resource) const
Checks if the given resource is written in a shader by the render task.
Vector< UnrealizedResourceInfo > unrealizations
A list of resources that will be unrealized for this task.
Definition RenderTask.hpp:92
bool realizes(const RenderResource &resource) const
Checks if a resource is realized for this render task.
bool unrealizes(const RenderResource &resource) const
Checks if a resource is unrealized for this render task.
RenderResource & getResource(const Slot &slot) const
Gets the current resource instance for the given slot.
Vector< AttachmentResourceInfo > colorAttachments
A list of resources that are used as color attachments.
Definition RenderTask.hpp:68
const AttachmentResourceInfo * getAttachmentInfo(const ImageRenderResource &resource) const
Finds the AttachmentResourceInfo structure for the attachment using resource.
bool reads(const RenderResource &resource) const
Checks if the given resource is read in a shader by the render task.
Vector< ShaderResourceInfo > shaderWrites
A list of resources that are written by shaders.
Definition RenderTask.hpp:45
const AttachmentResourceInfo * getAttachmentInfo(UInt32 attachmentIdx) const
Finds the AttachmentResourceInfo structure for the attachment at index attachmentIdx
AttachmentResourceInfo depthAttachment
A resource that is used as depth attachment.
Definition RenderTask.hpp:71
Vector< RealizedResourceInfo > realizations
A list of resources that will be realized for this task.
Definition RenderTask.hpp:83
Vector< ShaderResourceInfo > shaderReads
A list of resources that are read by shaders.
Definition RenderTask.hpp:42
AttachmentResourceInfo stencilAttachment
A resource that is used as stencil attachment.
Definition RenderTask.hpp:74