r.SceneRenderTargetResizeMethod

r.SceneRenderTargetResizeMethod

#Overview

name: r.SceneRenderTargetResizeMethod

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

It is referenced in 6 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.SceneRenderTargetResizeMethod is to control how scene render targets are resized in Unreal Engine. This setting is primarily used by the rendering system to manage memory usage and performance when rendering the scene.

This variable is primarily utilized by the Renderer module of Unreal Engine, as evidenced by its definition in the SceneTextures.cpp file. It’s also referenced in plugins like PanoramicCapture and nDisplay, indicating its importance in specialized rendering scenarios.

The value of this variable is set through the console variable system. It can be set programmatically or through console commands. The default value is 0, as defined in the CVarSceneTargetsResizeMethod declaration.

The variable interacts closely with CVarSceneTargetsResizeMethod, which appears to be the internal representation of the console variable. They share the same value and are used interchangeably in the code.

Developers should be aware that:

  1. This setting affects memory usage and potential stalls during rendering, especially when the scene size changes.
  2. It’s primarily used in game mode and on windowing platforms unless forced otherwise.
  3. Changing this value can impact performance and memory usage, so it should be done with careful consideration.

Best practices when using this variable include:

  1. Consider the trade-offs between memory usage and performance when choosing a value.
  2. Test thoroughly after changing this value, especially in scenarios where the render size might change frequently.
  3. Be aware of how this setting interacts with other rendering settings, such as ScreenPercentage.

Regarding the associated variable CVarSceneTargetsResizeMethod:

The purpose of CVarSceneTargetsResizeMethod is to serve as the internal representation of the r.SceneRenderTargetResizeMethod console variable. It’s used within the engine code to access and modify the resize method setting.

This variable is defined and used primarily within the Renderer module, specifically in the SceneTextures.cpp file. It’s used to control the behavior of scene target sizing in the FSceneTextureExtentState class.

The value of CVarSceneTargetsResizeMethod is set when the r.SceneRenderTargetResizeMethod console variable is modified. It’s accessed using the GetValueOnRenderThread() method, ensuring thread-safe access in rendering code.

Developers should be aware that modifying CVarSceneTargetsResizeMethod directly is not recommended. Instead, they should use the r.SceneRenderTargetResizeMethod console variable to change the resize method.

Best practices for CVarSceneTargetsResizeMethod include:

  1. Accessing its value using GetValueOnRenderThread() in render thread code for thread safety.
  2. Avoiding direct modification of this variable, instead using the console variable system.
  3. Being aware of its impact on scene target sizing when working on rendering code.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneTextures.cpp:23

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarSceneTargetsResizeMethod(
	TEXT("r.SceneRenderTargetResizeMethod"),
	0,
	TEXT("Control the scene render target resize method:\n")
	TEXT("(This value is only used in game mode and on windowing platforms unless 'r.SceneRenderTargetsResizingMethodForceOverride' is enabled.)\n")
	TEXT("0: Resize to match requested render size (Default) (Least memory use, can cause stalls when size changes e.g. ScreenPercentage)\n")
	TEXT("1: Fixed to screen resolution.\n")
	TEXT("2: Expands to encompass the largest requested render dimension. (Most memory use, least prone to allocation stalls.)"),	

#Loc: <Workspace>/Engine/Plugins/Experimental/PanoramicCapture/Source/PanoramicCapture/Private/SceneCapturer.cpp:306

Scope (from outer to inner):

file
function     USceneCapturer::USceneCapturer

Source code excerpt:

    //NOTE: ikrimae: Ensure that the main gameview is > CaptureWidth x CaptureHeight. Bug in Unreal Engine that won't re-alloc scene render targets to the correct size
    //               when the scenecapture component > current window render target. https://answers.unrealengine.com/questions/80531/scene-capture-2d-max-resolution.html
    //TODO: ikrimae: Ensure that r.SceneRenderTargetResizeMethod=2
    FSystemResolution::RequestResolutionChange(CaptureWidth, CaptureHeight, EWindowMode::Windowed);

	// Creating CaptureSceneComponent to use it as parent scene component.
	// This scene component will hold same world location from camera.
	// Camera rotation will be used following UseCameraRotation settings.
	// Then, angular step turn will be applied to capture components locally to simplify calculation step that finding proper rotation.

#Loc: <Workspace>/Engine/Plugins/Runtime/nDisplay/Source/DisplayCluster/Private/Game/EngineClasses/Basics/DisplayClusterViewportClient.cpp:365

Scope (from outer to inner):

file
function     void UDisplayClusterViewportClient::Init

Source code excerpt:

		}

		// r.SceneRenderTargetResizeMethod
		IConsoleVariable* const RTResizeCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.SceneRenderTargetResizeMethod"));
		if (RTResizeCVar)
		{
			RTResizeCVar->Set(int32(2));
		}

		// RHI.MaximumFrameLatency

#Loc: <Workspace>/Engine/Plugins/Runtime/nDisplay/Source/DisplayCluster/Private/Render/Viewport/DisplayClusterViewportManager.cpp:322

Scope (from outer to inner):

file
function     void FDisplayClusterViewportManager::UpdateSceneRenderTargetSize

Source code excerpt:

	if (SceneRenderTargetResizeMethod != ESceneRenderTargetResizeMethod::None)
	{
		IConsoleVariable* const RTResizeCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.SceneRenderTargetResizeMethod"));
		if (RTResizeCVar)
		{
			switch (SceneRenderTargetResizeMethod)
			{
			case ESceneRenderTargetResizeMethod::Reset:
				// Resize to match requested render size (Default) (Least memory use, can cause stalls when size changes e.g. ScreenPercentage)

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneTextures.cpp:22

Scope: file

Source code excerpt:

#include "Substrate/Substrate.h"

static TAutoConsoleVariable<int32> CVarSceneTargetsResizeMethod(
	TEXT("r.SceneRenderTargetResizeMethod"),
	0,
	TEXT("Control the scene render target resize method:\n")
	TEXT("(This value is only used in game mode and on windowing platforms unless 'r.SceneRenderTargetsResizingMethodForceOverride' is enabled.)\n")
	TEXT("0: Resize to match requested render size (Default) (Least memory use, can cause stalls when size changes e.g. ScreenPercentage)\n")
	TEXT("1: Fixed to screen resolution.\n")

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneTextures.cpp:236

Scope (from outer to inner):

file
class        class FSceneTextureExtentState
function     FIntPoint Compute

Source code excerpt:

				// #jira UE-156400: The 'clamp()' includes min and max values, so the range is [0 .. Count-1]
				// The checkNoEntry() macro is called from 'default:' in the switch() below, when the SceneTargetsSizingMethod is out of the supported range.
				SceneTargetsSizingMethod = (ESizingMethods)FMath::Clamp(CVarSceneTargetsResizeMethod.GetValueOnRenderThread(), 0, (int32)VisibleSizingMethodsCount - 1);
			}
		}

		switch (SceneTargetsSizingMethod)
		{
		case RequestedSize: