Skip to content

Commit 0183b26

Browse files
EmreDoganUnityEvergreen
authored andcommitted
[Forward Port] [trunk] [HDRP] Migrated performance warning platform check from HDRP package code to engine-side.
1 parent acf697b commit 0183b26

File tree

15 files changed

+693
-68
lines changed

15 files changed

+693
-68
lines changed

Packages/com.unity.render-pipelines.high-definition/Editor/BuildProcessors/HDRPPreprocessBuild.cs

Lines changed: 266 additions & 32 deletions
Large diffs are not rendered by default.

Packages/com.unity.render-pipelines.high-definition/Editor/Compositor/CompositionManagerEditor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ public override void OnInspectorGUI()
146146
}
147147
m_SerializedProperties.Update();
148148

149+
if (EditorGraphicsSettings.ShouldValidateGraphicsForActiveBuildTarget())
150+
{
151+
var validationSettings = HDProjectSettings.validationSettings;
152+
if (!validationSettings.k_GraphicsCompositor_Recommended && m_compositionManager.enableInternal)
153+
HDEditorUtils.ShowFeatureOptimisationWarning("Graphics Compositor");
154+
}
155+
149156
m_EnablePreview = EditorGUILayout.Toggle(Styles.k_EnablePreview, m_compositionManager.enableOutput);
150157
{
151158
m_compositionManager.enableOutput = m_EnablePreview;

Packages/com.unity.render-pipelines.high-definition/Editor/Lighting/VolumetricClouds/VolumetricCloudsEditor.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,35 @@ public override void OnInspectorGUI()
519519
}
520520
using var disableScope = new EditorGUI.DisabledScope(notSupported);
521521

522+
if (EditorGraphicsSettings.ShouldValidateGraphicsForActiveBuildTarget())
523+
{
524+
var validationSettings = HDProjectSettings.validationSettings;
525+
VolumetricClouds defaultClouds = HDEditorUtils.GetVolumeComponentDefaultState<VolumetricClouds>();
526+
527+
// Get effective quality value (use local if overridden, otherwise use default)
528+
bool useDefaultEnabled = !m_Enable.overrideState.boolValue;
529+
bool effectiveEnabled = useDefaultEnabled
530+
? (defaultClouds?.enable.value ?? false)
531+
: m_Enable.value.boolValue;
532+
533+
if (effectiveEnabled && !validationSettings.k_VolumetricClouds_Recommended)
534+
{
535+
if (useDefaultEnabled && HDEditorUtils.TryGetVolumeParameterSource<VolumetricClouds>(
536+
clouds => clouds.enable.overrideState && clouds.enable.value == effectiveEnabled,
537+
out var sourceProfile,
538+
out var sourceName))
539+
{
540+
HDEditorUtils.ShowFeatureOptimisationWarning(HDRenderPipelineUI.Styles.volumetricCloudsSubTitle.text, sourceName, () => Selection.activeObject = sourceProfile);
541+
}
542+
else
543+
{
544+
HDEditorUtils.ShowFeatureOptimisationWarning(HDRenderPipelineUI.Styles.volumetricCloudsSubTitle.text);
545+
}
546+
}
547+
}
548+
522549
EditorGUILayout.LabelField("General", EditorStyles.miniLabel);
523550
PropertyField(m_Enable, EditorGUIUtility.TrTextContent("State"));
524-
525551
if (m_Enable.value.boolValue && !notSupported)
526552
HDEditorUtils.EnsureFrameSetting(FrameSettingsField.VolumetricClouds);
527553

