p.Chaos.XPBDBending.ISPC.MinNumParallelBatches

p.Chaos.XPBDBending.ISPC.MinNumParallelBatches

#Overview

name: p.Chaos.XPBDBending.ISPC.MinNumParallelBatches

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

It is referenced in 5 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.Chaos.XPBDBending.ISPC.MinNumParallelBatches is to control the minimum number of parallel batches for ISPC (Intel SPMD Program Compiler) XPBDBending constraints in the Chaos physics engine. This setting is part of the Unreal Engine’s physics simulation system, specifically for handling bending constraints in soft body simulations.

This setting variable is primarily used in the Chaos physics engine, which is part of Unreal Engine’s Experimental module. It’s specifically utilized in the XPBDAnisotropic Bending Constraints system, which deals with the simulation of bending in soft bodies or cloth-like objects.

The value of this variable is set using an FAutoConsoleVariableRef, which means it can be adjusted at runtime through the console or configuration files. It’s initialized with a default value of 1028, which effectively disables the parallelization by default.

This variable interacts closely with another variable called Chaos_XPBDBending_ISPC_ParallelBatchSize. Together, these two variables determine when and how the bending constraints are processed in parallel.

Developers should be aware that this variable acts as a threshold. The parallel processing of bending constraints only occurs when the number of constraints in a color (a group of non-interfering constraints) is greater than or equal to the product of Chaos_XPBDBending_ISPC_ParallelBatchSize and Chaos_XPBDBending_ISPC_MinNumParallelBatches.

Best practices when using this variable include:

  1. Adjusting it based on the scale and complexity of your soft body simulations.
  2. Considering the trade-off between parallelization overhead and potential performance gains.
  3. Testing different values to find the optimal setting for your specific use case.

Regarding the associated variable Chaos_XPBDBending_ISPC_MinNumParallelBatches:

This is the internal variable that directly corresponds to the console variable p.Chaos.XPBDBending.ISPC.MinNumParallelBatches. It serves the same purpose and is used in the actual code logic to determine when to apply parallel processing.

The variable is used in multiple places within the FXPBDAnisotropicBendingConstraints::Apply function. It’s compared against the size of constraint colors to decide whether to use parallel processing for that particular group of constraints.

When adjusting these variables, developers should consider the nature of their simulations and the hardware they’re targeting. Higher values will lead to less frequent parallelization but potentially more efficient use of parallel resources when it does occur. Lower values will increase the frequency of parallelization but might introduce more overhead for smaller constraint groups.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/XPBDAnisotropicBendingConstraints.cpp:27

Scope (from outer to inner):

file
namespace    Chaos::Softs

Source code excerpt:

static int32 Chaos_XPBDBending_ISPC_MinNumParallelBatches = 1028;  // effectively disabled for now
FAutoConsoleVariableRef CVarChaosXPBDBendingISPCParallelBatchSize(TEXT("p.Chaos.XPBDBending.ISPC.ParallelBatchSize"), Chaos_XPBDBending_ISPC_ParallelBatchSize, TEXT("Parallel batch size for ISPC XPBDBending constraints"));
FAutoConsoleVariableRef CVarChaosXPBDBendingISPCMinNumParallelBatches(TEXT("p.Chaos.XPBDBending.ISPC.MinNumParallelBatches"), Chaos_XPBDBending_ISPC_MinNumParallelBatches, TEXT("Min number of batches to invoke parallelFor ISPC XPBDBending constraints"));

FXPBDAnisotropicBendingConstraints::FXPBDAnisotropicBendingConstraints(const FSolverParticlesRange& InParticles,
	const FTriangleMesh& TriangleMesh,
	const TArray<TVec3<FVec2f>>& FaceVertexPatternPositions,
	const TMap<FString, TConstArrayView<FRealSingle>>& WeightMaps,
	const FCollectionPropertyConstFacade& PropertyCollection)

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/XPBDAnisotropicBendingConstraints.cpp:25

Scope (from outer to inner):

file
namespace    Chaos::Softs

Source code excerpt:


