Skip to content

Commit c6073c3

Browse files
laylaarabEvergreen
authored andcommitted
Revert fix for performance regression caused by incorrect Meta pass stripping
1 parent 32c9b34 commit c6073c3

File tree

7 files changed

+7
-146
lines changed

7 files changed

+7
-146
lines changed

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

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using UnityEditor.SceneManagement;
43
using UnityEngine;
54
using UnityEngine.Rendering;
65
using UnityEngine.Rendering.HighDefinition;
@@ -17,7 +16,6 @@ internal class HDRPBuildData : IDisposable
1716
public List<HDRenderPipelineAsset> renderPipelineAssets { get; private set; } = new List<HDRenderPipelineAsset>();
1817
public bool playerNeedRaytracing { get; private set; }
1918
public bool stripDebugVariants { get; private set; } = true;
20-
public bool dynamicLightmapsUsed { get; private set; }
2119
public bool waterDecalMaskAndCurrent { get; private set; }
2220
public Dictionary<EntityId, ComputeShader> rayTracingComputeShaderCache { get; private set; } = new();
2321
public Dictionary<EntityId, ComputeShader> computeShaderCache { get; private set; } = new();
@@ -71,43 +69,13 @@ public HDRPBuildData(BuildTarget buildTarget, bool isDevelopmentBuild)
7169
m_Instance = this;
7270
}
7371

