r.Vulkan.DSetCacheTargetSetsPerPool

r.Vulkan.DSetCacheTargetSetsPerPool

#Overview

name: r.Vulkan.DSetCacheTargetSetsPerPool

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.Vulkan.DSetCacheTargetSetsPerPool is to control the target number of descriptor set allocations per single pool in the Vulkan rendering backend of Unreal Engine 5.

This setting variable is primarily used in the Vulkan RHI (Rendering Hardware Interface) subsystem of Unreal Engine 5. It is specifically utilized in the descriptor set cache management, which is a crucial part of the Vulkan rendering pipeline.

The value of this variable is set through the console variable system, as evidenced by the FAutoConsoleVariableRef declaration. It’s initialized with a default value of 4096 and can be modified at runtime through console commands or configuration files.

The associated variable GDSetCacheTargetSetsPerPool directly interacts with r.Vulkan.DSetCacheTargetSetsPerPool. They share the same value, with GDSetCacheTargetSetsPerPool being the actual integer variable used in the code.

Developers should be aware that this variable is marked as read-only and render thread safe (ECVF_ReadOnly | ECVF_RenderThreadSafe). This means it should not be modified during rendering operations and is intended to be set at initialization or between frames.

Best practices when using this variable include:

  1. Adjusting it based on the specific needs of your application, considering memory usage and performance implications.
  2. Testing different values to find the optimal balance between memory usage and descriptor set allocation efficiency.
  3. Avoiding frequent changes to this value, as it affects the allocation strategy of descriptor set pools.

Regarding the associated variable GDSetCacheTargetSetsPerPool:

The purpose of GDSetCacheTargetSetsPerPool is to store the actual integer value used in the code for determining the target number of descriptor set allocations per pool.

This variable is used directly in the VulkanRHI module, specifically in the FVulkanDescriptorSetCache class. It influences the allocation strategy for descriptor set pools, which are crucial for efficient resource binding in Vulkan.

The value of GDSetCacheTargetSetsPerPool is set through the console variable system, mirroring the value of r.Vulkan.DSetCacheTargetSetsPerPool.

It interacts with other variables and calculations in the descriptor set cache management system. For example, it’s used to calculate the MaxDescriptorSets value, which determines the size of descriptor set pools.

Developers should be aware that changes to this variable will directly affect the memory allocation patterns for descriptor sets, which can impact both performance and memory usage.

Best practices include:

  1. Monitoring the actual descriptor set usage in your application to determine if the default value is appropriate.
  2. Considering the trade-off between larger pools (which might waste memory) and smaller pools (which might require more frequent allocations).
  3. Profiling the application with different values to find the optimal setting for your specific use case.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanPendingState.cpp:582

Scope: file

Source code excerpt:

int32 GDSetCacheTargetSetsPerPool = 4096;
FAutoConsoleVariableRef CVarDSetCacheTargetSetsPerPool(
	TEXT("r.Vulkan.DSetCacheTargetSetsPerPool"),
	GDSetCacheTargetSetsPerPool,
	TEXT("Target number of descriptor set allocations per single pool.\n"),
	ECVF_ReadOnly | ECVF_RenderThreadSafe
);

int32 GDSetCacheMaxPoolLookups = 2;

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanPendingState.cpp:580

Scope: file

Source code excerpt:

}

int32 GDSetCacheTargetSetsPerPool = 4096;
FAutoConsoleVariableRef CVarDSetCacheTargetSetsPerPool(
	TEXT("r.Vulkan.DSetCacheTargetSetsPerPool"),
	GDSetCacheTargetSetsPerPool,
	TEXT("Target number of descriptor set allocations per single pool.\n"),
	ECVF_ReadOnly | ECVF_RenderThreadSafe
);

int32 GDSetCacheMaxPoolLookups = 2;
FAutoConsoleVariableRef CVarDSetCacheMaxPoolLookups(

#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanPendingState.cpp:696

Scope (from outer to inner):

file
function     void FVulkanDescriptorSetCache::AddCachedPool

Source code excerpt:

{
	check(PoolAllocRatio > 0.0f);
	const uint32 MaxDescriptorSets = FMath::RoundFromZero(GDSetCacheTargetSetsPerPool / PoolAllocRatio);
	if (FreePool)
	{
		constexpr float MinErrorTolerance = -0.10f;
		constexpr float MaxErrorTolerance = 0.50f;
		const float Error = ((static_cast<float>(FreePool->GetMaxDescriptorSets()) - static_cast<float>(MaxDescriptorSets)) / static_cast<float>(MaxDescriptorSets));
		if ((Error >= MinErrorTolerance) && (Error <= MaxErrorTolerance))