Expose Zyphos structural probe reservoir

This commit is contained in:
Meta Vens 2026-05-19 20:01:38 +01:00
commit 2dfbaa727c
8 changed files with 181 additions and 1 deletions

View file

@ -486,6 +486,9 @@ Current state: `FractalStructuralProbeGenerator` lowers an
`AquariumFractalSummary` into `FractalProbeSample` candidates with local center,
bound radius, projected target contribution, source PDF, material delta, and
payload handle. Renderer-facing temporal validation remains open.
`FractalStructuralProbeReservoir` builds a selected-cut reservoir from an
ownership tree, summaries, and projected pixels per world unit; Zyphos now
exposes that reservoir in its fractal render plan/debug dump.
### Phase D: Occupancy Graph

View file

@ -341,6 +341,8 @@ Tasks:
projected contribution target, source PDF, payload handle, and material delta.
- [x] Add structural probe generator that lowers IFS node summaries into
`FractalProbeSample` reservoir candidates.
- [x] Add selected-cut structural probe reservoir and expose it through Zyphos'
fractal render plan/debug dump.
- [ ] Add temporal reuse validation: camera motion, domain ancestry, local-frame
error, bounds, and disocclusion/material compatibility. Domain ancestry and
local-shift checks exist; camera/disocclusion/material validation still need

View file

@ -0,0 +1,91 @@
using Aquarium.Engine.Fractal.Grammar;
using Aquarium.Engine.Fractal.Temporal;
namespace Aquarium.Engine.Fractal.Lod;
public readonly record struct FractalProbeReservoirSnapshot(
bool HasSample,
AquariumFractalKey DomainKey,
AquariumFractalKey NodeKey,
float TargetContribution,
float BoundRadius,
float WeightSum,
int CandidateCount,
float ContributionWeight);
public static class FractalStructuralProbeReservoir
{
public static FractalProbeReservoirSnapshot Build(
FractalOwnershipTree tree,
IReadOnlyList<AquariumFractalSummary> summaries,
IReadOnlyList<AquariumSelectedCut> selectedCut,
float projectedPixelsPerWorldUnit,
IFractalRandom random)
{
ArgumentNullException.ThrowIfNull(tree);
ArgumentNullException.ThrowIfNull(summaries);
ArgumentNullException.ThrowIfNull(selectedCut);
ArgumentNullException.ThrowIfNull(random);
if (selectedCut.Count == 0)
{
return Empty();
}
var summariesByKey = summaries.ToDictionary(summary => summary.NodeKey.Value, StringComparer.Ordinal);
var nodesByKey = tree.Nodes.ToDictionary(node => node.Key.Value, StringComparer.Ordinal);
var sourceProbability = 1.0 / selectedCut.Count;
var reservoir = new ResampledImportanceReservoir<FractalProbeSample>();
for (var index = 0; index < selectedCut.Count; index++)
{
var cut = selectedCut[index];
if (!summariesByKey.TryGetValue(cut.NodeKey.Value, out var summary)
|| !nodesByKey.TryGetValue(cut.NodeKey.Value, out var node))
{
continue;
}
var candidate = FractalStructuralProbeGenerator.BuildCandidate(
summary,
node.DomainKey,
projectedPixelsPerWorldUnit,
sourceProbability,
payloadHandle: index);
reservoir.Add(candidate, random.NextDouble());
}
return Snapshot(reservoir);
}
private static FractalProbeReservoirSnapshot Snapshot(ResampledImportanceReservoir<FractalProbeSample> reservoir)
{
if (!reservoir.HasSample)
{
return Empty();
}
var selected = reservoir.SelectedSample;
return new FractalProbeReservoirSnapshot(
HasSample: true,
selected.DomainKey,
selected.NodeKey,
selected.TargetContribution,
selected.BoundRadius,
reservoir.WeightSum,
reservoir.CandidateCount,
reservoir.ContributionWeight);
}
private static FractalProbeReservoirSnapshot Empty()
{
return new FractalProbeReservoirSnapshot(
HasSample: false,
DomainKey: default,
NodeKey: default,
TargetContribution: 0.0f,
BoundRadius: 0.0f,
WeightSum: 0.0f,
CandidateCount: 0,
ContributionWeight: 0.0f);
}
}

View file

