TargetedRHIs

TargetedRHIs

#Overview

name: TargetedRHIs

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

It is referenced in 23 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of TargetedRHIs is to specify which Rendering Hardware Interfaces (RHIs) are targeted for a particular platform in Unreal Engine 5. This setting is used to determine which shader formats and graphics APIs should be supported for a specific target platform.

TargetedRHIs is primarily used by the target platform modules, such as WindowsTargetPlatform, LinuxTargetPlatform, and MacTargetPlatform. These modules rely on this setting to configure the appropriate RHIs for each platform.

The value of this variable is typically set in the platform-specific configuration files, such as WindowsTargetSettings, LinuxTargetSettings, and MacTargetSettings. It can be modified through the project settings in the Unreal Engine editor.

TargetedRHIs interacts with other variables like VulkanTargetedShaderFormats and D3D11TargetedShaderFormats. These variables work together to define the complete set of supported graphics APIs and shader formats for a given platform.

Developers should be aware that:

  1. The order of RHIs in the TargetedRHIs array can affect the priority of RHI selection.
  2. Some RHIs may be platform-specific (e.g., D3D12 for Windows).
  3. Changing TargetedRHIs may require recompiling shaders for the project.

Best practices when using this variable include:

  1. Carefully consider which RHIs are necessary for your target platforms to optimize performance and compatibility.
  2. Regularly review and update the TargetedRHIs list as new RHIs become available or as platform support changes.
  3. Ensure that the necessary development kits and tools are installed for all targeted RHIs.
  4. Test the project thoroughly on all targeted platforms and RHIs to ensure compatibility and performance.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseEngine.ini:3168, section: [/Script/LinuxTargetPlatform.LinuxTargetSettings]

Location: <Workspace>/Engine/Config/BaseEngine.ini:3173, section: [/Script/MacTargetPlatform.MacTargetSettings]

Location: <Workspace>/Projects/Lyra/Config/DefaultEngine.ini:386, section: [/Script/LinuxTargetPlatform.LinuxTargetSettings]

Location: <Workspace>/Projects/Lyra/Config/DefaultEngine.ini:387, section: [/Script/LinuxTargetPlatform.LinuxTargetSettings]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Developer/LauncherServices/Private/Launcher/LauncherWorker.cpp:326

Scope (from outer to inner):

file
function     static void AddDeviceToLaunchCommand

Source code excerpt:


			TArray<FString> OldConfigShaderFormats;
			WindowsEngineSettings.GetArray(TEXT("/Script/WindowsTargetPlatform.WindowsTargetSettings"), TEXT("TargetedRHIs"), OldConfigShaderFormats);

			for (const FString& OldConfigShaderFormat : OldConfigShaderFormats)
			{
				TargetedShaderFormats.AddUnique(OldConfigShaderFormat);
			}
		}

#Loc: <Workspace>/Engine/Source/Developer/LauncherServices/Private/Launcher/LauncherWorker.cpp:339

Scope (from outer to inner):

file
function     static void AddDeviceToLaunchCommand

Source code excerpt:


			bCheckTargetedRHIs = true;
			LinuxEngineSettings.GetArray(TEXT("/Script/LinuxTargetPlatform.LinuxTargetSettings"), TEXT("TargetedRHIs"), TargetedShaderFormats);
		}
		else if (Platform.StartsWith(TEXT("Android")))
		{
			FConfigFile AndroidEngineSettings;
			FConfigCacheIni::LoadLocalIniFile(AndroidEngineSettings, TEXT("Engine"), true, TEXT("Android"));

#Loc: <Workspace>/Engine/Source/Developer/Linux/LinuxTargetPlatform/Classes/LinuxTargetSettings.h:48

Scope (from outer to inner):

file
class        class ULinuxTargetSettings : public UObject

Source code excerpt:

	 */
	UPROPERTY(EditAnywhere, config, Category=Rendering)
	TArray<FString> TargetedRHIs;
};

#Loc: <Workspace>/Engine/Source/Developer/Linux/LinuxTargetPlatform/Private/LinuxTargetPlatformModule.cpp:46

Scope (from outer to inner):

file
class        class FLinuxTargetPlatformModule : public ITargetPlatformModule
function     virtual void StartupModule

