Update asset system for deferred allocation & add unit tests
Modernize Misaki.HighPerformance dependencies. Refactor texture asset creation to use deferred resource slots via CreateEmpty(). Remove fallback resource fields and update texture resolution logic. Add CreateEmpty() to resource database interfaces. Introduce comprehensive unit tests with mocks for asset management. Enable unsafe code in tests.
This commit is contained in:
@@ -34,7 +34,7 @@ internal partial class AssetEntry
|
||||
{
|
||||
// This will create a new slot in the database, but not allocation any GPU resource.
|
||||
// Everything in the slot will have the same value as the fallback texture, expect the slot will be marked as shared.
|
||||
var handle = e._resourceDatabase.CreateShared(e._assetManager.FallbackTexture.AsResource()).AsTexture();
|
||||
var handle = e._resourceDatabase.CreateEmpty().AsTexture();
|
||||
e.SetStorage(handle);
|
||||
};
|
||||
|
||||
@@ -155,7 +155,7 @@ internal partial class AssetManager
|
||||
{
|
||||
if (assetID == Guid.Empty)
|
||||
{
|
||||
return _fallbackTexture;
|
||||
return Handle<GPUTexture>.Invalid;
|
||||
}
|
||||
|
||||
var entry = GetOrCreateEntry(assetID);
|
||||
|
||||
@@ -295,17 +295,9 @@ internal partial class AssetManager : IDisposable
|
||||
|
||||
private readonly ConcurrentDictionary<Guid, AssetEntry> _entries;
|
||||
|
||||
// TODO
|
||||
private Handle<GPUTexture> _fallbackTexture;
|
||||
private Handle<GPUTexture> _fallbackNormalMap;
|
||||
private Handle<Mesh> _fallbackMesh;
|
||||
private Handle<Material> _fallbackMaterial;
|
||||
|
||||
public IContentProvider ContentProvider => _contentProvider;
|
||||
public ResourceStreamingProcessor StreamingProcessor => _streamingProcessor;
|
||||
|
||||
public Handle<GPUTexture> FallbackTexture => _fallbackTexture;
|
||||
|
||||
internal AssetManager(IResourceDatabase resourceDatabase, IContentProvider contentProvider, ResourceStreamingProcessor streamingProcessor, JobScheduler jobScheduler)
|
||||
{
|
||||
_resourceDatabase = resourceDatabase;
|
||||
@@ -378,10 +370,10 @@ internal partial class AssetManager : IDisposable
|
||||
for (var i = list.Count - 1; i >= 0; i--)
|
||||
{
|
||||
// This should create the entry and schedule the job on those assets does not have any dependency first.
|
||||
var handle = GetOrCreateEntry(list[i]).LoadJobHandle;
|
||||
Logger.DebugAssert(handle.IsValid);
|
||||
var depHandle = GetOrCreateEntry(list[i]).LoadJobHandle;
|
||||
Logger.DebugAssert(depHandle.IsValid);
|
||||
|
||||
depHandles.Add(handle);
|
||||
depHandles.Add(depHandle);
|
||||
}
|
||||
|
||||
dependency = _jobScheduler.CombineDependencies(depHandles);
|
||||
@@ -394,7 +386,8 @@ internal partial class AssetManager : IDisposable
|
||||
assetManager = this,
|
||||
};
|
||||
|
||||
entry.SetLoadJobHandle(_jobScheduler.Schedule(ref job, JobPriority.Low, dependency)); // Use low priority to avoid blocking main thread critical tasks like rendering and physics.
|
||||
var handle = _jobScheduler.Schedule(ref job, JobPriority.Low, dependency);
|
||||
entry.SetLoadJobHandle(handle); // Use low priority to avoid blocking main thread critical tasks like rendering and physics.
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Ghost.Core;
|
||||
using Ghost.Graphics;
|
||||
using SharpCompress.Common;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace Ghost.Engine;
|
||||
|
||||
Reference in New Issue
Block a user