@ -54,6 +54,12 @@ public static class ZyphosFractalTerrain
}
var selectedCut = resourcePlan.SelectedCut;
var structuralProbeReservoir = FractalStructuralProbeReservoir.Build(
Tree.Value,
Summaries.Value,
selectedCut,
bucketPixelsPerWorld,
new FractalXorShiftRandom(((uint)bucket ^ 0xC2B2AE35u) + (uint)selectedCut.Length));
var cutKey = CutCacheKey(selectedCut);
AquariumHeightFieldBrush[] brushes;
lock (PlanCacheLock)
@ -69,8 +75,9 @@ public static class ZyphosFractalTerrain
brushes,
selectedCut,
resourcePlan,
structuralProbeReservoir,
bucketPixelsPerWorld,
$"{selectedCut.Length}/{Summaries.Value.Length} cuts / {brushes.Length}/{OwnershipTree.Claims.Count} brushes / {resourcePlan.UpdateNodes.Length}/{DefaultBudget.MaxCpuUpdates} cpu updates / {resourcePlan.GpuEstimatedCost:0.0}/{DefaultBudget.MaxGpuEstimatedCost:0.0} gpu cost / {resourcePlan.Residency.ResidentNodes.Count}/{DefaultBudget.MaxResidentPayloads} resident / {resourcePlan.Residency.RequestedNodes.Count}/{DefaultBudget.MaxSsdRequests} ssd requests / {bucketPixelsPerWorld:0.00} px-wu");
$"{selectedCut.Length}/{Summaries.Value.Length} cuts / {brushes.Length}/{OwnershipTree.Claims.Count} brushes / {resourcePlan.UpdateNodes.Length}/{DefaultBudget.MaxCpuUpdates} cpu updates / {resourcePlan.GpuEstimatedCost:0.0}/{DefaultBudget.MaxGpuEstimatedCost:0.0} gpu cost / {resourcePlan.Residency.ResidentNodes.Count}/{DefaultBudget.MaxResidentPayloads} resident / {resourcePlan.Residency.RequestedNodes.Count}/{DefaultBudget.MaxSsdRequests} ssd requests / {(structuralProbeReservoir.HasSample ? structuralProbeReservoir.CandidateCount : 0)} probe candidates / {bucketPixelsPerWorld:0.00} px-wu");
}
private static string CutCacheKey(IReadOnlyList<AquariumSelectedCut> selectedCut)
@ -105,6 +112,8 @@ public static class ZyphosFractalTerrain
$" gpuEstimatedCost: {plan.ResourcePlan.GpuEstimatedCost:0.000}/{budget.MaxGpuEstimatedCost:0.000}",
$" ramResident: {plan.ResourcePlan.Residency.ResidentNodes.Count}/{budget.MaxResidentPayloads}",
$" ssdRequests: {plan.ResourcePlan.Residency.RequestedNodes.Count}/{budget.MaxSsdRequests}",
$" structuralProbe: {(plan.StructuralProbeReservoir.HasSample ? plan.StructuralProbeReservoir.NodeKey.Value : "none")}",
$" structuralProbeWeight: {plan.StructuralProbeReservoir.WeightSum:0.000} candidates={plan.StructuralProbeReservoir.CandidateCount} contributionWeight={plan.StructuralProbeReservoir.ContributionWeight:0.000}",
"selected:",
};
@ -144,5 +153,6 @@ public readonly record struct ZyphosFractalRenderPlan(
AquariumHeightFieldBrush[] HeightBrushes,
AquariumSelectedCut[] SelectedCuts,
FractalResourcePlan ResourcePlan,
FractalProbeReservoirSnapshot StructuralProbeReservoir,
float PixelsPerWorld,
string Summary);

View file

