diff --git a/scripts/dev-reload.ps1 b/scripts/dev-reload.ps1 index 56583f8..197c190 100644 --- a/scripts/dev-reload.ps1 +++ b/scripts/dev-reload.ps1 @@ -5,7 +5,7 @@ param( [switch]$Reopen, [int]$RetainSlots = 12, [int]$StartupTimeoutSeconds = 5, - [int]$HeadlessTimeoutSeconds = 30 + [int]$HeadlessTimeoutSeconds = 60 ) $ErrorActionPreference = "Stop" diff --git a/src/Aquarium.Engine/Render/D3D12Renderer.cs b/src/Aquarium.Engine/Render/D3D12Renderer.cs index 22de750..7b830ca 100644 --- a/src/Aquarium.Engine/Render/D3D12Renderer.cs +++ b/src/Aquarium.Engine/Render/D3D12Renderer.cs @@ -82,6 +82,7 @@ public sealed class D3D12Renderer : IAquariumRenderer private D3D12RenderTarget sceneRenderTarget; private D3D12RenderTarget sceneMetadataRenderTarget; private D3D12RenderTarget sceneControlRenderTarget; + private readonly Dictionary graphRenderTargets = new(StringComparer.Ordinal); private D3D12TrackedResource sceneDepthTarget; private D3D12DescriptorSlot sceneDepthStencilView; private readonly D3D12RenderTarget[] historyRenderTargets = new D3D12RenderTarget[2]; @@ -188,6 +189,7 @@ public sealed class D3D12Renderer : IAquariumRenderer sceneDepthTarget = CreateSceneDepthTarget(sceneDepthStencilView); CreateHistoryRenderTargets(); CreateBloomRenderTargets(); + CreateGraphRenderTargets(); bodyLightBuffer = new D3D12StructuredBuffer(device, MaxBodyLightCount, Marshal.SizeOf(), "Aquarium D3D12 Body Light Buffer"); agentVisualBuffer = new D3D12StructuredBuffer(device, MaxBodyVisualCount, Marshal.SizeOf(), "Aquarium D3D12 Body Visual Buffer"); resourceRegistry.Add("body-light-buffer", bodyLightBuffer); @@ -444,6 +446,7 @@ public sealed class D3D12Renderer : IAquariumRenderer bodyLightBuffer.Dispose(); DisposeBloomRenderTargets(); DisposeHistoryRenderTargets(); + DisposeGraphRenderTargets(); sceneRenderTarget.Dispose(); sceneMetadataRenderTarget.Dispose(); sceneControlRenderTarget.Dispose(); @@ -619,6 +622,7 @@ public sealed class D3D12Renderer : IAquariumRenderer DisposeBackBufferOverlays(); RemoveBloomRenderTargets(); RemoveHistoryRenderTargets(); + RemoveGraphRenderTargets(); resourceRegistry.RemoveRenderTarget("scene-hdr-target"); resourceRegistry.RemoveRenderTarget("scene-metadata-target"); resourceRegistry.RemoveRenderTarget("scene-control-target"); @@ -626,6 +630,7 @@ public sealed class D3D12Renderer : IAquariumRenderer resourceRegistry.RemoveRenderTarget("grid-height-target"); DisposeBloomRenderTargets(); DisposeHistoryRenderTargets(); + DisposeGraphRenderTargets(); sceneRenderTarget.Dispose(); sceneMetadataRenderTarget.Dispose(); sceneControlRenderTarget.Dispose(); @@ -658,6 +663,7 @@ public sealed class D3D12Renderer : IAquariumRenderer sceneDepthTarget = CreateSceneDepthTarget(sceneDepthStencilView); CreateHistoryRenderTargets(); CreateBloomRenderTargets(); + CreateGraphRenderTargets(); viewport = new Viewport(0.0f, 0.0f, width, height); scissorRect = new RawRect(0, 0, width, height); Console.WriteLine($"D3D12 resized: {width}x{height}; {resourceRegistry.Describe()}"); @@ -821,6 +827,81 @@ public sealed class D3D12Renderer : IAquariumRenderer return target; } + private void CreateGraphRenderTargets() + { + foreach (var targetDescription in renderGraph.RenderTargets) + { + if (IsLegacyGraphTarget(targetDescription.Handle.Name) || graphRenderTargets.ContainsKey(targetDescription.Handle.Name)) + { + continue; + } + + var targetSize = ResolveGraphTargetSize(targetDescription.Size); + var target = new D3D12RenderTarget( + device, + targetSize.Width, + targetSize.Height, + ToDxgiFormat(targetDescription.Format), + renderTargetViewArena.Allocate(), + null, + null, + allowUnorderedAccess: false, + new Color4(0.0f, 0.0f, 0.0f, 1.0f), + $"Aquarium D3D12 Graph Target {targetDescription.Handle.Name}"); + graphRenderTargets.Add(targetDescription.Handle.Name, target); + resourceRegistry.Add($"graph-target:{targetDescription.Handle.Name}", target); + } + } + + private void RemoveGraphRenderTargets() + { + foreach (var name in graphRenderTargets.Keys) + { + resourceRegistry.RemoveRenderTarget($"graph-target:{name}"); + } + } + + private void DisposeGraphRenderTargets() + { + foreach (var target in graphRenderTargets.Values) + { + target.Dispose(); + } + + graphRenderTargets.Clear(); + } + + private (int Width, int Height) ResolveGraphTargetSize(AquariumTargetSize size) + { + return size.Kind switch + { + AquariumTargetSizeKind.Fixed => (Math.Max(1, size.Width), Math.Max(1, size.Height)), + AquariumTargetSizeKind.MatchWindow => ( + Math.Max(1, (int)MathF.Ceiling(width * MathF.Max(size.Scale, 0.001f))), + Math.Max(1, (int)MathF.Ceiling(height * MathF.Max(size.Scale, 0.001f)))), + _ => throw new ArgumentOutOfRangeException(nameof(size), size.Kind, "Unsupported render target size policy."), + }; + } + + private static Format ToDxgiFormat(RenderFormat format) + { + return format switch + { + RenderFormat.R16Float => Format.R16_Float, + RenderFormat.Rgba16Float => Format.R16G16B16A16_Float, + RenderFormat.Bgra8Unorm => Format.B8G8R8A8_UNorm, + _ => throw new ArgumentOutOfRangeException(nameof(format), format, "Unsupported render target format."), + }; + } + + private static bool IsLegacyGraphTarget(string name) + { + return string.Equals(name, "grid-height", StringComparison.Ordinal) + || string.Equals(name, "scene", StringComparison.Ordinal) + || string.Equals(name, "scene-metadata", StringComparison.Ordinal) + || string.Equals(name, "scene-control", StringComparison.Ordinal); + } + private void RenderSceneAndPresent(D3D12PassContext context, FrameResources frameResources) { context.CommandList.BeginEvent("Scene Pass"); diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 05f2d4a..83516ff 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -3,6 +3,7 @@ {"timestamp":"2026-05-12T00:00:00+01:00","topic":"engine-client-boundary","lesson":"Aquarium.Engine is the native D3D12/window/render graph layer and must not accrete Epiphany frontend semantics. Aquarium.Epiphany is the client/runtime layer behind Aquarium.Engine.Contracts and should configure engine abstractions for cameras, targets, shaders, resources, and passes.","files":["docs/engine-client-boundary.md","src/Aquarium.Epiphany/Aquarium.Epiphany.csproj","src/Aquarium.Engine/Runtime/ClientRuntimeLoader.cs","state/memory.json","state/map.yaml"]} {"timestamp":"2026-05-12T00:00:00+01:00","topic":"epiphany-extraction-render-api-plan","lesson":"The next purification path is a small render graph API, not more renderer knobs: clients declare resources and passes, Aquarium owns D3D12 execution. Migrate in slices: freeze boundary, add Vortice-free descriptors, compile a minimal graph, convert presentation/bloom, move Epiphany body shaders and Grid policy to Aquarium.Epiphany, then replace AquariumFrame.","files":["docs/epiphany-extraction-render-api-plan.md","README.md","state/map.yaml","state/memory.json"]} {"timestamp":"2026-05-12T03:40:00+01:00","topic":"epiphany-render-policy-extraction","lesson":"Epiphany body shaders, Grid brush construction, body visual/light tables, and cursor projection moved behind Aquarium.Engine.Contracts. Aquarium.Engine now consumes AquariumRenderPlan and AquariumSceneState data and passes scripts/verify-boundaries.ps1 with no Epiphany role/client names in engine source.","files":["src/Aquarium.Engine.Contracts/Render/AquariumApp.cs","src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs","src/Aquarium.Epiphany/EpiphanyRenderPlan.cs","src/Aquarium.Epiphany/EpiphanySceneBuilder.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","scripts/verify-boundaries.ps1","state/memory.json","state/map.yaml"]} +{"timestamp":"2026-05-12T03:50:00+01:00","topic":"graph-target-allocation","lesson":"The render graph compiler now validates declared targets/passes and D3D12Renderer allocates non-legacy client-declared render targets through engine resource/descriptors, including resize rebuild. This is allocation only; full graph pass execution remains the next cut.","files":["src/Aquarium.Engine/Render/Graph/D3D12RenderGraphCompiler.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine.Contracts/Render/AquariumApp.cs","state/memory.json"]} {"timestamp":"2026-05-10T07:47:46+01:00","topic":"cursor-teardrop-sdf","lesson":"Use the MathWorld teardrop curve for the cursor profile with m=6, revolved into an SDF locator. Keep ripples as geometry, material as brass GGX metal, and avoid ambient fill.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json"],"source":"https://mathworld.wolfram.com/TeardropCurve.html"} {"timestamp":"2026-05-11T00:00:00+01:00","topic":"aquarium-focus-cut","lesson":"Runtime volumetrics, cloud/fog research, and the D3D11 scene renderer are shelved because they distract from Aquarium's Epiphany-client mission. Git history holds the experiment; live repo state should not preserve compatibility husks or dead guidance for removed medium settings.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine.Contracts/GraphicsSettings.cs","state/map.yaml","state/memory.json","state/scratch.md"]} {"timestamp":"2026-05-11T04:20:00+01:00","topic":"medium-froxel-purge","lesson":"Medium/froxel render targets, structured buffers, shader bindings, scene outputs, post history lanes, and medium debug paths were removed from the live D3D12 renderer. Future atmospheric or field transport work needs a new explicit pass contract rather than reviving shelved scaffolding.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","state/map.yaml","state/memory.json"]} diff --git a/state/memory.json b/state/memory.json index d92cc7b..f5c90c3 100644 --- a/state/memory.json +++ b/state/memory.json @@ -18,6 +18,7 @@ "Aquarium.Epiphany is the Epiphany client layer behind Aquarium.Engine.Contracts. It owns client runtime state, CultCache documents, CultNet interpretation, camera intent, and future render graph configuration against engine abstractions.", "The render API migration target is docs/epiphany-extraction-render-api-plan.md: clients declare render targets, cameras, shaders, passes, buffers, textures, and features through Vortice-free Aquarium contracts; Aquarium compiles that graph into D3D12 resources, descriptors, barriers, pipeline state, resize, shader reload, presentation, and debug inspection.", "Epiphany now declares its render plan, body shader manifest, body visual table, body light table, Grid brush list, and cursor projection through Aquarium.Engine.Contracts. Aquarium.Engine consumes those as data and must stay free of Epiphany role/client names; run scripts/verify-boundaries.ps1 to enforce that boundary.", + "D3D12Renderer now compiles an AquariumRenderPlan description and allocates non-legacy client-declared render targets through engine descriptor/resource machinery. Current legacy scene/Grid execution still needs to be replaced by graph pass execution.", "The host owns Win32 windowing, D3D12 rendering, input translation, and the client-runtime assembly boundary.", "D3D12 descriptor ownership stays explicit: static descriptors for long-lived views, per-frame transient descriptors reset only after fence wait, and whole-arena rebuilds on resize until real descriptor churn demands free lists.", "D3D12 previous-frame camera/Grid/time/cursor state is renderer-level temporal state, not per-swapchain-frame-resource state.",