r.Mobile.UseHWsRGBEncoding

r.Mobile.UseHWsRGBEncoding

#Overview

name: r.Mobile.UseHWsRGBEncoding

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

It is referenced in 7 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.Mobile.UseHWsRGBEncoding is to control how sRGB encoding is handled in mobile rendering for Unreal Engine 5. It is specifically related to the rendering system, particularly for mobile platforms.

This setting variable is primarily used in the Renderer module and affects various aspects of mobile rendering, including the base pass rendering, occlusion queries, and shader compilation. It also interacts with the Android runtime settings and OpenGL driver for Android.

The value of this variable is set through a console variable (CVAR) system. It can be set to 0 or 1, where 0 means sRGB encoding is written in the shader, and 1 means the GPU hardware is used to convert linear to sRGB automatically.

This variable interacts with other settings and variables, such as:

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

  1. It affects shader compilation and runtime behavior.
  2. It’s platform-dependent, with specific implications for Android devices.
  3. It interacts with HDR settings and can affect color output.

Best practices when using this variable include:

  1. Ensure the target hardware supports hardware sRGB encoding before enabling it.
  2. Test thoroughly on target devices to verify correct color output.
  3. Consider the performance implications of hardware vs. shader-based sRGB encoding.
  4. Coordinate its use with other related settings, especially those affecting color space and HDR.
  5. Be aware of its impact on shader permutations and compilation times.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/MobileBasePassRendering.cpp:60

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarMobileUseHWsRGBEncoding(
	TEXT("r.Mobile.UseHWsRGBEncoding"),
	0,
	TEXT("0: Write sRGB encoding in the shader\n")
	TEXT("1: Use GPU HW to convert linear to sRGB automatically (device must support sRGB write control)\n"),
	ECVF_RenderThreadSafe);

EMobileTranslucentColorTransmittanceMode MobileDefaultTranslucentColorTransmittanceMode(EShaderPlatform Platform)

#Loc: <Workspace>/Engine/Source/Runtime/Android/AndroidRuntimeSettings/Private/AndroidRuntimeSettings.cpp:67

Scope (from outer to inner):

file
function     void UAndroidRuntimeSettings::HandlesRGBHWSupport

Source code excerpt:

	const bool SupportssRGB = bPackageForMetaQuest;
	URendererSettings* const Settings = GetMutableDefault<URendererSettings>();
	static auto* MobileUseHWsRGBEncodingCVAR = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Mobile.UseHWsRGBEncoding"));

	if (SupportssRGB != Settings->bMobileUseHWsRGBEncoding)
	{
		Settings->bMobileUseHWsRGBEncoding = SupportssRGB;
		Settings->UpdateSinglePropertyInConfigFile(Settings->GetClass()->FindPropertyByName(GET_MEMBER_NAME_CHECKED(URendererSettings, bMobileUseHWsRGBEncoding)), GetDefaultConfigFilename());
	}

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SceneUtils.cpp:63

Scope (from outer to inner):

file
function     bool IsMobileColorsRGB

Source code excerpt:

ENGINE_API bool IsMobileColorsRGB()
{
	static auto* MobileUseHWsRGBEncodingCVAR = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.UseHWsRGBEncoding"));
	const bool bMobileUseHWsRGBEncoding = (MobileUseHWsRGBEncodingCVAR && MobileUseHWsRGBEncodingCVAR->GetValueOnAnyThread() == 1);

	return !IsMobileHDR() && bMobileUseHWsRGBEncoding;
}

ENGINE_API EAntiAliasingMethod GetDefaultAntiAliasingMethod(const FStaticFeatureLevel InFeatureLevel)

#Loc: <Workspace>/Engine/Source/Runtime/OpenGLDrv/Private/Android/AndroidOpenGL.cpp:776

Scope (from outer to inner):

file
function     bool FAndroidOpenGL::SupportsFramebufferSRGBEnable

Source code excerpt:

bool FAndroidOpenGL::SupportsFramebufferSRGBEnable()
{	
	static auto* MobileUseHWsRGBEncodingCVAR = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.UseHWsRGBEncoding"));
	const bool bMobileUseHWsRGBEncoding = (MobileUseHWsRGBEncodingCVAR && MobileUseHWsRGBEncodingCVAR->GetValueOnAnyThread() == 1);
	return bMobileUseHWsRGBEncoding;
}

void FAndroidOpenGL::BeginQuery(GLenum QueryType, GLuint Query)
{

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

Scope (from outer to inner):

file
function     void ShaderMapAppendKeyString

Source code excerpt:

		
		{
			static IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Mobile.UseHWsRGBEncoding"));
			KeyString += (CVar && CVar->GetInt() != 0) ? TEXT("_HWsRGB") : TEXT("");
		}
		
		{
			// make it per shader platform ?
			static IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Mobile.SupportGPUScene"));

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/MobileBasePassRendering.cpp:192

Scope (from outer to inner):

file
function     void MobileBasePassModifyCompilationEnvironment

Source code excerpt:

void MobileBasePassModifyCompilationEnvironment(const FMaterialShaderPermutationParameters& Parameters, FShaderCompilerEnvironment& OutEnvironment, EOutputFormat OutputFormat)
{
	static auto* MobileUseHWsRGBEncodingCVAR = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.UseHWsRGBEncoding"));
	const bool bMobileUseHWsRGBEncoding = (MobileUseHWsRGBEncodingCVAR && MobileUseHWsRGBEncodingCVAR->GetValueOnAnyThread() == 1);
	OutEnvironment.SetDefine( TEXT("OUTPUT_GAMMA_SPACE"), OutputFormat == LDR_GAMMA_32 && !bMobileUseHWsRGBEncoding);
	OutEnvironment.SetDefine( TEXT("OUTPUT_MOBILE_HDR"), OutputFormat == HDR_LINEAR_64 ? 1u : 0u);
	
	const bool bTranslucentMaterial = 
		IsTranslucentBlendMode(Parameters.MaterialParameters) ||

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneOcclusion.h:48

Scope (from outer to inner):

file
class        class FOcclusionQueryVS : public FGlobalShader
function     static void ModifyCompilationEnvironment

Source code excerpt:

	static void ModifyCompilationEnvironment(const FGlobalShaderPermutationParameters& Parameters, FShaderCompilerEnvironment& OutEnvironment)
	{
		static auto* MobileUseHWsRGBEncodingCVAR = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.UseHWsRGBEncoding"));
		const bool bMobileUseHWsRGBEncoding = (MobileUseHWsRGBEncodingCVAR && MobileUseHWsRGBEncodingCVAR->GetValueOnAnyThread() == 1);

		FGlobalShader::ModifyCompilationEnvironment(Parameters, OutEnvironment);
		OutEnvironment.SetDefine(TEXT("OUTPUT_GAMMA_SPACE"), IsMobileHDR() == false && !bMobileUseHWsRGBEncoding);
		OutEnvironment.SetDefine(TEXT("OUTPUT_MOBILE_HDR"), IsMobileHDR() == true);
	}