Skip to content

Commit 3c3691d

Browse files
alex-vazquez-unity3dEvergreen
authored andcommitted
[HDRP]Make sure we show warnings on the inspector and when building when some features are not available or have performance impact.
1 parent 483fca7 commit 3c3691d

7 files changed

Lines changed: 299 additions & 28 deletions

File tree

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

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,72 @@ public void OnPreprocessBuild(BuildReport report)
4343

4444
LogIncludedAssets(m_BuildData.renderPipelineAssets);
4545

46+
if (!IsConfigurationValid())
47+
{
48+
if(!ProceedWithBuild())
49+
throw new BuildFailedException("Build canceled by user due to HDRP configuration issues.");
50+
}
51+
52+
4653
GatherShaderFeatures();
4754
}
4855
}
4956

57+
private static bool IsConfigurationValid()
58+
{
59+
// Validate the configuration of the HDRP assets for the current build target. We want to make sure that users are aware of potential performance issues or unsupported features before building.
60+
// We still want to build the player even if the configuration is not optimal, but we log warnings to inform users about potential issues.
61+
// Note that we validate the configuration of all HDRP assets included in the build, not just the one assigned in Graphics Settings.
62+
// This is because users can have multiple HDRP assets in their project and switch between them at runtime, so we want to make sure that all of them are correctly configured for the target platform.
63+
64+
// We must log all the warnings, and avoid doing validConfiguration &= ValidationXXX, that will avoid logging all the warnings, and only log the first one that fails.
65+
// This way users will have a complete overview of all the potential issues with their configuration, and can fix them all at once, instead of having to go through multiple build iterations to fix each issue one by one.
66+
// So be carefull when you edit this code, and make sure to log all the warnings, even if one of the validation fails.
67+
bool validConfiguration = true;
68+
69+
{
70+
bool config = ValidateRayTracingConfiguration(m_BuildData.renderPipelineAssets);
71+
validConfiguration &= config;
72+
}
73+
74+
{
75+
bool config = ValidateSubsurfaceScatteringConfiguration(m_BuildData.renderPipelineAssets);
76+
validConfiguration &= config;
77+
}
78+
79+
{
80+
bool config = ValidateFilmGrainConfiguration(m_BuildData.renderPipelineAssets);
81+
validConfiguration &= config;
82+
}
83+
84+
return validConfiguration;
85+
}
86+
87+
internal static string k_DialogKey = $"{nameof(UnityEditor)}.{nameof(Rendering)}.{nameof(HighDefinition)}.{nameof(HDRPPreprocessBuild)}.{nameof(ProceedWithBuild)}";
88+
89+
private bool ProceedWithBuild()
90+
{
91+
if(HDEditorUtils.IsInTestSuiteOrBatchMode())
92+
return true;
93+
94+
var title = "Build Configuration Issues Detected";
95+
var body = new StringBuilder();
96+
97+
body.AppendLine("HDRP identified settings that may impact performance or enable unsupported features for the current build target.");
98+
body.AppendLine("Review the Console for details (look for messages tagged 'HDRP Build Validation').");
99+
body.AppendLine();
100+
body.Append("Do you want to continue building?");
101+
102+
return EditorUtility.DisplayDialog(
103+
title,
104+
body.ToString(),
105+
"Proceed",
106+
"Cancel",
107+
DialogOptOutDecisionType.ForThisMachine,
108+
k_DialogKey
109+
);
110+
}
111+
50112
internal static void LogIncludedAssets(List<HDRenderPipelineAsset> assetsList)
51113
{
52114
using (GenericPool<StringBuilder>.Get(out var assetsIncluded))
@@ -64,6 +126,104 @@ internal static void LogIncludedAssets(List<HDRenderPipelineAsset> assetsList)
64126
}
65127
}
66128

