Refactor resource management and update project configs

- Use `using` for MeshNode disposal in MeshAssetHandler
- Switch to `ref` UnsafeList in meshlet hierarchy methods for perf
- Ensure proper disposal of UnsafeList<int> and TempBinaryNode
- Add launchSettings.json for Ghost.Editor.Core debugging
- Update GhostEngine.slnx with platform mappings for Editor.Core
- Remove MHP_ENABLE_SAFETY_CHECKS from Debug|AnyCPU in csproj
This commit is contained in:
2026-05-07 00:23:51 +09:00
parent 744b058e6a
commit d052ca848f
5 changed files with 134 additions and 115 deletions

View File

@@ -261,17 +261,16 @@ internal class MeshAssetHandler : IImportableAssetHandler, IPackableAssetHandler
return Result.Failure<ImportedSubAsset[]>("Source file does not exist."); return Result.Failure<ImportedSubAsset[]>("Source file does not exist.");
} }
var meshSettings = ResolveSettings(sourcePath, settings);
var root = new MeshNode();
try try
{ {
var heapSize1 = AllocationManager.TotalAllocatedMemory; var meshSettings = ResolveSettings(sourcePath, settings);
using var root = new MeshNode();
var parseJob = new MeshParsingJob(root, sourcePath, AllocationHandle.Persistent, meshSettings); var parseJob = new MeshParsingJob(root, sourcePath, AllocationHandle.Persistent, meshSettings);
var context = default(Misaki.HighPerformance.Jobs.JobExecutionContext); var context = default(Misaki.HighPerformance.Jobs.JobExecutionContext);
parseJob.Execute(in context); parseJob.Execute(in context);
var heapSize2 = AllocationManager.TotalAllocatedMemory;
var manifest = new ModelManifest var manifest = new ModelManifest
{ {
AssetId = id, AssetId = id,
@@ -291,10 +290,6 @@ internal class MeshAssetHandler : IImportableAssetHandler, IPackableAssetHandler
{ {
return Result.Failure<ImportedSubAsset[]>($"Failed to import mesh asset: {ex.Message}"); return Result.Failure<ImportedSubAsset[]>($"Failed to import mesh asset: {ex.Message}");
} }
finally
{
root.Dispose();
}
} }
public ValueTask<Result> ExportAsync(string assetPath, string targetPath, IAssetExportOptions? options, CancellationToken token = default) public ValueTask<Result> ExportAsync(string assetPath, string targetPath, IAssetExportOptions? options, CancellationToken token = default)

View File

@@ -864,7 +864,7 @@ internal static unsafe partial class MeshProcessor
public int meshletIndex; public int meshletIndex;
} }
private static int BuildBinaryTree(UnsafeList<TempBinaryNode> nodes, UnsafeArray<int> meshletIndices, int start, int end, ReadOnlySpan<Meshlet> meshlets) private static int BuildBinaryTree(ref UnsafeList<TempBinaryNode> nodes, UnsafeArray<int> meshletIndices, int start, int end, ReadOnlySpan<Meshlet> meshlets)
{ {
if (start == end - 1) if (start == end - 1)
{ {
@@ -921,8 +921,8 @@ internal static unsafe partial class MeshProcessor
mid = start + (end - start) / 2; mid = start + (end - start) / 2;
} }
var left = BuildBinaryTree(nodes, meshletIndices, start, mid, meshlets); var left = BuildBinaryTree(ref nodes, meshletIndices, start, mid, meshlets);
var right = BuildBinaryTree(nodes, meshletIndices, mid, end, meshlets); var right = BuildBinaryTree(ref nodes, meshletIndices, mid, end, meshlets);
var leftNode = nodes[left]; var leftNode = nodes[left];
var rightNode = nodes[right]; var rightNode = nodes[right];
@@ -945,7 +945,7 @@ internal static unsafe partial class MeshProcessor
return internalNodeIndex; return internalNodeIndex;
} }
private static void GatherChildren(UnsafeList<TempBinaryNode> binaryNodes, int nodeIndex, UnsafeList<int> gathered) private static void GatherChildren(UnsafeList<TempBinaryNode> binaryNodes, int nodeIndex, ref UnsafeList<int> gathered)
{ {
gathered.Clear(); gathered.Clear();
var node = binaryNodes[nodeIndex]; var node = binaryNodes[nodeIndex];
@@ -992,8 +992,11 @@ internal static unsafe partial class MeshProcessor
return -1; return -1;
} }
using var gathered = new UnsafeList<int>(4, AllocationHandle.Persistent); var gathered = new UnsafeList<int>(4, AllocationHandle.Persistent);
GatherChildren(binaryNodes, binaryNodeIndex, gathered);
try
{
GatherChildren(binaryNodes, binaryNodeIndex, ref gathered);
var bvhNode = new MeshletHierarchyNode(); var bvhNode = new MeshletHierarchyNode();
@@ -1067,6 +1070,11 @@ internal static unsafe partial class MeshProcessor
hierarchyNodes[outNodeIndex] = bvhNode; hierarchyNodes[outNodeIndex] = bvhNode;
return outNodeIndex; return outNodeIndex;
} }
finally
{
gathered.Dispose();
}
}
/// <summary> /// <summary>
/// Builds a cluster LOD hierarchy from the input meshlet data. /// Builds a cluster LOD hierarchy from the input meshlet data.
@@ -1082,10 +1090,11 @@ internal static unsafe partial class MeshProcessor
meshletIndices[i] = i; meshletIndices[i] = i;
} }
var meshletsSpan = new ReadOnlySpan<Meshlet>(meshletData.meshlets.GetUnsafePtr(), meshletData.meshlets.Count); var binaryNodes = new UnsafeList<TempBinaryNode>(meshletData.meshletCount * 2, AllocationHandle.Persistent);
using var binaryNodes = new UnsafeList<TempBinaryNode>(meshletData.meshletCount * 2, AllocationHandle.Persistent); try
var rootIndex = BuildBinaryTree(binaryNodes, meshletIndices, 0, meshletIndices.Length, meshletsSpan); {
var rootIndex = BuildBinaryTree(ref binaryNodes, meshletIndices, 0, meshletIndices.Length, meshletData.meshlets);
if (!meshletData.hierarchyNodes.IsCreated) if (!meshletData.hierarchyNodes.IsCreated)
{ {
@@ -1121,4 +1130,9 @@ internal static unsafe partial class MeshProcessor
CollapseTo4Ary(binaryNodes, rootIndex, meshletData.hierarchyNodes); CollapseTo4Ary(binaryNodes, rootIndex, meshletData.hierarchyNodes);
} }
} }
finally
{
binaryNodes.Dispose();
}
}
} }

