p.Chaos.AxialSpring.ParallelConstraintCount

p.Chaos.AxialSpring.ParallelConstraintCount

#Overview

name: p.Chaos.AxialSpring.ParallelConstraintCount

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

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.Chaos.AxialSpring.ParallelConstraintCount is to control the parallelization of axial spring constraints in the Chaos physics system of Unreal Engine 5. This setting variable is used to determine when to switch from sequential to parallel processing of constraints.

This setting variable is primarily used in the Chaos physics subsystem, specifically within the axial spring constraints module. It’s part of the experimental Chaos namespace, indicating it’s a part of the new physics engine in Unreal Engine 5.

The value of this variable is set to 100 by default, as seen in the line:

int32 Chaos_AxialSpring_ParallelConstraintCount = 100;

However, it can be modified at runtime through the console variable system, as it’s registered as an auto console variable.

The associated variable Chaos_AxialSpring_ParallelConstraintCount directly interacts with it. They share the same value and purpose.

Developers must be aware that this variable affects performance and parallelization. If the number of constraints exceeds this threshold, the system will use parallel processing. This can have significant impacts on performance and behavior of the physics simulation.

Best practices when using this variable include:

  1. Profiling the application to determine the optimal threshold for your specific use case.
  2. Be cautious when modifying this value, as it can affect both performance and simulation accuracy.
  3. Consider the hardware capabilities of your target platforms when setting this value.

Regarding the associated variable Chaos_AxialSpring_ParallelConstraintCount:

Developers should treat both variables as effectively the same, with p.Chaos.AxialSpring.ParallelConstraintCount being the console-accessible version for runtime tuning.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDAxialSpringConstraints.cpp:21

Scope (from outer to inner):

file
namespace    Chaos::Softs

Source code excerpt:

// @todo(chaos): the parallel threshold (or decision to run parallel) should probably be owned by the solver and passed to the constraint container
int32 Chaos_AxialSpring_ParallelConstraintCount = 100;
FAutoConsoleVariableRef CVarChaosAxialSpringParallelConstraintCount(TEXT("p.Chaos.AxialSpring.ParallelConstraintCount"), Chaos_AxialSpring_ParallelConstraintCount, TEXT("If we have more constraints than this, use parallel-for in Apply."));

template<typename SolverParticlesOrRange>
void FPBDAxialSpringConstraints::InitColor(const SolverParticlesOrRange& InParticles)
{
	// In dev builds we always color so we can tune the system without restarting. See Apply()
#if UE_BUILD_SHIPPING || UE_BUILD_TEST

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDAxialSpringConstraints.cpp:20

Scope (from outer to inner):

file
namespace    Chaos::Softs

Source code excerpt:


// @todo(chaos): the parallel threshold (or decision to run parallel) should probably be owned by the solver and passed to the constraint container
int32 Chaos_AxialSpring_ParallelConstraintCount = 100;
FAutoConsoleVariableRef CVarChaosAxialSpringParallelConstraintCount(TEXT("p.Chaos.AxialSpring.ParallelConstraintCount"), Chaos_AxialSpring_ParallelConstraintCount, TEXT("If we have more constraints than this, use parallel-for in Apply."));

template<typename SolverParticlesOrRange>
void FPBDAxialSpringConstraints::InitColor(const SolverParticlesOrRange& InParticles)
{
	// In dev builds we always color so we can tune the system without restarting. See Apply()
#if UE_BUILD_SHIPPING || UE_BUILD_TEST
	if (Constraints.Num() > Chaos_AxialSpring_ParallelConstraintCount)
#endif
	{
		const TArray<TArray<int32>> ConstraintsPerColor = FGraphColoring::ComputeGraphColoringParticlesOrRange(Constraints, InParticles, ParticleOffset, ParticleOffset + ParticleCount);

		// Reorder constraints based on color so each array in ConstraintsPerColor contains contiguous elements.
		TArray<TVec3<int32>> ReorderedConstraints;

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDAxialSpringConstraints.cpp:100

Scope (from outer to inner):

file
namespace    Chaos::Softs
function     void FPBDAxialSpringConstraints::Apply

Source code excerpt:

	TRACE_CPUPROFILER_EVENT_SCOPE(FPBDAxialSpringConstraints_Apply);
	SCOPE_CYCLE_COUNTER(STAT_PBD_AxialSpring);
	if (ConstraintsPerColorStartIndex.Num() > 0 && Constraints.Num() > Chaos_AxialSpring_ParallelConstraintCount)
	{
		const int32 ConstraintColorNum = ConstraintsPerColorStartIndex.Num() - 1;
		if (!Stiffness.HasWeightMap())
		{
			const FSolverReal ExpStiffnessValue = (FSolverReal)Stiffness;