129+
internal static bool ValidateRayTracingConfiguration(List<HDRenderPipelineAsset> assetsList)
130+
{
131+
// Check if any asset has ray tracing enabled
132+
bool anyAssetHasRayTracingEnabled = false;
133+
foreach (var hdrpAsset in assetsList)
134+
{
135+
if (hdrpAsset != null && hdrpAsset.currentPlatformRenderPipelineSettings.supportRayTracing)
136+
{
137+
anyAssetHasRayTracingEnabled = true;
138+
break;
139+
}
140+
}
141+
142+
if (!anyAssetHasRayTracingEnabled)
143+
return true; // No ray tracing enabled, skip validation
144+
145+
var currentBuildTarget = EditorUserBuildSettings.activeBuildTarget;
146+
if (HDRenderPipeline.PlatformHasRaytracingIssues(currentBuildTarget, out var warning))
147+
{
148+
Debug.LogWarning($"HDRP Build Validation - Ray Tracing:{warning}");
149+
return false;
150+
}
151+
152+
return true;
153+
}
154+
155+
internal static bool ValidateSubsurfaceScatteringConfiguration(List<HDRenderPipelineAsset> assetsList)
156+
{
157+
var currentBuildTarget = EditorUserBuildSettings.activeBuildTarget;
158+
159+
// Only validate for Switch 2
160+
if (currentBuildTarget != BuildTarget.Switch2)
161+
return true;
162+
163+
// Check if any asset has Subsurface Scattering enabled
164+
bool anyAssetHasSSSEnabled = false;
165+
foreach (var hdrpAsset in assetsList)
166+
{
167+
if (hdrpAsset != null && hdrpAsset.currentPlatformRenderPipelineSettings.supportSubsurfaceScattering)
168+
{
169+
anyAssetHasSSSEnabled = true;
170+
break;
171+
}
172+
}
173+
174+
if (!anyAssetHasSSSEnabled)
175+
return true; // No SSS enabled, skip validation
176+
177+
var activeBuildTargetGroup = BuildPipeline.GetBuildTargetGroup(BuildTarget.Switch2);
178+
var namedBuildTarget = NamedBuildTarget.FromBuildTargetGroup(activeBuildTargetGroup);
179+
Debug.LogWarning($"HDRP Build Validation - Subsurface Scattering: Subsurface Scattering is enabled for {namedBuildTarget.TargetName}. For optimal performance, set the Downsample Level to the maximum value (2) for this platform.");
180+
return false;
181+
}
182+
183+
internal static bool ValidateFilmGrainConfiguration(List<HDRenderPipelineAsset> assetsList)
184+
{
185+
var currentBuildTarget = EditorUserBuildSettings.activeBuildTarget;
186+
187+
// Only validate for Switch 2
188+
if (currentBuildTarget != BuildTarget.Switch2)
189+
return true;
190+
191+
// Check default volume profile from HDRP Global Settings
192+
bool foundFilmGrain = false;
193+
var defaultVolumeProfileSettings = GraphicsSettings.GetRenderPipelineSettings<HDRPDefaultVolumeProfileSettings>();
194+
if (defaultVolumeProfileSettings?.volumeProfile != null)
195+
{
196+
if (defaultVolumeProfileSettings.volumeProfile.TryGet<FilmGrain>(out var filmGrain) && filmGrain.intensity.value > 0)
197+
{
198+
foundFilmGrain = true;
199+
}
200+
}
201+
202+
// Check volume profiles in each HDRP asset
203+
if (!foundFilmGrain)
204+
{
205+
foreach (var hdrpAsset in assetsList)
206+
{
207+
if (hdrpAsset != null && hdrpAsset.volumeProfile != null)
208+
{
209+
if (hdrpAsset.volumeProfile.TryGet<FilmGrain>(out var filmGrain) && filmGrain.intensity.value > 0)
210+
{
211+
foundFilmGrain = true;
212+
break;
213+
}
214+
}
215+
}
216+
}
217+
218+
if (!foundFilmGrain)
219+
return true; // No Film Grain with intensity > 0, skip validation
220+
221+
var activeBuildTargetGroup = BuildPipeline.GetBuildTargetGroup(BuildTarget.Switch2);
222+
var namedBuildTarget = NamedBuildTarget.FromBuildTargetGroup(activeBuildTargetGroup);
223+
Debug.LogWarning($"HDRP Build Validation - Film Grain: Film Grain is enabled for {namedBuildTarget.TargetName}. This may significantly impact performance and should be disabled for this platform.");
224+
return false;
225+
}
226+
67227
internal static void ConfigureMinimumMaxLoDValueForAllQualitySettings()
68228
{
69229
int GetMinimumMaxLoDValue(HDRenderPipelineAsset asset)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using UnityEditor.Rendering;
21
using UnityEngine;
32
using UnityEngine.Rendering.HighDefinition;
43

@@ -26,6 +25,9 @@ public override void OnInspectorGUI()
2625
{
2726
HDEditorUtils.EnsureFrameSetting(FrameSettingsField.FilmGrain);
2827

28+
if (m_Intensity.value.floatValue > 0)
29+
HDEditorUtils.ShowPlatformPerformanceWarning(BuildTarget.Switch2, "Film Grain");
30+
2931
PropertyField(m_Type);
3032

3133
if (m_Type.value.intValue == (int)FilmGrainLookup.Custom)

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using UnityEditor.Build;
56
using UnityEditor.Inspector.GraphicsSettingsInspectors;
67
using UnityEngine;
8+
using UnityEngine.Rendering;
79
using UnityEngine.Rendering.HighDefinition;
810
using UnityEngine.UIElements;
9-
using RenderingLayerMask = UnityEngine.RenderingLayerMask;
10-
using UnityEngine.Rendering;
1111

1212
namespace UnityEditor.Rendering.HighDefinition
1313
{
@@ -436,6 +436,41 @@ internal static bool EnsureVolume<T>(Func<T, string> volumeValidator) where T :
436436

437437
return true;
438438
}
439+
440+
/// <summary>
441+
/// Shows a platform-specific performance warning help box for a given feature.
442+
/// </summary>
443+
/// <param name="targetPlatform">The build target platform to check and display</param>
444+
/// <param name="featureName">The name of the feature (e.g., "Ray Tracing", "Film Grain")</param>
445+
/// <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)
447+
{
448+
if (EditorUserBuildSettings.activeBuildTarget != targetPlatform)
449+
return;
450+
451+
var activeBuildTargetGroup = BuildPipeline.GetBuildTargetGroup(targetPlatform);
452+
var namedBuildTarget = NamedBuildTarget.FromBuildTargetGroup(activeBuildTargetGroup);
453+
454+
string message = $"{featureName} is enabled for {namedBuildTarget.TargetName}. ";
455+
456+
if (!string.IsNullOrEmpty(recommendation))
457+
{
458+
message += recommendation;
459+
}
460+
else
461+
{
462+
message += "This may significantly impact performance and is not recommended for this platform.";
463+
}
464+
465+
EditorGUILayout.HelpBox(message, MessageType.Warning, wide: true);
466+
}
467+
468+
internal static bool IsInTestSuiteOrBatchMode()
469+
{
470+
string commandLineOptions = System.Environment.CommandLine;
471+
bool inTestSuite = commandLineOptions.Contains("-testResults");
472+
return inTestSuite || Application.isBatchMode;
473+
}
439474
}
440475

441476
// Due to a UI bug/limitation, we have to do it this way to support bold labels

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ public class Styles
185185
public static readonly GUIContent supportRaytracing = EditorGUIUtility.TrTextContent("Realtime Raytracing");
186186
public static readonly GUIContent supportedRayTracingMode = EditorGUIUtility.TrTextContent("Supported Ray Tracing Mode");
187187
public static readonly GUIContent supportVFXRayTracing = EditorGUIUtility.TrTextContent("Visual Effects Ray Tracing", "When enabled, Visual Effects Outputs which have Enable Ray Tracing on will be accounted for in Ray-traced effects.");
188-
public static readonly GUIContent rayTracingRestrictionOnlyWarning = EditorGUIUtility.TrTextContent("Ray tracing is currently only supported on DX12, Playstation 5 and Xbox Series X.", null, CoreEditorStyles.iconWarn);
188+
public static readonly GUIContent rayTracingRestrictionOnlyWarning = EditorGUIUtility.TrTextContent("Ray tracing requires DX12 on Windows. Disable Auto Graphics API and set Direct3D 12 as the first Graphics API in Player Settings. You can use the HDRP Wizard to configure these settings.", null, CoreEditorStyles.iconWarn);
189+
public static string rayTracingNotSupportedBuildTarget = L10n.Tr("The {0} does not support Ray tracing. Consider disabling it or switch to a platform that supports it.");
189190
public static readonly GUIContent rayTracingMSAAUnsupported = EditorGUIUtility.TrTextContent("When Ray tracing is enabled in asset, MSAA is not supported. Please refer to the documentation.");
190191
public static readonly GUIContent waterMSAAUnsupported = EditorGUIUtility.TrTextContent("When Water is enabled in asset, MSAA is not supported. Please refer to the documentation.");
191192
public static readonly GUIContent maximumLODLevel = EditorGUIUtility.TrTextContent("Maximum LOD Level");

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Text;
4-
using UnityEngine;
54
using Unity.Mathematics;
5+
using UnityEditorInternal;
6+
using UnityEngine;
67
using UnityEngine.Experimental.Rendering;
78
using UnityEngine.Rendering;
89
using UnityEngine.Rendering.HighDefinition;
9-
using UnityEditorInternal;
1010
using static UnityEngine.Rendering.HighDefinition.RenderPipelineSettings;
1111

1212
namespace UnityEditor.Rendering.HighDefinition
@@ -1442,12 +1442,11 @@ static void DrawSSGIQualitySetting(SerializedHDRenderPipelineAsset serialized, i
14421442

14431443
internal static void DisplayRayTracingSupportBox()
14441444
{
1445-
CoreEditorUtils.DrawFixMeBox(Styles.rayTracingRestrictionOnlyWarning, "Open", () =>
1445+
var currentBuildTarget = EditorUserBuildSettings.activeBuildTarget;
1446+
if (HDRenderPipeline.PlatformHasRaytracingIssues(currentBuildTarget, out var warning))
14461447
{
1447-
HDUserSettings.SetOpen(InclusiveMode.DXROptional, true); // Make sure DXR is open
1448-
HDWizard.OpenWindow();
1449-
});
1450-
1448+
EditorGUILayout.HelpBox(warning, MessageType.Warning);
1449+
}
14511450
}
14521451

14531452
static void Drawer_SectionRenderingUnsorted(SerializedHDRenderPipelineAsset serialized, Editor owner)
@@ -1509,19 +1508,18 @@ static void Drawer_SectionRenderingUnsorted(SerializedHDRenderPipelineAsset seri
15091508

15101509
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportRayTracing, Styles.supportRaytracing);
15111510

1511+
// If ray tracing is enabled by the asset but the current system does not support it display a warning
1512+
if (serialized.renderPipelineSettings.supportRayTracing.boolValue)
1513+
{
1514+
DisplayRayTracingSupportBox();
1515+
}
1516+
15121517
using (new EditorGUI.DisabledScope(!serialized.renderPipelineSettings.supportRayTracing.boolValue))
15131518
{
15141519
++EditorGUI.indentLevel;
15151520
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportedRayTracingMode, Styles.supportedRayTracingMode);
15161521
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportVFXRayTracing,
15171522
Styles.supportVFXRayTracing);
1518-
1519-
// If ray tracing is enabled by the asset but the current system does not support it display a warning
1520-
if (!HDRenderPipeline.currentSystemSupportsRayTracing)
1521-
{
1522-
if (serialized.renderPipelineSettings.supportRayTracing.boolValue)
1523-
DisplayRayTracingSupportBox();
1524-
}
15251523
--EditorGUI.indentLevel;
15261524
}
15271525

