public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
        {
            _logPath = EditorPrefs.GetString(KEY_LOG);
            _enabled = GetEnabled();

            if (_enabled)
            {
                Debug.Log("Initialising ShaderStrippers");
                if (!string.IsNullOrEmpty(_logPath))
                {
                    Debug.Log("Logfiles will be created in " + _logPath);
                }
                _keptLog.Clear();
                _keptLog.Add("Unstripped Shaders:");
                RefreshSettings();
                ShaderStripperBase.OnPreBuild(_deepLogs);
                foreach (var s in _strippers)
                {
                    if (s.active)
                    {
                        s.Initialize();
                    }
                }
                _swStrip.Reset();
                _swBuild.Reset();
                _swBuild.Start();
            }
            else
            {
                Debug.Log("ShaderStripper DISABLED");
            }
        }
Esempio n. 2
0
        static protected void LogMessage(ShaderStripperBase stripper, string message, MessageType type = MessageType.None)
        {
            if (!stripper._logOutput)
            {
                return;
            }
            string log = string.Format("ShaderStripper {0}: {1}", stripper.name, message);

            switch (type)
            {
            case MessageType.Info:
            case MessageType.None:
                _log.Add(log);
                break;

            case MessageType.Warning:
                log = "WARN: " + log;
                _log.Add(log);
                break;

            case MessageType.Error:
                log = "ERR: " + log;
                _log.Add(log);
                break;
            }
        }
        public void OnPostprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
        {
            if (!_enabled)
            {
                return;
            }

            _swBuild.Stop();

            string header = string.Format(
                "Build Time: {0}ms\nStrip Time: {1}ms\nTotal shaders built: {2}\nTotal shaders stripped: {3}",
                _swBuild.ElapsedMilliseconds, _swStrip.ElapsedMilliseconds, _keptCount, _rawCount - _keptCount
                );

            Debug.Log(header);

            var strippedKeywords = new ShaderLog("KEYWORDS-STRIPPED");

            foreach (var k in _allKeywords.log)
            {
                if (!_keptKeywords.Contains(k))
                {
                    strippedKeywords.Add(k);
                }
            }

            var strippedPlatformKeywords = new ShaderLog("PLATFORM-KEYWORDS-STRIPPED");

            foreach (var k in _allPlatformKeywordNames.log)
            {
                if (!_keptPlatformKeywordNames.Contains(k))
                {
                    strippedPlatformKeywords.Add(k);
                }
            }

            string logPath = EditorPrefs.GetString(ShaderStripperEditor.KEY_LOG);

            ShaderStripperBase.OnPostBuild(
                logPath, header, _keptLog, _allKeywords, _keptKeywords,
                _allPlatformKeywordNames, _keptPlatformKeywordNames,
                strippedKeywords, strippedPlatformKeywords
                );

            _swStrip.Reset();
            _swBuild.Reset();
            _keptLog.Clear();
            _keptCount = 0;
            _allKeywords.Clear();
            _keptKeywords.Clear();
            _allPlatformKeywordNames.Clear();
            _allPlatformKeywords.Clear();
            _keptPlatformKeywordNames.Clear();
            _keptPlatformKeywords.Clear();
        }
Esempio n. 4
0
        static protected void LogRemoval(ShaderStripperBase stripper, Shader shader, ShaderSnippetData pass)
        {
            if (!stripper._logOutput)
            {
                return;
            }
            string log = string.Format(
                "Stripping shader [{0}] pass type [{1}]\n\tShaderStripper: {2}",
                shader.name, pass.passType, stripper.name
                );

            _log.Add(log);
        }
