Skip to content

Commit 4954ec9

Browse files
joshua-davisEvergreen
authored andcommitted
UUM-69319 Fixed shader graph built-in target variants to get stripped…
[Jira](https://jira.unity3d.com/browse/UUM-69319) Fixed shader graph built-in pipeline variants not getting stripped when an SRP is active.
1 parent 9553014 commit 4954ec9

File tree

1 file changed

+56
-6
lines changed

1 file changed

+56
-6
lines changed

Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/Editor/ShaderPreprocessor.cs

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
using System;
22
using System.Collections.Generic;
3-
using UnityEditor;
3+
using System.Diagnostics.CodeAnalysis;
44
using UnityEditor.Build;
55
using UnityEditor.Build.Reporting;
66
using UnityEditor.Rendering.BuiltIn.ShaderGraph;
77
using UnityEngine;
8-
using UnityEngine.Profiling;
98
using UnityEngine.Rendering;
109

1110
namespace UnityEditor.Rendering.BuiltIn
@@ -89,6 +88,13 @@ internal class ShaderPreprocessor : IPreprocessShaders
8988
ShaderKeyword m_ScreenSpaceOcclusion = new ShaderKeyword(ShaderKeywordStrings.ScreenSpaceOcclusion);
9089
ShaderKeyword m_EditorVisualization = new ShaderKeyword(ShaderKeywordStrings.EDITOR_VISUALIZATION);
9190
ShaderTagId m_ShaderGraphShaderTag = new ShaderTagId("ShaderGraphShader");
91+
ShaderTagId m_ShaderGraphTargetIdTag = new ShaderTagId("ShaderGraphTargetId");
92+
93+
static List<string> SubTargetNames = new List<string>
94+
{
95+
typeof(BuiltInLitSubTarget).Name,
96+
typeof(BuiltInUnlitSubTarget).Name,
97+
};
9298

9399
int m_TotalVariantsInputCount;
94100
int m_TotalVariantsOutputCount;
@@ -115,7 +121,42 @@ bool IsShaderGraphShader(Shader shader, ShaderSnippetData snippetData)
115121
var shaderGraphTag = serializedSubShader.FindTagValue(m_ShaderGraphShaderTag);
116122
if (shaderGraphTag == ShaderTagId.none)
117123
return false;
118-
return true;
124+
125+
var targetIdTag = serializedSubShader.FindTagValue(m_ShaderGraphTargetIdTag);
126+
if (targetIdTag == ShaderTagId.none)
127+
return false;
128+
129+
var targetIdString = targetIdTag.name;
130+
foreach (var subTargetName in SubTargetNames)
131+
{
132+
if (targetIdString == subTargetName)
133+
return true;
134+
}
135+
return false;
136+
}
137+
138+
private static readonly ShaderTagId s_RenderPipelineShaderTagId = new ShaderTagId("RenderPipeline");
139+
140+
bool IsBiRPShaderGraphVariant([DisallowNull] Shader shader, ShaderSnippetData shaderVariant)
141+
{
142+
if (!IsShaderGraphShader(shader, shaderVariant))
143+
return false;
144+
145+
var shaderData = ShaderUtil.GetShaderData(shader);
146+
if (shaderData == null)
147+
return false;
148+
149+
int subshaderIndex = (int)shaderVariant.pass.SubshaderIndex;
150+
if (subshaderIndex < 0 || subshaderIndex >= shader.subshaderCount)
151+
return false;
152+
153+
var subShader = shaderData.GetSerializedSubshader(subshaderIndex);
154+
if (subShader == null)
155+
return false;
156+
157+
// A non-existing or empty "RenderPipeline" tag means it's built-in.
158+
var shaderTag = subShader.FindTagValue(s_RenderPipelineShaderTagId);
159+
return string.IsNullOrEmpty(shaderTag.name);
119160
}
120161

121162
bool StripUnusedPass(ShaderFeatures features, ShaderSnippetData snippetData)
@@ -319,17 +360,26 @@ public void OnProcessShader(Shader shader, ShaderSnippetData snippetData, IList<
319360
Profiler.BeginSample(k_ProcessShaderTag);
320361
#endif
321362

322-
// We only want to perform shader variant stripping if the built-in render pipeline
323-
// is the active render pipeline (i.e., there is no SRP asset in place).
324363
RenderPipelineAsset rpAsset = GraphicsSettings.currentRenderPipeline;
325-
if (rpAsset != null || compilerDataList == null || compilerDataList.Count == 0)
364+
if (compilerDataList == null || compilerDataList.Count == 0)
326365
return;
327366

328367
double stripTimeMs = 0.0;
329368
int prevVariantCount = compilerDataList.Count;
330369
using (TimedScope.FromRef(ref stripTimeMs))
331370
{
332371
var inputShaderVariantCount = compilerDataList.Count;
372+
373+
// If the active render pipeline is not built-in, we want to strip all BiRP SG variants
374+
// and completely ignore the rest (the other strippers will take care of those).
375+
if (rpAsset != null)
376+
{
377+
if (IsBiRPShaderGraphVariant(shader, snippetData))
378+
inputShaderVariantCount = 0;
379+
else
380+
return;
381+
}
382+
333383
for (int i = 0; i < inputShaderVariantCount;)
334384
{
335385
bool removeInput = true;

0 commit comments

Comments
 (0)