@ -166,3 +166,4 @@
{"timestamp":"2026-05-19T20:10:00+01:00","topic":"explicit-reservoir-guide-targets","lesson":"Phase B of the Perfect Machine architecture is implemented: the renderer now owns explicit current and history reservoir guide targets instead of packing previous reservoir validity into scene-control/history-control. Guide schema is x=reservoir confidence, y=sample age, z=domain validity, w=invalidation code. SDF and temporal Gaussian passes write the current guide; D3D12Post validates against current/previous guide data and persists the next guide while history-control.w remains pixel history age.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12SdfCommon.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12SdfProxy.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12TemporalGaussian.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","docs/perfect-machine-architecture.md","docs/temporal-spatial-evidence-reservoir.md"],"source":"Perfect Machine marching orders after architecture note became the design authority"}
{"timestamp":"2026-05-19T20:39:00+01:00","topic":"fractal-occupancy-graph","lesson":"FractalContributionCache now routes through `FractalOccupancyGraph`, the first explicit occupancy memory organ from the Perfect Machine architecture. The graph owns contribution estimates plus visibility/update-probability telemetry; observations update mean/variance/confidence through the existing estimator, and unobserved nodes lose confidence while stale uncertainty grows. This keeps cache convergence state in one authority instead of growing side tables.","files":["src/Aquarium.Engine.Fractal/Lod/FractalOccupancyGraph.cs","src/Aquarium.Engine.Fractal/Lod/FractalContributionCache.cs","tests/Aquarium.Engine.Fractal.Tests/FractalOccupancyGraphTests.cs","tests/Aquarium.Engine.Fractal.Tests/FractalContributionCacheTests.cs","docs/perfect-machine-architecture.md","research/rendering/fractal-brush-implementation-roadmap.md"],"source":"Perfect Machine Phase D implementation after explicit reservoir guide targets"}
{"timestamp":"2026-05-19T21:01:00+01:00","topic":"structural-probe-generator","lesson":"IFS structure can now enter the reservoir path as typed evidence. `FractalStructuralProbeGenerator` lowers `AquariumFractalSummary` rows into `FractalProbeSample` candidates with local center, bound radius, projected target contribution, clamped source PDF, material delta, and payload handle. This gives structural `.aquageo` summaries a real producer boundary before renderer-facing temporal validation and GPU reservoir reuse are added.","files":["src/Aquarium.Engine.Fractal/Lod/FractalStructuralProbeGenerator.cs","tests/Aquarium.Engine.Fractal.Tests/FractalStructuralProbeGeneratorTests.cs","docs/perfect-machine-architecture.md","research/rendering/fractal-brush-implementation-roadmap.md","state/memory.json"],"source":"Perfect Machine Phase C implementation after occupancy graph promotion"}
{"timestamp":"2026-05-19T21:18:00+01:00","topic":"zyphos-structural-probe-reservoir","lesson":"Zyphos now exposes a structural probe reservoir beside its selected cut and resource plan. `FractalStructuralProbeReservoir` builds a selected-cut `FractalProbeSample` reservoir from the ownership tree, summaries, node domains, and projected pixels per world unit; `ZyphosFractalRenderPlan` carries the snapshot and the debug dump reports selected probe weight/candidate count. This connects the pure IFS structural-probe producer to a live client path before GPU reservoir buffers are introduced.","files":["src/Aquarium.Engine.Fractal/Lod/FractalStructuralProbeReservoir.cs","src/Aquarium.Zyphos/ZyphosFractalTerrain.cs","tests/Aquarium.Engine.Fractal.Tests/FractalStructuralProbeReservoirTests.cs","tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs","docs/perfect-machine-architecture.md","research/rendering/fractal-brush-implementation-roadmap.md"],"source":"continuing Perfect Machine Phase C after adding structural probe generation"}

View file

@ -94,6 +94,7 @@
"FractalOccupancyGraph is now the live memory behind FractalContributionCache. It owns per-node contribution state, last visible frame, last observed score, and update probability; unobserved nodes decay confidence and grow stale uncertainty. Keep richer residency/resource fields here rather than adding another cache beside it.",
"FractalProbeSample is the typed reservoir sample shape for fractal SDF/detail reuse: domain key, node key, local center, bound radius, target contribution, source PDF, material delta, and payload handle. Reuse must pass domain lineage and local-shift validation now, and later camera motion, disocclusion, material compatibility, and visibility validation before it is allowed into temporal/spatial reuse.",
"FractalStructuralProbeGenerator lowers AquariumFractalSummary rows into FractalProbeSample reservoir candidates with local support, projected target contribution, clamped source PDF, material delta, and payload handle. This is the structural IFS probe producer; renderer-facing temporal validation still needs camera/disocclusion/material/visibility inputs.",
"FractalStructuralProbeReservoir builds a reservoir snapshot from an ownership tree, selected cut, summaries, and projected pixels per world unit. ZyphosFractalRenderPlan now carries this structural probe reservoir, so the planet path exposes reservoir-shaped structural evidence beside brushes/resource plans before GPU reuse exists.",
"Zyphos camera distance limits belong to the selected spatial domain, not one global planetary clamp. Leaf/pebble domains must be able to zoom below whole-body distances, and the parent star must be a visible SDF body when it is also the primary light source.",
"The consolidated fractal brush architecture lives in research/rendering/fractal-brush-architecture-plan.md. Its pipeline is client intent -> domain roots -> semantic IFS brush grammar -> ownership tree -> node summaries -> contribution cache/residency scheduler -> backend packets -> renderer passes -> debug/evidence. Its credibility depends on module boundaries and tests: contracts, pure CPU fractal core, D3D12 backend, client adapters, mock payload/probe/random/clock seams, shader parity tests, and deterministic performance fixtures.",
"The Perfect Machine waterfall architecture lives in docs/perfect-machine-architecture.md. Treat it as the design authority before expanding SDF splat backends, sensor-fusion candidate adapters, reservoir guide buffers, occupancy graph state, resource-tier residency, or stochastic learned priority. Its core split is domains -> evidence candidates -> target evaluation -> ReSTIR/GRIS reservoirs -> occupancy graph -> residency -> 2D/3D/projected SDF splat packets -> TAA guide buffers.",