@@ -1601,6 +1599,9 @@ static void Drawer_SectionMaterialUnsorted(SerializedHDRenderPipelineAsset seria
16011599
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportDistortion, Styles.supportDistortion);
16021600

16031601
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportSubsurfaceScattering, Styles.supportedSSSContent);
1602+
if (serialized.renderPipelineSettings.supportSubsurfaceScattering.boolValue)
1603+
HDEditorUtils.ShowPlatformPerformanceWarning(BuildTarget.Switch2, "Subsurface Scattering");
1604+
16041605
using (new EditorGUI.DisabledScope(serialized.renderPipelineSettings.supportSubsurfaceScattering.hasMultipleDifferentValues
16051606
|| !serialized.renderPipelineSettings.supportSubsurfaceScattering.boolValue))
16061607
{

Packages/com.unity.render-pipelines.high-definition/Editor/Wizard/HDWizard.Configuration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Entry[] BuildEntryList()
204204
});
205205

206206
var currentBuildTarget = CalculateSelectedBuildTarget();
207-
if ((currentBuildTarget == BuildTarget.PS5) || (currentBuildTarget == BuildTarget.GameCoreXboxSeries))
207+
if ((currentBuildTarget == BuildTarget.PS5) || (currentBuildTarget == BuildTarget.GameCoreXboxSeries) || (currentBuildTarget == BuildTarget.Switch2))
208208
{
209209
entryList.AddRange(new[]
210210
{

0 commit comments

Comments
 (0)