Refactor asset pipeline: new registry, loader, and runtime

Major overhaul of asset system:
- Split assets into source, .gmeta (JSON), and cooked .imported binaries
- Replaced Asset base class; added TextureAsset, TextureLoader
- AssetManager now uses job-based, dependency-aware loading
- Unified IAssetHandler API; removed legacy handler interfaces
- Updated D3D12 allocator and graphics code for new resource model
- Improved error handling, memory management, and GPU upload logic
- Updated docs and removed obsolete code/interfaces
This commit is contained in:
2026-04-18 01:46:37 +09:00
parent 13bf1501e4
commit abd5ad74d5
32 changed files with 4348 additions and 570 deletions

View File

@@ -7,6 +7,7 @@ using Misaki.HighPerformance.LowLevel.Collections;
using System.Diagnostics;
using System.Runtime.InteropServices;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
namespace Ghost.Graphics.D3D12;
@@ -39,7 +40,8 @@ internal unsafe class D3D12ResourceDatabase : IResourceDatabase
public ResourceBarrierData barrierData;
public readonly bool isExternal;
public bool isExternal;
public bool isShared;
public readonly bool Allocated => isExternal ? resource.resource.Get() != null : resource.allocation.Get() != null;
public readonly SharedPtr<ID3D12Resource> ResourcePtr => isExternal ? resource.resource.Get() : resource.allocation.Get()->GetResource();
@@ -48,6 +50,7 @@ internal unsafe class D3D12ResourceDatabase : IResourceDatabase
{
this.resource = new __resource_union(allocation);
this.isExternal = false;
this.isShared = false;
this.viewGroup = viewGroup;
this.barrierData = barrierData;
@@ -58,6 +61,7 @@ internal unsafe class D3D12ResourceDatabase : IResourceDatabase
{
this.resource = new __resource_union(resource);
this.isExternal = true;
this.isShared = false;
this.viewGroup = viewGroup;
this.barrierData = barrierData;
@@ -66,6 +70,11 @@ internal unsafe class D3D12ResourceDatabase : IResourceDatabase
public readonly uint Release(D3D12DescriptorAllocator descriptorAllocator)
{
if (isShared)
{
return 0;
}
var refCount = 0u;
if (Allocated)
{
@@ -400,6 +409,39 @@ internal unsafe class D3D12ResourceDatabase : IResourceDatabase
return Error.None;
}
public Handle<GPUResource> CreateShared(Handle<GPUResource> src)
{
if (src.IsInvalid)
{
return Handle<GPUResource>.Invalid;
}
var spinner = new SpinWait();
while (Interlocked.CompareExchange(ref _writeLock, 1, 0) != 0)
{
spinner.SpinOnce();
}
try
{
var (srcRecord, error) = GetResourceRecord(src);
if (error.IsFailure)
{
return Handle<GPUResource>.Invalid;
}
var newRecord = srcRecord.Get();
newRecord.isShared = true;
var id = _resources.Add(newRecord, out var generation);
return new Handle<GPUResource>(id, generation);
}
finally
{
Interlocked.Exchange(ref _writeLock, 0);
}
}
public void* MapResource(Handle<GPUResource> handle, uint subResource, ResourceRange? readRange)
{
var r = GetResourceRecord(handle);