Measure flame reservoir visual parity

This commit is contained in:
Meta Vens 2026-05-20 16:19:11 +01:00
commit bb02bae34b
6 changed files with 222 additions and 5 deletions

View file

@ -114,6 +114,42 @@ Local GTX 1070 receipt from 2026-05-20:
- equivalent FPS: `971.3`
- readback checksum: `0x2647D8B08575B848`
## Visual Parity Receipt
The receipt tool can compare GPU flame splat positions against the local CPU
flame oracle:
```powershell
.\scripts\fractal-splat-receipt.ps1 `
-Splats 2000000 `
-SplatUpdates 50000 `
-Warmup 0 `
-Frames 20 `
-Depth 8 `
-ReservoirUpdates 15000 `
-ProgramFlame tests\Aquarium.Engine.Fractal.Tests\Fixtures\Apophysis\linear-spherical-bubble.flame `
-ReadbackSplats 250000 `
-VisualParity `
-VisualParityReferenceSamples 1000000 `
-HistogramSize 128x128 `
-HistogramBounds -8,-8,8,8
```
First local scores, GPU 250k readback samples against 1M CPU reference samples:
| Frames | GPU ms/frame | Distribution score | L1 distance | RMSE | Cosine |
| ---: | ---: | ---: | ---: | ---: | ---: |
| 1 | 15.645 | 84.05% | 0.319072 | 0.000090 | 0.995365 |
| 5 | 4.017 | 84.10% | 0.318042 | 0.000089 | 0.995402 |
| 20 | 1.738 | 84.20% | 0.316019 | 0.000088 | 0.995591 |
| 60 + 10 warmup | 0.952 | 84.24% | 0.315136 | 0.000088 | 0.995505 |
This proves the current GPU flame program has high distribution similarity, but
it does **not** prove learned reservoir convergence. The score plateaus because
the current flame path initializes resident splats from the program and then
performs stochastic replacement; it does not yet use visual error feedback,
MIS/ReSTIR weights, or an external rendered-image residual to steer updates.
## Sources
- Apophysis 7x repository: https://github.com/wanily/apophysis7x

View file