Packages/com.unity.render-pipelines.high-definition/Editor/PostProcessing/FilmGrainEditor.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,36 @@ public override void OnInspectorGUI()
2525
{
2626
HDEditorUtils.EnsureFrameSetting(FrameSettingsField.FilmGrain);
2727

28-
if (m_Intensity.value.floatValue > 0)
29-
HDEditorUtils.ShowPlatformPerformanceWarning(BuildTarget.Switch2, "Film Grain");
28+
if (EditorGraphicsSettings.ShouldValidateGraphicsForActiveBuildTarget())
29+
{
30+
var defaultFilmGrain = HDEditorUtils.GetVolumeComponentDefaultState<FilmGrain>();
31+
32+
// Get effective intensity value (use local if overridden, otherwise use default)
33+
bool useDefaultIntensity = !m_Intensity.overrideState.boolValue;
34+
float effectiveIntensity = useDefaultIntensity
35+
? (defaultFilmGrain?.intensity.value ?? 0.0f)
36+
: m_Intensity.value.floatValue;
37+
38+
var validationSettings = HDProjectSettings.validationSettings;
39+
if (effectiveIntensity > 0.0f && !validationSettings.k_FilmGrain_Recommended)
40+
{
41+
using (new IndentLevelScope())
42+
{
43+
if (useDefaultIntensity && HDEditorUtils.TryGetVolumeParameterSource<FilmGrain>(
44+
filmGrain => filmGrain.intensity.overrideState && filmGrain.intensity.value > 0.0f,
45+
out var sourceProfile,
46+
out var sourceName))
47+
{
48+
HDEditorUtils.ShowFeatureOptimisationWarning("Film Grain", sourceName, () => Selection.activeObject = sourceProfile);
49+
}
50+
else
51+
{
52+
HDEditorUtils.ShowFeatureOptimisationWarning("Film Grain");
53+
}
54+
}
55+
56+
}
57+
}
3058

3159
PropertyField(m_Type);
3260

Packages/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDEditorUtils.cs

Lines changed: 144 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -437,32 +437,167 @@ internal static bool EnsureVolume<T>(Func<T, string> volumeValidator) where T :
437437
return true;
438438
}
439439

