CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
GPUComputePipeline.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 "Common.hpp"
11#include "Forward.hpp"
12
14
18
19#include <functional>
20#include <utility>
21
22namespace CeresEngine {
23
28 GPUShaderProgramPtr shaderProgram = nullptr;
29
34 GPUPipelineLayoutPtr pipelineLayout = nullptr;
35
39 String name;
40
42 GPUComputePipelineDescriptor() noexcept = default;
43
46 inline explicit GPUComputePipelineDescriptor(GPUShaderProgramPtr shaderProgram, GPUPipelineLayoutPtr pipelineLayout = nullptr) noexcept
47 : shaderProgram(std::move(shaderProgram)), pipelineLayout(std::move(pipelineLayout)) {}
48
51 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
52 CE_REFL_DATA(shaderProgram);
53 CE_REFL_DATA(pipelineLayout);
54 CE_REFL_DATA(name);
55 }
56 };
57
60 using GPURenderingBlock = std::function<void()>;
61
62 class CE_SCRIPT_EXPORT() GPUComputePipeline : public TDeviceObject<GPUComputePipelineDescriptor> {
63 public:
65 using TDeviceObject::TDeviceObject;
66
70
74
75 public:
80 [[nodiscard]] CE_SCRIPT_EXPORT()
81 virtual GPUResourceSetPtr createResourceSet(const GPUResourceSetDescriptor& descriptor) = 0;
82
84 virtual void begin(GPUCommandBuffer& commandBuffer) = 0;
85
87 virtual void end(GPUCommandBuffer& commandBuffer) = 0;
88
90 class Scope {
91 private:
93 GPUCommandBuffer* mCommandBuffer = nullptr;
94
96 GPUComputePipeline* mComputePipeline = nullptr;
97
98 public:
102 explicit Scope(GPUCommandBuffer& commandBuffer, GPUComputePipeline& computePipeline)
103 : mCommandBuffer(&commandBuffer), mComputePipeline(&computePipeline) {
104 mComputePipeline->begin(*mCommandBuffer);
105 }
106
108 explicit Scope(const GPUCommandBufferPtr& commandBuffer, GPUComputePipeline& computePipeline) : Scope(*commandBuffer, computePipeline) {}
109
111 explicit Scope(GPUCommandBuffer& commandBuffer, const GPUComputePipelinePtr& computePipeline) : Scope(commandBuffer, *computePipeline) {}
112
114 explicit Scope(const GPUCommandBufferPtr& commandBuffer, const GPUComputePipelinePtr& computePipeline) : Scope(*commandBuffer, *computePipeline) {}
115
117 ~Scope() noexcept { reset(); }
118
119 public:
121 void reset() {
122 if(mComputePipeline != nullptr) {
123 mComputePipeline->end(*mCommandBuffer);
124 mComputePipeline = nullptr;
125 mCommandBuffer = nullptr;
126 }
127 }
128 };
129
136 template<typename Func, typename... Args> decltype(auto) with(GPUCommandBuffer& commandBuffer, Func&& func, Args&&... args) {
137 const Scope scope(commandBuffer, *this, std::forward<Args>(args)...);
138 return func();
139 }
140 };
141
142} // namespace CeresEngine
143
#define CE_REFLECT_HASH(T)
Definition Hash.hpp:89
#define CE_REFL_DATA(N)
Definition Macros.hpp:541
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
Definition GPUCommandBuffer.hpp:77
A helper class that begins a scoped compute pipeline recording.
Definition GPUComputePipeline.hpp:90
~Scope() noexcept
Unbound the pipeline from the command buffer.
Definition GPUComputePipeline.hpp:117
Scope(GPUCommandBuffer &commandBuffer, GPUComputePipeline &computePipeline)
Creates a new scope and calls begin() on the pipeline.
Definition GPUComputePipeline.hpp:102
Scope(GPUCommandBuffer &commandBuffer, const GPUComputePipelinePtr &computePipeline)
Creates a new scope and calls begin() on the pipeline.
Definition GPUComputePipeline.hpp:111
Scope(const GPUCommandBufferPtr &commandBuffer, GPUComputePipeline &computePipeline)
Creates a new scope and calls begin() on the pipeline.
Definition GPUComputePipeline.hpp:108
void reset()
Unbound the pipeline from the command buffer.
Definition GPUComputePipeline.hpp:121
Scope(const GPUCommandBufferPtr &commandBuffer, const GPUComputePipelinePtr &computePipeline)
Creates a new scope and calls begin() on the pipeline.
Definition GPUComputePipeline.hpp:114
Definition GPUComputePipeline.hpp:62
GPUComputePipeline(GPUComputePipeline &&)=delete
Deleted move constructor.
GPUComputePipeline & operator=(const GPUComputePipeline &)=delete
decltype(auto) with(GPUCommandBuffer &commandBuffer, Func &&func, Args &&... args)
Prepares the pipeline for execution.
Definition GPUComputePipeline.hpp:136
GPUComputePipeline & operator=(GPUComputePipeline &&)=delete
GPUComputePipeline(const GPUComputePipeline &)=delete
Deleted copy constructor.
virtual void begin(GPUCommandBuffer &commandBuffer)=0
Prepares the pipeline for execution.
virtual void end(GPUCommandBuffer &commandBuffer)=0
Finishes the pipeline execution.
Definition Common.hpp:62
Definition Application.hpp:19
std::function< void()> GPURenderingBlock
A block executed by the render pass implementation when the renderer is ready to receive draw command...
Definition GPUComputePipeline.hpp:60
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition Span.hpp:668
Compute pipeline descriptor structure.
Definition GPUComputePipeline.hpp:25
static constexpr void reflect(Processor &&RTTI)
Executes the given processor for every field of the struct.
Definition GPUComputePipeline.hpp:51
Definition GPUResourceSet.hpp:716