p.ChaosCloth.Solver.MinParallelBatchSize

p.ChaosCloth.Solver.MinParallelBatchSize

#Overview

name: p.ChaosCloth.Solver.MinParallelBatchSize

This variable is created as a Console Variable (cvar).

It is referenced in 7 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.ChaosCloth.Solver.MinParallelBatchSize is to set the minimum number of particles to process in parallel batches by the Chaos Cloth solver. This setting is part of the Chaos Cloth simulation system in Unreal Engine 5, which is responsible for simulating realistic cloth behavior in games.

The Chaos Cloth plugin and its associated modules rely on this setting variable. It’s primarily used in the ChaosClothingSimulationSolver.cpp file, which is part of the ChaosCloth plugin.

The value of this variable is set through the Unreal Engine console variable system. It’s associated with the C++ variable ClothSolverMinParallelBatchSize, which is initialized with a default value of 1000.

This variable interacts with several other variables related to cloth simulation, such as bClothSolverParallelClothPreUpdate, bClothSolverParallelClothUpdate, and bClothSolverParallelClothPostUpdate. These variables control different aspects of parallel processing in the cloth simulation.

Developers should be aware that this variable affects the performance and behavior of the cloth simulation. A higher value may improve performance by reducing overhead from parallel processing, but it might also reduce the granularity of parallelization.

Best practices when using this variable include:

  1. Adjusting it based on the complexity and number of cloth simulations in your scene.
  2. Profiling performance with different values to find the optimal setting for your specific use case.
  3. Considering the target hardware capabilities when setting this value.

Regarding the associated variable ClothSolverMinParallelBatchSize:

When working with ClothSolverMinParallelBatchSize, developers should consider the same best practices and awareness points as mentioned for p.ChaosCloth.Solver.MinParallelBatchSize, as they are essentially two sides of the same coin in terms of functionality.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Plugins/ChaosCloth/Source/ChaosCloth/Private/ChaosCloth/ChaosClothingSimulationSolver.cpp:62

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:

static bool bClothSolverDisableCollision = false;

FAutoConsoleVariableRef CVarClothSolverMinParallelBatchSize(TEXT("p.ChaosCloth.Solver.MinParallelBatchSize"), ClothSolverMinParallelBatchSize, TEXT("The minimum number of particle to process in parallel batch by the solver."));
FAutoConsoleVariableRef CVarClothSolverParallelClothPreUpdate(TEXT("p.ChaosCloth.Solver.ParallelClothPreUpdate"), bClothSolverParallelClothPreUpdate, TEXT("Pre-transform the cloth particles for each cloth in parallel."));
FAutoConsoleVariableRef CVarClothSolverParallelClothUpdate(TEXT("p.ChaosCloth.Solver.ParallelClothUpdate"), bClothSolverParallelClothUpdate, TEXT("Skin the physics mesh and do the other cloth update for each cloth in parallel."));
FAutoConsoleVariableRef CVarClothSolverParallelClothPostUpdate(TEXT("p.ChaosCloth.Solver.ParallelClothPostUpdate"), bClothSolverParallelClothPostUpdate, TEXT("Pre-transform the cloth particles for each cloth in parallel."));
FAutoConsoleVariableRef CVarClothSolverDebugHitchLength(TEXT("p.ChaosCloth.Solver.DebugHitchLength"), ClothSolverDebugHitchLength, TEXT("Hitch length in ms. Create artificial hitches to debug simulation jitter. 0 to disable"));
FAutoConsoleVariableRef CVarClothSolverDebugHitchInterval(TEXT("p.ChaosCloth.Solver.DebugHitchInterval"), ClothSolverDebugHitchInterval, TEXT("Hitch interval in frames. Create artificial hitches to debug simulation jitter. 0 to disable"));
FAutoConsoleVariableRef CVarClothSolverDisableCollision(TEXT("p.ChaosCloth.Solver.DisableCollision"), bClothSolverDisableCollision, TEXT("Disable all collision particles. Needs reset of the simulation (p.ChaosCloth.Reset)."));

#Associated Variable and Callsites

This variable is associated with another variable named ClothSolverMinParallelBatchSize. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Plugins/ChaosCloth/Source/ChaosCloth/Private/ChaosCloth/ChaosClothingSimulationSolver.cpp:49

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:

