p.Chaos.Bending.ISPC

p.Chaos.Bending.ISPC

#Overview

name: p.Chaos.Bending.ISPC

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

It is referenced in 8 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.Chaos.Bending.ISPC is to control whether ISPC (Intel SPMD Program Compiler) optimizations are used in the bending constraints calculations within the Chaos physics system of Unreal Engine 5.

This setting variable is primarily used in the Chaos physics system, which is part of the Experimental module in Unreal Engine 5. It specifically affects the bending constraints calculations in soft body simulations.

The value of this variable is set through a console variable (CVar) named “p.Chaos.Bending.ISPC”. It is initialized to true by default in non-shipping builds, as seen in the PBDBendingConstraintsBase.cpp file.

The associated variable bChaos_Bending_ISPC_Enabled directly interacts with p.Chaos.Bending.ISPC. They share the same value and are used interchangeably in the code.

Developers should be aware that:

  1. This optimization is only available when INTEL_ISPC is defined and not in shipping builds.
  2. It affects performance of bending constraint calculations in soft body simulations.
  3. The optimization is type-dependent, as indicated by the check for bRealTypeCompatibleWithISPC in the code.

Best practices when using this variable include:

  1. Testing performance with and without ISPC optimizations to ensure it provides benefits for your specific use case.
  2. Ensuring that the ISPC compiler is properly set up in your development environment if you intend to use these optimizations.
  3. Being cautious when modifying this setting in shipping builds, as it’s designed to be always enabled in those scenarios.

Regarding the associated variable bChaos_Bending_ISPC_Enabled:

The purpose of bChaos_Bending_ISPC_Enabled is to provide a runtime toggle for ISPC optimizations in bending constraints calculations.

It is used in the same Chaos physics system and affects the same bending constraint calculations as p.Chaos.Bending.ISPC.

The value is set through the console variable p.Chaos.Bending.ISPC and is checked in various parts of the bending constraint code to determine whether to use ISPC-optimized code paths.

This variable directly interacts with p.Chaos.Bending.ISPC, essentially serving as its in-code representation.

Developers should be aware that this variable is used in conditional statements to choose between ISPC-optimized and standard code paths, potentially affecting performance and behavior of soft body simulations.

Best practices include:

  1. Using this variable consistently throughout the codebase when implementing ISPC-optimized alternatives.
  2. Ensuring that both ISPC and non-ISPC code paths are maintained and tested for correctness.
  3. Considering the impact on performance and simulation accuracy when enabling or disabling this optimization.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDBendingConstraintsBase.cpp:6

Scope: file

Source code excerpt:

#if INTEL_ISPC && !UE_BUILD_SHIPPING
bool bChaos_Bending_ISPC_Enabled = true;
FAutoConsoleVariableRef CVarChaosBendingISPCEnabled(TEXT("p.Chaos.Bending.ISPC"), bChaos_Bending_ISPC_Enabled, TEXT("Whether to use ISPC optimizations in Bending constraints"));

static_assert(sizeof(ispc::FVector4f) == sizeof(Chaos::Softs::FPAndInvM), "sizeof(ispc::FVector4f) != sizeof(Chaos::Softs::FPAndInvM");
static_assert(sizeof(ispc::FIntVector4) == sizeof(Chaos::TVec4<int32>), "sizeof(ispc::FIntVector4) != sizeof(Chaos::TVec4<int32>");
#endif

namespace Chaos::Softs 

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDBendingConstraints.cpp:148

Scope (from outer to inner):

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

Source code excerpt:

			const FSolverReal ExpBucklingValue = (FSolverReal)BucklingStiffness;
