p.Chaos.XPBDStretchBias.ISPC

p.Chaos.XPBDStretchBias.ISPC

#Overview

name: p.Chaos.XPBDStretchBias.ISPC

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

It is referenced in 5 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.Chaos.XPBDStretchBias.ISPC is to control whether ISPC (Intel SPMD Program Compiler) optimizations are used in XPBD (Extended Position Based Dynamics) Stretch Bias constraints within the Chaos physics engine of Unreal Engine 5.

This setting variable is primarily used in the Chaos physics subsystem, specifically in the XPBD Stretch Bias element constraints. It’s part of the experimental Chaos module, which is a new physics engine being developed for Unreal Engine.

The value of this variable is set through a console variable (CVar) system, allowing it to be changed at runtime. It’s initialized to true by default, but can be modified through the console or configuration files.

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

Developers must be aware that:

  1. This optimization is only available when INTEL_ISPC is defined and the build is not a shipping build.
  2. It affects performance and potentially behavior of the XPBD Stretch Bias constraints.
  3. The optimization relies on specific size relationships between ISPC and Chaos data types, as evidenced by the static_assert statements.

Best practices when using this variable include:

  1. Testing the performance impact with and without ISPC optimizations enabled.
  2. Ensuring consistent behavior between ISPC-optimized and non-optimized code paths.
  3. Being cautious when modifying related data structures, as it may break the size assumptions required for ISPC optimization.

Regarding the associated variable bChaos_XPBDStretchBiasElement_ISPC_Enabled:

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/XPBDStretchBiasElementConstraints.cpp:15

Scope: file

Source code excerpt:

#if INTEL_ISPC && !UE_BUILD_SHIPPING
bool bChaos_XPBDStretchBiasElement_ISPC_Enabled = true;
FAutoConsoleVariableRef CVarChaosXPBDStretchBiasISPCEnabled(TEXT("p.Chaos.XPBDStretchBias.ISPC"), bChaos_XPBDStretchBiasElement_ISPC_Enabled, TEXT("Whether to use ISPC optimizations in XPBD Stretch Bias constraints"));
static_assert(sizeof(ispc::FVector4f) == sizeof(Chaos::Softs::FPAndInvM), "sizeof(ispc::FVector4f) != sizeof(Chaos::Softs::FPAndInvM");
static_assert(sizeof(ispc::FIntVector) == sizeof(Chaos::TVec3<int32>), "sizeof(ispc::FIntVector) != sizeof(Chaos::TVec3<int32>");
//static_assert(sizeof(ispc::FVector2f) == sizeof(Chaos::Softs::FSolverVec2), "sizeof(ispc::FVector2f) != sizeof(Chaos::Softs::FSolverVec2");
static_assert(sizeof(ispc::FVector4f) == sizeof(Chaos::Softs::FSolverMatrix22), "sizeof(ispc::FVector2f) != sizeof(Chaos::Softs::FSolverMatrix22");
static_assert(sizeof(ispc::FVector3f) == sizeof(Chaos::Softs::FSolverVec3), "sizeof(ispc::FVector3f) != sizeof(Chaos::Softs::FSolverVec3");
#endif

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/XPBDStretchBiasElementConstraints.cpp:14

Scope: file

Source code excerpt:


#if INTEL_ISPC && !UE_BUILD_SHIPPING
bool bChaos_XPBDStretchBiasElement_ISPC_Enabled = true;
FAutoConsoleVariableRef CVarChaosXPBDStretchBiasISPCEnabled(TEXT("p.Chaos.XPBDStretchBias.ISPC"), bChaos_XPBDStretchBiasElement_ISPC_Enabled, TEXT("Whether to use ISPC optimizations in XPBD Stretch Bias constraints"));
static_assert(sizeof(ispc::FVector4f) == sizeof(Chaos::Softs::FPAndInvM), "sizeof(ispc::FVector4f) != sizeof(Chaos::Softs::FPAndInvM");
static_assert(sizeof(ispc::FIntVector) == sizeof(Chaos::TVec3<int32>), "sizeof(ispc::FIntVector) != sizeof(Chaos::TVec3<int32>");
//static_assert(sizeof(ispc::FVector2f) == sizeof(Chaos::Softs::FSolverVec2), "sizeof(ispc::FVector2f) != sizeof(Chaos::Softs::FSolverVec2");
static_assert(sizeof(ispc::FVector4f) == sizeof(Chaos::Softs::FSolverMatrix22), "sizeof(ispc::FVector2f) != sizeof(Chaos::Softs::FSolverMatrix22");
static_assert(sizeof(ispc::FVector3f) == sizeof(Chaos::Softs::FSolverVec3), "sizeof(ispc::FVector3f) != sizeof(Chaos::Softs::FSolverVec3");
#endif

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/XPBDStretchBiasElementConstraints.cpp:557

Scope (from outer to inner):

file
namespace    Chaos::Softs
function     void FXPBDStretchBiasElementConstraints::InitColor
function     void FXPBDStretchBiasElementConstraints::Apply

Source code excerpt:


#if INTEL_ISPC
			if (bRealTypeCompatibleWithISPC && bChaos_XPBDStretchBiasElement_ISPC_Enabled)
			{
				if (DampingNoMap > 0)
				{
					for (int32 ConstraintColorIndex = 0; ConstraintColorIndex < ConstraintColorNum; ++ConstraintColorIndex)
					{
						const int32 ColorStart = ConstraintsPerColorStartIndex[ConstraintColorIndex];

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

Scope (from outer to inner):

file
namespace    Chaos::Softs
function     void FXPBDStretchBiasElementConstraints::InitColor
function     void FXPBDStretchBiasElementConstraints::Apply

Source code excerpt:


#if INTEL_ISPC
			if (bRealTypeCompatibleWithISPC && bChaos_XPBDStretchBiasElement_ISPC_Enabled)
			{
				if (DampingHasWeightMap || DampingNoMap > 0)
				{
					for (int32 ConstraintColorIndex = 0; ConstraintColorIndex < ConstraintColorNum; ++ConstraintColorIndex)
					{
						const int32 ColorStart = ConstraintsPerColorStartIndex[ConstraintColorIndex];

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Public/Chaos/XPBDStretchBiasElementConstraints.h:182

Scope: file

Source code excerpt:

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