static int32 Chaos_XPBDBending_ISPC_ParallelBatchSize = 1028;
static int32 Chaos_XPBDBending_ISPC_MinNumParallelBatches = 1028;  // effectively disabled for now
FAutoConsoleVariableRef CVarChaosXPBDBendingISPCParallelBatchSize(TEXT("p.Chaos.XPBDBending.ISPC.ParallelBatchSize"), Chaos_XPBDBending_ISPC_ParallelBatchSize, TEXT("Parallel batch size for ISPC XPBDBending constraints"));
FAutoConsoleVariableRef CVarChaosXPBDBendingISPCMinNumParallelBatches(TEXT("p.Chaos.XPBDBending.ISPC.MinNumParallelBatches"), Chaos_XPBDBending_ISPC_MinNumParallelBatches, TEXT("Min number of batches to invoke parallelFor ISPC XPBDBending constraints"));

FXPBDAnisotropicBendingConstraints::FXPBDAnisotropicBendingConstraints(const FSolverParticlesRange& InParticles,
	const FTriangleMesh& TriangleMesh,
	const TArray<TVec3<FVec2f>>& FaceVertexPatternPositions,
	const TMap<FString, TConstArrayView<FRealSingle>>& WeightMaps,
	const FCollectionPropertyConstFacade& PropertyCollection)

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/XPBDAnisotropicBendingConstraints.cpp:692

Scope (from outer to inner):

file
function     void FXPBDAnisotropicBendingConstraints::Apply

Source code excerpt:

							const int32 ColorStart = ConstraintsPerColorStartIndex[ConstraintColorIndex];
							const int32 ColorSize = ConstraintsPerColorStartIndex[ConstraintColorIndex + 1] - ColorStart;	
							if (ColorSize >= Chaos_XPBDBending_ISPC_ParallelBatchSize * Chaos_XPBDBending_ISPC_MinNumParallelBatches)
							{
								const int32 NumBatches = FMath::DivideAndRoundUp(ColorSize, Chaos_XPBDBending_ISPC_ParallelBatchSize);
								PhysicsParallelFor(NumBatches, [this, &Particles, ColorStart, ColorSize,
									ParallelBatchSize = Chaos_XPBDBending_ISPC_ParallelBatchSize,
									Dt, &ExpStiffnessValue, &ExpBucklingValue, DampingRatioValue](const int32 BatchIndex)
								{

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/XPBDAnisotropicBendingConstraints.cpp:752

Scope (from outer to inner):

file
function     void FXPBDAnisotropicBendingConstraints::Apply

Source code excerpt:

							const int32 ColorStart = ConstraintsPerColorStartIndex[ConstraintColorIndex];
							const int32 ColorSize = ConstraintsPerColorStartIndex[ConstraintColorIndex + 1] - ColorStart;
							if (ColorSize >= Chaos_XPBDBending_ISPC_ParallelBatchSize * Chaos_XPBDBending_ISPC_MinNumParallelBatches)
							{
								const int32 NumBatches = FMath::DivideAndRoundUp(ColorSize, Chaos_XPBDBending_ISPC_ParallelBatchSize);
								PhysicsParallelFor(NumBatches, [this, &Particles, ColorStart, ColorSize,
									ParallelBatchSize = Chaos_XPBDBending_ISPC_ParallelBatchSize,
									Dt, &ExpStiffnessValue, &ExpBucklingValue, DampingRatioValue](const int32 BatchIndex)
								{

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/XPBDAnisotropicBendingConstraints.cpp:812

Scope (from outer to inner):

file
function     void FXPBDAnisotropicBendingConstraints::InitColor
function     void FXPBDAnisotropicBendingConstraints::Apply

Source code excerpt:

					const int32 ColorStart = ConstraintsPerColorStartIndex[ConstraintColorIndex];
					const int32 ColorSize = ConstraintsPerColorStartIndex[ConstraintColorIndex + 1] - ColorStart;
					if (ColorSize >= Chaos_XPBDBending_ISPC_ParallelBatchSize * Chaos_XPBDBending_ISPC_MinNumParallelBatches)
					{
						const int32 NumBatches = FMath::DivideAndRoundUp(ColorSize, Chaos_XPBDBending_ISPC_ParallelBatchSize);
						PhysicsParallelFor(NumBatches, [this, &Particles, ColorStart, ColorSize,
							ParallelBatchSize = Chaos_XPBDBending_ISPC_ParallelBatchSize,
							Dt, &ExpStiffnessValue, &ExpBucklingValue](const int32 BatchIndex)
						{