@ -8,6 +8,10 @@ param(
[int]$ReservoirUpdates = 50000,
[int]$ProgramTransforms = 0,
[string]$ProgramFlame = "",
[switch]$VisualParity,
[int]$VisualParityReferenceSamples = 1000000,
[string]$HistogramSize = "64x64",
[string]$HistogramBounds = "-8,-8,8,8",
[int]$ReadbackSplats = 64
)
@ -19,6 +23,16 @@ if (-not [string]::IsNullOrWhiteSpace($ProgramFlame)) {
$programArgs = @("--program-flame", $programFlamePath)
}
$parityArgs = @()
if ($VisualParity) {
$parityArgs = @(
"--visual-parity",
"--visual-parity-reference-samples", "$VisualParityReferenceSamples",
"--histogram-size", $HistogramSize,
"--histogram-bounds", $HistogramBounds
)
}
dotnet run --project (Join-Path $repoRoot "tools\Aquarium.Fractal.Receipt\Aquarium.Fractal.Receipt.csproj") -c Release -- `
--splats $Splats `
--splat-updates $SplatUpdates `
@ -28,4 +42,5 @@ dotnet run --project (Join-Path $repoRoot "tools\Aquarium.Fractal.Receipt\Aquari
--candidates $Candidates `
--reservoir-updates $ReservoirUpdates `
$programArgs `
$parityArgs `
--readback-splats $ReadbackSplats

View file

@ -150,6 +150,7 @@ renderer_state:
- The Apophysis/FLAM3 reference subset now has a runtime parser/evaluator boundary: FractalFlameFileParser reads `.flame` xforms with weight, color, affine coefficients, and `linear`/`spherical`/`bubble` variation weights; FractalFlameChaosGame produces deterministic point sets; FractalPointHistogramBuilder produces fixed histogram checksums for parity receipts.
- tools/Aquarium.Fractal.Receipt can now run a CPU flame histogram receipt with `--flame`; scripts/fractal-flame-receipt.ps1 emits the default linear/spherical/bubble fixture checksum 0xAEB1C81B under artifacts/fractal-flame-receipts. It can also hash binary PPM renders with `--reference-ppm`; scripts/fractal-flame-reference-render.ps1 drives a local external `flam3-render` through FLAM3's documented env vars and records image-shape/non-black/checksum receipts under artifacts/fractal-flame-reference without vendoring GPL renderer code.
- D3D12FractalReservoirCompute has an explicit flame 2D program mode for the proven FLAM3-style subset. FractalGpuProgramCompiler lowers flame rows into packed affine/variation program rows, and tools/Aquarium.Fractal.Receipt can run them with `--program-flame`. The splat cache initializes all resident rows once, then stochastic frame updates touch a budgeted subset. Local GTX 1070 receipt: 2,000,000 resident splats, 2,000,000 SDF/PBR/radiosity reservoirs each, 50,000 splat updates/frame, 15,000 reservoir updates/pass/frame, depth 8, 3 flame transforms, 1.030 ms/frame, 971.3 FPS equivalent, checksum 0x2647D8B08575B848.
- The first visual parity receipt compares GPU flame splat XY histograms against the CPU flame oracle. With 250,000 GPU readback splats and 1,000,000 CPU reference samples in 128x128 bounds -8,-8,8,8, the mixed flame fixture scores 84.05% distribution parity at frame 1, 84.10% at frame 5, 84.20% at frame 20, and 84.24% after the 60-frame/10-warmup receipt, with cosine similarity around 0.9955. This is a stable sampler score, not proof of learned convergence; visual-error feedback is still future work.
- D3D12 capacity logging now reports active fractal reservoir resident MiB, splat count, visible debug splat count, updates/pass, and candidates/update so the GPU cache has a receipt in normal runtime logs, not just in the standalone benchmark.
- The consolidated fractal brush architecture plan defines the intended pipeline: client intent -> domain roots -> semantic IFS brush grammar -> ownership tree -> node summaries -> contribution cache/residency scheduler -> backend packets -> renderer passes -> debug/evidence, with explicit module boundaries and mockable unit-test seams.
- The Perfect Machine architecture lives in docs/perfect-machine-architecture.md. It is the current waterfall design authority for fast 2D SDF splats, 3D SDF splats, 2D-projected-to-3D surface splats, IFS `.aquageo` structural probes, Mimir-style camera/audio evidence candidates, ReSTIR/GRIS reservoir reuse, heuristic occupancy graph updates, resource-tier residency, and TAA guide-buffer integration.

View file

@ -108,6 +108,7 @@
"The local Apophysis/FLAM3 subset parser owns only a small proven flame shape: xform weight/color, affine coefficients, and `linear`, `spherical`, and `bubble` variation weights. `FractalFlameChaosGame` and `FractalPointHistogramBuilder` provide deterministic CPU receipts. External renderer proof stays optional and outside runtime through FLAM3-compatible PPM receipt hashing.",
"Use `scripts/fractal-flame-receipt.ps1` for the local CPU flame receipt. The default mixed linear/spherical/bubble fixture uses 8192 samples, 64 burn-in, 64x64 bounds -8,-8,8,8, seed 0x0BADC0DE, and checksum 0xAEB1C81B. Use `scripts/fractal-flame-reference-render.ps1` with a local `flam3-render` executable to produce external PPM image receipts under artifacts/fractal-flame-reference; Aquarium does not vendor Apophysis or FLAM3.",
"FractalGpuProgramCompiler can lower the proven FLAM3-style flame subset into GPU program rows for D3D12FractalReservoirCompute's explicit flame 2D program mode. The receipt path initializes the full resident splat cache once, then stochastically updates a splat subset per frame; on 2026-05-20 the GTX 1070 ran the mixed flame fixture with 2,000,000 resident splats, three 2,000,000-row reservoir layers, 50,000 splat updates/frame, 15,000 reservoir updates/pass/frame, depth 8, and 3 flame transforms at 1.030 ms/frame / 971.3 FPS equivalent, checksum 0x2647D8B08575B848.",
"The first visual parity metric compares GPU flame splat XY histograms against the local CPU flame oracle. With 250,000 GPU readback splats, 1,000,000 CPU reference samples, 128x128 bounds -8,-8,8,8, and the mixed FLAM3-style fixture, distribution score is 84.05% at frame 1, 84.10% at frame 5, 84.20% at frame 20, and 84.24% after the 60-frame/10-warmup receipt; cosine similarity stays about 0.9955. This is high distribution similarity but not learned convergence: the current reservoir path initializes splats and stochastically replaces them, without visual-error feedback or ReSTIR/MIS target correction yet.",
"Zyphos' primary planetary terrain test path is now the fractal reservoir surface. The direct SDF planet and Umbros proxy shaders are removed from the render plan; only the parent star remains as a direct SDF body/light. If the planet looks wrong, fix the reservoir lowering/shading path instead of letting the old SDF terrain hide it.",
"The GPU splat receipt harness lives at tools/Aquarium.Fractal.Receipt and scripts/fractal-splat-receipt.ps1. The live receipt allocates one 80-byte packed SDF splat UAV plus three distinct 64-byte reservoir UAVs for SDF envelopes, PBR material envelopes, and radiosity; those reservoirs are sampled in independent compute passes under a stochastic update budget. On the local NVIDIA GTX 1070 it kept 2,000,000 splats and 2,000,000 reservoirs per layer resident. The fallback hash-fractal receipt updated 50,000 entries per layer with 2 candidates/update at 4.471 ms/frame, 223.7 FPS equivalent. The authored precomposed selected-cut receipt used depth 48, 4 compact transforms, and 15,000 updates per layer at 4.908 ms/frame, 203.7 FPS equivalent, with full reservoir coverage in 133.3 frames. D3D12FractalSplatRender consumes the raw splat, SDF, PBR, and radiosity buffers through separate graphics SRVs for the visible debug subset. This proves compute-side GPU residency, budgeted temporal convergence, authored-program splat population decoupled from domain ancestry depth, and first layered GPU consumption; final terrain/material/radiosity shading is still future work.",
"FractalProjectedSdfSplatCompiler is the Phase G 2D-projected-to-3D lowering seam: it converts resident SignedDistance2D page payload samples into compact 3D SDF splats through an explicit page-local Vector2 -> Vector3 mapping, surface normal, support radius, and splat budget. Zyphos caches a bounded first set with a flat local mapping until cube-sphere/torus mappers are added.",

View file

@ -47,6 +47,10 @@ The renderer work that matters next:
`scripts/fractal-splat-receipt.ps1 -ProgramFlame ... -SplatUpdates 50000`
is the GPU-resident flame stress receipt path; it initializes resident splats
once and then performs budgeted stochastic updates.
Add `-VisualParity -ReadbackSplats 250000 -HistogramSize 128x128` to score
GPU splat histograms against the CPU flame oracle. Current score plateaus
near 84.2% distribution parity / 0.9955 cosine, so the next architectural
need is visual-error feedback, not more raw sampling theater.
- Use `docs/zyphos-eusocial-sync.md` before evolving Zyphos world content.
Eusocial Interbeing owns canon in `E:\Projects\Eusocial Interbeing`; Zyphos
owns render constraints and feeds design questions back through the vault's

View file

@ -53,6 +53,16 @@ Console.WriteLine($"gpu splats/sec: {receipt.GpuSplatsPerSecond:N0}");
Console.WriteLine($"gpu reservoir candidates/sec: {receipt.GpuReservoirCandidatesPerSecond:N0}");
Console.WriteLine($"cpu submit+wait ms/frame: {receipt.CpuSubmitAndWaitMillisecondsPerFrame:0.000}");
Console.WriteLine($"readback checksum: 0x{receipt.ReadbackChecksum:X16}");
if (receipt.VisualParity is not null)
{
Console.WriteLine($"visual parity samples: {receipt.VisualParity.ComparedSamples:N0}/{receipt.VisualParity.ReferenceSamples:N0}");
Console.WriteLine($"visual parity bins: {receipt.VisualParity.Width}x{receipt.VisualParity.Height}");
Console.WriteLine($"visual parity occupancy overlap: {receipt.VisualParity.OccupancyOverlapPercent:0.00}%");
Console.WriteLine($"visual parity distribution score: {receipt.VisualParity.DistributionScorePercent:0.00}%");
Console.WriteLine($"visual parity l1 distance: {receipt.VisualParity.L1Distance:0.000000}");
Console.WriteLine($"visual parity rmse: {receipt.VisualParity.Rmse:0.000000}");
Console.WriteLine($"visual parity cosine: {receipt.VisualParity.CosineSimilarity:0.000000}");
}
Console.WriteLine($"receipt: {receiptPath}");
static string DescribeProgramMode(int mode)
@ -257,6 +267,7 @@ internal sealed class GpuFractalSplatReceiptRunner : IDisposable
}
var checksum = totalReadbackBytes == 0 ? 0UL : Checksum(readback, (int)totalReadbackBytes);
var visualParity = totalReadbackBytes == 0 ? null : BuildVisualParity(options, readback, splatStride, (int)(readbackSplatBytes / (ulong)splatStride));
var gpuSeconds = measuredGpuTicks / (double)timestampFrequency;
var gpuMsPerFrame = gpuSeconds * 1000.0 / Math.Max(measuredFrames, 1);
var cpuMsPerFrame = measuredCpuTicks * 1000.0 / Stopwatch.Frequency / Math.Max(measuredFrames, 1);
@ -283,7 +294,8 @@ internal sealed class GpuFractalSplatReceiptRunner : IDisposable
splatsPerSecond,
reservoirCandidatesPerSecond,
cpuMsPerFrame,
checksum);
checksum,
visualParity);
void Dispatch(ID3D12PipelineState state, int elementCount)
{
@ -409,6 +421,115 @@ internal sealed class GpuFractalSplatReceiptRunner : IDisposable
commandList.ResourceBarrier(ResourceBarrier.BarrierTransition(radiosity, ResourceStates.CopySource, ResourceStates.UnorderedAccess));
}
private static unsafe VisualParityReceipt? BuildVisualParity(
ReceiptOptions options,
ID3D12Resource readback,
int splatStride,
int readbackSplatCount)
{
if (!options.VisualParity || options.ProgramFlamePath is null || readbackSplatCount <= 0)
{
return null;
}
var flame = FractalFlameFileParser.ParseFirst(File.ReadAllText(options.ProgramFlamePath), unchecked((int)options.Seed));
var referencePoints = FractalFlameChaosGame.Generate(
flame,
options.VisualParityReferenceSamples,
options.HistogramBurnIn,
new FractalXorShiftRandom(options.Seed));
var referenceHistogram = FractalPointHistogramBuilder.Build(
referencePoints,
options.HistogramWidth,
options.HistogramHeight,
options.HistogramBounds);
var points = new Vector2[readbackSplatCount];
var splats = (AquariumPackedFractalSdfSplat3D*)readback.Map<byte>(0);
for (var index = 0; index < points.Length; index++)
{
var center = splats[index].CenterRadius;
points[index] = new Vector2(center.X, center.Y);
}
readback.Unmap(0);
var gpuHistogram = FractalPointHistogramBuilder.Build(
points,
options.HistogramWidth,
options.HistogramHeight,
options.HistogramBounds);
var metrics = CompareHistograms(referenceHistogram, gpuHistogram);
return new VisualParityReceipt(
readbackSplatCount,
options.VisualParityReferenceSamples,
options.HistogramWidth,
options.HistogramHeight,
[
options.HistogramBounds.X,
options.HistogramBounds.Y,
options.HistogramBounds.Z,
options.HistogramBounds.W,
],
referenceHistogram.HitCount,
gpuHistogram.HitCount,
metrics.ReferenceOccupiedBins,
metrics.GpuOccupiedBins,
metrics.SharedOccupiedBins,
metrics.OccupancyOverlapPercent,
metrics.L1Distance,
metrics.Rmse,
metrics.CosineSimilarity,
metrics.DistributionScorePercent);
}
private static HistogramComparison CompareHistograms(FractalPointHistogram reference, FractalPointHistogram candidate)
{
if (reference.Width != candidate.Width || reference.Height != candidate.Height)
{
throw new ArgumentException("Histogram dimensions must match.");
}
var referenceTotal = Math.Max(reference.HitCount, 1);
var candidateTotal = Math.Max(candidate.HitCount, 1);
var l1 = 0.0;
var squared = 0.0;
var dot = 0.0;
var referenceMagnitude = 0.0;
var candidateMagnitude = 0.0;
var referenceOccupied = 0;
var candidateOccupied = 0;
var sharedOccupied = 0;
for (var index = 0; index < reference.Bins.Length; index++)
{
var referenceProbability = reference.Bins[index] / (double)referenceTotal;
var candidateProbability = candidate.Bins[index] / (double)candidateTotal;
var delta = referenceProbability - candidateProbability;
l1 += Math.Abs(delta);
squared += delta * delta;
dot += referenceProbability * candidateProbability;
referenceMagnitude += referenceProbability * referenceProbability;
candidateMagnitude += candidateProbability * candidateProbability;
var referenceHas = reference.Bins[index] > 0;
var candidateHas = candidate.Bins[index] > 0;
referenceOccupied += referenceHas ? 1 : 0;
candidateOccupied += candidateHas ? 1 : 0;
sharedOccupied += referenceHas && candidateHas ? 1 : 0;
}
var occupiedUnion = Math.Max(referenceOccupied + candidateOccupied - sharedOccupied, 1);
var cosine = dot / Math.Max(Math.Sqrt(referenceMagnitude * candidateMagnitude), 1.0e-12);
var rmse = Math.Sqrt(squared / reference.Bins.Length);
return new HistogramComparison(
referenceOccupied,
candidateOccupied,
sharedOccupied,
sharedOccupied * 100.0 / occupiedUnion,
l1,
rmse,
cosine,
Math.Max(0.0, (1.0 - (l1 * 0.5)) * 100.0));
}
private void WaitForGpu()
{
fenceValue++;
@ -496,7 +617,9 @@ internal sealed record ReceiptOptions(
int HistogramBurnIn,
int HistogramWidth,
int HistogramHeight,
Vector4 HistogramBounds)
Vector4 HistogramBounds,
bool VisualParity,
int VisualParityReferenceSamples)
{
public static ReceiptOptions Parse(string[] args)
{
@ -521,7 +644,9 @@ internal sealed record ReceiptOptions(
64,
64,
64,
new Vector4(-8.0f, -8.0f, 8.0f, 8.0f));
new Vector4(-8.0f, -8.0f, 8.0f, 8.0f),
false,
1_000_000);
for (var index = 0; index < args.Length; index++)
{
var arg = args[index];
@ -547,6 +672,8 @@ internal sealed record ReceiptOptions(
"--histogram-burn-in" => options with { HistogramBurnIn = int.Parse(Next()) },
"--histogram-size" => ParseHistogramSize(options, Next()),
"--histogram-bounds" => ParseHistogramBounds(options, Next()),
"--visual-parity" => options with { VisualParity = true },
"--visual-parity-reference-samples" => options with { VisualParityReferenceSamples = int.Parse(Next()) },
_ => throw new ArgumentException($"Unknown receipt option: {arg}"),
};
}
@ -593,7 +720,12 @@ internal sealed record ReceiptOptions(
throw new FileNotFoundException("Receipt shader file was not found.", options.ShaderPath);
}
if (options.SplatCount <= 0 || options.SplatUpdatesPerFrame <= 0 || options.SplatUpdatesPerFrame > options.SplatCount || options.WarmupFrames < 0 || options.MeasuredFrames <= 0 || options.Depth <= 0 || options.CandidatesPerPass <= 0 || options.ReservoirUpdatesPerPass <= 0 || options.ReservoirUpdatesPerPass > options.SplatCount || options.ProgramTransformCount < 0 || options.ProgramMode < 0 || options.ProgramMode > 2 || options.ReadbackSplats < 0)
if (options.VisualParity && options.ProgramFlamePath is null)
{
throw new ArgumentException("Visual parity requires --program-flame so the GPU distribution has a CPU flame oracle.");
}
if (options.SplatCount <= 0 || options.SplatUpdatesPerFrame <= 0 || options.SplatUpdatesPerFrame > options.SplatCount || options.WarmupFrames < 0 || options.MeasuredFrames <= 0 || options.Depth <= 0 || options.CandidatesPerPass <= 0 || options.ReservoirUpdatesPerPass <= 0 || options.ReservoirUpdatesPerPass > options.SplatCount || options.ProgramTransformCount < 0 || options.ProgramMode < 0 || options.ProgramMode > 2 || options.ReadbackSplats < 0 || options.VisualParityReferenceSamples <= 0)
{
throw new ArgumentOutOfRangeException(nameof(args), "Splats, splat updates, frames, depth, candidates, and reservoir updates must be positive; splat/reservoir updates must not exceed splats; program transforms, warmup, and readback must not be negative.");
}
@ -660,6 +792,33 @@ internal sealed record ReferencePpmReceipt(
ulong RgbChecksum,
ulong LuminanceChecksum);
internal sealed record VisualParityReceipt(
int ComparedSamples,
int ReferenceSamples,
int Width,
int Height,
float[] Bounds,
int ReferenceHitCount,
int GpuHitCount,
int ReferenceOccupiedBins,
int GpuOccupiedBins,
int SharedOccupiedBins,
double OccupancyOverlapPercent,
double L1Distance,
double Rmse,
double CosineSimilarity,
double DistributionScorePercent);
internal readonly record struct HistogramComparison(
int ReferenceOccupiedBins,
int GpuOccupiedBins,
int SharedOccupiedBins,
double OccupancyOverlapPercent,
double L1Distance,
double Rmse,
double CosineSimilarity,
double DistributionScorePercent);
internal sealed record GpuFractalSplatReceipt(
string Adapter,
int SplatCount,
@ -680,4 +839,5 @@ internal sealed record GpuFractalSplatReceipt(
double GpuSplatsPerSecond,
double GpuReservoirCandidatesPerSecond,
double CpuSubmitAndWaitMillisecondsPerFrame,
ulong ReadbackChecksum);
ulong ReadbackChecksum,
VisualParityReceipt? VisualParity);