Skip to content

Commit f99d1f3

Browse files
CalChiuEvergreen
authored andcommitted
[UUM-138256] Added shader variant stripping for point sampling upsampling
1 parent f7e8344 commit f99d1f3

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,14 @@ enum ShaderFeatures : long
7373
StencilLODCrossFade = (1L << 50),
7474
DeferredPlus = (1L << 51),
7575
ReflectionProbeAtlas = (1L << 52),
76+
PointSamplingUpsampling = (1L << 53),
7677
#if SURFACE_CACHE
77-
SurfaceCache = (1L << 53),
78+
SurfaceCache = (1L << 54),
7879
#endif
7980
#if URP_SCREEN_SPACE_REFLECTION
80-
ScreenSpaceReflection = (1L << 54),
81+
ScreenSpaceReflection = (1L << 55),
8182
#endif
82-
RenderObjectDepthInputAttachment = (1L << 55),
83+
RenderObjectDepthInputAttachment = (1L << 56),
8384
All = ~0
8485
}
8586

@@ -605,6 +606,9 @@ internal static ShaderFeatures GetSupportedShaderFeaturesFromAsset(
605606
if(urpAsset.allowPostProcessAlphaOutput)
606607
urpAssetShaderFeatures |= ShaderFeatures.AlphaOutput;
607608

609+
if (urpAsset.upscalingFilter == UpscalingFilterSelection.Point)
610+
urpAssetShaderFeatures |= ShaderFeatures.PointSamplingUpsampling;
611+
608612
// Check each renderer & renderer feature
609613
urpAssetShaderFeatures = GetSupportedShaderFeaturesFromRenderers(
610614
ref urpAsset,
@@ -1206,6 +1210,9 @@ ref List<ScreenSpaceAmbientOcclusionSettings> ssaoRendererFeatures
12061210
spd.stripSSAOSampleCountHigh &= ssaoSettings.Samples != ScreenSpaceAmbientOcclusionSettings.AOSampleOption.High;
12071211
}
12081212

1213+
// Upscaling
1214+
spd.stripPointSamplingUpsampling = !IsFeatureEnabled(shaderFeatures, ShaderFeatures.PointSamplingUpsampling);
1215+
12091216
return spd;
12101217
}
12111218

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public bool PassHasKeyword(LocalKeyword keyword)
116116
Shader m_StencilDeferred = Shader.Find("Hidden/Universal Render Pipeline/StencilDeferred");
117117
Shader m_ClusterDeferred = Shader.Find("Hidden/Universal Render Pipeline/ClusterDeferred");
118118
Shader m_UberPostShader = Shader.Find("Hidden/Universal Render Pipeline/UberPost");
119+
Shader m_FinalPostShader = Shader.Find("Hidden/Universal Render Pipeline/FinalPost");
119120
Shader m_HDROutputBlitShader = Shader.Find("Hidden/Universal/BlitHDROverlay");
120121
Shader m_DataDrivenLensFlareShader = Shader.Find("Hidden/Universal Render Pipeline/LensFlareDataDriven");
121122
Shader m_ScreenSpaceLensFlareShader = Shader.Find("Hidden/Universal Render Pipeline/LensFlareScreenSpace");
@@ -201,6 +202,7 @@ public bool PassHasKeyword(LocalKeyword keyword)
201202
LocalKeyword m_ProceduralInstancing;
202203
LocalKeyword m_DepthAsInputAttachment;
203204
LocalKeyword m_DepthAsInputAttachmentMSAA;
205+
LocalKeyword m_PointSampling;
204206

