fix(render): harden portal exit handoff
Some checks failed
CI / linux-portable (push) Successful in 3m19s
CI / windows-gate (push) Failing after 6m43s
CI / release (push) Has been skipped

This commit is contained in:
Erik 2026-08-25 17:39:44 +02:00
parent ddbd7e4096
commit 82e4b4cb6d
17 changed files with 896 additions and 119 deletions

View file

@ -1,4 +1,5 @@
using System.Diagnostics;
using AcDream.App.Rendering;
using AcDream.Runtime;
namespace AcDream.App.Streaming;
@ -20,7 +21,9 @@ namespace AcDream.App.Streaming;
/// shape.</item>
/// <item>1 Hz progress — elapsed, the three flags, and the resident
/// landblock count, so a budget-paced linear drip is visually obvious in the
/// log.</item>
/// log. A paired <c>[reveal-resource]</c> snapshot attributes the cold render
/// barrier to mesh preparation/upload, arena growth, texture composites, or
/// process/GPU residency without sampling those owners every frame.</item>
/// <item><c>SUMMARY</c> once at the viewport reveal — the per-edge
/// timeline on one line.</item>
/// </list>
@ -31,6 +34,7 @@ namespace AcDream.App.Streaming;
internal sealed class RevealTimingProbe
{
private readonly Func<int>? _loadedLandblockCount;
private readonly IRenderFrameResourceDiagnosticsSource? _renderResources;
private readonly Stopwatch _clock = new();
private long _generation;
private string _kind = "";
@ -49,8 +53,13 @@ internal sealed class RevealTimingProbe
private long _lastProgressMs;
private int _framesSinceProgress;
public RevealTimingProbe(Func<int>? loadedLandblockCount) =>
public RevealTimingProbe(
Func<int>? loadedLandblockCount,
IRenderFrameResourceDiagnosticsSource? renderResources = null)
{
_loadedLandblockCount = loadedLandblockCount;
_renderResources = renderResources;
}
public void Begin(
string kind,
@ -80,6 +89,7 @@ internal sealed class RevealTimingProbe
+ $"cell=0x{destinationCell:X8} window={window.NearRadius}/"
+ $"{window.FarRadius} landblocks={_windowLandblocks} "
+ $"loaded={_loadedLandblockCount?.Invoke() ?? -1}");
EmitResourceSnapshot("begin", elapsedMilliseconds: 0);
}
public void Observe(
@ -91,37 +101,56 @@ internal sealed class RevealTimingProbe
_framesSinceProgress++;
long elapsed = _clock.ElapsedMilliseconds;
string? resourceCheckpoint = null;
if (!_render && readiness.IsRenderNeighborhoodReady)
{
_render = true;
_renderMs = elapsed;
Edge("render-ready", elapsed);
resourceCheckpoint = AppendCheckpoint(
resourceCheckpoint,
"render-ready");
}
if (!_composites && readiness.AreCompositeTexturesReady)
{
_composites = true;
_compositesMs = elapsed;
Edge("composites-ready", elapsed);
resourceCheckpoint = AppendCheckpoint(
resourceCheckpoint,
"composites-ready");
}
if (!_collision && readiness.IsCollisionReady)
{
_collision = true;
_collisionMs = elapsed;
Edge("collision-ready", elapsed);
resourceCheckpoint = AppendCheckpoint(
resourceCheckpoint,
"collision-ready");
}
if (!_gateReady && readiness.IsReady)
{
_gateReady = true;
_gateReadyMs = elapsed;
Edge("gate-ready", elapsed);
resourceCheckpoint = AppendCheckpoint(
resourceCheckpoint,
"gate-ready");
}
if (!_materialized && portal.Materialized)
{
_materialized = true;
_materializedMs = elapsed;
Edge("materialized", elapsed);
resourceCheckpoint = AppendCheckpoint(
resourceCheckpoint,
"materialized");
}
if (resourceCheckpoint is not null)
EmitResourceSnapshot(resourceCheckpoint, elapsed);
if (!_summarized && portal.WorldViewportObserved)
{
_summarized = true;
@ -132,6 +161,7 @@ internal sealed class RevealTimingProbe
+ $"gateReadyMs={_gateReadyMs} "
+ $"materializedMs={_materializedMs} "
+ $"landblocks={_windowLandblocks}");
EmitResourceSnapshot("summary", elapsed);
return;
}
@ -151,6 +181,7 @@ internal sealed class RevealTimingProbe
+ $"loaded={_loadedLandblockCount?.Invoke() ?? -1}"
+ $"/{_windowLandblocks} "
+ $"frames={_framesSinceProgress}");
EmitResourceSnapshot("progress", elapsed);
PublicationTimingProbe.EmitStreamingTickWindow();
_framesSinceProgress = 0;
}
@ -162,4 +193,77 @@ internal sealed class RevealTimingProbe
+ $"elapsedMs={elapsed} "
+ $"loaded={_loadedLandblockCount?.Invoke() ?? -1}"
+ $"/{_windowLandblocks}");
private void EmitResourceSnapshot(string checkpoint, long elapsedMilliseconds)
{
if (_renderResources is null)
return;
RenderFrameResourceDiagnosticsSnapshot snapshot =
_renderResources.Capture();
Console.WriteLine(FormatResourceLine(
checkpoint,
_kind,
_generation,
elapsedMilliseconds,
snapshot));
}
private static string AppendCheckpoint(string? current, string next) =>
current is null ? next : current + "+" + next;
internal static string FormatResourceLine(
string checkpoint,
string kind,
long generation,
long elapsedMilliseconds,
in RenderFrameResourceDiagnosticsSnapshot snapshot)
{
MeshStreamResourceDiagnostics mesh = snapshot.Mesh;
TextureStreamResourceDiagnostics textures = snapshot.Textures;
ProcessResourceDiagnostics process = snapshot.Process;
return $"[reveal-resource] checkpoint={checkpoint} kind={kind} "
+ $"gen={generation} elapsedMs={elapsedMilliseconds} "
+ $"meshData={mesh.RenderData} meshAtlases={mesh.AtlasArrays} "
+ $"meshUnusedLru={mesh.UnusedLru} meshBytes={mesh.EstimatedBytes} "
+ $"globalUploads={mesh.GlobalUploadCount} "
+ $"globalUploadBytes={mesh.GlobalUploadedBytes} "
+ $"frameUploads={mesh.FrameUploadCount} "
+ $"frameUploadBytes={mesh.FrameUploadBytes} "
+ $"frameArrayBytes={mesh.FrameArrayAllocationBytes} "
+ $"frameMipmapBytes={mesh.FrameMipmapBytes} "
+ $"frameBufferUploadBytes={mesh.FrameBufferUploadBytes} "
+ $"frameBufferAllocationBytes={mesh.FrameBufferAllocationBytes} "
+ $"frameBufferCopyBytes={mesh.FrameBufferCopyBytes} "
+ $"frameNewArrays={mesh.FrameNewArrayCount} "
+ $"frameNewBuffers={mesh.FrameNewBufferCount} "
+ $"frameStaleDiscards={mesh.FrameStaleDiscardCount} "
+ $"frameMipmapArrays={mesh.FrameMipmapArrayCount} "
+ $"staged={mesh.StagedUploadBacklog} "
+ $"stagedBytes={mesh.StagedUploadBytes} "
+ $"stagingHighWater={(mesh.StagingAtHighWater ? 1 : 0)} "
+ $"cpuMeshCache={mesh.CpuMeshCacheCount} "
+ $"cpuMeshCacheBytes={mesh.CpuMeshCacheBytes} "
+ $"arenaCapacityBytes={mesh.GlobalCapacityBytes} "
+ $"arenaPhysicalBytes={mesh.GlobalPhysicalCapacityBytes} "
+ $"arenaMigrating={(mesh.GlobalMigrationInProgress ? 1 : 0)} "
+ $"prepared={mesh.PreparedProbes}/{mesh.PreparedReads}/"
+ $"{mesh.PreparedLoaded}/{mesh.PreparedMissing}/"
+ $"{mesh.PreparedCorrupt} "
+ $"ownedTextures={textures.OwnedBindlessTextures} "
+ $"textureOwners={textures.TextureOwners} "
+ $"composites={textures.CachedCompositeTextures} "
+ $"unownedComposites={textures.CachedUnownedComposites} "
+ $"unownedCompositeBytes={textures.CachedUnownedCompositeBytes} "
+ $"compositeAtlases={textures.CompositeAtlases} "
+ $"compositeAtlasBytes={textures.CompositeAtlasBytes} "
+ $"compositePending={textures.CompositeWarmupPending} "
+ $"frameCompositeUploads={textures.FrameCompositeUploadCount} "
+ $"frameCompositeUploadBytes={textures.FrameCompositeUploadBytes} "
+ $"managedBytes={process.ManagedBytes} "
+ $"managedCommittedBytes={process.ManagedCommittedBytes} "
+ $"trackedGpuBytes={process.TrackedGpuBytes} "
+ $"trackedGpuBuffers={process.TrackedGpuBuffers} "
+ $"trackedGpuTextures={process.TrackedGpuTextures}";
}
}