MinTextureResidentMipCount

MinTextureResidentMipCount

#Overview

name: MinTextureResidentMipCount

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

It is referenced in 7 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of MinTextureResidentMipCount is to control the minimum number of mip levels that should remain resident in memory for textures in Unreal Engine 5. This setting is primarily used in the texture streaming system to manage memory usage and performance related to texture loading.

This setting variable is primarily relied upon by the Engine’s texture streaming subsystem and the Mutable plugin, which is an experimental plugin for runtime asset modification.

The value of this variable is set in multiple places:

  1. In the Engine’s initialization process (FSystemSettings::Initialize), it’s read from the GEngineIni configuration file under the [TextureStreaming] section.
  2. In the Mutable plugin, it’s set through the CompilerOptions::SetDataPackingStrategy function.

Other variables that interact with MinTextureResidentMipCount include:

  1. EmbeddedDataBytesLimit and PackagedDataBytesLimit in the Mutable plugin’s CompilerOptions.
  2. bSeparateImageMips, which controls the splitting of image data into mips for progressive textures.

Developers must be aware of the following when using this variable:

  1. It directly affects memory usage and texture streaming performance.
  2. Changing this value can impact the visual quality of distant objects or textures.
  3. In the Mutable plugin, it’s used during the compilation and linking process of mutable models.

Best practices when using this variable include:

  1. Carefully balance between memory usage and visual quality. A higher value will keep more mip levels in memory, potentially improving visual quality but increasing memory usage.
  2. Consider platform-specific requirements when setting this value, as mobile devices might benefit from a lower value to conserve memory.
  3. Test thoroughly after changing this value to ensure it doesn’t negatively impact performance or visual quality in your specific use case.
  4. When using the Mutable plugin, be mindful of how this value interacts with other compilation and linking options.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseEngine.ini:1810, section: [TextureStreaming]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Plugins/Experimental/Mutable/Source/MutableTools/Internal/MuT/AST.h:228

Scope (from outer to inner):

file
namespace    mu

Source code excerpt:


		// TODO: Unused?
		int32 MinTextureResidentMipCount = 0;

		/** This flag controls the splitting of image data into mips to store separately. It is usually necessary to
		* be able to generate progressive textures (for texture streaming).
		*/
		bool bSeparateImageMips = true;

#Loc: <Workspace>/Engine/Plugins/Experimental/Mutable/Source/MutableTools/Private/MuT/CodeOptimiser.cpp:484

Scope (from outer to inner):

file
namespace    mu
class        class FConstantTask
function     void Run

Source code excerpt:

			// Don't generate mips during linking here.
			FLinkerOptions LinkerOptions(ImOp);
			LinkerOptions.MinTextureResidentMipCount = 255;
			LinkerOptions.bSeparateImageMips = false;

			TSharedPtr<const Model> model = MakeShared<Model>();
			OP::ADDRESS at = ASTOp::FullLink(SourceCloned, model->GetPrivate()->m_program, &LinkerOptions);

			FProgram::FState state;

#Loc: <Workspace>/Engine/Plugins/Experimental/Mutable/Source/MutableTools/Private/MuT/Compiler.cpp:146

Scope (from outer to inner):

file
namespace    mu
function     void CompilerOptions::SetDataPackingStrategy

Source code excerpt:


	//---------------------------------------------------------------------------------------------
	void CompilerOptions::SetDataPackingStrategy(int32 MinTextureResidentMipCount, uint64 EmbeddedDataBytesLimit, uint64 PackagedDataBytesLimit)
	{
		m_pD->EmbeddedDataBytesLimit = EmbeddedDataBytesLimit;
		m_pD->PackagedDataBytesLimit = PackagedDataBytesLimit;
		m_pD->MinTextureResidentMipCount = MinTextureResidentMipCount;
	}


	//---------------------------------------------------------------------------------------------
	void CompilerOptions::SetEnableProgressiveImages(bool bEnabled)
	{

#Loc: <Workspace>/Engine/Plugins/Experimental/Mutable/Source/MutableTools/Private/MuT/Compiler.cpp:338

Scope (from outer to inner):

file
namespace    mu
function     TSharedPtr<Model> Compiler::Compile

Source code excerpt:

		for(FStateCompilationData& s: states )
        {
			LinkerOptions.MinTextureResidentMipCount = m_pD->m_options->GetPrivate()->MinTextureResidentMipCount;

            if (s.root)
            {
				s.state.m_root = ASTOp::FullLink(s.root, program, &LinkerOptions);
            }
            else

#Loc: <Workspace>/Engine/Plugins/Experimental/Mutable/Source/MutableTools/Private/MuT/CompilerPrivate.h:27

Scope (from outer to inner):

file
namespace    mu
class        class CompilerOptions::Private

Source code excerpt:


		// \TODO: Unused?
		int32 MinTextureResidentMipCount = 3;

        int32 ImageCompressionQuality = 0;
		int32 ImageTiling = 0 ;

		/** If this flag is enabled, the compiler can use concurrency to reduce compile time at the cost of higher CPU and memory usage. */
		bool bUseConcurrency = false;

#Loc: <Workspace>/Engine/Plugins/Experimental/Mutable/Source/MutableTools/Public/MuT/Compiler.h:75

Scope (from outer to inner):

file
namespace    mu
class        class CompilerOptions : public RefCounted

Source code excerpt:


        //! 
        void SetDataPackingStrategy( int32 MinTextureResidentMipCount, uint64 EmbeddedDataBytesLimit, uint64 PackagedDataBytesLimit);

		/** If enabled it will make sure that the object is compile to generate smaller mips of the images. */
		void SetEnableProgressiveImages(bool bEnabled);

		/** Set an optional pixel conversion function that will be called before any pixel format conversion. */
		void SetImagePixelFormatOverride(const FImageOperator::FImagePixelFormatFunc&);

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SystemSettings.cpp:230

Scope (from outer to inner):

file
function     void FSystemSettings::Initialize

Source code excerpt:


	// initialize a critical texture streaming value used by texture loading, etc
	int32 MinTextureResidentMipCount = 7;
	GConfig->GetInt(TEXT("TextureStreaming"), TEXT("MinTextureResidentMipCount"), MinTextureResidentMipCount, GEngineIni);
	UTexture2D::SetMinTextureResidentMipCount(MinTextureResidentMipCount);
}

void FSystemSettings::CVarSink()
{
	ApplyOverrides();
}