Added ProfilerMarkers for more detailed profiling info without the need for Deep Profiling.

This commit is contained in:
Gene Tailor 2026-02-16 21:05:57 +00:00
parent 69bf34b7d7
commit c1123cf543
3 changed files with 33 additions and 2 deletions

View File

@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEditor;
using System.Linq;
using Unity.Profiling;
using UnityEditor;
using UnityEngine;
namespace UniGLTF
{
@ -20,6 +21,9 @@ namespace UniGLTF
private readonly IReadOnlyDictionary<SubAssetKey, Texture> m_subAssets;
UnityPath m_textureDirectory;
private static ProfilerMarker s_MarkerStartExtractTextures = new ProfilerMarker("Start Extract Textures");
private static ProfilerMarker s_MarkerDelayedExtractTextures = new ProfilerMarker("Delayed Extract Textures");
public TextureExtractor(GltfData data, UnityPath textureDirectory, IReadOnlyDictionary<SubAssetKey, Texture> subAssets)
{
m_data = data;
@ -77,14 +81,20 @@ namespace UniGLTF
Action<SubAssetKey, Texture2D> addRemap,
Action<IEnumerable<UnityPath>> onCompleted = null)
{
s_MarkerStartExtractTextures.Begin();
var extractor = new TextureExtractor(data, textureDirectory, subAssets);
foreach (var param in textureDescriptorGenerator.Get().GetEnumerable())
{
extractor.Extract(param.SubAssetKey, param);
}
s_MarkerStartExtractTextures.End();
EditorApplication.delayCall += () =>
{
s_MarkerDelayedExtractTextures.Begin();
// Wait for the texture assets to be imported
foreach (var (key, targetPath) in extractor.Textures)
@ -97,6 +107,8 @@ namespace UniGLTF
}
}
s_MarkerDelayedExtractTextures.End();
if (onCompleted != null)
{
onCompleted(extractor.Textures.Values);

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using UniGLTF;
using Unity.Profiling;
using UnityEditor;
using UnityEngine;
@ -12,6 +13,8 @@ namespace VRM
UnityPath m_prefabPath;
List<UnityPath> m_paths = new List<UnityPath>();
private static ProfilerMarker s_MarkerConvertAndExtractImages = new ProfilerMarker("Convert and Extract Images");
public ITextureDescriptorGenerator TextureDescriptorGenerator => m_context.TextureDescriptorGenerator;
public VRMEditorImporterContext(VRMImporterContext context, UnityPath prefabPath)
@ -76,22 +79,27 @@ namespace VRM
/// </summary>
public void ConvertAndExtractImages(Action<IEnumerable<UnityPath>> onTextureReloaded)
{
s_MarkerConvertAndExtractImages.Begin();
//
// convert images(metallic roughness, occlusion map)
//
var task = m_context.LoadMaterialsAsync(new ImmediateCaller());
if (!task.IsCompleted)
{
s_MarkerConvertAndExtractImages.End();
throw new Exception();
}
if (task.IsFaulted)
{
if (task.Exception is AggregateException ae && ae.InnerExceptions.Count == 1)
{
s_MarkerConvertAndExtractImages.End();
throw ae.InnerException;
}
else
{
s_MarkerConvertAndExtractImages.End();
throw task.Exception;
}
}
@ -100,6 +108,7 @@ namespace VRM
var task2 = m_context.ReadMetaAsync(new ImmediateCaller());
if (!task2.IsCompleted || task2.IsCanceled || task2.IsFaulted)
{
s_MarkerConvertAndExtractImages.End();
throw new Exception();
}
@ -110,6 +119,8 @@ namespace VRM
var vrmTextures = new BuiltInVrmMaterialDescriptorGenerator(m_context.VRM);
var dirName = $"{m_prefabPath.FileNameWithoutExtension}.Textures";
TextureExtractor.ExtractTextures(m_context.Data, m_prefabPath.Parent.Child(dirName), m_context.TextureDescriptorGenerator, subAssets, (_x, _y) => { }, onTextureReloaded);
s_MarkerConvertAndExtractImages.End();
}
void SaveAsAsset(SubAssetKey _, UnityEngine.Object o)

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using UniGLTF;
using Unity.Profiling;
using UnityEditor;
using UnityEngine;
@ -10,6 +11,8 @@ namespace VRM
{
public class vrmAssetPostprocessor : AssetPostprocessor
{
private static ProfilerMarker s_MarkerCreatePrefab = new ProfilerMarker("Create Prefab");
#if !VRM_STOP_ASSETPOSTPROCESSOR
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
@ -76,6 +79,8 @@ namespace VRM
/// <value></value>
Action<IEnumerable<UnityPath>> onCompleted = texturePaths =>
{
s_MarkerCreatePrefab.Begin();
var map = texturePaths
.Select(x => x.LoadAsset<Texture>())
.ToDictionary(x => new SubAssetKey(x), x => x as UnityEngine.Object);
@ -94,6 +99,9 @@ namespace VRM
editor.SaveAsAsset(loaded);
}
s_MarkerCreatePrefab.End();
sw.Stop();
Debug.Log($"Import complete [importMs={sw.ElapsedMilliseconds}]");