Skip to content

Commit 4c2ee17

Browse files
laylaarabEvergreen
authored andcommitted
Provide a way for Surface Cache to be considered when stripping the meta pass from builds
1 parent f177a63 commit 4c2ee17

2 files changed

Lines changed: 41 additions & 14 deletions

File tree

Packages/com.unity.render-pipelines.universal/Editor/BuildProcessors/GraphicsSettingsStrippers/SurfaceCacheGIStripper.cs

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,32 @@ namespace UnityEditor.Rendering
1010
{
1111
static class SurfaceCacheStripperUtility
1212
{
13-
static bool IsSurfaceCacheEnabled(List<UniversalRenderPipelineAsset> urpAssets)
13+
static bool IsSurfaceCacheEnabled(UniversalRenderPipelineAsset urpAsset)
1414
{
15-
foreach (var urpAssetForBuild in urpAssets)
15+
foreach (var rendererData in urpAsset.m_RendererDataList)
1616
{
17-
foreach (var rendererData in urpAssetForBuild.m_RendererDataList)
17+
if(rendererData is not UniversalRendererData)
18+
continue;
19+
20+
foreach (var rendererFeature in rendererData.rendererFeatures)
1821
{
19-
if(rendererData is not UniversalRendererData)
20-
continue;
21-
22-
foreach (var rendererFeature in rendererData.rendererFeatures)
23-
{
24-
if (rendererFeature is SurfaceCacheGIRendererFeature { isActive: true })
25-
return true;
26-
}
22+
if (rendererFeature is SurfaceCacheGIRendererFeature { isActive: true })
23+
return true;
2724
}
2825
}
2926
return false;
3027
}
3128

29+
static bool IsSurfaceCacheEnabled(List<UniversalRenderPipelineAsset> urpAssets)
30+
{
31+
foreach (var urpAssetForBuild in urpAssets)
32+
{
33+
if (IsSurfaceCacheEnabled(urpAssetForBuild))
34+
return true;
35+
}
36+
return false;
37+
}
38+
3239
internal static bool CanRemoveSurfaceCacheSettings(List<UniversalRenderPipelineAsset> urpAssets)
3340
{
3441
if (GraphicsSettings.TryGetRenderPipelineSettings<URPShaderStrippingSetting>(out var urpShaderStrippingSettings) && !urpShaderStrippingSettings.stripUnusedVariants)
@@ -39,6 +46,26 @@ internal static bool CanRemoveSurfaceCacheSettings(List<UniversalRenderPipelineA
3946

4047
return true;
4148
}
49+
50+
// Required by native side for meta pass stripping.
51+
[UnityEngine.Scripting.Preserve]
52+
internal static bool IsSurfaceCacheEnabledForBuild()
53+
{
54+
// Check if we're building with URP and if Surface Cache is enabled in the build assets
55+
if (URPBuildData.instance.buildingPlayerForUniversalRenderPipeline)
56+
{
57+
return IsSurfaceCacheEnabled(URPBuildData.instance.renderPipelineAssets);
58+
}
59+
60+
// Fallback to current render pipeline asset if not in a build context
61+
var currentRP = UnityEngine.Rendering.GraphicsSettings.currentRenderPipeline;
62+
if (currentRP is UniversalRenderPipelineAsset urpAsset)
63+
{
64+
return IsSurfaceCacheEnabled(urpAsset);
65+
}
66+
67+
return false;
68+
}
4269
}
4370

4471
class UniversalSurfaceCacheIntegrationStripper : IRenderPipelineGraphicsSettingsStripper<UnityEngine.Rendering.Universal.SurfaceCacheRenderPipelineResourceSet>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,13 +1088,13 @@ internal bool StripUnusedPass_2D(ref IShaderScriptableStrippingData strippingDat
10881088

10891089
internal bool StripUnusedPass_Meta(ref IShaderScriptableStrippingData strippingData)
10901090
{
1091-
// Meta pass is needed in the player for Enlighten Precomputed Realtime GI albedo and emission.
1091+
// Meta pass is needed for Enlighten and Surface Cache realtime GI systems.
10921092
if (strippingData.passType == PassType.Meta)
10931093
{
10941094
if (SupportedRenderingFeatures.active.enlighten == false
1095-
|| ((int)SupportedRenderingFeatures.active.lightmapBakeTypes | (int)LightmapBakeType.Realtime) == 0
1095+
&& ((int)SupportedRenderingFeatures.active.lightmapBakeTypes | (int)LightmapBakeType.Realtime) == 0
10961096
#if SURFACE_CACHE
1097-
|| !strippingData.IsShaderFeatureEnabled(ShaderFeatures.SurfaceCache)
1097+
&& !strippingData.IsShaderFeatureEnabled(ShaderFeatures.SurfaceCache)
10981098
#endif
10991099
)
11001100
return true;

0 commit comments

Comments
 (0)