diff --git a/docs/d3d12-best-practices-audit.md b/docs/d3d12-best-practices-audit.md index 6876a02..2df4dc3 100644 --- a/docs/d3d12-best-practices-audit.md +++ b/docs/d3d12-best-practices-audit.md @@ -5,10 +5,12 @@ The current D3D12 path is acceptable as a bring-up scaffold. It proves the right classes of machinery: per-frame command allocators, fence-protected reuse, shader-visible descriptors, persistent mapped constants, explicit render target -state, and an offscreen target path. +state, an offscreen target path, SRV sampling, UAV binding, and resize-safe +descriptor arena rebuild. -It is not yet a production renderer architecture. The next risk is letting -smoke-pass helpers become permanent resource policy by accident. +It is not yet a production renderer architecture. The next risk is porting real +passes without keeping D3D11 as the comparison target and without promoting the +resource graph beyond smoke-pass scaffolding. ## Good Current Decisions @@ -31,8 +33,14 @@ smoke-pass helpers become permanent resource policy by accident. target in a second fullscreen pass instead of copying it as an opaque resource. - Renderer calls receive current window dimensions, and the D3D12 backend can recreate swapchain buffers plus dependent smoke resources on resize. +- Resize waits for the GPU, disposes swapchain-dependent targets, rebuilds + static shader and RTV descriptor arenas, and then recreates backbuffer/smoke + descriptors from a clean ownership state. +- Render targets can create UAV descriptors. The D3D12 smoke pass binds a + transient per-frame UAV descriptor and writes a diagnostic target from the + pixel shader, proving CBV and UAV tables can share the active transient heap. - The D3D12 smoke path exercises shader compilation, root signature, PSO, - descriptor table, RTV binding, barriers, copy, and present. + descriptor table, RTV/UAV binding, barriers, copy, and present. ## Temporary Acceptable Debt @@ -40,9 +48,9 @@ smoke-pass helpers become permanent resource policy by accident. suballocation before the renderer owns many textures/buffers. - Descriptor arenas are still simple bump allocators. Add free lists or descriptor-table paging only when real resource churn demands it. -- Resize currently consumes new static/RTV descriptors from fixed bring-up - arenas and fails loudly if capacity runs out. Production resize should reclaim - or rebuild descriptor arenas deliberately. +- Static shader and RTV descriptor arenas rebuild wholesale on resize. This is + deliberately simple and correct for swapchain-dependent resources; add finer + free lists only when non-resize churn proves it needs them. - Upload ring is per-frame and reset after fence wait. It is not yet a global transient allocator with suballocation statistics or overflow diagnostics. - Backbuffer state is assumed. Wrap swapchain buffers in state-tracked frame @@ -55,8 +63,8 @@ smoke-pass helpers become permanent resource policy by accident. - Upload ring capacity policy and overflow reporting for real frame data. - Debug names for D3D12 resources, descriptors by owner, and command lists. -- Production descriptor reclamation/rebuild policy for resize and resource - churn. +- A real pass migration that uses the D3D12 resource helpers without cloning + smoke-pass-local policy. ## Rule diff --git a/docs/d3d12-migration.md b/docs/d3d12-migration.md index 363521d..87a5dfe 100644 --- a/docs/d3d12-migration.md +++ b/docs/d3d12-migration.md @@ -11,13 +11,18 @@ has feature parity. swapchain, RTV heap, per-backbuffer command allocators, command list, fence-backed present loop, shader-visible CBV/SRV/UAV descriptor arena, per-frame upload buffers, renderer-owned offscreen render target, fullscreen - root signature, and a smoke-test PSO. + root signature, diagnostic UAV target, and smoke-test PSO. - The D3D12 path currently draws a diagnostic fullscreen pass. It exists to prove backend lifecycle, shader compilation, root signature creation, descriptor-table binding, per-frame upload-ring constants, PSO creation, render target binding, tracked resource state transitions, - render-target-to-swapchain copy, named objects, command-list events, and draw - submission before real scene passes migrate. + render-target-to-swapchain copy, UAV binding from a transient descriptor, + named objects, command-list events, and draw submission before real scene + passes migrate. +- Resize waits for the GPU, releases swapchain-dependent resources, rebuilds + static shader/RTV descriptor arenas, then recreates backbuffer views and + dependent render targets. Descriptor exhaustion on resize is no longer a + bring-up policy. - `IAquariumRenderer` is the host boundary. The host should not learn backend internals as the D3D12 renderer grows teeth. - `docs/d3d12-best-practices-audit.md` and `research/d3d12/synthesis.md` @@ -27,8 +32,8 @@ has feature parity. 1. Keep D3D11 as the visual reference. 2. Move shared renderer contracts behind explicit backend-neutral types. -3. Add UAV creation paths and a production descriptor reclamation/rebuild policy - for resize/resource churn. +3. Port the first real read-only pass after preserving D3D11 as the reference + output. 4. Keep capacity diagnostics loud while the backend is still small enough to make mistakes obvious. 5. Port the existing passes in visible order: grid height, froxel volume, scene, diff --git a/src/Aquarium.Engine/Render/D3D12RenderTarget.cs b/src/Aquarium.Engine/Render/D3D12RenderTarget.cs index d58e067..54669aa 100644 --- a/src/Aquarium.Engine/Render/D3D12RenderTarget.cs +++ b/src/Aquarium.Engine/Render/D3D12RenderTarget.cs @@ -13,6 +13,7 @@ internal sealed class D3D12RenderTarget : IDisposable Format format, D3D12DescriptorSlot renderTargetView, D3D12DescriptorSlot? shaderResourceView, + D3D12DescriptorSlot? unorderedAccessView, Color4 clearColor, string name) { @@ -21,6 +22,13 @@ internal sealed class D3D12RenderTarget : IDisposable Format = format; RenderTargetView = renderTargetView; ShaderResourceView = shaderResourceView; + UnorderedAccessView = unorderedAccessView; + var resourceFlags = ResourceFlags.AllowRenderTarget; + if (unorderedAccessView.HasValue) + { + resourceFlags |= ResourceFlags.AllowUnorderedAccess; + } + var optimizedClear = new ClearValue(format, in clearColor); Resource = device.CreateCommittedResource( HeapType.Default, @@ -32,7 +40,7 @@ internal sealed class D3D12RenderTarget : IDisposable 1, 1, 0, - ResourceFlags.AllowRenderTarget), + resourceFlags), ResourceStates.PixelShaderResource, optimizedClear); Resource.Name = name; @@ -50,6 +58,11 @@ internal sealed class D3D12RenderTarget : IDisposable }, shaderResourceView.Value.Cpu); } + + if (unorderedAccessView.HasValue) + { + CreateUnorderedAccessView(device, unorderedAccessView.Value); + } } public ID3D12Resource Resource { get; } @@ -64,8 +77,24 @@ internal sealed class D3D12RenderTarget : IDisposable public D3D12DescriptorSlot? ShaderResourceView { get; } + public D3D12DescriptorSlot? UnorderedAccessView { get; } + public ResourceStates State { get; private set; } = ResourceStates.PixelShaderResource; + public void CreateUnorderedAccessView(ID3D12Device device, D3D12DescriptorSlot unorderedAccessView) + { + device.CreateUnorderedAccessView( + Resource, + null, + new UnorderedAccessViewDescription + { + Format = Format, + ViewDimension = UnorderedAccessViewDimension.Texture2D, + Texture2D = new Texture2DUnorderedAccessView(), + }, + unorderedAccessView.Cpu); + } + public void Transition(ID3D12GraphicsCommandList commandList, ResourceStates nextState) { if (State == nextState) diff --git a/src/Aquarium.Engine/Render/D3D12Renderer.cs b/src/Aquarium.Engine/Render/D3D12Renderer.cs index 32687b7..15605e4 100644 --- a/src/Aquarium.Engine/Render/D3D12Renderer.cs +++ b/src/Aquarium.Engine/Render/D3D12Renderer.cs @@ -20,8 +20,8 @@ public sealed class D3D12Renderer : IAquariumRenderer private readonly ID3D12CommandQueue commandQueue; private readonly IDXGISwapChain3 swapChain; private readonly D3D12ResourceRegistry resourceRegistry = new(); - private readonly D3D12DescriptorArena renderTargetViewArena; - private readonly D3D12DescriptorArena staticShaderDescriptorArena; + private D3D12DescriptorArena renderTargetViewArena; + private D3D12DescriptorArena staticShaderDescriptorArena; private readonly FrameResources[] frames = new FrameResources[BackBufferCount]; private readonly ID3D12GraphicsCommandList commandList; private readonly ID3D12RootSignature fullscreenRootSignature; @@ -30,6 +30,7 @@ public sealed class D3D12Renderer : IAquariumRenderer private readonly ID3D12Fence fence; private readonly AutoResetEvent fenceEvent = new(false); private D3D12RenderTarget smokeRenderTarget; + private D3D12RenderTarget diagnosticUavTarget; private Viewport viewport; private RawRect scissorRect; private int width; @@ -74,8 +75,8 @@ public sealed class D3D12Renderer : IAquariumRenderer swapChain = swapChain1.QueryInterface(); frameIndex = (int)swapChain.CurrentBackBufferIndex; - renderTargetViewArena = new D3D12DescriptorArena(device, DescriptorHeapType.RenderTargetView, 32, DescriptorHeapFlags.None, "Aquarium D3D12 RTV Arena"); - staticShaderDescriptorArena = new D3D12DescriptorArena(device, DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView, 64, DescriptorHeapFlags.ShaderVisible, "Aquarium D3D12 Static Shader Descriptor Arena"); + renderTargetViewArena = CreateRenderTargetViewArena(); + staticShaderDescriptorArena = CreateStaticShaderDescriptorArena(); for (var index = 0; index < frames.Length; index++) { frames[index] = CreateFrameResources(index); @@ -83,15 +84,17 @@ public sealed class D3D12Renderer : IAquariumRenderer CreateRenderTargetViews(); smokeRenderTarget = CreateSmokeRenderTarget(); + diagnosticUavTarget = CreateDiagnosticUavTarget(); commandList = device.CreateCommandList(0, CommandListType.Direct, frames[frameIndex].CommandAllocator, null); commandList.Name = "Aquarium D3D12 Graphics Command List"; commandList.Close(); ReportStartupProgress(startupProgress, "Creating D3D12 fullscreen smoke pipeline"); fullscreenRootSignature = CreateFullscreenRootSignature(); fullscreenRootSignature.Name = "Aquarium D3D12 Fullscreen Root Signature"; - smokePipelineState = CreateSmokePipelineState(shaderPath ?? Path.Combine(AppContext.BaseDirectory, SmokeShaderRelativePath)); + var smokeShaderPath = Path.Combine(AppContext.BaseDirectory, SmokeShaderRelativePath); + smokePipelineState = CreateSmokePipelineState(smokeShaderPath); smokePipelineState.Name = "Aquarium D3D12 Smoke Pipeline"; - copyPipelineState = CreateCopyPipelineState(shaderPath ?? Path.Combine(AppContext.BaseDirectory, SmokeShaderRelativePath)); + copyPipelineState = CreateCopyPipelineState(smokeShaderPath); copyPipelineState.Name = "Aquarium D3D12 Copy Pipeline"; viewport = new Viewport(0.0f, 0.0f, width, height); scissorRect = new RawRect(0, 0, width, height); @@ -151,6 +154,8 @@ public sealed class D3D12Renderer : IAquariumRenderer device.CreateConstantBufferView( new ConstantBufferViewDescription(smokeConstants.GpuVirtualAddress, smokeConstants.SizeInBytes), frameResources.SmokeConstantsDescriptor.Cpu); + frameResources.DiagnosticUavDescriptor = frameResources.TransientShaderDescriptors.Allocate(); + diagnosticUavTarget.CreateUnorderedAccessView(device, frameResources.DiagnosticUavDescriptor); frameResources.CommandAllocator.Reset(); commandList.Reset(frameResources.CommandAllocator, null); @@ -175,6 +180,7 @@ public sealed class D3D12Renderer : IAquariumRenderer copyPipelineState.Dispose(); smokePipelineState.Dispose(); fullscreenRootSignature.Dispose(); + diagnosticUavTarget.Dispose(); smokeRenderTarget.Dispose(); for (var index = 0; index < frames.Length; index++) { @@ -211,7 +217,9 @@ public sealed class D3D12Renderer : IAquariumRenderer } WaitForGpu(); + resourceRegistry.RemoveRenderTarget("diagnostic-uav-target"); resourceRegistry.RemoveRenderTarget("smoke-target"); + diagnosticUavTarget.Dispose(); smokeRenderTarget.Dispose(); for (var index = 0; index < frames.Length; index++) { @@ -221,17 +229,16 @@ public sealed class D3D12Renderer : IAquariumRenderer width = newWidth; height = newHeight; - if (renderTargetViewArena.Available < BackBufferCount + 1 || staticShaderDescriptorArena.Available < 1) - { - throw new InvalidOperationException( - "D3D12 resize exhausted fixed descriptor bring-up arenas. " + - $"{renderTargetViewArena.Describe()}; {staticShaderDescriptorArena.Describe()}"); - } + renderTargetViewArena.Dispose(); + staticShaderDescriptorArena.Dispose(); + renderTargetViewArena = CreateRenderTargetViewArena(); + staticShaderDescriptorArena = CreateStaticShaderDescriptorArena(); swapChain.ResizeBuffers(BackBufferCount, (uint)width, (uint)height, Format.B8G8R8A8_UNorm, SwapChainFlags.None).CheckError(); frameIndex = (int)swapChain.CurrentBackBufferIndex; CreateRenderTargetViews(); smokeRenderTarget = CreateSmokeRenderTarget(); + diagnosticUavTarget = CreateDiagnosticUavTarget(); 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()}"); @@ -246,12 +253,29 @@ public sealed class D3D12Renderer : IAquariumRenderer Format.B8G8R8A8_UNorm, renderTargetViewArena.Allocate(), staticShaderDescriptorArena.Allocate(), + null, new Color4(0.006f, 0.014f, 0.022f, 1.0f), "Aquarium D3D12 Smoke Target"); resourceRegistry.Add("smoke-target", target); return target; } + private D3D12RenderTarget CreateDiagnosticUavTarget() + { + var target = new D3D12RenderTarget( + device, + width, + height, + Format.R8G8B8A8_UNorm, + renderTargetViewArena.Allocate(), + null, + staticShaderDescriptorArena.Allocate(), + new Color4(0.0f, 0.0f, 0.0f, 1.0f), + "Aquarium D3D12 Diagnostic UAV Target"); + resourceRegistry.Add("diagnostic-uav-target", target); + return target; + } + private void ClearBackBuffer(D3D12PassContext context, AquariumFrame frame) { _ = frame; @@ -265,11 +289,13 @@ public sealed class D3D12Renderer : IAquariumRenderer try { smokeRenderTarget.Transition(context.CommandList, ResourceStates.RenderTarget); + diagnosticUavTarget.Transition(context.CommandList, ResourceStates.UnorderedAccess); context.CommandList.ClearRenderTargetView(smokeRenderTarget.RenderTargetView.Cpu, clearColor); context.CommandList.SetDescriptorHeaps(frames[frameIndex].TransientShaderDescriptors.Heap); context.CommandList.SetPipelineState(smokePipelineState); context.CommandList.SetGraphicsRootSignature(fullscreenRootSignature); context.CommandList.SetGraphicsRootDescriptorTable(0, frames[frameIndex].SmokeConstantsDescriptor.Gpu); + context.CommandList.SetGraphicsRootDescriptorTable(2, frames[frameIndex].DiagnosticUavDescriptor.Gpu); context.CommandList.RSSetViewports(viewport); context.CommandList.RSSetScissorRects(scissorRect); context.CommandList.OMSetRenderTargets(smokeRenderTarget.RenderTargetView.Cpu, null); @@ -291,7 +317,7 @@ public sealed class D3D12Renderer : IAquariumRenderer context.CommandList.SetDescriptorHeaps(staticShaderDescriptorArena.Heap); context.CommandList.SetPipelineState(copyPipelineState); context.CommandList.SetGraphicsRootSignature(fullscreenRootSignature); - context.CommandList.SetGraphicsRootDescriptorTable(0, sourceDescriptor.Gpu); + context.CommandList.SetGraphicsRootDescriptorTable(1, sourceDescriptor.Gpu); context.CommandList.RSSetViewports(viewport); context.CommandList.RSSetScissorRects(scissorRect); context.CommandList.OMSetRenderTargets(context.RenderTargetView, null); @@ -352,6 +378,26 @@ public sealed class D3D12Renderer : IAquariumRenderer Console.WriteLine(message); } + private D3D12DescriptorArena CreateRenderTargetViewArena() + { + return new D3D12DescriptorArena( + device, + DescriptorHeapType.RenderTargetView, + 32, + DescriptorHeapFlags.None, + "Aquarium D3D12 RTV Arena"); + } + + private D3D12DescriptorArena CreateStaticShaderDescriptorArena() + { + return new D3D12DescriptorArena( + device, + DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView, + 64, + DescriptorHeapFlags.ShaderVisible, + "Aquarium D3D12 Static Shader Descriptor Arena"); + } + private ID3D12RootSignature CreateFullscreenRootSignature() { var constantBufferRange = new DescriptorRange( @@ -366,10 +412,17 @@ public sealed class D3D12Renderer : IAquariumRenderer 0, 0, D3D12.DescriptorRangeOffsetAppend); + var diagnosticUavRange = new DescriptorRange( + DescriptorRangeType.UnorderedAccessView, + 1, + 1, + 0, + D3D12.DescriptorRangeOffsetAppend); var rootParameters = new[] { new RootParameter(new RootDescriptorTable([constantBufferRange]), ShaderVisibility.Pixel), new RootParameter(new RootDescriptorTable([sourceTextureRange]), ShaderVisibility.Pixel), + new RootParameter(new RootDescriptorTable([diagnosticUavRange]), ShaderVisibility.Pixel), }; var staticSamplers = new[] { @@ -469,6 +522,8 @@ public sealed class D3D12Renderer : IAquariumRenderer public D3D12DescriptorSlot SmokeConstantsDescriptor { get; set; } + public D3D12DescriptorSlot DiagnosticUavDescriptor { get; set; } + public D3D12TrackedResource BackBuffer { get; set; } = null!; public D3D12DescriptorSlot BackBufferRenderTargetView { get; set; } diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12Smoke.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12Smoke.hlsl index bc7f24b..3d1b8c0 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12Smoke.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12Smoke.hlsl @@ -11,6 +11,7 @@ cbuffer SmokeConstants : register(b0) }; Texture2D sourceTexture : register(t0); +RWTexture2D diagnosticUav : register(u1); SamplerState sourceSampler : register(s0); VertexOut FullscreenTriangleVS(uint vertexId : SV_VertexID) @@ -27,6 +28,7 @@ float4 D3D12SmokePS(VertexOut input) : SV_Target0 float3 baseColor = lerp(float3(0.012, 0.022, 0.032), smokeTint.rgb, input.uv.y); float vignette = smoothstep(0.86, 0.18, length(input.uv - 0.5)); float pulse = 0.92 + 0.08 * sin(smokeParams.x); + diagnosticUav[uint2(input.position.xy)] = float4(input.uv, smokeParams.y / 16.0, 1.0); return float4(baseColor * (0.72 + 0.28 * vignette) * pulse, 1.0); } diff --git a/state/evidence.jsonl b/state/evidence.jsonl index e7e6c07..145f3e9 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -68,3 +68,4 @@ {"area":"renderer/d3d12","lesson":"Full-ass D3D12 foundation pass added debug names, command-list events, tracked swapchain backbuffer states, and per-frame persistent-mapped upload rings. This moves current code closer to the researched doctrine: visible ownership, inspectable GPU captures, and fence-safe transient CPU-to-GPU data. Next remaining pre-pass work is static/transient descriptor separation, resource registry, resize-safe recreation, and capacity diagnostics.","files":["src/Aquarium.Engine/Render/D3D12TrackedResource.cs","src/Aquarium.Engine/Render/D3D12DescriptorArena.cs","src/Aquarium.Engine/Render/D3D12UploadRing.cs","src/Aquarium.Engine/Render/D3D12RenderTarget.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","docs/d3d12-best-practices-audit.md","docs/d3d12-migration.md","state/scratch.md"],"verification":["dotnet build src\\Aquarium.Engine\\Aquarium.Engine.csproj","Aquarium.Engine.exe --headless --renderer d3d12 exited 0 with tracked resources, events, and upload ring"],"ts":"2026-05-09"} {"area":"renderer/d3d12","lesson":"D3D12 now separates static shader descriptors from per-frame transient descriptor arenas, resets transient descriptors only after frame fence wait, registers named resources, and reports capacity for upload ring, transient/static shader descriptors, and RTV descriptors. Keep arenas simple until real churn demands free lists; avoid exact-fit capacities that leave no room for immediate next resources.","files":["src/Aquarium.Engine/Render/D3D12DescriptorArena.cs","src/Aquarium.Engine/Render/D3D12ResourceRegistry.cs","src/Aquarium.Engine/Render/D3D12UploadRing.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","docs/d3d12-best-practices-audit.md","docs/d3d12-migration.md","state/scratch.md"],"verification":["dotnet build src\\Aquarium.Engine\\Aquarium.Engine.csproj","Aquarium.Engine.exe --headless --renderer d3d12 exited 0 and printed resource registry plus capacity diagnostics"],"ts":"2026-05-09"} {"area":"renderer/d3d12","lesson":"D3D12 render targets now support SRV descriptors, and the smoke target is sampled by a second fullscreen pass instead of copied as an opaque resource. The renderer interface now receives current window dimensions, allowing D3D12 to recreate swapchain buffers and dependent smoke resources on resize. Resize still consumes fixed bring-up descriptors and fails loudly before exhaustion; production descriptor reclamation/rebuild policy is still needed before serious pass migration.","files":["src/Aquarium.Engine/Render/IAquariumRenderer.cs","src/Aquarium.Engine/AquariumHost.cs","src/Aquarium.Engine/Render/D3D11Renderer.cs","src/Aquarium.Engine/Render/D3D12RenderTarget.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Smoke.hlsl","docs/d3d12-best-practices-audit.md","docs/d3d12-migration.md","state/scratch.md"],"verification":["dotnet build src\\Aquarium.Engine\\Aquarium.Engine.csproj","Aquarium.Engine.exe --headless --renderer d3d12 exited 0 with SRV copy/display pass and capacity diagnostics"],"ts":"2026-05-09"} +{"area":"renderer/d3d12","lesson":"D3D12 render targets now support UAV descriptors, and the smoke pass proves a transient per-frame UAV table by writing a diagnostic texture from the pixel shader. Pixel shader UAV registers share the render-target output namespace, so the first manual UAV must bind at u1 when SV_Target0 is present. Resize now waits for the GPU, releases swapchain-dependent resources, rebuilds static shader/RTV descriptor arenas, and recreates descriptors from a clean state instead of burning fixed slots. The D3D12 backend also ignores the D3D11 shader-source override and compiles its copied D3D12Smoke.hlsl.","files":["src/Aquarium.Engine/Render/D3D12RenderTarget.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Smoke.hlsl","docs/d3d12-best-practices-audit.md","docs/d3d12-migration.md","state/memory.json","state/map.yaml","state/scratch.md"],"verification":["dotnet build src\\Aquarium.Engine\\Aquarium.Engine.csproj",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 -HeadlessTimeoutSeconds 20 with AQUARIUM_RENDERER=d3d12 exited 0 and printed UAV/static/transient capacity diagnostics"],"ts":"2026-05-09"} diff --git a/state/map.yaml b/state/map.yaml index 8e4e1d2..26f0742 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -64,8 +64,10 @@ renderer_state: - Direct2D/DirectWrite debug UI panel with code-first controls bound to renderer state. - Global GraphicsSettings document feeding render debug, exposure, bloom intensity, bloom veil, and medium composite intensity. - First field instance structured buffer feeding a half-resolution registered medium diagnostic/transport pass. + - Parallel D3D12 scaffold behind IAquariumRenderer proving device/queue/swapchain, per-frame command allocators, fences, static/transient descriptor arenas, upload ring constants, RTV/SRV/UAV render targets, tracked barriers, command events, and resize descriptor-arena rebuild. - Splash screen with bundled app icon and GameCult typefaces. next: + - Port the first real D3D11 reference pass into D3D12 without cloning smoke-pass-local policy. - Promote field instances from fixed renderer table to a CPU-owned registry with per-field debug controls. - Extend explicit renderer debug modes for hits, normals, depth, bins, and lighting. - Restore HDR scene target, gentle pre-tonemap bloom, and ACES as explicit passes. diff --git a/state/memory.json b/state/memory.json index adb6f84..5654e88 100644 --- a/state/memory.json +++ b/state/memory.json @@ -15,6 +15,9 @@ "native_engine": [ "Aquarium Engine lives at E:\\Projects\\Aquarium-Engine and is the live C# line. Main is the development branch after the 2026-05-08 merge.", "The host owns Win32 windowing, D3D11 swapchain creation, shader compilation, input translation, and the live-runtime assembly boundary. Do not outsource the core frame protocol to a hidden framework loop.", + "D3D12 is being added beside D3D11, not by mutating the reference renderer in place. Keep descriptor ownership explicit: static descriptors for long-lived SRV/UAV tables, per-frame transient descriptors reset only after fence wait, and whole-arena rebuilds on resize until real non-resize churn demands free lists.", + "D3D12 pixel shader UAV registers share the output namespace. If a shader writes SV_Target0, bind the first manual UAV at u1, not u0.", + "D3D12 shader routing must not inherit the D3D11 --shader-source override by accident. Backend-specific HLSL should compile from its copied output path unless an explicit backend-specific override exists.", "Use Vortice at the graphics API membrane. Keep CultMath as the CPU math grammar. Do not let third-party math opinions leak inward unless the conversion is explicit.", "The renderer currently uses a fullscreen HLSL path. Traditional geometry is allowed only as scaffolding; the visible Aquarium world should be shader-owned." ], diff --git a/state/scratch.md b/state/scratch.md index fad30c9..c680b71 100644 --- a/state/scratch.md +++ b/state/scratch.md @@ -8,9 +8,11 @@ backend with device/queue/swapchain/RTV heap/per-frame command allocators/fence, plus a shader-visible descriptor arena, per-frame upload constant buffers, renderer-owned offscreen render target, fullscreen root signature, and smoke-test PSO that draws a diagnostic fullscreen triangle into the offscreen -target before copying to the swapchain. Next renderer work should generalize -this into SRV/UAV creation and resize-safe resource recreation before building -the stochastic transparent surface pipe. +target before sampling it back to the swapchain. Render targets now support +SRV/UAV descriptors, the smoke pass writes a diagnostic UAV through a per-frame +transient descriptor, and resize rebuilds static shader/RTV descriptor arenas +after a GPU wait instead of consuming fixed bring-up slots. Next renderer work +can start porting real passes while keeping D3D11 as the visual reference. ## Hot Context @@ -256,3 +258,11 @@ the stochastic transparent surface pipe. still consumes fixed bring-up descriptors and fails loudly before exhaustion; production descriptor reclamation/rebuild policy remains before serious pass migration. +- D3D12 UAV/resize-rebuild pass: render targets can own UAV descriptors, the + D3D12 smoke pass binds a transient per-frame UAV descriptor and writes a + diagnostic target from the pixel shader. Pixel shader UAVs share output + register namespace, so the diagnostic UAV binds at `u1` rather than `u0`. + D3D12 ignores the D3D11 `--shader-source` override and compiles its own copied + `D3D12Smoke.hlsl`. Resize now waits for the GPU, releases swapchain-dependent + resources, rebuilds static shader/RTV descriptor arenas, and recreates + backbuffer/smoke/diagnostic resources from a clean descriptor state.