p.Chaos.CalculateBounds.ISPC

p.Chaos.CalculateBounds.ISPC

#Overview

name: p.Chaos.CalculateBounds.ISPC

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

It is referenced in 11 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.Chaos.CalculateBounds.ISPC is to enable or disable ISPC (Intel SPMD Program Compiler) optimizations for calculating bounds in the Chaos cloth simulation system.

This setting variable is primarily used in the Chaos cloth simulation system, which is part of Unreal Engine’s physics and simulation modules. It specifically affects the performance of bounds calculation operations within the ChaosCloth plugin.

The value of this variable is set through a console variable (CVarChaosCalculateBoundsISPCEnabled) and is associated with the boolean variable bChaos_CalculateBounds_ISPC_Enabled. The default value is determined by the CHAOS_CALCULATE_BOUNDS_ISPC_ENABLED_DEFAULT macro.

This variable interacts closely with other ISPC-related variables in the Chaos cloth simulation, such as p.Chaos.PreSimulationTransforms.ISPC and p.Chaos.PreSubstepInterpolation.ISPC. Together, these variables control various ISPC optimizations in the cloth simulation pipeline.

Developers should be aware that:

  1. This optimization is only available on platforms that support ISPC.
  2. It may affect the precision of bounds calculations, so thorough testing is recommended when enabling or disabling this feature.
  3. The performance impact may vary depending on the specific hardware and the complexity of the cloth simulation.

Best practices when using this variable include:

  1. Benchmark the performance with and without ISPC optimization to ensure it provides a benefit for your specific use case.
  2. Verify that the visual results are acceptable when the optimization is enabled.
  3. Consider exposing this setting to technical artists or optimizers who may need to fine-tune performance on a per-project basis.

Regarding the associated variable bChaos_CalculateBounds_ISPC_Enabled: This boolean variable directly controls whether the ISPC optimization for bounds calculation is used in the code. It is set based on the console variable p.Chaos.CalculateBounds.ISPC and is checked in various parts of the cloth simulation code to determine whether to use the ISPC-optimized path or the standard C++ path for bounds calculations. Developers should treat this variable as read-only within their code and use the console variable to modify its value at runtime.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Plugins/ChaosCloth/Source/ChaosCloth/Private/ChaosCloth/ChaosClothingSimulationSolver.cpp:38

Scope: file

Source code excerpt:

FAutoConsoleVariableRef CVarChaosPreSimulationTransformsISPCEnabled(TEXT("p.Chaos.PreSimulationTransforms.ISPC"), bChaos_PreSimulationTransforms_ISPC_Enabled, TEXT("Whether to use ISPC optimizations in ApplySimulationTransforms"));
bool bChaos_CalculateBounds_ISPC_Enabled = CHAOS_CALCULATE_BOUNDS_ISPC_ENABLED_DEFAULT;
FAutoConsoleVariableRef CVarChaosCalculateBoundsISPCEnabled(TEXT("p.Chaos.CalculateBounds.ISPC"), bChaos_CalculateBounds_ISPC_Enabled, TEXT("Whether to use ISPC optimizations in CalculateBounds"));
bool bChaos_PreSubstepInterpolation_ISPC_Enabled = CHAOS_PRE_SUBSTEP_INTERPOLATION_ISPC_ENABLED_DEFAULT;
FAutoConsoleVariableRef CVarChaosPreSubstepInterpolationISPCEnabled(TEXT("p.Chaos.PreSubstepInterpolation.ISPC"), bChaos_PreSubstepInterpolation_ISPC_Enabled, TEXT("Whether to use ISPC optimization in PreSubstep"));

static_assert(sizeof(ispc::FVector3f) == sizeof(Chaos::Softs::FSolverVec3), "sizeof(ispc::FVector) != sizeof(Chaos::Softs::FSolverVec3)");
static_assert(sizeof(ispc::FTransform3f) == sizeof(Chaos::Softs::FSolverRigidTransform3), "sizeof(ispc::FVector) != sizeof(Chaos::Softs::FSolverRigidTransform3)");
#endif

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Plugins/ChaosCloth/Source/ChaosCloth/Private/ChaosCloth/ChaosClothingSimulationSolver.cpp:37

Scope: file

Source code excerpt:

