public ShaderVariantTool_ComputePreprocess() { SVL.ResetBuildList(); }
public void OnPreprocessBuild(BuildReport report) { DeletePlayerCacheBeforeBuild(); SVL.ResetBuildList(); SVL.buildTime = EditorApplication.timeSinceStartup; }
public void OnPostprocessBuild(BuildReport report) { //For reading EditorLog, we can extract the contents Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, SVL.buildProcessIDTitleEnd + SVL.buildProcessID); //Because of the new incremental build changes, Development build won't trigger OnShaderProcess - 1338940 if (SVL.shaderlist.Count == 0) { Debug.LogError("No shader or variant are logged. Please turn ON Delete PlayerCache Before Build checkbox in Window > ShaderVariantTool."); } //Calculate shader count by type SVL.normalShaderCount = SVL.shaderlist.Count - SVL.computeShaderCount; SVL.variantFromShader = SVL.variantTotalCount - SVL.variantFromCompute; //Reading EditorLog ReadShaderCompileInfo(); //Calculate build time SVL.buildTime = EditorApplication.timeSinceStartup - SVL.buildTime; SVL.buildTimeString = Helper.TimeFormatString(SVL.buildTime); //Sort the results and make row data SVL.Sorting(); //Prepare CSV string List <string[]> outputRows = new List <string[]>(); //Get Unity & branch version string version_changeset = Convert.ToString(InternalEditorUtility.GetUnityRevision(), 16); string version_branch = InternalEditorUtility.GetUnityBuildBranch(); string unity_version = Application.unityVersion + " " + version_branch + " (" + version_changeset + ")"; //Get Graphics API list var gfxAPIsList = PlayerSettings.GetGraphicsAPIs(report.summary.platform); string gfxAPIs = ""; for (int i = 0; i < gfxAPIsList.Length; i++) { gfxAPIs += gfxAPIsList[i].ToString() + " "; } //Build size var buildSize = report.summary.totalSize / 1024; //Write Overview Result outputRows.Add(new string[] { "Unity", unity_version }); outputRows.Add(new string[] { "Platform", report.summary.platform.ToString() }); outputRows.Add(new string[] { "Graphics API", gfxAPIs }); outputRows.Add(new string[] { "Build Path", report.summary.outputPath }); outputRows.Add(new string[] { "Build Size (Kb)", buildSize.ToString() }); //outputRows.Add( new string[] { "Build Time (seconds)" , ""+report.summary.totalTime } ); outputRows.Add(new string[] { "Build Time", SVL.buildTimeString }); //Write Overview - Shader //outputRows.Add( new string[] { "Shaders ----------------------------------" } ); outputRows.Add(new string[] { "Shader Count", SVL.normalShaderCount.ToString() }); outputRows.Add(new string[] { "Shader Variant Count before Stripping", SVL.variantBeforeStrippingCount.ToString() }); outputRows.Add(new string[] { "Shader Variant Count in Build", SVL.variantFromShader + " (cached:" + SVL.variantInCache + " compiled:" + SVL.variantCompiledCount + ")" }); //Write Overview - Compute //outputRows.Add( new string[] { "ComputeShaders ----------------------------------" } ); outputRows.Add(new string[] { "ComputeShader Count", SVL.computeShaderCount.ToString() }); outputRows.Add(new string[] { "ComputeShader Variant Count in Build", SVL.variantFromCompute.ToString() }); //outputRows.Add( new string[] { "Total Data Count" , ""+SVL.compiledTotalCount } ); outputRows.Add(new string[] { "" }); //Write Shader Result outputRows.Add(new string[] { "Shader", "Variant Count before Stripping", "Variant in Cache", "Compiled Variant Count", "Variant Count in Build", "Stripping+Compilation Time" }); for (int i = 0; i < SVL.shaderlist.Count; i++) { outputRows.Add(new string[] { SVL.shaderlist[i].name, SVL.shaderlist[i].editorLog_originalVariantCount.ToString(), SVL.shaderlist[i].editorLog_variantInCacheCount.ToString(), SVL.shaderlist[i].editorLog_compiledVariantCount.ToString(), SVL.shaderlist[i].noOfVariantsForThisShader.ToString(), //SVL.shaderlist[i].editorLog_renamingVariantCount.ToString(), Helper.TimeFormatString(SVL.shaderlist[i].editorLog_totalProcessTime) }); } outputRows.Add(new string[] { "" }); //Write Each variant Result for (int i = 0; i < SVL.rowData.Count; i++) { outputRows.Add(SVL.rowData[i]); } //Prepare CSV string int length = outputRows.Count; string delimiter = ","; StringBuilder sb = new StringBuilder(); for (int index = 0; index < length; index++) { sb.AppendLine(string.Join(delimiter, outputRows[index])); } //Write to CSV file ShaderVariantTool.folderPath = Application.dataPath.Replace("/Assets", "/"); ShaderVariantTool.savedFile = ShaderVariantTool.folderPath + "ShaderVariants_" + DateTime.Now.ToString("yyyyMMdd_hh-mm-ss") + ".csv"; StreamWriter outStream = System.IO.File.CreateText(ShaderVariantTool.savedFile); outStream.WriteLine(sb); outStream.Close(); //CleanUp outputRows.Clear(); SVL.buildProcessStarted = false; }
public void OnPostprocessBuild(BuildReport report) { //For reading EditorLog, we can extract the contents Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, SVL.buildProcessIDTitleEnd + SVL.buildProcessID); //Because of the new incremental build changes, Development build won't trigger OnShaderProcess - 1338940 if (SVL.shaderlist.Count == 0) { Debug.LogError("No shader or variant are logged. Please go to Window > ShaderVariantTool > turn ON Delete PlayerCache Before Build checkbox."); } //Calculate shader count by type SVL.normalShaderCount = SVL.shaderlist.Count - SVL.computeShaderCount; SVL.variantFromShader = SVL.variantTotalCount - SVL.variantFromCompute; //Reading EditorLog string editorLogPath = Helper.GetEditorLogPath(); ReadShaderCompileInfo(SVL.buildProcessIDTitleStart + SVL.buildProcessID, editorLogPath, false); //Calculate build time SVL.buildTime = EditorApplication.timeSinceStartup - SVL.buildTime; SVL.buildTimeString = Helper.TimeFormatString(SVL.buildTime); //Sort the results and make row data SVL.Sorting(); //Prepare CSV string List <string[]> outputRows = new List <string[]>(); //Get Unity & branch version string version_changeset = Convert.ToString(InternalEditorUtility.GetUnityRevision(), 16); string version_branch = InternalEditorUtility.GetUnityBuildBranch(); string unity_version = Application.unityVersion + " " + version_branch + " (" + version_changeset + ")"; //Get Graphics API list var gfxAPIsList = PlayerSettings.GetGraphicsAPIs(report.summary.platform); string gfxAPIs = ""; for (int i = 0; i < gfxAPIsList.Length; i++) { gfxAPIs += gfxAPIsList[i].ToString() + " "; } //Build size var buildSize = report.summary.totalSize / 1024; //Write Overview Result outputRows.Add(new string[] { "Unity", unity_version }); outputRows.Add(new string[] { "Platform", report.summary.platform.ToString() }); outputRows.Add(new string[] { "Graphics API", gfxAPIs }); outputRows.Add(new string[] { "Build Path", report.summary.outputPath }); outputRows.Add(new string[] { "Build Size (Kb)", buildSize.ToString() }); //outputRows.Add( new string[] { "Build Time (seconds)" , ""+report.summary.totalTime } ); outputRows.Add(new string[] { "Build Time", SVL.buildTimeString }); //Write Overview - Shader //outputRows.Add( new string[] { "Shaders ----------------------------------" } ); outputRows.Add(new string[] { "Shader Count", SVL.normalShaderCount.ToString() }); outputRows.Add(new string[] { "Shader Variant Count before Stripping", SVL.variantBeforeStrippingCount.ToString() }); outputRows.Add(new string[] { "Shader Variant Count in Build", SVL.variantFromShader + " (cached:" + SVL.variantInCache + " compiled:" + SVL.variantCompiledCount + ")" }); //Write Overview - Compute //outputRows.Add( new string[] { "ComputeShaders ----------------------------------" } ); outputRows.Add(new string[] { "ComputeShader Count", SVL.computeShaderCount.ToString() }); outputRows.Add(new string[] { "ComputeShader Variant Count in Build", SVL.variantFromCompute.ToString() }); outputRows.Add(new string[] { "" }); //Write Shader Result from Editor Log outputRows = AddEditorLogShaderInfo(outputRows, SVL.shaderlist); outputRows.Add(new string[] { "" }); //Write Each variant Result for (int i = 0; i < SVL.rowData.Count; i++) { outputRows.Add(SVL.rowData[i]); } //Save File string fileName = "ShaderVariants_" + DateTime.Now.ToString("yyyyMMdd_hh-mm-ss"); ShaderVariantTool.savedFile = SaveCSVFile(outputRows, fileName); //CleanUp outputRows.Clear(); //Let user know the tool has successfully done it's job Debug.Log("Build is done and ShaderVariantTool has done gathering data. Find the details on Windows > ShaderVariantTool, or look at the generated CSV report at: " + ShaderVariantTool.savedFile); SVL.buildProcessStarted = false; }