Source code excerpt:


		// We need to manually load the config properties here, as this module is loaded before the UObject system is setup to do this
		GConfig->GetArray(TEXT("/Script/LinuxTargetPlatform.LinuxTargetSettings"), TEXT("TargetedRHIs"), TargetSettings->TargetedRHIs, GEngineIni);
		TargetSettings->AddToRoot();

		ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings");

		if (SettingsModule != nullptr)
		{

#Loc: <Workspace>/Engine/Source/Developer/Linux/LinuxTargetPlatform/Public/LinuxTargetPlatform.h:281

Scope (from outer to inner):

file
class        class TLinuxTargetPlatform : public TTargetPlatformBase<TProperties>
function     virtual void GetAllTargetedShaderFormats

Source code excerpt:

		// Get the Target RHIs for this platform, we do not always want all those that are supported. (reload in case user changed in the editor)
		TArray<FString>TargetedShaderFormats;
		GConfig->GetArray(TEXT("/Script/LinuxTargetPlatform.LinuxTargetSettings"), TEXT("TargetedRHIs"), TargetedShaderFormats, GEngineIni);

		// Gather the list of Target RHIs and filter out any that may be invalid.
		TArray<FName> PossibleShaderFormats;
		GetAllPossibleShaderFormats(PossibleShaderFormats);

		for (int32 ShaderFormatIdx = TargetedShaderFormats.Num() - 1; ShaderFormatIdx >= 0; ShaderFormatIdx--)

#Loc: <Workspace>/Engine/Source/Developer/Linux/LinuxTargetPlatform/Public/LinuxTargetPlatform.h:306

Scope (from outer to inner):

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

Source code excerpt:

		TSuper::GetPlatformSpecificProjectAnalytics(AnalyticsParamArray);

		TSuper::AppendAnalyticsEventConfigArray(AnalyticsParamArray, TEXT("/Script/LinuxTargetPlatform.LinuxTargetSettings"), TEXT("TargetedRHIs"), GEngineIni);
	}

#if WITH_ENGINE
	virtual void GetReflectionCaptureFormats(TArray<FName>& OutFormats) const override
	{
		if (bRequiresEncodedHDRReflectionCaptures)

#Loc: <Workspace>/Engine/Source/Developer/Mac/MacTargetPlatform/Classes/MacTargetSettings.h:59

Scope (from outer to inner):

file
class        class UMacTargetSettings : public UObject

Source code excerpt:

	 */
	UPROPERTY(EditAnywhere, config, Category=Rendering)
	TArray<FString> TargetedRHIs;
	
	/**
	 * The set of architecture(s) this project supports for Editor builds
	 * This defines which CPU architectures to target: x86_64 (Intel), arm64 (Apple Silicon) or Universal (Intel & Apple Silicon).
	 * It is recommended to use Universal unless you have editor plugins or other libraries that do not support Apple Silicon
	 */

#Loc: <Workspace>/Engine/Source/Developer/Mac/MacTargetPlatform/Private/MacTargetPlatformModule.cpp:50

Scope (from outer to inner):

file
class        class FMacTargetPlatformModule : public ITargetPlatformModule
function     virtual void StartupModule

Source code excerpt:

		
		// We need to manually load the config properties here, as this module is loaded before the UObject system is setup to do this
        GConfig->GetArray(TEXT("/Script/MacTargetPlatform.MacTargetSettings"), TEXT("TargetedRHIs"), TargetSettings->TargetedRHIs, GEngineIni);
       
        if (!GConfig->GetInt(TEXT("/Script/MacTargetPlatform.MacTargetSettings"), TEXT("MetalLanguageVersion"), TargetSettings->MetalLanguageVersion, GEngineIni))
        {
            TargetSettings->MetalLanguageVersion = 0;
        }
        

#Loc: <Workspace>/Engine/Source/Developer/Mac/MacTargetPlatform/Public/GenericMacTargetPlatform.h:133

Scope (from outer to inner):

file
class        class TGenericMacTargetPlatform : public TTargetPlatformBase<FMacPlatformProperties<HAS_EDITOR_DATA, IS_DEDICATED_SERVER, IS_CLIENT_ONLY> >
function     virtual void GetAllTargetedShaderFormats

Source code excerpt:

		// Get the Target RHIs for this platform, we do not always want all those that are supported.
		TArray<FString>TargetedShaderFormats;
		GConfig->GetArray(TEXT("/Script/MacTargetPlatform.MacTargetSettings"), TEXT("TargetedRHIs"), TargetedShaderFormats, GEngineIni);

		// Gather the list of Target RHIs and filter out any that may be invalid.
		TArray<FName> PossibleShaderFormats;
		GetAllPossibleShaderFormats(PossibleShaderFormats);

		for (int32 ShaderFormatIdx = TargetedShaderFormats.Num() - 1; ShaderFormatIdx >= 0; ShaderFormatIdx--)

#Loc: <Workspace>/Engine/Source/Developer/Mac/MacTargetPlatform/Public/GenericMacTargetPlatform.h:158

Scope (from outer to inner):

file
class        class TGenericMacTargetPlatform : public TTargetPlatformBase<FMacPlatformProperties<HAS_EDITOR_DATA, IS_DEDICATED_SERVER, IS_CLIENT_ONLY> >
function     virtual void GetPlatformSpecificProjectAnalytics

Source code excerpt:

		TSuper::GetPlatformSpecificProjectAnalytics(AnalyticsParamArray);

		TSuper::AppendAnalyticsEventConfigArray(AnalyticsParamArray, TEXT("/Script/MacTargetPlatform.MacTargetSettings"), TEXT("TargetedRHIs"), GEngineIni);
	}