205207
private LocalKeyword TryGetLocalKeyword(Shader shader, string name)
206208
{
@@ -276,6 +278,7 @@ private void InitializeLocalShaderKeywords([DisallowNull] Shader shader)
276278
m_FilmGrain = TryGetLocalKeyword(shader, ShaderKeywordStrings.FilmGrain);
277279
m_SHPerVertex = TryGetLocalKeyword(shader, ShaderKeywordStrings.EVALUATE_SH_VERTEX);
278280
m_SHMixed = TryGetLocalKeyword(shader, ShaderKeywordStrings.EVALUATE_SH_MIXED);
281+
m_PointSampling = TryGetLocalKeyword(shader, ShaderKeywordStrings.PointSampling);
279282

280283
m_Instancing = TryGetLocalKeyword(shader, "INSTANCING_ON");
281284
m_DotsInstancing = TryGetLocalKeyword(shader, "DOTS_INSTANCING_ON");
@@ -866,6 +869,14 @@ internal bool StripUnusedFeatures_CrossFadeLod(ref IShaderScriptableStrippingDat
866869
return !strippingData.IsShaderFeatureEnabled(ShaderFeatures.LODCrossFade);
867870
}
868871

872+
internal bool StripUnusedFeatures_PointSamplingUpsampling(ref IShaderScriptableStrippingData strippingData, ref ShaderStripTool<ShaderFeatures> stripTool)
873+
{
874+
if (strippingData.shader != m_UberPostShader && strippingData.shader != m_FinalPostShader)
875+
return false;
876+
877+
return stripTool.StripMultiCompile(m_PointSampling, ShaderFeatures.PointSamplingUpsampling);
878+
}
879+
869880
internal bool StripUnusedFeatures(ref IShaderScriptableStrippingData strippingData)
870881
{
871882
if (StripUnusedFeatures_DebugDisplay(ref strippingData))
@@ -982,6 +993,9 @@ internal bool StripUnusedFeatures(ref IShaderScriptableStrippingData strippingDa
982993
if (StripUnusedFeatures_RenderObjectDepthInputAttachment(ref strippingData))
983994
return true;
984995

996+
if (StripUnusedFeatures_PointSamplingUpsampling(ref strippingData, ref stripTool))
997+
return true;
998+
985999
return false;
9861000
}
9871001

Packages/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAssetPrefiltering.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ internal enum PrefilteringModeAdditionalLights
219219
[ShaderKeywordFilter.RemoveIf(true, keywordNames: ShaderKeywordStrings.ReflectionProbeAtlas)]
220220
[SerializeField] private bool m_PrefilterReflectionProbeAtlas = false;
221221

222+
// Point Sampling Upscaling (_POINT_SAMPLING)
223+
[ShaderKeywordFilter.RemoveIf(true, keywordNames: ShaderKeywordStrings.PointSampling)]
224+
[SerializeField] private bool m_PrefilterPointSamplingUpsampling = false;
225+
222226
/// <summary>
223227
/// Data used for Shader Prefiltering. Gathered after going through the URP Assets,
224228
/// Renderers and Renderer Features in OnPreprocessBuild() inside ShaderPreprocessor.cs.
@@ -264,6 +268,8 @@ internal struct ShaderPrefilteringData
264268
public bool stripReflectionProbeBoxProjection;
265269
public bool stripReflectionProbeAtlas;
266270

271+
public bool stripPointSamplingUpsampling;
272+
267273
public bool stripScreenSpaceIrradiance;
268274

269275
// Keyword used by the DepthNormalOnly pass to write smoothness into alpha channel for screen space reflections.
@@ -331,6 +337,8 @@ internal void UpdateShaderKeywordPrefiltering(ref ShaderPrefilteringData prefilt
331337
m_PrefilterReflectionProbeBoxProjection = prefilteringData.stripReflectionProbeBoxProjection;
332338
m_PrefilterReflectionProbeAtlas = prefilteringData.stripReflectionProbeAtlas;
333339

340+
m_PrefilterPointSamplingUpsampling = prefilteringData.stripPointSamplingUpsampling;
341+
334342
m_PrefilterScreenSpaceIrradiance = prefilteringData.stripScreenSpaceIrradiance;
335343

336344
m_PrefilterWriteSmoothness = prefilteringData.stripWriteSmoothness;

0 commit comments

Comments
 (0)