Пример #1
0
        void OnGUI_BuildReportToolbar(List <GUIAction> actions, Func <IAsyncJob> buildReportJob, Object asset, PlatformJob capability)
        {
            if (m_AssetMetadata == null)
            {
                return;
            }

            var assetGUID = ShaderAnalysisUtils.CalculateGUIDFor(asset);
            var report    = m_AssetMetadata.GetReport(assetGUID);

            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            {
                EditorGUILayout.LabelField("Reporting", EditorStyles.whiteLargeLabel, GUILayout.Width(75));

                GUI.enabled = EditorShaderTools.DoesPlatformSupport(m_CurrentPlatform, capability);
                if (GUILayout.Button(EditorGUIUtility.TrIconContent("PlayButton On", "Build Report"), EditorStyles.toolbarButton, GUILayout.Width(k_IconSize)))
                {
                    actions.Add(new GUIAction(GUIActionKind.BuildReportJob, buildReportJob, asset));
                }
                m_BuildReportFeature = (BuildReportFeature)EditorGUILayout.EnumFlagsField(m_BuildReportFeature, GUILayout.Width(80));

                GUILayout.Space(k_HorizontalSpacing);

                var genDir = ShaderAnalysisUtils.GetTemporaryDirectory(asset, m_CurrentPlatform);
                GUI.enabled = genDir.Exists;
                if (GUILayout.Button(EditorGUIUtility.TrIconContent("Project", "Open Temp Dir"), EditorStyles.toolbarButton, GUILayout.Width(k_IconSize)))
                {
                    Application.OpenURL(genDir.FullName);
                }

                GUILayout.Space(k_HorizontalSpacing);

                GUI.enabled = report != null && ExporterUtilities.IsValid(m_ReportExporterIndex);
                if (GUILayout.Button(EditorGUIUtility.TrIconContent("SceneLoadOut", "Export to"), EditorStyles.toolbarButton, GUILayout.Width(k_IconSize)))
                {
                    actions.Add(new GUIAction(GUIActionKind.ExportReport, asset));
                }
                GUI.enabled           = true;
                m_ReportExporterIndex =
                    (ReportExporterIndex)EditorGUILayout.Popup((int)m_ReportExporterIndex,
                                                               ExporterUtilities.ReportExporterNames, GUILayout.Width(k_ExporterSize));
            }
            GUILayout.EndHorizontal();
            GUI.enabled = true;
        }
        void OnBuildReportJobComplete(IAsyncJob obj)
        {
            var asset = m_JobAssets[obj];

            m_JobAssets.Remove(obj);

            var job = obj as AsyncBuildReportJob;

            Assert.IsNotNull(job);

            ShaderBuildReport report = null;

            if (job.IsComplete() &&
                job.hasReport &&
                (report = job.builtReport) != null)
            {
                var metadata  = ShaderAnalysisUtils.LoadAssetMetadatasFor(job.target);
                var assetGUID = ShaderAnalysisUtils.CalculateGUIDFor(asset);
                metadata.SetReport(assetGUID, report);
                ShaderAnalysisUtils.SaveAssetMetadata(metadata);
            }
        }
        void OnGUI_DiffReportToolbar(List <GUIAction> actions, Object asset)
        {
            if (m_AssetMetadata == null)
            {
                return;
            }

            var assetGUID       = ShaderAnalysisUtils.CalculateGUIDFor(asset);
            var report          = m_AssetMetadata.GetReport(assetGUID);
            var reportReference = m_AssetMetadataReference != null?m_AssetMetadataReference.GetReport(assetGUID) : null;

            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            {
                EditorGUILayout.LabelField("Diff", EditorStyles.whiteLargeLabel, GUILayout.Width(55));

                GUI.enabled = report != null;
                if (GUILayout.Button(EditorGUIUtility.TrIconContent("SceneLoadIn", "Set as reference"), EditorStyles.toolbarButton, GUILayout.Width(k_IconSize)))
                {
                    actions.Add(new GUIAction(GUIActionKind.SetAsReference, assetGUID, report));
                }

                GUILayout.Space(k_HorizontalSpacing);

                GUI.enabled = report != null && reportReference != null && ExporterUtilities.IsValid(m_ReportDiffExporterIndex);
                if (GUILayout.Button(EditorGUIUtility.TrIconContent("SceneLoadOut", "Export diff to"), EditorStyles.toolbarButton, GUILayout.Width(k_IconSize)))
                {
                    actions.Add(new GUIAction(GUIActionKind.ExportDiffReport, report, reportReference, assetGUID));
                }
                GUI.enabled = true;
                m_ReportDiffExporterIndex =
                    (ReportDiffExporterIndex)EditorGUILayout.Popup((int)m_ReportDiffExporterIndex,
                                                                   ExporterUtilities.ReportDiffExporterNames, GUILayout.Width(k_ExporterSize));
            }
            GUILayout.EndHorizontal();
            GUI.enabled = true;
        }
        void OnGUI_DisplayLogResults(Object asset)
        {
            if (m_AssetMetadata == null)
            {
                return;
            }

            var assetGUID = ShaderAnalysisUtils.CalculateGUIDFor(asset);
            var report    = m_AssetMetadata.GetReport(assetGUID);

            if (report == null)
            {
                return;
            }

            var reportReference = m_AssetMetadataReference != null?m_AssetMetadataReference.GetReport(assetGUID) : null;

            EditorGUILayout.LabelField(string.Format("Skipped passes: {0}", report.skippedPasses.Aggregate(string.Empty, (s, v) => s += " " + v.Value)));

            m_BuildScrollPosition = GUILayout.BeginScrollView(m_BuildScrollPosition);
            EditorGUILayout.LabelField(UIUtils.Text(String.Format("Passes: {0}, MultiCompiles: {1}", report.programs.Count, report.compileUnits.Count)));
            for (var i = 0; i < report.programs.Count; ++i)
            {
                var program          = report.programs[i];
                var programHash      = ComputeProgramHash(i);
                var isProgramFoldout = m_BuildReportCache.GetBool(programHash);
                GUILayout.BeginHorizontal();
                isProgramFoldout = EditorGUILayout.Foldout(isProgramFoldout, UIUtils.Text(program.name), true);
                GUILayout.FlexibleSpace();

                if (program.compileErrors > 0)
                {
                    GUILayout.Box(EditorGUIUtility.IconContent("console.erroricon"), GUILayout.Width(16), GUILayout.Height(EditorGUIUtility.singleLineHeight));
                }
                if (program.compileWarnings > 0)
                {
                    GUILayout.Box(EditorGUIUtility.IconContent("console.warnicon"), GUILayout.Width(16), GUILayout.Height(EditorGUIUtility.singleLineHeight));
                }
                GetProgramToolbar(m_CurrentPlatform)(asset, report, program, reportReference, assetGUID);
                GUILayout.EndHorizontal();
                m_BuildReportCache.Set(programHash, isProgramFoldout);

                if (isProgramFoldout)
                {
                    ++EditorGUI.indentLevel;
                    EditorGUILayout.LabelField(UIUtils.Text(string.Format("{0} multicompiles", program.multicompiles.Length)));
                    EditorGUILayout.LabelField(UIUtils.Text(string.Format("{0} multicompiles sets", program.multicompileCombinations.Length)));

                    foreach (var cu in program.compileUnits)
                    {
                        var pu = cu.performanceUnit;
                        if (pu == null)
                        {
                            continue;
                        }

                        var cuHash = ComputeCompileUnitHash(programHash, cu.multicompileIndex);

                        GUILayout.BeginHorizontal();
                        var multiCompileFoldout = m_BuildReportCache.GetBool(cuHash);
                        multiCompileFoldout = EditorGUILayout.Foldout(multiCompileFoldout, UIUtils.Text(string.Join(" ", cu.defines)), true);
                        GUILayout.FlexibleSpace();
                        GetUnitToolbar(m_CurrentPlatform)(asset, report, program, cu, pu, pu.parsedReport, reportReference, assetGUID);
                        m_BuildReportCache.Set(cuHash, multiCompileFoldout);

                        if (cu.errors.Length > 0)
                        {
                            GUILayout.Box(EditorGUIUtility.IconContent("console.erroricon"), GUILayout.Width(16), GUILayout.Height(EditorGUIUtility.singleLineHeight));
                        }
                        if (cu.warnings.Length > 0)
                        {
                            GUILayout.Box(EditorGUIUtility.IconContent("console.warnicon"), GUILayout.Width(16), GUILayout.Height(EditorGUIUtility.singleLineHeight));
                        }
                        GUILayout.EndHorizontal();

                        if (multiCompileFoldout)
                        {
                            ++EditorGUI.indentLevel;

                            var perfs = pu.parsedReport;
                            EditorGUILayout.LabelField(UIUtils.Text("Performances"));
                            EditorGUILayout.LabelField(UIUtils.Text("Shader microcode size: {0} bytes", perfs.microCodeSize));
                            EditorGUILayout.LabelField(UIUtils.Text("VGPR count: {0} ({1} used)", perfs.VGPRCount, perfs.VGPRUsedCount));
                            EditorGUILayout.LabelField(UIUtils.Text("SGPR count: {0} ({1} used)", perfs.SGPRCount, perfs.SGPRUsedCount));
                            EditorGUILayout.LabelField(UIUtils.Text("User SGPR count: {0}", perfs.UserSGPRCount));
                            EditorGUILayout.LabelField(UIUtils.Text("LDS Size: {0} bytes", perfs.LDSSize));
                            EditorGUILayout.LabelField(UIUtils.Text("Threadgroup waves: {0}", perfs.threadGroupWaves));
                            EditorGUILayout.LabelField(UIUtils.Text("CU Occupancy: {0}/{1}", perfs.CUOccupancyCount, perfs.CUOccupancyMax));
                            EditorGUILayout.LabelField(UIUtils.Text("SIMD Occupancy: {0}/{1}", perfs.SIMDOccupancyCount, perfs.SIMDOccupancyMax));

                            foreach (var error in cu.errors)
                            {
                                EditorGUILayout.HelpBox(error.message, MessageType.Error);
                                GUILayout.Box(UIUtils.Text(UIUtils.ClampText(string.Join("\n", error.stacktrace))), EditorStyles.helpBox);
                            }
                            foreach (var warning in cu.warnings)
                            {
                                EditorGUILayout.HelpBox(UIUtils.ClampText(warning.message), MessageType.Warning);
                                GUILayout.Box(UIUtils.Text(UIUtils.ClampText(string.Join("\n", warning.stacktrace))), EditorStyles.helpBox);
                            }
                            --EditorGUI.indentLevel;
                        }
                    }
                    --EditorGUI.indentLevel;
                }
            }
            GUILayout.EndScrollView();
        }