r.MobileMaxLoadedMips

r.MobileMaxLoadedMips

#Overview

name: r.MobileMaxLoadedMips

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.MobileMaxLoadedMips is to control the maximum number of loaded mip levels for textures on non-streaming mobile platforms in Unreal Engine’s rendering system.

This setting variable is primarily used by the Engine’s texture management system, specifically for mobile platforms. It’s part of the rendering subsystem and affects texture loading and memory usage.

The value of this variable is set through a console variable (CVar) named CVarMobileMaxLoadedMips. It’s initialized with a default value of MAX_TEXTURE_MIP_COUNT, which is likely defined elsewhere in the engine.

The associated variable CVarMobileMaxLoadedMips interacts directly with r.MobileMaxLoadedMips, as they share the same value. This console variable is used to access and modify the setting at runtime.

Developers must be aware that this variable affects memory usage and texture quality on mobile platforms. Setting it too low may result in lower quality textures, while setting it too high may increase memory consumption.

Best practices when using this variable include:

  1. Balancing texture quality and memory usage based on target mobile devices.
  2. Testing different values to find the optimal setting for your specific game and target hardware.
  3. Considering this setting in conjunction with other texture-related settings for mobile platforms.

Regarding the associated variable CVarMobileMaxLoadedMips:

It’s a TAutoConsoleVariable that directly represents r.MobileMaxLoadedMips in the engine’s code. It’s used to get the current value of the setting (as seen in the MobileReduceLoadedMips function) and can be modified at runtime through console commands.

The variable is declared as render thread safe (ECVF_RenderThreadSafe), meaning it can be safely accessed from both game and render threads.

When working with CVarMobileMaxLoadedMips, developers should:

  1. Use GetValueOnAnyThread() to safely retrieve its value from any thread.
  2. Be cautious when modifying this value at runtime, as it can affect performance and memory usage.
  3. Consider exposing this setting in user-facing graphics options for mobile versions of the game, allowing players to balance quality and performance.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Texture2D.cpp:90

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarMobileMaxLoadedMips(
	TEXT("r.MobileMaxLoadedMips"),
	MAX_TEXTURE_MIP_COUNT,
	TEXT("Maximum number of loaded mips for nonstreaming mobile platforms.\n"),
	ECVF_RenderThreadSafe);


int32 GUseGenericStreamingPath = 0;

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Texture2D.cpp:89

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarMobileMaxLoadedMips(
	TEXT("r.MobileMaxLoadedMips"),
	MAX_TEXTURE_MIP_COUNT,
	TEXT("Maximum number of loaded mips for nonstreaming mobile platforms.\n"),
	ECVF_RenderThreadSafe);

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Texture2D.cpp:112

Scope (from outer to inner):

file
function     static int32 MobileReduceLoadedMips

Source code excerpt:

	// note they are still cooked  &shipped
	int32 NumReduceMips = FMath::Max(0, CVarMobileReduceLoadedMips.GetValueOnAnyThread());
	int32 MaxLoadedMips = FMath::Clamp(CVarMobileMaxLoadedMips.GetValueOnAnyThread(), 1, GMaxTextureMipCount);

	int32 NumMips = NumTotalMips;
	// Reduce number of mips as requested
	NumMips = FMath::Max(NumMips - NumReduceMips, 1);
	// Clamp number of mips as requested
	NumMips = FMath::Min(NumMips, MaxLoadedMips);