Add reservoir budget pressure probe

This commit is contained in:
Meta Vens 2026-05-30 00:21:34 +01:00
commit 4d4cf36353
9 changed files with 320 additions and 6 deletions

View file

@ -393,6 +393,10 @@ For same-time reference checks, the capture script can also emit a native-domain
reference at a larger reservoir work-grid scale. Reference-error rows therefore
compare a candidate against a higher-budget work grid without allocating a
native-resolution reservoir buffer.
An offline budget-pressure probe now bins that masked reference error by fixed
tiles and ranks tiles by mean error times mask coverage. The probe is allocator
evidence, not a runtime visibility owner: it says where additional reservoir
updates may buy stability under a fixed budget.
\section{Required Evaluation}

Binary file not shown.

View file

@ -675,6 +675,9 @@ support loss; it localizes where an eventual high-budget reference score should
look first. It can also capture a same-time native-domain reference at a larger
reservoir work-grid scale, producing reference-error rows without introducing a
native-resolution intermediate reservoir.
Those rows feed an offline budget-pressure probe that ranks fixed tiles by
masked reference error, giving the future scheduler a concrete pressure signal
without letting a debug script own runtime visibility.
The system has cut the false ``nearest-travel-minus-coverage'' priority owner
and the side-cache temptation.

View file

@ -557,6 +557,14 @@ Work packet:
reference scale 0.75 at 320x180, ready frame 2, final plus disocclusion.
This is a higher-budget work-grid reference, not a native-resolution escape
hatch.
13. Partial: add offline budget-pressure ranking from masked reference error.
`scripts/measure-reservoir-budget-pressure.ps1` bins candidate-vs-reference
final-color error by fixed tiles, applies the disocclusion/rejection mask
union when present, and ranks tiles by mean reference error multiplied by
mask coverage. Smoke `reservoir-budget-pressure-20260530-001046.*` measured
1306 of 42864 pixels and found the top 5 of 50 tiles carried 99.3305% of
measured reference-error delta. This is allocator evidence only; it does
not own runtime visibility or scheduling.
Required verification:

View file

