Route LocalCast history through shared reservoir

This commit is contained in:
Meta Vens 2026-05-19 14:02:29 +01:00
commit 857b51dbcb
6 changed files with 53 additions and 94 deletions

View file

@ -106,8 +106,10 @@ Ownership:
already-derived point claims.
- `LocalCastGpuFusionMapper` converts typed LocalCast point claims into compact
seeds only for that fallback path.
- `LocalCastGpuFusionAccumulator` owns the bounded history buffer for fallback
stable seeds before GPU lowering.
- `LocalCastGpuFusionAccumulator` is only the LocalCast adapter around
`TemporalSpatialEvidenceReservoir`; it maps fallback stable seeds into shared
evidence observations and lowers reservoir samples back to
`AquariumGpuFusionSeed`.
- `D3D12LocalCastFusion.hlsl` owns the first compute lowering pass.
- `D3D12Renderer` owns GPU sensor camera metadata storage, UAV-capable temporal
Gaussian storage, dispatch, and the transition back to shader-resource state

View file

@ -46,6 +46,8 @@ public sealed class TemporalSpatialEvidenceReservoir
public int MaxTrackCount { get; }
public int TrackCount => tracks.Count;
public void Observe(IEnumerable<TemporalSpatialEvidenceObservation> observations)
{
foreach (var observation in observations)

View file

@ -1,127 +1,79 @@
using System.Numerics;
using Aquarium.Engine.Fractal.Temporal;
using Aquarium.Engine.Render;
namespace Aquarium.LocalCast;
public sealed class LocalCastGpuFusionAccumulator
{
private readonly Dictionary<string, Track> tracks = new(StringComparer.Ordinal);
private const float PresentationDelaySeconds = 0.35f;
private readonly TemporalSpatialEvidenceReservoir reservoir;
private readonly LocalCastGpuFusionMapper mapper = new();
private readonly float historySeconds;
private readonly float smoothing;
private readonly int maxSeedCount;
public LocalCastGpuFusionAccumulator(float historySeconds, float smoothing = 0.45f, int maxSeedCount = 1_048_576)
{
if (!float.IsFinite(historySeconds) || historySeconds <= 0.0f)
{
throw new ArgumentOutOfRangeException(nameof(historySeconds), historySeconds, "History window must be positive.");
}
if (!float.IsFinite(smoothing) || smoothing <= 0.0f || smoothing > 1.0f)
{
throw new ArgumentOutOfRangeException(nameof(smoothing), smoothing, "Smoothing must be in (0, 1].");
}
this.historySeconds = historySeconds;
this.smoothing = smoothing;
this.maxSeedCount = Math.Max(1, maxSeedCount);
reservoir = new TemporalSpatialEvidenceReservoir(
historySeconds,
PresentationDelaySeconds,
smoothing,
Math.Max(1, maxSeedCount));
}
public int TrackCount => tracks.Count;
public int TrackCount => reservoir.TrackCount;
public void Observe(LocalCastVisualFrame frame)
{
var field = mapper.Map(frame);
var frameTimeSeconds = mapper.ToTimelineSeconds(frame.SourceTimeMaxNs);
foreach (var seed in field.Seeds)
{
if (string.IsNullOrWhiteSpace(seed.StableKey))
{
continue;
}
if (tracks.TryGetValue(seed.StableKey, out var current))
{
tracks[seed.StableKey] = current.Update(seed, frameTimeSeconds, smoothing);
}
else
{
tracks[seed.StableKey] = Track.Create(seed, frameTimeSeconds);
}
}
reservoir.Observe(field.Seeds.Select(seed => ToObservation(seed, frameTimeSeconds)));
}
public AquariumGpuFusionField BuildField(float renderTimeSeconds)
{
var cutoff = renderTimeSeconds - historySeconds;
var expired = new List<string>();
var seeds = new List<AquariumGpuFusionSeed>(Math.Min(tracks.Count, maxSeedCount));
foreach (var (key, track) in tracks)
{
if (track.LastObservedTimeSeconds < cutoff)
{
expired.Add(key);
continue;
}
var age = MathF.Max(0.0f, renderTimeSeconds - track.LastObservedTimeSeconds);
var retained = Math.Clamp(1.0f - (age / historySeconds), 0.0f, 1.0f);
var predictedCenter = track.Seed.Center + track.Seed.Velocity * age;
var previousCenter = predictedCenter - track.Seed.Velocity * (1.0f / 60.0f);
seeds.Add(track.Seed with
{
Center = predictedCenter,
PreviousCenter = previousCenter,
HistoryWeight = Math.Clamp(track.Seed.HistoryWeight * retained, 0.0f, 1.0f),
});
}
foreach (var key in expired)
{
tracks.Remove(key);
}
var snapshot = reservoir.BuildSnapshot(renderTimeSeconds);
return new AquariumGpuFusionField
{
Seeds = seeds
.OrderByDescending(seed => seed.HistoryWeight)
.Take(maxSeedCount)
.ToArray(),
Seeds = snapshot.Samples.Select(ToSeed).ToArray(),
AccumulationWindowSeconds = historySeconds,
PresentationDelaySeconds = 0.35f,
PresentationDelaySeconds = PresentationDelaySeconds,
};
}
private readonly record struct Track(AquariumGpuFusionSeed Seed, float LastObservedTimeSeconds)
private static TemporalSpatialEvidenceObservation ToObservation(AquariumGpuFusionSeed seed, float frameTimeSeconds)
{
public static Track Create(AquariumGpuFusionSeed seed, float observedTimeSeconds)
{
return new Track(seed, observedTimeSeconds);
}
return new TemporalSpatialEvidenceObservation(
seed.StableKey,
seed.Center,
seed.Radii,
Quaternion.Identity,
seed.ColorOpacity,
new Vector4(
MathF.Max(0.0001f, seed.Falloff),
MathF.Max(0.0001f, seed.ShapePower),
seed.HistoryWeight,
0.0f),
seed.Confidence,
frameTimeSeconds,
seed.FieldId);
}
public Track Update(AquariumGpuFusionSeed seed, float observedTimeSeconds, float smoothing)
{
var dt = MathF.Max(0.0001f, observedTimeSeconds - LastObservedTimeSeconds);
var measuredVelocity = (seed.Center - Seed.Center) / dt;
var confidence = Math.Clamp(seed.Confidence, 0.0f, 1.0f);
var alpha = smoothing * confidence;
var updatedCenter = Vector3.Lerp(Seed.Center, seed.Center, alpha);
return new Track(
Seed with
{
Center = updatedCenter,
PreviousCenter = Seed.Center,
Velocity = Vector3.Lerp(Seed.Velocity, measuredVelocity, alpha),
Radii = Vector3.Lerp(Seed.Radii, seed.Radii, alpha),
ColorOpacity = Vector4.Lerp(Seed.ColorOpacity, seed.ColorOpacity, alpha),
Confidence = Math.Clamp((Seed.Confidence * 0.85f) + (confidence * 0.15f), 0.0f, 1.0f),
HistoryWeight = Math.Clamp((Seed.HistoryWeight * 0.75f) + (confidence * 0.25f), 0.0f, 1.0f),
Falloff = MathF.Max(0.0001f, seed.Falloff),
ShapePower = MathF.Max(0.0001f, seed.ShapePower),
},
observedTimeSeconds);
}
private static AquariumGpuFusionSeed ToSeed(TemporalSpatialEvidenceSample sample)
{
return new AquariumGpuFusionSeed(
sample.StableKey,
sample.Center,
sample.PreviousCenter,
sample.Velocity,
sample.Radii,
sample.Payload0,
sample.Confidence,
sample.HistoryWeight,
MathF.Max(0.0001f, sample.Payload1.X),
MathF.Max(0.0001f, sample.Payload1.Y),
sample.FieldId);
}
}

View file

@ -153,3 +153,4 @@
{"timestamp":"2026-05-19T14:04:00+01:00","topic":"temporal-spatial-evidence-reservoir","lesson":"Temporal Gaussian accumulation now uses `TemporalSpatialEvidenceReservoir`, which owns stable-keyed spatial tracks, smoothing, delayed presentation, velocity prediction, confidence-weighted history, expiry, and max-track eviction. This pulls the common reservoir shape out from under Gaussian rendering so fractal SDF probes and Mimir sensor-fusion features can converge through the same evidence machinery before backend lowering.","files":["src/Aquarium.Engine.Fractal/Temporal/TemporalSpatialEvidenceObservation.cs","src/Aquarium.Engine.Fractal/Temporal/TemporalSpatialEvidenceReservoir.cs","src/Aquarium.Engine.Fractal/Temporal/TemporalGaussianAccumulator.cs","tests/Aquarium.Engine.Fractal.Tests/TemporalSpatialEvidenceReservoirTests.cs","docs/temporal-sdf-gaussian-field.md"],"source":"user pointed out fractal rendering and Mimir sensor fusion both accumulate surface/volume confidence into temporal reservoirs"}
{"timestamp":"2026-05-19T14:20:00+01:00","topic":"zyphos-fractal-resource-observability","lesson":"Zyphos exposes `zyphos-fractal-plan`, a command-level dump of the current fractal selected cut and resource plan. Keep this kind of budget/cut observability alongside renderer work: pixels alone are not enough to validate stochastic LOD, residency, or cache behavior.","files":["src/Aquarium.Zyphos/ZyphosFractalTerrain.cs","src/Aquarium.Zyphos/ZyphosRuntime.cs","tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs"],"source":"third implementation slice after adding resource planning; the machine needs to explain itself without screenshot divination"}
{"timestamp":"2026-05-19T14:43:00+01:00","topic":"fractal-contribution-cache-live-loop","lesson":"Fractal contribution planning now has a live cache loop. `FractalContributionCache` builds a resource plan from current summaries and cached states, stochastically observes only budgeted update nodes, updates estimator confidence, and lets Zyphos reuse compiled brush packets by selected-cut key instead of freezing the whole render plan by camera bucket. Static plan caches are not acceptable for stochastic LOD because they stop learning.","files":["src/Aquarium.Engine.Fractal/Lod/FractalContributionCache.cs","src/Aquarium.Zyphos/ZyphosFractalTerrain.cs","tests/Aquarium.Engine.Fractal.Tests/FractalContributionCacheTests.cs"],"source":"follow-up after resource observability revealed the old bucket plan cache prevented continual cache updates"}
{"timestamp":"2026-05-19T15:12:00+01:00","topic":"localcast-shared-temporal-reservoir","lesson":"LocalCast fallback GPU fusion history now delegates to `TemporalSpatialEvidenceReservoir`. `LocalCastGpuFusionAccumulator` maps LocalCast GPU fusion seeds into shared evidence observations and lowers reservoir samples back into `AquariumGpuFusionSeed`; it no longer owns separate stable-key history, smoothing, expiry, or max-count logic. This is the first consumer-side takeover of duplicated temporal reservoir code.","files":["src/Aquarium.LocalCast/LocalCastGpuFusionAccumulator.cs","src/Aquarium.Engine.Fractal/Temporal/TemporalSpatialEvidenceReservoir.cs","docs/temporal-sdf-gaussian-field.md"],"source":"user made Aquarium responsible for resolving temporal reservoir sampling architecturally and taking over consumer half-versions"}

View file

@ -112,6 +112,7 @@ renderer_state:
- Temporal resolve uses scene color, metadata, and control history only; dormant event history lanes are cut until a real producer and consumer contract exists.
- Aquarium owns the temporal SDF Gaussian field renderer boundary: clients can publish `AquariumTemporalGaussianField`, `TemporalGaussianAccumulator` can buffer stable keyed observations in world space, and D3D12 lowers those packets into an instanced compact-kernel splat pass that writes normal scene color/travel/metadata/control targets.
- Temporal Gaussian accumulation now lowers through `TemporalSpatialEvidenceReservoir`, a renderer-agnostic stable-key reservoir for confidence-weighted spatial samples with presentation delay, smoothing, velocity prediction, expiry, and max-track eviction. Gaussian splats are one lowering; fractal SDF probe evidence and Mimir sensor-fusion features should use the same reservoir shape when they need delayed coherence solving.
- LocalCast fallback GPU fusion history delegates to `TemporalSpatialEvidenceReservoir`. `LocalCastGpuFusionAccumulator` is now an adapter that maps LocalCast stable seeds into shared evidence observations and back into GPU fusion seeds; it does not own a parallel temporal sampling algorithm.
- Isolated Epiphany agent preview renders run through the real D3D12 renderer from src/Aquarium.Epiphany.AgentPreview; preview isolation is owned by a preview-only scene shader, while the engine exposes only final-frame PNG capture.
- Zyphos is the first nontrivial non-Epiphany client: a planetary-scale demo with spherical-domain terrain, atmospheric rim lighting, night-side glints, fixed-sky Umbros, and first-pass eclipse cadence.
- Zyphos/Umbros render-scale binary constants live in src/Aquarium.Zyphos/ZyphosUmbrosSystem.cs: Umbros is modeled as a 0.9-radius mutually tidally locked twin at 8 Zyphos radii, while the dim primary star phase moves through the Zyphos-local frame.

View file

@ -81,6 +81,7 @@
"The IFS contribution cache must probabilistically refresh node weights under a per-frame update budget. Use online mean/variance/confidence/sample-age state with nonzero exploration for visible or near-threshold nodes so weights converge instead of freezing stale guesses. Learned scoring may later rank update and residency priority from observed high-quality probes, but conservative summaries remain the safety authority for SDF bounds and visibility.",
"Aquarium's fractal renderer and Mimir-style sensor fusion share a deeper shape: both accumulate confidence-weighted spatial evidence into temporal reservoirs, then render a resolved surface/volume field. Keep the budget planner vocabulary general enough for CPU update work, GPU packet cost, RAM residency, and SSD request pressure; do not trap the future shared machinery inside renderer-only folklore.",
"Temporal Gaussian splats lower through TemporalSpatialEvidenceReservoir: stable keyed observations become delayed, smoothed, confidence-weighted tracks with velocity prediction, expiry, and max-track eviction before backend packet lowering. Treat Gaussian fields, fractal SDF probes, and Mimir sensor-fusion features as different evidence producers for this reservoir shape, not separate accumulator folklore.",
"LocalCastGpuFusionAccumulator must remain a thin adapter over TemporalSpatialEvidenceReservoir. LocalCast may own mapping from visual points/seeds into evidence payloads, but it must not grow a second stable-key history, smoothing, expiry, or sample-budget algorithm.",
"Zyphos fractal stress data should keep authored topology richer than the first renderer backend: both Zyphos and Umbros expose lat/long, surface, object-scale, and cube-tile domains in `.aquageo`, with explicit continent/forest/tree/leaf/coast/pebble and crater/boulder/pebble recursion. The current D3D12 height-field stress table uploads 64 shaped 2D brushes and the SDF planet shaders carry separate cheap bounded quadtree-style relief.",
"The `.aquageo` compiler must preserve each tile declaration as its own ownership-tree node. Collapsing every claim under the final tile makes the authored multi-domain world a lie even if the brush count looks impressive.",
"Zyphos passes cube-tile domain metadata through height brush packets and binds those packets into the SDF pass. The planet shader may use authored brush packets for post-hit material/detail evaluation; traced geometry must wait for selected-cut/resident packet policy so SDF distance loops do not evaluate every brush at every step.",