p.Chaos.XPBDBending.ISPC.ParallelBatchSize

p.Chaos.XPBDBending.ISPC.ParallelBatchSize

#Overview

name: p.Chaos.XPBDBending.ISPC.ParallelBatchSize

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.ParallelBatchSize is to control the parallel batch size for ISPC (Intel SPMD Program Compiler) XPBDBending constraints in Unreal Engine’s Chaos physics system. This setting variable is specifically used in the anisotropic bending constraints implementation for soft body simulation.

This setting variable is primarily used in the Chaos module, which is part of Unreal Engine’s experimental physics system. It’s specifically utilized in the XPBDAnisotropicBendingConstraints implementation.

The value of this variable is set using an FAutoConsoleVariableRef, which allows it to be modified at runtime through console commands. It’s initialized with a default value of 1028.

The associated variable Chaos_XPBDBending_ISPC_ParallelBatchSize directly interacts with p.Chaos.XPBDBending.ISPC.ParallelBatchSize. They share the same value, with Chaos_XPBDBending_ISPC_ParallelBatchSize being the actual variable used in the code.

Developers must be aware that this variable affects the parallelization of XPBD anisotropic bending constraint calculations. It determines the size of batches processed in parallel, which can impact performance and potentially simulation accuracy.

Best practices when using this variable include:

  1. Adjusting it based on the specific hardware and scene complexity to optimize performance.
  2. Testing different values to find the optimal balance between parallelization overhead and computation efficiency.
  3. Considering the relationship with Chaos_XPBDBending_ISPC_MinNumParallelBatches when tuning performance.

Regarding the associated variable Chaos_XPBDBending_ISPC_ParallelBatchSize:

#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:26

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,

#Associated Variable and Callsites

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

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

Scope (from outer to inner):

file
namespace    Chaos::Softs

Source code excerpt:

extern int32 Chaos_XPBDBending_ParallelConstraintCount;

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,

#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)
								{
									const int32 BatchStart = BatchIndex * ParallelBatchSize;
									const int32 BatchEnd = FMath::Min((BatchIndex + 1) * ParallelBatchSize, ColorSize);
									ispc::ApplyXPBDAnisotropicBendingDampingConstraints(
										(ispc::FVector4f*)Particles.GetPAndInvM().GetData(),

#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)
								{
									const int32 BatchStart = BatchIndex * ParallelBatchSize;
									const int32 BatchEnd = FMath::Min((BatchIndex + 1) * ParallelBatchSize, ColorSize);
									ispc::ApplyXPBDAnisotropicBendingConstraintsWithDamping(
										(ispc::FVector4f*)Particles.GetPAndInvM().GetData(),

#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)
						{
							const int32 BatchStart = BatchIndex * ParallelBatchSize;
							const int32 BatchEnd = FMath::Min((BatchIndex + 1) * ParallelBatchSize, ColorSize);
							ispc::ApplyXPBDAnisotropicBendingConstraints(
								(ispc::FVector4f*)Particles.GetPAndInvM().GetData(),