r.RayTracing.PSOCacheSize

r.RayTracing.PSOCacheSize

#Overview

name: r.RayTracing.PSOCacheSize

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.RayTracing.PSOCacheSize is to control the size of the ray tracing pipeline state object (PSO) cache in Unreal Engine 5’s rendering system. This setting variable determines the number of ray tracing pipelines to keep in the cache.

This setting variable is primarily used by the RHI (Rendering Hardware Interface) subsystem of Unreal Engine 5, specifically within the ray tracing functionality. It’s part of the engine’s rendering pipeline and affects the performance of ray tracing operations.

The value of this variable is set through the console variable system. It’s defined with a default value of 50, meaning the cache will store up to 50 ray tracing pipelines by default.

The associated variable CVarRTPSOCacheSize directly interacts with r.RayTracing.PSOCacheSize. They share the same value and purpose, with CVarRTPSOCacheSize being the actual console variable implementation.

Developers should be aware of the following when using this variable:

  1. It’s marked as read-only and render thread safe, meaning it should not be modified during runtime.
  2. Setting the value to 0 disables cache eviction, which could lead to increased memory usage if not managed carefully.
  3. The cache size directly affects performance and memory usage related to ray tracing operations.

Best practices for using this variable include:

  1. Adjust the value based on the specific needs of your project. Larger values may improve performance by reducing pipeline state recompilations but will consume more memory.
  2. Monitor performance and memory usage when tweaking this value to find the optimal balance for your project.
  3. Consider leaving it at the default value of 50 unless you have specific performance issues related to ray tracing pipeline state creation.

Regarding the associated variable CVarRTPSOCacheSize:

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/PipelineStateCache.cpp:158

Scope: file

Source code excerpt:

#if RHI_RAYTRACING
static TAutoConsoleVariable<int32> CVarRTPSOCacheSize(
	TEXT("r.RayTracing.PSOCacheSize"),
	50,
	TEXT("Number of ray tracing pipelines to keep in the cache (default = 50). Set to 0 to disable eviction.\n"),
	ECVF_ReadOnly | ECVF_RenderThreadSafe
);
#endif // RHI_RAYTRACING

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/PipelineStateCache.cpp:157

Scope: file

Source code excerpt:


#if RHI_RAYTRACING
static TAutoConsoleVariable<int32> CVarRTPSOCacheSize(
	TEXT("r.RayTracing.PSOCacheSize"),
	50,
	TEXT("Number of ray tracing pipelines to keep in the cache (default = 50). Set to 0 to disable eviction.\n"),
	ECVF_ReadOnly | ECVF_RenderThreadSafe
);
#endif // RHI_RAYTRACING

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/PipelineStateCache.cpp:2545

Scope (from outer to inner):

file
function     FRayTracingPipelineState* PipelineStateCache::GetAndOrCreateRayTracingPipelineState

Source code excerpt:


		// Remove old pipelines once per frame
		const int32 TargetCacheSize = CVarRTPSOCacheSize.GetValueOnAnyThread();
		if (TargetCacheSize > 0 && GRayTracingPipelineCache.GetLastTrimFrame() != GFrameCounter)
		{
			GRayTracingPipelineCache.Trim(TargetCacheSize);
		}

		Result = GRayTracingPipelineCache.Add(Initializer);