2019-12-26 15:32:37 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2018-09-25 10:11:35 -04:00
# include "Common/TargetPlatformBase.h"
2024-02-15 16:36:13 -05:00
# include "Common/TargetPlatformControlsBase.h"
2018-09-25 10:11:35 -04:00
# include "HAL/IConsoleManager.h"
2019-01-29 08:56:46 -05:00
# include "DeviceBrowserDefaultPlatformWidgetCreator.h"
2019-09-10 16:11:58 -04:00
# include "Interfaces/IProjectBuildMutatorFeature.h"
# include "Features/IModularFeatures.h"
# include "Interfaces/IProjectManager.h"
# include "Interfaces/IPluginManager.h"
# include "ProjectDescriptor.h"
# include "Misc/App.h"
# include "Misc/ConfigCacheIni.h"
2022-07-18 17:47:55 -04:00
# include "Sound/AudioFormatSettings.h"
2022-09-08 19:33:14 -04:00
# include "AnalyticsEventAttribute.h"
2019-09-10 16:11:58 -04:00
# define LOCTEXT_NAMESPACE "TargetPlatform"
2018-09-25 10:11:35 -04:00
2024-03-11 07:24:38 -04:00
PRAGMA_DISABLE_DEPRECATION_WARNINGS
2018-09-25 10:11:35 -04:00
bool FTargetPlatformBase : : UsesForwardShading ( ) const
{
static IConsoleVariable * CVarForwardShading = IConsoleManager : : Get ( ) . FindConsoleVariable ( TEXT ( " r.ForwardShading " ) ) ;
return CVarForwardShading ? ( CVarForwardShading - > GetInt ( ) ! = 0 ) : false ;
}
bool FTargetPlatformBase : : UsesDBuffer ( ) const
{
static IConsoleVariable * CVar = IConsoleManager : : Get ( ) . FindConsoleVariable ( TEXT ( " r.DBuffer " ) ) ;
return CVar ? ( CVar - > GetInt ( ) ! = 0 ) : false ;
}
2019-04-12 13:00:25 -04:00
bool FTargetPlatformBase : : UsesBasePassVelocity ( ) const
{
2022-02-01 09:53:17 -05:00
static IConsoleVariable * CVar = IConsoleManager : : Get ( ) . FindConsoleVariable ( TEXT ( " r.VelocityOutputPass " ) ) ;
return CVar ? ( CVar - > GetInt ( ) = = 1 ) : false ;
2019-04-12 13:00:25 -04:00
}
2020-09-24 00:43:27 -04:00
bool FTargetPlatformBase : : VelocityEncodeDepth ( ) const
2020-02-12 13:27:19 -05:00
{
2020-09-24 00:43:27 -04:00
return true ;
2020-02-12 13:27:19 -05:00
}
2019-04-12 13:00:25 -04:00
bool FTargetPlatformBase : : UsesSelectiveBasePassOutputs ( ) const
{
static IConsoleVariable * CVar = IConsoleManager : : Get ( ) . FindConsoleVariable ( TEXT ( " r.SelectiveBasePassOutputs " ) ) ;
2019-04-14 06:37:10 -04:00
return CVar ? ( CVar - > GetInt ( ) ! = 0 ) : false ;
2019-04-12 13:00:25 -04:00
}
2019-04-24 17:06:13 -04:00
bool FTargetPlatformBase : : UsesDistanceFields ( ) const
{
2021-07-12 11:23:28 -04:00
static IConsoleVariable * CVar = IConsoleManager : : Get ( ) . FindConsoleVariable ( TEXT ( " r.DistanceFields " ) ) ;
return CVar ? ( CVar - > GetInt ( ) ! = 0 ) : false ;
2019-04-24 17:06:13 -04:00
}
2020-02-12 13:27:19 -05:00
bool FTargetPlatformBase : : UsesRayTracing ( ) const
{
static IConsoleVariable * CVar = IConsoleManager : : Get ( ) . FindConsoleVariable ( TEXT ( " r.RayTracing " ) ) ;
return CVar ? ( CVar - > GetInt ( ) ! = 0 ) : false ;
}
2024-05-06 18:21:02 -04:00
ERayTracingRuntimeMode FTargetPlatformBase : : GetRayTracingMode ( ) const
{
return ERayTracingRuntimeMode : : Disabled ;
}
2024-04-10 09:49:42 -04:00
uint32 FTargetPlatformBase : : GetSupportedHardwareMask ( ) const
{
return 0 ;
}
2022-01-26 11:43:03 -05:00
EOfflineBVHMode FTargetPlatformBase : : GetStaticMeshOfflineBVHMode ( ) const
{
return EOfflineBVHMode : : Disabled ;
}
2023-07-24 20:01:35 -04:00
bool FTargetPlatformBase : : GetStaticMeshOfflineBVHCompression ( ) const
{
return false ;
}
2020-09-01 14:07:48 -04:00
bool FTargetPlatformBase : : ForcesSimpleSkyDiffuse ( ) const
{
return false ;
}
2019-05-15 10:21:41 -04:00
float FTargetPlatformBase : : GetDownSampleMeshDistanceFieldDivider ( ) const
{
return 1.0f ;
}
2020-08-11 01:36:57 -04:00
int32 FTargetPlatformBase : : GetHeightFogModeForOpaque ( ) const
{
// Don't override the project setting by default
// Platforms wish to support override need to implement the logic in their own target platform classes
return 0 ;
}
2021-03-05 19:27:14 -04:00
bool FTargetPlatformBase : : UsesMobileAmbientOcclusion ( ) const
{
static IConsoleVariable * CVar = IConsoleManager : : Get ( ) . FindConsoleVariable ( TEXT ( " r.Mobile.AmbientOcclusion " ) ) ;
return CVar ? ( CVar - > GetInt ( ) ! = 0 ) : false ;
}
2023-10-09 16:48:41 -04:00
bool FTargetPlatformBase : : UsesMobileDBuffer ( ) const
{
static IConsoleVariable * CVar = IConsoleManager : : Get ( ) . FindConsoleVariable ( TEXT ( " r.Mobile.DBuffer " ) ) ;
return CVar ? ( CVar - > GetInt ( ) ! = 0 ) : false ;
}
2022-05-24 11:21:35 -04:00
int32 GASTCHDRProfile = 0 ;
static FAutoConsoleVariableRef CVarAllowASTCHDRProfile (
TEXT ( " cook.AllowASTCHDRProfile " ) ,
GASTCHDRProfile ,
TEXT ( " whether to allow ASTC HDR profile, the hdr format is only supported on some devices, e.g. Apple A13, Mali-G72, Adreno (TM) 660 " ) ,
ECVF_Default | ECVF_ReadOnly
) ;
bool FTargetPlatformBase : : UsesASTCHDR ( ) const
{
2023-01-03 08:20:10 -05:00
static IConsoleVariable * CVar = IConsoleManager : : Get ( ) . FindConsoleVariable ( TEXT ( " cook.ASTCTextureCompressor " ) ) ;
const bool bUsesARMCompressor = ( CVar ? ( CVar - > GetInt ( ) ! = 0 ) : false ) ;
return ( bUsesARMCompressor & & GASTCHDRProfile ! = 0 ) ;
2022-05-24 11:21:35 -04:00
}
2022-06-30 15:44:00 -04:00
void FTargetPlatformBase : : GetRayTracingShaderFormats ( TArray < FName > & OutFormats ) const
{
if ( UsesRayTracing ( ) )
{
GetAllTargetedShaderFormats ( OutFormats ) ;
}
}
2022-09-08 19:33:14 -04:00
void FTargetPlatformBase : : GetPlatformSpecificProjectAnalytics ( TArray < FAnalyticsEventAttribute > & AnalyticsParamArray ) const
{
AppendAnalyticsEventAttributeArray ( AnalyticsParamArray ,
TEXT ( " UsesDistanceFields " ) , UsesDistanceFields ( ) ,
TEXT ( " UsesForwardShading " ) , UsesForwardShading ( )
) ;
}
void FTargetPlatformBase : : AppendAnalyticsEventConfigBool ( TArray < FAnalyticsEventAttribute > & AnalyticsParamArray , const TCHAR * ConfigSection , const TCHAR * ConfigKey , const FString & IniFileName , const TCHAR * AnalyticsKeyNameOverride )
{
bool ConfigValue ;
if ( GConfig - > GetBool ( ConfigSection , ConfigKey , ConfigValue , IniFileName ) )
{
AnalyticsParamArray . Add ( FAnalyticsEventAttribute ( AnalyticsKeyNameOverride ? AnalyticsKeyNameOverride : ConfigKey , ConfigValue ) ) ;
}
}
void FTargetPlatformBase : : AppendAnalyticsEventConfigInt ( TArray < FAnalyticsEventAttribute > & AnalyticsParamArray , const TCHAR * ConfigSection , const TCHAR * ConfigKey , const FString & IniFileName , const TCHAR * AnalyticsKeyNameOverride )
{
int32 ConfigValue ;
if ( GConfig - > GetInt ( ConfigSection , ConfigKey , ConfigValue , IniFileName ) )
{
AnalyticsParamArray . Add ( FAnalyticsEventAttribute ( AnalyticsKeyNameOverride ? AnalyticsKeyNameOverride : ConfigKey , ConfigValue ) ) ;
}
}
void FTargetPlatformBase : : AppendAnalyticsEventConfigFloat ( TArray < FAnalyticsEventAttribute > & AnalyticsParamArray , const TCHAR * ConfigSection , const TCHAR * ConfigKey , const FString & IniFileName , const TCHAR * AnalyticsKeyNameOverride )
{
float ConfigValue ;
if ( GConfig - > GetFloat ( ConfigSection , ConfigKey , ConfigValue , IniFileName ) )
{
AnalyticsParamArray . Add ( FAnalyticsEventAttribute ( AnalyticsKeyNameOverride ? AnalyticsKeyNameOverride : ConfigKey , ConfigValue ) ) ;
}
}
void FTargetPlatformBase : : AppendAnalyticsEventConfigString ( TArray < FAnalyticsEventAttribute > & AnalyticsParamArray , const TCHAR * ConfigSection , const TCHAR * ConfigKey , const FString & IniFileName , const TCHAR * AnalyticsKeyNameOverride )
{
FString ConfigValue ;
if ( GConfig - > GetString ( ConfigSection , ConfigKey , ConfigValue , IniFileName ) )
{
AnalyticsParamArray . Add ( FAnalyticsEventAttribute ( AnalyticsKeyNameOverride ? AnalyticsKeyNameOverride : ConfigKey , ConfigValue ) ) ;
}
}
void FTargetPlatformBase : : AppendAnalyticsEventConfigArray ( TArray < FAnalyticsEventAttribute > & AnalyticsParamArray , const TCHAR * ConfigSection , const TCHAR * ConfigKey , const FString & IniFileName , const TCHAR * AnalyticsKeyNameOverride )
{
TArray < FString > ConfigValue ;
if ( GConfig - > GetArray ( ConfigSection , ConfigKey , ConfigValue , IniFileName ) )
{
AnalyticsParamArray . Add ( FAnalyticsEventAttribute ( AnalyticsKeyNameOverride ? AnalyticsKeyNameOverride : ConfigKey , ConfigValue ) ) ;
}
}
2019-09-10 16:11:58 -04:00
static bool IsPluginEnabledForTarget ( const IPlugin & Plugin , const FProjectDescriptor * Project , const FString & Platform , EBuildConfiguration Configuration , EBuildTargetType TargetType )
{
if ( ! Plugin . GetDescriptor ( ) . SupportsTargetPlatform ( Platform ) )
{
return false ;
}
2021-11-18 14:37:34 -05:00
// TODO: Support transitive calculation of per-platform disabling for plugins.
// Plugins can reference other plugins, and it would be nice to be able to automatically disable for platform X
// plugins that are only referenced through another plugin that is disabled for platform X.
// For the time-being, to disable a transitively referenced plugin per-platform, the project has to
// directly include the plugin.
IPluginManager & PluginManager = IPluginManager : : Get ( ) ;
2019-09-10 16:11:58 -04:00
if ( Project ! = nullptr )
{
2021-11-18 14:37:34 -05:00
const FString & PluginName = Plugin . GetName ( ) ;
const FPluginReferenceDescriptor * PluginReference = Project - > Plugins . FindByPredicate (
[ & PluginName ] ( const FPluginReferenceDescriptor & ExistingReference )
{
return ExistingReference . Name = = PluginName ;
} ) ;
if ( PluginReference )
2019-09-10 16:11:58 -04:00
{
2021-11-18 14:37:34 -05:00
// TODO: Remove this workaround for indirect plugin references. A project can mark a plugin as
// "Enabled": false, but that merely prevents a direct reference, and the plugin might be referenced and
// enabled by other plugins. PluginReference->IsEnabledForPlatform, IsEnabledForTargetConfiguration, and
// IsEnabledForTarget will all return false in that case, even though the plugin is actually enabled.
// Other systems using IPluginManager::Get().GetEnabledPlugins will disagree with the disabled result.
// To workaround it, when we detect the case of a disabled plugin reference for a plugin that is
// indirectly enabled, we treat it as having all platforms enabled.
// To fix it properly, we will need to have plugins track for which platforms they are enabled,
// and query the pluginmanager here instead of querying the PluginReference directly.
if ( PluginReference - > bEnabled | | PluginReference - > bEnabled = = Plugin . IsEnabled ( ) )
2019-09-10 16:11:58 -04:00
{
2021-11-18 14:37:34 -05:00
bool bEnabledForProject = PluginReference - > IsEnabledForPlatform ( Platform ) & &
( Configuration = = EBuildConfiguration : : Unknown | | PluginReference - > IsEnabledForTargetConfiguration ( Configuration ) ) & &
PluginReference - > IsEnabledForTarget ( TargetType ) ;
if ( ! bEnabledForProject )
2019-11-19 16:53:37 -05:00
{
2021-11-18 14:37:34 -05:00
return false ;
2019-11-19 16:53:37 -05:00
}
}
}
}
return true ;
}
2019-09-10 16:11:58 -04:00
bool FTargetPlatformBase : : RequiresTempTarget ( bool bProjectHasCode , EBuildConfiguration Configuration , bool bRequiresAssetNativization , FText & OutReason ) const
{
// check to see if we already have a Target.cs file
if ( bProjectHasCode )
{
return false ;
}
// check if asset nativization is enabled
if ( bRequiresAssetNativization )
{
OutReason = LOCTEXT ( " TempTarget_Nativization " , " asset nativization is enabled " ) ;
return true ;
}
// check to see if any projectmutator modular features are available
for ( IProjectBuildMutatorFeature * Feature : IModularFeatures : : Get ( ) . GetModularFeatureImplementations < IProjectBuildMutatorFeature > ( PROJECT_BUILD_MUTATOR_FEATURE ) )
{
2020-07-29 16:19:10 -04:00
if ( Feature - > RequiresProjectBuild ( PlatformInfo - > Name , OutReason ) )
2019-09-10 16:11:58 -04:00
{
return true ;
}
}
// check the target platforms for any differences in build settings or additional plugins
const FProjectDescriptor * Project = IProjectManager : : Get ( ) . GetCurrentProject ( ) ;
if ( ! FApp : : IsEngineInstalled ( ) & & ! HasDefaultBuildSettings ( ) )
{
OutReason = LOCTEXT ( " TempTarget_NonDefaultBuildConfig " , " project has non-default build configuration " ) ;
return true ;
}
2019-11-19 16:53:37 -05:00
// check if there's a non-default plugin change
FText Reason ;
2020-07-01 17:07:12 -04:00
if ( IPluginManager : : Get ( ) . RequiresTempTargetForCodePlugin ( Project , GetPlatformInfo ( ) . UBTPlatformString , Configuration , PlatformInfo - > PlatformType , Reason ) )
2019-09-10 16:11:58 -04:00
{
2019-11-19 16:53:37 -05:00
OutReason = Reason ;
return true ;
2019-09-10 16:11:58 -04:00
}
2019-11-19 16:53:37 -05:00
2019-09-10 16:11:58 -04:00
return false ;
}
2021-11-18 14:37:34 -05:00
bool FTargetPlatformBase : : IsEnabledForPlugin ( const IPlugin & Plugin ) const
{
const FProjectDescriptor * Project = IProjectManager : : Get ( ) . GetCurrentProject ( ) ;
return IsPluginEnabledForTarget ( Plugin , Project , GetPlatformInfo ( ) . UBTPlatformString , EBuildConfiguration : : Unknown ,
GetRuntimePlatformType ( ) ) ;
}
2019-01-29 08:56:46 -05:00
TSharedPtr < IDeviceManagerCustomPlatformWidgetCreator > FTargetPlatformBase : : GetCustomWidgetCreator ( ) const
{
static TSharedPtr < FDeviceBrowserDefaultPlatformWidgetCreator > DefaultWidgetCreator = MakeShared < FDeviceBrowserDefaultPlatformWidgetCreator > ( ) ;
return DefaultWidgetCreator ;
}
2019-09-10 16:11:58 -04:00
bool FTargetPlatformBase : : HasDefaultBuildSettings ( ) const
{
// first check default build settings for all platforms
TArray < FString > BoolKeys , IntKeys , StringKeys , BuildKeys ;
BuildKeys . Add ( TEXT ( " bCompileApex " ) ) ;
BuildKeys . Add ( TEXT ( " bCompileICU " ) ) ;
BuildKeys . Add ( TEXT ( " bCompileSimplygon " ) ) ;
BuildKeys . Add ( TEXT ( " bCompileSimplygonSSF " ) ) ;
BuildKeys . Add ( TEXT ( " bCompileRecast " ) ) ;
BuildKeys . Add ( TEXT ( " bCompileSpeedTree " ) ) ;
BuildKeys . Add ( TEXT ( " bCompileWithPluginSupport " ) ) ;
BuildKeys . Add ( TEXT ( " bCompilePhysXVehicle " ) ) ;
BuildKeys . Add ( TEXT ( " bCompileFreeType " ) ) ;
BuildKeys . Add ( TEXT ( " bCompileForSize " ) ) ;
BuildKeys . Add ( TEXT ( " bCompileCEF3 " ) ) ;
BuildKeys . Add ( TEXT ( " bCompileCustomSQLitePlatform " ) ) ;
2020-07-01 17:07:12 -04:00
if ( ! DoProjectSettingsMatchDefault ( IniPlatformName ( ) , TEXT ( " /Script/BuildSettings.BuildSettings " ) , & BuildKeys , nullptr , nullptr ) )
2019-09-10 16:11:58 -04:00
{
return false ;
}
FString PlatformSection ;
GetBuildProjectSettingKeys ( PlatformSection , BoolKeys , IntKeys , StringKeys ) ;
2020-07-01 17:07:12 -04:00
if ( ! DoProjectSettingsMatchDefault ( IniPlatformName ( ) , PlatformSection , & BoolKeys , & IntKeys , & StringKeys ) )
2019-09-10 16:11:58 -04:00
{
return false ;
}
return true ;
}
bool FTargetPlatformBase : : DoProjectSettingsMatchDefault ( const FString & InPlatformName , const FString & InSection , const TArray < FString > * InBoolKeys , const TArray < FString > * InIntKeys , const TArray < FString > * InStringKeys )
{
FConfigFile ProjIni ;
FConfigFile DefaultIni ;
FConfigCacheIni : : LoadLocalIniFile ( ProjIni , TEXT ( " Engine " ) , true , * InPlatformName , true ) ;
FConfigCacheIni : : LoadExternalIniFile ( DefaultIni , TEXT ( " Engine " ) , * FPaths : : EngineConfigDir ( ) , * FPaths : : EngineConfigDir ( ) , true , NULL , true ) ;
if ( InBoolKeys ! = NULL )
{
for ( int Index = 0 ; Index < InBoolKeys - > Num ( ) ; + + Index )
{
FString Default ( TEXT ( " False " ) ) , Project ( TEXT ( " False " ) ) ;
DefaultIni . GetString ( * InSection , * ( ( * InBoolKeys ) [ Index ] ) , Default ) ;
ProjIni . GetString ( * InSection , * ( ( * InBoolKeys ) [ Index ] ) , Project ) ;
if ( Default . Compare ( Project , ESearchCase : : IgnoreCase ) )
{
return false ;
}
}
}
if ( InIntKeys ! = NULL )
{
for ( int Index = 0 ; Index < InIntKeys - > Num ( ) ; + + Index )
{
int64 Default ( 0 ) , Project ( 0 ) ;
DefaultIni . GetInt64 ( * InSection , * ( ( * InIntKeys ) [ Index ] ) , Default ) ;
ProjIni . GetInt64 ( * InSection , * ( ( * InIntKeys ) [ Index ] ) , Project ) ;
if ( Default ! = Project )
{
return false ;
}
}
}
if ( InStringKeys ! = NULL )
{
for ( int Index = 0 ; Index < InStringKeys - > Num ( ) ; + + Index )
{
FString Default ( TEXT ( " False " ) ) , Project ( TEXT ( " False " ) ) ;
DefaultIni . GetString ( * InSection , * ( ( * InStringKeys ) [ Index ] ) , Default ) ;
ProjIni . GetString ( * InSection , * ( ( * InStringKeys ) [ Index ] ) , Project ) ;
if ( Default . Compare ( Project , ESearchCase : : IgnoreCase ) )
{
return false ;
}
}
}
return true ;
}
2022-07-18 17:47:55 -04:00
FTargetPlatformBase : : FTargetPlatformBase ( const PlatformInfo : : FTargetPlatformInfo * const InPlatformInfo ) : PlatformInfo ( InPlatformInfo )
{
checkf ( PlatformInfo , TEXT ( " Null PlatformInfo was passed to FTargetPlatformBase. Check the static IsUsable function before creating this object. See FWindowsTargetPlatformModule::GetTargetPlatform() " ) ) ;
PlatformOrdinal = AssignPlatformOrdinal ( * this ) ;
# if WITH_ENGINE
// Build Audio Format Settings, Using long form equiv of GetConfigSysten to avoid calling a virtual
AudioFormatSettings = MakePimpl < Audio : : FAudioFormatSettings > (
FConfigCacheIni : : ForPlatform ( InPlatformInfo - > IniPlatformName ) , GEngineIni , InPlatformInfo - > IniPlatformName . ToString ( ) ) ;
# endif //WITH_ENGINE
}
# if WITH_ENGINE
const Audio : : FAudioFormatSettings & FTargetPlatformBase : : GetAudioFormatSettings ( ) const
{
check ( AudioFormatSettings . IsValid ( ) )
return * AudioFormatSettings ;
}
FName FTargetPlatformBase : : GetWaveFormat ( const class USoundWave * InWave ) const
{
return GetAudioFormatSettings ( ) . GetWaveFormat ( InWave ) ;
}
void FTargetPlatformBase : : GetAllWaveFormats ( TArray < FName > & OutFormats ) const
{
GetAudioFormatSettings ( ) . GetAllWaveFormats ( OutFormats ) ;
}
void FTargetPlatformBase : : GetWaveFormatModuleHints ( TArray < FName > & OutModuleNames ) const
{
GetAudioFormatSettings ( ) . GetWaveFormatModuleHints ( OutModuleNames ) ;
}
2024-02-15 16:36:13 -05:00
void FTargetPlatformBase : : GetTextureSizeLimits ( uint64 & OutMaximumSurfaceBytes , uint64 & OutMaximumPackageBytes ) const
{
FTargetPlatformControlsBase : : GetTextureSizeLimitsDefault ( GetConfigSystem ( ) , OutMaximumSurfaceBytes , OutMaximumPackageBytes ) ;
}
2022-07-18 17:47:55 -04:00
# endif // WITH_ENGINE
2024-03-11 07:24:38 -04:00
PRAGMA_ENABLE_DEPRECATION_WARNINGS
2019-09-10 16:11:58 -04:00
# undef LOCTEXT_NAMESPACE