Add reservoir temporal sequence probe

This commit is contained in:
Meta Vens 2026-05-29 23:48:45 +01:00
commit 0d9b890e2f
6 changed files with 328 additions and 5 deletions

View file

@ -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 { "<stderr missing>" }
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 { "<stderr missing>" }
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"

View file

@ -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"