diff --git a/docs/perfect-fensalir-machine-roadmap.md b/docs/perfect-fensalir-machine-roadmap.md index 3012685..57bc050 100644 --- a/docs/perfect-fensalir-machine-roadmap.md +++ b/docs/perfect-fensalir-machine-roadmap.md @@ -529,7 +529,15 @@ Work packet: match-window graph targets to 0.25-0.75 of present size, with 0.5 as the default. Headless capture accepts `--field-reservoir-scale`; debug UI reports the live work-grid size beside present size. -10. Current: add temporal leakage/ghosting metrics over motion/disocclusion +10. Partial: add temporal sequence probes. `scripts/capture-reservoir-mode-sequence.ps1` + builds one disposable runtime slot and captures native/baseline sequences + across ready-frame counts, debug modes, and work-grid scale. + `scripts/measure-reservoir-sequence.ps1` reports per-frame native/baseline + disagreement and per-mode frame-to-frame temporal deltas. First smoke run: + `reservoir-sequence-20260529-234414-*` at 640x360, final color only, ready + frames 2 and 4. It proved the harness works; it is still a probe, not a + disocclusion-masked ghosting score. +11. Current: add temporal leakage/ghosting metrics over motion/disocclusion sequences, then use those metrics to decide where the sampler spends its bounded update budget. diff --git a/scripts/capture-reservoir-mode-sequence.ps1 b/scripts/capture-reservoir-mode-sequence.ps1 new file mode 100644 index 0000000..5cb045c --- /dev/null +++ b/scripts/capture-reservoir-mode-sequence.ps1 @@ -0,0 +1,147 @@ +param( + [string]$OutputDirectory = "", + [string]$Stamp = "", + [int]$Width = 1280, + [int]$Height = 720, + [int[]]$ReadyFrames = @(4, 8, 12, 16), + [ValidateSet("native", "baseline", "both")] + [string]$FieldReservoirMode = "both", + [double]$FieldReservoirScale = 0.5, + [int[]]$RenderDebugModes = @(0, 13), + [int]$RetainSlots = 4, + [int]$TimeoutSeconds = 120 +) + +$ErrorActionPreference = "Stop" +Set-StrictMode -Version Latest + +$repoRoot = Resolve-Path (Join-Path $PSScriptRoot "..") +if ([string]::IsNullOrWhiteSpace($Stamp)) { + $Stamp = Get-Date -Format "yyyyMMdd-HHmmss" +} +if ([string]::IsNullOrWhiteSpace($OutputDirectory)) { + $OutputDirectory = Join-Path $repoRoot "artifacts\fensalir-captures" +} + +$OutputDirectory = [System.IO.Path]::GetFullPath($OutputDirectory) +$clientProject = Join-Path $repoRoot "src\Aquarium.Fensalir\Aquarium.Fensalir.csproj" +$devRoot = Join-Path $repoRoot "artifacts\dev-reload" +$slotRoot = Join-Path $devRoot "slots" +$slotPath = Join-Path $slotRoot ("fensalir-sequence-" + $Stamp + "-" + [guid]::NewGuid().ToString("N").Substring(0, 8)) +$cachePath = Join-Path $devRoot "fensalir-sequence-cultcache\aquarium-client.msgpack" +$stdoutLog = Join-Path $devRoot "fensalir-sequence.out.log" +$stderrLog = Join-Path $devRoot "fensalir-sequence.err.log" + +New-Item -ItemType Directory -Force -Path $slotPath | Out-Null +New-Item -ItemType Directory -Force -Path (Split-Path $cachePath) | Out-Null +New-Item -ItemType Directory -Force -Path $OutputDirectory | Out-Null + +Write-Host "Building Fensalir sequence slot:" +Write-Host " $slotPath" +dotnet build (Join-Path $repoRoot "src\Aquarium.Engine\Aquarium.Engine.csproj") -c Debug -o $slotPath /p:UseAppHost=true +if ($LASTEXITCODE -ne 0) { + throw "Engine build failed with exit code $LASTEXITCODE." +} + +dotnet build $clientProject -c Debug -o $slotPath /p:UseAppHost=false +if ($LASTEXITCODE -ne 0) { + throw "Fensalir client build failed with exit code $LASTEXITCODE." +} + +$exePath = Join-Path $slotPath "Aquarium.Engine.exe" +$clientAssembly = Join-Path $slotPath "Aquarium.Fensalir.dll" +$modes = if ($FieldReservoirMode -eq "both") { @("native", "baseline") } else { @($FieldReservoirMode) } +$captures = [System.Collections.Generic.List[object]]::new() + +function DebugSuffix { + param([int]$Mode) + + if ($Mode -eq 0) { + return "final" + } + if ($Mode -eq 13) { + return "rejection" + } + if ($Mode -eq 16) { + return "domain" + } + if ($Mode -eq 17) { + return "support" + } + if ($Mode -eq 18) { + return "shift" + } + + return "debug$Mode" +} + +foreach ($mode in $modes) { + foreach ($readyFrame in $ReadyFrames) { + foreach ($debugMode in $RenderDebugModes) { + $suffix = DebugSuffix -Mode $debugMode + $outputPath = Join-Path $OutputDirectory ("reservoir-sequence-$Stamp-$mode-f{0:D4}-$suffix.png" -f $readyFrame) + $arguments = @( + "--headless", + "--headless-width", $Width, + "--headless-height", $Height, + "--client-assembly", $clientAssembly, + "--cache", $cachePath, + "--shader-source", (Join-Path $slotPath "Render\Shaders\D3D12HeightField.hlsl"), + "--capture-frame", $outputPath, + "--field-reservoir-scale", $FieldReservoirScale + ) + if ($mode -eq "baseline") { + $arguments += @("--field-reservoir-mode", "baseline") + } + if ($debugMode -gt 0) { + $arguments += @("--render-debug", $debugMode) + } + + Write-Host ("Capturing {0} ready={1} debug={2} -> {3}" -f $mode, $readyFrame, $debugMode, $outputPath) + $env:AQUARIUM_HEADLESS_READY_FRAMES = [string][Math]::Max(1, $readyFrame) + $process = Start-Process -FilePath $exePath -ArgumentList $arguments -NoNewWindow -PassThru -RedirectStandardOutput $stdoutLog -RedirectStandardError $stderrLog + if (-not $process.WaitForExit([Math]::Max(1, $TimeoutSeconds) * 1000)) { + $process.Kill($true) + $tail = if (Test-Path $stderrLog) { Get-Content -Path $stderrLog -Tail 80 } else { "" } + throw "Fensalir sequence capture timed out after $TimeoutSeconds seconds.`n$($tail -join [Environment]::NewLine)" + } + + $process.WaitForExit() + $process.Refresh() + $exitCode = $process.ExitCode + if ($null -eq $exitCode -and (Test-Path $outputPath)) { + $exitCode = 0 + } + if ($exitCode -ne 0) { + $tail = if (Test-Path $stderrLog) { Get-Content -Path $stderrLog -Tail 80 } else { "" } + throw "Fensalir sequence capture failed with exit code $exitCode.`n$($tail -join [Environment]::NewLine)" + } + if (-not (Test-Path $outputPath)) { + throw "Fensalir sequence capture did not produce expected PNG: $outputPath" + } + + $captures.Add([pscustomobject]@{ + Mode = $mode + ReadyFrames = $readyFrame + RenderDebugMode = $debugMode + Suffix = $suffix + Path = $outputPath + }) + } + } +} + +$manifestPath = Join-Path $OutputDirectory "reservoir-sequence-$Stamp-manifest.csv" +$captures | Export-Csv -NoTypeInformation -Path $manifestPath + +if ($RetainSlots -gt 0) { + Get-ChildItem -Path $slotRoot -Directory -ErrorAction SilentlyContinue | + Where-Object { $_.Name -like "fensalir-sequence-*" } | + Sort-Object LastWriteTimeUtc -Descending | + Select-Object -Skip $RetainSlots | + Remove-Item -Recurse -Force -ErrorAction SilentlyContinue +} + +Write-Host "Reservoir sequence captured:" +Write-Host " Stamp: $Stamp" +Write-Host " Manifest: $manifestPath" diff --git a/scripts/measure-reservoir-sequence.ps1 b/scripts/measure-reservoir-sequence.ps1 new file mode 100644 index 0000000..5899de6 --- /dev/null +++ b/scripts/measure-reservoir-sequence.ps1 @@ -0,0 +1,154 @@ +param( + [string]$CaptureDirectory = "", + [string]$Stamp, + [string]$ManifestPath = "", + [string]$OutputPath = "" +) + +$ErrorActionPreference = "Stop" +Set-StrictMode -Version Latest + +$repoRoot = Resolve-Path (Join-Path $PSScriptRoot "..") +if ([string]::IsNullOrWhiteSpace($CaptureDirectory)) { + $CaptureDirectory = Join-Path $repoRoot "artifacts\fensalir-captures" +} +if ([string]::IsNullOrWhiteSpace($Stamp)) { + throw "Stamp is required, for example: -Stamp 20260529-234500" +} + +$CaptureDirectory = [System.IO.Path]::GetFullPath($CaptureDirectory) +if ([string]::IsNullOrWhiteSpace($ManifestPath)) { + $ManifestPath = Join-Path $CaptureDirectory "reservoir-sequence-$Stamp-manifest.csv" +} +if ([string]::IsNullOrWhiteSpace($OutputPath)) { + $OutputPath = Join-Path $CaptureDirectory "reservoir-sequence-$Stamp-metrics.md" +} +$ManifestPath = [System.IO.Path]::GetFullPath($ManifestPath) +$OutputPath = [System.IO.Path]::GetFullPath($OutputPath) +$csvPath = [System.IO.Path]::ChangeExtension($OutputPath, ".csv") + +if (-not (Test-Path -LiteralPath $ManifestPath)) { + throw "Missing sequence manifest: $ManifestPath" +} + +Add-Type -AssemblyName System.Drawing + +function Measure-ImageDelta { + param( + [string]$APath, + [string]$BPath, + [string]$Label + ) + + $a = [System.Drawing.Bitmap]::new($APath) + $b = [System.Drawing.Bitmap]::new($BPath) + try { + if ($a.Width -ne $b.Width -or $a.Height -ne $b.Height) { + throw "Capture dimensions differ for $Label." + } + + $changed = 0 + $sum = 0L + $max = 0 + for ($y = 0; $y -lt $a.Height; $y++) { + for ($x = 0; $x -lt $a.Width; $x++) { + $ca = $a.GetPixel($x, $y) + $cb = $b.GetPixel($x, $y) + $delta = [Math]::Max( + [Math]::Abs([int]$ca.R - [int]$cb.R), + [Math]::Max( + [Math]::Abs([int]$ca.G - [int]$cb.G), + [Math]::Abs([int]$ca.B - [int]$cb.B))) + if ($delta -gt 0) { + $changed++ + } + + $sum += $delta + if ($delta -gt $max) { + $max = $delta + } + } + } + + $total = $a.Width * $a.Height + [pscustomobject]@{ + Label = $Label + ChangedPixels = $changed + TotalPixels = $total + ChangedPercent = $changed / $total + MeanMaxChannelDelta = $sum / $total + MaxChannelDelta = $max + APath = $APath + BPath = $BPath + } + } + finally { + $a.Dispose() + $b.Dispose() + } +} + +$captures = Import-Csv -Path $ManifestPath +$results = [System.Collections.Generic.List[object]]::new() + +$groups = $captures | Group-Object Suffix +foreach ($group in $groups) { + $suffix = $group.Name + $nativeFrames = $group.Group | + Where-Object { $_.Mode -eq "native" } | + Sort-Object { [int]$_.ReadyFrames } + $baselineFrames = $group.Group | + Where-Object { $_.Mode -eq "baseline" } | + Sort-Object { [int]$_.ReadyFrames } + + foreach ($native in $nativeFrames) { + $baseline = $baselineFrames | Where-Object { [int]$_.ReadyFrames -eq [int]$native.ReadyFrames } | Select-Object -First 1 + if ($null -ne $baseline) { + $results.Add((Measure-ImageDelta -APath $native.Path -BPath $baseline.Path -Label "$suffix mode-delta f$($native.ReadyFrames)")) + } + } + + foreach ($modeFrames in @($nativeFrames, $baselineFrames)) { + for ($index = 1; $index -lt $modeFrames.Count; $index++) { + $previous = $modeFrames[$index - 1] + $current = $modeFrames[$index] + $results.Add((Measure-ImageDelta -APath $previous.Path -BPath $current.Path -Label "$suffix temporal-$($current.Mode) f$($previous.ReadyFrames)-f$($current.ReadyFrames)")) + } + } +} + +$results | Export-Csv -NoTypeInformation -Path $csvPath + +$lines = [System.Collections.Generic.List[string]]::new() +$lines.Add("# Reservoir Sequence Metrics") +$lines.Add("") +$lines.Add(("Stamp: ``{0}``" -f $Stamp)) +$lines.Add("") +$lines.Add("| Metric | Changed pixels | Changed % | Mean max-channel delta | Max channel delta |") +$lines.Add("| --- | ---: | ---: | ---: | ---: |") +foreach ($result in $results) { + $lines.Add(("| {0} | {1} / {2} | {3} | {4} | {5} |" -f + $result.Label, + $result.ChangedPixels, + $result.TotalPixels, + $result.ChangedPercent.ToString("P4"), + $result.MeanMaxChannelDelta.ToString("N4"), + $result.MaxChannelDelta)) +} +$lines.Add("") +$lines.Add("These are sequence probes, not a final ghosting score. Mode deltas show native/baseline disagreement at each sampled time. Temporal deltas show frame-to-frame output movement per mode; the next scorer must use disocclusion/rejection masks or a high-budget reference before claiming quality.") +Set-Content -LiteralPath $OutputPath -Value $lines -Encoding UTF8 + +Write-Host "Reservoir sequence metrics:" +foreach ($result in $results) { + Write-Host (" {0}: changed {1}/{2} ({3}) meanMax {4} max {5}" -f + $result.Label, + $result.ChangedPixels, + $result.TotalPixels, + $result.ChangedPercent.ToString("P4"), + $result.MeanMaxChannelDelta.ToString("N4"), + $result.MaxChannelDelta) +} +Write-Host "Wrote:" +Write-Host " $OutputPath" +Write-Host " $csvPath" diff --git a/state/evidence.jsonl b/state/evidence.jsonl index f6458c8..39889cc 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -298,3 +298,4 @@ {"timestamp":"2026-05-29T23:16:00+01:00","topic":"tubefield-replay-manifest","lesson":"TubeField replay authority no longer comes from a CPU-side single-batch special case. The history shader reads a bounded producer-keyed replay manifest and raw source descriptor table, scans for the selected sample's field-id family, and re-evaluates the shifted logical column/curve coordinate from the matching source. Overflow is invalid instead of guessed; exact scaling beyond the descriptor cap should become a replay atlas only when captures prove the cap is real pressure.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/D3D12StructuredBuffer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","tests/Aquarium.Engine.Tests/FieldReservoirAbiTests.cs","docs/perfect-fensalir-machine-roadmap.md","state/map.yaml","state/memory.json"],"source":"docs/perfect-fensalir-machine-roadmap.md"} {"timestamp":"2026-05-29T23:30:00+01:00","topic":"reservoir-baseline-comparison-mode","lesson":"Native-domain versus texel-owned baseline comparison now has an explicit field-reservoir mode switch. Both modes use the same reservoir rows; native mode enables domain validity, support overlap, and producer replay at temporal reuse, while baseline mode keeps texel-owned field/travel/normal/color/confidence validation. First paired captures at artifacts/fensalir-captures/reservoir-compare-20260529-231904-* changed 10.8208% of final-frame pixels, 0.0165% of rejection-debug pixels, and 0.2976% of shift-debug pixels. This proves the switch is live but does not yet measure temporal leakage or ghosting quality.","files":["src/Aquarium.Engine.Contracts/GraphicsSettings.cs","src/Aquarium.Engine.Contracts/AquariumRuntimeContracts.cs","src/Aquarium.Engine/AquariumHost.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","scripts/capture-fensalir-frame.ps1","tests/Aquarium.Engine.Tests/FieldReservoirAbiTests.cs","docs/perfect-fensalir-machine-roadmap.md"],"source":"artifacts/fensalir-captures/reservoir-compare-20260529-231904-*"} {"timestamp":"2026-05-29T23:55:00+01:00","topic":"budgeted-reservoir-work-grid","lesson":"The native-domain reservoir must be a budgeted spatiotemporal sampler, not a native-resolution buffer by another name. GraphicsSettings.FieldReservoirScale now clamps the internal work grid below final presentation scale; scene evidence targets, reservoir candidate/history rows, reservoir resolve, bloom sources, and match-window graph targets use that grid, while the full-resolution surface is reserved for final presentation/reconstruction. The comparison script now repeats native-vs-baseline image deltas, but the next real proof is temporal leakage/ghosting over motion sequences so adaptive update budgets can be spent where they buy visible stability.","files":["src/Aquarium.Engine.Contracts/GraphicsSettings.cs","src/Aquarium.Engine.Contracts/AquariumRuntimeContracts.cs","src/Aquarium.Engine/AquariumHost.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Fensalir/FensalirRuntime.cs","src/Aquarium.Zyphos/ZyphosRuntime.cs","scripts/capture-fensalir-frame.ps1","scripts/measure-reservoir-mode-comparison.ps1","tests/Aquarium.Engine.Tests/FieldReservoirAbiTests.cs","docs/perfect-fensalir-machine-roadmap.md","state/map.yaml","state/scratch.md"],"source":"user spatiotemporal reservoir upscaling sampler correction"} +{"timestamp":"2026-05-30T00:25:00+01:00","topic":"reservoir-sequence-probe","lesson":"Reservoir comparison now has a sequence-level probe instead of only single-frame deltas. scripts/capture-reservoir-mode-sequence.ps1 builds one disposable slot and captures native/baseline frames across ready-frame counts, debug modes, and reservoir work-grid scale; scripts/measure-reservoir-sequence.ps1 reports per-frame mode disagreement plus per-mode frame-to-frame temporal deltas. The first 640x360 final-only smoke sequence at reservoir-sequence-20260529-234414-* proved the harness works, but the metric remains a probe until disocclusion/rejection masks or high-budget references turn it into a real ghosting/leakage score.","files":["scripts/capture-reservoir-mode-sequence.ps1","scripts/measure-reservoir-sequence.ps1","docs/perfect-fensalir-machine-roadmap.md","state/scratch.md"],"source":"artifacts/fensalir-captures/reservoir-sequence-20260529-234414-*"} diff --git a/state/map.yaml b/state/map.yaml index 906eeb0..937a831 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -149,8 +149,12 @@ next_actions: single-frame deltas. The reservoir work grid is now clamped below present resolution by `GraphicsSettings.FieldReservoirScale` (0.5 default, 0.75 maximum), so native-domain replay spends bounded fill/compute before the - full-resolution presentation pass. The next cut is a temporal - leakage/ghosting metric harness plus future exact producer SDF replay. + full-resolution presentation pass. A sequence probe now captures + native/baseline timelines from one disposable slot and measures per-frame + mode disagreement plus frame-to-frame temporal deltas; the first smoke set + is `reservoir-sequence-20260529-234414-*`. The next cut is upgrading that + probe into a disocclusion/rejection-masked leakage/ghosting score plus + future exact producer SDF replay. - Build the planetary flow organ in staged cuts: provenance manifest, static relief and reanalysis cube-sphere bake pipeline, stochastic advection contracts, synthetic runtime slice, ERA5/OSCAR baseline learning, then diff --git a/state/scratch.md b/state/scratch.md index d364d49..9d31c44 100644 --- a/state/scratch.md +++ b/state/scratch.md @@ -17,6 +17,15 @@ First half-scale live capture: `artifacts/fensalir-captures/budgeted-reservoir-20260529-234039-final.png` at 1264x681 present output, nonblank by sampled pixel probe. +Temporal sequence harness smoke: +`scripts/capture-reservoir-mode-sequence.ps1` and +`scripts/measure-reservoir-sequence.ps1` produced +`artifacts/fensalir-captures/reservoir-sequence-20260529-234414-*` at 640x360, +final color only, ready frames 2 and 4. Native/baseline mode-delta changed +82.9025% of sampled pixels at f2 and 20.0206% at f4; temporal-native changed +78.5581%, temporal-baseline changed 48.9741%. These are probes, not a final +ghosting score. + ## Hot Lesson Area ReSTIR confirms that reuse over an area domain is invalid unless the @@ -48,8 +57,8 @@ cap remain intentionally non-authoritative. Follow `docs/perfect-fensalir-machine-roadmap.md` Phase 1: -1. Add a real metric harness for temporal leakage/ghosting over motion and - disocclusion sequences instead of relying on single-frame image deltas. +1. Turn the temporal sequence probe into a real leakage/ghosting score using + disocclusion/rejection masks or a high-budget reference. 2. Add exact SDF producer replay only when client SDF distance functions have a shared replay include or manifest instead of duplicating shader policy in post.