bool bChaos_PreSimulationTransforms_ISPC_Enabled = CHAOS_PRE_SIMULATION_TRANSFORMS_ISPC_ENABLED_DEFAULT;
FAutoConsoleVariableRef CVarChaosPreSimulationTransformsISPCEnabled(TEXT("p.Chaos.PreSimulationTransforms.ISPC"), bChaos_PreSimulationTransforms_ISPC_Enabled, TEXT("Whether to use ISPC optimizations in ApplySimulationTransforms"));
bool bChaos_CalculateBounds_ISPC_Enabled = CHAOS_CALCULATE_BOUNDS_ISPC_ENABLED_DEFAULT;
FAutoConsoleVariableRef CVarChaosCalculateBoundsISPCEnabled(TEXT("p.Chaos.CalculateBounds.ISPC"), bChaos_CalculateBounds_ISPC_Enabled, TEXT("Whether to use ISPC optimizations in CalculateBounds"));
bool bChaos_PreSubstepInterpolation_ISPC_Enabled = CHAOS_PRE_SUBSTEP_INTERPOLATION_ISPC_ENABLED_DEFAULT;
FAutoConsoleVariableRef CVarChaosPreSubstepInterpolationISPCEnabled(TEXT("p.Chaos.PreSubstepInterpolation.ISPC"), bChaos_PreSubstepInterpolation_ISPC_Enabled, TEXT("Whether to use ISPC optimization in PreSubstep"));

static_assert(sizeof(ispc::FVector3f) == sizeof(Chaos::Softs::FSolverVec3), "sizeof(ispc::FVector) != sizeof(Chaos::Softs::FSolverVec3)");
static_assert(sizeof(ispc::FTransform3f) == sizeof(Chaos::Softs::FSolverRigidTransform3), "sizeof(ispc::FVector) != sizeof(Chaos::Softs::FSolverRigidTransform3)");
#endif

#Loc: <Workspace>/Engine/Plugins/ChaosCloth/Source/ChaosCloth/Private/ChaosCloth/ChaosClothingSimulationSolver.cpp:2117

Scope (from outer to inner):

file
namespace    Chaos
function     FBoxSphereBounds FClothingSimulationSolver::CalculateBounds

Source code excerpt:

				const Softs::FSolverParticlesRange& Particles = Evolution->GetSoftBodyParticles(SoftBodyId);
