p.Chaos.PerParticleCollision.ISPC.ParallelBatchSize

p.Chaos.PerParticleCollision.ISPC.ParallelBatchSize

#Overview

name: p.Chaos.PerParticleCollision.ISPC.ParallelBatchSize

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

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.Chaos.PerParticleCollision.ISPC.ParallelBatchSize is to control the batch size for parallel processing in the Chaos physics engine’s per-particle collision system when using Intel ISPC (Intel SPMD Program Compiler) optimizations.

This setting variable is primarily used in the Chaos physics engine, which is part of Unreal Engine’s experimental physics system. Specifically, it’s used in the per-particle collision constraint module.

The value of this variable is set as a console variable, which means it can be adjusted at runtime. It’s initialized with a default value of 128, but can be changed using the console command system.

The associated variable Chaos_PerParticleCollision_ISPC_ParallelBatchSize directly interacts with it. This C++ variable holds the actual value used in the code, while p.Chaos.PerParticleCollision.ISPC.ParallelBatchSize is the console variable that allows runtime modification of this value.

Developers should be aware that this variable affects the performance of the per-particle collision system when using ISPC optimizations. Changing this value can impact the balance between parallelism and overhead. A larger batch size might improve performance on systems with more cores, while a smaller batch size might be better for systems with fewer cores or when dealing with smaller particle sets.

Best practices when using this variable include:

  1. Profiling the performance with different batch sizes to find the optimal value for your specific use case and target hardware.
  2. Consider exposing this as a user-adjustable setting in performance-critical applications, allowing end-users to optimize for their specific hardware.
  3. Be cautious about setting this value too high, as it might lead to load balancing issues or increased memory usage.

Regarding the associated variable Chaos_PerParticleCollision_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/PerParticlePBDCollisionConstraint.cpp:113

Scope: file

Source code excerpt:

static int32 Chaos_PerParticleCollision_ISPC_ParallelBatchSize = 128;
#if !UE_BUILD_SHIPPING
FAutoConsoleVariableRef CVarChaosPerParticleCollisionISPCParallelBatchSize(TEXT("p.Chaos.PerParticleCollision.ISPC.ParallelBatchSize"), Chaos_PerParticleCollision_ISPC_ParallelBatchSize, TEXT("Parallel batch size for ISPC"));
#endif

namespace Chaos::Softs {

// Helper function to call PhiWithNormal and return data to ISPC
extern "C" void GetPhiWithNormal(const uint8* CollisionParticles, const FSolverReal* InV, FSolverReal* Normal, FSolverReal* Phi, const int32 i, const int32 ProgramCount, const int32 Mask)

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PerParticlePBDCollisionConstraint.cpp:111

Scope: file

Source code excerpt:

#endif

static int32 Chaos_PerParticleCollision_ISPC_ParallelBatchSize = 128;
#if !UE_BUILD_SHIPPING
FAutoConsoleVariableRef CVarChaosPerParticleCollisionISPCParallelBatchSize(TEXT("p.Chaos.PerParticleCollision.ISPC.ParallelBatchSize"), Chaos_PerParticleCollision_ISPC_ParallelBatchSize, TEXT("Parallel batch size for ISPC"));
#endif

namespace Chaos::Softs {

// Helper function to call PhiWithNormal and return data to ISPC
extern "C" void GetPhiWithNormal(const uint8* CollisionParticles, const FSolverReal* InV, FSolverReal* Normal, FSolverReal* Phi, const int32 i, const int32 ProgramCount, const int32 Mask)

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PerParticlePBDCollisionConstraint.cpp:202

Scope (from outer to inner):

file
namespace    Chaos::Softs
function     void FPerParticlePBDCollisionConstraint::ApplyHelperISPC

Source code excerpt:

	const FSolverReal PerGroupThickness = MPerGroupThickness[DynamicGroupId];

	const int32 NumBatches = FMath::CeilToInt((FSolverReal)(Range - Offset) / (FSolverReal)Chaos_PerParticleCollision_ISPC_ParallelBatchSize);

	if (PerGroupFriction > UE_KINDA_SMALL_NUMBER)  // Fast friction
	{
		PhysicsParallelFor(NumBatches, [this, &InParticles, Dt, Offset, Range, DynamicGroupId, PerGroupFriction, PerGroupThickness](int32 BatchNumber)
			{
				const int32 BatchBegin = Offset + (Chaos_PerParticleCollision_ISPC_ParallelBatchSize * BatchNumber);
		const int32 BatchEnd = FMath::Min(Range, BatchBegin + Chaos_PerParticleCollision_ISPC_ParallelBatchSize);

#if INTEL_ISPC
		MCollisionParticlesActiveView.RangeFor(
			[this, &InParticles, Dt, BatchBegin, BatchEnd, DynamicGroupId, PerGroupFriction, PerGroupThickness](FSolverCollisionParticles& CollisionParticles, int32 CollisionOffset, int32 CollisionRange)
			{
				ispc::ApplyPerParticleCollisionFastFriction(

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PerParticlePBDCollisionConstraint.cpp:244

Scope (from outer to inner):

file
namespace    Chaos::Softs
function     void FPerParticlePBDCollisionConstraint::ApplyHelperISPC
lambda-function

Source code excerpt:

		PhysicsParallelFor(NumBatches, [this, &InParticles, Dt, Offset, Range, DynamicGroupId, PerGroupFriction, PerGroupThickness](int32 BatchNumber)
			{
				const int32 BatchBegin = Offset + (Chaos_PerParticleCollision_ISPC_ParallelBatchSize * BatchNumber);
		const int32 BatchEnd = FMath::Min(Range, BatchBegin + Chaos_PerParticleCollision_ISPC_ParallelBatchSize);

#if INTEL_ISPC
		MCollisionParticlesActiveView.RangeFor(
			[this, &InParticles, Dt, BatchBegin, BatchEnd, DynamicGroupId, PerGroupThickness](FSolverCollisionParticles& CollisionParticles, int32 CollisionOffset, int32 CollisionRange)
			{
				ispc::ApplyPerParticleCollisionNoFriction(