Use scalar D3D12 Grid height target

This commit is contained in:
Meta Vens 2026-05-09 13:46:10 +01:00
commit 4b0bf997f4
8 changed files with 20 additions and 16 deletions

View file

@ -33,8 +33,9 @@ resource graph beyond smoke-pass scaffolding.
target in a second fullscreen pass instead of copying it as an opaque resource.
- D3D12 renders the Grid height target as a proper brush pass: frame constants
plus a fixed body brush table feed a base field draw followed by one additive
up-facing gravity quad per body. The target is `R16G16B16A16_Float` so the
additive pass uses supported render-target blending, and mode `11` exposes it.
up-facing gravity quad per body. The target is scalar `R16_Float`: height is
one value, and the format still supports the additive render-target blending
the brush pass needs. Mode `11` exposes it.
- 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

View file

@ -22,7 +22,7 @@ has feature parity.
- The first real migrated pass is the Grid height pass. D3D12 uploads Aquarium
frame constants plus a fixed body brush table, renders a base Grid field, then
draws one additive up-facing gravity quad per body into a 128x128
`R16G16B16A16_Float` Grid height target. Render debug mode `11` displays that
scalar `R16_Float` Grid height target. Render debug mode `11` displays that
target.
- Resize waits for the GPU, releases swapchain-dependent resources, rebuilds
static shader/RTV descriptor arenas, then recreates backbuffer views and

View file

@ -79,7 +79,7 @@ The D3D12 backend has begun migrating this order with a proper brush-based Grid
height pass. It uploads the Aquarium frame constant buffer plus a fixed body
brush table through the D3D12 upload ring, renders the base Grid field, then
draws one additive up-facing gravity quad per body into a 128x128
`R16G16B16A16_Float` Grid height target. D3D12 render debug mode `11` displays
scalar `R16_Float` Grid height target. D3D12 render debug mode `11` displays
that target. D3D11 remains the visual reference until the full pass chain
reaches parity.

View file

@ -15,6 +15,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
{
private const int BackBufferCount = 2;
private const int GridHeightTextureSize = 128;
private const Format GridHeightFormat = Format.R16_Float;
private const int PlanetCount = 5;
private const int GridHeightBrushCount = PlanetCount + 1;
private const string GridShaderRelativePath = "Render/Shaders/D3D12Grid.hlsl";
@ -345,7 +346,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
device,
GridHeightTextureSize,
GridHeightTextureSize,
Format.R16G16B16A16_Float,
GridHeightFormat,
renderTargetViewArena.Allocate(),
staticShaderDescriptorArena.Allocate(),
null,
@ -648,7 +649,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
private ID3D12PipelineState CreateGridHeightBasePipelineState(string path)
{
return CreateFullscreenPipelineState(path, "FullscreenTriangleVS", "D3D12GridHeightBasePS", Format.R16G16B16A16_Float);
return CreateFullscreenPipelineState(path, "FullscreenTriangleVS", "D3D12GridHeightBasePS", GridHeightFormat);
}
private ID3D12PipelineState CreateGridHeightBrushPipelineState(string path)
@ -657,7 +658,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
path,
"D3D12GridHeightBrushVS",
"D3D12GridHeightBrushPS",
Format.R16G16B16A16_Float,
GridHeightFormat,
new BlendDescription(Blend.One, Blend.One, Blend.One, Blend.One));
}

View file

@ -76,12 +76,12 @@ VertexOut FullscreenTriangleVS(uint vertexId : SV_VertexID)
return output;
}
float4 D3D12GridHeightBasePS(VertexOut input) : SV_Target
float D3D12GridHeightBasePS(VertexOut input) : SV_Target
{
float2 world = gridWorld(saturate(input.uv));
float slow = sin((world.x * 0.08 + world.y * 0.06) + timeSeconds * 0.27)
* sin((world.x * -0.04 + world.y * 0.07) - timeSeconds * 0.19) * 0.035;
return float4(slow, 0.0, 0.0, 1.0);
return slow;
}
BrushVertexOut D3D12GridHeightBrushVS(uint vertexId : SV_VertexID, uint instanceId : SV_InstanceID)
@ -110,12 +110,12 @@ BrushVertexOut D3D12GridHeightBrushVS(uint vertexId : SV_VertexID, uint instance
return output;
}
float4 D3D12GridHeightBrushPS(BrushVertexOut input) : SV_Target
float D3D12GridHeightBrushPS(BrushVertexOut input) : SV_Target
{
float2 world = gridWorld(saturate(input.uv));
float distanceValue = length(world - input.centerRadius.xy);
float well = powerPulse(distanceValue, input.centerRadius.z, input.shape.x);
float ripple = sin(distanceValue * input.wave.y - timeSeconds * input.wave.z);
float signedHeight = input.shape.y * well + ripple * well * input.wave.x;
return float4(signedHeight, 0.0, 0.0, 0.0);
return signedHeight;
}

