bool StripUnusedPass(ShaderFeatures features, ShaderSnippetData snippetData) { // Strip all SRP shader variants if (IsSRPPass(snippetData)) { return(true); } // Meta pass is needed in the player for Enlighten Precomputed Realtime GI albedo and emission. if (snippetData.passType == PassType.Meta) { if (SupportedRenderingFeatures.active.enlighten == false || ((int)SupportedRenderingFeatures.active.lightmapBakeTypes | (int)LightmapBakeType.Realtime) == 0) { return(true); } } if (snippetData.passType == PassType.ShadowCaster) { if (!IsFeatureEnabled(features, ShaderFeatures.MainLightShadows) && !IsFeatureEnabled(features, ShaderFeatures.AdditionalLightShadows)) { return(true); } } return(false); }
public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList <ShaderCompilerData> data) { isShaderStrippingEnabled = EditorPrefs.GetBool("WaveShaderStripping", false); Menu.SetChecked("WaveVR/Enable Shader Stripping", isShaderStrippingEnabled); if (!isShaderStrippingEnabled) { return; } if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android) { Debug.Log("WaveEditorShaderStripping: Stripping Shaders"); List <GraphicsTier> stripTierList = new List <GraphicsTier>(); stripTierList.Add(GraphicsTier.Tier1); stripTierList.Add(GraphicsTier.Tier3); for (int i = data.Count - 1; i >= 0; --i) { if (stripTierList.Contains(data[i].graphicsTier)) { //Debug.Log("WaveEditorShaderStripping: Remove Shader at " + i); data.RemoveAt(i); } } } }
public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList <ShaderCompilerData> inputData) { // Do we have a shader variant stripper function for this shader? VariantStrippingFunc stripperFunc = null; m_StripperFuncs.TryGetValue(shader.name, out stripperFunc); if (stripperFunc == null || inputData.Count == 0) { return; } int inputShaderVariantCount = inputData.Count; ShaderCompilerData workaround = inputData[0]; for (int i = 0; i < inputData.Count; ++i) { ShaderCompilerData input = inputData[i]; if (stripperFunc(shader, snippet, input)) { inputData.RemoveAt(i); i--; } } // Currently if a certain snippet is completely stripped (for example if you remove a whole pass) other passes might get broken // To work around that, we make sure that we always have at least one variant. if (inputData.Count == 0) { inputData.Add(workaround); } }
public void OnProcessShader( Shader shader, ShaderSnippetData snippet, IList <ShaderCompilerData> shaderCompilerData) { #if MANUAL_SHADER_STRIPPING // In development, don't strip debug variants if (EditorUserBuildSettings.development) { return; } for (int i = 0; i < shaderCompilerData.Count; ++i) { bool mustStrip = false; foreach (var kw in m_ExcludedKeywords) { if (shaderCompilerData[i].shaderKeywordSet.IsEnabled(kw)) { mustStrip = true; break; } } if (mustStrip) { shaderCompilerData.RemoveAt(i); --i; } } #endif }
private void AppendShaderInfo(StringBuilder sb, Shader shader, ShaderSnippetData snippet, ShaderCompilerData compilerData) { if (sb.Length == 0) { sb.Append("Shader:" + shader.name).Append("\n"); sb.Append("ShaderType:").Append(snippet.shaderType).Append("\n"). Append("PassName:").Append(snippet.passName).Append("\n"). Append("PassType:").Append(snippet.passType).Append("\n\n"); } var keywords = compilerData.shaderKeywordSet.GetShaderKeywords(); var sortKeywords = new ShaderKeyword[keywords.Length]; for (int i = 0; i < keywords.Length; ++i) { sortKeywords[i] = keywords[i]; } System.Array.Sort(sortKeywords, new SortShaderKeyword()); sb.Append(" Keyword:"); foreach (var keyword in sortKeywords) { sb.Append(keyword.GetKeywordName()).Append(" "); } sb.Append("\n KeywordType:"); foreach (var keyword in sortKeywords) { sb.Append(keyword.GetKeywordType()).Append(" "); } sb.Append("\n").Append("\n"); }
public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList <ShaderCompilerData> inputData) { // This test will also return if we are not using HDRenderPipelineAsset if (m_CurrentHDRPAsset == null || !m_CurrentHDRPAsset.allowShaderVariantStripping) { return; } // Do we have a shader variant stripper function for this shader? VariantStrippingFunc stripperFunc = null; m_StripperFuncs.TryGetValue(shader.name, out stripperFunc); if (stripperFunc == null) { return; } int inputShaderVariantCount = inputData.Count; for (int i = 0; i < inputData.Count; ++i) { ShaderCompilerData input = inputData[i]; if (stripperFunc(m_CurrentHDRPAsset, shader, snippet, input)) { inputData.RemoveAt(i); i--; } } }
public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList <ShaderCompilerData> data) { if (snippet.passType == PassType.ForwardAdd || snippet.passType == PassType.LightPrePassBase || snippet.passType == PassType.LightPrePassFinal || snippet.passType == PassType.Deferred || snippet.passType == PassType.ScriptableRenderPipeline || snippet.passType == PassType.ScriptableRenderPipelineDefaultUnlit || snippet.passType == PassType.Meta || snippet.passType == PassType.MotionVectors) { data.Clear(); return; } s_cache.Clear(); s_cache.AddRange(data); data.Clear(); for (int i = 0; i < s_cache.Count; ++i) { var d = s_cache[i]; for (int j = 0; j < s_uselessKeywords.Length; ++j) { if (d.shaderKeywordSet.IsEnabled(s_uselessKeywords[j])) { continue; } } data.Add(d); } }
public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList <ShaderCompilerData> data) { if (shader.name.StartsWith("Shapes/") == false) { return; // ignore all non-Shapes shaders } // Shapes immediate mode has to force instancing on. // find variants that don't have an instancing counterpart, copy them, and add instancing string GetKeywordsStrWithoutInstancing(ShaderCompilerData set) { return(string.Join(",", set.shaderKeywordSet.GetShaderKeywords() #if UNITY_2019_3_OR_NEWER .Select(ShaderKeyword.GetGlobalKeywordName).Where(a => a != ShaderKeyword.GetGlobalKeywordName(inst)) #else .Select(a => a.GetKeywordName()).Where(a => a != inst.GetKeywordName()) #endif .OrderBy(a => a))); } HashSet <string> thingsWithInstancing = new HashSet <string>(data.Where(x => x.shaderKeywordSet.IsEnabled(inst)).Select(GetKeywordsStrWithoutInstancing)); HashSet <string> thingsWithoutInstancing = new HashSet <string>(data.Where(x => !x.shaderKeywordSet.IsEnabled(inst)).Select(GetKeywordsStrWithoutInstancing)); thingsWithoutInstancing.ExceptWith(thingsWithInstancing); // filter out only the ones missing instancing versions List <ShaderCompilerData> thingsToClone = data.Where(x => !x.shaderKeywordSet.IsEnabled(inst) && thingsWithoutInstancing.Contains(GetKeywordsStrWithoutInstancing(x))).ToList(); foreach (ShaderCompilerData thing in thingsToClone) { ShaderCompilerData copy = thing; copy.shaderKeywordSet.Enable(inst); data.Add(copy); } }
public static void ProcessFormalSVC(Shader shader, ShaderSnippetData snippet, IList <ShaderCompilerData> data) { // 这里用于全局剔除不要的特殊pass编译 if (snippet.passType == PassType.LightPrePassBase || snippet.passType == PassType.LightPrePassFinal || snippet.passType == PassType.Deferred) { data.Clear(); return; } if (m_allshaderVariantDict == null) { m_allshaderVariantDict = new Dictionary <string, ShaderVariantCollectionItem>(); shaderVariantCollection = AssetDatabase.LoadAssetAtPath <ShaderVariantCollection>(ShaderVariantCollectionPath); if (shaderVariantCollection == null) { return; } GetShaderVariantList(shaderVariantCollection, m_allshaderVariantDict); } ShaderVariantCollectionItem shaderVariantList; if (!m_allshaderVariantDict.TryGetValue(shader.name, out shaderVariantList)) { return; } for (int i = data.Count - 1; i >= 0; i--) { if (!shaderVariantList.IsContain(snippet.passType, data[i])) { data.RemoveAt(i); } } }
public void OnProcessShader( Shader shader, ShaderSnippetData snippet, IList <ShaderCompilerData> shaderCompilerData) { if (EditorUserBuildSettings.development) { return; } for (int i = 0; i < forbideName.Length; i++) { if (shader.name == forbideName[i]) { shaderCompilerData.Clear(); return; } } for (int i = 0; i < shaderCompilerData.Count; ++i) { var scp = shaderCompilerData[i]; for (int j = 0; j < m_ForbidenKeywords.Length; j++) { if (scp.shaderKeywordSet.IsEnabled(m_ForbidenKeywords[j])) { Debug.LogError("Remove one form " + shader.name); shaderCompilerData.RemoveAt(i); --i; continue; } } } Debug.Log("OnProcessShader " + shader.name + " Key World Count " + shaderCompilerData.Count); }
public bool KeepVariants(Shader shader, ShaderSnippetData snippet, ShaderCompilerData variants) { keywords.Clear(); var shaderKeywords = variants.shaderKeywordSet.GetShaderKeywords(); foreach (var shaderkeyword in shaderKeywords) { keywords.Add(ShaderKeyword.GetGlobalKeywordName(shaderkeyword)); } bool hasKeywords = keywords.Count > 0; Debug.Log(shader.name + "\tVariants:" + (hasKeywords ? string.Join("\t", keywords.ToArray()) : "<no keywords>")); if (hasKeywords && keepExportVariants != null) { ShaderVariant shaderVariant = new ShaderVariant(shader, snippet.passType, keywords.ToArray()); // 必须,自动导出的变体组合 if (keepExportVariants.Contains(shaderVariant)) { return(true); } // 可选,自定义变体组合 if (keepCustomVariants != null && keepCustomVariants.Contains(shaderVariant)) { return(true); } return(false); } return(true); }
void LogShaderVariants(Shader shader, ShaderSnippetData snippetData, uint prevVariantsCount, uint currVariantsCount, double stripTimeMs) { if (HDRenderPipelineGlobalSettings.instance.shaderVariantLogLevel == ShaderVariantLogLevel.Disabled) { return; } m_TotalVariantsInputCount += prevVariantsCount; m_TotalVariantsOutputCount += currVariantsCount; if (HDRenderPipelineGlobalSettings.instance.shaderVariantLogLevel == ShaderVariantLogLevel.OnlySRPShaders && !HDShaderUtils.IsHDRPShader(shader)) { return; } float percentageCurrent = ((float)currVariantsCount / prevVariantsCount) * 100.0f; float percentageTotal = ((float)m_TotalVariantsOutputCount / m_TotalVariantsInputCount) * 100.0f; string result = string.Format("STRIPPING: {0} ({1} pass) ({2}) -" + " Remaining shader variants = {3}/{4} = {5}% - Total = {6}/{7} = {8}% - Time={9}Ms", shader.name, snippetData.passName, snippetData.shaderType.ToString(), currVariantsCount, prevVariantsCount, percentageCurrent, m_TotalVariantsOutputCount, m_TotalVariantsInputCount, percentageTotal, stripTimeMs); Debug.Log(result); }
bool LDJRoleStandardShaderStripper(Shader shader, ShaderSnippetData snippet, ShaderCompilerData inputData) { List <ShaderKeyword> m_keywords = new List <ShaderKeyword>(); m_keywords.Add(new ShaderKeyword("SHADOWS_SCREEN")); m_keywords.Add(new ShaderKeyword("DYNAMICLIGHTMAP_ON")); m_keywords.Add(new ShaderKeyword("DIRLIGHTMAP_COMBINED")); m_keywords.Add(new ShaderKeyword("LIGHTMAP_SHADOW_MIXING")); m_keywords.Add(new ShaderKeyword("VERTEXLIGHT_ON")); m_keywords.Add(new ShaderKeyword("LIGHTMAP_ON")); m_keywords.Add(new ShaderKeyword("SHADOWS_SHADOWMASK")); for (int i = 0; i < m_keywords.Count; ++i) { if (inputData.shaderKeywordSet.IsEnabled(m_keywords[i])) { return(true); } } if (inputData.shaderKeywordSet.GetShaderKeywords().Length > 4) { return(true); } if (!inputData.shaderKeywordSet.IsEnabled(new ShaderKeyword("DIRECTIONAL")) || !inputData.shaderKeywordSet.IsEnabled(new ShaderKeyword("LIGHTPROBE_SH"))) { return(true); } return(false); }
bool StripUnused(ShaderFeatures features, Shader shader, ShaderSnippetData snippetData, ShaderCompilerData compilerData) { if (StripUnusedFeatures(features, shader, snippetData, compilerData)) return true; if (StripInvalidVariants(compilerData)) return true; if (StripUnsupportedVariants(compilerData)) return true; if (StripUnusedPass(features, snippetData)) return true; // Strip terrain holes // TODO: checking for the string name here is expensive // maybe we can rename alpha clip keyword name to be specific to terrain? if (compilerData.shaderKeywordSet.IsEnabled(m_AlphaTestOn) && !IsFeatureEnabled(features, ShaderFeatures.TerrainHoles) && shader.name.Contains(kTerrainShaderName)) return true; // TODO: Test against lightMode tag instead. if (snippetData.passName == kPassNameGBuffer) { if (!IsFeatureEnabled(features, ShaderFeatures.DeferredShading)) return true; if (IsFeatureEnabled(features, ShaderFeatures.DeferredWithAccurateGbufferNormals) && !compilerData.shaderKeywordSet.IsEnabled(m_GbufferNormalsOct)) return true; if (IsFeatureEnabled(features, ShaderFeatures.DeferredWithoutAccurateGbufferNormals) && compilerData.shaderKeywordSet.IsEnabled(m_GbufferNormalsOct)) return true; } return false; }
bool StripUnusedFeatures(ShaderFeatures features, Shader shader, ShaderSnippetData snippetData, ShaderCompilerData compilerData) { // strip main light shadows and cascade variants if (!IsFeatureEnabled(features, ShaderFeatures.MainLightShadows)) { if (compilerData.shaderKeywordSet.IsEnabled(m_MainLightShadows)) { return(true); } if (compilerData.shaderKeywordSet.IsEnabled(m_CascadeShadows)) { return(true); } } if (!IsFeatureEnabled(features, ShaderFeatures.SoftShadows) && compilerData.shaderKeywordSet.IsEnabled(m_SoftShadows)) { return(true); } if (compilerData.shaderKeywordSet.IsEnabled(m_MixedLightingSubtractive) && !IsFeatureEnabled(features, ShaderFeatures.MixedLighting)) { return(true); } // No additional light shadows bool isAdditionalLightShadow = compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightShadows); if (!IsFeatureEnabled(features, ShaderFeatures.AdditionalLightShadows) && isAdditionalLightShadow) { return(true); } // Additional light are shaded per-vertex or per-pixel. bool isFeaturePerPixelLightingEnabled = IsFeatureEnabled(features, ShaderFeatures.AdditionalLights); bool isFeaturePerVertexLightingEnabled = IsFeatureEnabled(features, ShaderFeatures.VertexLighting); bool isAdditionalLightPerPixel = compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightsPixel); bool isAdditionalLightPerVertex = compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightsVertex); // Strip if Per-Pixel lighting is NOT used in the project and the // Per-Pixel (_ADDITIONAL_LIGHTS) or additional shadows (_ADDITIONAL_LIGHT_SHADOWS) // variants are enabled in the shader. if (!isFeaturePerPixelLightingEnabled && (isAdditionalLightPerPixel || isAdditionalLightShadow)) { return(true); } // Strip if Per-Vertex lighting is NOT used in the project and the // Per-Vertex (_ADDITIONAL_LIGHTS_VERTEX) variant is enabled in the shader. if (!isFeaturePerVertexLightingEnabled && isAdditionalLightPerVertex) { return(true); } return(false); }
private void SaveResult(Shader shader, ShaderSnippetData snippet) { string shaderName = shader.name.Replace("/", "_"); string includeDir = LogDirectory + "/" + dateTimeStr + "/Include/" + shaderName; string excludeDir = LogDirectory + "/" + dateTimeStr + "/Exclude/" + shaderName; string name = shaderName + "_" + snippet.shaderType.ToString() + "_" + snippet.passName + "_" + snippet.passType; if (includeVariantsBuffer.Length != 0) { if (!System.IO.Directory.Exists(includeDir)) { System.IO.Directory.CreateDirectory(includeDir); } this.includeVariantsBuffer.Append("\n==================\n"); System.IO.File.AppendAllText(System.IO.Path.Combine(includeDir, name) + ".txt", includeVariantsBuffer.ToString()); } if (excludeVariantsBuffer.Length != 0) { if (!System.IO.Directory.Exists(excludeDir)) { System.IO.Directory.CreateDirectory(excludeDir); } this.excludeVariantsBuffer.Append("\n==================\n"); System.IO.File.AppendAllText(System.IO.Path.Combine(excludeDir, name) + ".txt", excludeVariantsBuffer.ToString()); } }
public override bool IsValidProcessor(Shader shader, ShaderSnippetData snippet, ShaderCompilerData data) { // Strip hidden shaders but not internal ones. // Stripping internal shaders can cause rendering issue in builds return(shader.name.StartsWith("Hidden/", StringComparison.OrdinalIgnoreCase) && !shader.name.StartsWith("Hidden/Internal", StringComparison.OrdinalIgnoreCase)); }
public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList <ShaderCompilerData> data) { if (snippet.shaderType != ShaderType.Fragment) { return; } // if s_ShaderVariantData is null, we might be building AssetBundles if (s_ShaderVariantData == null) { return; } if (!s_ShaderVariantData.ContainsKey(shader)) { s_ShaderVariantData.Add(shader, new List <ShaderVariantData>()); } foreach (var shaderCompilerData in data) { s_ShaderVariantData[shader].Add(new ShaderVariantData { passName = snippet.passName, compilerData = shaderCompilerData }); } }
public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList <ShaderCompilerData> data) { #if !WF_STRIP_DISABLE if (IsStripTargetShader(shader)) { // 設定はここで読み込む Core.InitUsedShaderVariantList(); if (settings == null || !settings.enableStripping) { // stripping しない return; } var usedShaderVariantList = Core.GetList(); var before = data.Count; var strip = 0; strip += DoStripForwardBasePass(shader, snippet, data, usedShaderVariantList); strip += DoStripMetaPass(shader, snippet, data); #if WF_STRIP_LOG_RESULT if (data.Count < before) { Debug.LogFormat("[WF][Preprocess] shader stripping: {0}/{1} at {2}/{3}/{4}", strip, before, shader.name, snippet.passName, snippet.shaderType); } #endif } #endif }
public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList <ShaderCompilerData> inputData) { // This test will also return if we are not using HDRenderPipelineAsset if (m_CurrentHDRPAsset == null || !m_CurrentHDRPAsset.allowShaderVariantStripping) { return; } int inputShaderVariantCount = inputData.Count; for (int i = 0; i < inputData.Count; ++i) { ShaderCompilerData input = inputData[i]; bool removeInput = false; // Call list of strippers // Note that all strippers cumulate each other, so be aware of any conflict here foreach (BaseShaderPreprocessor material in materialList) { if (material.ShadersStripper(m_CurrentHDRPAsset, shader, snippet, input)) { removeInput = true; } } if (removeInput) { inputData.RemoveAt(i); i--; } } }
public void OnProcessShader(Shader shader, ShaderSnippetData snippetData, IList <ShaderCompilerData> compilerDataList) { LightweightRP lw = RenderPipelineManager.currentPipeline as LightweightRP; if (lw == null) { return; } PipelineCapabilities capabilities = LightweightRP.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 }
public void OnProcessShader(Shader shader, ShaderSnippetData snippetData, IList <ShaderCompilerData> compilerDataList) { LightweightRenderPipelineAsset lwrpAsset = GraphicsSettings.renderPipelineAsset as LightweightRenderPipelineAsset; if (lwrpAsset == null || compilerDataList == null || compilerDataList.Count == 0) { return; } StripVariantsInfo stripInfo = lwrpAsset.stripVariantsInfo; int prevVariantCount = compilerDataList.Count; for (int i = 0; i < compilerDataList.Count; ++i) { if (stripInfo != null) { if (StripUnused(stripInfo, shader, snippetData, compilerDataList[i])) { compilerDataList.RemoveAt(i); --i; } } } if (lwrpAsset.shaderVariantLogLevel != ShaderVariantLogLevel.Disabled) { m_TotalVariantsInputCount += prevVariantCount; m_TotalVariantsOutputCount += compilerDataList.Count; if (compilerDataList.Count < prevVariantCount) { LogShaderVariants(shader, snippetData, lwrpAsset.shaderVariantLogLevel, prevVariantCount, compilerDataList.Count); } } }
private bool IsExist(List <ShaderVariantsInfo> shaderVariants, Shader shader, ShaderSnippetData snippet, ShaderCompilerData data) { var keywords = data.shaderKeywordSet.GetShaderKeywords(); var compiledKeyword = Convert(keywords); if (compiledKeyword.Count == 0) { return(true); } foreach (var variant in shaderVariants) { if (variant.shader != shader) { continue; } if (variant.passType != snippet.passType) { continue; } if (IsMatch(variant.keywordsForCheck, compiledKeyword)) { return(true); } } return(false); }
bool StripUnused(StripVariantsInfo stripInfo /*not null*/, Shader shader, ShaderSnippetData snippetData, ShaderCompilerData compilerData) { foreach (string shadername in stripInfo.globalShaderNames) { if (StripGlobalShader(shadername, shader)) { return(true); } } foreach (string keyword in stripInfo.globalKeywords) { if (StripGlobalKeywords(keyword, compilerData)) { return(true); } } if (stripInfo.specifiedShaders != null) { foreach (SpecifiedShaderKeyword specifed in stripInfo.specifiedShaders) { if (StripSpecifiedKeyward(specifed, shader, compilerData)) { return(true); } } } return(false); }
public void OnProcessShader(Shader shader, ShaderSnippetData snippetData, IList <ShaderCompilerData> compilerDataList) { UniversalRenderPipelineAsset urpAsset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset; if (urpAsset == null || compilerDataList == null || compilerDataList.Count == 0) { return; } ShaderFeatures features = GetSupportedShaderFeatures(urpAsset); int prevVariantCount = compilerDataList.Count; for (int i = 0; i < compilerDataList.Count; ++i) { if (StripUnused(features, shader, snippetData, compilerDataList[i])) { compilerDataList.RemoveAt(i); --i; } } if (urpAsset.shaderVariantLogLevel != ShaderVariantLogLevel.Disabled) { m_TotalVariantsInputCount += prevVariantCount; m_TotalVariantsOutputCount += compilerDataList.Count; LogShaderVariants(shader, snippetData, urpAsset.shaderVariantLogLevel, prevVariantCount, compilerDataList.Count); } }
void LogShaderVariants(Shader shader, ShaderSnippetData snippetData, ShaderVariantLogLevel logLevel, int prevVariantsCount, int currVariantsCount) { Func <bool> showlog = () => { if (logLevel == ShaderVariantLogLevel.AllShaders) { return(true); } if (logLevel == ShaderVariantLogLevel.OnlyLightweightRPShaders && shader.name.Contains("Lightweight Render Pipeline")) { return(true); } LightweightRenderPipelineAsset lwrpAsset = GraphicsSettings.renderPipelineAsset as LightweightRenderPipelineAsset; if (logLevel == ShaderVariantLogLevel.ShowIfAbove && currVariantsCount > lwrpAsset.shaderVariantShowNum) { return(true); } return(false); }; if (showlog()) { float percentageCurrent = (float)currVariantsCount / (float)prevVariantsCount * 100f; float percentageTotal = (float)m_TotalVariantsOutputCount / (float)m_TotalVariantsInputCount * 100f; string result = string.Format("{9}'s 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, Application.productName); Debug.Log(YText(result)); } }
bool TerrainShaderStripper(Shader shader, ShaderSnippetData snippet, ShaderCompilerData inputData) { for (int i = 0; i < m_keywords.Count; ++i) { if (inputData.shaderKeywordSet.IsEnabled(m_keywords[i])) { return(true); } } // 假设项目是固定前向渲染,那么延迟渲染pass可以去掉 if (snippet.passType == PassType.Deferred) { return(true); } // 假设项目拟定的设备渲染分级是只有Tier3用法线图,那么Tier1和2可以去掉 if (inputData.graphicsTier != GraphicsTier.Tier3 && inputData.shaderKeywordSet.IsEnabled(m_KeywordTerrainNormalMap)) { return(true); } if (!inputData.platformKeywordSet.IsEnabled(BuiltinShaderDefine.UNITY_USE_NATIVE_HDR) && inputData.shaderKeywordSet.IsEnabled(m_KeywordHDR)) { return(true); } if (inputData.platformKeywordSet.IsEnabled(BuiltinShaderDefine.UNITY_NO_SCREENSPACE_SHADOWS) && inputData.shaderKeywordSet.IsEnabled(m_KeywordScreenShadow)) { // No cascade shadow map return(true); } return(false); }
bool StripUnused(ShaderFeatures features, Shader shader, ShaderSnippetData snippetData, ShaderCompilerData compilerData) { if (StripUnusedFeatures(features, shader, snippetData, compilerData)) { return(true); } if (StripInvalidVariants(compilerData)) { return(true); } if (StripUnsupportedVariants(compilerData)) { return(true); } if (StripUnusedPass(features, snippetData)) { return(true); } // Strip terrain holes // TODO: checking for the string name here is expensive // maybe we can rename alpha clip keyword name to be specific to terrain? if (compilerData.shaderKeywordSet.IsEnabled(m_AlphaTestOn) && !IsFeatureEnabled(features, ShaderFeatures.TerrainHoles) && shader.name.Contains(kTerrainShaderName)) { return(true); } return(false); }
bool StripUnused(ShaderFeatures features, Shader shader, ShaderSnippetData snippetData, ShaderCompilerData compilerData) { if (StripUnusedShader(features, shader, compilerData)) { return(true); } if (StripUnusedPass(features, snippetData)) { return(true); } if (StripUnusedFeatures(features, shader, compilerData)) { return(true); } if (StripUnsupportedVariants(compilerData)) { return(true); } if (StripInvalidVariants(compilerData)) { return(true); } if (StripDeprecated(compilerData)) { return(true); } return(false); }
public void OnProcessShader( Shader shader, ShaderSnippetData snippetData, IList <ShaderCompilerData> compilerData) { foreach (ShaderCompilerData d in compilerData) { foreach (ShaderKeyword keyword in d.shaderKeywordSet.GetShaderKeywords()) { if (shaderKeywords.ContainsKey(keyword.GetKeywordName())) { shaderKeywords[keyword.GetKeywordName()]++; } else { shaderKeywords.Add(keyword.GetKeywordName(), 1); } } } if (variants.ContainsKey(shader.name)) { variants[shader.name] += compilerData.Count; } else { variants.Add(shader.name, compilerData.Count); } }