{

static int32 ClothSolverMinParallelBatchSize = 1000;
static bool bClothSolverParallelClothPreUpdate = true;
static bool bClothSolverParallelClothUpdate = true;
static bool bClothSolverParallelClothPostUpdate = true;
static bool bClothSolverDisableTimeDependentNumIterations = false;
static bool bClothSolverUseVelocityScale = true;
static float ClothSolverMaxVelocity = 0.f;

#Loc: <Workspace>/Engine/Plugins/ChaosCloth/Source/ChaosCloth/Private/ChaosCloth/ChaosClothingSimulationSolver.cpp:62

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:

static bool bClothSolverDisableCollision = false;

FAutoConsoleVariableRef CVarClothSolverMinParallelBatchSize(TEXT("p.ChaosCloth.Solver.MinParallelBatchSize"), ClothSolverMinParallelBatchSize, TEXT("The minimum number of particle to process in parallel batch by the solver."));
FAutoConsoleVariableRef CVarClothSolverParallelClothPreUpdate(TEXT("p.ChaosCloth.Solver.ParallelClothPreUpdate"), bClothSolverParallelClothPreUpdate, TEXT("Pre-transform the cloth particles for each cloth in parallel."));
FAutoConsoleVariableRef CVarClothSolverParallelClothUpdate(TEXT("p.ChaosCloth.Solver.ParallelClothUpdate"), bClothSolverParallelClothUpdate, TEXT("Skin the physics mesh and do the other cloth update for each cloth in parallel."));
FAutoConsoleVariableRef CVarClothSolverParallelClothPostUpdate(TEXT("p.ChaosCloth.Solver.ParallelClothPostUpdate"), bClothSolverParallelClothPostUpdate, TEXT("Pre-transform the cloth particles for each cloth in parallel."));
FAutoConsoleVariableRef CVarClothSolverDebugHitchLength(TEXT("p.ChaosCloth.Solver.DebugHitchLength"), ClothSolverDebugHitchLength, TEXT("Hitch length in ms. Create artificial hitches to debug simulation jitter. 0 to disable"));
FAutoConsoleVariableRef CVarClothSolverDebugHitchInterval(TEXT("p.ChaosCloth.Solver.DebugHitchInterval"), ClothSolverDebugHitchInterval, TEXT("Hitch interval in frames. Create artificial hitches to debug simulation jitter. 0 to disable"));
FAutoConsoleVariableRef CVarClothSolverDisableCollision(TEXT("p.ChaosCloth.Solver.DisableCollision"), bClothSolverDisableCollision, TEXT("Disable all collision particles. Needs reset of the simulation (p.ChaosCloth.Reset)."));

#Loc: <Workspace>/Engine/Plugins/ChaosCloth/Source/ChaosCloth/Private/ChaosCloth/ChaosClothingSimulationSolver.cpp:1577

Scope (from outer to inner):

file
namespace    Chaos
function     void FClothingSimulationSolver::ApplyPreSimulationTransforms
lambda-function

Source code excerpt:

						Particles.V(Index) = AnimationVelocitiesView[Index] + RelVelocity * FMath::Sqrt(MaxVelocitySquared / RelVelocitySquaredLength);
					}
					}, Particles.GetRangeSize() < ClothSolverMinParallelBatchSize);
				}
			}

			// Update collision particles
			const TSet<int32>& ActiveCollisionRanges = Evolution->GetGroupActiveCollisionParticleRanges(GroupId);
			for (const int32 CollisionRangeId : ActiveCollisionRanges)

#Loc: <Workspace>/Engine/Plugins/ChaosCloth/Source/ChaosCloth/Private/ChaosCloth/ChaosClothingSimulationSolver.cpp:1679

Scope (from outer to inner):

file
namespace    Chaos
function     void FClothingSimulationSolver::ApplyPreSimulationTransforms
lambda-function

Source code excerpt:

						Particles.V(Index) = AnimationVelocities[Index] + RelVelocity * FMath::Sqrt(MaxVelocitySquared / RelVelocitySquaredLength);
					}
				}, RangeSize < ClothSolverMinParallelBatchSize);
			}
		}, /*bForceSingleThreaded =*/ !bClothSolverParallelClothPreUpdate);

#if FRAMEPRO_ENABLED
		FRAMEPRO_CUSTOM_STAT("ChaosClothSolverMinParallelBatchSize", ClothSolverMinParallelBatchSize, "ChaosClothSolver", "Particles", FRAMEPRO_COLOUR(128, 0, 255));
		FRAMEPRO_CUSTOM_STAT("ChaosClothSolverParallelClothPreUpdate", bClothSolverParallelClothPreUpdate, "ChaosClothSolver", "Enabled", FRAMEPRO_COLOUR(128, 128, 64));
#endif

		{
			TRACE_CPUPROFILER_EVENT_SCOPE(FClothingSimulationSolver_CollisionPreSimulationTransforms);
			SCOPE_CYCLE_COUNTER(STAT_ChaosClothCollisionPreSimulationTransforms);

#Loc: <Workspace>/Engine/Plugins/ChaosCloth/Source/ChaosCloth/Private/ChaosCloth/ChaosClothingSimulationSolver.cpp:1758

Scope (from outer to inner):

file
namespace    Chaos
function     void FClothingSimulationSolver::PreSubstep
lambda-function

Source code excerpt:

						InterpolatedAnimationNormalsView[Index] = (InterpolationAlpha * AnimationNormalsView[Index] + ((Softs::FSolverReal)1. - InterpolationAlpha) * OldAnimationNormalsView[Index]).GetSafeNormal();

					}, Particles.GetRangeSize() < ClothSolverMinParallelBatchSize);
				}
			}
		}, /*bForceSingleThreaded =*/ !bClothSolverParallelClothPreUpdate);

		{
			TRACE_CPUPROFILER_EVENT_SCOPE(ChaosPBDClearCollidedArray);

#Loc: <Workspace>/Engine/Plugins/ChaosCloth/Source/ChaosCloth/Private/ChaosCloth/ChaosClothingSimulationSolver.cpp:1808

Scope (from outer to inner):

file
namespace    Chaos
function     void FClothingSimulationSolver::PreSubstep
lambda-function

Source code excerpt:

					InterpolatedAnimationNormals[Index] = (InterpolationAlpha * AnimationNormals[Index] + ((Softs::FSolverReal)1. - InterpolationAlpha) * OldAnimationNormals[Index]).GetSafeNormal();

				}, RangeSize < ClothSolverMinParallelBatchSize);
			}
		}, /*bForceSingleThreaded =*/ !bClothSolverParallelClothPreUpdate);
	}
}

void FClothingSimulationSolver::UpdateSolverField()