示例#1
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 foldoutGPUMemoryGPU = String.Format("Total GPU memory ({0})", SizeString(gpuMemory));
                    EditorGUILayout.FoldoutTitlebar(false, new GUIContent(foldoutGPUMemoryGPU), true);
                    if (GUILayout.Button("Dump detail to Editor.log", EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
                    {
                        Lightmapping.LogGPUMemoryStatistics();
                    }
                }
            }

            {
                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.GetLightProbeMemLabels();
                ShowObjectNamesSizesAndCounts("Light Probes", kEditorPrefsLightProbes, labels.labels, labels.sizes, dummyCounts);
            }

            {
                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;
        }