440+
/// <summary>
441+
/// Gets the resolved default state for a volume component, which combines global and quality default profiles.
442+
/// Use this to determine what values will be used for non-overridden parameters.
443+
/// </summary>
444+
/// <typeparam name="T">The type of volume component to retrieve</typeparam>
445+
/// <returns>The volume component with resolved default state, or null if not initialized</returns>
446+
internal static T GetVolumeComponentDefaultState<T>() where T : VolumeComponent
447+
{
448+
if (!VolumeManager.instance.isInitialized)
449+
return null;
450+
451+
return VolumeManager.instance.GetVolumeComponentDefaultState(typeof(T)) as T;
452+
}
453+
454+
/// <summary>
455+
/// Gets the effective value of a volume parameter, considering override state and default fallback.
456+
/// If the parameter is overridden, returns the local value. Otherwise, returns the value from
457+
/// the default parameter (or the fallback if default is null).
458+
/// </summary>
459+
/// <typeparam name="T">The type of the parameter value</typeparam>
460+
/// <param name="parameter">The volume parameter to get the value from</param>
461+
/// <param name="defaultParameter">The default parameter to use when parameter is not overridden</param>
462+
/// <param name="fallbackValue">Fallback value if default parameter is null</param>
463+
/// <returns>The effective value considering override state and defaults</returns>
464+
internal static T GetEffectiveParameterValue<T>(
465+
VolumeParameter<T> parameter,
466+
VolumeParameter<T> defaultParameter,
467+
T fallbackValue)
468+
{
469+
if (parameter.overrideState)
470+
return parameter.value;
471+
472+
return defaultParameter != null ? defaultParameter.value : fallbackValue;
473+
}
474+
475+
/// <summary>
476+
/// Finds which default volume profile (global or quality) is setting a parameter value.
477+
/// Checks in precedence order: Quality profile overrides Global profile.
478+
/// </summary>
479+
/// <typeparam name="T">The type of volume component</typeparam>
480+
/// <param name="parameterPredicate">Predicate which specifies the target</param>
481+
/// <param name="sourceProfile">The volume profile that is setting the value, or null if not found</param>
482+
/// <param name="sourceDescription">Human-readable description of the source (e.g., "Quality Profile in HDRenderPipelineAsset")</param>
483+
/// <returns>True if a profile with the target parameter was found</returns>
484+
internal static bool TryGetVolumeParameterSource<T>(
485+
System.Func<T, bool> parameterPredicate,
486+
out VolumeProfile sourceProfile,
487+
out string sourceDescription) where T : VolumeComponent
488+
{
489+
sourceProfile = null;
490+
sourceDescription = null;
491+
492+
if (!VolumeManager.instance.isInitialized)
493+
return false;
494+
495+
// Check quality profile first (higher precedence)
496+
if (VolumeManager.instance.qualityDefaultProfile != null &&
497+
VolumeManager.instance.qualityDefaultProfile.TryGet<T>(out var qualityComponent) &&
498+
qualityComponent.active && parameterPredicate(qualityComponent))
499+
{
500+
sourceProfile = VolumeManager.instance.qualityDefaultProfile;
501+
var assetName = HDRenderPipeline.currentAsset != null ? HDRenderPipeline.currentAsset.name : "HDRP Asset";
502+
sourceDescription = $"Quality Profile ({assetName})";
503+
return true;
504+
}
505+
506+
// Check global default profile (lower precedence)
507+
if (VolumeManager.instance.globalDefaultProfile != null &&
508+
VolumeManager.instance.globalDefaultProfile.TryGet<T>(out var globalComponent) &&
509+
globalComponent.active && parameterPredicate(globalComponent))
510+
{
511+
sourceProfile = VolumeManager.instance.globalDefaultProfile;
512+
sourceDescription = "Global Profile (Graphics Settings)";
513+
return true;
514+
}
515+
516+
return false;
517+
}
518+
440519
/// <summary>
441520
/// Shows a platform-specific performance warning help box for a given feature.
442521
/// </summary>
443-
/// <param name="targetPlatform">The build target platform to check and display</param>
444522
/// <param name="featureName">The name of the feature (e.g., "Ray Tracing", "Film Grain")</param>
445523
/// <param name="recommendation">Optional recommendation text. If null, uses default "is not recommended for this platform"</param>
446-
internal static void ShowPlatformPerformanceWarning(BuildTarget targetPlatform, string featureName, string recommendation = null)
524+
internal static void ShowFeatureOptimisationWarning(string featureName, string recommendation = null)
447525
{
448-
if (EditorUserBuildSettings.activeBuildTarget != targetPlatform)
449-
return;
526+
string message = $"{featureName} is enabled for the active platform.\n";
527+
528+
if (!string.IsNullOrEmpty(recommendation))
529+
{
530+
message += recommendation;
531+
}
532+
else
533+
{
534+
message += HDRenderPipelineUI.Styles.featureNotRecommendedWarning;
535+
}
450536

451-
var activeBuildTargetGroup = BuildPipeline.GetBuildTargetGroup(targetPlatform);
452-
var namedBuildTarget = NamedBuildTarget.FromBuildTargetGroup(activeBuildTargetGroup);
537+
EditorGUILayout.HelpBox(message, MessageType.Warning, wide: true);
538+
}
453539

454-
string message = $"{featureName} is enabled for {namedBuildTarget.TargetName}. ";
540+
/// <summary>
541+
/// Shows a platform-specific performance warning help box for a given feature.
542+
/// </summary>
543+
/// <param name="featureName">The name of the feature (e.g., "Ray Tracing", "Film Grain")</param>
544+
/// <param name="recommendation">Optional recommendation text. If null, uses default "is not recommended for this platform"</param>
545+
internal static void ShowFeatureOptimisationWarning(string featureName, string sourceAssetName, Action onButtonClicked, string recommendation = null)
546+
{
547+
string message = $"{featureName} is enabled in {sourceAssetName} for the active platform.\n";
455548

456549
if (!string.IsNullOrEmpty(recommendation))
457550
{
458551
message += recommendation;
459552
}
460553
else
461554
{
462-
message += "This may significantly impact performance and is not recommended for this platform.";
555+
message += HDRenderPipelineUI.Styles.featureNotRecommendedWarning;
463556
}
464557

465-
EditorGUILayout.HelpBox(message, MessageType.Warning, wide: true);
558+
CoreEditorUtils.DrawFixMeBox(
559+
message,
560+
MessageType.Warning,
561+
"Open",
562+
onButtonClicked);
563+
}
564+
565+
internal static void ShowFeatureParameterOptimisationWarning(string settingName, string settingValue, string recommendation = null)
566+
{
567+
EditorGUILayout.HelpBox(CreateParameterWarningMessage(settingName, settingValue, null, recommendation), MessageType.Warning, wide: true);
568+
}
569+
570+
internal static void ShowFeatureParameterOptimisationWarning(string settingName, string settingValue, string sourceAssetName, Action onButtonClicked, string recommendation = null)
571+
{
572+
CoreEditorUtils.DrawFixMeBox(
573+
CreateParameterWarningMessage(settingName, settingValue, sourceAssetName, recommendation),
574+
MessageType.Warning,
575+
"Open",
576+
onButtonClicked);
577+
}
578+
579+
internal static string CreateParameterWarningMessage(string settingName, string settingValue, string sourceAssetName = null, string recommendation = null)
580+
{
581+
string message = $"{settingName}: {settingValue} ";
582+
if (sourceAssetName != null)
583+
{
584+
message += $"is set in {sourceAssetName}.";
585+
}
586+
else
587+
{
588+
message += $"is used for the active platform.";
589+
}
590+
591+
if (!string.IsNullOrEmpty(recommendation))
592+
{
593+
message += '\n' + recommendation;
594+
}
595+
else
596+
{
597+
message += $"\nThis may impact performance and is not recommended for this platform.";
598+
}
599+
600+
return message;
466601
}
467602

