Example #1
0
        private static CompiledShader AccumulateToCompiledShader(CompiledShader src, CompiledShader dst)
        {
            dst.editorLog_originalVariantCount  += src.editorLog_originalVariantCount;
            dst.editorLog_compiledVariantCount  += src.editorLog_compiledVariantCount;
            dst.editorLog_totalProcessTime      += src.editorLog_totalProcessTime;
            dst.editorLog_remainingVariantCount += src.editorLog_remainingVariantCount;
            dst.editorLog_variantInCacheCount   += src.editorLog_variantInCacheCount;

            return(dst);
        }
Example #2
0
        public void OnProcessComputeShader(ComputeShader shader, string kernelName, IList <ShaderCompilerData> data)
        {
            int newVariantsForThisShader = 0;

            //The real variant count
            newVariantsForThisShader += data.Count;

            //Go through all the variants
            for (int i = 0; i < data.Count; ++i)
            {
                ShaderKeyword[] sk = data[i].shaderKeywordSet.GetShaderKeywords();

                //The default variant
                if (sk.Length == 0)
                {
                    CompiledShaderVariant scv_default = new CompiledShaderVariant();
                    //scv.id = id;
                    scv_default.shaderName             = shader.name;
                    scv_default.kernelName             = kernelName;
                    scv_default.passName               = "--";
                    scv_default.passType               = "--";
                    scv_default.shaderType             = "--";
                    scv_default.graphicsTier           = "--";
                    scv_default.shaderCompilerPlatform = "--";
                    scv_default.shaderKeywordName      = "No Keyword / All Off";
                    scv_default.shaderKeywordType      = "--";
                    scv_default.shaderKeywordIndex     = "-1";
                    scv_default.isShaderKeywordValid   = "--";
                    scv_default.isShaderKeywordEnabled = "--";
                    SVL.variantlist.Add(scv_default);
                    SVL.compiledTotalCount++;
                }

                for (int k = 0; k < sk.Length; ++k)
                {
                    CompiledShaderVariant scv = new CompiledShaderVariant();

                    //scv.id = id;
                    scv.shaderName = shader.name;
                    scv.kernelName = kernelName;
                    scv.passName   = "--";
                    scv.passType   = "--";
                    scv.shaderType = "--";

                    scv.graphicsTier           = data[i].graphicsTier.ToString();
                    scv.shaderCompilerPlatform = data[i].shaderCompilerPlatform.ToString();
                    //scv.shaderRequirements = ""+data[i].shaderRequirements;
                    //scv.platformKeywordName = ""+data[i].platformKeywordSet.ToString();
                    //scv.isplatformKeywordEnabled = ""+data[i].platformKeywordSet.IsEnabled(BuiltinShaderDefine.SHADER_API_DESKTOP);

                    bool         isLocal   = ShaderKeyword.IsKeywordLocal(sk[k]);
                    LocalKeyword lkey      = new LocalKeyword(shader, sk[k].name);
                    bool         isDynamic = lkey.isDynamic;
                    scv.shaderKeywordName      = (isLocal? "[Local]" : "[Global]") + (isDynamic? "[Dynamic] " : " ") + sk[k].name; //sk[k].GetKeywordName();
                    scv.shaderKeywordType      = isLocal? "--" : ShaderKeyword.GetGlobalKeywordType(sk[k]).ToString();             //""+sk[k].GetKeywordType().ToString();
                    scv.shaderKeywordIndex     = sk[k].index.ToString();
                    scv.isShaderKeywordValid   = sk[k].IsValid().ToString();
                    scv.isShaderKeywordEnabled = data[i].shaderKeywordSet.IsEnabled(sk[k]).ToString();

                    SVL.variantlist.Add(scv);
                    SVL.compiledTotalCount++;

                    //Just to verify API is correct
                    //string globalShaderKeywordName = ShaderKeyword.GetGlobalKeywordName(sk[k]);
                    //if( !isLocal && globalShaderKeywordName != ShaderKeyword.GetKeywordName(shader,sk[k]) ) Debug.LogError("Bug. ShaderKeyword.GetGlobalKeywordName() and  ShaderKeyword.GetKeywordName() is wrong");
                    // ShaderKeywordType globalShaderKeywordType = ShaderKeyword.GetGlobalKeywordType(sk[k]);
                    //if( !isLocal && globalShaderKeywordType != ShaderKeyword.GetKeywordType(shader,sk[k]) ) Debug.LogError("Bug. ShaderKeyword.GetGlobalKeywordType() and  ShaderKeyword.GetKeywordType() is wrong");
                }
            }

            //Add to shader list
            int compiledShaderId = SVL.shaderlist.FindIndex(o => o.name == shader.name);

            if (compiledShaderId == -1)
            {
                CompiledShader newCompiledShader = new CompiledShader();
                newCompiledShader.name       = shader.name;
                newCompiledShader.guiEnabled = false;
                newCompiledShader.noOfVariantsForThisShader = 0;
                SVL.shaderlist.Add(newCompiledShader);
                SVL.computeShaderCount++;
                compiledShaderId = SVL.shaderlist.Count - 1;
            }

            //Add variant count to shader
            CompiledShader compiledShader = SVL.shaderlist[compiledShaderId];

            compiledShader.noOfVariantsForThisShader += newVariantsForThisShader;
            SVL.shaderlist[compiledShaderId]          = compiledShader;

            //Add to total count
            SVL.variantTotalCount  += newVariantsForThisShader;
            SVL.variantFromCompute += newVariantsForThisShader;
        }
        //[MenuItem("ShaderVariantTool/Debug/TestEditorLog")]
        private void ReadShaderCompileInfo()
        {
            //For making sure there is no bug
            int variantCountinBuild = 0;

            //Decide EditorLog path
            string editorLogPath = "";

            switch (Application.platform)
            {
            case RuntimePlatform.WindowsEditor: editorLogPath = Environment.GetEnvironmentVariable("AppData").Replace("Roaming", "") + "Local\\Unity\\Editor\\Editor.log"; break;

            case RuntimePlatform.OSXEditor: editorLogPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Library") + "/Logs/Unity/Editor.log"; break;

            case RuntimePlatform.LinuxEditor: editorLogPath = "~/.config/unity3d/Editor.log"; break;
            }

            //Read EditorLog
            string     fromtext    = SVL.buildProcessIDTitleStart + SVL.buildProcessID;
            string     totext      = SVL.buildProcessIDTitleEnd + SVL.buildProcessID;
            string     currentLine = "";
            bool       startFound  = false;
            bool       endFound    = false;
            FileStream fs          = new FileStream(editorLogPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            using (StreamReader sr = new StreamReader(fs))
            {
                while (!startFound)
                {
                    currentLine = sr.ReadLine();
                    if (currentLine.Contains(fromtext))
                    {
                        startFound = true;
                    }
                }
                while (!endFound)
                {
                    currentLine = sr.ReadLine();
                    if (currentLine.Contains(totext))
                    {
                        endFound = true;
                    }
                    else
                    {
                        if (currentLine.Contains("Compiling shader "))
                        {
                            //Shader name
                            string shaderName = Helper.ExtractString(currentLine, "Compiling shader ", " pass ");
                            shaderName = shaderName.Replace("\"", "");

                            //Shader pass
                            string passName = Helper.ExtractString(currentLine, " pass ", "\" (");
                            passName = passName.Replace("\"", "");

                            //Shader program e.g. vert / frag
                            string programName = Helper.ExtractString(currentLine, passName + "\" (", "");
                            programName = programName.Replace("\"", "").Replace(")", "");

                            //total variant
                            currentLine = sr.ReadLine();
                            if (currentLine.Contains("prepared") && !currentLine.Contains("variants, prepared"))
                            {
                                currentLine = sr.ReadLine();
                            }
                            string totalVariant = Helper.ExtractString(currentLine, "", " variants,");
                            totalVariant = totalVariant.Replace(" ", "");
                            int totalVariantInt = int.Parse(totalVariant);

                            //remaining variant & stripping time
                            currentLine = sr.ReadLine();
                            string strippingTime       = Helper.ExtractString(currentLine, "finished in ", " seconds. ");
                            string remainingVariant    = Helper.ExtractString(currentLine, " seconds. ", " variants left");
                            int    remainingVariantInt = int.Parse(remainingVariant);

                            //jump to line of compilation time
                            if (remainingVariantInt > 0)
                            {
                                currentLine = sr.ReadLine();
                                while (!currentLine.Contains("finished in ") || currentLine.Contains("variants ready"))
                                {
                                    currentLine = sr.ReadLine();
                                }
                            }

                            //compilation time and compiled variant count (time is faster if there are cached variants)
                            string compileTime      = "0.00";
                            string compiledVariants = "0";
                            string localCache       = "0";
                            string remoteCache      = "0";
                            if (remainingVariantInt > 0)
                            {
                                compileTime      = Helper.ExtractString(currentLine, "finished in ", " seconds. ");
                                compiledVariants = Helper.ExtractString(currentLine, ", compiled ", " variants");
                                localCache       = Helper.ExtractString(currentLine, "Local cache hits ", ", remote");
                                remoteCache      = Helper.ExtractString(currentLine, "remote cache hits ", ", compiled");

                                //Changes for the latest PR
                                localCache  = Helper.ExtractString(localCache, "", "(");
                                localCache  = localCache.Replace(" ", "");
                                remoteCache = Helper.ExtractString(remoteCache, "", "(");
                                remoteCache = remoteCache.Replace(" ", "");
                            }
                            int   compiledVariantsInt = int.Parse(compiledVariants);
                            int   localCacheInt       = int.Parse(localCache);
                            int   remoteCacheInt      = int.Parse(remoteCache);
                            float strippingTimeFloat  = float.Parse(strippingTime);
                            float compileTimeFloat    = float.Parse(compileTime);

                            //---------- Add to ShaderList ------------//
                            int            listID = SVL.shaderlist.IndexOf(SVL.shaderlist.Find(x => x.name.Equals(shaderName)));
                            CompiledShader temp   = SVL.shaderlist[listID];
                            temp.editorLog_originalVariantCount  += totalVariantInt;
                            temp.editorLog_compiledVariantCount  += compiledVariantsInt;
                            temp.editorLog_totalProcessTime      += strippingTimeFloat + compileTimeFloat;
                            temp.editorLog_remainingVariantCount += remainingVariantInt;
                            temp.editorLog_variantInCacheCount   += localCacheInt + remoteCacheInt;
                            SVL.shaderlist[listID] = temp;
                            //---------- For total countinvariantInCacheg ------------//
                            SVL.variantBeforeStrippingCount += totalVariantInt;
                            SVL.variantCompiledCount        += compiledVariantsInt;
                            SVL.variantInCache  += localCacheInt + remoteCacheInt;
                            variantCountinBuild += remainingVariantInt; //for making sure no bug

                            //Debug
                            // if(shaderName == "Universal Render Pipeline/Lit")
                            // {
                            //     string debugText = shaderName +"-"+ passName +"-"+ programName + "\n";
                            //     debugText += totalVariant +"-"+ remainingVariant +"-time-"+ strippingTime + "\n";
                            //     debugText += compileTime +"-"+ compiledVariants + "\n";
                            //     DebugLog(debugText);
                            // }
                        }
                    }
                }
            }

            //Bug check - in case my codes in OnProcessShader VS reading EditorLog counts different result
            if (SVL.variantFromShader != variantCountinBuild)
            {
                Debug.LogError("ShaderVariantTool error. " +
                               "Tool counted there are " + SVL.variantFromShader + " shader variants in build, " +
                               "but Editor Log counted " + variantCountinBuild + ". Please contact @mingwai on slack.");
            }
            if (SVL.variantInCache + SVL.variantCompiledCount != variantCountinBuild)
            {
                Debug.LogError("ShaderVariantTool error. " +
                               "The sum of " + SVL.variantInCache + " variants in cache + " +
                               SVL.variantCompiledCount + " variants compiled is not equal to the accumulated sum " +
                               variantCountinBuild + " variants. Please contact @mingwai on slack.");
            }
        }
Example #4
0
        public static List <CompiledShader> ReadShaderCompileInfo(string startTimeStamp, string editorLogPath, bool isLogReader)
        {
            //For making sure there is no bug
            int variantCountinBuild = 0;

            //Read EditorLog
            string                fromtext    = startTimeStamp;
            string                totext      = startTimeStamp.Replace(SVL.buildProcessIDTitleStart, SVL.buildProcessIDTitleEnd);
            string                currentLine = "";
            bool                  startFound  = false;
            bool                  endFound    = false;
            FileStream            fs          = new FileStream(editorLogPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            List <CompiledShader> compiledShaderInfoFromEditorLog = new List <CompiledShader>();

            using (StreamReader sr = new StreamReader(fs))
            {
                while (!startFound)
                {
                    currentLine = sr.ReadLine();
                    if (currentLine.Contains(fromtext))
                    {
                        startFound = true;
                    }
                }
                while (!endFound)
                {
                    currentLine = sr.ReadLine();
                    if (currentLine.Contains(totext))
                    {
                        endFound = true;
                    }
                    else
                    {
                        if (currentLine.Contains("Compiling shader "))
                        {
                            //Shader name
                            string shaderName = Helper.ExtractString(currentLine, "Compiling shader ", " pass ");
                            shaderName = shaderName.Replace("\"", "");

                            //Shader pass
                            string passName = Helper.ExtractString(currentLine, " pass ", "\" (");
                            passName = passName.Replace("\"", "");

                            //Shader program e.g. vert / frag
                            string programName = Helper.ExtractString(currentLine, passName + "\" (", "");
                            programName = programName.Replace("\"", "").Replace(")", "");

                            //skip the line bla bla bla prepared
                            currentLine = sr.ReadLine();
                            while (!currentLine.Contains("variants left after stripping, "))
                            {
                                currentLine = sr.ReadLine();
                            }

                            //remaining variant & stripping time
                            string remainingVariant    = Helper.ExtractString(currentLine, "", " / ");
                            int    remainingVariantInt = int.Parse(remainingVariant);

                            //total variant
                            string totalVariant = Helper.ExtractString(currentLine, "/ ", " variants");
                            totalVariant = totalVariant.Replace(" ", "");
                            int totalVariantInt = int.Parse(totalVariant);

                            //stripping time
                            string strippingTime = Helper.ExtractString(currentLine, "variants left after stripping, processed in ", " seconds");

                            //jump to line of compilation time
                            if (remainingVariantInt > 0)
                            {
                                currentLine = sr.ReadLine();
                                while (!currentLine.Contains("finished in ") || currentLine.Contains("variants ready"))
                                {
                                    currentLine = sr.ReadLine();
                                }
                            }

                            //compilation time and compiled variant count (time is faster if there are cached variants)
                            string remainingText    = currentLine;
                            string startString      = "";
                            string endString        = "";
                            string compileTime      = "0.00";
                            string compiledVariants = "0";
                            string localCache       = "0";
                            string remoteCache      = "0";
                            if (remainingVariantInt > 0)
                            {
                                //Compile time
                                startString   = "finished in ";
                                endString     = " seconds. ";
                                compileTime   = Helper.ExtractString(remainingText, startString, endString, false);
                                compileTime   = compileTime.Replace(" ", "");
                                remainingText = Helper.GetRemainingString(remainingText, endString);

                                //Local cache hit
                                startString   = "Local cache hits ";
                                endString     = " (";
                                localCache    = Helper.ExtractString(remainingText, startString, endString, false);
                                localCache    = localCache.Replace(" ", "");
                                remainingText = Helper.GetRemainingString(remainingText, endString);

                                //Remote cache hit
                                startString   = "remote cache hits ";
                                endString     = " (";
                                remoteCache   = Helper.ExtractString(remainingText, startString, endString, false);
                                remoteCache   = remoteCache.Replace(" ", "");
                                remainingText = Helper.GetRemainingString(remainingText, endString);

                                //Compiled variants
                                startString      = "), compiled ";
                                endString        = " variants (";
                                compiledVariants = Helper.ExtractString(remainingText, startString, endString, false);
                                compiledVariants = compiledVariants.Replace(" ", "");
                                remainingText    = Helper.GetRemainingString(remainingText, endString);
                            }
                            int   compiledVariantsInt = int.Parse(compiledVariants);
                            int   localCacheInt       = int.Parse(localCache);
                            int   remoteCacheInt      = int.Parse(remoteCache);
                            float strippingTimeFloat  = float.Parse(strippingTime);
                            float compileTimeFloat    = float.Parse(compileTime);
                            //---------- Temp object info ------------//
                            CompiledShader temp = new CompiledShader();
                            temp.name = shaderName;
                            temp.editorLog_originalVariantCount  = totalVariantInt;
                            temp.editorLog_compiledVariantCount  = compiledVariantsInt;
                            temp.editorLog_totalProcessTime      = strippingTimeFloat + compileTimeFloat;
                            temp.editorLog_remainingVariantCount = remainingVariantInt;
                            temp.editorLog_variantInCacheCount   = localCacheInt + remoteCacheInt;
                            //---------- Add to temp list ------------//
                            int templistID = compiledShaderInfoFromEditorLog.IndexOf(compiledShaderInfoFromEditorLog.Find(x => x.name.Equals(temp.name)));
                            if (templistID == -1)
                            {
                                //Add a new shader record
                                compiledShaderInfoFromEditorLog.Add(temp);
                            }
                            else
                            {
                                //Add to existing shader record
                                compiledShaderInfoFromEditorLog[templistID] = AccumulateToCompiledShader(temp, compiledShaderInfoFromEditorLog[templistID]);
                            }

                            //Debug
                            // if(shaderName == "Universal Render Pipeline/Lit")
                            // {
                            //     string debugText = shaderName +"-"+ passName +"-"+ programName + "\n";
                            //     debugText += totalVariant +"-"+ remainingVariant +"-time-"+ strippingTime + "\n";
                            //     debugText += compileTime +"-"+ compiledVariants + "\n";
                            //     DebugLog(debugText);
                            // }
                        }
                    }
                }
            }

            if (!isLogReader)
            {
                for (int i = 0; i < compiledShaderInfoFromEditorLog.Count; i++)
                {
                    int listID = SVL.shaderlist.IndexOf(SVL.shaderlist.Find(x => x.name.Equals(compiledShaderInfoFromEditorLog[i].name)));
                    SVL.shaderlist[listID] = AccumulateToCompiledShader(compiledShaderInfoFromEditorLog[i], SVL.shaderlist[listID]);
                    //---------- For total countinvariantInCacheg ------------//
                    SVL.variantBeforeStrippingCount += compiledShaderInfoFromEditorLog[i].editorLog_originalVariantCount;
                    SVL.variantCompiledCount        += compiledShaderInfoFromEditorLog[i].editorLog_compiledVariantCount;
                    SVL.variantInCache  += compiledShaderInfoFromEditorLog[i].editorLog_variantInCacheCount;
                    variantCountinBuild += compiledShaderInfoFromEditorLog[i].editorLog_remainingVariantCount; //for making sure no bug
                }

                //Bug check - in case my codes in OnProcessShader VS reading EditorLog counts different result
                if (SVL.variantFromShader != variantCountinBuild)
                {
                    Debug.LogError("ShaderVariantTool error. " +
                                   "Tool counted there are " + SVL.variantFromShader + " shader variants in build, " +
                                   "but Editor Log counted " + variantCountinBuild + ". Please contact @mingwai on slack.");
                }
                int variantCacheAndCompiledSum = SVL.variantInCache + SVL.variantCompiledCount;
                if (variantCacheAndCompiledSum != variantCountinBuild)
                {
                    Debug.LogError("ShaderVariantTool error. " +
                                   "The sum of shader variants in EditorLog (" + variantCacheAndCompiledSum + " = " + SVL.variantInCache + " in cache + " +
                                   SVL.variantCompiledCount + " compiled) is not equal to the sum of shader variants collected by ShaderVariantTool (" +
                                   variantCountinBuild + "). Please contact @mingwai on slack. This could be related to exisiting known issue: Case 1389276");
                }

                //Print invalid / disabled keyword error
                if (SVL.invalidKey != "")
                {
                    Debug.LogError("Some shader keywords are invalid: " + SVL.invalidKey);
                }
                if (SVL.disabledKey != "")
                {
                    Debug.LogWarning("Some shader keywords are disabled but they are not being stripped: " + SVL.disabledKey);
                }
            }

            return(compiledShaderInfoFromEditorLog);
        }
Example #5
0
        // public void Awake()
        // {
        // }

        // public void OnDestroy()
        // {
        // }

        void OnGUI()
        {
            Color originalBackgroundColor = GUI.backgroundColor;

            //Width for the columns & style
            float    currentSize  = this.position.width;
            float    widthForEach = currentSize / (SVL.columns.Length - 1 + currentSize * 0.0002f);
            GUIStyle background   = new GUIStyle
            {
                normal =
                {
                    background = Texture2D.whiteTexture,
                    textColor  = Color.white
                }
            };

            //Title
            GUI.color = Color.cyan;
            GUILayout.Label("Build the player and see the variants list here.", EditorStyles.wordWrappedLabel);
            ShaderVariantTool_BuildPreprocess.deletePlayerCacheBeforeBuild = GUILayout.Toggle(ShaderVariantTool_BuildPreprocess.deletePlayerCacheBeforeBuild, "Delete PlayerCache Before Build");
            GUILayout.Space(10);
            GUI.color = Color.white;

            if (savedFile != "")
            {
                GUI.color = Color.green;

                GUILayout.Label("Build Time: " + SVL.buildTimeString, EditorStyles.wordWrappedLabel);

                GUILayout.Space(5);

                //Result - Shader
                GUI.color = Color.white;
                GUILayout.Label("Shader", EditorStyles.boldLabel);
                GUILayout.Label("Shader Count: " + SVL.normalShaderCount, EditorStyles.wordWrappedLabel);
                GUILayout.Label("Shader Variant Count before Stripping: " + SVL.variantBeforeStrippingCount, EditorStyles.wordWrappedLabel);
                GUILayout.Label("Shader Variant Count in Build: " + SVL.variantFromShader +
                                " (cached:" + SVL.variantInCache + " compiled:" + SVL.variantCompiledCount + ")", EditorStyles.wordWrappedLabel);

                GUILayout.Space(5);

                //Result - ComputeShader
                GUI.color = Color.white;
                GUILayout.Label("ComputeShader", EditorStyles.boldLabel);
                GUILayout.Label("ComputeShader Count: " + SVL.computeShaderCount, EditorStyles.wordWrappedLabel);
                GUILayout.Label("ComputeShader Variant Count in Build: " + SVL.variantFromCompute, EditorStyles.wordWrappedLabel);

                GUILayout.Space(10);

                //Saved file path
                GUI.color = Color.green;
                GUILayout.Label("Saved: " + savedFile, EditorStyles.wordWrappedLabel);

                //Show folder button
                GUI.color = Color.white;
                if (GUILayout.Button("Show in explorer", GUILayout.Width(200)))
                {
                    EditorUtility.RevealInFinder(savedFile.Replace(@"/", @"\"));
                    //System.Diagnostics.Process.Start("explorer.exe", "/select,"+savedFile.Replace(@"/", @"\")); // explorer doesn't like front slashes
                }
            }
            GUI.color = Color.white;
            GUILayout.Space(15);

            //Column Titles
            EditorGUILayout.BeginHorizontal();
            for (int i = 1; i < SVL.columns.Length; i++)
            {
                int al = i % 2;
                GUI.backgroundColor = al == 0 ? columnColor1 :columnColor2;
                GUILayoutOption[] columnLayoutOption = new GUILayoutOption[]
                {
                    GUILayout.Width(Mathf.RoundToInt(widthForEach * widthScale[i])),
                    GUILayout.Height(55)
                };
                EditorGUILayout.LabelField(SVL.columns[i].Replace(" ", "\n"), background, columnLayoutOption);
            }
            EditorGUILayout.EndHorizontal();

            //Reset color
            GUI.backgroundColor = originalBackgroundColor;
            GUI.color           = Color.white;

            //Scroll Start
            scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(0), GUILayout.Height(0));

            //Display result
            if (SVL.shaderlist.Count > 0 && SVL.rowData.Count > 0)
            {
                for (int k = 1; k < SVL.rowData.Count; k++) //first row is title so start with 1
                {
                    string         shaderName    = SVL.rowData[k][0];
                    int            shaderIndex   = SVL.shaderlist.FindIndex(o => o.name == shaderName);
                    CompiledShader currentShader = SVL.shaderlist[shaderIndex];

                    if (shaderName != SVL.rowData[k - 1][0]) //show title
                    {
                        GUI.backgroundColor         = originalBackgroundColor;
                        currentShader.guiEnabled    = EditorGUILayout.Foldout(currentShader.guiEnabled, shaderName + " (" + currentShader.noOfVariantsForThisShader + ")");
                        SVL.shaderlist[shaderIndex] = currentShader;
                    }

                    //Show the shader variants
                    if (currentShader.guiEnabled)
                    {
                        EditorGUILayout.BeginHorizontal();
                        for (int i = 1; i < SVL.columns.Length; i++)
                        {
                            string t = SVL.rowData[k][i];

                            int al = i % 2;
                            GUI.backgroundColor = al == 0 ? columnColor1 :columnColor2;
                            if (t == "True")
                            {
                                background.normal.textColor = Color.green;
                            }
                            else if (t == "False")
                            {
                                background.normal.textColor = Color.red;
                            }
                            else if (t.Contains("[Global]"))
                            {
                                background.normal.textColor = Color.cyan;
                            }
                            else if (t.Contains("[Local]"))
                            {
                                background.normal.textColor = Color.yellow;
                            }
                            else
                            {
                                background.normal.textColor = Color.white;
                            }

                            EditorGUILayout.LabelField(t, background, GUILayout.Width(widthForEach * widthScale[i]));
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    GUI.backgroundColor = originalBackgroundColor;
                }
            }

            //Scroll End
            GUILayout.FlexibleSpace();
            GUILayout.EndScrollView();
            EditorGUILayout.Separator();
        }
        public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList <ShaderCompilerData> data)
        {
            int newVariantsForThisShader = 0;

            //The real variant count
            newVariantsForThisShader += data.Count;

            //Go through all the variants
            for (int i = 0; i < data.Count; ++i)
            {
                ShaderKeyword[] sk = data[i].shaderKeywordSet.GetShaderKeywords();

                //The default variant
                if (sk.Length == 0)
                {
                    CompiledShaderVariant scv_default = new CompiledShaderVariant();
                    //scv.id = id;
                    scv_default.shaderName             = shader.name;
                    scv_default.passName               = snippet.passName;
                    scv_default.passType               = snippet.passType.ToString();
                    scv_default.shaderType             = snippet.shaderType.ToString();
                    scv_default.kernelName             = "--";
                    scv_default.graphicsTier           = "--";
                    scv_default.buildTarget            = "--";
                    scv_default.shaderCompilerPlatform = "--";
                    //scv_default.shaderRequirements = "--";
                    scv_default.platformKeywords  = "--";
                    scv_default.shaderKeywordName = "No Keyword / All Off";
                    scv_default.shaderKeywordType = "--";
                    SVL.variantlist.Add(scv_default);
                    SVL.compiledTotalCount++;
                }

                for (int k = 0; k < sk.Length; ++k)
                {
                    CompiledShaderVariant scv = new CompiledShaderVariant();

                    //scv.id = id;
                    scv.shaderName = shader.name;
                    scv.passName   = snippet.passName;
                    scv.passType   = snippet.passType.ToString();
                    scv.shaderType = snippet.shaderType.ToString();
                    scv.kernelName = "--";

                    scv.graphicsTier           = data[i].graphicsTier.ToString();
                    scv.buildTarget            = data[i].buildTarget.ToString();
                    scv.shaderCompilerPlatform = data[i].shaderCompilerPlatform.ToString();
                    //scv.shaderRequirements = data[i].shaderRequirements.ToString().Replace(",","\n");
                    scv.platformKeywords = Helper.GetPlatformKeywordList(data[i].platformKeywordSet);

                    bool         isLocal   = ShaderKeyword.IsKeywordLocal(sk[k]);
                    LocalKeyword lkey      = new LocalKeyword(shader, sk[k].name);
                    bool         isDynamic = lkey.isDynamic;
                    scv.shaderKeywordName = (isLocal? "[Local]" : "[Global]") + (isDynamic? "[Dynamic] " : " ") + sk[k].name; //sk[k].GetKeywordName();
                    scv.shaderKeywordType = isLocal? "--" : ShaderKeyword.GetGlobalKeywordType(sk[k]).ToString();             //""+sk[k].GetKeywordType().ToString();
                    if (!sk[k].IsValid())
                    {
                        SVL.invalidKey += "\n" + "Shader " + scv.shaderName + " Keyword " + scv.shaderKeywordName + " is invalid.";
                    }
                    if (!data[i].shaderKeywordSet.IsEnabled(sk[k]))
                    {
                        SVL.disabledKey += "\n" + "Shader " + scv.shaderName + " Keyword " + scv.shaderKeywordName + " is not enabled. You can create a custom shader stripping script to strip it.";
                    }

                    SVL.variantlist.Add(scv);
                    SVL.compiledTotalCount++;

                    //Just to verify API is correct
                    //string globalShaderKeywordName = ShaderKeyword.GetGlobalKeywordName(sk[k]);
                    //if( !isLocal && globalShaderKeywordName != ShaderKeyword.GetKeywordName(shader,sk[k]) ) Debug.LogError("Bug. ShaderKeyword.GetGlobalKeywordName() and  ShaderKeyword.GetKeywordName() is wrong");
                    //ShaderKeywordType globalShaderKeywordType = ShaderKeyword.GetGlobalKeywordType(sk[k]);
                    //if( !isLocal && globalShaderKeywordType != ShaderKeyword.GetKeywordType(shader,sk[k]) ) Debug.LogError("Bug. ShaderKeyword.GetGlobalKeywordType() and  ShaderKeyword.GetKeywordType() is wrong");
                }
            }

            //Add to shader list
            int compiledShaderId = SVL.shaderlist.FindIndex(o => o.name == shader.name);

            if (compiledShaderId == -1)
            {
                CompiledShader newCompiledShader = new CompiledShader();
                newCompiledShader.name       = shader.name;
                newCompiledShader.guiEnabled = false;
                newCompiledShader.noOfVariantsForThisShader = 0;
                SVL.shaderlist.Add(newCompiledShader);
                compiledShaderId = SVL.shaderlist.Count - 1;
            }

            //Add variant count to shader
            CompiledShader compiledShader = SVL.shaderlist[compiledShaderId];

            compiledShader.noOfVariantsForThisShader += newVariantsForThisShader;
            SVL.shaderlist[compiledShaderId]          = compiledShader;

            //Add to total count
            SVL.variantTotalCount += newVariantsForThisShader;
        }