r.Vulkan.PipelineLRUSize

r.Vulkan.PipelineLRUSize

#Overview

name: r.Vulkan.PipelineLRUSize

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

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.Vulkan.PipelineLRUSize is to control the maximum size of shader memory for the Vulkan pipeline cache in Unreal Engine 5. It is used within the Vulkan rendering subsystem to manage the Least Recently Used (LRU) cache for pipelines.

This setting variable is primarily used by the Vulkan RHI (Rendering Hardware Interface) module in Unreal Engine 5. Specifically, it’s utilized in the VulkanPipeline.cpp file, which is part of the VulkanRHI subsystem.

The value of this variable is set through a console variable (CVarLRUMaxPipelineSize) with a default value of LRU_MAX_PIPELINE_SIZE * 1024 * 1024. It can be modified at runtime using console commands or through configuration files.

This variable interacts closely with CVarLRUMaxPipelineSize, which is essentially an alias for r.Vulkan.PipelineLRUSize. They share the same value and purpose.

Developers must be aware that this variable directly affects the memory usage of the Vulkan pipeline cache. Setting it too low might result in frequent pipeline recompilations, while setting it too high could lead to excessive memory usage.

Best practices when using this variable include:

  1. Monitor performance and memory usage to find the optimal value for your specific project.
  2. Consider adjusting this value based on the target hardware capabilities.
  3. Be cautious when modifying this value in shipping builds, as it can significantly impact performance and memory usage.

Regarding the associated variable CVarLRUMaxPipelineSize:

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanPipeline.cpp:84

Scope: file

Source code excerpt:


TAutoConsoleVariable<int32> CVarLRUMaxPipelineSize(
	TEXT("r.Vulkan.PipelineLRUSize"),
	LRU_MAX_PIPELINE_SIZE * 1024 * 1024,
	TEXT("Maximum size of shader memory ."),
	ECVF_RenderThreadSafe);

TAutoConsoleVariable<int32> CVarLRUPipelineCapacity(
	TEXT("r.Vulkan.PipelineLRUCapactiy"),

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanPipeline.cpp:83

Scope: file

Source code excerpt:



TAutoConsoleVariable<int32> CVarLRUMaxPipelineSize(
	TEXT("r.Vulkan.PipelineLRUSize"),
	LRU_MAX_PIPELINE_SIZE * 1024 * 1024,
	TEXT("Maximum size of shader memory ."),
	ECVF_RenderThreadSafe);

TAutoConsoleVariable<int32> CVarLRUPipelineCapacity(

#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanPipeline.cpp:2497

Scope (from outer to inner):

file
function     void FVulkanPipelineStateCacheManager::LRUTrim

Source code excerpt:

	}
	uint32 tid = FPlatformTLS::GetCurrentThreadId();
	uint32 MaxSize = (uint32)CVarLRUMaxPipelineSize.GetValueOnAnyThread();
	while (LRUUsedPipelineSize + nSpaceNeeded > MaxSize || LRUUsedPipelineCount > LRUUsedPipelineMax)
	{
		LRUPRINT_DEBUG(TEXT("%d EVICTING %d + %d > %d || %d > %d\n"), tid, LRUUsedPipelineSize , nSpaceNeeded, MaxSize ,LRUUsedPipelineCount ,LRUUsedPipelineMax);
		LRUEvictOne();
	}
}

#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanPipeline.cpp:2526

Scope (from outer to inner):

file
function     void FVulkanPipelineStateCacheManager::LRUAdd

Source code excerpt:

	check(PSO->LRUNode == 0);
	check(PSO->GetVulkanPipeline());
	uint32 MaxSize = (uint32)CVarLRUMaxPipelineSize.GetValueOnAnyThread();
	uint32 PSOSize = PSO->PipelineCacheSize;

	LRUUsedPipelineSize += PSOSize;
	LRUUsedPipelineCount += 1;

	SET_DWORD_STAT(STAT_VulkanNumPSOLRUSize, LRUUsedPipelineSize);