diff --git a/src/Aquarium.Engine/Render/D3D12Renderer.cs b/src/Aquarium.Engine/Render/D3D12Renderer.cs index 16d46e8..17a832d 100644 --- a/src/Aquarium.Engine/Render/D3D12Renderer.cs +++ b/src/Aquarium.Engine/Render/D3D12Renderer.cs @@ -60,6 +60,10 @@ public sealed class D3D12Renderer : IAquariumRenderer private const int RootTemporalGaussians = 13; private const int RootCurrentReservoirGuide = 14; private const int RootHistoryReservoirGuide = 15; + private const int RootFractalSplatSrv = 16; + private const int RootFractalSdfReservoirSrv = 17; + private const int RootFractalPbrReservoirSrv = 18; + private const int RootFractalRadiosityReservoirSrv = 19; private const int RootFusionFrameConstants = 0; private const int RootFusionSeeds = 1; private const int RootFusionSensorCameras = 2; @@ -630,12 +634,6 @@ public sealed class D3D12Renderer : IAquariumRenderer temporalGaussianBuffer.CreateShaderResourceView(device, frameResources.TemporalGaussianDescriptor); frameResources.TemporalGaussianUnorderedAccessDescriptor = frameResources.TransientShaderDescriptors.Allocate(); temporalGaussianBuffer.CreateUnorderedAccessView(device, frameResources.TemporalGaussianUnorderedAccessDescriptor); - if (fractalSplatBuffer is not null) - { - frameResources.FractalSplatDescriptor = frameResources.TransientShaderDescriptors.Allocate(); - fractalSplatBuffer.CreateShaderResourceView(device, frameResources.FractalSplatDescriptor); - } - frameResources.StudioPmremDescriptor = frameResources.TransientShaderDescriptors.Allocate(); studioPmremTexture.CreateShaderResourceView(device, frameResources.StudioPmremDescriptor); frameResources.StudioIrradianceDescriptor = frameResources.TransientShaderDescriptors.Allocate(); @@ -1472,10 +1470,16 @@ public sealed class D3D12Renderer : IAquariumRenderer context.CommandList.DrawInstanced(6, (uint)temporalGaussianCount, 0, 0); } - if (visibleFractalSplatCount > 0 && fractalSplatBuffer is not null) + if (visibleFractalSplatCount > 0 && fractalSplatBuffer is not null && fractalSdfReservoirBuffer is not null && fractalPbrReservoirBuffer is not null && fractalRadiosityReservoirBuffer is not null) { fractalSplatBuffer.Transition(context.CommandList, ResourceStates.PixelShaderResource | ResourceStates.NonPixelShaderResource); - context.CommandList.SetGraphicsRootDescriptorTable(RootTemporalGaussians, frameResources.FractalSplatDescriptor.Gpu); + fractalSdfReservoirBuffer.Transition(context.CommandList, ResourceStates.PixelShaderResource | ResourceStates.NonPixelShaderResource); + fractalPbrReservoirBuffer.Transition(context.CommandList, ResourceStates.PixelShaderResource | ResourceStates.NonPixelShaderResource); + fractalRadiosityReservoirBuffer.Transition(context.CommandList, ResourceStates.PixelShaderResource | ResourceStates.NonPixelShaderResource); + context.CommandList.SetGraphicsRootShaderResourceView(RootFractalSplatSrv, fractalSplatBuffer.Resource.GPUVirtualAddress); + context.CommandList.SetGraphicsRootShaderResourceView(RootFractalSdfReservoirSrv, fractalSdfReservoirBuffer.Resource.GPUVirtualAddress); + context.CommandList.SetGraphicsRootShaderResourceView(RootFractalPbrReservoirSrv, fractalPbrReservoirBuffer.Resource.GPUVirtualAddress); + context.CommandList.SetGraphicsRootShaderResourceView(RootFractalRadiosityReservoirSrv, fractalRadiosityReservoirBuffer.Resource.GPUVirtualAddress); context.CommandList.SetPipelineState(fractalSplatRenderPipelineState!); context.CommandList.DrawInstanced(6, (uint)visibleFractalSplatCount, 0, 0); } @@ -2463,6 +2467,10 @@ public sealed class D3D12Renderer : IAquariumRenderer new RootParameter(new RootDescriptorTable([temporalGaussianRange]), ShaderVisibility.All), new RootParameter(new RootDescriptorTable([currentReservoirGuideRange]), ShaderVisibility.Pixel), new RootParameter(new RootDescriptorTable([historyReservoirGuideRange]), ShaderVisibility.Pixel), + new RootParameter(RootParameterType.ShaderResourceView, new RootDescriptor(38, 0), ShaderVisibility.All), + new RootParameter(RootParameterType.ShaderResourceView, new RootDescriptor(39, 0), ShaderVisibility.All), + new RootParameter(RootParameterType.ShaderResourceView, new RootDescriptor(40, 0), ShaderVisibility.All), + new RootParameter(RootParameterType.ShaderResourceView, new RootDescriptor(41, 0), ShaderVisibility.All), }; var staticSamplers = new[] { @@ -2922,8 +2930,6 @@ public sealed class D3D12Renderer : IAquariumRenderer public D3D12DescriptorSlot TemporalGaussianUnorderedAccessDescriptor { get; set; } - public D3D12DescriptorSlot FractalSplatDescriptor { get; set; } - public D3D12DescriptorSlot StudioPmremDescriptor { get; set; } public D3D12DescriptorSlot StudioIrradianceDescriptor { get; set; } diff --git a/src/Aquarium.Engine/Render/Shaders/D3D12FractalSplatRender.hlsl b/src/Aquarium.Engine/Render/Shaders/D3D12FractalSplatRender.hlsl index c2c15e7..73a9b7c 100644 --- a/src/Aquarium.Engine/Render/Shaders/D3D12FractalSplatRender.hlsl +++ b/src/Aquarium.Engine/Render/Shaders/D3D12FractalSplatRender.hlsl @@ -36,7 +36,34 @@ struct FractalSdfSplat float4 key; }; -StructuredBuffer fractalSdfSplats : register(t25); +struct SdfEnvelopeReservoir +{ + float4 centerRadius; + float4 radiiFalloff; + float4 weightTargetCount; + float4 validation; +}; + +struct PbrMaterialReservoir +{ + float4 baseColorRoughMetal; + float4 normalVariance; + float4 weightTargetCount; + float4 validation; +}; + +struct RadiosityReservoir +{ + float4 radianceDistance; + float4 directionOcclusion; + float4 weightTargetCount; + float4 validation; +}; + +StructuredBuffer fractalSdfSplats : register(t38); +StructuredBuffer sdfEnvelopeReservoirs : register(t39); +StructuredBuffer pbrMaterialReservoirs : register(t40); +StructuredBuffer radiosityReservoirs : register(t41); struct FractalSplatVertexOut { @@ -44,6 +71,8 @@ struct FractalSplatVertexOut nointerpolation uint splatIndex : TEXCOORD0; float2 quad : TEXCOORD1; float travel : TEXCOORD2; + float reservoirConfidence : TEXCOORD3; + float radiosityEnergy : TEXCOORD4; }; struct SceneOut @@ -85,17 +114,20 @@ FractalSplatVertexOut D3D12FractalSplatVS(uint vertexId : SV_VertexID, uint inst uint splatIndex = VisibleSplatIndex(instanceId); FractalSdfSplat splat = fractalSdfSplats[splatIndex]; + SdfEnvelopeReservoir sdf = sdfEnvelopeReservoirs[splatIndex]; + bool sdfResident = sdf.weightTargetCount.z > 0.5; + float4 centerRadius = sdfResident ? sdf.centerRadius : splat.centerRadius; float3 forward; float3 right; float3 up; cameraBasis(cameraPosition, cameraTarget, forward, right, up); float worldScale = max(viewRadius * 0.16, 0.05); - float3 center = cameraTarget + splat.centerRadius.xyz * worldScale; + float3 center = cameraTarget + centerRadius.xyz * worldScale; float3 delta = center - cameraPosition; float z = max(dot(delta, forward), 0.0001); float2 projected = float2(dot(delta, right), dot(delta, up)) / z * 1.6; float clipAspect = resolution.x / max(resolution.y, 1.0); - float boundRadius = max(splat.centerRadius.w * worldScale * 1.8, 0.002 * viewRadius); + float boundRadius = max(centerRadius.w * worldScale * 1.8, 0.002 * viewRadius); float projectedRadius = boundRadius / z * 1.6 + 0.002; float2 clipCenter = float2(projected.x / clipAspect, projected.y); float2 clipRadius = float2(projectedRadius / clipAspect, projectedRadius); @@ -105,6 +137,8 @@ FractalSplatVertexOut D3D12FractalSplatVS(uint vertexId : SV_VertexID, uint inst output.splatIndex = splatIndex; output.quad = corners[vertexId]; output.travel = z; + output.reservoirConfidence = sdfResident ? saturate(sdf.validation.x) : saturate(splat.materialConfidence.w) * 0.25; + output.radiosityEnergy = 0.0; return output; } @@ -117,16 +151,37 @@ SceneOut D3D12FractalSplatPS(FractalSplatVertexOut input) } FractalSdfSplat splat = fractalSdfSplats[input.splatIndex]; - float weight = pow(saturate(1.0 - r2), max(splat.radiiFalloff.w * 0.35, 0.5)); + SdfEnvelopeReservoir sdf = sdfEnvelopeReservoirs[input.splatIndex]; + PbrMaterialReservoir pbr = pbrMaterialReservoirs[input.splatIndex]; + RadiosityReservoir radiosity = radiosityReservoirs[input.splatIndex]; + + bool sdfResident = sdf.weightTargetCount.z > 0.5; + bool pbrResident = pbr.weightTargetCount.z > 0.5; + bool radiosityResident = radiosity.weightTargetCount.z > 0.5; + float falloff = sdfResident ? sdf.radiiFalloff.w : splat.radiiFalloff.w; + float weight = pow(saturate(1.0 - r2), max(falloff * 0.35, 0.5)); float material = saturate(splat.materialConfidence.x); - float3 color = lerp(float3(0.05, 0.42, 1.0), float3(1.0, 0.72, 0.18), material); - float opacity = saturate(weight * 0.34); + float3 fallbackColor = lerp(float3(0.05, 0.42, 1.0), float3(1.0, 0.72, 0.18), material); + float3 pbrColor = saturate(pbr.baseColorRoughMetal.rgb); + float3 radiosityColor = saturate(radiosity.radianceDistance.rgb); + float reservoirConfidence = min( + sdfResident ? saturate(sdf.validation.x) : 0.0, + min( + pbrResident ? saturate(pbr.validation.x) : 0.0, + radiosityResident ? saturate(radiosity.validation.x) : 0.0)); + float3 color = pbrResident ? pbrColor : fallbackColor; + color += radiosityResident ? radiosityColor * (0.18 + reservoirConfidence * 0.35) : 0.0; + float opacity = saturate(weight * (0.18 + reservoirConfidence * 0.28)); SceneOut output; output.colorTravel = float4(color * opacity, min(input.travel, farDistance + 1.0)); output.metadata = float4(FIELD_ID_FRACTAL_SPLAT_BASE, normalize(float3(input.quad, 1.0))); - output.control = float4(opacity, saturate(splat.materialConfidence.w), saturate(splat.centerRadius.w * 40.0), 0.0); - output.reservoirGuide = float4(saturate(splat.materialConfidence.w), 0.0, 1.0, 0.0); + output.control = float4(opacity, reservoirConfidence, saturate((sdfResident ? sdf.centerRadius.w : splat.centerRadius.w) * 40.0), 0.0); + output.reservoirGuide = float4( + sdfResident ? saturate(sdf.validation.x) : 0.0, + pbrResident ? saturate(pbr.validation.x) : 0.0, + radiosityResident ? saturate(radiosity.validation.x) : 0.0, + reservoirConfidence); output.depth = saturate(input.travel / max(farDistance, 0.0001)); return output; } diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 5f573db..83eb03a 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -181,3 +181,4 @@ {"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"} {"timestamp":"2026-05-20T02:08:12+01:00","topic":"visible-fractal-splat-consumption","lesson":"The first visible GPU-resident fractal consumption path is now a capped debug draw, not a CPU readback. `D3D12FractalSplatRender.hlsl` reads the computed `AquariumPackedFractalSdfSplat3D` buffer as an SRV and draws up to 131,072 splat instances into the scene. This proves the renderer can consume the compute-populated splat buffer directly; final terrain, material, and radiosity integration still need domain-correct shading over the same buffers. A Zyphos shader compile bug also surfaced here: `line` was treated as an HLSL token, so the planet debug variable is now `gridLine`.","files":["src/Aquarium.Engine/Render/Shaders/D3D12FractalSplatRender.hlsl","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine.Contracts/Render/AquariumApp.cs","src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs","src/Aquarium.Zyphos/Shaders/D3D12ZyphosPlanet.hlsl","state/map.yaml"],"source":"continued Perfect Machine build: make the GPU-resident fractal splat buffer visible in the renderer"} +{"timestamp":"2026-05-20T07:47:00+01:00","topic":"layered-fractal-reservoir-consumption","lesson":"The visible fractal splat draw must consume the same independent reservoir layers produced by compute. Reusing the temporal Gaussian descriptor slot for raw splats hid the SDF/PBR/radiosity contract. The renderer now binds raw splats plus SDF envelope, PBR material, and radiosity reservoirs as separate graphics SRVs; the debug draw uses SDF reservoirs for support, PBR reservoirs for color, radiosity reservoirs for energy, and writes per-layer confidence into the reservoir guide MRT. This is still a capped debug view, but it proves the three-layer reservoir machine reaches visible pixels without CPU readback or buffer collapse.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12FractalSplatRender.hlsl","state/map.yaml","state/memory.json"],"source":"user insisted SDF splats, PBR splats, and radiosity splats are different sampled types and the Perfect Machine must not flatten them"} diff --git a/state/map.yaml b/state/map.yaml index d1e3c5e..ee689e6 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -140,7 +140,7 @@ renderer_state: - 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 renderer now has a first visible consumption path for computed fractal splats: D3D12FractalSplatRender.hlsl reads the GPU-resident splat buffer as an SRV and draws a capped 131,072-instance debug splat subset into the scene after the reservoir compute update. This is an observability/render-consumption proof, not the final terrain/material/radiosity shading path. + - The renderer now has a first visible layered-reservoir consumption path for computed fractal splats: D3D12FractalSplatRender.hlsl binds separate GPU SRVs for raw splats, SDF envelope reservoirs, PBR material reservoirs, and radiosity reservoirs, then draws a capped 131,072-instance debug subset into the scene after compute updates. This is an observability/render-consumption proof for the three-pass reservoir contract, not the final terrain/material/radiosity shading path. - D3D12 capacity logging now reports active fractal reservoir resident MiB, splat count, visible debug splat count, updates/pass, and candidates/update so the GPU cache has a receipt in normal runtime logs, not just in the standalone benchmark. - 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. diff --git a/state/memory.json b/state/memory.json index cbaf6dd..adf9657 100644 --- a/state/memory.json +++ b/state/memory.json @@ -99,7 +99,7 @@ "FractalStructuralProbeReservoir builds a reservoir snapshot from an ownership tree, selected cut, summaries, and projected pixels per world unit. ZyphosFractalRenderPlan now carries this structural probe reservoir, so the planet path exposes reservoir-shaped structural evidence beside brushes/resource plans before GPU reuse exists.", "AquariumFractalSdfSplat3D is the compact 3D SDF splat packet contract for Phase F. FractalSdfSplat3DCompiler lowers FractalProbeSample evidence into stable domain/node/payload-keyed splats, and FractalSdfSplat3DKernel owns CPU compact-weight/signed-distance parity math. Zyphos exposes a first structural splat from its probe reservoir before D3D12 lowering.", "Hot fractal splat storage must be GPU-resident packed buffers manipulated by compute shaders. Stable string-keyed splat contracts are metadata/debug boundaries, not million-instance hot buffers. `AquariumPackedFractalSdfSplat3D` is the numeric 80-byte packet shape; C# staging/readback paths use unsafe `FractalNativeBuffer` when CPU memory is genuinely needed.", - "The GPU splat receipt harness lives at tools/Aquarium.Fractal.Receipt and scripts/fractal-splat-receipt.ps1. The live receipt allocates one 80-byte packed SDF splat UAV plus three distinct 64-byte reservoir UAVs for SDF envelopes, PBR material envelopes, and radiosity; those reservoirs are sampled in independent compute passes under a stochastic update budget. On the local NVIDIA GTX 1070 it kept 2,000,000 splats and 2,000,000 reservoirs per layer resident, updated 50,000 entries per reservoir layer per frame with 2 candidates/update, and measured 4.471 ms/frame, 223.7 FPS equivalent over 120 frames. This proves compute-side GPU residency and budgeted temporal convergence, not final shaded visibility.", + "The GPU splat receipt harness lives at tools/Aquarium.Fractal.Receipt and scripts/fractal-splat-receipt.ps1. The live receipt allocates one 80-byte packed SDF splat UAV plus three distinct 64-byte reservoir UAVs for SDF envelopes, PBR material envelopes, and radiosity; those reservoirs are sampled in independent compute passes under a stochastic update budget. On the local NVIDIA GTX 1070 it kept 2,000,000 splats and 2,000,000 reservoirs per layer resident, updated 50,000 entries per reservoir layer per frame with 2 candidates/update, and measured 4.471 ms/frame, 223.7 FPS equivalent over 120 frames. D3D12FractalSplatRender now consumes the raw splat, SDF, PBR, and radiosity buffers through separate graphics SRVs for the visible debug subset. This proves compute-side GPU residency, budgeted temporal convergence, and first layered GPU consumption; final terrain/material/radiosity shading is still future work.", "FractalProjectedSdfSplatCompiler is the Phase G 2D-projected-to-3D lowering seam: it converts resident SignedDistance2D page payload samples into compact 3D SDF splats through an explicit page-local Vector2 -> Vector3 mapping, surface normal, support radius, and splat budget. Zyphos caches a bounded first set with a flat local mapping until cube-sphere/torus mappers are added.", "Zyphos camera distance limits belong to the selected spatial domain, not one global planetary clamp. Leaf/pebble domains must be able to zoom below whole-body distances, and the parent star must be a visible SDF body when it is also the primary light source.", "The consolidated fractal brush architecture lives in research/rendering/fractal-brush-architecture-plan.md. Its pipeline is client intent -> domain roots -> semantic IFS brush grammar -> ownership tree -> node summaries -> contribution cache/residency scheduler -> backend packets -> renderer passes -> debug/evidence. Its credibility depends on module boundaries and tests: contracts, pure CPU fractal core, D3D12 backend, client adapters, mock payload/probe/random/clock seams, shader parity tests, and deterministic performance fixtures.",