r.TextureStreaming

r.TextureStreaming

#Overview

name: r.TextureStreaming

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

It is referenced in 20 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.TextureStreaming is to control whether texture streaming is enabled in Unreal Engine 5. Texture streaming is a technique used to dynamically load and unload texture mip levels based on what is visible on screen, which helps manage memory usage and improve performance.

This setting variable is primarily used by the rendering system and the texture streaming subsystem. It’s referenced in various parts of the engine, including:

  1. The Engine module (RendererSettings, ContentStreaming, TextureDerivedData)
  2. The MovieRenderPipeline plugin
  3. The MovieSceneCaptureDialog module

The value of this variable is set in multiple places:

  1. It’s defined as a console variable with a default value of 1 (enabled) in TextureStreamingHelpers.cpp
  2. It can be set through project settings in the URendererSettings class
  3. It can be overridden via command line arguments or console commands
  4. It’s automatically disabled if the hardware doesn’t support texture streaming or if running on a dedicated server

The associated variable CVarSetTextureStreaming interacts directly with r.TextureStreaming. They share the same value and are used interchangeably in the code.

Developers should be aware that:

  1. Disabling texture streaming can increase memory usage significantly
  2. Some code relies on the r.TextureStreaming value, so changing it can have wide-ranging effects
  3. The setting can be changed at runtime, but this may cause visual artifacts if not handled properly

Best practices when using this variable include:

  1. Generally, leave texture streaming enabled unless there’s a specific reason to disable it
  2. When disabling texture streaming for specific use cases (e.g., movie rendering), make sure to restore the original value afterward
  3. Be cautious when changing this value at runtime, as it may affect performance and visual quality

Regarding the associated variable CVarSetTextureStreaming:

The purpose of CVarSetTextureStreaming is to provide a programmatic way to control the r.TextureStreaming setting. It’s used internally by the engine to manage the texture streaming state.

This variable is primarily used in the Engine module, specifically in content streaming and texture-related code.

The value of CVarSetTextureStreaming is set in the same places as r.TextureStreaming, as they share the same value.

Developers should be aware that modifying CVarSetTextureStreaming directly will affect the r.TextureStreaming setting and vice versa.

Best practices for using CVarSetTextureStreaming include:

  1. Use it when you need to programmatically control texture streaming within C++ code
  2. Always consider the implications of changing texture streaming state on performance and memory usage
  3. Ensure that changes to this variable are synchronized with any other systems that depend on texture streaming state

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/RendererSettings.h:375

Scope (from outer to inner):

file
class        class URendererSettings : public UDeveloperSettings

