diff --git a/research/rendering/fractal-brush-implementation-roadmap.md b/research/rendering/fractal-brush-implementation-roadmap.md index 7b026c1..ba63f28 100644 --- a/research/rendering/fractal-brush-implementation-roadmap.md +++ b/research/rendering/fractal-brush-implementation-roadmap.md @@ -218,7 +218,7 @@ Tasks: - [x] Implement operations: `Union`, `Subtract`, `Common`, `Repeat`, `Refine`, `Capture`, `Bind`. - [ ] Implement operation bounds. - [x] Add flattening compiler to shaped 2D brush packets. -- [ ] Add debug dump for authored tree and flattened packets. +- [x] Add debug dump for authored tree and flattened packets. Tests: @@ -277,7 +277,7 @@ Tasks: - [x] Add selected-cut builder. - [x] Add hysteresis fade weights. - [x] Add budget clamp. -- [ ] Add debug channels: score, depth, fade, estimated cost. +- [x] Add debug channels: score, depth, fade, estimated cost. Tests: @@ -336,7 +336,7 @@ Tasks: - [x] Add child request queue. - [ ] Add score/cost eviction policy. - [x] Add parent-summary fallback path. -- [ ] Add debug channels: residency, requests, evictions. +- [x] Add debug channels: residency, requests, evictions. Tests: diff --git a/src/Aquarium.Engine.Fractal/Debug/FractalDebugDump.cs b/src/Aquarium.Engine.Fractal/Debug/FractalDebugDump.cs new file mode 100644 index 0000000..273b60c --- /dev/null +++ b/src/Aquarium.Engine.Fractal/Debug/FractalDebugDump.cs @@ -0,0 +1,58 @@ +using System.Globalization; +using System.Text; +using Aquarium.Engine.Fractal; +using Aquarium.Engine.Fractal.Grammar; + +namespace Aquarium.Engine.Fractal.Debug; + +public static class FractalDebugDump +{ + public static string Build( + FractalOwnershipTree tree, + IReadOnlyList summaries, + IReadOnlyList selectedCut) + { + ArgumentNullException.ThrowIfNull(tree); + ArgumentNullException.ThrowIfNull(summaries); + ArgumentNullException.ThrowIfNull(selectedCut); + + var builder = new StringBuilder(); + builder.AppendLine($"domain {tree.Domain.Key} kind={tree.Domain.Kind}"); + builder.AppendLine($"nodes {tree.Nodes.Count} claims {tree.Claims.Count} summaries {summaries.Count} cut {selectedCut.Count}"); + foreach (var node in tree.Nodes) + { + builder.AppendLine($"node {node.Key} op={node.Operation} claims={node.ClaimCount} bounds={FormatBounds(node.BoundsMinMax)}"); + } + + foreach (var claim in tree.Claims) + { + builder.AppendLine( + string.Create( + CultureInfo.InvariantCulture, + $"claim {claim.Key} payload={claim.PayloadKind} center=({claim.Center.X:0.###},{claim.Center.Y:0.###}) radii=({claim.Radii.X:0.###},{claim.Radii.Y:0.###}) amp={claim.Amplitude:0.###} tags={claim.Tags}")); + } + + foreach (var summary in summaries) + { + builder.AppendLine( + string.Create( + CultureInfo.InvariantCulture, + $"summary {summary.NodeKey} heightError={summary.MaxHeightError:0.###} cost={summary.EstimatedCost:0.###} descendants={summary.DescendantCount}")); + } + + foreach (var cut in selectedCut) + { + builder.AppendLine( + string.Create( + CultureInfo.InvariantCulture, + $"cut {cut.NodeKey} score={cut.Score:0.###} fade={cut.Fade:0.###} summary={cut.UsesSummary} requestChildren={cut.RequestedChildren}")); + } + + return builder.ToString(); + } + + private static string FormatBounds(System.Numerics.Vector4 bounds) + { + return string.Create(CultureInfo.InvariantCulture, $"({bounds.X:0.###},{bounds.Y:0.###})-({bounds.Z:0.###},{bounds.W:0.###})"); + } +} diff --git a/src/Aquarium.Zyphos/ZyphosFractalTerrain.cs b/src/Aquarium.Zyphos/ZyphosFractalTerrain.cs index 48e2010..f9d2f89 100644 --- a/src/Aquarium.Zyphos/ZyphosFractalTerrain.cs +++ b/src/Aquarium.Zyphos/ZyphosFractalTerrain.cs @@ -1,5 +1,8 @@ +using Aquarium.Engine.Fractal; using Aquarium.Engine.Fractal.Brushes; +using Aquarium.Engine.Fractal.Debug; using Aquarium.Engine.Fractal.Grammar; +using Aquarium.Engine.Fractal.Lod; using Aquarium.Engine.Render; namespace Aquarium.Zyphos; @@ -15,12 +18,16 @@ public static class ZyphosFractalTerrain """; private static readonly Lazy Tree = new(() => FractalDslCompiler.Compile(Grammar)); + private static readonly Lazy Summaries = new(() => FractalSummaryBuilder.Build(Tree.Value)); + private static readonly Lazy SelectedCut = new(() => FractalSelectedCutBuilder.Build(Summaries.Value, _ => 8.0f, maxEstimatedCost: 8.0f)); private static readonly Lazy Brushes = new(() => FractalHeightBrushCompiler.CompileMany(Tree.Value.Claims)); public static FractalOwnershipTree OwnershipTree => Tree.Value; public static AquariumHeightFieldBrush[] HeightBrushes => Brushes.Value; + public static string DebugDump => FractalDebugDump.Build(OwnershipTree, Summaries.Value, SelectedCut.Value); + public static string Summary => - $"{OwnershipTree.Claims.Count} DSL claims / {OwnershipTree.Nodes.Count} node / {HeightBrushes.Length} shaped brushes"; + $"{OwnershipTree.Claims.Count} DSL claims / {OwnershipTree.Nodes.Count} node / {SelectedCut.Value.Length} cuts / {HeightBrushes.Length} shaped brushes"; } diff --git a/src/Aquarium.Zyphos/ZyphosRuntime.cs b/src/Aquarium.Zyphos/ZyphosRuntime.cs index 73ea7a4..0b2f29e 100644 --- a/src/Aquarium.Zyphos/ZyphosRuntime.cs +++ b/src/Aquarium.Zyphos/ZyphosRuntime.cs @@ -50,7 +50,8 @@ public sealed class ZyphosRuntime : IAquariumRuntime panel.Readout("Terrain DSL", () => ZyphosFractalTerrain.Summary); panel.Readout("Objects", () => "fractal height DSL, atmosphere, moon"); }) - .Command("zyphos", _ => $"Zyphos: {ZyphosFractalTerrain.Summary}", "Report Zyphos demo status."); + .Command("zyphos", _ => $"Zyphos: {ZyphosFractalTerrain.Summary}", "Report Zyphos demo status.") + .Command("zyphos-fractal", _ => ZyphosFractalTerrain.DebugDump, "Dump the compiled Zyphos fractal terrain grammar."); } public AquariumFrame ComposeFrame(AquariumFrame frame, AquariumFrameInput input) diff --git a/state/evidence.jsonl b/state/evidence.jsonl index a465262..269e023 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -131,3 +131,4 @@ {"timestamp":"2026-05-18T05:31:00+01:00","topic":"fractal-pipeline-fixture","lesson":"The first fractal architecture spine now composes end to end in a test fixture: cube tile stable key -> semantic domain/claim -> ownership tree -> conservative summary -> selected cut -> residency fallback/request -> shaped height brush compiler. Keep extending this fixture as the interview-grade proof that module boundaries are real and not prose taped to unrelated helpers.","files":["tests/Aquarium.Engine.Fractal.Tests/FractalPipelineFixtureTests.cs"],"source":"eleventh fractal implementation slice added an end-to-end composition test for the new module network"} {"timestamp":"2026-05-18T05:49:00+01:00","topic":"fractal-dsl-first-slice","lesson":"Aquarium now has a first line-oriented fractal DSL that compiles into semantic ownership trees instead of renderer packets. The DSL declares a cube tile domain, direct shaped `height` claims, and recursive `ifs` emitters with deterministic seeded branching. Keep this syntax small until Zyphos proves it visually; the language authority is semantic claims, not shader-side brush bags.","files":["src/Aquarium.Engine.Fractal/Grammar/FractalDslCompiler.cs","tests/Aquarium.Engine.Fractal.Tests/FractalDslCompilerTests.cs","research/rendering/fractal-brush-implementation-roadmap.md"],"source":"user explicitly wanted to express a fractal world in Aquarium's own DSL and see it rendered"} {"timestamp":"2026-05-18T06:04:00+01:00","topic":"zyphos-fractal-dsl-render-proof","lesson":"Zyphos now renders its height field from Aquarium's fractal DSL instead of a hand-authored circular brush. `ZyphosFractalTerrain` owns the demo grammar, compiles it through `FractalDslCompiler` into a semantic ownership tree, and lowers claims to shaped height brushes through `FractalHeightBrushCompiler`. This is the first visible proof path for authoring a fractal world in Aquarium's own DSL and seeing it inside the engine.","files":["src/Aquarium.Zyphos/ZyphosFractalTerrain.cs","src/Aquarium.Zyphos/ZyphosSceneBuilder.cs","src/Aquarium.Zyphos/ZyphosRuntime.cs","tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs"],"source":"user emphasized wanting to express a fractal world in the DSL and see it rendered in engine"} +{"timestamp":"2026-05-18T06:18:00+01:00","topic":"fractal-debug-dump","lesson":"Fractal worlds now have a text debug dump that reports domain, nodes, claims, summaries, and selected cuts. Zyphos exposes this through the `zyphos-fractal` command so the rendered DSL terrain can be inspected as authored semantic rows and LOD decisions instead of inferred from pixels alone.","files":["src/Aquarium.Engine.Fractal/Debug/FractalDebugDump.cs","src/Aquarium.Zyphos/ZyphosFractalTerrain.cs","src/Aquarium.Zyphos/ZyphosRuntime.cs","tests/Aquarium.Engine.Fractal.Tests/FractalDebugDumpTests.cs"],"source":"observability pass after wiring Zyphos to the fractal DSL renderer path"} diff --git a/tests/Aquarium.Engine.Fractal.Tests/FractalDebugDumpTests.cs b/tests/Aquarium.Engine.Fractal.Tests/FractalDebugDumpTests.cs new file mode 100644 index 0000000..1e608c5 --- /dev/null +++ b/tests/Aquarium.Engine.Fractal.Tests/FractalDebugDumpTests.cs @@ -0,0 +1,29 @@ +using System.Numerics; +using Aquarium.Engine.Fractal; +using Aquarium.Engine.Fractal.Debug; +using Aquarium.Engine.Fractal.Grammar; +using Aquarium.Engine.Fractal.Lod; + +namespace Aquarium.Engine.Fractal.Tests; + +public sealed class FractalDebugDumpTests +{ + [Fact] + public void DebugDumpNamesDomainClaimsSummariesAndCuts() + { + const string source = """ + tile PositiveZ 0 0 0 debug/world + height ridge 1 2 3 1 0.4 4 0.8 0.2 9 ridge + """; + var tree = FractalDslCompiler.Compile(source); + var summaries = FractalSummaryBuilder.Build(tree); + var cut = FractalSelectedCutBuilder.Build(summaries, _ => 10.0f, maxEstimatedCost: 1.0f); + + var dump = FractalDebugDump.Build(tree, summaries, cut); + + Assert.Contains("domain cube/PositiveZ/L00/0/0:debug/world", dump); + Assert.Contains("claim cube/PositiveZ/L00/0/0:debug/world/root/claim/0000/ridge", dump); + Assert.Contains("summary cube/PositiveZ/L00/0/0:debug/world/root", dump); + Assert.Contains("cut cube/PositiveZ/L00/0/0:debug/world/root", dump); + } +}