Move grid brush packing out of renderer

This commit is contained in:
Meta Vens 2026-05-12 04:03:43 +01:00
commit 55fa5e82cb
3 changed files with 105 additions and 95 deletions

View file

@ -1,4 +1,5 @@
using Aquarium.Engine.Input;
using Aquarium.Engine.Render.Features;
using Aquarium.Engine.Render.Graph;
using SharpGen.Runtime;
using Aquarium.Engine.Render.Ui;
@ -26,7 +27,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
private const int GridHeightTextureSize = 128;
private const Format GridHeightFormat = Format.R16_Float;
private const Format SceneDepthFormat = Format.D32_Float;
private const int MaxGridHeightBrushCount = 8;
private const int MaxBodyLightCount = 64;
private const int MaxBodyVisualCount = 64;
private const float GridTransparentMinZ = -1.85f;
@ -96,7 +96,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
private readonly D3D12CubeTexture studioIrradianceTexture;
private readonly AquariumBodyLight[] bodyLights = new AquariumBodyLight[MaxBodyLightCount];
private readonly AquariumBodyVisual[] bodyVisuals = new AquariumBodyVisual[MaxBodyVisualCount];
private readonly AquariumGridHeightBrush[] gridHeightBrushes = new AquariumGridHeightBrush[MaxGridHeightBrushCount];
private Viewport viewport;
private RawRect scissorRect;
private int width;
@ -109,7 +108,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
private Vector2 previousCursorWorld;
private float previousGridRadius = 0.001f;
private float previousTimeSeconds;
private GridHeightBrushConstants gridHeightBrushConstants;
private D3D12GridHeightBrushConstants gridHeightBrushConstants;
private GraphicsSettings settings = GraphicsSettings.Default;
private double accumulatedFrameCpuMilliseconds;
private double accumulatedRecordCpuMilliseconds;
@ -1107,7 +1106,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
activeCommandList.DrawInstanced(3, 1, 0, 0);
activeCommandList.SetPipelineState(gridHeightBrushPipelineState!);
activeCommandList.SetGraphicsRootDescriptorTable(2, frameResources.GridBrushConstantsDescriptor.Gpu);
activeCommandList.DrawInstanced(6, MaxGridHeightBrushCount, 0, 0);
activeCommandList.DrawInstanced(6, D3D12GridHeightBrushConstants.MaxBrushCount, 0, 0);
}
finally
{
@ -1117,22 +1116,9 @@ public sealed class D3D12Renderer : IAquariumRenderer
private void CopySceneState(AquariumSceneState scene)
{
Array.Clear(gridHeightBrushes);
Array.Clear(bodyVisuals);
Array.Clear(bodyLights);
gridHeightBrushConstants = default;
var brushCount = Math.Min(scene.GridHeightBrushes.Count, MaxGridHeightBrushCount);
for (var index = 0; index < brushCount; index++)
{
var brush = scene.GridHeightBrushes[index];
gridHeightBrushes[index] = brush;
gridHeightBrushConstants.Set(
index,
new Vector4(brush.Center, brush.Radius, 0.0f),
new Vector4(brush.Power, brush.Amplitude, 0.0f, 0.0f),
new Vector4(brush.WaveAmplitude, brush.WaveFrequency, brush.WaveSpeed, brush.WaveSinePower));
}
gridHeightBrushConstants = D3D12GridHeightBrushConstants.FromBrushes(scene.GridHeightBrushes);
var visualCount = Math.Min(scene.BodyVisuals.Count, MaxBodyVisualCount);
for (var index = 0; index < visualCount; index++)
@ -1771,83 +1757,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
float BloomVeilIntensity,
Vector4 CursorWorlds);
[StructLayout(LayoutKind.Sequential)]
private record struct GridHeightBrushConstants(
Vector4 CenterRadius0,
Vector4 CenterRadius1,
Vector4 CenterRadius2,
Vector4 CenterRadius3,
Vector4 CenterRadius4,
Vector4 CenterRadius5,
Vector4 CenterRadius6,
Vector4 CenterRadius7,
Vector4 Shape0,
Vector4 Shape1,
Vector4 Shape2,
Vector4 Shape3,
Vector4 Shape4,
Vector4 Shape5,
Vector4 Shape6,
Vector4 Shape7,
Vector4 Wave0,
Vector4 Wave1,
Vector4 Wave2,
Vector4 Wave3,
Vector4 Wave4,
Vector4 Wave5,
Vector4 Wave6,
Vector4 Wave7)
{
public void Set(int index, Vector4 centerRadius, Vector4 shape, Vector4 wave)
{
switch (index)
{
case 0:
CenterRadius0 = centerRadius;
Shape0 = shape;
Wave0 = wave;
break;
case 1:
CenterRadius1 = centerRadius;
Shape1 = shape;
Wave1 = wave;
break;
case 2:
CenterRadius2 = centerRadius;
Shape2 = shape;
Wave2 = wave;
break;
case 3:
CenterRadius3 = centerRadius;
Shape3 = shape;
Wave3 = wave;
break;
case 4:
CenterRadius4 = centerRadius;
Shape4 = shape;
Wave4 = wave;
break;
case 5:
CenterRadius5 = centerRadius;
Shape5 = shape;
Wave5 = wave;
break;
case 6:
CenterRadius6 = centerRadius;
Shape6 = shape;
Wave6 = wave;
break;
case 7:
CenterRadius7 = centerRadius;
Shape7 = shape;
Wave7 = wave;
break;
default:
throw new ArgumentOutOfRangeException(nameof(index), index, "Grid height brush index is outside the fixed brush table.");
}
}
}
private sealed record D3D12ShaderPaths(
string Grid,
string Scene,

View file

@ -0,0 +1,100 @@
using System.Numerics;
using System.Runtime.InteropServices;
namespace Aquarium.Engine.Render.Features;
[StructLayout(LayoutKind.Sequential)]
internal record struct D3D12GridHeightBrushConstants(
Vector4 CenterRadius0,
Vector4 CenterRadius1,
Vector4 CenterRadius2,
Vector4 CenterRadius3,
Vector4 CenterRadius4,
Vector4 CenterRadius5,
Vector4 CenterRadius6,
Vector4 CenterRadius7,
Vector4 Shape0,
Vector4 Shape1,
Vector4 Shape2,
Vector4 Shape3,
Vector4 Shape4,
Vector4 Shape5,
Vector4 Shape6,
Vector4 Shape7,
Vector4 Wave0,
Vector4 Wave1,
Vector4 Wave2,
Vector4 Wave3,
Vector4 Wave4,
Vector4 Wave5,
Vector4 Wave6,
Vector4 Wave7)
{
public const int MaxBrushCount = 8;
public static D3D12GridHeightBrushConstants FromBrushes(IReadOnlyList<AquariumGridHeightBrush> brushes)
{
var constants = new D3D12GridHeightBrushConstants();
var brushCount = Math.Min(brushes.Count, MaxBrushCount);
for (var index = 0; index < brushCount; index++)
{
var brush = brushes[index];
constants.Set(
index,
new Vector4(brush.Center, brush.Radius, 0.0f),
new Vector4(brush.Power, brush.Amplitude, 0.0f, 0.0f),
new Vector4(brush.WaveAmplitude, brush.WaveFrequency, brush.WaveSpeed, brush.WaveSinePower));
}
return constants;
}
private void Set(int index, Vector4 centerRadius, Vector4 shape, Vector4 wave)
{
switch (index)
{
case 0:
CenterRadius0 = centerRadius;
Shape0 = shape;
Wave0 = wave;
break;
case 1:
CenterRadius1 = centerRadius;
Shape1 = shape;
Wave1 = wave;
break;
case 2:
CenterRadius2 = centerRadius;
Shape2 = shape;
Wave2 = wave;
break;
case 3:
CenterRadius3 = centerRadius;
Shape3 = shape;
Wave3 = wave;
break;
case 4:
CenterRadius4 = centerRadius;
Shape4 = shape;
Wave4 = wave;
break;
case 5:
CenterRadius5 = centerRadius;
Shape5 = shape;
Wave5 = wave;
break;
case 6:
CenterRadius6 = centerRadius;
Shape6 = shape;
Wave6 = wave;
break;
case 7:
CenterRadius7 = centerRadius;
Shape7 = shape;
Wave7 = wave;
break;
default:
throw new ArgumentOutOfRangeException(nameof(index), index, "Grid height brush index is outside the fixed brush table.");
}
}
}

View file

@ -5,6 +5,7 @@
{"timestamp":"2026-05-12T03:40:00+01:00","topic":"epiphany-render-policy-extraction","lesson":"Epiphany body shaders, Grid brush construction, body visual/light tables, and cursor projection moved behind Aquarium.Engine.Contracts. Aquarium.Engine now consumes AquariumRenderPlan and AquariumSceneState data and passes scripts/verify-boundaries.ps1 with no Epiphany role/client names in engine source.","files":["src/Aquarium.Engine.Contracts/Render/AquariumApp.cs","src/Aquarium.Engine.Contracts/Render/AquariumRenderPlan.cs","src/Aquarium.Epiphany/EpiphanyRenderPlan.cs","src/Aquarium.Epiphany/EpiphanySceneBuilder.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","scripts/verify-boundaries.ps1","state/memory.json","state/map.yaml"]}
{"timestamp":"2026-05-12T03:50:00+01:00","topic":"graph-target-allocation","lesson":"The render graph compiler now validates declared targets/passes and D3D12Renderer allocates non-legacy client-declared render targets through engine resource/descriptors, including resize rebuild. This is allocation only; full graph pass execution remains the next cut.","files":["src/Aquarium.Engine/Render/Graph/D3D12RenderGraphCompiler.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine.Contracts/Render/AquariumApp.cs","state/memory.json"]}
{"timestamp":"2026-05-12T04:00:00+01:00","topic":"minimal-non-epiphany-client","lesson":"Aquarium now includes src/Aquarium.Sample.Minimal, a non-Epiphany client that references only Aquarium.Engine.Contracts, declares a minimal render plan, and boots through the same host/client assembly loader. Keep it as a boundary proof while the graph executor replaces legacy fixed passes.","files":["src/Aquarium.Sample.Minimal/MinimalRuntime.cs","src/Aquarium.Sample.Minimal/Aquarium.Sample.Minimal.csproj","README.md","state/map.yaml"]}
{"timestamp":"2026-05-12T04:05:00+01:00","topic":"grid-brush-gpu-packing","lesson":"GridHeightBrushConstants is D3D12 GPU packing for the height-field brush pass, not scene policy. Keep brush authoring in the client, keep packing in engine feature code, and keep D3D12Renderer limited to upload/command recording until the height-field pass moves fully into the graph executor.","files":["src/Aquarium.Engine/Render/Features/D3D12GridHeightBrushConstants.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","state/evidence.jsonl"]}
{"timestamp":"2026-05-10T07:47:46+01:00","topic":"cursor-teardrop-sdf","lesson":"Use the MathWorld teardrop curve for the cursor profile with m=6, revolved into an SDF locator. Keep ripples as geometry, material as brass GGX metal, and avoid ambient fill.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json"],"source":"https://mathworld.wolfram.com/TeardropCurve.html"}
{"timestamp":"2026-05-11T00:00:00+01:00","topic":"aquarium-focus-cut","lesson":"Runtime volumetrics, cloud/fog research, and the D3D11 scene renderer are shelved because they distract from Aquarium's Epiphany-client mission. Git history holds the experiment; live repo state should not preserve compatibility husks or dead guidance for removed medium settings.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine.Contracts/GraphicsSettings.cs","state/map.yaml","state/memory.json","state/scratch.md"]}
{"timestamp":"2026-05-11T04:20:00+01:00","topic":"medium-froxel-purge","lesson":"Medium/froxel render targets, structured buffers, shader bindings, scene outputs, post history lanes, and medium debug paths were removed from the live D3D12 renderer. Future atmospheric or field transport work needs a new explicit pass contract rather than reviving shelved scaffolding.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","state/map.yaml","state/memory.json"]}