468603
internal static bool IsInTestSuiteOrBatchMode()

Packages/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.Skin.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ int CountBits(uint bitMask) // System.Numerics.BitOperations not available
422422
public static GUIContent staticBatchingInfoMessage =
423423
EditorGUIUtility.TrTextContent("Static Batching is not recommended when using GPU draw submission modes, performance may improve if Static Batching is disabled in Player Settings.");
424424

425+
public static readonly string featureNotRecommendedWarning = L10n.Tr("This feature is not optimized for this platform, enabling it may affect performance.");
426+
public static readonly string maxFogBudgetWarning = L10n.Tr("The maximum recommended fog budget for this platform is {0}. Lower the tier to stay under this for optimal performance.");
427+
public static readonly string minFogBudgetForDensityCutoffWarning = L10n.Tr("It is recommended to use Density cutoff when the fog budget is > {0} for this platform.");
428+
425429
public const string memoryDrawback = "Adds GPU memory";
426430
public const string shaderVariantDrawback = "Adds Shader Variants";
427431
public const string lotShaderVariantDrawback = "Adds multiple Shader Variants";

Packages/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,13 @@ static void Drawer_Volumetric(SerializedHDRenderPipelineAsset serialized, Editor
230230
}
231231

232232
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportVolumetricClouds, Styles.supportVolumetricCloudsContent);
233+
234+
if (EditorGraphicsSettings.ShouldValidateGraphicsForActiveBuildTarget())
235+
{
236+
var validationSettings = HDProjectSettings.validationSettings;
237+
if (serialized.renderPipelineSettings.supportVolumetricClouds.boolValue && !validationSettings.k_VolumetricClouds_Recommended)
238+
HDEditorUtils.ShowFeatureOptimisationWarning(Styles.volumetricCloudsSubTitle.text);
239+
}
233240
}
234241