Source code excerpt:


	UPROPERTY(config, EditAnywhere, Category=Textures, meta=(
		ConsoleVariable="r.TextureStreaming",DisplayName="Texture Streaming",
		ToolTip="When enabled textures will stream in based on what is visible on screen."))
	uint32 bTextureStreaming:1;

	UPROPERTY(config, EditAnywhere, Category=Textures, meta=(
		ConsoleVariable="Compat.UseDXT5NormalMaps",DisplayName="Use DXT5 Normal Maps",
		ToolTip="Whether to use DXT5 for normal maps, otherwise BC5 will be used, which is not supported on all hardware. Changing this setting requires restarting the editor.",

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Streaming/TextureStreamingHelpers.cpp:92

Scope: file

Source code excerpt:

#if PLATFORM_SUPPORTS_TEXTURE_STREAMING
TAutoConsoleVariable<int32> CVarSetTextureStreaming(
	TEXT("r.TextureStreaming"),
	1,
	TEXT("Allows to define if texture streaming is enabled, can be changed at run time.\n")
	TEXT("0: off\n")
	TEXT("1: on (default)"),
	ECVF_Default | ECVF_RenderThreadSafe);
#endif

#Loc: <Workspace>/Engine/Plugins/MovieScene/MovieRenderPipeline/Source/MovieRenderPipelineCore/Private/Graph/Nodes/MovieGraphGlobalGameOverrides.cpp:45

Scope (from outer to inner):

file
function     void UMovieGraphGlobalGameOverridesNode::BuildNewProcessCommandLineArgsImpl

Source code excerpt:

	if (bDisableTextureStreaming)
	{
		InOutDeviceProfileCvars.Add(TEXT("r.TextureStreaming=0"));
	}

	if (bDisableLODs)
	{
		InOutDeviceProfileCvars.Add(TEXT("r.ForceLOD=0"));
		InOutDeviceProfileCvars.Add(TEXT("r.SkeletalMeshLODBias=-10"));

#Loc: <Workspace>/Engine/Plugins/MovieScene/MovieRenderPipeline/Source/MovieRenderPipelineCore/Private/Graph/Nodes/MovieGraphGlobalGameOverrides.cpp:111

Scope (from outer to inner):

file
function     void UMovieGraphGlobalGameOverridesNode::ApplySettings

Source code excerpt:

	if (bDisableTextureStreaming)
	{
		MOVIEPIPELINE_STORE_AND_OVERRIDE_CVAR_INT(PreviousTextureStreaming, TEXT("r.TextureStreaming"), 0, bOverrideValues);
	}
	
	if (bDisableLODs)
	{
		MOVIEPIPELINE_STORE_AND_OVERRIDE_CVAR_INT(PreviousForceLOD, TEXT("r.ForceLOD"), 0, bOverrideValues);
		MOVIEPIPELINE_STORE_AND_OVERRIDE_CVAR_INT(PreviousSkeletalMeshBias, TEXT("r.SkeletalMeshLODBias"), -10, bOverrideValues);

#Loc: <Workspace>/Engine/Plugins/MovieScene/MovieRenderPipeline/Source/MovieRenderPipelineCore/Private/MoviePipelineGameOverrideSetting.cpp:55

Scope (from outer to inner):

file
function     void UMoviePipelineGameOverrideSetting::ApplyCVarSettings

Source code excerpt:

		break;
	case EMoviePipelineTextureStreamingMethod::Disabled:
		MOVIEPIPELINE_STORE_AND_OVERRIDE_CVAR_INT(PreviousTextureStreaming, TEXT("r.TextureStreaming"), 0, bOverrideValues);
		break;
	default:
		// We don't change their texture streaming settings.
		break;
	}

#Loc: <Workspace>/Engine/Plugins/MovieScene/MovieRenderPipeline/Source/MovieRenderPipelineCore/Private/MoviePipelineGameOverrideSetting.cpp:181

Scope (from outer to inner):

file
function     void UMoviePipelineGameOverrideSetting::BuildNewProcessCommandLineArgsImpl

Source code excerpt:

		break;
	case EMoviePipelineTextureStreamingMethod::Disabled:
		InOutDeviceProfileCvars.Add(TEXT("r.TextureStreaming=0"));
		break;
	default:
		// We don't change their texture streaming settings.
		break;
	}

#Loc: <Workspace>/Engine/Plugins/MovieScene/MovieRenderPipeline/Source/MovieRenderPipelineCore/Public/Graph/Nodes/MovieGraphGlobalGameOverrides.h:107

Scope (from outer to inner):

file
function     class MOVIERENDERPIPELINECORE_API UMovieGraphGlobalGameOverridesNode : public UMovieGraphSettingNode { GENERATED_BODY

Source code excerpt:

	 *
	 * Configures the following cvars:
	 * - r.TextureStreaming
	 */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Rendering", meta = (EditCondition = "bOverride_bDisableTextureStreaming"))
	bool bDisableTextureStreaming;

	/**
	 * Disabling LODs will use the highest quality LOD for meshes and particle systems, regardless of distance. Note
	 * that this does not affect Nanite.
	 *
	 * Configures the following cvars:
	 * - r.ForceLOD
	 * - r.SkeletalMeshLODBias

#Loc: <Workspace>/Engine/Source/Editor/MovieSceneCaptureDialog/Private/MovieSceneCaptureDialogModule.cpp:420

Scope (from outer to inner):

file
function     void FInEditorCapture::Start

Source code excerpt:

		}

		IConsoleVariable* CVarTextureStreaming = IConsoleManager::Get().FindConsoleVariable(TEXT("r.TextureStreaming"));
		if (CVarTextureStreaming)
		{
			BackedUpTextureStreaming = CVarTextureStreaming->GetInt();
			CVarTextureStreaming->Set(0, ECVF_SetByConsole);
		}
	}

#Loc: <Workspace>/Engine/Source/Editor/MovieSceneCaptureDialog/Private/MovieSceneCaptureDialogModule.cpp:582

Scope (from outer to inner):

file
function     void FInEditorCapture::Shutdown

Source code excerpt:

		}

		IConsoleVariable* CVarTextureStreaming = IConsoleManager::Get().FindConsoleVariable(TEXT("r.TextureStreaming"));
		if (CVarTextureStreaming)
		{
			CVarTextureStreaming->Set(BackedUpTextureStreaming, ECVF_SetByConsole);
		}
	}

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/ContentStreaming.cpp:1304

Scope (from outer to inner):

file
function     void FStreamingManagerCollection::AddOrRemoveTextureStreamingManagerIfNeeded

Source code excerpt:

			bUseTextureStreaming = false;

			// some code relies on r.TextureStreaming so we're going to disable it here to reflect the hardware capabilities and system needs
			CVarSetTextureStreaming.AsVariable()->Set(0, ECVF_SetByCode);
		}
	}
#endif

	if ( bUseTextureStreaming )

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/TextureDerivedData.cpp:2168

Scope (from outer to inner):

file
function     bool FTexturePlatformData::TryLoadMipsWithSizes

Source code excerpt:

#if PLATFORM_SUPPORTS_TEXTURE_STREAMING
				// We want to make sure that any non-streamed mips are coming from the texture asset file, and not from an external bulk file.
				// But because "r.TextureStreaming" is driven by the project setting as well as the command line option "-NoTextureStreaming", 
				// is it possible for streaming mips to be loaded in non streaming ways.
				// Also check if editor data is available, in which case we are probably loading cooked data in the editor.
				if (!FPlatformProperties::HasEditorOnlyData() && CVarSetTextureStreaming.GetValueOnAnyThread() != 0)
				{
					UE_CLOG(Mip.BulkData.IsInSeparateFile(), LogTexture, Error, TEXT("Loading non-streamed mips from an external bulk file.  This is not desireable.  File %s"),
						*(Mip.BulkData.GetDebugName()) );

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/ContentStreaming.cpp:776

Scope (from outer to inner):

file
function     FStreamingManagerCollection::FStreamingManagerCollection

Source code excerpt:

	if( FParse::Param( FCommandLine::Get(), TEXT( "NoTextureStreaming" ) ) )
	{
		CVarSetTextureStreaming.AsVariable()->Set(0, ECVF_SetByCommandline);
	}
#endif

	AddOrRemoveTextureStreamingManagerIfNeeded(true);

	if (FApp::CanEverRenderAudio())

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/ContentStreaming.cpp:1295

Scope (from outer to inner):

file
function     void FStreamingManagerCollection::AddOrRemoveTextureStreamingManagerIfNeeded

Source code excerpt:

#if PLATFORM_SUPPORTS_TEXTURE_STREAMING
	{
		bUseTextureStreaming = CVarSetTextureStreaming.GetValueOnGameThread() != 0;
	}

	if( !GRHISupportsTextureStreaming || IsRunningDedicatedServer() )
	{
		if (bUseTextureStreaming)
		{

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/ContentStreaming.cpp:1305

Scope (from outer to inner):

file
function     void FStreamingManagerCollection::AddOrRemoveTextureStreamingManagerIfNeeded

Source code excerpt:


			// some code relies on r.TextureStreaming so we're going to disable it here to reflect the hardware capabilities and system needs
			CVarSetTextureStreaming.AsVariable()->Set(0, ECVF_SetByCode);
		}
	}
#endif

	if ( bUseTextureStreaming )
	{

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Streaming/TextureStreamingHelpers.cpp:91

Scope: file

Source code excerpt:


#if PLATFORM_SUPPORTS_TEXTURE_STREAMING
TAutoConsoleVariable<int32> CVarSetTextureStreaming(
	TEXT("r.TextureStreaming"),
	1,
	TEXT("Allows to define if texture streaming is enabled, can be changed at run time.\n")
	TEXT("0: off\n")
	TEXT("1: on (default)"),
	ECVF_Default | ECVF_RenderThreadSafe);

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Streaming/TextureStreamingHelpers.h:54

Scope: file

Source code excerpt:


#if PLATFORM_SUPPORTS_TEXTURE_STREAMING
extern TAutoConsoleVariable<int32> CVarSetTextureStreaming;
#endif

extern TAutoConsoleVariable<float> CVarStreamingBoost;
extern TAutoConsoleVariable<float> CVarStreamingMinBoost;
extern TAutoConsoleVariable<int32> CVarStreamingUseFixedPoolSize;
extern TAutoConsoleVariable<int32> CVarStreamingPoolSize;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/TextureDerivedData.cpp:2171

Scope (from outer to inner):

file
function     bool FTexturePlatformData::TryLoadMipsWithSizes

Source code excerpt:

				// is it possible for streaming mips to be loaded in non streaming ways.
				// Also check if editor data is available, in which case we are probably loading cooked data in the editor.
				if (!FPlatformProperties::HasEditorOnlyData() && CVarSetTextureStreaming.GetValueOnAnyThread() != 0)
				{
					UE_CLOG(Mip.BulkData.IsInSeparateFile(), LogTexture, Error, TEXT("Loading non-streamed mips from an external bulk file.  This is not desireable.  File %s"),
						*(Mip.BulkData.GetDebugName()) );
				}
#endif
				Mip.BulkData.GetCopy(&OutMipData[MipIndex - FirstMipToLoad], true);

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:6216

Scope (from outer to inner):

file
function     bool UEngine::HandleListTexturesCommand

Source code excerpt:


	FRenderAssetStreamingManager* Streamer = nullptr;
	if (!IStreamingManager::HasShutdown() && !!CVarSetTextureStreaming.GetValueOnAnyThread())
	{
		Streamer = (FRenderAssetStreamingManager*)&IStreamingManager::Get().GetRenderAssetStreamingManager();
		Streamer->UpdateResourceStreaming(0.f, true);
	}

	int32 NumApplicableToMinSize = 0;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:6484

Scope (from outer to inner):

file
function     bool UEngine::HandleListStaticMeshesCommand

Source code excerpt:


	FRenderAssetStreamingManager* Streamer = nullptr;
	if (!IStreamingManager::HasShutdown() && !!CVarSetTextureStreaming.GetValueOnAnyThread())
	{
		Streamer = (FRenderAssetStreamingManager*)&IStreamingManager::Get().GetRenderAssetStreamingManager();
		Streamer->UpdateResourceStreaming(0.f, true);
	}

	//Collect usage counts

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:6807

Scope (from outer to inner):

file
function     bool UEngine::HandleListSkeletalMeshesCommand

Source code excerpt:


	FRenderAssetStreamingManager* Streamer = nullptr;
	if (!IStreamingManager::HasShutdown() && !!CVarSetTextureStreaming.GetValueOnAnyThread())
	{
		Streamer = (FRenderAssetStreamingManager*)&IStreamingManager::Get().GetRenderAssetStreamingManager();
		Streamer->UpdateResourceStreaming(0.f, true);
	}

	// Collect meshes.