diff --git a/src/Aquarium.Engine.Contracts/Render/AquariumApp.cs b/src/Aquarium.Engine.Contracts/Render/AquariumApp.cs index a2d6606..05288e6 100644 --- a/src/Aquarium.Engine.Contracts/Render/AquariumApp.cs +++ b/src/Aquarium.Engine.Contracts/Render/AquariumApp.cs @@ -144,6 +144,12 @@ public sealed class AquariumShaderBuilder(AquariumShaderManifest manifest) return this; } + public AquariumShaderBuilder FractalReservoir(string path) + { + manifest.FractalReservoir(path); + return this; + } + public AquariumShaderBuilder Include(string path) { manifest.Include(path); diff --git a/src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs b/src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs index f6c648b..294ed0c 100644 --- a/src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs +++ b/src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs @@ -31,6 +31,8 @@ public sealed class AquariumShaderManifest public string LocalCastFusionShader { get; private set; } = "D3D12LocalCastFusion.hlsl"; + public string FractalReservoirShader { get; private set; } = "D3D12FractalReservoirCompute.hlsl"; + public string PostShader { get; private set; } = "D3D12Post.hlsl"; public string SdfCommonInclude { get; private set; } = "D3D12SdfCommon.hlsli"; @@ -75,6 +77,12 @@ public sealed class AquariumShaderManifest return this; } + public AquariumShaderManifest FractalReservoir(string path) + { + FractalReservoirShader = path; + return this; + } + public AquariumShaderManifest Post(string path) { PostShader = path; diff --git a/src/Aquarium.Engine/Render/D3D12Renderer.cs b/src/Aquarium.Engine/Render/D3D12Renderer.cs index 303c17d..5881b5a 100644 --- a/src/Aquarium.Engine/Render/D3D12Renderer.cs +++ b/src/Aquarium.Engine/Render/D3D12Renderer.cs @@ -1,4 +1,5 @@ using Aquarium.Engine.Audio; +using Aquarium.Engine.Fractal; using Aquarium.Engine.Input; using Aquarium.Engine.Render.Features; using Aquarium.Engine.Render.Graph; @@ -65,6 +66,11 @@ public sealed class D3D12Renderer : IAquariumRenderer private const int RootFusionAcousticConstraints = 4; private const int RootFusionOutput = 5; private const int RootFusionNativePoints = 6; + private const int RootFractalConstants = 0; + private const int RootFractalSplats = 1; + private const int RootFractalSdfReservoirs = 2; + private const int RootFractalPbrReservoirs = 3; + private const int RootFractalRadiosityReservoirs = 4; private static readonly DebugUi.DebugUiOption[] RenderDebugOptions = [ new(0, "Final"), @@ -101,11 +107,16 @@ public sealed class D3D12Renderer : IAquariumRenderer private readonly ID3D12GraphicsCommandList commandList; private readonly ID3D12RootSignature fullscreenRootSignature; private readonly ID3D12RootSignature localCastFusionRootSignature; + private readonly ID3D12RootSignature fractalReservoirRootSignature; private ID3D12PipelineState? heightFieldBasePipelineState; private ID3D12PipelineState? heightFieldBrushPipelineState; private ID3D12PipelineState? scenePipelineState; private ID3D12PipelineState? temporalGaussianPipelineState; private ID3D12PipelineState? localCastFusionPipelineState; + private ID3D12PipelineState? fractalSplatPipelineState; + private ID3D12PipelineState? fractalSdfReservoirPipelineState; + private ID3D12PipelineState? fractalPbrReservoirPipelineState; + private ID3D12PipelineState? fractalRadiosityReservoirPipelineState; private ID3D12PipelineState?[] sdfProxyPipelineStates = []; private ID3D12PipelineState? bloomPrefilterPipelineState; private ID3D12PipelineState? bloomDownsamplePipelineState; @@ -150,6 +161,10 @@ public sealed class D3D12Renderer : IAquariumRenderer private readonly D3D12StructuredBuffer gpuFusionSeedBuffer; private readonly D3D12StructuredBuffer gpuFusionPointBuffer; private readonly D3D12StructuredBuffer temporalGaussianBuffer; + private D3D12StructuredBuffer? fractalSplatBuffer; + private D3D12StructuredBuffer? fractalSdfReservoirBuffer; + private D3D12StructuredBuffer? fractalPbrReservoirBuffer; + private D3D12StructuredBuffer? fractalRadiosityReservoirBuffer; private readonly Dictionary externalSensorTextures = new(StringComparer.Ordinal); private readonly D3D12CubeTexture studioPmremTexture; private readonly D3D12CubeTexture studioIrradianceTexture; @@ -167,6 +182,7 @@ public sealed class D3D12Renderer : IAquariumRenderer private int gpuFusionSeedCount; private int gpuFusionPointCount; private bool temporalGaussiansGpuGenerated; + private AquariumFractalReservoirField activeFractalReservoirField = AquariumFractalReservoirField.Empty; private Viewport viewport; private RawRect scissorRect; private int width; @@ -294,6 +310,8 @@ public sealed class D3D12Renderer : IAquariumRenderer fullscreenRootSignature.Name = "Aquarium D3D12 Fullscreen Root Signature"; localCastFusionRootSignature = CreateLocalCastFusionRootSignature(); localCastFusionRootSignature.Name = "Aquarium D3D12 LocalCast Fusion Root Signature"; + fractalReservoirRootSignature = CreateFractalReservoirRootSignature(); + fractalReservoirRootSignature.Name = "Aquarium D3D12 Fractal Reservoir Root Signature"; CaptureShaderWriteTimes(); StartPipelineBuild("initial"); viewport = new Viewport(0.0f, 0.0f, width, height); @@ -529,6 +547,7 @@ public sealed class D3D12Renderer : IAquariumRenderer } CopySceneState(frame.Scene); + EnsureFractalReservoirBuffers(activeFractalReservoirField); var activeGpuSensorInput = frame.Scene.GpuSensorFrame.HasInput; var activeAccumulationWindow = activeGpuSensorInput ? frame.Scene.GpuSensorFrame.AccumulationWindowSeconds @@ -649,6 +668,7 @@ public sealed class D3D12Renderer : IAquariumRenderer commandList.BeginEvent("Aquarium D3D12 Frame"); UploadSceneStructuredResources(commandList, frameResources); DispatchLocalCastGpuFusion(commandList, frameResources); + DispatchFractalReservoirs(commandList); RenderHeightField(commandList, frameResources); RenderSceneAndPresent(new D3D12PassContext(commandList, frameResources.BackBuffer, frameResources.BackBufferRenderTargetView.Cpu), frameResources); commandList.EndEvent(); @@ -779,6 +799,10 @@ public sealed class D3D12Renderer : IAquariumRenderer && scenePipelineState is not null && temporalGaussianPipelineState is not null && localCastFusionPipelineState is not null + && fractalSplatPipelineState is not null + && fractalSdfReservoirPipelineState is not null + && fractalPbrReservoirPipelineState is not null + && fractalRadiosityReservoirPipelineState is not null && sdfProxyPipelineStates.All(pipeline => pipeline is not null) && bloomPrefilterPipelineState is not null && bloomDownsamplePipelineState is not null @@ -817,8 +841,10 @@ public sealed class D3D12Renderer : IAquariumRenderer DisposePipelineStates(); fullscreenRootSignature.Dispose(); localCastFusionRootSignature.Dispose(); + fractalReservoirRootSignature.Dispose(); studioIrradianceTexture.Dispose(); studioPmremTexture.Dispose(); + DisposeFractalReservoirBuffers(); temporalGaussianBuffer.Dispose(); gpuFusionPointBuffer.Dispose(); gpuFusionSeedBuffer.Dispose(); @@ -972,6 +998,14 @@ public sealed class D3D12Renderer : IAquariumRenderer temporalGaussian.Name = "Aquarium D3D12 Temporal Gaussian Pipeline"; var localCastFusion = CreateLocalCastFusionPipelineState(paths.LocalCastFusion); localCastFusion.Name = "Aquarium D3D12 LocalCast Fusion Compute Pipeline"; + var fractalSplat = CreateFractalReservoirPipelineState(paths.FractalReservoir, "D3D12FractalSplatReceiptCS"); + fractalSplat.Name = "Aquarium D3D12 Fractal Splat Compute Pipeline"; + var fractalSdfReservoir = CreateFractalReservoirPipelineState(paths.FractalReservoir, "D3D12SdfEnvelopeReservoirCS"); + fractalSdfReservoir.Name = "Aquarium D3D12 Fractal SDF Reservoir Compute Pipeline"; + var fractalPbrReservoir = CreateFractalReservoirPipelineState(paths.FractalReservoir, "D3D12PbrMaterialReservoirCS"); + fractalPbrReservoir.Name = "Aquarium D3D12 Fractal PBR Reservoir Compute Pipeline"; + var fractalRadiosityReservoir = CreateFractalReservoirPipelineState(paths.FractalReservoir, "D3D12RadiosityReservoirCS"); + fractalRadiosityReservoir.Name = "Aquarium D3D12 Fractal Radiosity Reservoir Compute Pipeline"; var sdfProxies = new ID3D12PipelineState[paths.SdfShaders.Count]; for (var index = 0; index < paths.SdfShaders.Count; index++) { @@ -996,6 +1030,10 @@ public sealed class D3D12Renderer : IAquariumRenderer scene, temporalGaussian, localCastFusion, + fractalSplat, + fractalSdfReservoir, + fractalPbrReservoir, + fractalRadiosityReservoir, sdfProxies, bloomPrefilter, bloomDownsample, @@ -1272,6 +1310,67 @@ public sealed class D3D12Renderer : IAquariumRenderer graphRenderTargets.Clear(); } + private void EnsureFractalReservoirBuffers(AquariumFractalReservoirField field) + { + if (!field.HasInput) + { + return; + } + + if (fractalSplatBuffer is not null && fractalSplatBuffer.ElementCount >= field.SplatCount) + { + return; + } + + WaitForGpu(); + DisposeFractalReservoirBuffers(); + fractalSplatBuffer = CreateFractalReservoirBuffer( + field.SplatCount, + "fractal-sdf-splat-buffer", + "Aquarium D3D12 Fractal SDF Splat Buffer"); + fractalSdfReservoirBuffer = CreateFractalReservoirBuffer( + field.SplatCount, + "fractal-sdf-envelope-reservoir-buffer", + "Aquarium D3D12 Fractal SDF Envelope Reservoir Buffer"); + fractalPbrReservoirBuffer = CreateFractalReservoirBuffer( + field.SplatCount, + "fractal-pbr-material-reservoir-buffer", + "Aquarium D3D12 Fractal PBR Material Reservoir Buffer"); + fractalRadiosityReservoirBuffer = CreateFractalReservoirBuffer( + field.SplatCount, + "fractal-radiosity-reservoir-buffer", + "Aquarium D3D12 Fractal Radiosity Reservoir Buffer"); + } + + private D3D12StructuredBuffer CreateFractalReservoirBuffer(int elementCount, string registryName, string resourceName) + where T : unmanaged + { + var buffer = new D3D12StructuredBuffer( + device, + elementCount, + Marshal.SizeOf(), + resourceName, + allowUnorderedAccess: true); + resourceRegistry.Add(registryName, buffer); + return buffer; + } + + private void DisposeFractalReservoirBuffers() + { + resourceRegistry.RemoveStructuredBuffer("fractal-radiosity-reservoir-buffer"); + resourceRegistry.RemoveStructuredBuffer("fractal-pbr-material-reservoir-buffer"); + resourceRegistry.RemoveStructuredBuffer("fractal-sdf-envelope-reservoir-buffer"); + resourceRegistry.RemoveStructuredBuffer("fractal-sdf-splat-buffer"); + fractalRadiosityReservoirBuffer?.Dispose(); + fractalPbrReservoirBuffer?.Dispose(); + fractalSdfReservoirBuffer?.Dispose(); + fractalSplatBuffer?.Dispose(); + fractalRadiosityReservoirBuffer = null; + fractalPbrReservoirBuffer = null; + fractalSdfReservoirBuffer = null; + fractalSplatBuffer = null; + } + private (int Width, int Height) ResolveGraphTargetSize(AquariumTargetSize size) { return size.Kind switch @@ -1560,6 +1659,58 @@ public sealed class D3D12Renderer : IAquariumRenderer } } + private void DispatchFractalReservoirs(ID3D12GraphicsCommandList activeCommandList) + { + if (!activeFractalReservoirField.HasInput || + fractalSplatBuffer is null || + fractalSdfReservoirBuffer is null || + fractalPbrReservoirBuffer is null || + fractalRadiosityReservoirBuffer is null) + { + return; + } + + activeCommandList.BeginEvent("Fractal Reservoir GPU Update"); + try + { + fractalSplatBuffer.Transition(activeCommandList, ResourceStates.UnorderedAccess); + fractalSdfReservoirBuffer.Transition(activeCommandList, ResourceStates.UnorderedAccess); + fractalPbrReservoirBuffer.Transition(activeCommandList, ResourceStates.UnorderedAccess); + fractalRadiosityReservoirBuffer.Transition(activeCommandList, ResourceStates.UnorderedAccess); + activeCommandList.SetComputeRootSignature(fractalReservoirRootSignature); + BindFractalReservoirConstants(activeCommandList); + activeCommandList.SetComputeRootUnorderedAccessView(RootFractalSplats, fractalSplatBuffer.Resource.GPUVirtualAddress); + activeCommandList.SetComputeRootUnorderedAccessView(RootFractalSdfReservoirs, fractalSdfReservoirBuffer.Resource.GPUVirtualAddress); + activeCommandList.SetComputeRootUnorderedAccessView(RootFractalPbrReservoirs, fractalPbrReservoirBuffer.Resource.GPUVirtualAddress); + activeCommandList.SetComputeRootUnorderedAccessView(RootFractalRadiosityReservoirs, fractalRadiosityReservoirBuffer.Resource.GPUVirtualAddress); + Dispatch(fractalSplatPipelineState!, activeFractalReservoirField.SplatCount); + activeCommandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(fractalSplatBuffer.Resource)); + Dispatch(fractalSdfReservoirPipelineState!, activeFractalReservoirField.ReservoirUpdatesPerPass); + Dispatch(fractalPbrReservoirPipelineState!, activeFractalReservoirField.ReservoirUpdatesPerPass); + Dispatch(fractalRadiosityReservoirPipelineState!, activeFractalReservoirField.ReservoirUpdatesPerPass); + } + finally + { + activeCommandList.EndEvent(); + } + + void Dispatch(ID3D12PipelineState pipelineState, int elementCount) + { + activeCommandList.SetPipelineState(pipelineState); + activeCommandList.Dispatch((uint)((elementCount + 255) / 256), 1, 1); + } + } + + private void BindFractalReservoirConstants(ID3D12GraphicsCommandList activeCommandList) + { + activeCommandList.SetComputeRoot32BitConstant(RootFractalConstants, (uint)activeFractalReservoirField.SplatCount, 0); + activeCommandList.SetComputeRoot32BitConstant(RootFractalConstants, (uint)temporalFrameIndex, 1); + activeCommandList.SetComputeRoot32BitConstant(RootFractalConstants, (uint)activeFractalReservoirField.Depth, 2); + activeCommandList.SetComputeRoot32BitConstant(RootFractalConstants, activeFractalReservoirField.Seed, 3); + activeCommandList.SetComputeRoot32BitConstant(RootFractalConstants, (uint)activeFractalReservoirField.CandidatesPerReservoirUpdate, 4); + activeCommandList.SetComputeRoot32BitConstant(RootFractalConstants, (uint)activeFractalReservoirField.ReservoirUpdatesPerPass, 5); + } + private void CreateGpuSensorTextureViews(AquariumGpuSensorFrame sensorFrame, D3D12DescriptorSlot firstDescriptor) { var activeHandles = new HashSet(StringComparer.Ordinal); @@ -1660,6 +1811,9 @@ public sealed class D3D12Renderer : IAquariumRenderer gpuFusionPointCount = 0; gpuFusionPointSource = default; temporalGaussiansGpuGenerated = false; + activeFractalReservoirField = scene.FractalReservoirField.HasInput + ? scene.FractalReservoirField + : AquariumFractalReservoirField.Empty; heightFieldBrushConstants = D3D12HeightFieldBrushConstants.FromBrushes(scene.HeightFieldBrushes); var objectCount = Math.Min(scene.SdfObjects.Count, MaxSdfObjectCount); @@ -2033,6 +2187,10 @@ public sealed class D3D12Renderer : IAquariumRenderer scenePipelineState!, temporalGaussianPipelineState!, localCastFusionPipelineState!, + fractalSplatPipelineState!, + fractalSdfReservoirPipelineState!, + fractalPbrReservoirPipelineState!, + fractalRadiosityReservoirPipelineState!, sdfProxyPipelineStates.Select(pipeline => pipeline!).ToArray(), bloomPrefilterPipelineState!, bloomDownsamplePipelineState!, @@ -2049,6 +2207,10 @@ public sealed class D3D12Renderer : IAquariumRenderer scenePipelineState = pipelines.Scene; temporalGaussianPipelineState = pipelines.TemporalGaussian; localCastFusionPipelineState = pipelines.LocalCastFusion; + fractalSplatPipelineState = pipelines.FractalSplat; + fractalSdfReservoirPipelineState = pipelines.FractalSdfReservoir; + fractalPbrReservoirPipelineState = pipelines.FractalPbrReservoir; + fractalRadiosityReservoirPipelineState = pipelines.FractalRadiosityReservoir; for (var index = 0; index < sdfProxyPipelineStates.Length; index++) { sdfProxyPipelineStates[index] = pipelines.SdfProxies[index]; @@ -2068,6 +2230,10 @@ public sealed class D3D12Renderer : IAquariumRenderer scenePipelineState = null; temporalGaussianPipelineState = null; localCastFusionPipelineState = null; + fractalSplatPipelineState = null; + fractalSdfReservoirPipelineState = null; + fractalPbrReservoirPipelineState = null; + fractalRadiosityReservoirPipelineState = null; Array.Clear(sdfProxyPipelineStates); bloomPrefilterPipelineState = null; bloomDownsamplePipelineState = null; @@ -2336,6 +2502,23 @@ public sealed class D3D12Renderer : IAquariumRenderer return device.CreateRootSignature(0, in description, RootSignatureVersion.Version1); } + private ID3D12RootSignature CreateFractalReservoirRootSignature() + { + var rootParameters = new[] + { + new RootParameter(new RootConstants(0, 0, 6), ShaderVisibility.All), + new RootParameter(RootParameterType.UnorderedAccessView, new RootDescriptor(0, 0), ShaderVisibility.All), + new RootParameter(RootParameterType.UnorderedAccessView, new RootDescriptor(1, 0), ShaderVisibility.All), + new RootParameter(RootParameterType.UnorderedAccessView, new RootDescriptor(2, 0), ShaderVisibility.All), + new RootParameter(RootParameterType.UnorderedAccessView, new RootDescriptor(3, 0), ShaderVisibility.All), + }; + var description = new RootSignatureDescription( + RootSignatureFlags.None, + rootParameters, + []); + return device.CreateRootSignature(0, in description, RootSignatureVersion.Version1); + } + private FrameResources CreateFrameResources(int index) { var commandAllocator = device.CreateCommandAllocator(CommandListType.Direct); @@ -2377,6 +2560,17 @@ public sealed class D3D12Renderer : IAquariumRenderer return device.CreateComputePipelineState(description); } + private ID3D12PipelineState CreateFractalReservoirPipelineState(string path, string entryPoint) + { + var computeShader = CompileShader(path, entryPoint, "cs_5_0"); + var description = new ComputePipelineStateDescription + { + RootSignature = fractalReservoirRootSignature, + ComputeShader = computeShader, + }; + return device.CreateComputePipelineState(description); + } + private ID3D12PipelineState CreateBloomPrefilterPipelineState(string path) { return CreateFullscreenPipelineState(path, "FullscreenTriangleVS", "D3D12BloomPrefilterPS", SceneHdrFormat); @@ -2566,6 +2760,7 @@ public sealed class D3D12Renderer : IAquariumRenderer string Scene, string TemporalGaussian, string LocalCastFusion, + string FractalReservoir, string SdfCommon, string SdfProxy, IReadOnlyList SdfShaders, @@ -2573,7 +2768,7 @@ public sealed class D3D12Renderer : IAquariumRenderer IReadOnlyList Includes, string Post) { - public IReadOnlyList All { get; } = [HeightField, Scene, TemporalGaussian, LocalCastFusion, SdfCommon, SdfProxy, ..SdfShaders, SdfMath, ..Includes, Post]; + public IReadOnlyList All { get; } = [HeightField, Scene, TemporalGaussian, LocalCastFusion, FractalReservoir, SdfCommon, SdfProxy, ..SdfShaders, SdfMath, ..Includes, Post]; public static D3D12ShaderPaths FromManifest(string root, AquariumShaderManifest manifest) { @@ -2586,6 +2781,7 @@ public sealed class D3D12Renderer : IAquariumRenderer shaderPath(manifest.SceneShader), shaderPath(manifest.TemporalGaussianShader), shaderPath(manifest.LocalCastFusionShader), + shaderPath(manifest.FractalReservoirShader), shaderPath(manifest.SdfCommonInclude), shaderPath(manifest.SdfProxyInclude), manifest.SdfShaderPaths.Select(shaderPath).ToArray(), @@ -2601,6 +2797,10 @@ public sealed class D3D12Renderer : IAquariumRenderer ID3D12PipelineState Scene, ID3D12PipelineState TemporalGaussian, ID3D12PipelineState LocalCastFusion, + ID3D12PipelineState FractalSplat, + ID3D12PipelineState FractalSdfReservoir, + ID3D12PipelineState FractalPbrReservoir, + ID3D12PipelineState FractalRadiosityReservoir, IReadOnlyList SdfProxies, ID3D12PipelineState BloomPrefilter, ID3D12PipelineState BloomDownsample, @@ -2615,6 +2815,10 @@ public sealed class D3D12Renderer : IAquariumRenderer BloomBlurHorizontal.Dispose(); BloomDownsample.Dispose(); BloomPrefilter.Dispose(); + FractalRadiosityReservoir.Dispose(); + FractalPbrReservoir.Dispose(); + FractalSdfReservoir.Dispose(); + FractalSplat.Dispose(); LocalCastFusion.Dispose(); TemporalGaussian.Dispose(); foreach (var sdfProxy in SdfProxies) diff --git a/src/Aquarium.Engine/Render/D3D12StructuredBuffer.cs b/src/Aquarium.Engine/Render/D3D12StructuredBuffer.cs index de869e7..9c5f5df 100644 --- a/src/Aquarium.Engine/Render/D3D12StructuredBuffer.cs +++ b/src/Aquarium.Engine/Render/D3D12StructuredBuffer.cs @@ -26,6 +26,10 @@ internal sealed class D3D12StructuredBuffer : IDisposable public ID3D12Resource Resource { get; } + public int ElementCount => elementCount; + + public int StrideBytes => strideBytes; + public ResourceStates State { get; private set; } = ResourceStates.Common; public int SizeBytes { get; } diff --git a/src/Aquarium.Zyphos/ZyphosSceneBuilder.cs b/src/Aquarium.Zyphos/ZyphosSceneBuilder.cs index caea6cb..3b2be0d 100644 --- a/src/Aquarium.Zyphos/ZyphosSceneBuilder.cs +++ b/src/Aquarium.Zyphos/ZyphosSceneBuilder.cs @@ -12,6 +12,11 @@ public static class ZyphosSceneBuilder TraceHeightFieldSurface = false, UseStarfieldBackground = true, HeightFieldBrushes = fractalPlan.HeightBrushes, + FractalReservoirField = new AquariumFractalReservoirField + { + SplatCount = 2_000_000, + ReservoirUpdatesPerPass = 50_000, + }, SdfObjects = BuildSdfObjects(timeSeconds, previousTimeSeconds), SdfLights = BuildSdfLights(timeSeconds), }; diff --git a/state/evidence.jsonl b/state/evidence.jsonl index a129773..8e78295 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -179,3 +179,4 @@ {"timestamp":"2026-05-19T21:29:26+00:00","topic":"gpu-resident-layered-reservoir-receipt","lesson":"The layered temporal cache is not one generic reservoir with a layer enum. SDF envelope splats, PBR material splats, and radiosity splats are three different sampled measures, so the GPU receipt now uses three distinct 64-byte reservoir packet types and three independent compute passes. Full rewrites of all three 2,000,000-entry reservoir layers every frame missed the target on the GTX 1070; the coherent architecture is stochastic budgeted refresh over resident reservoirs. With 50,000 updates per reservoir layer per frame, 2 candidates/update, and 2,000,000 resident splats/reservoirs, the receipt measured 4.471 ms/frame and 223.7 FPS equivalent over 120 frames, with full reservoir coverage in 40 frames.","files":["src/Aquarium.Engine.Contracts/Fractal/AquariumFractalContracts.cs","tests/Aquarium.Engine.Fractal.Tests/FractalSdfSplat3DContractTests.cs","tools/Aquarium.Fractal.Receipt/Program.cs","scripts/fractal-splat-receipt.ps1","docs/perfect-machine-architecture.md","research/rendering/fractal-brush-implementation-roadmap.md","state/memory.json","state/map.yaml"],"source":"user corrected that SDF splats, PBR splats, and radiosity splats are sampled independently in different shader passes"} {"timestamp":"2026-05-20T01:24:49+01:00","topic":"fractal-reservoir-shader-asset","lesson":"The fractal GPU reservoir compute path must live as an engine shader asset, not as embedded receipt-tool text. `src/Aquarium.Engine/Render/Shaders/D3D12FractalReservoirCompute.hlsl` now owns the splat population pass plus the independent SDF envelope, PBR material, and radiosity reservoir update passes. `tools/Aquarium.Fractal.Receipt` compiles that shader file directly, keeping the receipt and future renderer pass on one source of truth.","files":["src/Aquarium.Engine/Render/Shaders/D3D12FractalReservoirCompute.hlsl","tools/Aquarium.Fractal.Receipt/Program.cs","state/map.yaml"],"source":"continued Perfect Machine build after the GPU receipt proved the pass should become reusable renderer architecture"} {"timestamp":"2026-05-20T01:31:00+01:00","topic":"fractal-reservoir-render-contract","lesson":"The render contract now exposes `AquariumFractalReservoirField` on `AquariumSceneState`: clients request a GPU-resident fractal reservoir field by resident splat count, depth, seed, reservoir candidates/update, and updates/pass. This keeps million-instance splat population inside GPU compute instead of making clients publish CPU splat lists.","files":["src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs","tests/Aquarium.Engine.Fractal.Tests/FractalReservoirFieldContractTests.cs","state/map.yaml"],"source":"continued Perfect Machine build: the shared shader needed a client-to-renderer contract surface"} +{"timestamp":"2026-05-20T01:57:56+01:00","topic":"renderer-owned-fractal-reservoir-pass","lesson":"D3D12Renderer now owns the first live fractal reservoir compute pass instead of leaving it in the receipt tool. The renderer creates a separate fractal reservoir root signature, compiles four compute pipelines from `D3D12FractalReservoirCompute.hlsl`, lazily allocates GPU UAV buffers for splats plus SDF/PBR/radiosity reservoirs, inserts a UAV barrier after splat population, and dispatches the three independent reservoir passes when `AquariumFractalReservoirField` is present. Zyphos now requests the 2,000,000-splat, 50,000-updates/pass field by default. The pass still needs a shaded consumption path before it produces visible terrain pixels.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/D3D12StructuredBuffer.cs","src/Aquarium.Engine.Contracts/Render/AquariumApp.cs","src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs","src/Aquarium.Zyphos/ZyphosSceneBuilder.cs","tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs","tools/Aquarium.Fractal.Receipt/Program.cs","state/map.yaml"],"source":"continued Perfect Machine build: turn the GPU reservoir receipt into a renderer-owned frame pass"} diff --git a/state/map.yaml b/state/map.yaml index 654a9f4..9c5c339 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -139,6 +139,7 @@ renderer_state: - Hot fractal splats and their temporal cache layers must be GPU-resident packed buffers. AquariumPackedFractalSdfSplat3D is the 80-byte numeric splat packet; the SDF envelope, PBR material, and radiosity reservoir packets are distinct 64-byte UAV rows sampled in independent compute passes. tools/Aquarium.Fractal.Receipt proves a D3D12 compute path can keep 2,000,000 splats and 2,000,000 reservoirs per layer resident on the GTX 1070, update 50,000 entries per reservoir layer per frame with 2 candidates/update, and run at 4.471 ms/frame, 223.7 FPS equivalent, with only tiny checksum readback. The receipt now compiles the shared engine shader asset src/Aquarium.Engine/Render/Shaders/D3D12FractalReservoirCompute.hlsl instead of carrying private embedded shader text. - 2D-projected-to-3D splats have a pure compiler seam: FractalProjectedSdfSplatCompiler maps resident SignedDistance2D page payload samples through an explicit page-to-world function and normal into bounded AquariumFractalSdfSplat3D packets. - AquariumSceneState now carries AquariumFractalReservoirField as the narrow client-to-renderer request for GPU-resident fractal reservoirs: resident splat count, IFS depth/seed, candidates per reservoir update, and stochastic updates per pass. This is a budgeted GPU field request, not a CPU splat list. + - D3D12Renderer owns the first live fractal reservoir compute hook: a separate root signature, four compute pipelines from D3D12FractalReservoirCompute.hlsl, lazy UAV buffers for splats/SDF/PBR/radiosity reservoirs, a UAV barrier after splat population, and per-frame dispatch when AquariumFractalReservoirField is present. Zyphos requests the 2M-splat, 50k-updates/pass field by default. - The consolidated fractal brush architecture plan defines the intended pipeline: client intent -> domain roots -> semantic IFS brush grammar -> ownership tree -> node summaries -> contribution cache/residency scheduler -> backend packets -> renderer passes -> debug/evidence, with explicit module boundaries and mockable unit-test seams. - The Perfect Machine architecture lives in docs/perfect-machine-architecture.md. It is the current waterfall design authority for fast 2D SDF splats, 3D SDF splats, 2D-projected-to-3D surface splats, IFS `.aquageo` structural probes, Mimir-style camera/audio evidence candidates, ReSTIR/GRIS reservoir reuse, heuristic occupancy graph updates, resource-tier residency, and TAA guide-buffer integration. - Fractal surface page planning now has a CPU boundary: FractalSurfacePagePlanner lowers selected IFS cuts into stable height, 2D signed-distance, material, and confidence page metadata; ZyphosFractalRenderPlan exposes these pages, while the live D3D12 page store and atlas remain future work. diff --git a/tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs b/tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs index 7a16f34..078b7b0 100644 --- a/tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs +++ b/tests/Aquarium.Engine.Fractal.Tests/ZyphosFractalTerrainTests.cs @@ -79,6 +79,18 @@ public sealed class ZyphosFractalTerrainTests MathF.Abs(near.HeightBrushes[^1].Amplitude) * MathF.Max(near.HeightBrushes[^1].Radius, near.HeightBrushes[^1].RadiusY)); } + [Fact] + public void ZyphosSceneRequestsGpuFractalReservoirField() + { + var shot = ZyphosCameraComposer.Compose(ZyphosSpatialDomainCatalog.CanopyLeaf, 0.1f, 0.4f, 0.1f, 0.0f); + var scene = ZyphosSceneBuilder.Build(1.0f, 0.9f, ZyphosFractalTerrain.BuildRenderPlan(shot)); + + Assert.True(scene.FractalReservoirField.HasInput); + Assert.Equal(2_000_000, scene.FractalReservoirField.SplatCount); + Assert.Equal(50_000, scene.FractalReservoirField.ReservoirUpdatesPerPass); + Assert.Equal(2, scene.FractalReservoirField.CandidatesPerReservoirUpdate); + } + [Fact] public void ZyphosFractalPlanDebugDumpReportsResourceBudgets() { diff --git a/tools/Aquarium.Fractal.Receipt/Program.cs b/tools/Aquarium.Fractal.Receipt/Program.cs index 915e4fa..41b5bd2 100644 --- a/tools/Aquarium.Fractal.Receipt/Program.cs +++ b/tools/Aquarium.Fractal.Receipt/Program.cs @@ -114,6 +114,7 @@ internal sealed class GpuFractalSplatReceiptRunner : IDisposable commandList.SetComputeRootUnorderedAccessView(4, radiosityReservoirs.GPUVirtualAddress); commandList.EndQuery(queryHeap, QueryType.Timestamp, 0); Dispatch(splatPipelineState, options.SplatCount); + commandList.ResourceBarrier(ResourceBarrier.BarrierUnorderedAccessView(splats)); Dispatch(sdfPipelineState, options.ReservoirUpdatesPerPass); Dispatch(pbrPipelineState, options.ReservoirUpdatesPerPass); Dispatch(radiosityPipelineState, options.ReservoirUpdatesPerPass);