#if WITH_ENGINE
	virtual const class FStaticMeshLODSettings& GetStaticMeshLODSettings( ) const override
	{
		return StaticMeshLODSettings;

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

Scope (from outer to inner):

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

Source code excerpt:

		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") );
	}

#if WITH_ENGINE
	virtual void GetReflectionCaptureFormats(TArray<FName>& OutFormats) const override
	{
		if (bRequiresEncodedHDRReflectionCaptures)

#Loc: <Workspace>/Engine/Source/Editor/DetailCustomizations/Private/LinuxTargetSettingsDetails.cpp:72

Scope (from outer to inner):

file
function     static FText GetFriendlyNameFromLinuxShaderFormat

Source code excerpt:

	else if (InShaderFormat == TEXT("GLSL_430"))
	{
		// Explicitly remove these formats as they are obsolete/not quite supported; users can still target them by adding them as +TargetedRHIs in the TargetPlatform ini.
		FriendlyRHIName = FText::GetEmpty();
	}
	else
	{
		FriendlyRHIName = LOCTEXT("UnknownRHI", "UnknownRHI");
	}

#Loc: <Workspace>/Engine/Source/Editor/DetailCustomizations/Private/MacTargetSettingsDetails.cpp:175

Scope (from outer to inner):

file
function     void FMacTargetSettingsDetails::CustomizeDetails

Source code excerpt:

    
	// Setup the supported/targeted RHI property view
	TargetShaderFormatsDetails = MakeShareable(new FShaderFormatsPropertyDetails(&DetailBuilder, TEXT("TargetedRHIs"), TEXT("Targeted RHIs")));
	TargetShaderFormatsDetails->SetOnUpdateShaderWarning(OnUpdateShaderStandardWarning);
	TargetShaderFormatsDetails->CreateTargetShaderFormatsPropertyView(TargetPlatform, &GetFriendlyNameFromRHINameMac);
	
	// Setup the shader version property view
    // Handle max. shader version a little specially.
    {

#Loc: <Workspace>/Engine/Source/Editor/DetailCustomizations/Private/WindowsTargetSettingsDetails.cpp:76

Scope (from outer to inner):

file
function     static FText GetFriendlyNameFromWindowsShaderPlatform

Source code excerpt:

	case SP_OPENGL_PCES3_1:
	case SP_VULKAN_PCES3_1:
		// Explicitly remove these formats as they are obsolete/not quite supported; users can still target them by adding them as +TargetedRHIs in the TargetPlatform ini.
		FriendlyRHIName = FText::GetEmpty();
		break;

	default:
		UE_LOG(LogEngine, Warning, TEXT("Unknown Windows target RHI %s"), *InShaderPlatformName.ToString());
		FriendlyRHIName = LOCTEXT("UnknownRHI", "UnknownRHI");

#Loc: <Workspace>/Engine/Source/Runtime/Apple/MetalRHI/Private/MetalRHI.cpp:48

Scope (from outer to inner):

file
function     static void ValidateTargetedRHIFeatureLevelExists

Source code excerpt:

#if PLATFORM_MAC
	TArray<FString> TargetedShaderFormats;
	GConfig->GetArray(TEXT("/Script/MacTargetPlatform.MacTargetSettings"), TEXT("TargetedRHIs"), TargetedShaderFormats, GEngineIni);
	
	for (FString Name : TargetedShaderFormats)
	{
		FName ShaderFormatName(*Name);
		if (ShaderFormatToLegacyShaderPlatform(ShaderFormatName) == Platform)
		{

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/RendererSettings.cpp:422

Scope (from outer to inner):

file
function     void URendererSettings::CheckForMissingShaderModels

Source code excerpt:

		// Gather all Windows shader format settings
		{
			GConfig->GetArray(TEXT("/Script/WindowsTargetPlatform.WindowsTargetSettings"), TEXT("TargetedRHIs"), WindowsTargetedRHIs, GEngineIni);

			// If using Vulkan in Windows, warn about Vulkan settings
			if (IsVulkanPlatform(GMaxRHIShaderPlatform))
			{
				GConfig->GetArray(TEXT("/Script/WindowsTargetPlatform.WindowsTargetSettings"), TEXT("VulkanTargetedShaderFormats"), WindowsVulkanTargetedShaderFormats, GEngineIni);
				CopySM6Format(TEXT("SF_VULKAN_SM6"), WindowsTargetedRHIs, WindowsVulkanTargetedShaderFormats);

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/RendererSettings.cpp:440

Scope (from outer to inner):

file
function     void URendererSettings::CheckForMissingShaderModels

Source code excerpt:

		// Gather all Linux shader format settings
		GConfig->GetArray(TEXT("/Script/LinuxTargetPlatform.LinuxTargetSettings"), TEXT("VulkanTargetedShaderFormats"), LinuxVulkanTargetedShaderFormats, GEngineIni);
		GConfig->GetArray(TEXT("/Script/LinuxTargetPlatform.LinuxTargetSettings"), TEXT("TargetedRHIs"), LinuxTargetedRHIs, GEngineIni);
		CopySM6Format(TEXT("SF_VULKAN_SM6"), LinuxTargetedRHIs, LinuxVulkanTargetedShaderFormats);
#elif PLATFORM_MAC
		// TODO: Gather all Mac shader format settings
#endif

		const bool bProjectUsesD3D = (D3D11TargetedShaderFormats.Num() + D3D12TargetedShaderFormats.Num()) > 0;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/StaticMesh.cpp:6735

Scope (from outer to inner):

file
function     void UStaticMesh::CheckForMissingShaderModels

Source code excerpt:

		// Gather all Windows shader format settings
		{
			GConfig->GetArray(TEXT("/Script/WindowsTargetPlatform.WindowsTargetSettings"), TEXT("TargetedRHIs"), WindowsTargetedRHIs, GEngineIni);

			// If using Vulkan in Windows, warn about Vulkan settings
			if (IsVulkanPlatform(GMaxRHIShaderPlatform))
			{
				GConfig->GetArray(TEXT("/Script/WindowsTargetPlatform.WindowsTargetSettings"), TEXT("VulkanTargetedShaderFormats"), WindowsVulkanTargetedShaderFormats, GEngineIni);
				CopySM6Format(TEXT("SF_VULKAN_SM6"), WindowsTargetedRHIs, WindowsVulkanTargetedShaderFormats);

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/StaticMesh.cpp:6753

Scope (from outer to inner):

file
function     void UStaticMesh::CheckForMissingShaderModels

Source code excerpt:

		// Gather all Linux shader format settings
		GConfig->GetArray(TEXT("/Script/LinuxTargetPlatform.LinuxTargetSettings"), TEXT("VulkanTargetedShaderFormats"), LinuxVulkanTargetedShaderFormats, GEngineIni);
		GConfig->GetArray(TEXT("/Script/LinuxTargetPlatform.LinuxTargetSettings"), TEXT("TargetedRHIs"), LinuxTargetedRHIs, GEngineIni);
		CopySM6Format(TEXT("SF_VULKAN_SM6"), LinuxTargetedRHIs, LinuxVulkanTargetedShaderFormats);
#elif PLATFORM_MAC
		// TODO: Gather all Mac shader format settings
#endif

		const bool bProjectUsesD3D = (D3D11TargetedShaderFormats.Num() + D3D12TargetedShaderFormats.Num()) > 0;

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/Apple/Platform/Mac/MacPlatformDynamicRHI.h:20

Scope (from outer to inner):

file
namespace    UE
namespace    FMacPlatformDynamicRHI
function     void AddTargetedShaderFormats

Source code excerpt:

void AddTargetedShaderFormats(TArray<FString>& TargetedShaderFormats)
{
	GConfig->GetArray(TEXT("/Script/MacTargetPlatform.MacTargetSettings"), TEXT("TargetedRHIs"), TargetedShaderFormats, GEngineIni);
}

} // namespace FMacPlatformDynamicRHI
} // namespace UE

namespace FPlatformDynamicRHI = UE::FMacPlatformDynamicRHI;

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/Linux/LinuxDynamicRHI.cpp:78

Scope (from outer to inner):

file
function     FDynamicRHI* PlatformCreateDynamicRHI

Source code excerpt:

	{
		TArray<FString> TargetedShaderFormats;
		GConfig->GetArray(TEXT("/Script/LinuxTargetPlatform.LinuxTargetSettings"), TEXT("TargetedRHIs"), TargetedShaderFormats, GEngineIni);

		// First come first serve
		for (int32 SfIdx = 0; SfIdx < TargetedShaderFormats.Num(); ++SfIdx)
		{
			// If we are not forcing opengl and we havent failed to create a VulkanRHI try to again with a different TargetedRHI
			if (!bForceOpenGL && !bVulkanFailed && TargetedShaderFormats[SfIdx].StartsWith(TEXT("SF_VULKAN_")))

#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();