UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TaskDispatcherSolver.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
5#include "Tasks/Task.h"
6
7
8namespace Chaos
9{
10 class FClusterUnionPhysicsProxy;
11}
13
14
15namespace Chaos::Private
16{
17
18// This class is responsible to dispatch the solver tasks
19// It orchestrates the task dependencies according to data flow.
20// This class shouldn't do any simulation logic and code.
22{
23private:
24
25 // Array of batch of array of rigid particles
27 // Geometry Collection array
29 TArray<FClusterUnionPhysicsProxy*> ActiveClusterUnions;
30
31 // Tasks that collect rigid particle
32 TArray<UE::Tasks::FTask> DirtyRigidPendingTasks;
33 // Tasks that collect Geometry collection and cluster union
34 UE::Tasks::FTask DirtyGCAndClusterPendingTask;
35
36 // Outer tasks which will create sub task once the collect task will be finish
37 // collecting Geometry collection and cluster union proxies
38 UE::Tasks::FTask GCPendingTask;
39 UE::Tasks::FTask ClusterPendingTask;
40
41 // Last task which copy in PullData the proxy for those three types of proxy
42 UE::Tasks::FTask PreviousCopyRigidTask;
43
44 // PullData copies to buffer physics results by batch
45 TArray<TArray<FDirtyRigidParticleData>> PullDataDirtyRigidsArray;
46
47 // GC and cluster batches tasks launches by GCPendingTask & ClusterPendingTask
48 TArray<UE::Tasks::FTask> GCBatchTasks;
49 TArray<UE::Tasks::FTask> ClusterBatchTasks;
50
51 int32 NumRigidBatches;
52
53public:
54
55 int32 GetNumRigidBatches() const { return NumRigidBatches; }
56
60
62
63 template<typename LambdaRigid, typename LambdaGCAndCluster>
65 {
66 constexpr int32 MinRigidPerTask = 50;
67 const int32 NumTasks = FMath::Max(FMath::Min(FTaskGraphInterface::Get().GetNumWorkerThreads() - 1, Chaos::MaxNumWorkers), 1);
68 const int32 NumDirtyTask = FMath::Max(FMath::Min(NumTasks, NumDirty), 1);
71
72 // We can have at most NumDirty overall active particles across all dirty proxy lists
73 // and in each list at most NumProxies. So we take the min, otherwise for example in a world
74 // with a few million static particles and one dynamic we'll allocate enough storage for the
75 // millions of particles despite only ever syncing one
76 for (int32 BatchIndex = 0; BatchIndex < LocalNumRigidBatches; BatchIndex++)
77 {
78 const int32 StartIndex = BatchIndex * DirtyByTask;
79 int32 EndIndex = (BatchIndex + 1) * DirtyByTask;
80 EndIndex = FMath::Min(NumDirty, EndIndex);
81
84
85 // Create Task here
87 {
89 CollectRigidResults(StartIndex, EndIndex, ActiveRigid);
90 });
91 DirtyRigidPendingTasks.Add(DirtyPendingTask);
92 }
93
94 // The GC and cluster proxies are shared among several particles
95 // all those following task will be computed sequentially to be sure not to add twice the same proxy.
96 // A fill all then merge approach could be potentially more efficient (not sure)
98 {
100 CollectGCAndClustersResults(0, NumDirty, ActiveGC, ActiveClusterUnions);
101 }, DirtyGCAndClusterPendingTask);
102 DirtyGCAndClusterPendingTask = DirtyPendingTask;
103
105 }
106
107 void BufferRigidResults(FPullPhysicsData* PullData);
110 void WaitTaskEndBufferResults() const;
111
112};
113}
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define QUICK_SCOPE_CYCLE_COUNTER(Stat)
Definition Stats.h:652
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UE_SOURCE_LOCATION
Definition PreprocessorHelpers.h:71
Definition PBDRigidsSolver.h:84
Definition PullPhysicsDataImp.h:166
Definition TaskDispatcherSolver.h:22
void BufferClusterResults(FPullPhysicsData *PullData)
Definition TaskDispatcherSolver.cpp:124
void BufferGCResults(FPullPhysicsData *PullData, FPBDRigidsSolver *RigidsSolver)
Definition TaskDispatcherSolver.cpp:85
int32 CollectPhysicsResults(LambdaRigid CollectRigidResults, LambdaGCAndCluster CollectGCAndClustersResults, int32 NumDirty, int32 DispatchBatchIndex)
Definition TaskDispatcherSolver.h:64
int32 GetNumRigidBatches() const
Definition TaskDispatcherSolver.h:55
void WaitTaskEndBufferResults() const
Definition TaskDispatcherSolver.cpp:162
void BufferRigidResults(FPullPhysicsData *PullData)
Definition TaskDispatcherSolver.cpp:50
FTaskDispatcherSolver()
Definition TaskDispatcherSolver.h:57
Definition ParticleIterator.h:639
Definition GeometryCollectionPhysicsProxy.h:143
static CORE_API FTaskGraphInterface & Get()
Definition TaskGraph.cpp:1794
Definition Array.h:670
void Reset(SizeType NewSize=0)
Definition Array.h:2246
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
Definition BodyInstance.h:90
Definition SkeletalMeshComponent.h:307
CHAOS_API int32 MaxNumWorkers
Definition Parallel.cpp:13
TTask< TInvokeResult_T< TaskBodyType > > Launch(const TCHAR *DebugName, TaskBodyType &&TaskBody, ETaskPriority Priority=ETaskPriority::Normal, EExtendedTaskPriority ExtendedPriority=EExtendedTaskPriority::None, ETaskFlags Flags=ETaskFlags::None)
Definition Task.h:266
static constexpr UE_FORCEINLINE_HINT T DivideAndRoundUp(T Dividend, T Divisor)
Definition UnrealMathUtility.h:694