View file

@ -0,0 +1,66 @@
using System.Numerics;
using Aquarium.Engine.Fractal;
using Aquarium.Engine.Fractal.Grammar;
using Aquarium.Engine.Fractal.Lod;
namespace Aquarium.Engine.Fractal.Tests;
public sealed class FractalStructuralProbeReservoirTests
{
[Fact]
public void StructuralProbeReservoirBuildsFromSelectedCut()
{
var domainKey = new AquariumFractalKey("domain/tile");
var rootKey = new AquariumFractalKey("domain/tile/root");
var domain = new AquariumFractalDomain(domainKey, AquariumFractalDomainKind.CubeSphereTile, default, Vector4.Zero, Vector4.Zero);
var tree = FractalOwnershipTreeBuilder.BuildFlatUnion(domain, rootKey, [
Claim("claim/a", domainKey, rootKey, Vector2.Zero, Vector2.One),
]);
var summaries = FractalSummaryBuilder.Build(tree);
var cut = FractalSelectedCutBuilder.Build(summaries, _ => 8.0f, maxEstimatedCost: 8.0f);
var snapshot = FractalStructuralProbeReservoir.Build(tree, summaries, cut, 8.0f, new TestFractalRandom(0.0));
Assert.True(snapshot.HasSample);
Assert.Equal(domainKey, snapshot.DomainKey);
Assert.Equal(rootKey, snapshot.NodeKey);
Assert.Equal(1, snapshot.CandidateCount);
Assert.True(snapshot.TargetContribution > 0.0f);
Assert.True(snapshot.WeightSum > 0.0f);
}
[Fact]
public void StructuralProbeReservoirReturnsEmptyForEmptyCut()
{
var domainKey = new AquariumFractalKey("domain/tile");
var domain = new AquariumFractalDomain(domainKey, AquariumFractalDomainKind.CubeSphereTile, default, Vector4.Zero, Vector4.Zero);
var tree = FractalOwnershipTreeBuilder.BuildFlatUnion(domain, new AquariumFractalKey("domain/tile/root"), []);
var snapshot = FractalStructuralProbeReservoir.Build(tree, [], [], 8.0f, new TestFractalRandom(0.0));
Assert.False(snapshot.HasSample);
Assert.Equal(0, snapshot.CandidateCount);
}
private static AquariumBrushClaim Claim(
string key,
AquariumFractalKey domainKey,
AquariumFractalKey nodeKey,
Vector2 center,
Vector2 radii)
{
return new AquariumBrushClaim(
new AquariumFractalKey(key),
domainKey,
nodeKey,
AquariumFractalPayloadKind.Height,
center,
radii,
RotationRadians: 0.0f,
Falloff: 4.0f,
ShapePower: 1.0f,
Amplitude: 1.0f,
Seed: 17,
Tags: "probe");
}
}

View file

@ -52,6 +52,10 @@ public sealed class ZyphosFractalTerrainTests
Assert.Contains("cpu updates", near.Summary, StringComparison.Ordinal);
Assert.Contains("gpu cost", near.Summary, StringComparison.Ordinal);
Assert.Contains("resident", near.Summary, StringComparison.Ordinal);
Assert.Contains("probe candidates", near.Summary, StringComparison.Ordinal);
Assert.True(near.StructuralProbeReservoir.HasSample);
Assert.True(near.StructuralProbeReservoir.CandidateCount > 0);
Assert.True(near.StructuralProbeReservoir.WeightSum > 0.0f);
Assert.Empty(near.ResourcePlan.Residency.RequestedNodes);
Assert.True(MathF.Abs(near.HeightBrushes[0].Amplitude) * MathF.Max(near.HeightBrushes[0].Radius, near.HeightBrushes[0].RadiusY) >=
MathF.Abs(near.HeightBrushes[^1].Amplitude) * MathF.Max(near.HeightBrushes[^1].Radius, near.HeightBrushes[^1].RadiusY));
@ -68,6 +72,8 @@ public sealed class ZyphosFractalTerrainTests
Assert.Contains("gpuEstimatedCost:", dump, StringComparison.Ordinal);
Assert.Contains("ramResident:", dump, StringComparison.Ordinal);
Assert.Contains("ssdRequests:", dump, StringComparison.Ordinal);
Assert.Contains("structuralProbe:", dump, StringComparison.Ordinal);
Assert.Contains("structuralProbeWeight:", dump, StringComparison.Ordinal);
Assert.Contains("selected:", dump, StringComparison.Ordinal);
}
}