diff --git a/docs/d3d12-best-practices-audit.md b/docs/d3d12-best-practices-audit.md index b7e6d17..14c45b3 100644 --- a/docs/d3d12-best-practices-audit.md +++ b/docs/d3d12-best-practices-audit.md @@ -5,8 +5,8 @@ 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, an offscreen target path, SRV sampling, UAV binding, and resize-safe -descriptor arena rebuild. +state, a migrated Grid height pass, 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 porting real passes without keeping D3D11 as the comparison target and without promoting the @@ -31,6 +31,9 @@ resource graph beyond smoke-pass scaffolding. transient descriptor, static descriptor, and RTV usage. - Render targets may create SRVs, and the smoke path now samples its offscreen target in a second fullscreen pass instead of copying it as an opaque resource. +- D3D12 compiles the real `GridHeightPS` from `Aquarium.hlsl`, uploads the + Aquarium frame constants, renders a fixed 128x128 float Grid height target, + and exposes that target through render debug mode `11`. - 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 @@ -55,8 +58,6 @@ resource graph beyond smoke-pass scaffolding. 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 - resources before resize and multi-pass presentation. - The offscreen smoke target copies to the swapchain. Keep this only if the real post-process graph needs it; otherwise present from the final render target path with no ornamental copy. @@ -65,8 +66,8 @@ resource graph beyond smoke-pass scaffolding. - Upload ring capacity policy and overflow reporting for real frame data. - Descriptor-owner diagnostics beyond heap-level capacity summaries. -- A real pass migration that uses the D3D12 resource helpers without cloning - smoke-pass-local policy. +- Continue pass migration without cloning smoke-pass-local policy into each + resource. ## Rule diff --git a/docs/d3d12-migration.md b/docs/d3d12-migration.md index 87a5dfe..ab2dd0a 100644 --- a/docs/d3d12-migration.md +++ b/docs/d3d12-migration.md @@ -10,8 +10,8 @@ has feature parity. - `--renderer d3d12` creates a D3D12 device, command queue, flip-discard 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, diagnostic UAV target, and smoke-test PSO. + per-frame upload buffers, renderer-owned Grid height target, offscreen smoke + target, fullscreen 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, @@ -19,6 +19,10 @@ has feature parity. render-target-to-swapchain copy, UAV binding from a transient descriptor, named objects, command-list events, and draw submission before real scene passes migrate. +- The first real migrated pass is the Grid height pass. D3D12 compiles + `GridHeightPS` from `Aquarium.hlsl`, uploads the Aquarium frame constants, + renders a 128x128 `R32G32B32A32_Float` Grid height target, and can display it + through render debug mode `11`. - 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 @@ -32,8 +36,7 @@ has feature parity. 1. Keep D3D11 as the visual reference. 2. Move shared renderer contracts behind explicit backend-neutral types. -3. Port the first real read-only pass after preserving D3D11 as the reference - output. +3. Port the Grid height 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/docs/hlsl-renderer.md b/docs/hlsl-renderer.md index faa9e35..04349ec 100644 --- a/docs/hlsl-renderer.md +++ b/docs/hlsl-renderer.md @@ -75,6 +75,13 @@ Current frame order: tonemapping, and raymarching unless a specific diegetic surface asks for the trouble. +The D3D12 backend has begun migrating this order with the same Grid height pass: +it compiles `GridHeightPS` from `Aquarium.hlsl`, uploads the Aquarium frame +constant buffer through the D3D12 upload ring, renders a 128x128 +`R32G32B32A32_Float` Grid height target, and can display that target with D3D12 +render debug mode `11`. D3D11 remains the visual reference until the full pass +chain reaches parity. + The shader far distance is frame-derived, not a fixed constant. C# sends the distance from the camera to the Grid origin plus the Grid radius, which matches the circular Grid fade boundary and avoids wasting raymarch work past the diff --git a/src/Aquarium.Engine/Render/D3D12Renderer.cs b/src/Aquarium.Engine/Render/D3D12Renderer.cs index 3c879e6..840c0e6 100644 --- a/src/Aquarium.Engine/Render/D3D12Renderer.cs +++ b/src/Aquarium.Engine/Render/D3D12Renderer.cs @@ -7,12 +7,15 @@ using Vortice.Direct3D12; using Vortice.DXGI; using Vortice.Mathematics; using System.Numerics; +using System.Runtime.InteropServices; namespace Aquarium.Engine.Render; public sealed class D3D12Renderer : IAquariumRenderer { private const int BackBufferCount = 2; + private const int GridHeightTextureSize = 128; + private const string AquariumShaderRelativePath = "Render/Shaders/Aquarium.hlsl"; private const string SmokeShaderRelativePath = "Render/Shaders/D3D12Smoke.hlsl"; private readonly IDXGIFactory4 factory; @@ -25,10 +28,13 @@ public sealed class D3D12Renderer : IAquariumRenderer private readonly FrameResources[] frames = new FrameResources[BackBufferCount]; private readonly ID3D12GraphicsCommandList commandList; private readonly ID3D12RootSignature fullscreenRootSignature; + private readonly ID3D12PipelineState gridHeightPipelineState; private readonly ID3D12PipelineState smokePipelineState; private readonly ID3D12PipelineState copyPipelineState; + private readonly ID3D12PipelineState gridHeightDebugPipelineState; private readonly ID3D12Fence fence; private readonly AutoResetEvent fenceEvent = new(false); + private D3D12RenderTarget gridHeightRenderTarget; private D3D12RenderTarget smokeRenderTarget; private D3D12RenderTarget diagnosticUavTarget; private Viewport viewport; @@ -36,7 +42,12 @@ public sealed class D3D12Renderer : IAquariumRenderer private int width; private int height; private ulong fenceValue; + private int temporalFrameIndex; private int frameIndex; + private Vector3 previousCameraPosition; + private Vector2 previousGridCenter; + private float previousGridRadius = 0.001f; + private float previousTimeSeconds; private GraphicsSettings settings = GraphicsSettings.Default; private bool debugUiVisible = true; @@ -83,6 +94,7 @@ public sealed class D3D12Renderer : IAquariumRenderer } CreateRenderTargetViews(); + gridHeightRenderTarget = CreateGridHeightRenderTarget(); smokeRenderTarget = CreateSmokeRenderTarget(); diagnosticUavTarget = CreateDiagnosticUavTarget(); commandList = device.CreateCommandList(0, CommandListType.Direct, frames[frameIndex].CommandAllocator, null); @@ -91,11 +103,16 @@ public sealed class D3D12Renderer : IAquariumRenderer ReportStartupProgress(startupProgress, "Creating D3D12 fullscreen smoke pipeline"); fullscreenRootSignature = CreateFullscreenRootSignature(); fullscreenRootSignature.Name = "Aquarium D3D12 Fullscreen Root Signature"; + var aquariumShaderPath = Path.Combine(AppContext.BaseDirectory, AquariumShaderRelativePath); var smokeShaderPath = Path.Combine(AppContext.BaseDirectory, SmokeShaderRelativePath); + gridHeightPipelineState = CreateGridHeightPipelineState(aquariumShaderPath); + gridHeightPipelineState.Name = "Aquarium D3D12 Grid Height Pipeline"; smokePipelineState = CreateSmokePipelineState(smokeShaderPath); smokePipelineState.Name = "Aquarium D3D12 Smoke Pipeline"; copyPipelineState = CreateCopyPipelineState(smokeShaderPath); copyPipelineState.Name = "Aquarium D3D12 Copy Pipeline"; + gridHeightDebugPipelineState = CreateGridHeightDebugPipelineState(smokeShaderPath); + gridHeightDebugPipelineState.Name = "Aquarium D3D12 Grid Height Debug Pipeline"; viewport = new Viewport(0.0f, 0.0f, width, height); scissorRect = new RawRect(0, 0, width, height); fence = device.CreateFence(0); @@ -143,6 +160,42 @@ public sealed class D3D12Renderer : IAquariumRenderer WaitForFrame(frameResources); frameResources.UploadRing.Reset(); frameResources.TransientShaderDescriptors.Reset(); + var gridOrigin = new Vector3(frame.Grid.Center.X, frame.Grid.Center.Y, 0.0f); + var farDistance = Vector3.Distance(frame.CameraPosition, gridOrigin) + MathF.Max(frame.Grid.Radius, 0.001f); + if (temporalFrameIndex == 0) + { + previousCameraPosition = frame.CameraPosition; + previousGridCenter = frame.Grid.Center; + previousGridRadius = frame.Grid.Radius; + previousTimeSeconds = frame.TimeSeconds; + } + + var frameConstants = frameResources.UploadRing.WriteConstant(new FrameConstants( + new Vector2(width, height), + frame.TimeSeconds, + frame.Grid.Radius, + frame.CameraPosition, + farDistance, + frame.Grid.Center, + temporalFrameIndex, + previousTimeSeconds, + previousCameraPosition, + previousGridRadius, + previousGridCenter, + Vector2.Zero, + Vector2.Zero, + RenderDebugMode, + settings.SceneExposure, + settings.BloomIntensity, + settings.BloomVeilIntensity, + settings.MediumCompositeIntensity, + settings.MediumDebugStep, + Vector3.Zero)); + frameResources.FrameConstantsDescriptor = frameResources.TransientShaderDescriptors.Allocate(); + device.CreateConstantBufferView( + new ConstantBufferViewDescription(frameConstants.GpuVirtualAddress, frameConstants.SizeInBytes), + frameResources.FrameConstantsDescriptor.Cpu); + var smokeConstants = frameResources.UploadRing.WriteConstant(new SmokeConstants( new Vector4( 0.020f + settings.SceneExposure * 0.08f, @@ -160,6 +213,7 @@ public sealed class D3D12Renderer : IAquariumRenderer commandList.Reset(frameResources.CommandAllocator, null); commandList.BeginEvent("Aquarium D3D12 Frame"); + RenderGridHeight(commandList, frameResources); ClearBackBuffer(new D3D12PassContext(commandList, frameResources.BackBuffer, frameResources.BackBufferRenderTargetView.Cpu), frame); commandList.EndEvent(); commandList.Close(); @@ -168,6 +222,11 @@ public sealed class D3D12Renderer : IAquariumRenderer swapChain.Present(1, PresentFlags.None); SignalFrame(frameResources); ReportCapacityOncePerSecond(frame.TimeSeconds, frameResources); + previousCameraPosition = frame.CameraPosition; + previousGridCenter = frame.Grid.Center; + previousGridRadius = frame.Grid.Radius; + previousTimeSeconds = frame.TimeSeconds; + temporalFrameIndex++; frameIndex = (int)swapChain.CurrentBackBufferIndex; } @@ -177,11 +236,14 @@ public sealed class D3D12Renderer : IAquariumRenderer fenceEvent.Dispose(); fence.Dispose(); commandList.Dispose(); + gridHeightDebugPipelineState.Dispose(); copyPipelineState.Dispose(); smokePipelineState.Dispose(); + gridHeightPipelineState.Dispose(); fullscreenRootSignature.Dispose(); diagnosticUavTarget.Dispose(); smokeRenderTarget.Dispose(); + gridHeightRenderTarget.Dispose(); for (var index = 0; index < frames.Length; index++) { frames[index].Dispose(); @@ -219,8 +281,10 @@ public sealed class D3D12Renderer : IAquariumRenderer WaitForGpu(); resourceRegistry.RemoveRenderTarget("diagnostic-uav-target"); resourceRegistry.RemoveRenderTarget("smoke-target"); + resourceRegistry.RemoveRenderTarget("grid-height-target"); diagnosticUavTarget.Dispose(); smokeRenderTarget.Dispose(); + gridHeightRenderTarget.Dispose(); for (var index = 0; index < frames.Length; index++) { resourceRegistry.RemoveResource($"backbuffer-{index}"); @@ -237,6 +301,7 @@ public sealed class D3D12Renderer : IAquariumRenderer swapChain.ResizeBuffers(BackBufferCount, (uint)width, (uint)height, Format.B8G8R8A8_UNorm, SwapChainFlags.None).CheckError(); frameIndex = (int)swapChain.CurrentBackBufferIndex; CreateRenderTargetViews(); + gridHeightRenderTarget = CreateGridHeightRenderTarget(); smokeRenderTarget = CreateSmokeRenderTarget(); diagnosticUavTarget = CreateDiagnosticUavTarget(); viewport = new Viewport(0.0f, 0.0f, width, height); @@ -261,6 +326,23 @@ public sealed class D3D12Renderer : IAquariumRenderer return target; } + private D3D12RenderTarget CreateGridHeightRenderTarget() + { + var target = new D3D12RenderTarget( + device, + GridHeightTextureSize, + GridHeightTextureSize, + Format.R32G32B32A32_Float, + renderTargetViewArena.Allocate(), + staticShaderDescriptorArena.Allocate(), + null, + false, + new Color4(0.0f, 0.0f, 0.0f, 1.0f), + "Aquarium D3D12 Grid Height Target"); + resourceRegistry.Add("grid-height-target", target); + return target; + } + private D3D12RenderTarget CreateDiagnosticUavTarget() { var target = new D3D12RenderTarget( @@ -312,12 +394,16 @@ public sealed class D3D12Renderer : IAquariumRenderer context.CommandList.BeginEvent("Copy Smoke Target To Swapchain"); try { - var sourceDescriptor = smokeRenderTarget.ShaderResourceView - ?? throw new InvalidOperationException("Smoke target was created without an SRV."); + var showGridHeight = RenderDebugMode == 11; + var sourceTarget = showGridHeight ? gridHeightRenderTarget : smokeRenderTarget; + var sourceDescriptor = sourceTarget.ShaderResourceView + ?? throw new InvalidOperationException($"{sourceTarget.Resource.Name} was created without an SRV."); + var presentPipelineState = showGridHeight ? gridHeightDebugPipelineState : copyPipelineState; smokeRenderTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource); + sourceTarget.Transition(context.CommandList, ResourceStates.PixelShaderResource); context.BackBuffer.Transition(context.CommandList, ResourceStates.RenderTarget); context.CommandList.SetDescriptorHeaps(staticShaderDescriptorArena.Heap); - context.CommandList.SetPipelineState(copyPipelineState); + context.CommandList.SetPipelineState(presentPipelineState); context.CommandList.SetGraphicsRootSignature(fullscreenRootSignature); context.CommandList.SetGraphicsRootDescriptorTable(1, sourceDescriptor.Gpu); context.CommandList.RSSetViewports(viewport); @@ -333,6 +419,32 @@ public sealed class D3D12Renderer : IAquariumRenderer } } + private void RenderGridHeight(ID3D12GraphicsCommandList activeCommandList, FrameResources frameResources) + { + var viewport = new Viewport(0.0f, 0.0f, GridHeightTextureSize, GridHeightTextureSize); + var scissorRect = new RawRect(0, 0, GridHeightTextureSize, GridHeightTextureSize); + + activeCommandList.BeginEvent("Grid Height Pass"); + try + { + gridHeightRenderTarget.Transition(activeCommandList, ResourceStates.RenderTarget); + activeCommandList.ClearRenderTargetView(gridHeightRenderTarget.RenderTargetView.Cpu, new Color4(0.0f, 0.0f, 0.0f, 1.0f)); + activeCommandList.SetDescriptorHeaps(frameResources.TransientShaderDescriptors.Heap); + activeCommandList.SetPipelineState(gridHeightPipelineState); + activeCommandList.SetGraphicsRootSignature(fullscreenRootSignature); + activeCommandList.SetGraphicsRootDescriptorTable(0, frameResources.FrameConstantsDescriptor.Gpu); + activeCommandList.RSSetViewports(viewport); + activeCommandList.RSSetScissorRects(scissorRect); + activeCommandList.OMSetRenderTargets(gridHeightRenderTarget.RenderTargetView.Cpu, null); + activeCommandList.IASetPrimitiveTopology(PrimitiveTopology.TriangleList); + activeCommandList.DrawInstanced(3, 1, 0, 0); + } + finally + { + activeCommandList.EndEvent(); + } + } + private void SignalFrame(FrameResources frameResources) { var signalValue = ++fenceValue; @@ -454,29 +566,28 @@ public sealed class D3D12Renderer : IAquariumRenderer private ID3D12PipelineState CreateSmokePipelineState(string path) { - var vertexShader = CompileShader(path, "FullscreenTriangleVS", "vs_5_0"); - var pixelShader = CompileShader(path, "D3D12SmokePS", "ps_5_0"); - var description = new GraphicsPipelineStateDescription - { - RootSignature = fullscreenRootSignature, - VertexShader = vertexShader, - PixelShader = pixelShader, - BlendState = BlendDescription.Opaque, - RasterizerState = RasterizerDescription.CullNone, - DepthStencilState = DepthStencilDescription.None, - SampleMask = uint.MaxValue, - PrimitiveTopologyType = PrimitiveTopologyType.Triangle, - RenderTargetFormats = [Format.B8G8R8A8_UNorm], - SampleDescription = new SampleDescription(1, 0), - }; - - return device.CreateGraphicsPipelineState(description); + return CreateFullscreenPipelineState(path, "FullscreenTriangleVS", "D3D12SmokePS", Format.B8G8R8A8_UNorm); } private ID3D12PipelineState CreateCopyPipelineState(string path) { - var vertexShader = CompileShader(path, "FullscreenTriangleVS", "vs_5_0"); - var pixelShader = CompileShader(path, "D3D12CopyPS", "ps_5_0"); + return CreateFullscreenPipelineState(path, "FullscreenTriangleVS", "D3D12CopyPS", Format.B8G8R8A8_UNorm); + } + + private ID3D12PipelineState CreateGridHeightDebugPipelineState(string path) + { + return CreateFullscreenPipelineState(path, "FullscreenTriangleVS", "D3D12GridHeightDebugPS", Format.B8G8R8A8_UNorm); + } + + private ID3D12PipelineState CreateGridHeightPipelineState(string path) + { + return CreateFullscreenPipelineState(path, "FullscreenTriangleVS", "GridHeightPS", Format.R32G32B32A32_Float); + } + + private ID3D12PipelineState CreateFullscreenPipelineState(string path, string vertexEntryPoint, string pixelEntryPoint, Format renderTargetFormat) + { + var vertexShader = CompileShader(path, vertexEntryPoint, "vs_5_0"); + var pixelShader = CompileShader(path, pixelEntryPoint, "ps_5_0"); var description = new GraphicsPipelineStateDescription { RootSignature = fullscreenRootSignature, @@ -487,7 +598,7 @@ public sealed class D3D12Renderer : IAquariumRenderer DepthStencilState = DepthStencilDescription.None, SampleMask = uint.MaxValue, PrimitiveTopologyType = PrimitiveTopologyType.Triangle, - RenderTargetFormats = [Format.B8G8R8A8_UNorm], + RenderTargetFormats = [renderTargetFormat], SampleDescription = new SampleDescription(1, 0), }; @@ -509,8 +620,32 @@ public sealed class D3D12Renderer : IAquariumRenderer D3D12TrackedResource BackBuffer, CpuDescriptorHandle RenderTargetView); + [StructLayout(LayoutKind.Sequential)] private readonly record struct SmokeConstants(Vector4 Tint, Vector4 Params); + [StructLayout(LayoutKind.Sequential)] + private readonly record struct FrameConstants( + Vector2 Resolution, + float TimeSeconds, + float GridRadius, + Vector3 CameraPosition, + float FarDistance, + Vector2 GridCenter, + float FrameIndex, + float PreviousTimeSeconds, + Vector3 PreviousCameraPosition, + float PreviousGridRadius, + Vector2 PreviousGridCenter, + Vector2 JitterPixels, + Vector2 PreviousJitterPixels, + float RenderDebugMode, + float Exposure, + float BloomIntensity, + float BloomVeilIntensity, + float MediumCompositeIntensity, + float MediumDebugStep, + Vector3 PresentationPadding); + private sealed class FrameResources( ID3D12CommandAllocator commandAllocator, D3D12UploadRing uploadRing, @@ -522,6 +657,8 @@ public sealed class D3D12Renderer : IAquariumRenderer public D3D12DescriptorArena TransientShaderDescriptors { get; } = transientShaderDescriptors; + public D3D12DescriptorSlot FrameConstantsDescriptor { get; set; } + public D3D12DescriptorSlot SmokeConstantsDescriptor { get; set; } public D3D12DescriptorSlot DiagnosticUavDescriptor { get; set; } diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12Smoke.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12Smoke.hlsl index 3d1b8c0..11e0a0a 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12Smoke.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12Smoke.hlsl @@ -36,3 +36,13 @@ float4 D3D12CopyPS(VertexOut input) : SV_Target0 { return sourceTexture.SampleLevel(sourceSampler, input.uv, 0.0); } + +float4 D3D12GridHeightDebugPS(VertexOut input) : SV_Target0 +{ + float height = sourceTexture.SampleLevel(sourceSampler, input.uv, 0.0).r; + float signedShape = saturate(abs(height) * 0.85); + float3 negative = float3(0.08, 0.34, 0.52); + float3 positive = float3(0.95, 0.62, 0.22); + float3 baseColor = height < 0.0 ? negative : positive; + return float4(baseColor * signedShape, 1.0); +} diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 5baec85..86f38b7 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -70,3 +70,4 @@ {"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"} {"area":"renderer/d3d12","lesson":"D3D12 resource capability must remain separate from descriptor ownership. A texture can be created with AllowUnorderedAccess for transient UAV views without allocating a persistent static UAV descriptor. The diagnostic UAV target now uses a transient per-frame UAV descriptor only, reducing static heap use and keeping descriptor ownership honest before real pass migration.","files":["src/Aquarium.Engine/Render/D3D12RenderTarget.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","research/d3d12/synthesis.md","docs/d3d12-best-practices-audit.md","state/memory.json","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx", ".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 -HeadlessTimeoutSeconds 20 with AQUARIUM_RENDERER=d3d12 exited 0 and static shader descriptors dropped to 1/64"],"ts":"2026-05-09"} +{"area":"renderer/d3d12","lesson":"The first real D3D12 pass migration is Grid height: compile GridHeightPS from Aquarium.hlsl, upload the Aquarium frame constants through the D3D12 upload ring, render a 128x128 R32G32B32A32_Float Grid height target, and expose it through D3D12 render debug mode 11. Keep temporal previous camera/Grid/time as renderer-level state; swapchain frame resources are allocator reuse buckets, not frame-history state.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Smoke.hlsl","docs/d3d12-migration.md","docs/d3d12-best-practices-audit.md","docs/hlsl-renderer.md","state/map.yaml","state/memory.json","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 -HeadlessTimeoutSeconds 20 with AQUARIUM_RENDERER=d3d12 and AQUARIUM_RENDER_DEBUG_MODE=11 exited 0",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4 -HeadlessTimeoutSeconds 20 with AQUARIUM_RENDERER=d3d12 and AQUARIUM_RENDER_DEBUG_MODE=0 exited 0"],"ts":"2026-05-09"} diff --git a/state/map.yaml b/state/map.yaml index 26f0742..d6c49ce 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -64,10 +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. + - 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, resize descriptor-arena rebuild, and the first migrated Grid height pass. - 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. + - Port the froxel/field resource upload path 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 518def9..4e097b7 100644 --- a/state/memory.json +++ b/state/memory.json @@ -16,6 +16,7 @@ "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. Resource capability flags are not descriptor ownership; do not burn static UAV descriptors just to allow a transient UAV view.", + "D3D12 previous-frame camera/Grid/time state must be renderer-level temporal state, not per-swapchain-frame-resource state. The swapchain image index is an allocator/reuse index, not frame history.", "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.", diff --git a/state/scratch.md b/state/scratch.md index 4984ab8..0584769 100644 --- a/state/scratch.md +++ b/state/scratch.md @@ -269,3 +269,10 @@ can start porting real passes while keeping D3D11 as the visual reference. `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. +- D3D12 Grid height migration pass: the backend now compiles `GridHeightPS` + from `Aquarium.hlsl`, uploads the Aquarium frame constants through the + per-frame upload ring, renders a 128x128 `R32G32B32A32_Float` Grid height + target, and displays it in render debug mode `11`. Temporal previous + camera/Grid/time state is renderer-level state, not swapchain-frame-resource + state; swapchain image index is not frame history. Next D3D12 migration step + is the froxel/field resource upload path.