Keep D3D12 off swapchain until ready

This commit is contained in:
Meta Vens 2026-05-09 23:12:37 +01:00
commit bb742d6ef2
4 changed files with 7 additions and 58 deletions

View file

@ -58,6 +58,10 @@ public static class AquariumHost
}
renderer.Render(runtimeLoader.Runtime.Frame, window.ClientWidth, window.ClientHeight);
if (!runtime.Options.Headless && !renderer.HasPresentedReadyFrame)
{
window.PaintSplash("Aquarium", "Compiling renderer pipelines");
}
frames++;
if (renderer.HasPresentedReadyFrame)

View file

@ -396,7 +396,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
commandQueue.ExecuteCommandList(commandList);
var overlayCpuStart = Stopwatch.GetTimestamp();
RenderLoadingOverlay(frameResources);
RenderOverlay(frame, frameResources);
var overlayCpuMilliseconds = ElapsedMilliseconds(overlayCpuStart);
swapChain.Present(1, PresentFlags.None);
var frameCpuMilliseconds = ElapsedMilliseconds(frameCpuStart);
@ -432,27 +432,11 @@ public sealed class D3D12Renderer : IAquariumRenderer
private void RenderPipelineLoadingFrame(AquariumFrame frame, FrameResources frameResources, long frameCpuStart)
{
frameResources.CommandAllocator.Reset();
commandList.Reset(frameResources.CommandAllocator, null);
commandList.BeginEvent("Aquarium D3D12 Pipeline Loading Frame");
frameResources.BackBuffer.Transition(commandList, ResourceStates.RenderTarget);
commandList.ClearRenderTargetView(frameResources.BackBufferRenderTargetView.Cpu, new Color4(0.002f, 0.006f, 0.008f, 1.0f));
commandList.EndEvent();
commandList.Close();
commandQueue.ExecuteCommandList(commandList);
var overlayCpuStart = Stopwatch.GetTimestamp();
RenderOverlay(frame, frameResources);
var overlayCpuMilliseconds = ElapsedMilliseconds(overlayCpuStart);
swapChain.Present(1, PresentFlags.None);
SignalFrame(frameResources);
var frameCpuMilliseconds = ElapsedMilliseconds(frameCpuStart);
accumulatedOverlayCpuMilliseconds += overlayCpuMilliseconds;
accumulatedFrameCpuMilliseconds += frameCpuMilliseconds;
accumulatedTimingFrames++;
ReportCapacityOncePerSecond(frame.TimeSeconds, frameResources);
frameIndex = (int)swapChain.CurrentBackBufferIndex;
Thread.Sleep(8);
}
public void Dispose()
@ -560,16 +544,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
frameResources.BackBuffer.MarkState(ResourceStates.Present);
}
private void RenderLoadingOverlay(FrameResources frameResources)
{
var wrappedBackBuffer = overlayWrappedBackBuffers[frameIndex];
overlayOn12Device.AcquireWrappedResources([wrappedBackBuffer]);
overlays[frameIndex].RenderSplash("Aquarium", "Compiling renderer pipelines");
overlayOn12Device.ReleaseWrappedResources([wrappedBackBuffer]);
overlayContext.Flush();
frameResources.BackBuffer.MarkState(ResourceStates.Present);
}
private void DisposeBackBufferOverlays()
{
foreach (var overlay in overlays)

View file

@ -30,8 +30,6 @@ internal sealed class DirectWriteOverlay : IDisposable
private readonly ID2D1SolidColorBrush trackHoverBrush;
private readonly ID2D1SolidColorBrush trackActiveBrush;
private readonly IDWriteTextFormat titleFormat;
private readonly IDWriteTextFormat splashTitleFormat;
private readonly IDWriteTextFormat splashBodyFormat;
private readonly IDWriteTextFormat smallFormat;
private readonly int width;
private readonly int height;
@ -81,8 +79,6 @@ internal sealed class DirectWriteOverlay : IDisposable
trackHoverBrush = renderTarget.CreateSolidColorBrush(new Color4(0.32f, 0.29f, 0.29f, 0.98f));
trackActiveBrush = renderTarget.CreateSolidColorBrush(new Color4(0.45f, 0.38f, 0.34f, 1.0f));
titleFormat = CreateTextFormat("Montserrat", 18.0f, FontWeight.Thin);
splashTitleFormat = CreateTextFormat("Montserrat", 28.0f, FontWeight.Thin);
splashBodyFormat = CreateTextFormat("Ubuntu Sans", 12.0f, FontWeight.Regular);
smallFormat = CreateTextFormat("Ubuntu Sans", 11.0f, FontWeight.Regular);
}
@ -137,34 +133,9 @@ internal sealed class DirectWriteOverlay : IDisposable
renderTarget.EndDraw();
}
public void RenderSplash(string header, string body)
{
var centerY = height * 0.50f;
renderTarget.BeginDraw();
DrawHeader(
header,
splashTitleFormat,
RectFromEdges(0, centerY - 46.0f, width, centerY - 4.0f),
primaryTextBrush);
renderTarget.DrawLine(
new System.Numerics.Vector2(width * 0.35f, centerY + 6.0f),
new System.Numerics.Vector2(width * 0.65f, centerY + 6.0f),
outlineBrush,
1.0f);
renderTarget.DrawText(
body,
splashBodyFormat,
RectFromEdges(0, centerY + 18.0f, width, centerY + 44.0f),
quietTextBrush,
DrawTextOptions.Clip);
renderTarget.EndDraw();
}
public void Dispose()
{
smallFormat.Dispose();
splashBodyFormat.Dispose();
splashTitleFormat.Dispose();
titleFormat.Dispose();
smallCapsTypography.Dispose();
fontCollection.Dispose();

View file

@ -105,4 +105,4 @@
{"timestamp":"2026-05-09T22:55:27.0000000+01:00","topic":"d3d12-grid-temporal-blue-noise","lesson":"Stable blue-noise dithering is too static for TAA to converge stochastic Grid coverage. The failure mode to avoid is global threshold flicker where all pixels toggle together. Use a per-frame low-discrepancy pixel offset into the blue-noise tile so each pixel changes threshold over time while the spatial mask remains decorrelated.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json","state/scratch.md"]}
{"timestamp":"2026-05-09T22:59:44.0000000+01:00","topic":"d3d12-grid-taa-color-contract","lesson":"Stable temporal control, history age/weight, and field identity do not prove Grid TAA is smoothing color. D3D12 was still feeding stochastic hit/miss radiance into resolve/history. The fix is the D3D11 contract: post resolve reconstructs analytic Grid color from current Grid travel/world position using the Grid height target, nearest-loads Grid history, and skips color-delta rejection for Grid pixels while raw debug keeps showing the stochastic stream.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","state/memory.json","state/scratch.md"]}
{"timestamp":"2026-05-09T23:08:12.0000000+01:00","topic":"d3d12-grid-expected-value-brightness","lesson":"Once D3D12 Grid resolve reconstructs the expected stochastic value, line brightness must be tuned as averaged transparent radiance, not as sparse on-sample brightness. The earlier 0.24 alpha scale made Cartesian and isoline contributions collapse when the color path became mathematically honest. Keep scene stochastic selection and post analytic reconstruction using identical Grid color/alpha constants.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","state/evidence.jsonl"]}
{"timestamp":"2026-05-09T23:16:34.0000000+01:00","topic":"startup-splash-ready-gate","lesson":"The Win32 GDI splash only owns startup before the swapchain begins presenting. Once D3D12 owns the window, loading frames must draw the splash through the DirectWrite/D3D11On12 overlay bridge and suppress the normal debug overlay until the first real ready frame. Repainting the HWND DC after Present does not reliably cover the swapchain surface.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/DirectWriteOverlay.cs","state/evidence.jsonl"]}
{"timestamp":"2026-05-09T23:16:34.0000000+01:00","topic":"startup-splash-ready-gate","lesson":"Do not present D3D12 loading frames before the initial shader pipelines are ready. Presenting a black/loading swapchain frame takes visible ownership away from the Win32 splash, and DirectWrite loading text can persist into later frames because it wrote into a live backbuffer. While the async pipeline task runs, the renderer should avoid touching the swapchain; the host can keep repainting the GDI splash until HasPresentedReadyFrame becomes true.","files":["src/Aquarium.Engine/AquariumHost.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","state/evidence.jsonl"]}