Fix D3D12 resize backbuffer release

This commit is contained in:
Meta Vens 2026-05-30 21:55:22 +01:00
commit 7527cade95
5 changed files with 67 additions and 0 deletions

View file

@ -1826,6 +1826,8 @@ public sealed class D3D12Renderer : IAquariumRenderer
overlays = [];
overlayWrappedBackBuffers = [];
overlayContext.ClearState();
overlayContext.Flush();
}
private D3D12PipelineSet CreatePipelineSet(D3D12ShaderPaths paths)
@ -1919,6 +1921,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
WaitForGpu();
DisposeBackBufferOverlays();
DisposeProgramOutputTexture();
RemoveBloomRenderTargets();
RemoveGraphRenderTargets();
resourceRegistry.RemoveRenderTarget("scene-hdr-target");

View file

@ -305,6 +305,7 @@
{"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.*"}
{"timestamp":"2026-05-30T01:58:00+01:00","topic":"reservoir-spatial-reuse-budget","lesson":"The renderer now has a first runtime sampling budget inside the reservoir history update owner. GraphicsSettings.FieldReservoirSpatialReuseBudget flows through UI, runtime options, CLI/env overrides, capture scripts, frame constants, and D3D12ReservoirHistoryUpdateCS. Current and temporal rows are still written for every reservoir work-grid pixel; only the 3x3 spatial neighbor reuse pass is spent on the deterministic budget phase. The default is 0.5, so the machine combines half presentation grid reservoir surfaces with half spatial reuse sampling by default. Smoke reservoir-sequence-20260530-003006-* compared native scale 0.5/spatial budget 0.5 against reference scale 0.75/spatial budget 1.0; masked reference-error-native covered 3.8261% of frame pixels, and reservoir-budget-pressure-20260530-003006.* found the top 5/50 tiles carried 90.8321% of measured reference-error delta.","files":["src/Aquarium.Engine.Contracts/GraphicsSettings.cs","src/Aquarium.Engine/AquariumHost.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","scripts/capture-fensalir-frame.ps1","scripts/capture-reservoir-mode-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-003006-*"}
{"timestamp":"2026-05-30T02:10:00+01:00","topic":"reservoir-spatial-budget-debug","lesson":"The spatial reuse sampling budget now has a visible owner-layer probe. Render debug mode 20, Reservoir Spatial Budget, colors work-grid pixels that spend 3x3 spatial reuse green and skipped pixels blue; capture-reservoir-mode-sequence.ps1 names the mode spatial-budget. Smoke reservoir-sequence-20260530-003746-* captured the debug view at native scale 0.5/spatial budget 0.5. A bitmap probe on the 304x141 present output counted 32078 green pixels, 6818 blue pixels, and 3968 filtering/other pixels, proving the budget branch is observable where the user sees it.","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","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-003746-*"}
{"timestamp":"2026-05-30T22:02:00+01:00","topic":"d3d12-resize-reference-release","lesson":"The Fensalir resize crash was a hidden-reference ownership bug in the swapchain path. Resize disposed DirectWrite overlays and D3D11-on-12 wrapped backbuffers, but the D3D11 immediate context could still retain references unless it was explicitly cleared and flushed before IDXGISwapChain::ResizeBuffers. Resize now clears/flushes the overlay context and drops program-output shared textures before recreating size-dependent surfaces. A visible dev slot survived seven programmatic window resizes and logged target rebuilds without stderr.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","tests/Aquarium.Engine.Tests/D3D12ResizeTests.cs","state/scratch.md","state/map.yaml"],"source":"artifacts/dev-reload/latest.out.log"}
{"timestamp":"2026-05-30T00:29:26+01:00","topic":"surfacepage-uav-depth-socket","lesson":"SurfacePage resources can now be GPU-resident unordered-access outputs as well as shader-readable pages. D3D12FieldTexture2D tracks UAV capability, creates UAV descriptors, and D3D12FieldResourceRegistry resolves UnorderedAccess SurfacePages while reusing empty pages across version changes when shape/format/access are unchanged. This gives Mimir stereo-depth/height outputs a real compute-writable resource socket without private output textures or CPU readback.","files":["src/Aquarium.Engine/Render/D3D12FieldTexture2D.cs","src/Aquarium.Engine/Render/D3D12FieldResourceRegistry.cs","tests/Aquarium.Engine.Tests/D3D12SharedTextureInteropTests.cs","docs/perfect-fensalir-machine-roadmap.md","state/map.yaml"],"source":"dotnet test tests/Aquarium.Engine.Tests/Aquarium.Engine.Tests.csproj --filter RegistryResolvesUnorderedAccessSurfacePageForComputeDepthOutput"}
{"timestamp":"2026-05-30T00:37:29+01:00","topic":"stereo-depth-lowering-contract","lesson":"FieldEvidence now carries typed stereo-depth lowering metadata for future D3D12 SGM dispatch. AquariumFieldStereoDepthLowering binds a Height claim to shader-readable left/right texture resources, profile/calibration/camera-pair identity, depth range/disparity settings, and a compute-writable UAV disparity SurfacePage. Validation rejects claim encoding mismatches, payload/resource mismatches, non-UAV disparity outputs, and missing/non-readable inputs. This keeps Mimir libSGM-provenance depth inside Fensalir resource authority rather than a private texture, CPU readback, CUDA, or TensorRT path.","files":["src/Aquarium.Engine.Contracts/Render/AquariumFieldEvidence.cs","tests/Aquarium.Engine.Tests/FieldEvidenceContractTests.cs","docs/perfect-fensalir-machine-roadmap.md","state/map.yaml"],"source":"dotnet test tests/Aquarium.Engine.Tests/Aquarium.Engine.Tests.csproj --filter StereoDepth"}
{"timestamp":"2026-05-30T00:43:53+01:00","topic":"stereo-depth-dispatch-readiness","lesson":"D3D12Renderer now evaluates stereo-depth lowerings for dispatch readiness without installing a fake depth kernel. A lowering is counted ready only when the SurfacePage Height claim is planned, left/right input Texture2D resources resolve through the field resource registry, and the disparity SurfacePage resolves with UAV capability. Capacity logs report ready/unplanned/unresolved counts and explicitly say the kernel is not installed.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","docs/perfect-fensalir-machine-roadmap.md","state/map.yaml"],"source":"dotnet build src/Aquarium.Engine/Aquarium.Engine.csproj --no-restore"}

