UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SimpleMeshDrawCommandPass.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 SimpleMeshDrawCommandPass.h
5=============================================================================*/
6
7#pragma once
8
10#include "SceneUtils.h"
11#include "MeshPassProcessor.h"
13#include "RenderGraphBuilder.h"
14
15class FGPUScene;
17
22{
23public:
27 RENDERER_API FSimpleMeshDrawCommandPass(const FSceneView& View, FInstanceCullingManager* InstanceCullingManager, bool bEnableStereo = false);
28
36
37 FDynamicPassMeshDrawListContext* GetDynamicPassMeshDrawListContext() { return &DynamicPassMeshDrawListContext; }
38
39 EInstanceCullingMode GetInstanceCullingMode() const { return InstanceCullingContext.GetInstanceCullingMode(); }
40
41private:
44 FMeshCommandOneFrameArray VisibleMeshDrawCommands;
45 FInstanceCullingContext InstanceCullingContext;
46 FGraphicsMinimalPipelineStateSet GraphicsMinimalPipelineStateSet;
47 FDynamicMeshDrawCommandStorage DynamicMeshDrawCommandStorage;
48 bool bNeedsInitialization = false;
49 FDynamicPassMeshDrawListContext DynamicPassMeshDrawListContext;
50
51 // Is set to true if and only if the BuildRenderingCommands has been called with an enabled GPU scene (which implies a valid Scene etc).
52 // Is used to check that we don't submit any draw commands that require a GPU scene without supplying one.
53 bool bSupportsScenePrimitives = false;
54
55 bool bUsingStereo = false;
56 bool bWasDrawCommandsSetup = false;
57
58 uint32 InstanceFactor = 1;
59
60 // GPUCULL_TODO: Only for legacy path
61 FRHIBuffer* PrimitiveIdVertexBuffer = nullptr;
62};
63
64// GPUCULL_TODO: Write documentation
65template <typename PassParametersType, typename AddMeshBatchesCallbackLambdaType, typename PassPrologueLambdaType>
66void AddSimpleMeshPass(FRDGBuilder& GraphBuilder, PassParametersType* PassParametersIn, const FScene* Scene, const FSceneView &View, FInstanceCullingManager* InstanceCullingManager, FRDGEventName&& PassName,
71{
73
74 // TODO: don't do this when the parameters are exclusive (optimization)
76
77 // Copy parameters to ensure we can overwrite the InstanceCullingDrawParams
79
81
82 AddMeshBatchesCallback(SimpleMeshDrawCommandPass->GetDynamicPassMeshDrawListContext());
83
84 // It is legal to render a simple mesh pass without a FScene, but then mesh draw commands must not reference primitive ID streams.
85 if (Scene != nullptr)
86 {
87 SimpleMeshDrawCommandPass->BuildRenderingCommands(GraphBuilder, View, *Scene, PassParameters->InstanceCullingDrawParams);
88 }
89
91 {
92 PassParameters->InstanceCullingDrawParams.DrawIndirectArgsBuffer = nullptr;
93 }
94
95 GraphBuilder.AddPass(
96 MoveTemp(PassName),
100 {
101 PassPrologueCallback(RHICmdList);
102
103 SimpleMeshDrawCommandPass->SubmitDraw(RHICmdList, PassParameters->InstanceCullingDrawParams);
104 }
105 );
106}
107
108// GPUCULL_TODO: Write documentation
109template <typename PassParametersType, typename AddMeshBatchesCallbackLambdaType>
110void AddSimpleMeshPass(FRDGBuilder& GraphBuilder, PassParametersType* PassParameters, const FScene* Scene, const FSceneView& View, FInstanceCullingManager *InstanceCullingManager, FRDGEventName&& PassName, const FIntRect& ViewPortRect,
112{
113 AddSimpleMeshPass(GraphBuilder, PassParameters, Scene, View, InstanceCullingManager, MoveTemp(PassName), ERDGPassFlags::Raster, AddMeshBatchesCallback,
114 [ViewPortRect](FRHICommandList& RHICmdList)
115 {
116 RHICmdList.SetViewport(static_cast<float>(ViewPortRect.Min.X), static_cast<float>(ViewPortRect.Min.Y), 0.0f,
117 static_cast<float>(ViewPortRect.Max.X), static_cast<float>(ViewPortRect.Max.Y), 1.0f);
118 }
119 );
120}
121
122template <typename PassParametersType, typename AddMeshBatchesCallbackLambdaType>
125{
126 AddSimpleMeshPass(GraphBuilder, PassParameters, Scene, View, InstanceCullingManager, MoveTemp(PassName), ERDGPassFlags::Raster, AddMeshBatchesCallback,
127 [ViewPortRect](FRHICommandList& RHICmdList)
128 {
129 RHICmdList.SetViewport(static_cast<float>(ViewPortRect.Min.X), static_cast<float>(ViewPortRect.Min.Y), 0.0f,
130 static_cast<float>(ViewPortRect.Max.X), static_cast<float>(ViewPortRect.Max.Y), 1.0f);
131 },
133 );
134}
135
136// GPUCULL_TODO: Write documentation
137template <typename PassParametersType, typename AddMeshBatchesCallbackLambdaType>
138void AddSimpleMeshPass(FRDGBuilder& GraphBuilder, PassParametersType* PassParameters, const FScene* Scene, const FSceneView& View, FInstanceCullingManager *InstanceCullingManager, FRDGEventName&& PassName,
139 const FIntRect& ViewPortRect,
142{
143 AddSimpleMeshPass(GraphBuilder, PassParameters, Scene, View, InstanceCullingManager, MoveTemp(PassName), PassFlags, AddMeshBatchesCallback,
144 [ViewPortRect](FRHICommandList& RHICmdList)
145 {
146 RHICmdList.SetViewport(ViewPortRect.Min.X, ViewPortRect.Min.Y, 0.0f, ViewPortRect.Max.X, ViewPortRect.Max.Y, 1.0f);
147 }
148 );
149}
150
151// GPUCULL_TODO: Write documentation
152template <typename PassParametersType, typename AddMeshBatchesCallbackLambdaType, typename PassPrologueLambdaType>
153void AddSimpleMeshPass(FRDGBuilder& GraphBuilder, PassParametersType* PassParametersIn, const FGPUScene& GPUScene, const FSceneView& View, FInstanceCullingManager* InstanceCullingManager, FRDGEventName&& PassName,
157{
158 // TODO: don't do this when the parameters are exclusive (optimization)
160
161 // Copy parameters to ensure we can overwrite the InstanceCullingDrawParams
163
165
166 AddMeshBatchesCallback(SimpleMeshDrawCommandPass->GetDynamicPassMeshDrawListContext());
167
168 SimpleMeshDrawCommandPass->BuildRenderingCommands(GraphBuilder, View, GPUScene, PassParameters->InstanceCullingDrawParams);
169
170 GraphBuilder.AddPass(
171 MoveTemp(PassName),
173 PassFlags,
175 {
176 PassPrologueCallback(RHICmdList);
177
178 SimpleMeshDrawCommandPass->SubmitDraw(RHICmdList, PassParameters->InstanceCullingDrawParams);
179 }
180 );
181}
182
183// GPUCULL_TODO: Write documentation
184template <typename PassParametersType, typename AddMeshBatchesCallbackLambdaType>
185void AddSimpleMeshPass(FRDGBuilder& GraphBuilder, PassParametersType* PassParameters, const FGPUScene& GPUScene, const FSceneView& View, FInstanceCullingManager* InstanceCullingManager, FRDGEventName&& PassName, const FIntRect& ViewPortRect,
187{
188 AddSimpleMeshPass(GraphBuilder, PassParameters, GPUScene, View, InstanceCullingManager, MoveTemp(PassName), ERDGPassFlags::Raster, AddMeshBatchesCallback,
189 [ViewPortRect](FRHICommandList& RHICmdList)
190 {
191 RHICmdList.SetViewport(ViewPortRect.Min.X, ViewPortRect.Min.Y, 0.0f, ViewPortRect.Max.X, ViewPortRect.Max.Y, 1.0f);
192 }
193 );
194}
195
196// GPUCULL_TODO: Write documentation
197template <typename PassParametersType, typename AddMeshBatchesCallbackLambdaType>
198void AddSimpleMeshPass(FRDGBuilder& GraphBuilder, PassParametersType* PassParameters, const FGPUScene& GPUScene, const FSceneView& View, FInstanceCullingManager* InstanceCullingManager, FRDGEventName&& PassName,
199 const FIntRect& ViewPortRect,
202{
203 AddSimpleMeshPass(GraphBuilder, PassParameters, GPUScene, View, InstanceCullingManager, MoveTemp(PassName), PassFlags, AddMeshBatchesCallback,
204 [ViewPortRect](FRHICommandList& RHICmdList)
205 {
206 RHICmdList.SetViewport(ViewPortRect.Min.X, ViewPortRect.Min.Y, 0.0f, ViewPortRect.Max.X, ViewPortRect.Max.Y, 1.0f);
207 }
208 );
209}
210
211#if 0
212
213// GPUCULL_TODO: Write documentation
214template <typename PassParametersType, typename AddMeshBatchesCallbackLambdaType, typename PassPrologueLambdaType>
215void AddSimpleMeshPass(FRDGBuilder& GraphBuilder, PassParametersType* PassParameters, const FScene* Scene, const FSceneView& View, FRDGEventName&& PassName,
217{
218 // TODO: ViewRect is only in FViewInfo
219 AddSimpleMeshPass(GraphBuilder, PassParameters, Scene, View, MoveTemp(PassName), View.ViewRect, AddMeshBatchesCallback);
220}
221
222#endif
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define TRACE_CPUPROFILER_EVENT_SCOPE(Name)
Definition CpuProfilerTrace.h:528
EInstanceCullingMode
Definition InstanceCullingContext.h:45
ERDGPassFlags
Definition RenderGraphDefinitions.h:128
void AddSimpleMeshPass(FRDGBuilder &GraphBuilder, PassParametersType *PassParametersIn, const FScene *Scene, const FSceneView &View, FInstanceCullingManager *InstanceCullingManager, FRDGEventName &&PassName, const ERDGPassFlags &PassFlags, AddMeshBatchesCallbackLambdaType AddMeshBatchesCallback, PassPrologueLambdaType PassPrologueCallback, bool bAllowIndirectArgsOverride=true)
Definition SimpleMeshDrawCommandPass.h:66
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition MeshPassProcessor.h:1692
Definition MeshPassProcessor.h:1798
Definition GPUScene.h:217
Definition InstanceCullingContext.h:74
EInstanceCullingMode GetInstanceCullingMode() const
Definition InstanceCullingContext.h:208
Definition InstanceCullingManager.h:45
Definition RenderGraphBuilder.h:49
ObjectType * AllocObject(TArgs &&... Args)
Definition RenderGraphBuilder.inl:158
ParameterStructType * AllocParameters()
Definition RenderGraphBuilder.inl:170
FRDGPassRef AddPass(FRDGEventName &&Name, const ParameterStructType *ParameterStruct, ERDGPassFlags Flags, ExecuteLambdaType &&ExecuteLambda)
Definition RenderGraphEvent.h:38
Definition RHIResources.h:1581
Definition RHICommandList.h:3819
void SetViewport(float MinX, float MinY, float MinZ, float MaxX, float MaxY, float MaxZ)
Definition RHICommandList.h:4015
Definition SceneView.h:1425
Definition ScenePrivate.h:2875
Definition SimpleMeshDrawCommandPass.h:22
FDynamicPassMeshDrawListContext * GetDynamicPassMeshDrawListContext()
Definition SimpleMeshDrawCommandPass.h:37
EInstanceCullingMode GetInstanceCullingMode() const
Definition SimpleMeshDrawCommandPass.h:39
RENDERER_API void SubmitDraw(FRHICommandList &RHICmdList, const FInstanceCullingDrawParams &InstanceCullingDrawParams) const
Definition SimpleMeshDrawCommandPass.cpp:65
RENDERER_API void BuildRenderingCommands(FRDGBuilder &GraphBuilder, const FSceneView &View, const FGPUScene &GPUScene, FInstanceCullingDrawParams &OutInstanceCullingDrawParams)
Definition SimpleMeshDrawCommandPass.cpp:30
Definition RenderGraphDefinitions.h:103