74-
public void SetDynamicLightmapsUsedInBuildScenes()
75-
{
76-
dynamicLightmapsUsed = DynamicLightmapsUsedInBuildScenes();
77-
}
78-
79-
static bool DynamicLightmapsUsedInBuildScenes()
80-
{
81-
var originalSetup = EditorSceneManager.GetSceneManagerSetup();
82-
83-
bool dynamicLightmapsUsed = false;
84-
foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
85-
{
86-
if (!scene.enabled) continue;
87-
88-
EditorSceneManager.OpenScene(scene.path, OpenSceneMode.Single);
89-
90-
if (Lightmapping.HasDynamicGILightmapTextures())
91-
{
92-
dynamicLightmapsUsed = true;
93-
break;
94-
}
95-
}
96-
97-
if (originalSetup.Length > 0)
98-
EditorSceneManager.RestoreSceneManagerSetup(originalSetup);
99-
100-
return dynamicLightmapsUsed;
101-
}
102-
10372
public void Dispose()
10473
{
10574
renderPipelineAssets?.Clear();
10675
rayTracingComputeShaderCache?.Clear();
10776
computeShaderCache?.Clear();
10877
playerNeedRaytracing = false;
10978
stripDebugVariants = true;
110-
dynamicLightmapsUsed = false;
11179
waterDecalMaskAndCurrent = false;
11280
buildingPlayerForHDRenderPipeline = false;
11381
runtimeShaders = null;

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ public void OnPreprocessBuild(BuildReport report)
3333
bool isDevelopmentBuild = (report.summary.options & BuildOptions.Development) != 0;
3434
m_BuildData = new HDRPBuildData(EditorUserBuildSettings.activeBuildTarget, isDevelopmentBuild);
3535

36-
// Since the HDRPBuildData instance is used in a lot of places, doing this check here ensures that it is done before the build starts.
37-
m_BuildData.SetDynamicLightmapsUsedInBuildScenes();
38-
3936
if (m_BuildData.buildingPlayerForHDRenderPipeline)
4037
{
4138
// Now that we know that we are on HDRP we need to make sure everything is correct, otherwise we break the build.

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using UnityEditor.SceneManagement;
21
using UnityEngine;
32
using UnityEngine.Rendering;
43
using UnityEngine.Rendering.HighDefinition;
@@ -71,10 +70,8 @@ protected override bool DoShadersStripper(HDRenderPipelineAsset hdrpAsset, Shade
7170
// Remove editor only pass
7271
bool isSceneSelectionPass = snippet.passName == "SceneSelectionPass";
7372
bool isScenePickingPass = snippet.passName == "ScenePickingPass";
74-
75-
bool isEnlightenSupported = SupportedRenderingFeatures.active.enlighten && ((int)SupportedRenderingFeatures.active.lightmapBakeTypes | (int)LightmapBakeType.Realtime) != 0;
76-
bool metaPassUnused = (snippet.passName == "META") && (!isEnlightenSupported || !HDRPBuildData.instance.dynamicLightmapsUsed);
77-
73+
bool metaPassUnused = (snippet.passName == "META") && (SupportedRenderingFeatures.active.enlighten == false ||
74+
((int)SupportedRenderingFeatures.active.lightmapBakeTypes | (int)LightmapBakeType.Realtime) == 0);
7875
bool editorVisualization = inputData.shaderKeywordSet.IsEnabled(m_EditorVisualization);
7976
if (isSceneSelectionPass || isScenePickingPass || metaPassUnused || editorVisualization)
8077
return true;

Packages/com.unity.render-pipelines.universal/Editor/ShaderBuildPreprocessor.cs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using UnityEditor.Build;
44
using UnityEditor.Build.Reporting;
5-
using UnityEditor.SceneManagement;
65
using UnityEngine;
76
using UnityEngine.Rendering.Universal;
87
using UnityEngine.Rendering;
@@ -134,7 +133,6 @@ class ShaderBuildPreprocessor : IPreprocessBuildWithReport, IPostprocessBuildWit
134133
public static bool s_Strip2DPasses;
135134
public static bool s_UseSoftShadowQualityLevelKeywords;
136135
public static bool s_StripXRVariants;
137-
public static bool s_UsesDynamicLightmaps;
138136

139137
public static List<ShaderFeatures> supportedFeaturesList
140138
{
@@ -433,27 +431,6 @@ private static void GetEveryShaderFeatureAndUpdateURPAssets(List<ShaderFeatures>
433431
// The path for gathering shader features for normal shader stripping
434432
private static void HandleEnabledShaderStripping()
435433
{
436-
var originalSetup = EditorSceneManager.GetSceneManagerSetup();
437-
438-
bool dynamicLightmapsUsed = false;
439-
foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
440-
{
441-
if (!scene.enabled) continue;
442-
443-
EditorSceneManager.OpenScene(scene.path, OpenSceneMode.Single);
444-
445-
if (Lightmapping.HasDynamicGILightmapTextures())
446-
{
447-
dynamicLightmapsUsed = true;
448-
break;
449-
}
450-
}
451-
452-
if (originalSetup.Length > 0)
453-
EditorSceneManager.RestoreSceneManagerSetup(originalSetup);
454-
455-
s_UsesDynamicLightmaps = dynamicLightmapsUsed;
456-
457434
s_Strip2DPasses = true;
458435
using (ListPool<UniversalRenderPipelineAsset>.Get(out List<UniversalRenderPipelineAsset> urpAssets))
459436
{

Packages/com.unity.render-pipelines.universal/Editor/ShaderScriptableStripper.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ internal interface IShaderScriptableStrippingData
3131
public bool stripUnusedVariants { get; set; }
3232
public bool stripUnusedPostProcessingVariants { get; set; }
3333
public bool stripUnusedXRVariants { get; set; }
34-
public bool usesDynamicLightmaps { get; set; }
3534

3635
public Shader shader { get; set; }
3736
public ShaderType shaderType { get; set; }
@@ -70,7 +69,6 @@ internal struct StrippingData : IShaderScriptableStrippingData
7069
public bool stripUnusedVariants { get; set; }
7170
public bool stripUnusedPostProcessingVariants { get; set; }
7271
public bool stripUnusedXRVariants { get; set; }
73-
public bool usesDynamicLightmaps { get; set; }
7472

7573
public Shader shader { get; set; }
7674
public ShaderType shaderType { get => passData.shaderType; set{} }
@@ -1057,17 +1055,15 @@ internal bool StripUnusedPass_2D(ref IShaderScriptableStrippingData strippingDat
10571055

10581056
internal bool StripUnusedPass_Meta(ref IShaderScriptableStrippingData strippingData)
10591057
{
1060-
bool isEnlightenSupported = SupportedRenderingFeatures.active.enlighten && ((int)SupportedRenderingFeatures.active.lightmapBakeTypes | (int)LightmapBakeType.Realtime) != 0;
1061-
1062-
// Meta pass is needed in the player for Enlighten Precomputed Realtime GI albedo and emission, as well as Surface Cache Global Illumination.
1058+
// Meta pass is needed in the player for Enlighten Precomputed Realtime GI albedo and emission.
10631059
if (strippingData.passType == PassType.Meta)
10641060
{
1065-
if ((!isEnlightenSupported || !strippingData.usesDynamicLightmaps)
1066-
1061+
if (SupportedRenderingFeatures.active.enlighten == false
1062+
|| ((int)SupportedRenderingFeatures.active.lightmapBakeTypes | (int)LightmapBakeType.Realtime) == 0
10671063
#if SURFACE_CACHE
1068-
&& !strippingData.IsShaderFeatureEnabled(ShaderFeatures.SurfaceCache)
1064+
|| !strippingData.IsShaderFeatureEnabled(ShaderFeatures.SurfaceCache)
10691065
#endif
1070-
)
1066+
)
10711067
return true;
10721068
}
10731069
return false;
@@ -1233,7 +1229,6 @@ public bool CanRemoveVariant([DisallowNull] Shader shader, ShaderSnippetData pas
12331229
stripUnusedVariants = ShaderBuildPreprocessor.s_StripUnusedVariants,
12341230
stripUnusedPostProcessingVariants = ShaderBuildPreprocessor.s_StripUnusedPostProcessingVariants,
12351231
stripUnusedXRVariants = ShaderBuildPreprocessor.s_StripXRVariants,
1236-
usesDynamicLightmaps = ShaderBuildPreprocessor.s_UsesDynamicLightmaps,
12371232
IsHDRDisplaySupportEnabled = PlayerSettings.allowHDRDisplaySupport,
12381233
shader = shader,
12391234
passData = passData,

Packages/com.unity.render-pipelines.universal/Tests/Editor/ShaderScriptableStripperTests.cs

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ internal struct TestStrippingData : IShaderScriptableStrippingData
2929
public bool stripUnusedVariants { get; set; }
3030
public bool stripUnusedPostProcessingVariants { get; set; }
3131
public bool stripUnusedXRVariants { get; set; }
32-
public bool usesDynamicLightmaps { get; set; }
3332
public bool IsHDRDisplaySupportEnabled { get; set; }
3433
public bool IsRenderCompatibilityMode { get; set; }
3534

@@ -227,7 +226,6 @@ public void TestStripUnusedPass(string shaderName)
227226
helper.IsFalse(helper.stripper.StripUnusedPass(ref helper.data));
228227

229228
TestStripUnusedPass_2D(shader);
230-
TestStripUnusedPass_Meta(shader);
231229
TestStripUnusedPass_XR(shader);
232230
TestStripUnusedPass_ShadowCaster(shader);
233231
TestStripUnusedPass_Decals(shader);
@@ -250,76 +248,6 @@ public void TestStripUnusedPass_2D(Shader shader)
250248
helper.IsTrue(helper.stripper.StripUnusedPass(ref helper.data));
251249
}
252250

253-
public void TestStripUnusedPass_Meta(Shader shader)
254-
{
255-
TestHelper helper;
256-
257-
bool enlightenPrev = SupportedRenderingFeatures.active.enlighten;
258-
LightmapBakeType lightmapBakeTypesPrev = SupportedRenderingFeatures.active.lightmapBakeTypes;
259-
260-
SupportedRenderingFeatures.active.enlighten = false;
261-
SupportedRenderingFeatures.active.lightmapBakeTypes = LightmapBakeType.Mixed | LightmapBakeType.Baked;
262-
263-
helper = new TestHelper(shader, ShaderFeatures.None);
264-
helper.data.usesDynamicLightmaps = false;
265-
helper.data.passType = PassType.Meta;
266-
helper.IsTrue(helper.stripper.StripUnusedPass_Meta(ref helper.data));
267-
helper.IsTrue(helper.stripper.StripUnusedPass(ref helper.data));
268-
269-
SupportedRenderingFeatures.active.enlighten = true;
270-
SupportedRenderingFeatures.active.lightmapBakeTypes = LightmapBakeType.Mixed | LightmapBakeType.Baked;
271-
helper = new TestHelper(shader, ShaderFeatures.None);
272-
helper.data.usesDynamicLightmaps = false;
273-
helper.data.passType = PassType.Meta;
274-
helper.IsTrue(helper.stripper.StripUnusedPass_Meta(ref helper.data));
275-
helper.IsTrue(helper.stripper.StripUnusedPass(ref helper.data));
276-
277-
SupportedRenderingFeatures.active.enlighten = false;
278-
SupportedRenderingFeatures.active.lightmapBakeTypes = LightmapBakeType.Realtime | LightmapBakeType.Mixed | LightmapBakeType.Baked;
279-
helper = new TestHelper(shader, ShaderFeatures.None);
280-
helper.data.usesDynamicLightmaps = false;
281-
helper.data.passType = PassType.Meta;
282-
helper.IsTrue(helper.stripper.StripUnusedPass_Meta(ref helper.data));
283-
helper.IsTrue(helper.stripper.StripUnusedPass(ref helper.data));
284-
285-
SupportedRenderingFeatures.active.enlighten = false;
286-
SupportedRenderingFeatures.active.lightmapBakeTypes = LightmapBakeType.Mixed | LightmapBakeType.Baked;
287-
helper = new TestHelper(shader, ShaderFeatures.None);
288-
helper.data.usesDynamicLightmaps = true;
289-
helper.data.passType = PassType.Meta;
290-
helper.IsTrue(helper.stripper.StripUnusedPass_Meta(ref helper.data));
291-
helper.IsTrue(helper.stripper.StripUnusedPass(ref helper.data));
292-
293-
SupportedRenderingFeatures.active.enlighten = true;
294-
SupportedRenderingFeatures.active.lightmapBakeTypes = LightmapBakeType.Realtime | LightmapBakeType.Mixed | LightmapBakeType.Baked;
295-
helper = new TestHelper(shader, ShaderFeatures.None);
296-
helper.data.usesDynamicLightmaps = true;
297-
helper.data.passType = PassType.Meta;
298-
helper.IsFalse(helper.stripper.StripUnusedPass_Meta(ref helper.data));
299-
helper.IsFalse(helper.stripper.StripUnusedPass(ref helper.data));
300-
301-
#if SURFACE_CACHE
302-
SupportedRenderingFeatures.active.enlighten = false;
303-
SupportedRenderingFeatures.active.lightmapBakeTypes = LightmapBakeType.Mixed | LightmapBakeType.Baked;
304-
helper = new TestHelper(shader, ShaderFeatures.SurfaceCache);
305-
helper.data.usesDynamicLightmaps = false;
306-
helper.data.passType = PassType.Meta;
307-
helper.IsFalse(helper.stripper.StripUnusedPass_Meta(ref helper.data));
308-
helper.IsFalse(helper.stripper.StripUnusedPass(ref helper.data));
309-
310-
SupportedRenderingFeatures.active.enlighten = true;
311-
SupportedRenderingFeatures.active.lightmapBakeTypes = LightmapBakeType.Realtime | LightmapBakeType.Mixed | LightmapBakeType.Baked;
312-
helper = new TestHelper(shader, ShaderFeatures.SurfaceCache);
313-
helper.data.usesDynamicLightmaps = true;
314-
helper.data.passType = PassType.Meta;
315-
helper.IsFalse(helper.stripper.StripUnusedPass_Meta(ref helper.data));
316-
helper.IsFalse(helper.stripper.StripUnusedPass(ref helper.data));
317-
#endif
318-
319-
// Restore previous SupportedRenderingFeatures values
320-
SupportedRenderingFeatures.active.enlighten = enlightenPrev;
321-
SupportedRenderingFeatures.active.lightmapBakeTypes = lightmapBakeTypesPrev;
322-
}
323251

324252
public void TestStripUnusedPass_XR(Shader shader)
325253
{

Packages/com.unity.render-pipelines.universal/Tests/Editor/ShaderStripToolTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ internal struct TestStrippingData : IShaderScriptableStrippingData
3030
public bool stripUnusedVariants { get; set; }
3131
public bool stripUnusedPostProcessingVariants { get; set; }
3232
public bool stripUnusedXRVariants { get; set; }
33-
public bool usesDynamicLightmaps { get; set; }
3433

3534
public Shader shader { get; set; }
3635
public ShaderType shaderType { get; set; }

0 commit comments

Comments
 (0)