feat(render): unify physical residency accounting

This commit is contained in:
Erik 2026-07-24 16:20:48 +02:00
parent 1866ea0c6d
commit 3e18fc2730
25 changed files with 642 additions and 48 deletions

View file

@ -1,5 +1,6 @@
using System.Text.Json;
using AcDream.App.Rendering;
using AcDream.App.Rendering.Residency;
using AcDream.App.Streaming;
using AcDream.App.UI.Testing;
@ -53,6 +54,8 @@ internal sealed record WorldLifecycleResourceSnapshot(
int StagedMeshUploads,
long StagedMeshBytes,
long TrackedGpuBytes,
long ResidencyGpuBytes,
long GpuTrackerMinusResidencyBytes,
int TrackedGpuBuffers,
int TrackedGpuTextures,
int OwnedCompositeTextures,
@ -74,6 +77,7 @@ internal sealed record WorldLifecycleResourceSnapshot(
long DatObjectCacheHits,
long DatObjectCacheMisses,
long DatObjectCacheEvictions,
ResidencySnapshot Residency,
double Fps,
double FrameMilliseconds,
string? LastFrameProfile);

View file

@ -1,6 +1,7 @@
using AcDream.App.Rendering;
using AcDream.App.Rendering.Vfx;
using AcDream.App.Rendering.Wb;
using AcDream.App.Rendering.Residency;
using AcDream.App.Streaming;
using AcDream.App.World;
using AcDream.Content;
@ -36,6 +37,7 @@ internal sealed class WorldLifecycleResourceSnapshotSource
private readonly WbDrawDispatcher _dispatcher;
private readonly FrameProfiler _frameProfiler;
private readonly IDatReaderWriter _dats;
private readonly ResidencyManager _residency;
public WorldLifecycleResourceSnapshotSource(
GpuWorldState world,
@ -52,7 +54,8 @@ internal sealed class WorldLifecycleResourceSnapshotSource
TextureCache textures,
WbDrawDispatcher dispatcher,
FrameProfiler frameProfiler,
IDatReaderWriter dats)
IDatReaderWriter dats,
ResidencyManager residency)
{
_world = world ?? throw new ArgumentNullException(nameof(world));
_animations = animations
@ -77,6 +80,8 @@ internal sealed class WorldLifecycleResourceSnapshotSource
_frameProfiler = frameProfiler
?? throw new ArgumentNullException(nameof(frameProfiler));
_dats = dats ?? throw new ArgumentNullException(nameof(dats));
_residency = residency
?? throw new ArgumentNullException(nameof(residency));
}
public WorldLifecycleResourceSnapshot Capture(RenderFrameOutcome outcome)
@ -105,6 +110,9 @@ internal sealed class WorldLifecycleResourceSnapshotSource
: default;
CacheStats cpuMeshCacheStats = meshManager.CpuMeshCacheStats;
CacheStats decodedTextureCacheStats = meshManager.DecodedTextureCacheStats;
ResidencySnapshot residency = _residency.CaptureSnapshot();
long trackedGpuBytes = GpuMemoryTracker.AllocatedBytes;
long residencyGpuBytes = residency.TotalCharges.PhysicalGpuBytes;
return new WorldLifecycleResourceSnapshot(
LoadedLandblocks: _world.LoadedLandblockIds.Count,
@ -129,7 +137,10 @@ internal sealed class WorldLifecycleResourceSnapshotSource
MeshEstimatedBytes: mesh.EstimatedBytes,
StagedMeshUploads: _meshes.StagedUploadBacklog,
StagedMeshBytes: _meshes.StagedUploadBytes,
TrackedGpuBytes: GpuMemoryTracker.AllocatedBytes,
TrackedGpuBytes: trackedGpuBytes,
ResidencyGpuBytes: residencyGpuBytes,
GpuTrackerMinusResidencyBytes: checked(
trackedGpuBytes - residencyGpuBytes),
TrackedGpuBuffers: GpuMemoryTracker.BufferCount,
TrackedGpuTextures: GpuMemoryTracker.TextureCount,
OwnedCompositeTextures: _textures.OwnedBindlessTextureCount,
@ -152,6 +163,7 @@ internal sealed class WorldLifecycleResourceSnapshotSource
DatObjectCacheHits: datObjectCacheStats.Hits,
DatObjectCacheMisses: datObjectCacheStats.Misses,
DatObjectCacheEvictions: datObjectCacheStats.Evictions,
Residency: residency,
Fps: render.Fps,
FrameMilliseconds: render.FrameMilliseconds,
LastFrameProfile: _frameProfiler.LastReport);