235242
static void Drawer_SectionProbeVolume(SerializedHDRenderPipelineAsset serialized, Editor owner)
@@ -1231,6 +1238,13 @@ static void Drawer_SectionHighQualityLineRenderingSettings(SerializedHDRenderPip
12311238
{
12321239
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportHighQualityLineRendering, Styles.supportHighQualityLineRenderingContent);
12331240

1241+
if (EditorGraphicsSettings.ShouldValidateGraphicsForActiveBuildTarget())
1242+
{
1243+
var validationSettings = HDProjectSettings.validationSettings;
1244+
if (serialized.renderPipelineSettings.supportHighQualityLineRendering.boolValue && !validationSettings.k_HighQualityLineRendering_Recommended)
1245+
HDEditorUtils.ShowFeatureOptimisationWarning(Styles.highQualityLineRenderingSubTitle.text);
1246+
}
1247+
12341248
++EditorGUI.indentLevel;
12351249
using (new EditorGUI.DisabledScope(!serialized.renderPipelineSettings.supportHighQualityLineRendering.boolValue))
12361250
{
@@ -1448,7 +1462,7 @@ static void DrawSSGIQualitySetting(SerializedHDRenderPipelineAsset serialized, i
14481462
internal static void DisplayRayTracingSupportBox()
14491463
{
14501464
var currentBuildTarget = EditorUserBuildSettings.activeBuildTarget;
1451-
if (HDRenderPipeline.PlatformHasRaytracingIssues(currentBuildTarget, out var warning))
1465+
if (HDRenderPipeline.CheckPlatformRaytracingCompatability(currentBuildTarget, out var warning))
14521466
{
14531467
EditorGUILayout.HelpBox(warning, MessageType.Warning);
14541468
}
@@ -1604,8 +1618,13 @@ static void Drawer_SectionMaterialUnsorted(SerializedHDRenderPipelineAsset seria
16041618
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportDistortion, Styles.supportDistortion);
16051619

16061620
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportSubsurfaceScattering, Styles.supportedSSSContent);
1607-
if (serialized.renderPipelineSettings.supportSubsurfaceScattering.boolValue)
1608-
HDEditorUtils.ShowPlatformPerformanceWarning(BuildTarget.Switch2, "Subsurface Scattering");
1621+
1622+
if (EditorGraphicsSettings.ShouldValidateGraphicsForActiveBuildTarget())
1623+
{
1624+
var validationSettings = HDProjectSettings.validationSettings;
1625+
if (serialized.renderPipelineSettings.supportSubsurfaceScattering.boolValue && !validationSettings.k_SubsurfaceScattering_Recommended)
1626+
HDEditorUtils.ShowFeatureOptimisationWarning(Styles.supportedSSSContent.text);
1627+
}
16091628

16101629
using (new EditorGUI.DisabledScope(serialized.renderPipelineSettings.supportSubsurfaceScattering.hasMultipleDifferentValues
16111630
|| !serialized.renderPipelineSettings.supportSubsurfaceScattering.boolValue))

Packages/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/LineRendering/HDRenderPipeline.LineRendering.VolumeComponentEditor.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,36 @@ public override void OnInspectorGUI()
4343
}
4444
using var disableScope = new EditorGUI.DisabledScope(notSupported);
4545

46+
if (!notSupported && EditorGraphicsSettings.ShouldValidateGraphicsForActiveBuildTarget())
47+
{
48+
var validationSettings = HDProjectSettings.validationSettings;
49+
var defaultHQLines = HDEditorUtils.GetVolumeComponentDefaultState<HighQualityLineRenderingVolumeComponent>();
50+
51+
// Get effective enable value (use local if overridden, otherwise use default)
52+
bool useDefaultEnable = !m_Enable.overrideState.boolValue;
53+
bool effectiveEnable = useDefaultEnable
54+
? (defaultHQLines?.enable.value ?? false)
55+
: m_Enable.value.boolValue;
56+
57+
if (effectiveEnable && !validationSettings.k_HighQualityLineRendering_Recommended)
58+
{
59+
using (new IndentLevelScope())
60+
{
61+
if (useDefaultEnable && HDEditorUtils.TryGetVolumeParameterSource<HighQualityLineRenderingVolumeComponent>(
62+
hqLines => hqLines.enable.overrideState && hqLines.enable.value == effectiveEnable,
63+
out var sourceProfile,
64+
out var sourceName))
65+
{
66+
HDEditorUtils.ShowFeatureOptimisationWarning(HDRenderPipelineUI.Styles.highQualityLineRenderingSubTitle.text, sourceName, () => Selection.activeObject = sourceProfile);
67+
}
68+
else
69+
{
70+
HDEditorUtils.ShowFeatureOptimisationWarning(HDRenderPipelineUI.Styles.highQualityLineRenderingSubTitle.text);
71+
}
72+
}
73+
}
74+
}
75+
4676
EditorGUILayout.LabelField("General", EditorStyles.miniLabel);
4777
PropertyField(m_Enable);
4878
PropertyField(m_CompositionMode);

0 commit comments

Comments
 (0)