feat(render): Campaign V slice V6k commit 1 - the sky draws on Vulkan

V4f's content, landed as a SECOND arm per section 5.5.6: GL keeps its raw world
path through to V10 and the RHI world path ships on Vulkan. Every GL statement in
SkyRenderer is the one it always issued; the encoder arm lives in SkyRenderer.Rhi.cs
and runs only when there is no GL context.

What it produces. ACDREAM_RENDER_BACKEND=vulkan renders the sky: the dome
quadrants, the horizon band, the cloud sheet and the fog gradient, in the same
place and the same colours as the GL capture of the same scene (within a few
units on the channels sampled, which is the day-fraction drift between two
launches). Section 5.5.15's first V7 defect - "the sky is flat fog" - is closed.

Three things differ from the GL arm, each because Vulkan bakes what GL sets. The
per-submesh blend function becomes two PIPELINES, additive for sun/moon/stars and
straight alpha for everything else, because core Vulkan 1.3 does not make blend
dynamic. The SkyParams block becomes a ring slice taken per draw rather than one
buffer rewritten per draw, because a descriptor's contents are read at execution
time, not record time. And the pass is borrowed from IWorldPassScope, because the
frame's one backbuffer pass resolves and a second pass could not load what it
left.

The sky is the first Vulkan consumer of set 1 binding 4. Section 5.5.8 recorded
that UniformSkyParams was missing from the uniform set layout and V6i-2 added it;
until now nothing had ever bound it.

The stride bug, which is the fourth of its class this campaign. The first Vulkan
sky frame drew the dome as a field of blue-white noise. The RHI vertex layout
declared a 32-byte stride - position, normal, texcoord, exactly what sky.vert
reads - while AcDream.Core.Terrain.Vertex is 36 bytes: it carries a fourth
member, TerrainLayer, that no sky attribute names and that the GL arm never
described to a glVertexAttribPointer but did count, because it says
sizeof(Vertex). Nothing else in the frame looked wrong, no validation rule was
violated, and the offline pixel gate masks the sky band, so only a side-by-side
capture found it. SkyVertexLayoutTests now asserts the REQUIREMENT - the stride
is the uploaded record's footprint - rather than today's number.

The last interim handle table is gone. V4t retired the private
GlBindlessHandleTable in WbDrawDispatcher, EnvCellRenderer, TerrainModernRenderer
and ParticleRenderer and deliberately left the sky's, because the sky is the one
world path that mints its own resident handles from TextureCache's raw GL texture
names rather than interning someone else's. It now registers those handles
through V4t's RegisterWorldTextureHandle seam instead, which is the same
mechanical change the other four took, and the class and its tests are deleted
because nothing else ever used them.

TextureCache gains RegisterWorldSurface(surfaceId, repeat), the sky's RHI texture
source: the same DecodeFromDats the GL path uses, created through
IGpuDevice.CreateTexture and paired with a real sampler object rather than baked
into a bindless handle. Keyed by (surface, wrap) for the same reason the GL arm
keys its handles that way - a table entry is a combined image sampler, so the
dome sampled CLAMP_TO_EDGE and a scrolling cloud sheet sampled REPEAT are two
entries over one decoded texture.

Gates. Release build green. App tests 4,109 passed / 3 skipped - the 4,112
baseline less the six GlBindlessHandleTable tests that went with the class, plus
three vertex-layout tests. Strict GL offline pixel gate against 7ae796a1:
4.43e-05, 25 differing pixels of 563,200, inside the documented 9-31 band, with
maximumChannelDelta 48 in the same 46-52 range every control pair reports. GL
connected repeat gate at 3 runs: 3/3 RENDERED on the desktop witness and 3/3 on
the client capture. Seven-day-group before-and-after comparison on GL - the
method V6e used, because the pixel gate masks the sky band - matching in
gradient, cloud sheet, horizon band and fog on every group, including day group
2's salmon cloud band and day group 6's green band. One offline Vulkan run with
VK_LAYER_KHRONOS_validation proven inserted by the loader: zero validation
errors, zero warnings, a captured sky frame, graceful close.

Coverage gap, stated rather than assumed. The offline scene is a fixed outdoor
view at one time of day, so the sun, the moon and the rain cylinder are drawn by
neither arm's gate. They join the accumulated user-gate debt in plan section 5.1,
where V6e already filed them.

No divergence-register row: no retail-facing behaviour changes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-07-28 16:31:37 +02:00
parent 7ae796a110
commit 22aa2edc65
7 changed files with 618 additions and 293 deletions

View file

