DefaultGraphicsRHI

DefaultGraphicsRHI

#Overview

name: DefaultGraphicsRHI

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 DefaultGraphicsRHI is to select the default Graphics Rendering Hardware Interface (RHI) for Windows platforms in Unreal Engine 5. It is primarily used for configuring the rendering system.

This setting variable is relied upon by the Windows Target Platform module and the RHI subsystem. It’s particularly important for Windows-specific rendering configurations.

The value of this variable is typically set in the project’s configuration files, specifically in the “DefaultEngine.ini” file under the “/Script/WindowsTargetPlatform.WindowsTargetSettings” section.

DefaultGraphicsRHI interacts with other variables such as D3D12TargetedShaderFormats, D3D11TargetedShaderFormats, and VulkanTargetedShaderFormats. It also has a relationship with the deprecated TargetedRHIs variable.

Developers must be aware that changing this variable requires an editor restart to take effect. It’s crucial to ensure that the selected RHI is also included in the Targeted RHIs list.

Best practices when using this variable include:

  1. Carefully considering the target hardware and performance requirements when selecting the default RHI.
  2. Ensuring compatibility between the chosen RHI and other project settings.
  3. Testing the application thoroughly after changing this setting, as it can significantly impact rendering performance and compatibility.
  4. Being mindful of platform-specific limitations and requirements when selecting the RHI.
  5. Keeping the project’s targeted RHIs list up-to-date to align with the chosen default RHI.

#Setting Variables

#References In INI files

Location: <Workspace>/Projects/Lyra/Config/DefaultEngine.ini:295, section: [/Script/WindowsTargetPlatform.WindowsTargetSettings]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Developer/Windows/WindowsTargetPlatform/Classes/WindowsTargetSettings.h:46

Scope (from outer to inner):

file
class        class UWindowsTargetSettings : public UObject

Source code excerpt:

	/** Select which RHI to use. Make sure its also selected as a Targeted RHI. Requires Editor restart. */
	UPROPERTY(EditAnywhere, config, Category="Targeted RHIs", Meta = (DisplayName = "Default RHI", ConfigRestartRequired = true))
	EDefaultGraphicsRHI DefaultGraphicsRHI;

	UPROPERTY(config, meta = (DeprecatedProperty, DeprecationMessage = "Use one of the RHI specific lists."))
	TArray<FString> TargetedRHIs_DEPRECATED;

	UPROPERTY(EditAnywhere, config, Category = "Rendering", Meta = (ConfigRestartRequired = true))
	TArray<FString> D3D12TargetedShaderFormats;

#Loc: <Workspace>/Engine/Source/Developer/Windows/WindowsTargetPlatform/Public/GenericWindowsTargetPlatform.h:307

Scope (from outer to inner):

file
class        class TGenericWindowsTargetPlatform : public TTargetPlatformBase<TProperties>
function     virtual void GetPlatformSpecificProjectAnalytics

Source code excerpt:

		);
	
		TSuper::AppendAnalyticsEventConfigString(AnalyticsParamArray, TEXT("/Script/WindowsTargetPlatform.WindowsTargetSettings"), TEXT("DefaultGraphicsRHI"), GEngineIni);

		TSuper::AppendAnalyticsEventConfigArray(AnalyticsParamArray, TEXT("/Script/WindowsTargetPlatform.WindowsTargetSettings"), TEXT("D3D12TargetedShaderFormats"), GEngineIni);
		TSuper::AppendAnalyticsEventConfigArray(AnalyticsParamArray, TEXT("/Script/WindowsTargetPlatform.WindowsTargetSettings"), TEXT("D3D11TargetedShaderFormats"), GEngineIni);
		TSuper::AppendAnalyticsEventConfigArray(AnalyticsParamArray, TEXT("/Script/WindowsTargetPlatform.WindowsTargetSettings"), TEXT("VulkanTargetedShaderFormats"), GEngineIni);
		TSuper::AppendAnalyticsEventConfigArray(AnalyticsParamArray, TEXT("/Script/WindowsTargetPlatform.WindowsTargetSettings"), TEXT("TargetedRHIs"), GEngineIni, TEXT("TargetedRHIs_Deprecated") );
	}

#Loc: <Workspace>/Engine/Source/Editor/GameProjectGeneration/Private/GameProjectUtils.cpp:162

Scope (from outer to inner):

file
namespace    anonymous
function     void AddRaytracingConfigValues

