From 3c391b2fe69a9bfd4989f5c7504ad59fcf3726aa Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 29 May 2026 16:43:36 +0100 Subject: [PATCH] Cut reservoir visibility split --- docs/reservoir-reconstruction-action-plan.md | 30 +++++++++++++++---- .../Render/Shaders/D3D12FieldReservoir.hlsli | 29 ++++++++++++++++++ .../Render/Shaders/D3D12Post.hlsl | 11 ++++--- .../Render/Shaders/D3D12TubeField.hlsl | 14 ++++----- state/evidence.jsonl | 2 ++ state/map.yaml | 15 ++++++++-- 6 files changed, 80 insertions(+), 21 deletions(-) diff --git a/docs/reservoir-reconstruction-action-plan.md b/docs/reservoir-reconstruction-action-plan.md index 29c981e..2372052 100644 --- a/docs/reservoir-reconstruction-action-plan.md +++ b/docs/reservoir-reconstruction-action-plan.md @@ -82,12 +82,24 @@ old occluded tubes leak through nearby missed tube samples. - Field evidence lowering now preserves proposal policy through backend packets, and validation rejects zero or non-finite target/sourcePdf before backend emission. +- `D3D12FieldReservoirResolvePS` is demoted to a raw scene/SDF MRT carry pass. + It no longer calls the current-frame reservoir merge or imports TubeField + row-0 proposals. `D3D12ReservoirHistoryUpdateCS` is the only owner of row-0 + current RIS merge, then temporal, spatial, row-3 final, and resolved HDR + field texture output. +- TubeField separates conservative proxy discovery from reservoir support. + The proxy envelope can be broad enough to find analytic hits, but the emitted + proposal uses a narrow core support coverage for target/control/guide. +- Current-frame visibility proposals now reject materially farther structural + samples before RIS merge. Near-equal-depth samples still use RIS; occluded + samples no longer compete merely because they have high luminance. ## Authority Map - Owner: `D3D12ReservoirHistoryUpdateCS` owns temporal/spatial reuse and row-3 - final reservoir output; `D3D12FieldReservoirResolvePS` owns only current-frame - normalization and initial RIS merge. + final reservoir output. It also owns row-0 current-frame RIS merge. + `D3D12FieldReservoirResolvePS` owns only raw scene/SDF MRT carry-forward into + the compute-owned history update; it has no proposal selection authority. - Inputs: scene/SDF MRT evidence, TubeField row-0 proposals, previous row-3 final reservoirs, camera reprojection inputs, current metadata/control/guide. - Outputs: row 0 current, row 1 temporal, row 2 spatial, row 3 final, plus the @@ -95,7 +107,8 @@ old occluded tubes leak through nearby missed tube samples. - Derived state: proxy raster output and scene MRTs are proposal inputs; carried history rows are validation inputs; debug guide lanes are diagnostics. - Forbidden writers: TubeField proxy rasterization, presentation, prior history - rows, and priority-sorted visibility buffers must not decide final color. + rows, fullscreen resolve, and priority-sorted visibility buffers must not + decide final color. - Shared path: direct scene/SDF, TubeField, and future producers must emit target/sourcePdf/represented proposal state before reservoir update/reuse. - Deletion line: the old nearest-travel-minus-coverage replacement path is gone @@ -115,7 +128,14 @@ old occluded tubes leak through nearby missed tube samples. unsupported instead of masquerading as accepted history. Rejection mode now separates temporal rejection, disocclusion/no previous support, spatial reuse, missing explicit motion, occlusion, and field-id mismatch. -8. Partial: tune occlusion/disocclusion thresholds against fresh captures after +8. Done: cut the surviving split owner where fullscreen resolve merged + current-frame proposals before the compute history pass merged them again. +9. Done: add a current-frame visibility gate before RIS so farther structural + samples do not compete as visible proposals at the same pixel. +10. Partial: tune occlusion/disocclusion thresholds against fresh captures after this architecture cut. -9. Next: capture final color and row-3 debug views against the noisy/occlusion +11. Next: add row-stage debug probes or tighten producer support semantics for + TubeField; fresh captures still show broad support bands after the ownership + and visibility cuts. +12. Next: capture final color and row-3 debug views against the noisy/occlusion screenshot class and tune target/support policy from those diagnostics. diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12FieldReservoir.hlsli b/src/Aquarium.Engine/Render/Shaders/D3D12FieldReservoir.hlsli index 0ff8960..e00e152 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12FieldReservoir.hlsli +++ b/src/Aquarium.Engine/Render/Shaders/D3D12FieldReservoir.hlsli @@ -169,3 +169,32 @@ FieldReservoirSample mergeFieldReservoirSamples( merged.guide.z = saturate(min(current.guide.z, other.guide.z)); return merged; } + +FieldReservoirSample mergeFieldReservoirVisibilityProposals( + FieldReservoirSample current, + FieldReservoirSample other, + float rng, + float farTravel) +{ + bool currentValid = fieldReservoirSampleValid(current, farTravel); + bool otherValid = fieldReservoirSampleValid(other, farTravel); + if (!currentValid || !otherValid) + { + return mergeFieldReservoirSamples(current, other, rng, farTravel); + } + + float nearTravel = min(current.colorTravel.w, other.colorTravel.w); + float visibilityTolerance = max(0.025, nearTravel * 0.006); + float travelDelta = abs(current.colorTravel.w - other.colorTravel.w); + if (travelDelta > visibilityTolerance) + { + if (current.colorTravel.w <= other.colorTravel.w) + { + return current; + } + + return other; + } + + return mergeFieldReservoirSamples(current, other, rng, farTravel); +} diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl index 60b2ccb..beac9f4 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl @@ -517,7 +517,7 @@ FieldReservoirSample currentFrameReservoirSample(uint2 pixel, float2 uv) uint baseIndex = (pixel.y * width + pixel.x) * FieldReservoirSlotsPerPixel; FieldReservoirSample current = sceneFieldReservoirSample(uv); FieldReservoirSample tube = fieldReservoirCandidates[baseIndex + FieldReservoirRowCurrent]; - current = mergeFieldReservoirSamples( + current = mergeFieldReservoirVisibilityProposals( current, tube, fieldReservoirRandom01(pixel, (uint)frameIndex, 31u), @@ -712,13 +712,12 @@ float4 reservoirDebugOrColor(FieldReservoirSample candidate) FieldReservoirResolveOut D3D12FieldReservoirResolvePS(VertexOut input) { uint2 pixel = (uint2)pixelFromUv(input.uv); - FieldReservoirSample sample = currentFrameReservoirSample(pixel, input.uv); FieldReservoirResolveOut output; - output.colorTravel = sample.colorTravel; - output.metadata = sample.metadata; - output.control = sample.control; - output.reservoirGuide = sample.guide; + output.colorTravel = sourceTexture.Load(int3(pixel, 0)); + output.metadata = loadCurrentMetadata(input.uv); + output.control = loadCurrentControl(input.uv); + output.reservoirGuide = loadCurrentReservoirGuide(input.uv); return output; } diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12TubeField.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12TubeField.hlsl index 45eca95..509a444 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12TubeField.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12TubeField.hlsl @@ -680,7 +680,7 @@ void injectFieldReservoirSample(FieldReservoirSample sample, float2 pixel) uint baseIndex = pixelIndex * FieldReservoirSlotsPerPixel; FieldReservoirSample current = FieldReservoirCandidates[baseIndex + FieldReservoirRowCurrent]; - FieldReservoirCandidates[baseIndex + FieldReservoirRowCurrent] = mergeFieldReservoirSamples( + FieldReservoirCandidates[baseIndex + FieldReservoirRowCurrent] = mergeFieldReservoirVisibilityProposals( current, sample, fieldReservoirRandom01(clampedPixel, (uint)frameIndex, 211u + (uint)round(sample.metadata.x)), @@ -831,9 +831,9 @@ SceneOut D3D12TubeFieldPS(TubeFieldVertexOut input) float closestT = baseHit.axisT; float radiusWorld = baseHit.radius; float3 tubeNormal = baseHit.normal; - float aa = max(fwidth(baseSdf), max(0.75, baseRadiusPx * max(input.feather, 0.0))); - float coverage = 1.0 - smoothstep(0.0, aa, baseSdf); - if (coverage > 0.02 && jitterSdf <= aa) + float supportAa = max(0.55, min(baseRadiusPx * 0.18, 1.75)); + float supportCoverage = 1.0 - smoothstep(0.0, supportAa, baseSdf); + if (supportCoverage > 0.02 && jitterSdf <= supportAa) { closestT = lerp(baseHit.axisT, jitterClosestT, 0.35); } @@ -845,7 +845,7 @@ SceneOut D3D12TubeFieldPS(TubeFieldVertexOut input) float normalFacing = saturate(-dot(ray, tubeNormal)); float glowFacing = pow(normalFacing, max(input.material.z, 0.0001)); float alphaFacing = pow(normalFacing, max(input.material.w, 0.0001)); - float claimCoverage = saturate(input.color.a * coverage * alphaFacing); + float claimCoverage = saturate(input.color.a * supportCoverage * alphaFacing); if (claimCoverage <= 0.004) { discard; @@ -875,8 +875,8 @@ SceneOut D3D12TubeFieldPS(TubeFieldVertexOut input) output.colorTravel = float4(color, min(travel, farDistance + 1.0)); float candidateFieldId = abs(input.tubeData.w) + (float)PhysicalColumnWithOffset((uint)round(input.tubeData.x), currentRollingOffset) * 0.01; output.metadata = float4(candidateFieldId, tubeNormal); - output.control = float4(claimCoverage, coverage, saturate(radiusWorld / max(viewRadius, 0.0001)), value); - output.reservoirGuide = float4(claimCoverage, 0.0, coverage, value); + output.control = float4(claimCoverage, supportCoverage, saturate(radiusWorld / max(viewRadius, 0.0001)), value); + 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); FieldReservoirSample sample = makeFieldReservoirSample( diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 82e7985..9d2629b 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -286,3 +286,5 @@ {"timestamp":"2026-05-29T15:45:00+01:00","type":"decision","status":"ok","note":"Hard-rebuilt the live field reservoir into a shared seven-lane FieldReservoirSample ABI with proposal and stats lanes. Rows now mean current, temporal, spatial, and final; TubeField proxy rasterization emits one-sample RIS proposals into row 0; scene/SDF MRT evidence normalizes into the same proposal shape; temporal reuse validates previous row-3 final reservoirs; spatial reuse validates neighboring current reservoirs; old nearest-travel-minus-coverage slot replacement is cut from TubeField injection and final resolve. Proposal policy now survives field evidence lowering/backend packets and invalid zero/NaN target/sourcePdf is rejected before backend emission. Verified with Aquarium.Engine.Tests, dotnet build Fensalir.sln, headless dev reload, and Mimir --mimir-spectrum-upload-smoke."} {"timestamp":"2026-05-29T16:01:00+01:00","type":"verification","status":"ok","note":"Completed the reservoir diagnostics cut after the rebuild: render debug options 13-15 now name row-3 reservoir rejection, stats, and proposal views; invalid final reservoirs render as unsupported instead of accepted green/proposal mass; CPU RIS tests now pin sourcePdf, represented count, merge probability, selected target, weight sum, candidate count, and contribution weight. Verified with Aquarium.Engine.Tests, Aquarium.Engine.Fractal.Tests, dotnet build Fensalir.sln, headless dev reload, Mimir --mimir-spectrum-upload-smoke, and captures artifacts/fensalir-captures/reservoir-rebuild-fixed-mode13.png, mode14.png, and mode15.png."} {"timestamp":"2026-05-29T16:06:00+01:00","type":"decision","status":"ok","note":"Row-3 final reservoir color now applies the RIS contribution weight via fieldReservoirResolvedColor; intermediate current-frame proposal MRTs remain raw to avoid double-weighting before temporal/spatial reuse. Reservoir rejection debug now distinguishes unsupported final rows, temporal rejection, disocclusion/no previous support, spatial reuse, missing explicit motion, occlusion, and field-id mismatch. Verified with headless dev reload and captures artifacts/fensalir-captures/reservoir-rebuild-weighted-final.png, reservoir-rebuild-weighted-proposal.png, and reservoir-rebuild-rejection-codes.png."} +{"timestamp":"2026-05-29T16:34:00+01:00","type":"decision","status":"ok","note":"Cut a surviving split reservoir owner: D3D12FieldReservoirResolvePS no longer calls currentFrameReservoirSample or imports TubeField row-0 proposals. It now forwards raw scene/SDF MRT evidence only, leaving D3D12ReservoirHistoryUpdateCS as the sole owner of row-0 RIS merge, temporal reuse, spatial reuse, row-3 final, and resolved HDR field output. Verified with dotnet build Fensalir.sln and Mimir synthetic spectrum captures artifacts/runtime/mimir-reservoir-rebuild-single-owner-headless-180.png plus mode13/mode14/mode15 debug captures; remaining noise is now visible as broad TubeField support/proposal mass rather than double-counted fullscreen resolve authority."} +{"timestamp":"2026-05-29T16:45:00+01:00","type":"decision","status":"partial","note":"TubeField proposal emission now separates conservative proxy discovery from reservoir support, using narrow tube-core support for target/control/guide. Current-frame proposal assembly also gates structural visibility before RIS: materially farther samples at the same pixel are rejected as occluded, while near-equal-depth samples still use RIS. Verified shader compile/headless reload, Aquarium.Engine.Tests, Aquarium.Engine.Fractal.Tests, Mimir --mimir-spectrum-upload-smoke, and Mimir synthetic captures artifacts/runtime/mimir-reservoir-rebuild-visibility-gate-headless-180.png plus mode13/mode14/mode15. The visible result improves overlap slightly but still shows broad row-3 support bands, so the next cut needs row-stage debug probes or producer support semantics rather than another downstream clamp."} diff --git a/state/map.yaml b/state/map.yaml index 817432d..3a97654 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -213,8 +213,11 @@ next_actions: 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, so the SDF/scene path and TubeField path share target/sourcePdf - and history semantics. TubeField candidate discovery is still the + 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 fixed-function raster path: compute emits conservative GPU-resident segment proxy geometry and indirect draw packets, the proxy raster only schedules covered pixels, and the proxy pixel shader analytically intersects the @@ -228,7 +231,13 @@ next_actions: 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. Reservoir debug modes 13-15 inspect the compute-owned + 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 deleted TubeField-local compute