View file

@ -71,4 +71,5 @@
{"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 exposed the Grid height target and frame-constant path, but its original fullscreen per-texel body loop was intentionally superseded by a brush-rendered pass. 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"}
{"area":"renderer/d3d12","lesson":"The D3D12 Grid height pass must be a real gravity brush pass, not a fullscreen shader loop over every body per texel. It now renders a base field, uploads a small body brush constant table, and draws one additive up-facing quad per body into a 128x128 R16G16B16A16_Float target. R32G32B32A32_Float is the wrong target format for additive blending here. The root signature must expose frame constants to the vertex shader because the brush vertex shader performs the top-down Grid-space orthographic transform.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Grid.hlsl","docs/d3d12-migration.md","docs/d3d12-best-practices-audit.md","docs/hlsl-renderer.md","state/memory.json","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 and AQUARIUM_RENDER_DEBUG_MODE=11 exited 0","dotnet build Aquarium.Engine.slnx",".\\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"}
{"area":"renderer/d3d12","lesson":"The D3D12 Grid height pass must be a real gravity brush pass, not a fullscreen shader loop over every body per texel. It renders a base field, uploads a small body brush constant table, and draws one additive up-facing quad per body into a 128x128 scalar R16_Float target. R32G32B32A32_Float is the wrong target format for additive blending here, and extra channels are waste unless the pass contract actually stores extra data. The root signature must expose frame constants to the vertex shader because the brush vertex shader performs the top-down Grid-space orthographic transform.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Grid.hlsl","docs/d3d12-migration.md","docs/d3d12-best-practices-audit.md","docs/hlsl-renderer.md","state/memory.json","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 and AQUARIUM_RENDER_DEBUG_MODE=11 exited 0","dotnet build Aquarium.Engine.slnx",".\\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"}
{"area":"renderer/d3d12","lesson":"A Grid height target is scalar. The D3D12 brush-rendered Grid height pass should use R16_Float and scalar pixel-shader outputs; four float channels were defensive waste after the R32G32B32A32_Float blend failure, not a real contract. Add channels only when the pass explicitly stores more than height.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Grid.hlsl","docs/d3d12-migration.md","docs/d3d12-best-practices-audit.md","docs/hlsl-renderer.md","state/memory.json","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 and AQUARIUM_RENDER_DEBUG_MODE=11 exited 0","dotnet build Aquarium.Engine.slnx",".\\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"}

View file

@ -17,7 +17,7 @@
"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 Grid height must be brush-rendered, not a fullscreen per-texel loop over bodies. Use a top-down Grid-space orthographic brush pass: base field draw, then one additive up-facing quad per body into a blendable float target. Do not use R32G32B32A32_Float for additive brush composition; use a blendable format such as R16G16B16A16_Float unless a later reason overrides it.",
"D3D12 Grid height must be brush-rendered, not a fullscreen per-texel loop over bodies. Use a top-down Grid-space orthographic brush pass: base field draw, then one additive up-facing quad per body into a scalar R16_Float height target. Height is one value; do not spend extra channels unless the pass contract actually gains more data. Do not use R32G32B32A32_Float for additive brush composition.",
"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.",

View file

@ -273,8 +273,9 @@ can start porting real passes while keeping D3D11 as the visual reference.
fullscreen per-texel body loop. That was the wrong architecture. The D3D12
Grid height pass now behaves like Aetheria's gravity layer: a base Grid field
draw, then one additive up-facing quad per body, driven by a small uploaded
brush table. The target is `R16G16B16A16_Float` because additive blending is
not the right bet on `R32G32B32A32_Float`. Render debug mode `11` displays the
height target. Temporal previous camera/Grid/time state is renderer-level
brush table. The target is scalar `R16_Float`: height is one value, and
additive blending works on that format where `R32G32B32A32_Float` was the
wrong bet. Render debug mode `11` displays the height target. 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.