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:
@@ -261,17 +261,16 @@ internal class MeshAssetHandler : IImportableAssetHandler, IPackableAssetHandler
|
||||
return Result.Failure<ImportedSubAsset[]>("Source file does not exist.");
|
||||
}
|
||||
|
||||
var meshSettings = ResolveSettings(sourcePath, settings);
|
||||
var root = new MeshNode();
|
||||
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 context = default(Misaki.HighPerformance.Jobs.JobExecutionContext);
|
||||
parseJob.Execute(in context);
|
||||
|
||||
var heapSize2 = AllocationManager.TotalAllocatedMemory;
|
||||
|
||||
var manifest = new ModelManifest
|
||||
{
|
||||
AssetId = id,
|
||||
@@ -291,10 +290,6 @@ internal class MeshAssetHandler : IImportableAssetHandler, IPackableAssetHandler
|
||||
{
|
||||
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)
|
||||
|
||||
@@ -864,7 +864,7 @@ internal static unsafe partial class MeshProcessor
|
||||
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)
|
||||
{
|
||||
@@ -921,8 +921,8 @@ internal static unsafe partial class MeshProcessor
|
||||
mid = start + (end - start) / 2;
|
||||
}
|
||||
|
||||
var left = BuildBinaryTree(nodes, meshletIndices, start, mid, meshlets);
|
||||
var right = BuildBinaryTree(nodes, meshletIndices, mid, end, meshlets);
|
||||
var left = BuildBinaryTree(ref nodes, meshletIndices, start, mid, meshlets);
|
||||
var right = BuildBinaryTree(ref nodes, meshletIndices, mid, end, meshlets);
|
||||
|
||||
var leftNode = nodes[left];
|
||||
var rightNode = nodes[right];
|
||||
@@ -945,7 +945,7 @@ internal static unsafe partial class MeshProcessor
|
||||
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();
|
||||
var node = binaryNodes[nodeIndex];
|
||||
@@ -992,8 +992,11 @@ internal static unsafe partial class MeshProcessor
|
||||
return -1;
|
||||
}
|
||||
|
||||
using var gathered = new UnsafeList<int>(4, AllocationHandle.Persistent);
|
||||
GatherChildren(binaryNodes, binaryNodeIndex, gathered);
|
||||
var gathered = new UnsafeList<int>(4, AllocationHandle.Persistent);
|
||||
|
||||
try
|
||||
{
|
||||
GatherChildren(binaryNodes, binaryNodeIndex, ref gathered);
|
||||
|
||||
var bvhNode = new MeshletHierarchyNode();
|
||||
|
||||
@@ -1067,6 +1070,11 @@ internal static unsafe partial class MeshProcessor
|
||||
hierarchyNodes[outNodeIndex] = bvhNode;
|
||||
return outNodeIndex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
gathered.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a cluster LOD hierarchy from the input meshlet data.
|
||||
@@ -1082,10 +1090,11 @@ internal static unsafe partial class MeshProcessor
|
||||
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);
|
||||
var rootIndex = BuildBinaryTree(binaryNodes, meshletIndices, 0, meshletIndices.Length, meshletsSpan);
|
||||
try
|
||||
{
|
||||
var rootIndex = BuildBinaryTree(ref binaryNodes, meshletIndices, 0, meshletIndices.Length, meshletData.meshlets);
|
||||
|
||||
if (!meshletData.hierarchyNodes.IsCreated)
|
||||
{
|
||||
@@ -1121,4 +1130,9 @@ internal static unsafe partial class MeshProcessor
|
||||
CollapseTo4Ary(binaryNodes, rootIndex, meshletData.hierarchyNodes);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
binaryNodes.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"profiles": {
|
||||
"Ghost.Editor.Core": {
|
||||
"commandName": "Project",
|
||||
"debugEngines": "managed"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,9 @@
|
||||
<Folder Name="/Editor/">
|
||||
<Project Path="Editor/Ghost.DSL/Ghost.DSL.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 Path="Editor/Ghost.Editor/Ghost.Editor.csproj">
|
||||
<Platform Solution="*|ARM64" Project="ARM64" />
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<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>
|
||||
<IsTrimmable>True</IsTrimmable>
|
||||
</PropertyGroup>
|
||||
|
||||
Reference in New Issue
Block a user