Nameless Engine
Loading...
Searching...
No Matches
Pipeline.h
1#pragma once
2
3// Standard.
4#include <set>
5#include <unordered_set>
6
7// Custom.
8#include "shader/general/ShaderUser.h"
9#include "render/general/pipeline/PipelineConfiguration.h"
10#include "render/general/pipeline/PipelineShaderConstantsManager.hpp"
11
12namespace ne {
13 class Renderer;
14 class PipelineManager;
15 class Material;
16 class ComputeShaderInterface;
17 class Pipeline;
18
20 class Pipeline : public ShaderUser {
21 // Only Pipeline manager should be able to create Pipeline.
22 friend class PipelineManager;
23
24 // Will notify when material is no longer referencing a Pipeline.
25 friend class PipelineSharedPtr;
26
27 public:
28 Pipeline() = delete;
29 Pipeline(const Pipeline&) = delete;
30 Pipeline& operator=(const Pipeline&) = delete;
31
32 virtual ~Pipeline() override = default;
33
52 Pipeline* pPipeline, const char* pConstantName, unsigned int iValueToCopy);
53
55 std::unique_ptr<PipelineShaderConstantsManager> pConstantsManager;
56
61 std::unordered_map<std::string, size_t> uintConstantsOffsets;
62 };
63
77 static std::string combineShaderNames(
78 std::string_view sVertexShaderName,
79 std::string_view sPixelShaderName,
80 std::string_view sComputeShaderName = "");
81
90 std::variant<size_t, Error> getUintConstantOffset(const std::string& sConstantName);
91
98 std::pair<std::mutex, std::unordered_set<Material*>>* getMaterialsThatUseThisPipeline();
99
105 std::string getPipelineIdentifier() const;
106
112 Renderer* getRenderer() const;
113
122
130 std::pair<std::mutex, std::optional<ShaderConstantsData>>* getShaderConstants();
131
132 protected:
140 explicit Pipeline(
143 std::unique_ptr<PipelineConfiguration> pPipelineConfiguration);
144
161 [[nodiscard]] virtual std::optional<Error> recreateInternalResources() = 0;
162
170 void setShaderConstants(const std::unordered_map<std::string, size_t>& uintConstantsOffsets);
171
172 private:
184 static std::variant<std::shared_ptr<Pipeline>, Error> createGraphicsPipeline(
187 std::unique_ptr<PipelineConfiguration> pPipelineConfiguration);
188
200 static std::variant<std::shared_ptr<Pipeline>, Error> createComputePipeline(
201 Renderer* pRenderer, PipelineManager* pPipelineManager, const std::string& sComputeShaderName);
202
212 void onMaterialUsingPipeline(Material* pMaterial);
213
224
234 void onComputeShaderUsingPipeline(ComputeShaderInterface* pComputeShaderInterface);
235
246
252 std::pair<std::mutex, std::unordered_set<Material*>> mtxMaterialsThatUseThisPipeline;
253
259 std::pair<std::mutex, std::unordered_set<ComputeShaderInterface*>>
261
263 std::pair<std::mutex, std::optional<ShaderConstantsData>> mtxShaderConstantsData;
264
266 const std::unique_ptr<PipelineConfiguration> pPipelineConfiguration;
267
270
272 Renderer* const pRenderer = nullptr;
273 };
274} // namespace ne
Definition: ComputeShaderInterface.h:46
Definition: Error.h:27
Definition: Material.h:63
Definition: PipelineConfiguration.h:24
Definition: PipelineManager.h:54
Definition: PipelineSharedPtr.h:15
Definition: Pipeline.h:20
std::pair< std::mutex, std::optional< ShaderConstantsData > > mtxShaderConstantsData
Definition: Pipeline.h:263
std::pair< std::mutex, std::optional< ShaderConstantsData > > * getShaderConstants()
Definition: Pipeline.cpp:182
void onMaterialUsingPipeline(Material *pMaterial)
Definition: Pipeline.cpp:186
std::string getPipelineIdentifier() const
Definition: Pipeline.cpp:175
std::pair< std::mutex, std::unordered_set< Material * > > mtxMaterialsThatUseThisPipeline
Definition: Pipeline.h:252
const std::unique_ptr< PipelineConfiguration > pPipelineConfiguration
Definition: Pipeline.h:266
Renderer *const pRenderer
Definition: Pipeline.h:272
void onMaterialNoLongerUsingPipeline(Material *pMaterial)
Definition: Pipeline.cpp:206
std::variant< size_t, Error > getUintConstantOffset(const std::string &sConstantName)
Definition: Pipeline.cpp:59
static std::variant< std::shared_ptr< Pipeline >, Error > createComputePipeline(Renderer *pRenderer, PipelineManager *pPipelineManager, const std::string &sComputeShaderName)
Definition: Pipeline.cpp:138
static std::variant< std::shared_ptr< Pipeline >, Error > createGraphicsPipeline(Renderer *pRenderer, PipelineManager *pPipelineManager, std::unique_ptr< PipelineConfiguration > pPipelineConfiguration)
Definition: Pipeline.cpp:91
std::pair< std::mutex, std::unordered_set< Material * > > * getMaterialsThatUseThisPipeline()
Definition: Pipeline.cpp:87
void setShaderConstants(const std::unordered_map< std::string, size_t > &uintConstantsOffsets)
Definition: Pipeline.cpp:25
PipelineManager *const pPipelineManager
Definition: Pipeline.h:269
const PipelineConfiguration * getConfiguration() const
Definition: Pipeline.cpp:278
void onComputeShaderNoLongerUsingPipeline(ComputeShaderInterface *pComputeShaderInterface)
Definition: Pipeline.cpp:251
Renderer * getRenderer() const
Definition: Pipeline.cpp:276
void onComputeShaderUsingPipeline(ComputeShaderInterface *pComputeShaderInterface)
Definition: Pipeline.cpp:232
static std::string combineShaderNames(std::string_view sVertexShaderName, std::string_view sPixelShaderName, std::string_view sComputeShaderName="")
Definition: Pipeline.cpp:44
virtual std::optional< Error > recreateInternalResources()=0
std::pair< std::mutex, std::unordered_set< ComputeShaderInterface * > > mtxComputeShadersThatUseThisPipeline
Definition: Pipeline.h:260
Definition: Renderer.h:43
Definition: ShaderUser.h:20
Definition: Pipeline.h:35
void findOffsetAndCopySpecialValueToConstant(Pipeline *pPipeline, const char *pConstantName, unsigned int iValueToCopy)
Definition: Pipeline.cpp:280
std::unordered_map< std::string, size_t > uintConstantsOffsets
Definition: Pipeline.h:61
std::unique_ptr< PipelineShaderConstantsManager > pConstantsManager
Definition: Pipeline.h:55