Source code excerpt:

			ConfigValues.Emplace(TEXT("DefaultEngine.ini"),
				TEXT("/Script/WindowsTargetPlatform.WindowsTargetSettings"),
				TEXT("DefaultGraphicsRHI"),
				TEXT("DefaultGraphicsRHI_DX12"),
				true /* ShouldReplaceExistingValue */);

			ConfigValues.Emplace(TEXT("DefaultEngine.ini"),
				TEXT("/Script/Engine.RendererSettings"),
				TEXT("r.SkinCache.CompileShaders"),
				TEXT("True"),
				true /* ShouldReplaceExistingValue */);

			ConfigValues.Emplace(TEXT("DefaultEngine.ini"),

#Loc: <Workspace>/Engine/Source/Editor/GameProjectGeneration/Private/GameProjectUtils.cpp:2089

Scope (from outer to inner):

file
function     void GameProjectUtils::AddHardwareConfigValues

Source code excerpt:

		ConfigValues.Emplace(TEXT("DefaultEngine.ini"),
			TEXT("/Script/WindowsTargetPlatform.WindowsTargetSettings"),
			TEXT("DefaultGraphicsRHI"),
			TEXT("DefaultGraphicsRHI_DX12"),
			false /* ShouldReplaceExistingValue */);

		// Force clear D3D12TargetedShaderFormats since the BaseEngine list can change at any time.
		ConfigValues.Emplace(TEXT("DefaultEngine.ini"),
			TEXT("/Script/WindowsTargetPlatform.WindowsTargetSettings"),
			TEXT("!D3D12TargetedShaderFormats"),
			TEXT("ClearArray"),
			false /* ShouldReplaceExistingValue */);

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/Windows/WindowsDynamicRHI.cpp:271

Scope (from outer to inner):

file
function     TOptional<EWindowsRHI> ParseDefaultWindowsRHI

Source code excerpt:

	TOptional<EWindowsRHI> DefaultRHI{};

	FString DefaultGraphicsRHI;
	if (GConfig->GetString(TEXT("/Script/WindowsTargetPlatform.WindowsTargetSettings"), TEXT("DefaultGraphicsRHI"), DefaultGraphicsRHI, GEngineIni))
	{
		const FString NAME_DX11(TEXT("DefaultGraphicsRHI_DX11"));
		const FString NAME_DX12(TEXT("DefaultGraphicsRHI_DX12"));
		const FString NAME_VULKAN(TEXT("DefaultGraphicsRHI_Vulkan"));

		if (DefaultGraphicsRHI == NAME_DX11)
		{
			DefaultRHI = EWindowsRHI::D3D11;
		}
		else if (DefaultGraphicsRHI == NAME_DX12)
		{
			DefaultRHI = EWindowsRHI::D3D12;
		}
		else if (DefaultGraphicsRHI == NAME_VULKAN)
		{
			DefaultRHI = EWindowsRHI::Vulkan;
		}
		else if (DefaultGraphicsRHI != TEXT("DefaultGraphicsRHI_Default"))
		{
			UE_LOG(LogRHI, Error, TEXT("Unrecognized setting '%s' for DefaultGraphicsRHI"), *DefaultGraphicsRHI);
		}
	}

	return DefaultRHI;
}

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/Windows/WindowsDynamicRHI.cpp:622

Scope: file

Source code excerpt:

}

// Choose the default from DefaultGraphicsRHI or TargetedRHIs. DefaultGraphicsRHI has precedence.
static EWindowsRHI ChooseDefaultRHI(const FParsedWindowsDynamicRHIConfig& Config)
{
	// Default graphics RHI is the main project setting that governs the choice, so it takes the priority
	if (TOptional<EWindowsRHI> ConfigDefault = Config.DefaultRHI)
	{
		return ConfigDefault.GetValue();

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/Windows/WindowsDynamicRHI.cpp:925

Scope (from outer to inner):

file
function     static IDynamicRHIModule* LoadDynamicRHIModule

Source code excerpt:

	const FParsedWindowsDynamicRHIConfig Config = ParseWindowsDynamicRHIConfig();

	// RHI is chosen by the project settings (first DefaultGraphicsRHI, then TargetedRHIs are consulted, "Default" maps to D3D12). 
	// After this, a separate game-only setting (does not affect editor) bPreferD3D12InGame selects between D3D12 or D3D11 (but will not have any effect if Vulkan or OpenGL are chosen).
	// Commandline switches apply after this and can force an arbitrary RHIs. If RHI isn't supported, the game will refuse to start.

	EWindowsRHI DefaultRHI = ChooseDefaultRHI(Config);
	const TOptional<EWindowsRHI> PreferredRHI = ChoosePreferredRHI(DefaultRHI);
	const TOptional<ERHIFeatureLevel::Type> ForcedFeatureLevel = GetForcedFeatureLevel();