acdream/src/AcDream.App/Diagnostics/WorldLifecycleResourceSnapshotSource.cs
Erik b16f820643 feat(render): Campaign V slice V6h — the Vulkan composition host
ACDREAM_RENDER_BACKEND=vulkan now runs the real GameWindow composition rather
than a second main(). All nine phases execute: DAT load, streaming, camera,
entity table, session, and the real retained UiHost drawing through the RHI.
No world renderers — they are raw GL until V4t and the world arm behind it.

The offline log is the client's own (acdream.pak opened, 6266 spells, Region
0x13000000, "loading world view centered on 0xA9B4FFFF", fourteen retail
LayoutDesc lines, streaming radii), and the captured frame is the retail
retained UI: vitals, combat/spell bar with DAT scarab icons, the nine-slot
toolbar, chat with tabs and Send, radar/compass with dat-font glyphs. Sampled
against the GL capture the widgets agree — chat interior RGBA (25,24,27,158)
vs (22,21,23,158), vitals bar (117,1,0) and toolbar slot (0,11,17) identical.

Three seams, as §5.5.9 specified:

1. Platform acquisition — already generic — publishes GameWindowGraphics
   instead of a bare GL. Phases that still speak raw GL read Graphics.Gl and
   take their Vulkan arm when it is null; each branch names the slice that
   removes it.
2. VulkanHostInputCameraCompositionFactory is a new file and the whole of the
   Phase-1 fork: four graphics members differ, input/camera/pointer delegate.
   The default factory is chosen inside the phase from the platform result.
   HostInputCameraResult gained backend-neutral Retirement and FrameSlots.
3. The frame root forks on one condition. The GL world-scene assembly is
   unchanged, wrapped in `if (gl is not null)`; the Vulkan arm's graph is one
   backbuffer clear pass computing the same RenderFrameFoundation from the same
   clock and weather owners, then private presentation over it.

§5.5.9's three TextureCache couplings are unpicked: the constructor takes GL?
and rejects bindless without one, world entry points route through a Gl
property that throws naming V4t, and the (GlGpuTexture) VRAM-accounting cast
became a backend test. That cast's stated reason — DrawSprite's texture-unit
binding — was already stale, deleted at V6d.

VulkanBringUpHost is reduced to the capability-probe harness it is named for:
the instance/surface/device/swapchain sequence moved into VulkanGraphicsContext,
which the composition host and the harness now share. It is reached only with
ACDREAM_VULKAN_PROBE=1.

One latent Vulkan defect surfaced and is fixed here. The first composition-host
frame died with ErrorDeviceLost; validation named VUID-vkCmdDraw-None-08600 —
descriptor set 2 never bound. VulkanGpuPassEncoder bound sets 0/1/2 only as a
side effect of BindStorageBuffer/BindUniformBuffer, so a pass sampling the
texture table while binding no buffer — every retained-UI and debug-line pass —
drew with the table unbound. It survived V6c-V6g because the bring-up host
always drew VulkanRhiScene first and the UI pass inherited its binds; the
composition host has no 3-D scene. The fix is one line in the encoder's
constructor beside the viewport and scissor defaults, which exist for exactly
the same reason: a pass opens with complete binding state rather than depending
on what preceded it.

Gates: strict GL offline pixel gate against 46d893f7 measures 1.24e-05 (7 of
563,200 pixels), inside the documented 15-23 px / 4.1e-05 band, so GL behaviour
did not move. App tests 4,075/3 skips; complete Release suite 9,138/5 skips.
One full Vulkan run with VK_LAYER_KHRONOS_validation: zero errors, zero
warnings. Both Vulkan runs converged the ownership ledger — no [shutdown]
diagnostic on either stream. The reduced probe harness presented 34,811
validation-clean frames.

No divergence-register row: GL is the shipping backend and the pixel gate proves
it unmoved; the Vulkan arm is not a retail deviation but a backend under
construction.

Next is V4t, the texture stack, which the world arm cannot be written without.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-28 11:47:37 +02:00

212 lines
11 KiB
C#