View file

@ -174,6 +174,11 @@ next_actions:
`reservoir-sequence-20260530-003746-*` proves it. The next cut is turning
budget-pressure evidence into a renderer-owned per-tile adaptive update
contract plus future exact producer SDF replay.
- Window resize no longer crashes on the D3D12 swapchain path: resize now
disposes DirectWrite overlays and wrapped backbuffers, clears/flushes the
D3D11-on-12 context before `ResizeBuffers`, and drops program-output shared
textures before recreating size-dependent surfaces. Visible resize probe
`20260530-215113-639e6612` survived seven programmatic resizes.
- 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

@ -87,6 +87,15 @@ for the current frame. Smoke
mode at scale 0.5 / spatial budget 0.5. A bitmap probe counted 32078 green,
6818 blue, and 3968 other/filtering pixels in the 304x141 present output.
Window resize fix:
The Fensalir window resize path now explicitly clears and flushes the D3D11-on-12
overlay context after disposing DirectWrite overlays and wrapped backbuffer
resources, before `IDXGISwapChain::ResizeBuffers`. Resize also disposes
program-output shared textures before recreating size-dependent output surfaces.
Probe `scripts/dev-reload.ps1` visible slot `20260530-215113-639e6612` survived
seven programmatic resizes and logged rebuilt D3D12 targets at each size with no
stderr.
## Hot Lesson
Area ReSTIR confirms that reuse over an area domain is invalid unless the
@ -113,6 +122,10 @@ SDF history reconstructs the previous selected world hit from stored UV/travel,
carries it through object center motion, and validates current ray/travel/support
before temporal reuse can merge it. TubeField batches beyond the manifest source
cap remain intentionally non-authoritative.
Swapchain resize correctness depends on releasing both D3D12 backbuffer owners
and D3D11-on-12 overlay references before `ResizeBuffers`. Disposing wrapped
resources is not enough; the D3D11 immediate context must be cleared and flushed
so it stops holding hidden references.
## Next Bounded Move

View file

@ -0,0 +1,45 @@
namespace Aquarium.Engine.Tests;
public sealed class D3D12ResizeTests
{
[Fact]
public void ResizeReleasesOverlayAndProgramOutputReferencesBeforeResizeBuffers()
{
var repoRoot = FindRepoRoot();
var renderer = File.ReadAllText(Path.Combine(repoRoot, "src", "Aquarium.Engine", "Render", "D3D12Renderer.cs"));
var disposeOverlayIndex = renderer.IndexOf("private void DisposeBackBufferOverlays()", StringComparison.Ordinal);
Assert.True(disposeOverlayIndex >= 0);
var disposeOverlayEndIndex = renderer.IndexOf("private void ResizeIfNeeded", disposeOverlayIndex, StringComparison.Ordinal);
Assert.True(disposeOverlayEndIndex > disposeOverlayIndex);
var disposeOverlayBody = renderer[disposeOverlayIndex..disposeOverlayEndIndex];
Assert.Contains("overlayContext.ClearState();", disposeOverlayBody);
Assert.Contains("overlayContext.Flush();", disposeOverlayBody);
var resizeIndex = renderer.IndexOf("private void ResizeIfNeeded", StringComparison.Ordinal);
Assert.True(resizeIndex >= 0);
var resizeBuffersIndex = renderer.IndexOf("swapChain.ResizeBuffers", resizeIndex, StringComparison.Ordinal);
Assert.True(resizeBuffersIndex > resizeIndex);
var preResizeBuffersBody = renderer[resizeIndex..resizeBuffersIndex];
Assert.Contains("DisposeBackBufferOverlays();", preResizeBuffersBody);
Assert.Contains("DisposeProgramOutputTexture();", preResizeBuffersBody);
}
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.");
}
}