p.Chaos.GC.InitConstantDataUseParallelFor

p.Chaos.GC.InitConstantDataUseParallelFor

#Overview

name: p.Chaos.GC.InitConstantDataUseParallelFor

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

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.Chaos.GC.InitConstantDataUseParallelFor is to control the parallelization of data initialization in the Geometry Collection component of Unreal Engine’s Chaos physics system.

This setting variable is primarily used in the Geometry Collection Engine module, which is part of Unreal Engine’s experimental Chaos physics system. It specifically affects the initialization of constant data within the GeometryCollectionComponent.

The value of this variable is set as a console variable, which means it can be changed at runtime. It’s initialized to true by default, as seen in the code:

bool bChaos_GC_InitConstantDataUseParallelFor = true;
FAutoConsoleVariableRef CVarChaosGCInitConstantDataUseParallelFor(TEXT("p.Chaos.GC.InitConstantDataUseParallelFor"), bChaos_GC_InitConstantDataUseParallelFor, TEXT("When enabled, InitConstant data will use parallelFor for copying some of the data"));

This variable interacts closely with another variable, bChaos_GC_InitConstantDataParallelForBatchSize, which determines the batch size for the parallel processing when this setting is enabled.

Developers should be aware that enabling this variable will cause the system to use parallel processing for initializing constant data, which can improve performance but may also increase complexity and potentially introduce race conditions if not handled correctly.

Best practices when using this variable include:

  1. Testing performance with it both enabled and disabled to ensure it’s beneficial for your specific use case.
  2. Adjusting the bChaos_GC_InitConstantDataParallelForBatchSize in conjunction with this setting to find the optimal balance between parallelization and overhead.
  3. Being cautious when modifying any code that relies on this setting, as changes could affect the parallel execution.

Regarding the associated variable bChaos_GC_InitConstantDataUseParallelFor:

This is the actual boolean variable that stores the state of the setting. It’s used directly in the code to determine whether to use parallel processing, as seen in the GetBoneColors function:

if (bChaos_GC_InitConstantDataUseParallelFor)
{
    ParallelFor(TEXT("GC:InitBoneColors"), NumPoints, bChaos_GC_InitConstantDataParallelForBatchSize,
        [&](const int32 InPointIndex)
        {
            // ... parallel processing code ...
        });
}

The same considerations and best practices apply to this variable as to the console variable it’s associated with. Developers should be aware that changing this variable’s value will directly affect the execution of certain functions in the GeometryCollectionComponent, potentially impacting performance and behavior of the Geometry Collection system.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/GeometryCollectionEngine/Private/GeometryCollection/GeometryCollectionComponent.cpp:113

Scope: file

Source code excerpt:


bool bChaos_GC_InitConstantDataUseParallelFor = true;
FAutoConsoleVariableRef CVarChaosGCInitConstantDataUseParallelFor(TEXT("p.Chaos.GC.InitConstantDataUseParallelFor"), bChaos_GC_InitConstantDataUseParallelFor, TEXT("When enabled, InitConstant data will use parallelFor for copying some of the data"));

int32 bChaos_GC_InitConstantDataParallelForBatchSize = 5000;
FAutoConsoleVariableRef CVarChaosGCInitConstantDataParallelForBatchSize(TEXT("p.Chaos.GC.InitConstantDataParallelForBatchSize"), bChaos_GC_InitConstantDataParallelForBatchSize, TEXT("When parallelFor is used in InitConstantData, defined the minimium size of a batch of vertex "));

int32 MaxGeometryCollectionAsyncPhysicsTickIdleTimeMs = 30;
FAutoConsoleVariableRef CVarMaxGeometryCollectionAsyncPhysicsTickIdleTimeMs(TEXT("p.Chaos.GC.MaxGeometryCollectionAsyncPhysicsTickIdleTimeMs"), MaxGeometryCollectionAsyncPhysicsTickIdleTimeMs, TEXT("Amount of time in milliseconds before the async tick turns off when it is otherwise not doing anything."));

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/GeometryCollectionEngine/Private/GeometryCollection/GeometryCollectionComponent.cpp:112

Scope: file

Source code excerpt:

FAutoConsoleVariableRef CVarChaosGCUseCustomRenderer(TEXT("p.Chaos.GC.UseCustomRenderer"), bChaos_GC_UseCustomRenderer, TEXT("When enabled, use a custom renderer if specified"));

bool bChaos_GC_InitConstantDataUseParallelFor = true;
FAutoConsoleVariableRef CVarChaosGCInitConstantDataUseParallelFor(TEXT("p.Chaos.GC.InitConstantDataUseParallelFor"), bChaos_GC_InitConstantDataUseParallelFor, TEXT("When enabled, InitConstant data will use parallelFor for copying some of the data"));

int32 bChaos_GC_InitConstantDataParallelForBatchSize = 5000;
FAutoConsoleVariableRef CVarChaosGCInitConstantDataParallelForBatchSize(TEXT("p.Chaos.GC.InitConstantDataParallelForBatchSize"), bChaos_GC_InitConstantDataParallelForBatchSize, TEXT("When parallelFor is used in InitConstantData, defined the minimium size of a batch of vertex "));

int32 MaxGeometryCollectionAsyncPhysicsTickIdleTimeMs = 30;
FAutoConsoleVariableRef CVarMaxGeometryCollectionAsyncPhysicsTickIdleTimeMs(TEXT("p.Chaos.GC.MaxGeometryCollectionAsyncPhysicsTickIdleTimeMs"), MaxGeometryCollectionAsyncPhysicsTickIdleTimeMs, TEXT("Amount of time in milliseconds before the async tick turns off when it is otherwise not doing anything."));

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/GeometryCollectionEngine/Private/GeometryCollection/GeometryCollectionComponent.cpp:3109

Scope (from outer to inner):

file
function     void UGeometryCollectionComponent::GetBoneColors

Source code excerpt:


	OutColors.SetNumUninitialized(NumPoints);
	if (bChaos_GC_InitConstantDataUseParallelFor)
	{
		ParallelFor(TEXT("GC:InitBoneColors"), NumPoints, bChaos_GC_InitConstantDataParallelForBatchSize,
			[&](const int32 InPointIndex)
			{
				const int32 BoneIndex = BoneMap[InPointIndex];
				OutColors[InPointIndex] = BoneColors[BoneIndex].ToFColor(true);