using AcDream.App.Rendering;
using AcDream.App.Rendering.Scene;
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;
using AcDream.Core.Physics;
using AcDream.Core.Vfx;
using DatReaderWriter.Lib.IO;
namespace AcDream.App.Diagnostics;
/// <summary>
/// Samples the canonical owners used by the connected lifecycle gate. This is
/// deliberately a read-only view: it owns no counters and keeps no mirrored
/// resource state between checkpoints.
/// </summary>
internal sealed class WorldLifecycleResourceSnapshotSource
{
// Generation index 3 is the large object heap; see GCMemoryInfo.GenerationInfo
// (verified against the installed net10.0 runtime — Gen0/1/2, LOH, POH).
private const int LohGenerationIndex = 3;
private readonly GpuWorldState _world;
private readonly LiveEntityAnimationRuntimeView<LiveEntityAnimationState>
_animations;
private readonly RenderFrameDiagnosticsController _renderDiagnostics;
private readonly LiveEntityRuntime _liveEntities;
private readonly StreamingController _streaming;
private readonly ParticleSystem _particles;
private readonly ParticleHookSink _particleSink;
private readonly EntityEffectController _effects;
private readonly LiveEntityLightController _lights;
private readonly PhysicsScriptRunner _scripts;
// Campaign V slice V6h: absent on a backend that composes no world
// renderers. Their counters report zero, which is the truth there.
private readonly WbMeshAdapter? _meshes;
private readonly TextureCache _textures;
private readonly WbDrawDispatcher? _dispatcher;
private readonly FrameProfiler _frameProfiler;
private readonly IDatReaderWriter _dats;
private readonly ResidencyManager _residency;
private readonly PhysicsDataCache _physics;
private readonly ICurrentRenderSceneOracleSnapshotSource?
_renderSceneOracle;
private readonly IRenderSceneShadowSnapshotSource?
_renderSceneShadow;
private readonly IRenderFrameProductSnapshotSource?
_renderFrameProduct;
public WorldLifecycleResourceSnapshotSource(
GpuWorldState world,
LiveEntityAnimationRuntimeView<LiveEntityAnimationState> animations,
RenderFrameDiagnosticsController renderDiagnostics,
LiveEntityRuntime liveEntities,
StreamingController streaming,
ParticleSystem particles,
ParticleHookSink particleSink,
EntityEffectController effects,
LiveEntityLightController lights,
PhysicsScriptRunner scripts,
WbMeshAdapter? meshes,
TextureCache textures,
WbDrawDispatcher? dispatcher,
FrameProfiler frameProfiler,
IDatReaderWriter dats,
ResidencyManager residency,
PhysicsDataCache physics,
ICurrentRenderSceneOracleSnapshotSource? renderSceneOracle = null,
IRenderSceneShadowSnapshotSource? renderSceneShadow = null,
IRenderFrameProductSnapshotSource? renderFrameProduct = null)
{
_world = world ?? throw new ArgumentNullException(nameof(world));
_animations = animations
?? throw new ArgumentNullException(nameof(animations));
_renderDiagnostics = renderDiagnostics
?? throw new ArgumentNullException(nameof(renderDiagnostics));
_liveEntities = liveEntities
?? throw new ArgumentNullException(nameof(liveEntities));
_streaming = streaming
?? throw new ArgumentNullException(nameof(streaming));
_particles = particles
?? throw new ArgumentNullException(nameof(particles));
_particleSink = particleSink
?? throw new ArgumentNullException(nameof(particleSink));
_effects = effects ?? throw new ArgumentNullException(nameof(effects));
_lights = lights ?? throw new ArgumentNullException(nameof(lights));
_scripts = scripts ?? throw new ArgumentNullException(nameof(scripts));
_meshes = meshes;
_textures = textures ?? throw new ArgumentNullException(nameof(textures));
_dispatcher = dispatcher;
_frameProfiler = frameProfiler
?? throw new ArgumentNullException(nameof(frameProfiler));
_dats = dats ?? throw new ArgumentNullException(nameof(dats));
_residency = residency
?? throw new ArgumentNullException(nameof(residency));
_physics = physics ?? throw new ArgumentNullException(nameof(physics));
_renderSceneOracle = renderSceneOracle;
_renderSceneShadow = renderSceneShadow;
_renderFrameProduct = renderFrameProduct;
}
public WorldLifecycleResourceSnapshot Capture(RenderFrameOutcome outcome)
{
// Present on GL, absent on a backend with no world renderers. The mesh
// manager is still required whenever an adapter exists — a composed
// adapter without one is a composition bug, not a backend difference.
ObjectMeshManager? meshManager = _meshes is null
? null
: _meshes.MeshManager
?? throw new InvalidOperationException(
"Lifecycle snapshots require the composed modern mesh manager.");
var mesh = meshManager?.Diagnostics ?? default;
RenderFrameDiagnosticsSnapshot render = _renderDiagnostics.Snapshot;
GCMemoryInfo memory = GC.GetGCMemoryInfo();
ReadOnlySpan<GCGenerationInfo> generations = memory.GenerationInfo;
long lohSizeBytes = generations.Length > LohGenerationIndex
? generations[LohGenerationIndex].SizeAfterBytes
: 0L;
long lohFragmentationBytes = generations.Length > LohGenerationIndex
? generations[LohGenerationIndex].FragmentationAfterBytes
: 0L;
// The DAT-object cache lives behind IDatReaderWriter (a third-party
// interface from the DatReaderWriter package — we cannot extend it).
// RuntimeDatCollection is the one production implementation that
// owns the bounded per-database caches; a caller supplying a test
// double simply reports zero counters here.
CacheStats datObjectCacheStats = _dats is RuntimeDatCollection runtimeDats
? runtimeDats.ObjectCacheStats
: default;
CacheStats cpuMeshCacheStats = meshManager?.CpuMeshCacheStats ?? default;
CacheStats decodedTextureCacheStats =
meshManager?.DecodedTextureCacheStats ?? default;
ResidencySnapshot residency = _residency.CaptureSnapshot();
long trackedGpuBytes = GpuMemoryTracker.AllocatedBytes;
long residencyGpuBytes = residency.TotalCharges.PhysicalGpuBytes;
return new WorldLifecycleResourceSnapshot(
LoadedLandblocks: _world.LoadedLandblockIds.Count,
WorldEntities: _world.Entities.Count,
AnimatedEntities: _animations.Count,
VisibleLandblocks: outcome.World.VisibleLandblocks,
TotalLandblocks: outcome.World.TotalLandblocks,
LiveEntities: _liveEntities.Count,
MaterializedLiveEntities: _liveEntities.MaterializedCount,
RenderSceneOracle: _renderSceneOracle?.Snapshot
?? CurrentRenderSceneOracleSnapshot.Disabled,
RenderSceneShadow:
_renderSceneShadow?.CaptureCheckpointSnapshot()
?? RenderSceneShadowComparisonSnapshot.Disabled,
RenderFrameProduct:
_renderFrameProduct?.Snapshot
?? RenderFrameProductComparisonSnapshot.Disabled,
PendingLiveTeardowns: _liveEntities.PendingTeardownCount,
PendingLandblockRetirements: _streaming.PendingRetirementCount,
ParticleEmitters: _particles.ActiveEmitterCount,
Particles: _particles.ActiveParticleCount,
ParticleBindings: _particleSink.ActiveBindingCount,
ParticleOwners: _particleSink.TrackedOwnerCount,
EffectOwners: _effects.ReadyOwnerCount,
LightOwners: _lights.TrackedOwnerCount,
ScriptOwners: _scripts.ActiveOwnerCount,
ActiveScripts: _scripts.ActiveScriptCount,
MeshRenderData: mesh.RenderData,
MeshAtlasArrays: mesh.AtlasArrays,
MeshEstimatedBytes: mesh.EstimatedBytes,
StagedMeshUploads: _meshes?.StagedUploadBacklog ?? 0,
StagedMeshBytes: _meshes?.StagedUploadBytes ?? 0,
TrackedGpuBytes: trackedGpuBytes,
ResidencyGpuBytes: residencyGpuBytes,
GpuTrackerMinusResidencyBytes: checked(
trackedGpuBytes - residencyGpuBytes),
TrackedGpuBuffers: GpuMemoryTracker.BufferCount,
TrackedGpuTextures: GpuMemoryTracker.TextureCount,
OwnedCompositeTextures: _textures.OwnedBindlessTextureCount,
CompositeTextureOwners: _textures.TextureOwnerCount,
ActiveParticleTextures: _textures.ActiveParticleTextureCount,
ParticleTextureOwners: _textures.ParticleTextureOwnerCount,
CompositeWarmupPending:
_dispatcher?.LastCompositeWarmupPendingCount ?? 0,
ManagedBytes: GC.GetTotalMemory(forceFullCollection: false),
ManagedCommittedBytes: memory.TotalCommittedBytes,
LohSizeBytes: lohSizeBytes,
LohFragmentationBytes: lohFragmentationBytes,
ProcessTotalAllocatedBytes: GC.GetTotalAllocatedBytes(precise: false),
CpuMeshCacheHits: cpuMeshCacheStats.Hits,
CpuMeshCacheMisses: cpuMeshCacheStats.Misses,
CpuMeshCacheEvictions: cpuMeshCacheStats.Evictions,
DecodedTextureCacheHits: decodedTextureCacheStats.Hits,
DecodedTextureCacheMisses: decodedTextureCacheStats.Misses,
DecodedTextureCacheEvictions: decodedTextureCacheStats.Evictions,
DatObjectCacheHits: datObjectCacheStats.Hits,
DatObjectCacheMisses: datObjectCacheStats.Misses,
DatObjectCacheEvictions: datObjectCacheStats.Evictions,
PhysicsGraphGfxObjs: _physics.GraphGfxObjCount,
PhysicsGraphSetups: _physics.GraphSetupCount,
PhysicsGraphCells: _physics.GraphCellStructCount,
PhysicsFlatGfxObjs: _physics.FlatGfxObjCount,
PhysicsFlatSetups: _physics.FlatSetupCount,
PhysicsFlatCells: _physics.FlatCellStructCount,
PhysicsFlatEnvCells: _physics.FlatEnvCellCount,
CollisionShadow: _physics.CollisionShadowStats,
StreamingWork: _streaming.WorkDiagnostics,
Residency: residency,
Fps: render.Fps,
FrameMilliseconds: render.FrameMilliseconds,
LastFrameProfile: _frameProfiler.LastReport);
}
}