Esempio n. 5
0
        static protected void LogRemoval(ShaderStripperBase stripper, Shader shader, ShaderSnippetData pass, int variantIndex, int variantCount, ShaderCompilerData variant)
        {
            if (!stripper._logOutput)
            {
                return;
            }
            string log = null;

            if (_deepLogs)
            {
                log = string.Format(
                    "Stripping shader [{0}] pass type [{1}] variant [{2}/{3}] [{4}]\n\tShaderStripper: {5}\n\tKeywords:",
                    shader.name, pass.passType, variantIndex, variantCount - 1, variant.graphicsTier, stripper.name
                    );
                var ks = variant.shaderKeywordSet.GetShaderKeywords();

                if (ks != null && ks.Length > 0)
                {
                    bool first = true;
                    foreach (var k in variant.shaderKeywordSet.GetShaderKeywords())
                    {
                        if (!first)
                        {
                            log += ",";
                        }
                        log  += " " + GetKeywordName(k);
                        first = false;
                    }
                }
                else
                {
                    log += " <no keywords>";
                }
            }
            else
            {
                log = string.Format(
                    "Stripping shader [{0}] pass type [{1}] variant [{2}/{3}]\n\tShaderStripper: {4}",
                    shader.name, pass.passType, variantIndex, variantCount - 1, stripper.name
                    );
            }
            _log.Add(log);
        }
        public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList <ShaderCompilerData> data)
        {
            if (!_enabled)
            {
                return;
            }
            _rawCount += data.Count;

            var builtins = (BuiltinShaderDefine[])System.Enum.GetValues(typeof(BuiltinShaderDefine));

            if (_deepLogs)
            {
                for (int i = 0; i < data.Count; ++i)
                {
                    foreach (var k in data[i].shaderKeywordSet.GetShaderKeywords())
                    {
                        string sn = ShaderStripperBase.GetKeywordName(k);
                        if (!_allKeywords.Contains(sn))
                        {
                            _allKeywords.Add(sn);
                        }
                    }
                    var pks = data[i].platformKeywordSet;
                    foreach (var b in builtins)
                    {
                        if (pks.IsEnabled(b))
                        {
                            if (!_allPlatformKeywords.Contains(b))
                            {
                                _allPlatformKeywords.Add(b);
                                _allPlatformKeywordNames.Add(b.ToString());
                            }
                        }
                    }
                }
            }

            _swStrip.Start();
            for (int i = 0; i < _strippers.Count; ++i)
            {
                var s = _strippers[i];
                if (!s.active)
                {
                    continue;
                }
                s.Strip(shader, snippet, data);
                if (data.Count == 0)
                {
                    break;
                }
            }
            _swStrip.Stop();
            if (data.Count > 0)
            {
                _keptCount += data.Count;
                _keptLog.Add(string.Format(
                                 "    {0}::[{1}]{2} [{3} variants]", shader.name,
                                 snippet.passType, snippet.passName, data.Count
                                 ));

                if (_deepLogs)
                {
                    foreach (var d in data)
                    {
                        string varLog = string.Format(
                            "\t\t[{0}][{1}] ", d.graphicsTier, d.shaderCompilerPlatform
                            );
                        foreach (var k in d.shaderKeywordSet.GetShaderKeywords())
                        {
                            varLog += ShaderStripperBase.GetKeywordName(k) + " ";
                        }

                        varLog += "\n\t\t\t";
                        foreach (var b in _platformKeywords)
                        {
                            if (d.platformKeywordSet.IsEnabled(b))
                            {
                                varLog += b.ToString() + " ";
                            }
                        }

                        varLog += string.Format("\n\t\t\tREQ: {0}", d.shaderRequirements.ToString());
                        _keptLog.Add(varLog);

                        foreach (var k in d.shaderKeywordSet.GetShaderKeywords())
                        {
                            string sn = ShaderStripperBase.GetKeywordName(k);
                            if (!_keptKeywords.Contains(sn))
                            {
                                _keptKeywords.Add(sn);
                            }
                        }

                        var pks = d.platformKeywordSet;
                        foreach (var b in builtins)
                        {
                            if (pks.IsEnabled(b))
                            {
                                if (!_keptPlatformKeywords.Contains(b))
                                {
                                    _keptPlatformKeywords.Add(b);
                                    _keptPlatformKeywordNames.Add(b.ToString());
                                }
                            }
                        }
                    }
                }
            }
        }