#if INTEL_ISPC
			if (bRealTypeCompatibleWithISPC && bChaos_Bending_ISPC_Enabled)
			{
				for (int32 ConstraintColorIndex = 0; ConstraintColorIndex < ConstraintColorNum; ++ConstraintColorIndex)
				{
					const int32 ColorStart = ConstraintsPerColorStartIndex[ConstraintColorIndex];
					const int32 ColorSize = ConstraintsPerColorStartIndex[ConstraintColorIndex + 1] - ColorStart;
					ispc::ApplyBendingConstraints(

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDBendingConstraints.cpp:182

Scope (from outer to inner):

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

Source code excerpt:

		{
#if INTEL_ISPC
			if (bRealTypeCompatibleWithISPC && bChaos_Bending_ISPC_Enabled)
			{
				for (int32 ConstraintColorIndex = 0; ConstraintColorIndex < ConstraintColorNum; ++ConstraintColorIndex)
				{
					const int32 ColorStart = ConstraintsPerColorStartIndex[ConstraintColorIndex];
					const int32 ColorSize = ConstraintsPerColorStartIndex[ConstraintColorIndex + 1] - ColorStart;
					ispc::ApplyBendingConstraintsWithMaps(

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDBendingConstraintsBase.cpp:5

Scope: file

Source code excerpt:


#if INTEL_ISPC && !UE_BUILD_SHIPPING
bool bChaos_Bending_ISPC_Enabled = true;
FAutoConsoleVariableRef CVarChaosBendingISPCEnabled(TEXT("p.Chaos.Bending.ISPC"), bChaos_Bending_ISPC_Enabled, TEXT("Whether to use ISPC optimizations in Bending constraints"));

static_assert(sizeof(ispc::FVector4f) == sizeof(Chaos::Softs::FPAndInvM), "sizeof(ispc::FVector4f) != sizeof(Chaos::Softs::FPAndInvM");
static_assert(sizeof(ispc::FIntVector4) == sizeof(Chaos::TVec4<int32>), "sizeof(ispc::FIntVector4) != sizeof(Chaos::TVec4<int32>");
#endif

namespace Chaos::Softs 

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDBendingConstraintsBase.cpp:154

Scope (from outer to inner):

file
namespace    Chaos::Softs
function     void FPBDBendingConstraintsBase::Init

Source code excerpt:

		IsBuckled.SetNumUninitialized(Constraints.Num());
#if INTEL_ISPC
		if (bRealTypeCompatibleWithISPC && bChaos_Bending_ISPC_Enabled)
		{
			ispc::InitBendingConstraintsIsBuckled(
				(const ispc::FVector3f*)InParticles.XArray().GetData(),
				(const ispc::FIntVector4*)Constraints.GetData(),
				RestAngles.GetData(),
				IsBuckled.GetData(),

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

Scope (from outer to inner):

file
namespace    Chaos::Softs
function     void FXPBDAnisotropicBendingConstraints::InitColor
function     void FXPBDAnisotropicBendingConstraints::Init

Source code excerpt:

	X3Array.SetNumUninitialized(Constraints.Num());
	X4Array.SetNumUninitialized(Constraints.Num());
	if (bRealTypeCompatibleWithISPC && bChaos_Bending_ISPC_Enabled && ConstraintsIndex1.Num() == Constraints.Num())
	{
		ispc::InitXPBDBendingConstraintsIsBuckled(
			(const ispc::FVector3f*)Particles.XArray().GetData(),
			ConstraintsIndex1.GetData(),
			ConstraintsIndex2.GetData(),
			ConstraintsIndex3.GetData(),

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/XPBDBendingConstraints.cpp:105

Scope (from outer to inner):

file
namespace    Chaos::Softs
function     void FXPBDBendingConstraints::InitColor
function     void FXPBDBendingConstraints::Init

Source code excerpt:

	X3Array.SetNumUninitialized(Constraints.Num());
	X4Array.SetNumUninitialized(Constraints.Num());
	if (bRealTypeCompatibleWithISPC && bChaos_Bending_ISPC_Enabled && ConstraintsIndex1.Num() == Constraints.Num())
	{
		ispc::InitXPBDBendingConstraintsIsBuckled(
			(const ispc::FVector3f*)InParticles.XArray().GetData(),
			ConstraintsIndex1.GetData(),
			ConstraintsIndex2.GetData(),
			ConstraintsIndex3.GetData(),

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Public/Chaos/PBDBendingConstraintsBase.h:330

Scope: file

Source code excerpt:

// Support ISPC enable/disable in non-shipping builds
#if !INTEL_ISPC
const bool bChaos_Bending_ISPC_Enabled = false;
#elif UE_BUILD_SHIPPING
const bool bChaos_Bending_ISPC_Enabled = true;
#else
extern CHAOS_API bool bChaos_Bending_ISPC_Enabled;
#endif