void MemoryCentricView(LightmapData[] lightmaps, bool showDirLightmap, bool showShadowMask, GlobalMapsViewType viewType)
        {
            Lightmapping.ResetExplicitlyShownMemLabels();

            Dictionary <Hash128, SortedList <int, int> > gbufferHashToLightmapIndices = new Dictionary <Hash128, SortedList <int, int> >();

            for (int i = 0; i < lightmaps.Length; i++)
            {
                Hash128 gbufferHash;
                if (Lightmapping.GetGBufferHash(i, out gbufferHash))
                {
                    if (!gbufferHashToLightmapIndices.ContainsKey(gbufferHash))
                    {
                        gbufferHashToLightmapIndices.Add(gbufferHash, new SortedList <int, int>());
                    }

                    gbufferHashToLightmapIndices[gbufferHash].Add(i, i);
                }
            }

            float totalGBuffersSize  = 0.0f;
            float totalLightmapsSize = 0.0f;

            foreach (var entry in gbufferHashToLightmapIndices)
            {
                Hash128 gbufferHash     = entry.Key;
                float   gbufferDataSize = Lightmapping.GetGBufferMemory(ref gbufferHash);
                totalGBuffersSize += gbufferDataSize;

                SortedList <int, int> lightmapIndices = entry.Value;
                foreach (var i in lightmapIndices)
                {
                    LightmapMemory lightmapMemory = Lightmapping.GetLightmapMemory(i.Value);
                    totalLightmapsSize += lightmapMemory.lightmapDataSize;
                    totalLightmapsSize += lightmapMemory.lightmapTexturesSize;
                }
            }

            if (gbufferHashToLightmapIndices.Count > 0)
            {
                const bool toggleOnLabelClick = true;
                string     foldoutNameFull    = String.Format(
                    "G-buffers ({0}) | Lightmaps ({1})",
                    SizeString(totalGBuffersSize),
                    SizeString(totalLightmapsSize));
                bool showDetailsOld = EditorPrefs.GetBool(kEditorPrefsGBuffersLightmapsAlbedoEmissive, true);

                bool showDetails = EditorGUILayout.Foldout(showDetailsOld, foldoutNameFull, toggleOnLabelClick, s_Styles.boldFoldout);

                if (showDetails != showDetailsOld)
                {
                    EditorPrefs.SetBool(kEditorPrefsGBuffersLightmapsAlbedoEmissive, showDetails);
                }

                if (showDetails)
                {
                    foreach (var entry in gbufferHashToLightmapIndices)
                    {
                        GUILayout.BeginHorizontal();
                        {
                            GUILayout.Space(15);
                            GUILayout.BeginVertical();
                            {
                                Hash128 gbufferHash     = entry.Key;
                                float   gbufferDataSize = Lightmapping.GetGBufferMemory(ref gbufferHash);
                                GUILayout.Label(EditorGUIUtility.TrTextContent("G-buffer: " + gbufferDataSize.ToString("0.0") + " MB", gbufferHash.ToString()), EditorStyles.miniLabel, GUILayout.ExpandWidth(false));

                                SortedList <int, int> lightmapIndices = entry.Value;
                                foreach (var i in lightmapIndices)
                                {
                                    LightmapRow(i.Value, lightmaps, showDirLightmap, showShadowMask, viewType);
                                }
                            }
                            GUILayout.EndVertical();
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.Space(10);
                    }
                }
            }

            System.UInt64[] dummyCounts = new System.UInt64[0];
            {
                MemLabels labels = Lightmapping.GetTransmissionTexturesMemLabels();
                ShowObjectNamesSizesAndCounts("Transmission textures", kEditorPrefsTransmissionTextures, labels.labels, labels.sizes, dummyCounts, Precision.Tenths);
            }

            {
                MemLabels labels = Lightmapping.GetMaterialTexturesMemLabels();
                ShowObjectNamesSizesAndCounts("Albedo/emissive textures", kEditorPrefsMaterialTextures, labels.labels, labels.sizes, dummyCounts, Precision.Hundredths);
            }

            {
                GeoMemLabels labels = Lightmapping.GetGeometryMemory();
                ShowObjectNamesSizesAndCounts("Geometry data", kEditorPrefsGeometryData, labels.labels, labels.sizes, labels.triCounts, Precision.Hundredths);
            }

            {
                MemLabels labels = Lightmapping.GetNotShownMemLabels();
                string    remainingEntriesFoldoutName = Lightmapping.isProgressiveLightmapperDone ? "Leaks" : "In-flight";
                ShowObjectNamesSizesAndCounts(remainingEntriesFoldoutName, kEditorPrefsInFlight, labels.labels, labels.sizes, dummyCounts, Precision.Tenths);
            }
        }
示例#2
0
        private void DebugInfoSection(LightmapData[] lightmaps)
        {
            if (!showDebugInfo)
            {
                return;
            }

            Lightmapping.ResetExplicitlyShownMemLabels();
            float oldWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 400.0f;

            {
                float gpuMemory = Lightmapping.ComputeTotalGPUMemoryUsageInBytes();
                if (gpuMemory > 0.0f)
                {
                    string foldoutNameGPU = String.Format("Total GPU memory ({0})", SizeString(gpuMemory));
                    EditorGUILayout.FoldoutTitlebar(false, new GUIContent(foldoutNameGPU), true);
                }
            }

            {
                Dictionary <Hash128, SortedList <int, int> > gbufferHashToLightmapIndices = new Dictionary <Hash128, SortedList <int, int> >();
                for (int i = 0; i < lightmaps.Length; i++)
                {
                    Hash128 gbufferHash;
                    if (Lightmapping.GetGBufferHash(i, out gbufferHash))
                    {
                        if (!gbufferHashToLightmapIndices.ContainsKey(gbufferHash))
                        {
                            gbufferHashToLightmapIndices.Add(gbufferHash, new SortedList <int, int>());
                        }

                        gbufferHashToLightmapIndices[gbufferHash].Add(i, i);
                    }
                }

                float totalGBuffersSize  = 0.0f;
                float totalLightmapsSize = 0.0f;

                foreach (var entry in gbufferHashToLightmapIndices)
                {
                    Hash128 gbufferHash     = entry.Key;
                    float   gbufferDataSize = Lightmapping.GetGBufferMemory(ref gbufferHash);
                    totalGBuffersSize += gbufferDataSize;

                    SortedList <int, int> lightmapIndices = entry.Value;
                    foreach (var i in lightmapIndices)
                    {
                        LightmapMemory lightmapMemory = Lightmapping.GetLightmapMemory(i.Value);
                        totalLightmapsSize += lightmapMemory.lightmapDataSizeCPU;
                        totalLightmapsSize += lightmapMemory.lightmapTexturesSize;
                    }
                }

                string foldoutNameFull = String.Format(
                    "G-buffers ({0}) | Lightmaps ({1})",
                    SizeString(totalGBuffersSize),
                    SizeString(totalLightmapsSize));

                if (lightmaps.Length > 0)
                {
                    EditorGUILayout.FoldoutTitlebar(false, new GUIContent(foldoutNameFull), true);
                }
            }

            System.UInt64[] dummyCounts = new System.UInt64[0];
            {
                MemLabels labels = Lightmapping.GetTransmissionTexturesMemLabels();
                ShowObjectNamesSizesAndCounts("Transmission textures", kEditorPrefsTransmissionTextures, labels.labels, labels.sizes, dummyCounts);
            }

            {
                MemLabels labels = Lightmapping.GetMaterialTexturesMemLabels();
                ShowObjectNamesSizesAndCounts("Albedo/emissive textures", kEditorPrefsMaterialTextures, labels.labels, labels.sizes, dummyCounts);
            }

            {
                GeoMemLabels labels = Lightmapping.GetGeometryMemory();
                ShowObjectNamesSizesAndCounts("Geometry data", kEditorPrefsGeometryData, labels.labels, labels.sizes, labels.triCounts);
            }

            {
                // Note: this needs to go last.
                // It simply shows all the memory labels that were not explicitly queried after the Lightmapping.ResetExplicitlyShownMemLabels() call.
                MemLabels labels = Lightmapping.GetNotShownMemLabels();
                string    remainingEntriesFoldoutName = Lightmapping.isProgressiveLightmapperDone ? "Leaks" : "In-flight";
                ShowObjectNamesSizesAndCounts(remainingEntriesFoldoutName, kEditorPrefsInFlight, labels.labels, labels.sizes, dummyCounts);
            }

            EditorGUILayout.Space();
            EditorGUIUtility.labelWidth = oldWidth;
        }