diff --git a/docs/papers/fensalir-native-domain-reservoirs.pdf b/docs/papers/fensalir-native-domain-reservoirs.pdf index 368bcda..c4bfbf3 100644 Binary files a/docs/papers/fensalir-native-domain-reservoirs.pdf and b/docs/papers/fensalir-native-domain-reservoirs.pdf differ diff --git a/docs/papers/fensalir-native-domain-reservoirs.tex b/docs/papers/fensalir-native-domain-reservoirs.tex index e11dd73..7125915 100644 --- a/docs/papers/fensalir-native-domain-reservoirs.tex +++ b/docs/papers/fensalir-native-domain-reservoirs.tex @@ -80,11 +80,11 @@ as though support overlap were obvious. contains a shared four-row GPU field reservoir for current-frame RIS, temporal reuse, spatial/domain reuse, and final resolve. TubeField and SDF contributors already share target/source-PDF proposal lanes, and an older -nearest-depth-minus-coverage priority path has been cut. The remaining fault -is precise: the live row ABI is still too texel-shaped. It carries field id, -travel, normal, support scalar, guide confidence, proposal weights, and stats, -but it does not yet make the selected native-domain coordinate and support -footprint a first-class invariant. +nearest-depth-minus-coverage priority path has been cut. The live row ABI now +stores selected sample coordinates, producer-domain coordinates, support +footprint, domain kind, and shift kind alongside field id, travel, normal, +guide confidence, proposal weights, and stats. That makes support overlap a +first-class validation input rather than an inference from a texel. This paper narrows the previous architecture manifesto into one testable claim: @@ -328,6 +328,37 @@ and selected producer-domain coordinates must become visible state.} \label{fig:prototype-debug} \end{figure} +The first native-domain ABI cut expands each live \texttt{FieldReservoirSample} +row from seven to nine \texttt{float4} lanes: + +\begin{center} +\begin{tabular}{ll} +\toprule +Lane & Meaning \\ +\midrule +\texttt{colorTravel} & resolved HDR contribution and camera travel \\ +\texttt{metadata} & field id and normal/gradient payload \\ +\texttt{control} & coverage, scalar support, detail, age/value payload \\ +\texttt{guide} & confidence, sample age, domain validity, rejection code \\ +\texttt{motion} & previous UV, expected previous travel, explicit-motion flag \\ +\texttt{domainSample} & selected pixel/sample UV and packed producer coordinate \\ +\texttt{domainSupport} & support footprint, domain kind, shift kind \\ +\texttt{proposal} & target, source PDF, represented count, proposal kind \\ +\texttt{stats} & selected target, weight sum, candidate count, contribution weight \\ +\bottomrule +\end{tabular} +\end{center} + +TubeField row-0 proposals write the selected subpixel UV, physical rolling +column, curve sample coordinate, tube-core support footprint, and explicit +motion shift kind when rolling-column replay is available. SDF scene proposals +reconstruct the current world hit, pack object-local coordinates, and mark the +sample as object-replayable. Reservoir validity now fails when a live sample +lacks domain state, and temporal/spatial validation multiplies the existing +field/travel/normal/confidence checks by support overlap in the selected-domain +lane. Debug modes expose selected coordinates, support footprint/domain kind, +and shift/rejection state from the same row-3 layer consumed by presentation. + \section{Required Evaluation} This paper is not submission-ready until the following evaluation exists. diff --git a/docs/papers/fensalir-pipeline.pdf b/docs/papers/fensalir-pipeline.pdf index 17a6d26..8677595 100644 Binary files a/docs/papers/fensalir-pipeline.pdf and b/docs/papers/fensalir-pipeline.pdf differ diff --git a/docs/papers/fensalir-pipeline.tex b/docs/papers/fensalir-pipeline.tex index 1876683..449abb8 100644 --- a/docs/papers/fensalir-pipeline.tex +++ b/docs/papers/fensalir-pipeline.tex @@ -525,8 +525,9 @@ safety. The first implementation already has pieces of this: shaped 2D brush envelopes, semantic claim/tree rows, conservative summaries, fractal contribution state, projected SDF splat compilation, GPU splat/reservoir receipt harness, direct -TubeField resource lowerings, surface, volume, and mesh resource declarations, and a -shared four-row field reservoir execution ABI. The live ABI currently uses: +TubeField resource lowerings, surface, volume, and mesh resource declarations, +and a shared four-row field reservoir execution ABI. The live ABI currently +uses: \begin{center} \begin{tabular}{cl} @@ -541,10 +542,15 @@ Row & Meaning \\ \end{tabular} \end{center} -This row layout is useful, but incomplete as a foundation. The next mandatory -cut is to add or repack a first-class domain/sample-coordinate lane so TubeField -and SDF proposals carry selected subpixel/domain coordinates plus support. -Without that, temporal/spatial reuse remains too close to a texel cache. +Each row is now a nine-lane \texttt{FieldReservoirSample}: color/travel, +metadata, control, guide, motion, domain sample, domain support, proposal, and +stats. The domain sample lane stores selected pixel/sample UV plus packed +producer coordinates; the domain support lane stores support footprint, domain +kind, and shift kind. TubeField proposals write selected subpixel UV, +physical rolling column, curve coordinate, tube support, and explicit motion +when available. SDF proposals reconstruct object-local hit coordinates and +mark object-motion replay. Temporal and spatial reuse now reject missing +domain state and include support overlap in the validation weight. \section{Reconstruction and Denoising} @@ -628,16 +634,19 @@ validated reservoirs. Neither mode lets a pixel row become truth. 1070-class machine \cite{fensalirPerfectMachine}; \item D3D12 TubeField resource and generated-mesh lowerings; \item shared field reservoir ABI with current/temporal/spatial/final row - semantics; + semantics, selected domain/sample coordinates, support footprints, proposal + lanes, stats lanes, and row-3 debug modes for rejection, proposal, domain, + support, and shift state; \item HDR presentation path with exposure, bloom pyramid, ACES-fit transform, and debug modes \cite{fensalirHDR}. \end{itemize} -The known architectural gap is also explicit: the current row ABI still needs -domain/sample-coordinate authority. The system has cut the false -``nearest-travel-minus-coverage'' priority owner, but a real \AreaReSTIR-style -domain reservoir requires selected support coordinates before further occlusion -tuning deserves trust. +The known architectural gap has moved forward: the current row ABI now carries +domain/sample-coordinate authority, but temporal reuse still needs full +producer re-evaluation after support overlap rather than treating overlap as +the whole legal shift story. The system has cut the false +``nearest-travel-minus-coverage'' priority owner and the side-cache temptation; +the next proof cut is producer-domain replay with measured rejection precision. \section{Evaluation Plan} diff --git a/docs/perfect-fensalir-machine-roadmap.md b/docs/perfect-fensalir-machine-roadmap.md index 78edb5f..793e5d2 100644 --- a/docs/perfect-fensalir-machine-roadmap.md +++ b/docs/perfect-fensalir-machine-roadmap.md @@ -33,6 +33,9 @@ Fensalir already has the first shared GPU field-reservoir spine: - Proposal lanes carry target, source PDF, represented count, and proposal kind. - Stats lanes carry selected target, weight sum, candidate count, and contribution weight. +- The nine-lane `FieldReservoirSample` row now carries color/travel, metadata, + control, guide, motion, selected domain/sample coordinate, support/shift + metadata, proposal, and stats. - The four rows per pixel mean current RIS, temporal reuse, spatial/domain reuse, and final resolved reservoir. - The old TubeField-local ReSTIR/tile-bin path and nearest-travel-minus-coverage @@ -40,11 +43,11 @@ Fensalir already has the first shared GPU field-reservoir spine: - Debug modes now inspect the compute-owned reservoir layer rather than stale guide textures. -The surviving flaw is precise: the live ABI is still too texel-shaped. It can -validate by field id, travel, normal, motion, scalar support, proposal, and -confidence, but it does not yet store the selected producer-domain coordinate -and full support footprint that Area ReSTIR tells us are required for legal -area-domain reuse. +The surviving flaw has moved one layer downstream: the live ABI now stores +selected sample UV, packed producer coordinate, support footprint, domain kind, +and shift kind, and temporal/spatial validation uses support overlap. It still +needs producer-domain replay/re-evaluation before reuse can claim the full Area +ReSTIR proof rather than a first legal-overlap gate. ## Invariants @@ -465,14 +468,17 @@ Objective: pay the first proof obligation for the focused native-domain paper. Work packet: -1. Add/repack the `FieldReservoirSample` ABI with selected domain/sample +1. Done: add/repack the `FieldReservoirSample` ABI with selected domain/sample coordinate and support footprint. -2. Write TubeField row-0 selected subpixel/source/curve support. -3. Write SDF row-0 selected hit/domain support. -4. Add debug modes for selected coordinate, support overlap, and shift kind. -5. Implement temporal support-overlap validation before further threshold - tuning. -6. Capture the occluded-spectrum-tubes scene in baseline and native-domain +2. Done: write TubeField row-0 selected subpixel/source/curve support. +3. Done: write SDF row-0 selected hit/domain support. +4. Done: add debug modes for selected coordinate, support footprint/domain, + and shift kind. +5. Done: implement temporal/spatial support-overlap validation before further + threshold tuning. +6. Next: implement producer re-evaluation after the support-overlap gate for + TubeField rolling-column replay and SDF object-hit replay. +7. Capture the occluded-spectrum-tubes scene in baseline and native-domain modes. Required verification: diff --git a/scripts/capture-fensalir-frame.ps1 b/scripts/capture-fensalir-frame.ps1 index 8ca2d3c..2f68c0a 100644 --- a/scripts/capture-fensalir-frame.ps1 +++ b/scripts/capture-fensalir-frame.ps1 @@ -3,6 +3,7 @@ param( [int]$Width = 1280, [int]$Height = 720, [int]$ReadyFrames = 8, + [int]$RenderDebugMode = -1, [int]$RetainSlots = 4, [int]$TimeoutSeconds = 120 ) @@ -51,6 +52,9 @@ $arguments = @( "--shader-source", (Join-Path $slotPath "Render\Shaders\D3D12HeightField.hlsl"), "--capture-frame", $OutputPath ) +if ($RenderDebugMode -ge 0) { + $arguments += @("--render-debug", $RenderDebugMode) +} $env:AQUARIUM_HEADLESS_READY_FRAMES = [string][Math]::Max(1, $ReadyFrames) $process = Start-Process -FilePath $exePath -ArgumentList $arguments -NoNewWindow -PassThru -RedirectStandardOutput $stdoutLog -RedirectStandardError $stderrLog diff --git a/src/Aquarium.Engine.Contracts/GraphicsSettings.cs b/src/Aquarium.Engine.Contracts/GraphicsSettings.cs index 22df2ff..b7507e4 100644 --- a/src/Aquarium.Engine.Contracts/GraphicsSettings.cs +++ b/src/Aquarium.Engine.Contracts/GraphicsSettings.cs @@ -7,7 +7,7 @@ public readonly record struct GraphicsSettings( float BloomVeilIntensity) { public const int MinRenderDebugMode = 0; - public const int MaxRenderDebugMode = 15; + public const int MaxRenderDebugMode = 18; public const float MinSceneExposure = 0.02f; public const float MaxSceneExposure = 1.2f; public const float MinBloomIntensity = 0.0f; diff --git a/src/Aquarium.Engine/Render/D3D12Renderer.cs b/src/Aquarium.Engine/Render/D3D12Renderer.cs index 5376834..36c18b3 100644 --- a/src/Aquarium.Engine/Render/D3D12Renderer.cs +++ b/src/Aquarium.Engine/Render/D3D12Renderer.cs @@ -44,8 +44,8 @@ public sealed class D3D12Renderer : IAquariumRenderer private const int MaxTubeFieldIndices = MaxTubeFieldSegments * 6; private const int MaxTubeFieldDrawBatches = 4_096; private const int FieldReservoirSlotsPerPixel = 4; - private const int FieldReservoirCandidateStrideBytes = 112; - private const int FieldReservoirHistoryStrideBytes = 112; + private const int FieldReservoirCandidateStrideBytes = 144; + private const int FieldReservoirHistoryStrideBytes = 144; private const int GeneratedMeshDrawArgumentUIntCount = 5; private const int GeneratedMeshDrawArgumentBytes = GeneratedMeshDrawArgumentUIntCount * sizeof(uint); private const float SurfaceTransparentMinZ = -1.85f; @@ -132,6 +132,9 @@ public sealed class D3D12Renderer : IAquariumRenderer new(13, "Reservoir Rejection"), new(14, "Reservoir Stats"), new(15, "Reservoir Proposal"), + new(16, "Reservoir Domain"), + new(17, "Reservoir Support"), + new(18, "Reservoir Shift"), ]; private static readonly DebugUi.DebugUiOption[] SynthPresetOptions = AquaSynth.Dsl.BuiltInScripts.ReferenceScripts() .Select((preset, index) => new DebugUi.DebugUiOption(index, $"{preset.Family}/{preset.Name}")) diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12FieldReservoir.hlsli b/src/Aquarium.Engine/Render/Shaders/D3D12FieldReservoir.hlsli index e00e152..61e6e04 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12FieldReservoir.hlsli +++ b/src/Aquarium.Engine/Render/Shaders/D3D12FieldReservoir.hlsli @@ -5,6 +5,8 @@ struct FieldReservoirSample float4 control; float4 guide; float4 motion; + float4 domainSample; + float4 domainSupport; float4 proposal; float4 stats; }; @@ -16,6 +18,13 @@ static const uint FieldReservoirRowSpatial = 2u; static const uint FieldReservoirRowFinal = 3u; static const float FieldReservoirEpsilon = 0.000001; static const float FieldProposalKindDeterministicStructural = 1.0; +static const float FieldDomainKindNone = 0.0; +static const float FieldDomainKindScreen = 1.0; +static const float FieldDomainKindTube = 2.0; +static const float FieldDomainKindSdf = 3.0; +static const float FieldShiftKindNone = 0.0; +static const float FieldShiftKindExplicitMotion = 1.0; +static const float FieldShiftKindObjectReplay = 2.0; uint fieldReservoirHash(uint value) { @@ -41,6 +50,8 @@ FieldReservoirSample emptyFieldReservoirSample(float farTravel) sample.control = 0.0; sample.guide = float4(1.0, 0.0, 1.0, 2.0); sample.motion = 0.0; + sample.domainSample = 0.0; + sample.domainSupport = 0.0; sample.proposal = 0.0; sample.stats = 0.0; return sample; @@ -65,6 +76,8 @@ FieldReservoirSample makeFieldReservoirSample( float4 control, float4 guide, float4 motion, + float4 domainSample, + float4 domainSupport, float target, float sourcePdf, float representedCandidateCount, @@ -80,11 +93,26 @@ FieldReservoirSample makeFieldReservoirSample( sample.control = control; sample.guide = guide; sample.motion = motion; + sample.domainSample = domainSample; + sample.domainSupport = domainSupport; sample.proposal = float4(safeTarget, safePdf, safeCount, proposalKind); sample.stats = float4(safeTarget, weight, safeCount, weight / max(safeCount * safeTarget, FieldReservoirEpsilon)); return sample; } +bool fieldReservoirDomainStateValid(FieldReservoirSample sample) +{ + float domainKind = sample.domainSupport.z; + if (domainKind <= FieldDomainKindNone + 0.5) + { + return false; + } + + return all(sample.domainSample.xy >= 0.0) && + all(sample.domainSample.xy <= 1.0) && + all(sample.domainSupport.xy > 0.0); +} + bool fieldReservoirSampleValid(FieldReservoirSample sample, float farTravel) { return sample.metadata.x > 0.5 && @@ -92,6 +120,7 @@ bool fieldReservoirSampleValid(FieldReservoirSample sample, float farTravel) sample.colorTravel.w <= farTravel && saturate(sample.control.x) > 0.0 && saturate(sample.guide.z) > 0.0 && + fieldReservoirDomainStateValid(sample) && sample.proposal.x > 0.0 && sample.proposal.y > 0.0 && sample.stats.x > 0.0 && @@ -99,6 +128,24 @@ bool fieldReservoirSampleValid(FieldReservoirSample sample, float farTravel) sample.stats.z > 0.0; } +float fieldReservoirDomainSupportOverlap(FieldReservoirSample a, FieldReservoirSample b, float2 dimensions) +{ + if (!fieldReservoirDomainStateValid(a) || !fieldReservoirDomainStateValid(b)) + { + return 0.0; + } + + if (abs(a.domainSupport.z - b.domainSupport.z) > 0.25) + { + return 0.0; + } + + float2 pixelDelta = (a.domainSample.xy - b.domainSample.xy) * max(dimensions, float2(1.0, 1.0)); + float2 support = max(a.domainSupport.xy + b.domainSupport.xy, float2(FieldReservoirEpsilon, FieldReservoirEpsilon)); + float normalizedDistance = length(pixelDelta / support); + return 1.0 - smoothstep(0.75, 1.25, normalizedDistance); +} + float fieldReservoirContributionWeight(FieldReservoirSample sample) { return sample.stats.w > 0.0 diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl index beac9f4..57c940d 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl @@ -380,6 +380,32 @@ float4 D3D12BloomBlurVerticalPS(VertexOut input) : SV_Target0 return float4(color, 1.0); } +float4 sceneReservoirDomainSample(float2 uv, float4 colorTravel, float4 metadata) +{ + if (metadata.x >= FIELD_ID_SDF_OBJECT_BASE) + { + float2 pixel = (floor(uv * resolution) + 0.5); + float3 ray = rayDirectionForPixel(pixel, jitterPixels, cameraPosition, cameraTarget); + float3 worldPosition = cameraPosition + ray * colorTravel.w; + int sdfIndex = clamp((int)round(metadata.x - FIELD_ID_SDF_OBJECT_BASE), 0, AQUARIUM_SDF_OBJECT_CAPACITY - 1); + float3 localPosition = worldPosition - sdfObjects[sdfIndex].centerRadius.xyz; + return float4(uv, localPosition.xz); + } + + return float4(uv, uv); +} + +float4 sceneReservoirDomainSupport(float4 metadata, float4 control) +{ + if (metadata.x >= FIELD_ID_SDF_OBJECT_BASE) + { + float radiusPx = max(1.0, 1.0 + saturate(control.y) * 2.0); + return float4(radiusPx, radiusPx, FieldDomainKindSdf, FieldShiftKindObjectReplay); + } + + return float4(1.0, 1.0, FieldDomainKindScreen, FieldShiftKindNone); +} + FieldReservoirSample sceneFieldReservoirSample(float2 uv) { float4 colorTravel = sourceTexture.SampleLevel(sourceSampler, uv, 0.0); @@ -393,6 +419,8 @@ FieldReservoirSample sceneFieldReservoirSample(float2 uv) control, guide, 0.0, + sceneReservoirDomainSample(uv, colorTravel, metadata), + sceneReservoirDomainSupport(metadata, control), target, 1.0, 1.0, @@ -422,7 +450,8 @@ float reservoirTemporalValidationWeight( FieldReservoirSample previousSample, float expectedPreviousTravel, float3 neighborhoodMin, - float3 neighborhoodMax) + float3 neighborhoodMax, + float2 dimensions) { if (!fieldReservoirSampleValid(currentSample, farDistance) || !fieldReservoirSampleValid(previousSample, farDistance)) @@ -454,13 +483,15 @@ float reservoirTemporalValidationWeight( float detailWeight = 1.0 - smoothstep(0.08, 0.45, abs(saturate(previousSample.control.z) - saturate(currentSample.control.z))); float confidenceWeight = lerp(0.45, 1.0, min(reservoirSampleConfidence(currentSample), reservoirSampleConfidence(previousSample))); float domainWeight = reservoirSampleDomainValidity(currentSample) * reservoirSampleDomainValidity(previousSample); - return travelWeight * fieldWeight * normalWeight * colorWeight * coverageWeight * coverageContinuityWeight * detailWeight * confidenceWeight * domainWeight; + float supportOverlap = fieldReservoirDomainSupportOverlap(currentSample, previousSample, dimensions); + return travelWeight * fieldWeight * normalWeight * colorWeight * coverageWeight * coverageContinuityWeight * detailWeight * confidenceWeight * domainWeight * supportOverlap; } float reservoirTemporalRejectionCode( FieldReservoirSample currentSample, FieldReservoirSample previousSample, - float expectedPreviousTravel) + float expectedPreviousTravel, + float2 dimensions) { if (!fieldReservoirSampleValid(previousSample, farDistance)) { @@ -483,10 +514,20 @@ float reservoirTemporalRejectionCode( return 6.0; } + if (!fieldReservoirDomainStateValid(previousSample) || !fieldReservoirDomainStateValid(currentSample)) + { + return 7.0; + } + + if (fieldReservoirDomainSupportOverlap(currentSample, previousSample, dimensions) <= 0.0) + { + return 8.0; + } + return 1.0; } -float reservoirSpatialValidationWeight(FieldReservoirSample currentSample, FieldReservoirSample neighborSample, float pixelDistance) +float reservoirSpatialValidationWeight(FieldReservoirSample currentSample, FieldReservoirSample neighborSample, float pixelDistance, float2 dimensions) { if (!fieldReservoirSampleValid(currentSample, farDistance) || !fieldReservoirSampleValid(neighborSample, farDistance)) @@ -506,8 +547,9 @@ float reservoirSpatialValidationWeight(FieldReservoirSample currentSample, Field } float supportWeight = smoothstep(0.001, 0.45, min(saturate(neighborSample.control.x), saturate(currentSample.control.x))); + float supportOverlap = fieldReservoirDomainSupportOverlap(currentSample, neighborSample, dimensions); float distanceWeight = 1.0 - smoothstep(0.0, 1.75, pixelDistance); - return fieldWeight * travelWeight * normalWeight * supportWeight * distanceWeight * + return fieldWeight * travelWeight * normalWeight * supportWeight * supportOverlap * distanceWeight * reservoirSampleDomainValidity(currentSample) * reservoirSampleDomainValidity(neighborSample); } @@ -577,10 +619,11 @@ FieldReservoirSample temporallyReuseReservoirSample(FieldReservoirSample current previous, expectedPreviousTravel, neighborhoodMin, - neighborhoodMax); + neighborhoodMax, + (float2)dimensions); if (validationWeight <= 0.0) { - temporal.guide.w = reservoirTemporalRejectionCode(current, previous, expectedPreviousTravel); + temporal.guide.w = reservoirTemporalRejectionCode(current, previous, expectedPreviousTravel, (float2)dimensions); return temporal; } @@ -616,7 +659,7 @@ FieldReservoirSample spatiallyReuseReservoirSample(FieldReservoirSample temporal uint2 neighborPixel = (uint2)neighborSigned; float2 neighborUv = (float2(neighborPixel) + 0.5) / float2(dimensions); FieldReservoirSample neighbor = currentFrameReservoirSample(neighborPixel, neighborUv); - float validationWeight = reservoirSpatialValidationWeight(spatial, neighbor, length(float2(x, y))); + float validationWeight = reservoirSpatialValidationWeight(spatial, neighbor, length(float2(x, y)), (float2)dimensions); if (validationWeight <= 0.0) { continue; @@ -706,6 +749,37 @@ float4 reservoirDebugOrColor(FieldReservoirSample candidate) candidate.colorTravel.w); } + if (renderDebugMode >= 15.5 && renderDebugMode < 16.5) + { + if (!fieldReservoirSampleValid(candidate, farDistance)) + { + return float4(0.0, 0.0, 0.0, candidate.colorTravel.w); + } + + return float4(frac(candidate.domainSample.x), frac(candidate.domainSample.y), saturate(candidate.domainSupport.z / 4.0), candidate.colorTravel.w); + } + + if (renderDebugMode >= 16.5 && renderDebugMode < 17.5) + { + if (!fieldReservoirSampleValid(candidate, farDistance)) + { + return float4(0.0, 0.0, 0.0, candidate.colorTravel.w); + } + + float2 footprint = saturate(candidate.domainSupport.xy / 8.0); + return float4(footprint.x, footprint.y, saturate(candidate.guide.z), candidate.colorTravel.w); + } + + if (renderDebugMode >= 17.5 && renderDebugMode < 18.5) + { + if (!fieldReservoirSampleValid(candidate, farDistance)) + { + return float4(0.0, 0.0, 0.0, candidate.colorTravel.w); + } + + return float4(saturate(candidate.domainSupport.w / 3.0), saturate(candidate.guide.w / 7.0), saturate(candidate.domainSupport.z / 4.0), candidate.colorTravel.w); + } + return float4(fieldReservoirResolvedColor(candidate, farDistance), candidate.colorTravel.w); } @@ -809,7 +883,7 @@ ResolveOut D3D12ReservoirPresentationResolvePS(VertexOut input) { finalColor = float3(currentReservoirConfidence, saturate(reservoirSampleAge / MAX_HISTORY_AGE), currentReservoirDomainValidity); } - else if (renderDebugMode >= 12.5 && renderDebugMode < 15.5) + else if (renderDebugMode >= 12.5 && renderDebugMode < 18.5) { finalColor = saturate(resolved); } diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12TubeField.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12TubeField.hlsl index 509a444..4c097be 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12TubeField.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12TubeField.hlsl @@ -879,12 +879,19 @@ SceneOut D3D12TubeFieldPS(TubeFieldVertexOut input) output.reservoirGuide = float4(claimCoverage, 0.0, supportCoverage, value); output.depth = saturate(travel / max(farDistance, 0.0001)); float target = fieldReservoirDefaultTarget(output.colorTravel, output.control, output.reservoirGuide); + float selectedColumn = (float)PhysicalColumnWithOffset((uint)round(input.tubeData.x), currentRollingOffset); + float2 selectedUv = (baseSamplePx + 0.5) / max(resolution, float2(1.0, 1.0)); + float2 selectedProducerCoord = float2(selectedColumn, sampleX); + float2 supportFootprintPx = max(float2(baseRadiusPx, baseRadiusPx), float2(0.5, 0.5)); + float shiftKind = motion.w > 0.5 ? FieldShiftKindExplicitMotion : FieldShiftKindNone; FieldReservoirSample sample = makeFieldReservoirSample( output.colorTravel, output.metadata, output.control, output.reservoirGuide, motion, + float4(saturate(selectedUv), selectedProducerCoord), + float4(supportFootprintPx, FieldDomainKindTube, shiftKind), target, 1.0, 1.0, diff --git a/state/evidence.jsonl b/state/evidence.jsonl index bcafaa9..c389bce 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -292,3 +292,4 @@ {"timestamp":"2026-05-29T20:35:00+01:00","topic":"fensalir-pipeline-paper","lesson":"The Fensalir pipeline now has a living MiKTeX paper that frames the renderer as a fractal domain reservoir pipeline rather than a screen-space temporal cache. The paper cites the local research archive plus external anchors for ReSTIR/GRIS/Area ReSTIR/TSR, cube-sphere/QSC domains, EWA/Gaussian splatting, clipmaps/Nanite, implicit and sensor fusion, HDR presentation, D3D12 resource discipline, and planetary-flow data/model sources. Use it as the public research synthesis before broad implementation changes; update it as implementation proves, falsifies, or sharpens the claims.","files":["docs/papers/fensalir-pipeline.tex","docs/papers/fensalir-pipeline.pdf","docs/README.md"],"sources":["docs/perfect-machine-architecture.md","docs/fractal-domain-reservoir.md","docs/temporal-spatial-evidence-reservoir.md","research/rendering/fractal-brush-architecture-plan.md","research/rendering/cube-sphere-fractal-brushes.md","research/planetary-flow-organ-literature.md"]} {"timestamp":"2026-05-29T21:10:00+01:00","topic":"siggraph-core-paper-reorientation","lesson":"SIGGRAPH framing should not sell the whole Perfect Machine as one paper. The focused technical claim is native-domain reservoir state for mixed TubeField/SDF/splat reuse: selected producer-domain coordinate, support footprint, proposal measure, target value, and legal shift metadata should reduce leakage/ghosting compared with texel-owned reuse. The broad pipeline paper remains architecture context; the focused paper names required scenes, baselines, ablations, metrics, and current prototype debug captures, and explicitly does not claim final results until those proof obligations are paid.","files":["docs/papers/fensalir-native-domain-reservoirs.tex","docs/papers/fensalir-native-domain-reservoirs.pdf","docs/README.md"],"sources":["user SIGGRAPH-hat review","docs/papers/fensalir-pipeline.tex","docs/fractal-domain-reservoir.md","docs/temporal-spatial-evidence-reservoir.md"]} {"timestamp":"2026-05-29T21:35:00+01:00","topic":"perfect-fensalir-machine-roadmap","lesson":"The Perfect Fensalir Machine roadmap now makes the native-domain reservoir proof the first implementation gate. The immediate work packet is to add or repack FieldReservoirSample so TubeField and SDF row-0 proposals carry selected domain/sample coordinates and support, expose support/shift debug views, and validate temporal reuse by support overlap before more occlusion-threshold tuning. Broader fractal hierarchy, residency, sensor/flow, and learned-priority work waits behind the evaluated mixed-field proof.","files":["docs/perfect-fensalir-machine-roadmap.md","docs/README.md","state/scratch.md","state/map.yaml"],"sources":["docs/fractal-domain-reservoir.md","docs/papers/fensalir-native-domain-reservoirs.tex","docs/reservoir-reconstruction-action-plan.md","user requested synthesis into implementation roadmap"]} +{"timestamp":"2026-05-29T22:23:11+01:00","topic":"native-domain-reservoir-abi","lesson":"FieldReservoirSample is now a nine-lane native-domain reservoir row: colorTravel, metadata, control, guide, motion, domainSample, domainSupport, proposal, and stats. TubeField proposals write selected subpixel UV, physical rolling column, curve coordinate, tube support footprint, and shift kind; SDF proposals reconstruct object-local hit coordinates. Reservoir validity rejects missing domain state, temporal/spatial reuse includes support overlap, and debug modes 16-18 expose domain coordinate, support/domain kind, and shift state. The next proof cut is producer re-evaluation after support overlap, not another occlusion threshold.","files":["src/Aquarium.Engine/Render/Shaders/D3D12FieldReservoir.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12TubeField.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine.Contracts/GraphicsSettings.cs","tests/Aquarium.Engine.Tests/FieldReservoirAbiTests.cs","docs/papers/fensalir-native-domain-reservoirs.tex","docs/papers/fensalir-pipeline.tex","docs/perfect-fensalir-machine-roadmap.md","state/map.yaml","state/scratch.md"],"sources":["docs/perfect-fensalir-machine-roadmap.md"]} diff --git a/state/map.yaml b/state/map.yaml index cd5ace9..3b7172d 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -128,10 +128,11 @@ next_actions: residency, and learned-priority work waits behind that gate. - Cut the rendering rebuild through explicit field-domain/field-claim contracts before adding another backend-specific visual path. - - Before more occlusion-threshold tuning, update the live GPU reservoir ABI or - packing plan so TubeField and SDF proposals include selected - domain/sample-coordinate and support data. Then debug temporal/spatial reuse - in terms of support overlap and legal shifts, not nearest previous texels. + - Before more occlusion-threshold tuning, extend the first native-domain ABI + cut into producer replay/re-evaluation. TubeField and SDF proposals now + include selected domain/sample-coordinate and support data, and reuse + validates support overlap; the next cut is to re-evaluate the shifted + TubeField/SDF sample in the target domain before merge. - 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 @@ -251,17 +252,20 @@ next_actions: flat family constant, so temporal/reprojection/reservoir consumers can distinguish source-lane claims while preserving the TubeField family range. D3D12 now has the first real shared field-reservoir spine. The HLSL - reservoir ABI is a seven-lane `FieldReservoirSample` - colorTravel/metadata/control/guide/motion/proposal/stats record. Proposal - stores target, sourcePdf, representedCandidateCount, and proposalKind; - stats stores selectedTarget, weightSum, candidateCount, and contribution - weight. The four rows per pixel are no longer a private top-four visible - list: row 0 is current-frame initial RIS, row 1 is temporal reuse, row 2 is - spatial/domain reuse, and row 3 is the final resolved reservoir consumed by - bloom/presentation. Direct scene/SDF contributors are normalized into the - same deterministic structural one-sample proposal shape as TubeField before - RIS merge inside `D3D12ReservoirHistoryUpdateCS`, so the SDF/scene path and - TubeField path share target/sourcePdf and history semantics. The fullscreen + reservoir ABI is a nine-lane `FieldReservoirSample` + colorTravel/metadata/control/guide/motion/domainSample/domainSupport/proposal/stats + record. `domainSample` stores selected pixel/sample UV plus packed producer + coordinate; `domainSupport` stores support footprint, domain kind, and shift + kind. Proposal stores target, sourcePdf, representedCandidateCount, and + proposalKind; stats stores selectedTarget, weightSum, candidateCount, and + contribution weight. The four rows per pixel are no longer a private + top-four visible list: row 0 is current-frame initial RIS, row 1 is temporal + reuse, row 2 is spatial/domain reuse, and row 3 is the final resolved + reservoir consumed by bloom/presentation. Direct scene/SDF contributors are + normalized into the same deterministic structural one-sample proposal shape + as TubeField before RIS merge inside `D3D12ReservoirHistoryUpdateCS`, so the + SDF/scene path and TubeField path share target/sourcePdf and history + semantics. The fullscreen field resolve pass is explicitly demoted to raw scene/SDF MRT carry-forward; it does not call current-frame reservoir merge and cannot import TubeField proposals before the compute pass. TubeField candidate discovery is still the @@ -271,22 +275,27 @@ next_actions: camera ray with the generated tube frustum/cap neighborhood in world space. TubeField now writes a one-sample reservoir proposal into row 0 with target derived from projected coverage, guide confidence, and luminance relevance; - sourcePdf is 1.0 for deterministic structural proposals. The old - nearest-travel-minus-coverage priority authority is cut from both TubeField - injection and final resolve. Shared temporal reuse validates only the - previous frame's row-3 final reservoir by field id, travel, normal, domain - validity, motion/previous UV, and guide confidence before RIS merge; rejected - history cannot become visible fallback by itself. Spatial reuse validates - neighboring current reservoirs by field id, travel, normal, support, and - domain before merge. Current-frame structural proposal assembly has a + sourcePdf is 1.0 for deterministic structural proposals. TubeField row-0 + proposals also write selected subpixel UV, physical rolling column, curve + coordinate, tube support footprint, and explicit motion shift kind when + available; SDF scene proposals reconstruct object-local hit coordinates and + mark object-motion replay. The old nearest-travel-minus-coverage priority + authority is cut from both TubeField injection and final resolve. Shared + temporal reuse validates only the previous frame's row-3 final reservoir by + field id, travel, normal, domain validity, motion/previous UV, guide + confidence, and support overlap before RIS merge; rejected history cannot + become visible fallback by itself. Spatial reuse validates neighboring + current reservoirs by field id, travel, normal, support overlap, and domain + before merge. Current-frame structural proposal assembly has a visibility gate before RIS: if two valid proposals at the same pixel differ materially in travel, the farther proposal is treated as occluded and cannot compete by target/luminance. Near-equal-depth proposals still merge through RIS. TubeField also separates conservative proxy discovery from reservoir support; row-0 target/control/guide use narrow tube-core support rather than - the broad proxy envelope. Reservoir debug modes 13-15 inspect the compute-owned - final/reuse layer: rejection state, selectedTarget, weightSum, - candidateCount, proposal target/sourcePdf, and contribution weight. The + the broad proxy envelope. Reservoir debug modes 13-18 inspect the + compute-owned final/reuse layer: rejection state, selectedTarget, weightSum, + candidateCount, proposal target/sourcePdf, contribution weight, selected + domain/sample coordinate, support footprint/domain kind, and shift kind. The deleted TubeField-local compute ReSTIR/tile-bin path is not a live authority, fallback, or hidden mode. Any future temporal/spatial reuse for tubes must extend the shared reservoir diff --git a/state/scratch.md b/state/scratch.md index 3de3a3e..eb25576 100644 --- a/state/scratch.md +++ b/state/scratch.md @@ -2,8 +2,8 @@ ## Current Slice -Implement the first Perfect Fensalir Machine roadmap packet: add native-domain -sample coordinate/support authority to the shared field reservoir. +Extend the first Perfect Fensalir Machine reservoir cut from native-domain row +state into producer-domain replay/re-evaluation. ## Hot Lesson @@ -14,24 +14,23 @@ history trust at the layer that owns visible output. Fensalir needs both, but one level higher: selected samples are field and radiance claims lowered from semantic domains and a dynamic contribution tree into bounded GPU reservoirs. -The current seven-lane row ABI can remain only as an execution projection if it -gains first-class selected domain/sample-coordinate authority. A row keyed only -by pixel, travel, field id, guide, proposal, and stats is still too texel-like. +The current nine-lane row ABI now carries first-class selected +domain/sample-coordinate authority. A row keyed only by pixel, travel, field id, +guide, proposal, and stats is no longer accepted as valid reservoir evidence. ## Next Bounded Move -Follow `docs/perfect-fensalir-machine-roadmap.md` Phase 1 and the immediate -work packet: +Follow `docs/perfect-fensalir-machine-roadmap.md` Phase 1: -1. Add or repack `FieldReservoirSample` with selected domain/sample coordinate - and support footprint. -2. Write TubeField row-0 selected subpixel/source/curve support. -3. Write SDF row-0 selected hit/domain support. -4. Add debug modes for selected coordinate, support overlap, and shift kind. -5. Implement temporal support-overlap validation before further threshold - tuning. +1. Implement producer re-evaluation after the support-overlap gate for + TubeField rolling-column replay. +2. Implement SDF object-hit replay/re-evaluation for shifted history. +3. Capture the occluded-spectrum-tubes scene in baseline/native-domain modes + after replay is real, not merely support-overlap filtered. ## Verification - `dotnet build Fensalir.sln` +- `dotnet test tests/Aquarium.Engine.Tests/Aquarium.Engine.Tests.csproj` +- `dotnet test tests/Aquarium.Engine.Fractal.Tests/Aquarium.Engine.Fractal.Tests.csproj` - `.\scripts\dev-reload.ps1 -Headless -RetainSlots 4 -ClientProject src\Aquarium.Fensalir\Aquarium.Fensalir.csproj` diff --git a/tests/Aquarium.Engine.Tests/FieldReservoirAbiTests.cs b/tests/Aquarium.Engine.Tests/FieldReservoirAbiTests.cs new file mode 100644 index 0000000..ddf18b9 --- /dev/null +++ b/tests/Aquarium.Engine.Tests/FieldReservoirAbiTests.cs @@ -0,0 +1,57 @@ +using System.Text.RegularExpressions; + +namespace Aquarium.Engine.Tests; + +public sealed class FieldReservoirAbiTests +{ + [Fact] + public void HlslReservoirRowsCarryNativeDomainState() + { + var repoRoot = FindRepoRoot(); + var hlsl = File.ReadAllText(Path.Combine(repoRoot, "src", "Aquarium.Engine", "Render", "Shaders", "D3D12FieldReservoir.hlsli")); + var renderer = File.ReadAllText(Path.Combine(repoRoot, "src", "Aquarium.Engine", "Render", "D3D12Renderer.cs")); + + var structMatch = Regex.Match( + hlsl, + @"struct\s+FieldReservoirSample\s*\{(?.*?)\};", + RegexOptions.Singleline); + + Assert.True(structMatch.Success); + var lanes = Regex.Matches(structMatch.Groups["body"].Value, @"\bfloat4\s+\w+\s*;") + .Select(match => match.Value) + .ToArray(); + + Assert.Equal(9, lanes.Length); + Assert.Contains("float4 domainSample;", lanes); + Assert.Contains("float4 domainSupport;", lanes); + Assert.Contains("private const int FieldReservoirCandidateStrideBytes = 144;", renderer); + Assert.Contains("private const int FieldReservoirHistoryStrideBytes = 144;", renderer); + } + + [Fact] + public void NativeDomainSamplesAreRequiredForReservoirValidity() + { + var repoRoot = FindRepoRoot(); + var hlsl = File.ReadAllText(Path.Combine(repoRoot, "src", "Aquarium.Engine", "Render", "Shaders", "D3D12FieldReservoir.hlsli")); + + Assert.Contains("bool fieldReservoirDomainStateValid", hlsl); + Assert.Contains("fieldReservoirDomainStateValid(sample) &&", hlsl); + Assert.Contains("float fieldReservoirDomainSupportOverlap", hlsl); + } + + private static string FindRepoRoot() + { + var directory = new DirectoryInfo(AppContext.BaseDirectory); + while (directory is not null) + { + if (File.Exists(Path.Combine(directory.FullName, "Fensalir.sln"))) + { + return directory.FullName; + } + + directory = directory.Parent; + } + + throw new InvalidOperationException("Could not locate Fensalir.sln from test output directory."); + } +}