#if INTEL_ISPC
				if (bRealTypeCompatibleWithISPC && bChaos_CalculateBounds_ISPC_Enabled)
				{
					Softs::FSolverVec3 NewMin = BoundingBox.Min();
					Softs::FSolverVec3 NewMax = BoundingBox.Max();

					ispc::CalculateBounds(
						(ispc::FVector3f&)NewMin,

#Loc: <Workspace>/Engine/Plugins/ChaosCloth/Source/ChaosCloth/Private/ChaosCloth/ChaosClothingSimulationSolver.cpp:2157

Scope (from outer to inner):

file
namespace    Chaos
function     FBoxSphereBounds FClothingSimulationSolver::CalculateBounds

Source code excerpt:

				const Softs::FSolverParticlesRange& Particles = Evolution->GetSoftBodyParticles(SoftBodyId);
#if INTEL_ISPC
				if (bRealTypeCompatibleWithISPC && bChaos_CalculateBounds_ISPC_Enabled)
				{
					ispc::CalculateSquaredRadius(
						SquaredRadius,
						(const ispc::FVector3f&)Center,
						(const ispc::FVector3f*)Particles.XArray().GetData(),
						0,

#Loc: <Workspace>/Engine/Plugins/ChaosCloth/Source/ChaosCloth/Private/ChaosCloth/ChaosClothingSimulationSolver.cpp:2190

Scope (from outer to inner):

file
namespace    Chaos
function     FBoxSphereBounds FClothingSimulationSolver::CalculateBounds

Source code excerpt:


#if INTEL_ISPC
			if (bRealTypeCompatibleWithISPC && bChaos_CalculateBounds_ISPC_Enabled)
			{
				ParticlesActiveView.RangeFor(
					[&BoundingBox](Softs::FSolverParticles& Particles, int32 Offset, int32 Range)
				{
					Softs::FSolverVec3 NewMin = BoundingBox.Min();
					Softs::FSolverVec3 NewMax = BoundingBox.Max();

#Loc: <Workspace>/Engine/Plugins/ChaosCloth/Source/ChaosCloth/Private/ChaosCloth/ChaosClothingSimulationSolver.cpp:2223

Scope (from outer to inner):

file
namespace    Chaos
function     FBoxSphereBounds FClothingSimulationSolver::CalculateBounds

Source code excerpt:


#if INTEL_ISPC
			if (bRealTypeCompatibleWithISPC && bChaos_CalculateBounds_ISPC_Enabled)
			{
				ParticlesActiveView.RangeFor(
					[&SquaredRadius, &Center](Softs::FSolverParticles& Particles, int32 Offset, int32 Range)
				{
					ispc::CalculateSquaredRadius(
						SquaredRadius,

#Loc: <Workspace>/Engine/Plugins/ChaosCloth/Source/ChaosCloth/Private/ChaosCloth/IspcTestChaosClothingSimulationSolver.cpp:11

Scope (from outer to inner):

file
function     bool FIspcTestChaosClothingSimulationSolverAABB::RunTest

Source code excerpt:

	using namespace Chaos;
	
	bool InitialState = bChaos_CalculateBounds_ISPC_Enabled;

	const int32 NumParticles = 100;

	bChaos_CalculateBounds_ISPC_Enabled = true;
	FBoxSphereBounds ISPCAABB;
	{
		FClothingSimulationSolver ClothingSimulationSolver;
		ClothingSimulationSolver.AddParticles(NumParticles, 0);
		ClothingSimulationSolver.EnableParticles(0, true);

#Loc: <Workspace>/Engine/Plugins/ChaosCloth/Source/ChaosCloth/Private/ChaosCloth/IspcTestChaosClothingSimulationSolver.cpp:36

Scope (from outer to inner):

file
function     bool FIspcTestChaosClothingSimulationSolverAABB::RunTest

Source code excerpt:

	}

	bChaos_CalculateBounds_ISPC_Enabled = false;
	FBoxSphereBounds CPPAABB;
	{
		FClothingSimulationSolver ClothingSimulationSolver;
		ClothingSimulationSolver.AddParticles(NumParticles, 0);
		ClothingSimulationSolver.EnableParticles(0, true);

#Loc: <Workspace>/Engine/Plugins/ChaosCloth/Source/ChaosCloth/Private/ChaosCloth/IspcTestChaosClothingSimulationSolver.cpp:57

Scope (from outer to inner):

file
function     bool FIspcTestChaosClothingSimulationSolverAABB::RunTest

Source code excerpt:

	}

	bChaos_CalculateBounds_ISPC_Enabled = InitialState;

	TestTrue(TEXT("Origin"), ISPCAABB.Origin.Equals(CPPAABB.Origin));
	TestTrue(TEXT("Extent"), ISPCAABB.BoxExtent.Equals(CPPAABB.BoxExtent));
	TestEqual(TEXT("Radius"), ISPCAABB.SphereRadius, CPPAABB.SphereRadius);

	return true;

#Loc: <Workspace>/Engine/Plugins/ChaosCloth/Source/ChaosCloth/Private/ChaosCloth/IspcTestChaosClothingSimulationSolver.cpp:162

Scope (from outer to inner):

file
function     bool FIspcTestChaosClothingSimulationSolverPreSimulation::RunTest

Source code excerpt:

	}

	bChaos_CalculateBounds_ISPC_Enabled = InitialState;

	for (int32 i = 0; i < NumParticles; ++i)
	{
		{
			Softs::FSolverVec3& ISPCXSolver = *ISPCSimulation.GetParticleXs(i);
			Softs::FSolverVec3& CPPXSolver = *CPPSimulation.GetParticleXs(i);

#Loc: <Workspace>/Engine/Plugins/ChaosCloth/Source/ChaosCloth/Public/ChaosCloth/ChaosClothingSimulationSolver.h:476

Scope: file

Source code excerpt:

// Support run-time toggling on supported platforms in non-shipping configurations
#if !INTEL_ISPC || UE_BUILD_SHIPPING
static constexpr bool bChaos_CalculateBounds_ISPC_Enabled = INTEL_ISPC && CHAOS_CALCULATE_BOUNDS_ISPC_ENABLED_DEFAULT;
static constexpr bool bChaos_PreSimulationTransforms_ISPC_Enabled = INTEL_ISPC && CHAOS_PRE_SIMULATION_TRANSFORMS_ISPC_ENABLED_DEFAULT;
static constexpr bool bChaos_PreSubstepInterpolation_ISPC_Enabled = INTEL_ISPC && CHAOS_PRE_SUBSTEP_INTERPOLATION_ISPC_ENABLED_DEFAULT;
#else
extern bool bChaos_PreSimulationTransforms_ISPC_Enabled;
extern bool bChaos_CalculateBounds_ISPC_Enabled;
extern bool bChaos_PreSubstepInterpolation_ISPC_Enabled;
#endif