p.Chaos.Bending.ParallelConstraintCount
p.Chaos.Bending.ParallelConstraintCount
#Overview
name: p.Chaos.Bending.ParallelConstraintCount
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
If we have more constraints than this, use parallel-for in Apply.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.Chaos.Bending.ParallelConstraintCount is to determine when to use parallel processing for bending constraints in the Chaos physics system of Unreal Engine 5. It sets a threshold for the number of constraints that triggers parallel execution.
This setting variable is primarily used by the Chaos physics subsystem, specifically within the bending constraints module. It’s part of the experimental Chaos namespace, indicating it’s a feature of the new physics engine in Unreal Engine 5.
The value of this variable is set to 100 by default, as seen in the source code. It can be modified at runtime through the console variable system, allowing for easy tuning and experimentation.
The associated variable Chaos_Bending_ParallelConstraintCount directly interacts with p.Chaos.Bending.ParallelConstraintCount. They share the same value, with the console variable (p.Chaos.Bending.ParallelConstraintCount) controlling the C++ variable (Chaos_Bending_ParallelConstraintCount).
Developers should be aware that this variable affects performance optimization. When the number of constraints exceeds the value set by this variable, the system will use parallel processing for applying constraints, potentially improving performance for complex simulations.
Best practices when using this variable include:
- Monitoring performance with different threshold values to find the optimal setting for your specific use case.
- Consider adjusting this value based on the target hardware capabilities.
- Be cautious when modifying this value in shipping builds, as it may affect gameplay consistency across different systems.
Regarding the associated variable Chaos_Bending_ParallelConstraintCount:
- It’s the actual C++ variable used in the code logic to determine when to use parallel processing.
- It’s used in the FPBDBendingConstraints::Apply function to decide whether to use parallel execution for constraint application.
- The variable is checked against the number of constraints (Constraints.Num()) to make this decision.
- Developers should not modify this variable directly in code, but instead use the console variable p.Chaos.Bending.ParallelConstraintCount to adjust its value.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDBendingConstraints.cpp:18
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_Bending_ParallelConstraintCount = 100;
FAutoConsoleVariableRef CVarChaosBendingParallelConstraintCount(TEXT("p.Chaos.Bending.ParallelConstraintCount"), Chaos_Bending_ParallelConstraintCount, TEXT("If we have more constraints than this, use parallel-for in Apply."));
template<typename SolverParticlesOrRange>
void FPBDBendingConstraints::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_Bending_ParallelConstraintCount
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDBendingConstraints.cpp:17
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_Bending_ParallelConstraintCount = 100;
FAutoConsoleVariableRef CVarChaosBendingParallelConstraintCount(TEXT("p.Chaos.Bending.ParallelConstraintCount"), Chaos_Bending_ParallelConstraintCount, TEXT("If we have more constraints than this, use parallel-for in Apply."));
template<typename SolverParticlesOrRange>
void FPBDBendingConstraints::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_Bending_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<TVec4<int32>> ReorderedConstraints;
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDBendingConstraints.cpp:140
Scope (from outer to inner):
file
namespace Chaos::Softs
function void FPBDBendingConstraints::Apply
Source code excerpt:
const bool BucklingStiffnessHasWeightMap = BucklingStiffness.HasWeightMap();
if (ConstraintsPerColorStartIndex.Num() > 0 && Constraints.Num() > Chaos_Bending_ParallelConstraintCount)
{
const int32 ConstraintColorNum = ConstraintsPerColorStartIndex.Num() - 1;
if (!StiffnessHasWeightMap && !BucklingStiffnessHasWeightMap)
{
const FSolverReal ExpStiffnessValue = (FSolverReal)Stiffness;
const FSolverReal ExpBucklingValue = (FSolverReal)BucklingStiffness;