@ -1,105 +0,0 @@
using AcDream.App.Rendering;
using Xunit;
namespace AcDream.App.Tests.Rendering;
/// <summary>
/// Campaign V slice V2 (2026-07-27): pure-CPU proof of
/// <see cref="GlBindlessHandleTable"/>'s bookkeeping — the handle→slot
/// allocator each Campaign V-touched renderer (WbDrawDispatcher,
/// EnvCellRenderer, TerrainModernRenderer, ParticleRenderer) owns to back its
/// own binding=9 GL texture table.
/// </summary>
public class GlBindlessHandleTableTests
{
[Fact]
public void GetOrAdd_FirstHandle_AssignsSlotZero_AndMarksDirty()
{
var table = new GlBindlessHandleTable();
uint slot = table.GetOrAdd(0xDEADBEEFu);
Assert.Equal(0u, slot);
Assert.True(table.Dirty);
Assert.Equal(new ulong[] { 0xDEADBEEFu }, table.Handles.ToArray());
}
[Fact]
public void GetOrAdd_SameHandleTwice_ReturnsSameSlot_AndDoesNotDuplicate()
{
var table = new GlBindlessHandleTable();
uint first = table.GetOrAdd(111ul);
table.MarkFlushed();
uint second = table.GetOrAdd(111ul);
Assert.Equal(first, second);
Assert.False(table.Dirty); // no NEW handle was registered
Assert.Single(table.Handles.ToArray());
}
[Fact]
public void GetOrAdd_DistinctHandles_AssignStableIncreasingSlots()
{
var table = new GlBindlessHandleTable();
uint a = table.GetOrAdd(1ul);
uint b = table.GetOrAdd(2ul);
uint c = table.GetOrAdd(3ul);
// Re-querying an already-registered handle must not shift anyone else's slot.
uint aAgain = table.GetOrAdd(1ul);
Assert.Equal(0u, a);
Assert.Equal(1u, b);
Assert.Equal(2u, c);
Assert.Equal(a, aAgain);
Assert.Equal(new ulong[] { 1ul, 2ul, 3ul }, table.Handles.ToArray());
}
[Fact]
public void ZeroHandle_IsRegisteredLikeAnyOther_NotSpecialCased()
{
// The pre-V2 behaviour let a batch/pass carry a literal zero bindless
// handle through to the shader unchanged (an existing "no texture"
// edge case some batches hit). V2 must reproduce that bit-for-bit: a
// zero handle gets a real slot whose table entry is uvec2(0,0) — the
// same value the shader would have received directly before V2.
var table = new GlBindlessHandleTable();
uint slot = table.GetOrAdd(0ul);
Assert.Equal(0u, table.Handles[(int)slot]);
}
[Fact]
public void MarkFlushed_ClearsDirty_UntilNextNewHandle()
{
var table = new GlBindlessHandleTable();
table.GetOrAdd(42ul);
Assert.True(table.Dirty);
table.MarkFlushed();
Assert.False(table.Dirty);
table.GetOrAdd(42ul); // already known — must NOT re-dirty
Assert.False(table.Dirty);
table.GetOrAdd(43ul); // genuinely new — must re-dirty
Assert.True(table.Dirty);
}
[Fact]
public void GetOrAdd_GrowsPastInitialCapacity_WithoutLosingEarlierSlots()
{
var table = new GlBindlessHandleTable();
const int count = 200; // exceeds the 64-entry initial backing array
for (int i = 0; i < count; i++)
{
uint slot = table.GetOrAdd((ulong)i + 1000ul);
Assert.Equal((uint)i, slot);
}
for (int i = 0; i < count; i++)
Assert.Equal((ulong)i + 1000ul, table.Handles[i]);
}
}

View file

@ -0,0 +1,82 @@
using System.Runtime.CompilerServices;
using AcDream.App.Rendering.Gpu;
using AcDream.App.Rendering.Sky;
using AcDream.Core.Terrain;
using Xunit;
namespace AcDream.App.Tests.Rendering;
/// <summary>
/// Campaign V slice V6k: the sky's RHI vertex layout must describe the CPU record
/// the GL arm uploads, not a record that merely looks like it.
///
/// <para>The slice's first Vulkan sky frame drew the dome as a field of noise
/// because the layout declared a 32-byte stride — position + normal + texcoord,
/// which is exactly what <c>sky.vert</c> reads — while
/// <see cref="Vertex"/> is 36 bytes: it carries a fourth member,
/// <c>TerrainLayer</c>, that no sky attribute names. The GL arm has always said
/// <c>sizeof(Vertex)</c> and was unaffected, and nothing else in the frame looked
/// wrong, so only a side-by-side capture caught it.</para>
///
/// <para>The assertion is the REQUIREMENT — "the stride is the record's
/// footprint" — rather than the number, so adding or removing a member of
/// <see cref="Vertex"/> keeps it honest instead of pinning today's answer.</para>
/// </summary>
public class SkyVertexLayoutTests
{
[Fact]
public void SkyVertexLayout_StrideMatchesTheUploadedRecord()
{
Assert.Equal(
(uint)Unsafe.SizeOf<Vertex>(),
SkyRenderer.SkyVertexLayout.StrideBytes);
}
[Fact]
public void SkyVertexLayout_DeclaresTheThreeAttributesTheShaderReads()
{
Assert.Collection(
SkyRenderer.SkyVertexLayout.Attributes,
position =>
{
Assert.Equal(0u, position.Location);
Assert.Equal(GpuVertexFormat.Float3, position.Format);
Assert.Equal(0u, position.OffsetBytes);
},
normal =>
{
Assert.Equal(1u, normal.Location);
Assert.Equal(GpuVertexFormat.Float3, normal.Format);
Assert.Equal(12u, normal.OffsetBytes);
},
texCoord =>
{
Assert.Equal(2u, texCoord.Location);
Assert.Equal(GpuVertexFormat.Float2, texCoord.Format);
Assert.Equal(24u, texCoord.OffsetBytes);
});
}
/// <summary>
/// Every attribute has to fit inside the stride it is read with. A layout that
/// reaches past its own stride is the same defect wearing the other face.
/// </summary>
[Fact]
public void SkyVertexLayout_EveryAttributeFitsInsideTheStride()
{
foreach (GpuVertexAttribute attribute in SkyRenderer.SkyVertexLayout.Attributes)
{
uint size = attribute.Format switch
{
GpuVertexFormat.Float1 => 4u,
GpuVertexFormat.Float2 => 8u,
GpuVertexFormat.Float3 => 12u,
GpuVertexFormat.Float4 => 16u,
_ => 4u,
};
Assert.True(
attribute.OffsetBytes + size <= SkyRenderer.SkyVertexLayout.StrideBytes,
$"Attribute at location {attribute.Location} reaches past the vertex stride.");
}
}
}