@ -0,0 +1,285 @@
param(
[string]$CaptureDirectory = "",
[string]$Stamp,
[string]$ManifestPath = "",
[string]$CandidateMode = "native",
[int]$ReadyFrames = 0,
[int]$TileSize = 32,
[double]$HotTilePercent = 0.10,
[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 20260530-001046"
}
if ($TileSize -lt 4) {
throw "TileSize must be at least 4."
}
if ($HotTilePercent -le 0.0 -or $HotTilePercent -gt 1.0) {
throw "HotTilePercent must be in the range (0, 1]."
}
$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-budget-pressure-$Stamp.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
$captures = Import-Csv -Path $ManifestPath
$byKey = @{}
foreach ($capture in $captures) {
$key = "{0}|{1}|{2}" -f $capture.Mode, $capture.ReadyFrames, $capture.Suffix
$byKey[$key] = $capture
}
function Find-Capture {
param(
[string]$Mode,
[int]$Frame,
[string]$Suffix
)
$key = "{0}|{1}|{2}" -f $Mode, $Frame, $Suffix
if ($byKey.ContainsKey($key)) {
return $byKey[$key]
}
return $null
}
function Find-PreferredMask {
param(
[string]$Mode,
[int]$Frame
)
$disocclusion = Find-Capture -Mode $Mode -Frame $Frame -Suffix "disocclusion"
if ($null -ne $disocclusion) {
return $disocclusion.Path
}
$rejection = Find-Capture -Mode $Mode -Frame $Frame -Suffix "rejection"
if ($null -ne $rejection) {
return $rejection.Path
}
return ""
}
if ($ReadyFrames -le 0) {
$candidateFrames = @($captures |
Where-Object { $_.Mode -eq $CandidateMode -and $_.Suffix -eq "final" } |
Sort-Object { [int]$_.ReadyFrames })
if ($candidateFrames.Count -eq 0) {
throw "No final captures found for mode '$CandidateMode'."
}
$ReadyFrames = [int]$candidateFrames[0].ReadyFrames
}
$candidate = Find-Capture -Mode $CandidateMode -Frame $ReadyFrames -Suffix "final"
$reference = Find-Capture -Mode "reference" -Frame $ReadyFrames -Suffix "final"
if ($null -eq $candidate) {
throw "Missing final candidate capture for mode '$CandidateMode' frame $ReadyFrames."
}
if ($null -eq $reference) {
throw "Missing final reference capture for frame $ReadyFrames."
}
$candidateMaskPath = Find-PreferredMask -Mode $CandidateMode -Frame $ReadyFrames
$referenceMaskPath = Find-PreferredMask -Mode "reference" -Frame $ReadyFrames
$candidateImage = [System.Drawing.Bitmap]::new($candidate.Path)
$referenceImage = [System.Drawing.Bitmap]::new($reference.Path)
$candidateMask = if ([string]::IsNullOrWhiteSpace($candidateMaskPath)) { $null } else { [System.Drawing.Bitmap]::new($candidateMaskPath) }
$referenceMask = if ([string]::IsNullOrWhiteSpace($referenceMaskPath)) { $null } else { [System.Drawing.Bitmap]::new($referenceMaskPath) }
try {
if ($candidateImage.Width -ne $referenceImage.Width -or $candidateImage.Height -ne $referenceImage.Height) {
throw "Candidate and reference dimensions differ."
}
if ($candidateMask -ne $null -and ($candidateMask.Width -ne $candidateImage.Width -or $candidateMask.Height -ne $candidateImage.Height)) {
throw "Candidate mask dimensions differ."
}
if ($referenceMask -ne $null -and ($referenceMask.Width -ne $candidateImage.Width -or $referenceMask.Height -ne $candidateImage.Height)) {
throw "Reference mask dimensions differ."
}
$tilesX = [int][Math]::Ceiling($candidateImage.Width / [double]$TileSize)
$tilesY = [int][Math]::Ceiling($candidateImage.Height / [double]$TileSize)
$tileRows = [System.Collections.Generic.List[object]]::new()
for ($tileY = 0; $tileY -lt $tilesY; $tileY++) {
for ($tileX = 0; $tileX -lt $tilesX; $tileX++) {
$x0 = $tileX * $TileSize
$y0 = $tileY * $TileSize
$x1 = [Math]::Min($x0 + $TileSize, $candidateImage.Width)
$y1 = [Math]::Min($y0 + $TileSize, $candidateImage.Height)
$tilePixels = ($x1 - $x0) * ($y1 - $y0)
$maskedPixels = 0
$changedPixels = 0
$sumDelta = 0L
$maxDelta = 0
for ($y = $y0; $y -lt $y1; $y++) {
for ($x = $x0; $x -lt $x1; $x++) {
$maskActive = $true
if ($candidateMask -ne $null -or $referenceMask -ne $null) {
$maskActive = $false
if ($candidateMask -ne $null) {
$cm = $candidateMask.GetPixel($x, $y)
$maskActive = $maskActive -or ([Math]::Max([int]$cm.R, [Math]::Max([int]$cm.G, [int]$cm.B)) -gt 12)
}
if ($referenceMask -ne $null) {
$rm = $referenceMask.GetPixel($x, $y)
$maskActive = $maskActive -or ([Math]::Max([int]$rm.R, [Math]::Max([int]$rm.G, [int]$rm.B)) -gt 12)
}
}
if (-not $maskActive) {
continue
}
$a = $candidateImage.GetPixel($x, $y)
$b = $referenceImage.GetPixel($x, $y)
$delta = [Math]::Max(
[Math]::Abs([int]$a.R - [int]$b.R),
[Math]::Max(
[Math]::Abs([int]$a.G - [int]$b.G),
[Math]::Abs([int]$a.B - [int]$b.B)))
$maskedPixels++
if ($delta -gt 0) {
$changedPixels++
}
$sumDelta += $delta
if ($delta -gt $maxDelta) {
$maxDelta = $delta
}
}
}
$measuredDenominator = if ($maskedPixels -gt 0) { $maskedPixels } else { 1 }
$tileRows.Add([pscustomobject]@{
TileX = $tileX
TileY = $tileY
X = $x0
Y = $y0
Width = $x1 - $x0
Height = $y1 - $y0
TilePixels = $tilePixels
MeasuredPixels = $maskedPixels
MaskCoverage = $maskedPixels / $tilePixels
ChangedPixels = $changedPixels
ChangedPercent = $changedPixels / $measuredDenominator
MeanMaxChannelDelta = $sumDelta / $measuredDenominator
MaxChannelDelta = $maxDelta
PressureScore = ($sumDelta / $measuredDenominator) * ($maskedPixels / $tilePixels)
})
}
}
$ranked = @($tileRows | Sort-Object PressureScore -Descending)
$hotCount = [Math]::Max(1, [int][Math]::Ceiling($ranked.Count * $HotTilePercent))
$hotTiles = @($ranked | Select-Object -First $hotCount)
$measuredPixels = ($tileRows | Measure-Object -Property MeasuredPixels -Sum).Sum
$totalPixels = ($tileRows | Measure-Object -Property TilePixels -Sum).Sum
$totalDelta = 0.0
foreach ($row in $tileRows) {
$totalDelta += $row.MeanMaxChannelDelta * $row.MeasuredPixels
}
$hotMeasuredPixels = ($hotTiles | Measure-Object -Property MeasuredPixels -Sum).Sum
$hotDelta = 0.0
foreach ($row in $hotTiles) {
$hotDelta += $row.MeanMaxChannelDelta * $row.MeasuredPixels
}
$capturedDeltaShare = if ($totalDelta -gt 0.0) { $hotDelta / $totalDelta } else { 0.0 }
$rank = 1
$exportRows = foreach ($row in $ranked) {
[pscustomobject]@{
Rank = $rank++
TileX = $row.TileX
TileY = $row.TileY
X = $row.X
Y = $row.Y
Width = $row.Width
Height = $row.Height
TilePixels = $row.TilePixels
MeasuredPixels = $row.MeasuredPixels
MaskCoverage = $row.MaskCoverage
ChangedPixels = $row.ChangedPixels
ChangedPercent = $row.ChangedPercent
MeanMaxChannelDelta = $row.MeanMaxChannelDelta
MaxChannelDelta = $row.MaxChannelDelta
PressureScore = $row.PressureScore
}
}
$exportRows | Export-Csv -NoTypeInformation -Path $csvPath
$lines = [System.Collections.Generic.List[string]]::new()
$lines.Add("# Reservoir Budget Pressure")
$lines.Add("")
$lines.Add(("Stamp: ``{0}``" -f $Stamp))
$lines.Add(("Candidate: ``{0}``, ready frame ``{1}``" -f $CandidateMode, $ReadyFrames))
$lines.Add(("Reference: higher-work-grid native-domain ``reference``"))
$lines.Add(("Tile size: ``{0}``; hot tile share: ``{1}``" -f $TileSize, $HotTilePercent.ToString("P2")))
$lines.Add(("Mask sources: candidate ``{0}``, reference ``{1}``" -f $candidateMaskPath, $referenceMaskPath))
$lines.Add("")
$lines.Add(("Measured pixels: ``{0}`` / ``{1}`` ({2})" -f $measuredPixels, $totalPixels, ($measuredPixels / $totalPixels).ToString("P4")))
$lines.Add(("Top {0} of {1} tiles carry {2} of measured reference-error delta." -f $hotCount, $ranked.Count, $capturedDeltaShare.ToString("P4")))
$lines.Add("")
$lines.Add("| Rank | Tile | Origin | Mask/frame % | Changed % | Mean max-channel delta | Max delta | Pressure |")
$lines.Add("| ---: | --- | --- | ---: | ---: | ---: | ---: | ---: |")
foreach ($row in ($ranked | Select-Object -First ([Math]::Min(12, $ranked.Count)))) {
$lines.Add(("| {0} | {1},{2} | {3},{4} | {5} | {6} | {7} | {8} | {9} |" -f
($ranked.IndexOf($row) + 1),
$row.TileX,
$row.TileY,
$row.X,
$row.Y,
$row.MaskCoverage.ToString("P4"),
$row.ChangedPercent.ToString("P4"),
$row.MeanMaxChannelDelta.ToString("N4"),
$row.MaxChannelDelta,
$row.PressureScore.ToString("N4")))
}
$lines.Add("")
$lines.Add("PressureScore is mean max-channel reference error multiplied by mask coverage. It is an offline allocator probe: it identifies where extra reservoir update work may buy visible stability, but it does not own visibility or runtime scheduling.")
Set-Content -LiteralPath $OutputPath -Value $lines -Encoding UTF8
Write-Host "Reservoir budget pressure:"
Write-Host (" measured {0}/{1} pixels ({2})" -f $measuredPixels, $totalPixels, ($measuredPixels / $totalPixels).ToString("P4"))
Write-Host (" top {0}/{1} tiles carry {2} of measured reference-error delta" -f $hotCount, $ranked.Count, $capturedDeltaShare.ToString("P4"))
Write-Host "Wrote:"
Write-Host " $OutputPath"
Write-Host " $csvPath"
}
finally {
if ($candidateMask -ne $null) {
$candidateMask.Dispose()
}
if ($referenceMask -ne $null) {
$referenceMask.Dispose()
}
$candidateImage.Dispose()
$referenceImage.Dispose()
}

View file

@ -302,3 +302,4 @@
{"timestamp":"2026-05-30T00:40:00+01:00","topic":"reservoir-rejection-masked-sequence-probe","lesson":"The reservoir sequence harness is now resumable and mask-aware. Existing PNGs are skipped and still recorded into the manifest, which lets interrupted sequence captures continue instead of throwing away completed frames. When rejection-debug captures are present, scripts/measure-reservoir-sequence.ps1 reports masked native/baseline and temporal deltas over the union of rejection-mask pixels. The 320x180 smoke set reservoir-sequence-20260529-235031-* covered about 41% of frame pixels with the rejection mask and produced masked rows, proving the pressure signal works; it is still not a final ghosting score without a high-budget reference or explicit disocclusion mask.","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-235031-*"}
{"timestamp":"2026-05-30T01:05:00+01:00","topic":"reservoir-disocclusion-mask","lesson":"Temporal disocclusion is now exposed by the reservoir owner instead of inferred from broad rejection color. Debug mode 19 maps temporal rejection codes for previous UV loss, previous-closer history, and support loss into a focused disocclusion mask, and the sequence measurer prefers disocclusion masks over rejection masks when both exist. The native-only 320x180 smoke set reservoir-sequence-20260530-000151-* produced a 3.1098% frame mask and a masked temporal-native delta row, proving the mask path is live. The remaining proof gap is a high-budget reference or repeated-sample reference mode so masked deltas can become actual error scores.","files":["src/Aquarium.Engine.Contracts/GraphicsSettings.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","scripts/capture-reservoir-mode-sequence.ps1","scripts/measure-reservoir-sequence.ps1","tests/Aquarium.Engine.Tests/FieldReservoirAbiTests.cs","docs/perfect-fensalir-machine-roadmap.md","state/map.yaml","state/scratch.md"],"source":"artifacts/fensalir-captures/reservoir-sequence-20260530-000151-*"}
{"timestamp":"2026-05-30T01:25:00+01:00","topic":"reservoir-higher-work-grid-reference","lesson":"The sequence harness can now score candidates against a same-time higher-work-grid native-domain reference without violating the no-native-reservoir-buffer rule. capture-reservoir-mode-sequence.ps1 accepts -ReferenceFieldReservoirScale, captures reference rows in native-domain mode at that larger scale, and labels them reference in the manifest. measure-reservoir-sequence.ps1 emits reference-error rows and masked reference-error rows using disocclusion/rejection masks when present. The 320x180 smoke set reservoir-sequence-20260530-001046-* compared native scale 0.5 against reference scale 0.75 at the same ready-frame count; masked reference-error-native covered 3.0468% of frame pixels and changed 42.0368%. The next architectural step is adaptive update/sample budget policy driven by these reference-error pressure signals.","files":["scripts/capture-reservoir-mode-sequence.ps1","scripts/measure-reservoir-sequence.ps1","docs/perfect-fensalir-machine-roadmap.md","state/map.yaml","state/scratch.md"],"source":"artifacts/fensalir-captures/reservoir-sequence-20260530-001046-*"}
{"timestamp":"2026-05-30T01:40:00+01:00","topic":"reservoir-budget-pressure-probe","lesson":"The reservoir quality harness now converts same-time higher-work-grid reference error into per-tile budget pressure without making the probe a runtime owner. measure-reservoir-budget-pressure.ps1 reads a sequence manifest, compares a candidate final capture against the native-domain reference final capture at the same ready frame, applies disocclusion/rejection masks when present, and ranks fixed tiles by mean reference error times mask coverage. On reservoir-budget-pressure-20260530-001046.* the probe measured 1306/42864 pixels and found the top 5/50 tiles carried 99.3305% of measured reference-error delta, giving a concrete target for adaptive update policy while preserving the no-native-resolution-reservoir invariant.","files":["scripts/measure-reservoir-budget-pressure.ps1","docs/perfect-fensalir-machine-roadmap.md","state/map.yaml","state/scratch.md"],"source":"artifacts/fensalir-captures/reservoir-budget-pressure-20260530-001046.*"}

View file

@ -161,9 +161,12 @@ next_actions:
narrower mask path. The sequence harness can also capture a same-time
native-domain reference at a higher reservoir work-grid scale through
`-ReferenceFieldReservoirScale`; `reservoir-sequence-20260530-001046-*`
proves reference-error rows from scale 0.5 against scale 0.75. The next cut
is using those reference-error rows to drive adaptive sampling/update budget
policy plus future exact producer SDF replay.
proves reference-error rows from scale 0.5 against scale 0.75. The offline
budget-pressure probe `reservoir-budget-pressure-20260530-001046.*` ranks
masked reference error by tile; its first smoke found the top 5 of 50 tiles
carried 99.3305% of measured reference-error delta. The next cut is turning
that evidence into a renderer-owned adaptive update contract 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

View file

@ -57,6 +57,16 @@ compared native scale 0.5 against reference scale 0.75 at 320x180, ready frame
masked reference-error-native covered 3.0468% of frame pixels and changed
42.0368%.
Budget-pressure probe:
`scripts/measure-reservoir-budget-pressure.ps1` reads a sequence manifest with a
same-time `reference` capture and ranks fixed tiles by masked candidate versus
reference final-color error. It uses the candidate/reference disocclusion masks
when available, falling back to rejection masks. Smoke
`artifacts/fensalir-captures/reservoir-budget-pressure-20260530-001046.*`
measured 1306 of 42864 pixels and found the top 5 of 50 tiles carried 99.3305%
of measured reference-error delta. This is offline allocator evidence, not a
runtime scheduler.
## Hot Lesson
Area ReSTIR confirms that reuse over an area domain is invalid unless the
@ -88,9 +98,9 @@ cap remain intentionally non-authoritative.
Follow `docs/perfect-fensalir-machine-roadmap.md` Phase 1:
1. Use the same-time higher-work-grid reference rows to drive an adaptive
sampling/update budget policy. Do not add native-resolution reservoir
intermediates.
1. Convert budget-pressure evidence into a renderer-owned adaptive update
contract only after the owner, inputs, outputs, and transition behavior are
explicit. Do not add native-resolution reservoir intermediates.
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.