View File

@@ -0,0 +1,8 @@
{
"profiles": {
"Ghost.Editor.Core": {
"commandName": "Project",
"debugEngines": "managed"
}
}
}

View File

@@ -7,7 +7,9 @@
<Folder Name="/Editor/"> <Folder Name="/Editor/">
<Project Path="Editor/Ghost.DSL/Ghost.DSL.csproj" /> <Project Path="Editor/Ghost.DSL/Ghost.DSL.csproj" />
<Project Path="Editor/Ghost.Editor.Core/Ghost.Editor.Core.csproj"> <Project Path="Editor/Ghost.Editor.Core/Ghost.Editor.Core.csproj">
<Platform Solution="Debug|x64" Project="x64" /> <Platform Solution="*|ARM64" Project="ARM64" />
<Platform Solution="*|x64" Project="x64" />
<Platform Solution="*|x86" Project="x86" />
</Project> </Project>
<Project Path="Editor/Ghost.Editor/Ghost.Editor.csproj"> <Project Path="Editor/Ghost.Editor/Ghost.Editor.csproj">
<Platform Solution="*|ARM64" Project="ARM64" /> <Platform Solution="*|ARM64" Project="ARM64" />

View File

@@ -8,7 +8,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>$(DefineConstants);MHP_ENABLE_SAFETY_CHECKS;MHP_ENABLE_MIMALLOC;MHP_FASTMATH</DefineConstants> <DefineConstants>$(DefineConstants);MHP_ENABLE_MIMALLOC;MHP_FASTMATH</DefineConstants>
<IsAotCompatible>True</IsAotCompatible> <IsAotCompatible>True</IsAotCompatible>
<IsTrimmable>True</IsTrimmable> <IsTrimmable>True</IsTrimmable>
</PropertyGroup> </PropertyGroup>