r.Streaming.MaxNumTexturesToStreamPerFrame

r.Streaming.MaxNumTexturesToStreamPerFrame

#Overview

name: r.Streaming.MaxNumTexturesToStreamPerFrame

The value of this variable can be defined or overridden in .ini config files. 5 .ini config files referencing this setting variable.

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.Streaming.MaxNumTexturesToStreamPerFrame is to control the maximum number of 2D textures allowed to stream from CPU memory to GPU memory in each frame. This setting is part of Unreal Engine’s texture streaming system, which is responsible for managing the loading and unloading of texture data to optimize memory usage and performance.

The texture streaming system, which is part of Unreal Engine’s rendering subsystem, relies on this setting variable. It is primarily used in the StreamingManagerTexture.cpp file, which is part of the Engine module.

The value of this variable is set through a console variable (CVar) system, allowing it to be adjusted at runtime. It is defined with a default value of 0, which means no limit is imposed by default.

This variable interacts closely with another console variable, r.Streaming.AmortizeCPUToGPUCopy. The effect of r.Streaming.MaxNumTexturesToStreamPerFrame is only applied when r.Streaming.AmortizeCPUToGPUCopy is set.

Developers must be aware that:

  1. Setting this value to 0 or a negative number means no limit will be applied.
  2. The variable only takes effect when r.Streaming.AmortizeCPUToGPUCopy is set.
  3. This setting can impact performance and memory usage, especially on platforms with limited resources.

Best practices when using this variable include:

  1. Use it in conjunction with r.Streaming.AmortizeCPUToGPUCopy for more granular control over texture streaming.
  2. Adjust the value based on the target platform’s capabilities and the game’s specific requirements.
  3. Monitor performance metrics when adjusting this value to find the optimal setting for your game.

The associated variable CVarTextureStreamingMaxNumTexturesToStreamPerFrame is the internal representation of the r.Streaming.MaxNumTexturesToStreamPerFrame console variable. It is used within the engine code to access and modify the setting’s value. This variable is defined using the TAutoConsoleVariable template, which allows it to be easily accessed and modified through the console variable system.

The CVarTextureStreamingMaxNumTexturesToStreamPerFrame variable is used in the ShouldAmortizeMipCopies() function to determine if mip copies should be amortized, and in the ProcessPendingMipCopyRequests() function to control the number of textures processed per frame. Developers should be aware that changes to the console variable will directly affect the behavior of these functions and, consequently, the texture streaming system’s performance.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseScalability.ini:558, section: [TextureQuality@0]

Location: <Workspace>/Engine/Config/BaseScalability.ini:569, section: [TextureQuality@1]

Location: <Workspace>/Engine/Config/BaseScalability.ini:580, section: [TextureQuality@2]

Location: <Workspace>/Engine/Config/BaseScalability.ini:591, section: [TextureQuality@3]

Location: <Workspace>/Engine/Config/BaseScalability.ini:602, section: [TextureQuality@Cine]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Streaming/StreamingManagerTexture.cpp:1425

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarTextureStreamingMaxNumTexturesToStreamPerFrame(
	TEXT("r.Streaming.MaxNumTexturesToStreamPerFrame"),
	0,
	TEXT("Maximum number of 2D textures allowed to stream from CPU memory to GPU memory each frame. ")
	TEXT("<= 0 means no limit. This has no effect if r.Streaming.AmortizeCPUToGPUCopy is not set"),
	ECVF_Scalability | ECVF_ExcludeFromPreview);

static FORCEINLINE bool ShouldAmortizeMipCopies()

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Streaming/StreamingManagerTexture.cpp:1424

Scope: file

Source code excerpt:

	ECVF_Scalability | ECVF_ExcludeFromPreview);

static TAutoConsoleVariable<int32> CVarTextureStreamingMaxNumTexturesToStreamPerFrame(
	TEXT("r.Streaming.MaxNumTexturesToStreamPerFrame"),
	0,
	TEXT("Maximum number of 2D textures allowed to stream from CPU memory to GPU memory each frame. ")
	TEXT("<= 0 means no limit. This has no effect if r.Streaming.AmortizeCPUToGPUCopy is not set"),
	ECVF_Scalability | ECVF_ExcludeFromPreview);

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Streaming/StreamingManagerTexture.cpp:1434

Scope (from outer to inner):

file
function     static bool ShouldAmortizeMipCopies

Source code excerpt:

{
	return CVarTextureStreamingAmortizeCPUToGPUCopy.GetValueOnGameThread()
		&& CVarTextureStreamingMaxNumTexturesToStreamPerFrame.GetValueOnGameThread() > 0;
}

/**
 * Stream textures/meshes in/out, based on the priorities calculated by the async work.
 * @param bProcessEverything	Whether we're processing all textures in one go
 */

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Streaming/StreamingManagerTexture.cpp:1536

Scope (from outer to inner):

file
function     void FRenderAssetStreamingManager::ProcessPendingMipCopyRequests

Source code excerpt:


	TArray<FStreamingRenderAsset>& StreamingRenderAssets = GetStreamingRenderAssetsAsyncSafe();
	int32 NumRemainingRequests = CVarTextureStreamingMaxNumTexturesToStreamPerFrame.GetValueOnGameThread();

	while (NumRemainingRequests
		&& CurrentPendingMipCopyRequestIdx < PendingMipCopyRequests.Num())
	{
		const FPendingMipCopyRequest& Request = PendingMipCopyRequests[CurrentPendingMipCopyRequestIdx++];