浏览代码
Merge pull request #1243 from Unity-Technologies/lw/shader-keywords-stripping
Merge pull request #1243 from Unity-Technologies/lw/shader-keywords-stripping
Lw/shader keywords stripping/main
GitHub
7 年前
当前提交
9aa25b18
共有 30 个文件被更改,包括 455 次插入 和 138 次删除
-
4ScriptableRenderPipeline/Core/CoreRP/Utilities/CoreUtils.cs
-
63ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineAsset.cs
-
102ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightAssetEditor.cs
-
3ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/lightweightPBRExtraPasses.template
-
3ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/lightweightPBRForwardPass.template
-
1ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/lightweightUnlitExtraPasses.template
-
1ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderGraph/lightweightUnlitPass.template
-
31ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
-
70ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightShadowPass.cs
-
11ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Shadows.hlsl
-
1ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightBlit.shader
-
3ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightCopyDepth.shader
-
1ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightSampling.shader
-
1ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightScreenSpaceShadows.shader
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandard.shader
-
3ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticles.shader
-
2ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticlesSimpleLighting.shader
-
3ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticlesUnlit.shader
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardSimpleLighting.shader
-
1ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardUnlit.shader
-
7ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightStandardTerrain.shader
-
5ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightStandardTerrainAddPass.shader
-
6ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightStandardTerrainBase.shader
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightWavingGrass.shader
-
9ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Terrain/LightweightWavingGrassBillboard.shader
-
13Tests/GraphicsTests/RenderPipeline/LightweightPipeline/LightweightPipelineAsset.asset
-
134ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderPreprocessor.cs
-
11ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/ShaderPreprocessor.cs.meta
-
66ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs
-
11ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs.meta
|
|||
//#define LOG_VARIANTS
|
|||
//#define LOG_ONLY_LWRP_VARIANTS
|
|||
|
|||
using System.Collections.Generic; |
|||
using UnityEditor.Build; |
|||
using UnityEditor.Rendering; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Experimental.Rendering.LightweightPipeline; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
public class ShaderPreprocessor : IPreprocessShaders |
|||
{ |
|||
#if LOG_VARIANTS
|
|||
int m_TotalVariantsInputCount; |
|||
int m_TotalVariantsOutputCount; |
|||
#endif
|
|||
|
|||
// Multiple callback may be implemented.
|
|||
// The first one executed is the one where callbackOrder is returning the smallest number.
|
|||
public int callbackOrder { get { return 0; } } |
|||
|
|||
bool StripUnusedShader(PipelineCapabilities capabilities, Shader shader) |
|||
{ |
|||
if (shader.name.Contains("Debug")) |
|||
return true; |
|||
|
|||
if (shader.name.Contains("HDRenderPipeline")) |
|||
return true; |
|||
|
|||
if (!CoreUtils.HasFlag(capabilities, PipelineCapabilities.DirectionalShadows) && |
|||
shader.name.Contains("ScreenSpaceShadows")) |
|||
return true; |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool StripUnusedPass(PipelineCapabilities capabilities, ShaderSnippetData snippetData) |
|||
{ |
|||
if (snippetData.passType == PassType.Meta) |
|||
return true; |
|||
|
|||
if (snippetData.passType == PassType.ShadowCaster) |
|||
if (!CoreUtils.HasFlag(capabilities, PipelineCapabilities.DirectionalShadows) && !CoreUtils.HasFlag(capabilities, PipelineCapabilities.LocalShadows)) |
|||
return true; |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool StripUnusedVariant(PipelineCapabilities capabilities, ShaderCompilerData compilerData) |
|||
{ |
|||
if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.AdditionalLights) && |
|||
!CoreUtils.HasFlag(capabilities, PipelineCapabilities.AdditionalLights)) |
|||
return true; |
|||
|
|||
if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.VertexLights) && |
|||
!CoreUtils.HasFlag(capabilities, PipelineCapabilities.VertexLights)) |
|||
return true; |
|||
|
|||
if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.DirectionalShadows) && |
|||
!CoreUtils.HasFlag(capabilities, PipelineCapabilities.DirectionalShadows)) |
|||
return true; |
|||
|
|||
if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.LocalShadows) && |
|||
!CoreUtils.HasFlag(capabilities, PipelineCapabilities.LocalShadows)) |
|||
return true; |
|||
|
|||
if (compilerData.shaderKeywordSet.IsEnabled(LightweightKeywords.SoftShadows) && |
|||
!CoreUtils.HasFlag(capabilities, PipelineCapabilities.SoftShadows)) |
|||
return true; |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool StripUnused(PipelineCapabilities capabilities, Shader shader, ShaderSnippetData snippetData, ShaderCompilerData compilerData) |
|||
{ |
|||
if (StripUnusedShader(capabilities, shader)) |
|||
return true; |
|||
|
|||
if (StripUnusedPass(capabilities, snippetData)) |
|||
return true; |
|||
|
|||
if (StripUnusedVariant(capabilities, compilerData)) |
|||
return true; |
|||
|
|||
return false; |
|||
} |
|||
|
|||
#if LOG_VARIANTS
|
|||
void LogVariants(Shader shader, ShaderSnippetData snippetData, int prevVariantsCount, int currVariantsCount) |
|||
{ |
|||
#if LOG_ONLY_LWRP_VARIANTS
|
|||
if (shader.name.Contains("LightweightPipeline")) |
|||
#endif
|
|||
{ |
|||
float percentageCurrent = (float)currVariantsCount / (float)prevVariantsCount * 100f; |
|||
float percentageTotal = (float)m_TotalVariantsOutputCount / (float)m_TotalVariantsInputCount * 100f; |
|||
|
|||
string result = string.Format("STRIPPING: {0} ({1} pass) ({2}) -" + |
|||
" Remaining shader variants = {3}/{4} = {5}% - Total = {6}/{7} = {8}%", |
|||
shader.name, snippetData.passName, snippetData.shaderType.ToString(), currVariantsCount, |
|||
prevVariantsCount, percentageCurrent, m_TotalVariantsOutputCount, m_TotalVariantsInputCount, |
|||
percentageTotal); |
|||
Debug.Log(result); |
|||
} |
|||
} |
|||
|
|||
#endif
|
|||
|
|||
public void OnProcessShader(Shader shader, ShaderSnippetData snippetData, IList<ShaderCompilerData> compilerDataList) |
|||
{ |
|||
PipelineCapabilities capabilities = UnityEngine.Experimental.Rendering.LightweightPipeline.LightweightPipeline.GetPipelineCapabilities(); |
|||
int prevVariantCount = compilerDataList.Count; |
|||
|
|||
for (int i = 0; i < compilerDataList.Count; ++i) |
|||
{ |
|||
if (StripUnused(capabilities, shader, snippetData, compilerDataList[i])) |
|||
{ |
|||
compilerDataList.RemoveAt(i); |
|||
--i; |
|||
} |
|||
} |
|||
|
|||
#if LOG_VARIANTS
|
|||
m_TotalVariantsInputCount += prevVariantCount; |
|||
m_TotalVariantsOutputCount += compilerDataList.Count; |
|||
|
|||
LogVariants(shader, snippetData, prevVariantCount, compilerDataList.Count); |
|||
#endif
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9f7bf504ded5bcb48835f194831914c8 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.LightweightPipeline |
|||
{ |
|||
[Flags] |
|||
public enum PipelineCapabilities |
|||
{ |
|||
AdditionalLights = (1 << 0), |
|||
VertexLights = (1 << 1), |
|||
DirectionalShadows = (1 << 2), |
|||
LocalShadows = (1 << 3), |
|||
SoftShadows = (1 << 4), |
|||
} |
|||
|
|||
public class LightweightKeywords |
|||
{ |
|||
public static readonly string AdditionalLightsText = "_ADDITIONAL_LIGHTS"; |
|||
public static readonly string VertexLightsText = "_VERTEX_LIGHTS"; |
|||
public static readonly string MixedLightingSubtractiveText = "_MIXED_LIGHTING_SUBTRACTIVE"; |
|||
public static readonly string MainLightCookieText = "_MAIN_LIGHT_COOKIE"; |
|||
public static readonly string DirectionalShadowsText = "_SHADOWS_ENABLED"; |
|||
public static readonly string LocalShadowsText = "_LOCAL_SHADOWS_ENABLED"; |
|||
public static readonly string SoftShadowsText = "_SHADOWS_SOFT"; |
|||
public static readonly string CascadeShadowsText = "_SHADOWS_CASCADE"; |
|||
|
|||
public static readonly ShaderKeyword AdditionalLights = new ShaderKeyword(AdditionalLightsText); |
|||
public static readonly ShaderKeyword VertexLights = new ShaderKeyword(VertexLightsText); |
|||
public static readonly ShaderKeyword MixedLightingSubtractive = new ShaderKeyword(MixedLightingSubtractiveText); |
|||
public static readonly ShaderKeyword MainLightCookie = new ShaderKeyword(MainLightCookieText); |
|||
public static readonly ShaderKeyword DirectionalShadows = new ShaderKeyword(DirectionalShadowsText); |
|||
public static readonly ShaderKeyword LocalShadows = new ShaderKeyword(LocalShadowsText); |
|||
public static readonly ShaderKeyword SoftShadows = new ShaderKeyword(SoftShadowsText); |
|||
} |
|||
|
|||
public partial class LightweightPipeline |
|||
{ |
|||
static PipelineCapabilities s_PipelineCapabilities; |
|||
|
|||
public static PipelineCapabilities GetPipelineCapabilities() |
|||
{ |
|||
return s_PipelineCapabilities; |
|||
} |
|||
|
|||
static void SetPipelineCapabilities(LightweightPipelineAsset pipelineAsset) |
|||
{ |
|||
s_PipelineCapabilities = 0U; |
|||
|
|||
if (pipelineAsset.MaxPixelLights > 1 || pipelineAsset.SupportsVertexLight) |
|||
s_PipelineCapabilities |= PipelineCapabilities.AdditionalLights; |
|||
|
|||
if (pipelineAsset.SupportsVertexLight) |
|||
s_PipelineCapabilities |= PipelineCapabilities.VertexLights; |
|||
|
|||
if (pipelineAsset.SupportsDirectionalShadows) |
|||
s_PipelineCapabilities |= PipelineCapabilities.DirectionalShadows; |
|||
|
|||
if (pipelineAsset.SupportsLocalShadows) |
|||
s_PipelineCapabilities |= PipelineCapabilities.LocalShadows; |
|||
|
|||
bool anyShadows = pipelineAsset.SupportsDirectionalShadows || pipelineAsset.SupportsLocalShadows; |
|||
if (pipelineAsset.SupportsSoftShadows && anyShadows) |
|||
s_PipelineCapabilities |= PipelineCapabilities.SoftShadows; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d973de1eba2f6934e9c31429e8e40c09 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue