r.GPUParticle.MaxNumIterations

r.GPUParticle.MaxNumIterations

#Overview

name: r.GPUParticle.MaxNumIterations

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 r.GPUParticle.MaxNumIterations is to control the maximum number of iterations when using a fixed delta time for GPU particle simulation. This setting is part of the GPU particle simulation system in Unreal Engine 5.

This setting variable is primarily used in the Unreal Engine’s particle simulation module, specifically in the GPU-based particle simulation subsystem. It’s referenced in the Engine/Source/Runtime/Engine/Private/Particles/ParticleGpuSimulation.cpp file, which suggests it’s a core part of the engine’s particle simulation functionality.

The value of this variable is set as a console variable (CVar) with a default value of 3. It can be modified at runtime through the console or configuration files.

This variable interacts with other GPU particle simulation settings, particularly:

  1. r.GPUParticle.FixDeltaSeconds (CVarGPUParticleFixDeltaSeconds)
  2. r.GPUParticle.FixTolerance (CVarGPUParticleFixTolerance)

Developers must be aware that this variable directly impacts the performance and accuracy of GPU particle simulations. A higher value may lead to more accurate simulations but at the cost of performance, while a lower value might improve performance but potentially reduce simulation accuracy.

Best practices when using this variable include:

  1. Balancing between simulation accuracy and performance based on the specific needs of the game or application.
  2. Testing different values to find the optimal setting for your particular use case.
  3. Considering adjusting this value dynamically based on the current performance requirements or scene complexity.

Regarding the associated variable CVarGPUParticleMaxNumIterations:

The purpose of CVarGPUParticleMaxNumIterations is to provide programmatic access to the r.GPUParticle.MaxNumIterations setting within the C++ code of the engine.

This variable is used in the same GPU particle simulation system as r.GPUParticle.MaxNumIterations. It’s defined and used in the ParticleGpuSimulation.cpp file.

The value of this variable is set when the r.GPUParticle.MaxNumIterations console variable is initialized. It’s then accessed in the FGPUSpriteParticleEmitterInstance class, specifically in the GetDynamicData function.

CVarGPUParticleMaxNumIterations interacts directly with CVarGPUParticleFixDeltaSeconds and CVarGPUParticleFixTolerance in the particle simulation logic.

Developers should be aware that this is the actual variable used in the C++ code to retrieve the value set by r.GPUParticle.MaxNumIterations. Any changes to r.GPUParticle.MaxNumIterations will be reflected in this variable.

Best practices for using CVarGPUParticleMaxNumIterations include:

  1. Using GetValueOnAnyThread() method to access its value, as shown in the provided code snippet.
  2. Being cautious about changing its value directly, as it should generally reflect the value of r.GPUParticle.MaxNumIterations.
  3. Considering the impact on performance and simulation accuracy when using this value in calculations.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Particles/ParticleGpuSimulation.cpp:123

Scope: file

Source code excerpt:

static TAutoConsoleVariable<float> CVarGPUParticleFixDeltaSeconds(TEXT("r.GPUParticle.FixDeltaSeconds"), 1.f/30.f,TEXT("GPU particle fix delta seconds."));
static TAutoConsoleVariable<float> CVarGPUParticleFixTolerance(TEXT("r.GPUParticle.FixTolerance"),.1f,TEXT("Delta second tolerance before switching to a fix delta seconds."));
static TAutoConsoleVariable<int32> CVarGPUParticleMaxNumIterations(TEXT("r.GPUParticle.MaxNumIterations"),3,TEXT("Max number of iteration when using a fix delta seconds."));

static TAutoConsoleVariable<int32> CVarSimulateGPUParticles(TEXT("r.GPUParticle.Simulate"), 1, TEXT("Enable or disable GPU particle simulation"));

/*-----------------------------------------------------------------------------
	Allocators used to manage GPU particle resources.
-----------------------------------------------------------------------------*/

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Particles/ParticleGpuSimulation.cpp:123

Scope: file

Source code excerpt:

static TAutoConsoleVariable<float> CVarGPUParticleFixDeltaSeconds(TEXT("r.GPUParticle.FixDeltaSeconds"), 1.f/30.f,TEXT("GPU particle fix delta seconds."));
static TAutoConsoleVariable<float> CVarGPUParticleFixTolerance(TEXT("r.GPUParticle.FixTolerance"),.1f,TEXT("Delta second tolerance before switching to a fix delta seconds."));
static TAutoConsoleVariable<int32> CVarGPUParticleMaxNumIterations(TEXT("r.GPUParticle.MaxNumIterations"),3,TEXT("Max number of iteration when using a fix delta seconds."));

static TAutoConsoleVariable<int32> CVarSimulateGPUParticles(TEXT("r.GPUParticle.Simulate"), 1, TEXT("Enable or disable GPU particle simulation"));

/*-----------------------------------------------------------------------------
	Allocators used to manage GPU particle resources.
-----------------------------------------------------------------------------*/

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Particles/ParticleGpuSimulation.cpp:3398

Scope (from outer to inner):

file
class        class FGPUSpriteParticleEmitterInstance : public FParticleEmitterInstance
function     virtual FDynamicEmitterDataBase* GetDynamicData

Source code excerpt:

			const float FixDeltaSeconds = CVarGPUParticleFixDeltaSeconds.GetValueOnAnyThread();
			const float FixTolerance = CVarGPUParticleFixTolerance.GetValueOnAnyThread();
			const int32 MaxNumIterations = CVarGPUParticleMaxNumIterations.GetValueOnAnyThread();

			DeltaSecondsInFix = FixDeltaSeconds;
			NumIterationsInFix = 0;

			DeltaSecondsInVar = PendingDeltaSeconds + OffsetSeconds;
			NumIterationsInVar = 1;