Plasma Engine  2.0
Loading...
Searching...
No Matches
RenderPipeline.h
1#pragma once
2
3#include <Foundation/Configuration/CVar.h>
4#include <Foundation/Containers/DynamicArray.h>
5#include <Foundation/Containers/HybridArray.h>
6#include <Foundation/Strings/HashedString.h>
7#include <Foundation/Types/UniquePtr.h>
8#include <RendererCore/Pipeline/ExtractedRenderData.h>
9
10class plProfilingId;
11class plView;
14struct plPermutationVar;
15class plDGMLGraph;
16class plFrustum;
18
19class PL_RENDERERCORE_DLL plRenderPipeline : public plRefCounted
20{
21public:
22 enum class PipelineState
23 {
24 Uninitialized,
25 RebuildError,
26 Initialized
27 };
28
31
32 void AddPass(plUniquePtr<plRenderPipelinePass>&& pPass);
33 void RemovePass(plRenderPipelinePass* pPass);
34 void GetPasses(plDynamicArray<const plRenderPipelinePass*>& ref_passes) const;
35 void GetPasses(plDynamicArray<plRenderPipelinePass*>& ref_passes);
36 plRenderPipelinePass* GetPassByName(const plStringView& sPassName);
37 plHashedString GetViewName() const;
38
39 bool Connect(plRenderPipelinePass* pOutputNode, const char* szOutputPinName, plRenderPipelinePass* pInputNode, const char* szInputPinName);
40 bool Connect(plRenderPipelinePass* pOutputNode, plHashedString sOutputPinName, plRenderPipelinePass* pInputNode, plHashedString sInputPinName);
41 bool Disconnect(plRenderPipelinePass* pOutputNode, plHashedString sOutputPinName, plRenderPipelinePass* pInputNode, plHashedString sInputPinName);
42
43 const plRenderPipelinePassConnection* GetInputConnection(const plRenderPipelinePass* pPass, plHashedString sInputPinName) const;
44 const plRenderPipelinePassConnection* GetOutputConnection(const plRenderPipelinePass* pPass, plHashedString sOutputPinName) const;
45
46 void AddExtractor(plUniquePtr<plExtractor>&& pExtractor);
47 void RemoveExtractor(plExtractor* pExtractor);
48 void GetExtractors(plDynamicArray<const plExtractor*>& ref_extractors) const;
49 void GetExtractors(plDynamicArray<plExtractor*>& ref_extractors);
50 plExtractor* GetExtractorByName(const plStringView& sExtractorName);
51
52 template <typename T>
53 PL_ALWAYS_INLINE T* GetFrameDataProvider() const
54 {
55 return static_cast<T*>(GetFrameDataProvider(plGetStaticRTTI<T>()));
56 }
57
58 const plExtractedRenderData& GetRenderData() const;
59 plRenderDataBatchList GetRenderDataBatchesWithCategory(
61
63 void CreateDgmlGraph(plDGMLGraph& ref_graph);
64
65#if PL_ENABLED(PL_COMPILE_FOR_DEVELOPMENT)
66 static plCVarBool cvar_SpatialCullingVis;
67#endif
68
69 PL_DISALLOW_COPY_AND_ASSIGN(plRenderPipeline);
70
71private:
72 friend class plRenderWorld;
73 friend class plView;
74
75 // \brief Rebuilds the render pipeline, e.g. sorting passes via dependencies and creating render targets.
76 PipelineState Rebuild(const plView& view);
77 bool RebuildInternal(const plView& view);
78 bool SortPasses();
79 bool InitRenderTargetDescriptions(const plView& view);
80 bool CreateRenderTargetUsage(const plView& view);
81 bool InitRenderPipelinePasses();
82 void SortExtractors();
83 void UpdateViewData(const plView& view, plUInt32 uiDataIndex);
84
85 void RemoveConnections(plRenderPipelinePass* pPass);
86 void ClearRenderPassGraphTextures();
87 bool AreInputDescriptionsAvailable(const plRenderPipelinePass* pPass, const plHybridArray<plRenderPipelinePass*, 32>& done) const;
88 bool ArePassThroughInputsDone(const plRenderPipelinePass* pPass, const plHybridArray<plRenderPipelinePass*, 32>& done) const;
89
90 plFrameDataProviderBase* GetFrameDataProvider(const plRTTI* pRtti) const;
91
92 void ExtractData(const plView& view);
93 void FindVisibleObjects(const plView& view);
94
95 void Render(plRenderContext* pRenderer);
96
97 plRasterizerView* PrepareOcclusionCulling(const plFrustum& frustum, const plView& view);
98 void PreviewOcclusionBuffer(const plRasterizerView& rasterizer, const plView& view);
99
100private: // Member data
101 // Thread data
102 plThreadID m_CurrentExtractThread;
103 plThreadID m_CurrentRenderThread;
104
105 // Pipeline render data
106 plExtractedRenderData m_Data[2];
108
109#if PL_ENABLED(PL_COMPILE_FOR_DEVELOPMENT)
110 plTime m_AverageCullingTime;
111#endif
112
113 plHashedString m_sName;
114 plUInt64 m_uiLastExtractionFrame;
115 plUInt64 m_uiLastRenderFrame;
116
117 // Render pass graph data
118 PipelineState m_PipelineState = PipelineState::Uninitialized;
119
120 struct ConnectionData
121 {
122 // Inputs / outputs match the node pin indices. Value at index is nullptr if not connected.
125 };
128
130 struct TextureUsageData
131 {
133 plUInt16 m_uiFirstUsageIdx;
134 plUInt16 m_uiLastUsageIdx;
135 const plRenderPipelineNodePin* m_pTextureProvider = nullptr;
136 };
137 plDynamicArray<TextureUsageData> m_TextureUsage;
138 plDynamicArray<plUInt16> m_TextureUsageIdxSortedByFirstUsage;
139 plDynamicArray<plUInt16> m_TextureUsageIdxSortedByLastUsage;
140
142
143 // Extractors
145 plDynamicArray<plUniquePtr<plExtractor>> m_SortedExtractors;
146
147 // Data Providers
149 mutable plHashTable<const plRTTI*, plUInt32> m_TypeToDataProviderIndex;
150
151 plDynamicArray<plPermutationVar> m_PermutationVars;
152
153 // Occlusion Culling
154 plGALTextureHandle m_hOcclusionDebugViewTexture;
155};
This class encapsulates building a DGML compatible graph.
Definition DGMLWriter.h:10
Definition DynamicArray.h:81
Definition ExtractedRenderData.h:10
Definition Extractor.h:9
Definition FrameDataProvider.h:6
Represents the frustum of some camera and can be used for culling objects.
Definition Frustum.h:32
Definition RendererFoundationDLL.h:411
Definition HashTable.h:333
This class is optimized to take nearly no memory (sizeof(void*)) and to allow very fast checks whethe...
Definition HashedString.h:25
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Definition Map.h:408
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
Definition RasterizerView.h:16
Base class for reference counted objects.
Definition RefCounted.h:52
Definition RenderContext.h:30
Definition RenderDataBatch.h:64
Definition RenderPipeline.h:20
Definition RenderPipelinePass.h:26
Definition RenderWorld.h:40
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
[internal] Helper class to implement plCVarInt, plCVarFlag, plCVarBool and plCVarString.
Definition CVar.h:267
A Unique ptr manages an object and destroys that object when it goes out of scope....
Definition UniquePtr.h:10
Encapsulates a view on the given world through the given camera and rendered with the specified Rende...
Definition View.h:21
Definition Declarations.h:24
Definition RenderData.h:19
Definition RenderPipelineNode.h:10
Passed to plRenderPipelinePass::InitRenderPipelinePass to inform about existing connections on each i...
Definition RenderPipelinePass.h:16
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12