r.AllowHDR

r.AllowHDR

#Overview

name: r.AllowHDR

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.AllowHDR is to enable or disable High Dynamic Range (HDR) support for a project in Unreal Engine 5. It is primarily used for the rendering system, specifically for HDR display output.

This setting variable is mainly relied upon by the RenderCore module of Unreal Engine 5, as evident from its location in the RenderCore.cpp file.

The value of this variable is set through a console variable (CVarAllowHDR) defined in the RenderCore.cpp file. It can be set in the project’s defaultengine.ini file on a per-project or per-platform basis. The default value is 0 (disabled).

The r.AllowHDR variable interacts with command-line parameters. If “-hdr” is passed as a command-line argument, HDR will be forced on, overriding the console variable. Similarly, if “-nohdr” is passed, HDR will be forced off.

Developers must be aware that this variable is marked as ECVF_ReadOnly, meaning its value should not be changed at runtime. It’s intended to be set at startup and remain constant throughout the application’s lifecycle.

Best practices when using this variable include:

  1. Setting it in the project’s defaultengine.ini file for consistent behavior across builds.
  2. Ensuring that the hardware and platform support HDR before enabling it.
  3. Testing the application thoroughly with HDR both enabled and disabled to ensure proper rendering in all scenarios.

Regarding the associated variable CVarAllowHDR:

The purpose of CVarAllowHDR is to serve as the actual console variable implementation of r.AllowHDR. It’s an instance of TAutoConsoleVariable that directly controls the HDR setting.

CVarAllowHDR is used within the RenderCore module, specifically in the IsHDRAllowed() function, to determine if HDR should be enabled.

The value of CVarAllowHDR is set when it’s initialized in the RenderCore.cpp file. It can be modified through console commands or configuration files.

CVarAllowHDR interacts closely with r.AllowHDR, essentially providing the backend for the r.AllowHDR setting.

Developers should be aware that CVarAllowHDR is the actual variable being checked in the code, while r.AllowHDR is the console command used to set it.

Best practices for CVarAllowHDR include:

  1. Avoid directly modifying it in code; instead, use the r.AllowHDR console command or configuration settings.
  2. When querying the HDR status, use the IsHDRAllowed() function rather than directly accessing CVarAllowHDR.
  3. Remember that changes to this variable may not take effect immediately due to its ReadOnly nature.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/RenderCore.cpp:342

Scope: file

Source code excerpt:

// Note: Enables or disables HDR support for a project. Typically this would be set on a per-project/per-platform basis in defaultengine.ini
TAutoConsoleVariable<int32> CVarAllowHDR(
	TEXT("r.AllowHDR"),
	0,
	TEXT("Creates an HDR compatible swap-chain and enables HDR display output.")
	TEXT("0: Disabled (default)\n")
	TEXT("1: Allow HDR, if supported by the platform and display \n"),
	ECVF_ReadOnly);

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/RenderCore.cpp:429

Scope (from outer to inner):

file
function     RENDERCORE_API bool IsHDRAllowed

Source code excerpt:

RENDERCORE_API bool IsHDRAllowed()
{
	// HDR can be forced on or off on the commandline. Otherwise we check the cvar r.AllowHDR
	if (FParse::Param(FCommandLine::Get(), TEXT("hdr")))
	{
		return true;
	}
	else if (FParse::Param(FCommandLine::Get(), TEXT("nohdr")))
	{

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/RenderCore.cpp:341

Scope: file

Source code excerpt:


// Note: Enables or disables HDR support for a project. Typically this would be set on a per-project/per-platform basis in defaultengine.ini
TAutoConsoleVariable<int32> CVarAllowHDR(
	TEXT("r.AllowHDR"),
	0,
	TEXT("Creates an HDR compatible swap-chain and enables HDR display output.")
	TEXT("0: Disabled (default)\n")
	TEXT("1: Allow HDR, if supported by the platform and display \n"),
	ECVF_ReadOnly);

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/RenderCore.cpp:439

Scope (from outer to inner):

file
function     bool IsHDRAllowed

Source code excerpt:

	}

	return (CVarAllowHDR.GetValueOnAnyThread() != 0);
}

RENDERCORE_API EDisplayOutputFormat HDRGetDefaultDisplayOutputFormat()
{
	return static_cast<EDisplayOutputFormat>(FMath::Clamp(CVarDisplayOutputDevice.GetValueOnAnyThread(), 0, static_cast<int32>(EDisplayOutputFormat::MAX) - 1));
}