r.TextureProfiler.MinTextureSizeMB

r.TextureProfiler.MinTextureSizeMB

#Overview

name: r.TextureProfiler.MinTextureSizeMB

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.TextureProfiler.MinTextureSizeMB is to set a minimum size threshold for textures to be reported by the texture profiler in Unreal Engine 5. It’s primarily used for performance profiling and optimization of the rendering system.

This setting variable is used within the RHI (Rendering Hardware Interface) module of Unreal Engine 5, specifically in the texture profiling system. The texture profiler is responsible for tracking and reporting texture usage and sizes, which is crucial for optimizing memory usage and rendering performance.

The value of this variable is set through a console variable (CVar) system, which allows it to be changed at runtime. It’s initialized with a default value of 16 MB in the source code.

This variable interacts closely with another variable named CVarTextureProfilerMinRenderTargetSizeMB, which sets a similar threshold for render targets. Together, these variables control the granularity of texture profiling in the engine.

Developers should be aware that this variable affects the level of detail in texture profiling. Setting it too low might result in excessive reporting of small textures, potentially overwhelming the profiler and making it harder to identify significant texture usage. Conversely, setting it too high might hide important information about smaller textures.

Best practices when using this variable include:

  1. Adjusting it based on the project’s specific needs and texture usage patterns.
  2. Using it in conjunction with CVarTextureProfilerMinRenderTargetSizeMB for comprehensive texture profiling.
  3. Monitoring its impact on profiling performance, especially in large projects.

Regarding the associated variable CVarTextureProfilerMinTextureSizeMB:

The purpose of CVarTextureProfilerMinTextureSizeMB is to provide a programmatic interface to the r.TextureProfiler.MinTextureSizeMB setting. It’s used internally by the engine to access and modify the minimum texture size threshold for profiling.

This variable is used in the same RHI module, specifically in the FTextureProfiler class methods. It’s used to retrieve the current threshold value and apply it in texture profiling operations.

The value of CVarTextureProfilerMinTextureSizeMB is set automatically by the CVar system when r.TextureProfiler.MinTextureSizeMB is modified, ensuring they always have the same value.

CVarTextureProfilerMinTextureSizeMB interacts directly with the texture profiling logic, influencing which textures are individually reported and which are grouped into an “Other” category.

Developers should be aware that this variable is the internal representation of the console variable and should generally be accessed through the CVar system rather than directly.

Best practices for using CVarTextureProfilerMinTextureSizeMB include:

  1. Using GetValueOnAnyThread() method when accessing its value, as shown in the code examples.
  2. Considering thread safety when accessing or modifying this variable in multithreaded contexts.
  3. Using this variable in conjunction with engine profiling tools to optimize texture memory usage.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/TextureProfiler.cpp:34

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarTextureProfilerMinTextureSizeMB(
	TEXT("r.TextureProfiler.MinTextureSizeMB"),
	16,
	TEXT("The minimum size for any texture to be reported.  All textures below this threshold will be reported as Other."));

static TAutoConsoleVariable<int32> CVarTextureProfilerMinRenderTargetSizeMB(
	TEXT("r.TextureProfiler.MinRenderTargetSizeMB"),
	0,

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/TextureProfiler.cpp:33

Scope: file

Source code excerpt:

CSV_DEFINE_CATEGORY(TextureWasteProfiler, true);

static TAutoConsoleVariable<int32> CVarTextureProfilerMinTextureSizeMB(
	TEXT("r.TextureProfiler.MinTextureSizeMB"),
	16,
	TEXT("The minimum size for any texture to be reported.  All textures below this threshold will be reported as Other."));

static TAutoConsoleVariable<int32> CVarTextureProfilerMinRenderTargetSizeMB(
	TEXT("r.TextureProfiler.MinRenderTargetSizeMB"),

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/TextureProfiler.cpp:321

Scope (from outer to inner):

file
function     void FTextureProfiler::Update

Source code excerpt:

	FScopeLock Lock(&TextureMapCS);
	
	size_t MinTextureSize = (size_t)CVarTextureProfilerMinTextureSizeMB.GetValueOnAnyThread() * 1024LL * 1024LL;
	size_t MinRenderTargetSize = (size_t)CVarTextureProfilerMinRenderTargetSizeMB.GetValueOnAnyThread() * 1024LL * 1024LL;

	// Keep track of all stats that have been added this round.  the CVS trace profiler wants to know what stats have been added, but only once per frame
	// Keep one set per category
	struct ECategoryIndex
	{

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/TextureProfiler.cpp:409

Scope (from outer to inner):

file
function     void FTextureProfiler::DumpTextures

Source code excerpt:

		OutputDevice.Logf(TEXT("%s%c%s%c%s%c%s"), TEXT("Texture"), Sep, TEXT("Combined Size(MB)"), Sep, TEXT("Count"), Sep, TEXT("Combined Wasted(KB)"));

		size_t MinTextureSize = CVarTextureProfilerMinTextureSizeMB.GetValueOnAnyThread() * 1024 * 1024;
		size_t MinRenderTargetSize = CVarTextureProfilerMinRenderTargetSizeMB.GetValueOnAnyThread() * 1024 * 1024;

		size_t MinSize = RenderTargets ? MinRenderTargetSize : MinTextureSize;

		const TMap<FName, FTextureDetails>& CombinedSizes = RenderTargets ? CombinedRenderTargetSizes : CombinedTextureSizes;