fix(render): S3 chunk 4 round 2 — draw-gate condition pinned, scissor and terrain-clip stacks deleted, one outside-view slice constructor

Round-1 three-lens FAIL at d60ca4ea0 found: the K2 fix was right in
production but nothing pinned the draw side (restoring the pre-fix gate
left every lane green); a stale "still ends an active scissor" comment
asserted a mechanism the same round had already deleted; the sky.vert
comment claimed retail clips the sky when it draws unclipped; the K6
pin ran through ClipFrameAssembler.Assemble, which has zero production
callers, so it proved nothing about the producer that actually runs.
This round closes L1-L9.

L1 (BLOCKING) — draw-side weather-gate pin. Added
RetailPViewPassExecutorTests.DrawLandscapeDynamicsPhase_GatesDrawWeatherOnceOnWalkDriverWeatherTurnFired:
reads DrawLandscapeDynamicsPhase's compiled call graph and asserts (a)
the call immediately before DrawWeatherOnce is
WalkFrameDriver.get_WeatherTurnFired and (b) exactly one
brfalse/brfalse.s branch sits between that call and the draw, jumping
forward past it. Three mutations, each shown failing:

  M1 (restore `if (clipAssembly.OutsideViewSlices.Length != 0)`):
    Assert.Equal() Failure: Values differ
    Expected: typeof(AcDream.App.Rendering.Walk.WalkFrameDriver)
    Actual:   typeof(AcDream.App.Rendering.ClipFrameAssembly)

  M2 (drop the gate, unconditional call):
    Assert.Equal() Failure: Values differ
    Expected: typeof(AcDream.App.Rendering.Walk.WalkFrameDriver)
    Actual:   typeof(AcDream.App.Rendering.RetailPViewPassExecutor)

  M3 (invert to `if (!walkDriver.WeatherTurnFired)`):
    Assert.Single() Failure: The collection did not contain any matching items
    Expected:   (predicate expression)
    Collection: [CompiledBranch { Offset = 7, OpCode = brfalse.s, TargetOffset = 17 }, CompiledBranch { Offset = 24, OpCode = brtrue.s, TargetOffset = 33 }]

Corrected WalkFrameDriverTranscriptTests.cs's doc comment (the
Collect_WeatherTurnFiredMatchesThePrintedOcLineExactly block): it pins
the print half and the flag only, and now names the real draw-side pin
instead of falsely claiming to double as one.

L2 (MAJOR) — scissor stack deleted, K4 comment corrected. Deleted
IWorldPassSurface.BeginScissor/EndScissor and their RhiWorldPassSurface
bodies, the scissor call inside ClearInteriorDepth, NdcScissorRect.cs +
NdcScissorRectTests.cs (BeginScissor had zero remaining callers, and
RhiWorldPassSurface.BeginScissor was NdcScissorRect.ToPixels' only
production caller). This left RhiWorldPassSurface's 4th constructor
parameter (IRetailPViewFramebufferSource) and RetailPViewPassExecutor.cs's
RetailPViewFramebufferSize/IRetailPViewFramebufferSource/
SilkRetailPViewFramebufferSource types entirely dead (framebuffer size
was needed only for the scissor's NDC-to-pixel conversion) — removed
them and their one call site in FrameRootComposition.cs. Rewrote
RetailPViewPassExecutor.cs's K4 comment: it no longer asserts a live
scissor mechanism; it states that VulkanGpuPassEncoder's constructor
sets the full-attachment scissor once, at pass begin
(VulkanGpuPassEncoder.cs:87), and nothing narrows it after that. KEPT
per the round-1 verdict: ScissorFallbacks, OutsidePlaneCount,
OutsideViewNdcAabb, HasOutsideView, OutdoorVisible, OutdoorSlot,
ClipViewSlice.NdcAabb (the >8-edge zero-plane slice case the punch fans
still consume) and the VulkanViewportMapping.ScissorToVulkan pass-begin
path (IGpuPassEncoder.SetScissor stays). Also deleted
ClipFrameAssembly.TerrainMode/TerrainScissorNdcAabb and their writers
in ClipFrameAssembler.cs (both Assemble and ReassembleOutsideViewFromWalk);
OutsidePlaneCount's formula reduces to `outsideHasScissorFallback ? 0 :
outsideMaxPlaneCount` without needing the deleted TerrainClipMode
comparison (a scissor-fallback slice can only exist when outdoorVisible
is already true, so the three original cases collapse identically).
Deleted the two "terrain=" / "outMode=" diagnostic reads in
WorldRenderDiagnostics.cs (:345, :409) and the now-vestigial
EmitClipRouteProbe "ubo: n=..." segment that read ClipFrame's deleted
terrain bytes.

DEVIATION from L2's literal text: kept the TerrainClipMode enum type
itself — WorldSceneRenderer.cs's flat-world safety path (explicitly
"out of this chunk's scope" per K4's own round-1 comment) still uses it
for an unrelated "did the flat terrain draw" diagnostic flag, with its
own WorldSceneDiagnosticsController/WorldRenderDiagnostics/test
consumers. Deleting the type would require rewriting files outside
every round's declared file list. Reworded its doc comment to state
this plainly.

L3 (MAJOR, completes K3) — dead TerrainClip UBO deleted from the sky
and terrain shaders. Deleted the block, both gl_ClipDistance loops, and
the gl_PerVertex redeclaration (nothing else needs it) from sky.vert,
terrain_modern.vert, terrain_atmospheric.vert. Recompiled via
tools/compile-shaders.ps1 (glslc via the Vulkan SDK, managed shaderc
fallback also runs) — 24/24 pairs compiled; only sky.vert.spv,
terrain_atmospheric.vert.spv and terrain_modern.vert.spv changed.
Re-pinned VulkanShaderManifestTests.cs's frozen retail-oracle hashes
for sky.vert.spv (7d67a9e3624d198b370d402b5c12e4ce925bf9b8e646ef5123636a86d5985ab5)
and terrain_modern.vert.spv (8a73d89ef0e51e550327b9ff8c24857e309103b1d491030cf0d4d8594b45068c)
with dated comments, matching the existing re-pin convention.

Deleted WorldFrameSectionBinding.BindTerrainClip and
WorldFrameSections.TerrainClip (+ its Reset) with its two callers
(SkyRenderer.Rhi.cs:258, TerrainModernRenderer.Rhi.cs:259). DEVIATION
from L3's literal text: kept the shared Zeroed(...) helper in
WorldPassScope.cs — it is also called by BindSceneLighting and
BindClipRegions, both of which stay; deleting it would have broken
those two live bindings. Deleted IWorldPassSurface.BindTerrainClip
(no-op interface method + RhiWorldPassSurface body) and
WorldScenePassExecutor.cs's two calls to it (:121, :235).

Deleted ClipFrame's _terrainBytes field, TerrainBytes/TerrainBytesForTest
properties, Reset's Array.Clear(_terrainBytes), and the stale
header/K3 comment paragraphs. DEVIATION from L3's literal text: kept
ClipFrame.TerrainUboBytes and ClipFrame.TerrainClipUboBinding —
PortalDepthMaskRenderer.Rhi.cs (:140, :187) is a live production
consumer of both constants for the KEPT exit-seal/punch-fan clip block,
which was never in scope for deletion (portal_depth.vert's own
TerrainClip UBO declaration is the KEEP block, untouched). Reworded
both constants' doc comments (ClipFrame.cs, VulkanPipelineLayouts.cs's
UniformTerrainClip) to say only the portal-depth clip block uses
binding 2 now, and corrected the two GpuBindingModel.cs comments that
explained why terrain-tiling/sky-params bindings are 3/4 by naming "the
terrain clip block". Updated VulkanShaderDescriptorContractTests.cs's
TerrainVertexShaderDeclaresItsClipBlockInTheUniformSet (renamed
TerrainVertexShaderDeclaresOnlySceneLightingInTheUniformSet):
terrain_modern.vert's uniform set is now {SceneLighting} only. Deleted
ClipFrameLayoutTests.NoClip_TerrainBytes_Count0_AllZeros and its K3
comment; corrected the class doc comment and LayoutConstants_MatchShaderStruct's
"terrain UBO"/binding-contract comments to describe the portal-depth
consumer instead.

REQUIRED L3 fact (declared-but-never-bound dynamic uniform binding):
VulkanFrameBindings's constructor seeds EVERY declared uniform binding
(0..UniformBindingCount-1, including binding 2) with the shared dummy
buffer's range before any renderer runs (VulkanFrameBindings.cs:128-130,
`_arena.SeedUniform(binding, dummy.Handle.Handle, dummyUniformRange)`
in a loop over every binding) — "Every binding is always bound, whether
a renderer uses it or not... unused ones point at a shared dummy range"
(VulkanFrameBindings.cs:27-31). So after this round, when the sky or
terrain pipeline draws, set 1's shared descriptor layout still declares
binding 2 (portal_depth.vert's own declaration keeps
IsDeclaredUniformBinding(2) true), and its descriptor still points at a
valid (dummy) range from that seed — vkCmdBindDescriptorSets stays
legal even though neither shader statically uses binding 2 any more.
No SPIR-V-side change was needed to keep this legal.

L4 (MAJOR) — one outside-view slice constructor. Extracted
ClipFrameAssembler.AppendOutsideSlice (frame, ViewPolygon,
outsideSlicesList, ref maxPlaneCount, ref hasScissorFallback, ref
scissorFallbacks) — the exact ClipPlaneSet.From/AppendSlot/
ClipViewSlice-construction body — and call it from both Assemble's
outside_view loop and ReassembleOutsideViewFromWalk's outside_view
loop. Rewrote ClipFrameLayoutTests's K6 pin
(ClipViewSlicePlanes_PunchFanPath_EqualsCpuViewPolygonEdgePlanes_ForASyntheticView):
builds a synthetic WalkPortalView from pixel-space points (the
WalkCopyViewTests pattern) via a trivial IWalkRayCaster, runs
BeginWalkFrame(frame, outdoorRoot: false) then
ReassembleOutsideViewFromWalk(assembly, walkView, 640, 480), and reads
assembly.OutsideViewSlices[0].Planes — the exact production pair
RetailPViewPassExecutor.cs's BeginWalkFrame call and
RetailPViewRenderer.cs's ReassembleOutsideViewFromWalk call make.
Mutation (perturbed planes[0].W inside the shared helper, right after
`planes = cps.PlaneArray;`):

  edge 0 midpoint (-0.3,0.10000001) should lie ~on its OWN GPU plane; the closest plane was only 0.5251073 away

The pin's own source contains no `Assemble(` call — grep-checked by
extracting the method body and searching it for the literal text; no
match.

L5 — shader comments corrected. sky.vert/terrain_modern.vert/
terrain_atmospheric.vert now state retail draws the sky once
(LScape::draw @0x00506330 -> GameSky::Draw(sky,0) @0x0050633c, before
draw_check_blocks) and the landscape is view-culled per cell, never
GPU-clipped (RenderDeviceD3D::DrawBlock @0x005a17c0). The "Phase W
Stage 4"/"U.3 default" clip narratives are deleted along with the
blocks they described.

L6 — grep sweep. `grep -rn "<token>" src tests docs/architecture`
returns nothing for SetTerrainClip, BeginDoorwayScissor,
BindTerrainClip, TerrainBytes, "active scissor", and NdcScissorRect —
confirmed after this commit (docs/plans and docs/research keep the
historical record, untouched). TerrainClipMode is the one deliberate
exception (see the L2 deviation note above); every one of its 9
remaining hits is a live, non-stale reference (the enum declaration,
WorldSceneRenderer's flat-path local, or their diagnostic/test
plumbing), not a stale mention of a deleted mechanism.

L7 — Issue130DoorwayStripTests. Deleted AnySliceAdmitsScissor,
worstScissorGapPx and its PIN 1 assertion, the header's scissor
sentences, and the scissorGap half of MeasureTopEdgeGap (dropped the
fbW parameter it alone needed). Rewrote the header: the scissor
mechanism is retired (the sky and landscape draw unclipped; aperture
exactness comes from the depth clear, the exit seals and the interior
repaint). The remaining plane-gap half (the canary PIN,
`worstPlaneGapPx <= 1.2f`) still pins something production reads:
AnySliceAdmitsPlanes walks slice.Planes from the SAME ProjectToClip ->
ClipToRegion -> ClipPlaneSet.From pipeline
RetailPViewPassExecutor.DrawWalkPunchFan reads through
clipAssembly.OutsideViewSlices[activeViewIndex].Planes — so the test
was kept, not deleted.

L8 — DrawWalkSky loop-shape pin. Added
DrawWalkSky_RenderSkyCallSiteHasNoEnclosingBackwardBranch (same
backward-branch-span shape as K1's DrawWeatherOnce pin), plus a note in
both pins that CompiledCallGraph.ReadBranches does not decode a
compiled switch jump table, but no C# loop construct compiles to one.
Mutation (wrapped the RenderSky call in `for (int i = 0; i < 2; i++)`):

  Assert.DoesNotContain() Failure: Filter matched in collection
  Collection: [..., CompiledBranch { Offset = 20, OpCode = brtrue.s, TargetOffset = 25 }, CompiledBranch { Offset = 23, OpCode = br.s, TargetOffset = 66 }, CompiledBranch { Offset = 72, OpCode = blt.s, TargetOffset = 13 }, CompiledBranch { Offset = 80, OpCode = brfalse.s, TargetOffset = 116 }, CompiledBranch { Offset = 88, OpCode = brfalse.s, TargetOffset = 116 }]

(the Offset=72 -> TargetOffset=13 entry is the injected loop's backward
branch spanning the call).

L9 — this message.

Gates: dotnet build 0 warnings / 0 errors. Hermetic filter
(Lane!=InstalledDat&...&Status!=KnownFailure): 6827 passed, 0 failed.
InstalledDat lane against a real DAT directory: 244 passed, 4 failed —
exactly the four known failures (LayoutImporterMediaBearingChildSweepTests
+ LayoutImporterInvisibleSweepTests, both #383; TowerAscentReplayTests,
KnownFailure; WalkTraceConformanceTests.Oh_doorway_still_first_frame_diff,
#458 KnownFailure). No register row added (every deletion here removes
an acdream-only rule; the KEEP items already had their equivalence
pins from round 1). No new flag/probe.

OWED: the lead's ACDREAM_DEVTOOLS=1 four-pose visual self-gate against
the running client is not run by this agent — CLAUDE.md and this
task's own instructions forbid launching the graphical client from
here; that visual/validation-layer pass remains the user's to run
before this round is accepted.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-09-03 15:11:21 +02:00
parent ff607a1e04
commit 7df0b94c9f
32 changed files with 832 additions and 991 deletions

View file

@ -38,7 +38,6 @@ public class ClipFrameAssemblerTests
Assert.Equal(new Vector4(-1f, -1f, 1f, 1f), slice.NdcAabb);
Assert.True(assembly.OutdoorVisible);
Assert.True(assembly.HasOutsideView);
Assert.Equal(TerrainClipMode.Scissor, assembly.TerrainMode);
Assert.Equal(1, frame.SlotCount);
}
@ -59,7 +58,6 @@ public class ClipFrameAssemblerTests
Assert.Empty(assembly.OutsideViewSlices);
Assert.False(assembly.OutdoorVisible);
Assert.False(assembly.HasOutsideView);
Assert.Equal(TerrainClipMode.Skip, assembly.TerrainMode);
Assert.Equal(Vector4.Zero, assembly.OutsideViewNdcAabb);
Assert.Equal(0, assembly.ScissorFallbacks);
Assert.Equal(1, frame.SlotCount);
@ -93,7 +91,6 @@ public class ClipFrameAssemblerTests
Assert.NotEqual(0, asm.OutdoorSlot);
Assert.Single(asm.OutsideViewSlices);
Assert.Equal(asm.OutdoorSlot, asm.OutsideViewSlices[0].Slot);
Assert.Equal(TerrainClipMode.Planes, asm.TerrainMode);
Assert.Equal(4, asm.OutsidePlaneCount);
Assert.Equal(0, asm.ScissorFallbacks);
}
@ -117,7 +114,6 @@ public class ClipFrameAssemblerTests
Assert.DoesNotContain(cellB, asm.CellIdToSlot.Keys);
Assert.False(asm.OutdoorVisible);
Assert.Empty(asm.OutsideViewSlices);
Assert.Equal(TerrainClipMode.Skip, asm.TerrainMode);
Assert.Equal(0, asm.OutsidePlaneCount);
}
@ -138,11 +134,9 @@ public class ClipFrameAssemblerTests
Assert.NotEqual(0, asm.OutdoorSlot);
Assert.Equal(2, asm.OutsideViewSlices.Length);
Assert.NotEqual(asm.OutsideViewSlices[0].Slot, asm.OutsideViewSlices[1].Slot);
Assert.Equal(TerrainClipMode.Planes, asm.TerrainMode);
Assert.Equal(4, asm.OutsidePlaneCount);
Assert.Equal(0, asm.ScissorFallbacks);
Assert.Equal(4, asm.Frame.SlotCount); // slot 0 + cell + two outside slices
Assert.Equal(Vector4.Zero, asm.TerrainScissorNdcAabb);
}
[Fact]
@ -167,7 +161,6 @@ public class ClipFrameAssemblerTests
Assert.Single(asm.OutsideViewSlices);
Assert.Equal(4, asm.Frame.SlotCount); // slot 0 + two cell slices + outside slice
Assert.Equal(0, asm.ScissorFallbacks);
Assert.Equal(TerrainClipMode.Planes, asm.TerrainMode);
}
[Fact]
@ -179,7 +172,6 @@ public class ClipFrameAssemblerTests
var asm = ClipFrameAssembler.Assemble(ClipFrame.NoClip(), pv);
Assert.True(asm.HasOutsideView);
Assert.Equal(TerrainClipMode.Planes, asm.TerrainMode);
Assert.Single(asm.OutsideViewSlices);
var expected = new Vector4(
@ -198,14 +190,12 @@ public class ClipFrameAssemblerTests
var asm = ClipFrameAssembler.Assemble(ClipFrame.NoClip(), pv);
Assert.True(asm.HasOutsideView);
Assert.Equal(TerrainClipMode.Planes, asm.TerrainMode);
Assert.Equal(2, asm.OutsideViewSlices.Length);
var expected = new Vector4(
pv.OutsideView.MinX, pv.OutsideView.MinY,
pv.OutsideView.MaxX, pv.OutsideView.MaxY);
Assert.Equal(expected, asm.OutsideViewNdcAabb);
Assert.Equal(Vector4.Zero, asm.TerrainScissorNdcAabb);
}
[Fact]
@ -219,7 +209,6 @@ public class ClipFrameAssemblerTests
var asm = ClipFrameAssembler.Assemble(ClipFrame.NoClip(), pv);
Assert.False(asm.HasOutsideView);
Assert.Equal(TerrainClipMode.Skip, asm.TerrainMode);
Assert.Equal(Vector4.Zero, asm.OutsideViewNdcAabb);
}
@ -246,7 +235,6 @@ public class ClipFrameAssemblerTests
Assert.Contains(0xA9B40200, asm2.CellIdToSlot.Keys);
Assert.DoesNotContain(0xA9B40100, asm2.CellIdToSlot.Keys);
Assert.False(asm2.OutdoorVisible);
Assert.Equal(TerrainClipMode.Skip, asm2.TerrainMode);
}
[Fact]
@ -295,7 +283,6 @@ public class ClipFrameAssemblerTests
Assert.Empty(cleared.CellIdToViewSlices);
Assert.Empty(cleared.PerCellPlaneCounts);
Assert.Empty(cleared.OutsideViewSlices);
Assert.Equal(TerrainClipMode.Skip, cleared.TerrainMode);
}
[Fact]

View file

@ -1,15 +1,16 @@
using System.Numerics;
using AcDream.App.Rendering;
using AcDream.App.Rendering.Gpu;
using AcDream.App.Rendering.Walk;
using Xunit;
namespace AcDream.App.Tests.Rendering;
/// <summary>
/// Phase U.3: CPU-side proof that <see cref="ClipFrame"/> packs the shared clip
/// data in the EXACT std430 (mesh SSBO) / std140 (terrain UBO) byte layout the
/// shaders read. A silent layout drift here would mis-clip at U.4 with no build
/// error — these tests are the gate that catches it.
/// Phase U.3: CPU-side proof that <see cref="ClipFrame"/> packs the mesh SSBO
/// clip-region table in the EXACT std430 byte layout mesh_modern.vert reads. A
/// silent layout drift here would mis-clip at U.4 with no build error — these
/// tests are the gate that catches it.
///
/// Layout under test (mesh CellClip, std430):
/// offset 0 : uint count
@ -20,7 +21,11 @@ namespace AcDream.App.Tests.Rendering;
/// ...
/// offset 16 + i*16 : vec4 planes[i]
/// stride 144 bytes per slot.
/// Terrain UBO (std140): int count at 0 (padded to 16), vec4 planes[8] at 16.
///
/// <see cref="ClipFrame.TerrainUboBytes"/>/<see cref="ClipFrame.TerrainClipUboBinding"/>
/// share this file only because they happen to reuse the identical std140
/// 144-byte shape for a DIFFERENT, still-live consumer — see their own doc
/// comments (S3 chunk 4 fix round 2, L3).
/// </summary>
public class ClipFrameLayoutTests
{
@ -41,11 +46,12 @@ public class ClipFrameLayoutTests
Assert.Equal(16, ClipFrame.CellClipPlanesOffset);
Assert.Equal(8, ClipFrame.MaxPlanes);
Assert.Equal(144, ClipFrame.TerrainUboBytes);
// Binding contract: mesh clip regions on SSBO binding=2, terrain on UBO binding=2.
// The mesh side's binding index moved off ClipFrame at Campaign V slice
// V11 — the RHI arm addresses it through GpuBindingModel.StorageClipRegions
// instead of a raw GL binding constant (see ClipFrame's BeginFrame doc
// comment); the terrain UBO binding is still genuinely shared, so it stays.
// Binding contract: mesh clip regions on SSBO binding=2, PortalDepthMaskRenderer's
// exit-seal/punch-fan clip block on UBO binding=2. The mesh side's binding
// index moved off ClipFrame at Campaign V slice V11 — the RHI arm addresses
// it through GpuBindingModel.StorageClipRegions instead of a raw GL binding
// constant (see ClipFrame's BeginFrame doc comment); the portal-depth UBO
// binding is still genuinely shared, so it stays.
Assert.Equal(2u, GpuBindingModel.StorageClipRegions);
Assert.Equal(2u, ClipFrame.TerrainClipUboBinding);
}
@ -66,17 +72,6 @@ public class ClipFrameLayoutTests
Assert.Equal(0, b);
}
[Fact]
public void NoClip_TerrainBytes_Count0_AllZeros()
{
var frame = ClipFrame.NoClip();
var t = frame.TerrainBytesForTest;
Assert.Equal(ClipFrame.TerrainUboBytes, t.Length);
Assert.Equal(0, ReadInt(t, 0)); // count 0 ⇒ terrain ungated
foreach (var b in t)
Assert.Equal(0, b);
}
[Fact]
public void AppendSlot_WritesCountAndPlanes_AtStd430Offsets()
{
@ -180,11 +175,9 @@ public class ClipFrameLayoutTests
AssertPlaneAt(bytes, baseOff + ClipFrame.CellClipPlanesOffset + i * 16, cps.Planes[i]);
}
// S3 chunk 4 fix round 1 (K3): SetTerrainClip_WritesCountAndPlanes_AtStd140Offsets
// is deleted along with ClipFrame.SetTerrainClip itself (no production
// writer remains). NoClip_TerrainBytes_Count0_AllZeros above still pins
// the permanent all-zero state SetTerrainClip used to be the only way
// to move off of.
// S3 chunk 4 fix round 2 (L3): the walk's screen-space clip gate and its
// own std140 layout pin are deleted outright — no shader declares that
// block any more, so there is nothing left to pack or pin.
private static void AssertPlaneAt(System.ReadOnlySpan<byte> bytes, int offset, Vector4 expected)
{
@ -246,39 +239,62 @@ public class ClipFrameLayoutTests
/// KEEP item 2 — punch fans: <c>RetailPViewPassExecutor.DrawWalkPunchFan</c>
/// reads its clip planes through <c>clipAssembly.OutsideViewSlices
/// [activeViewIndex].Planes</c> — <see cref="ClipViewSlice"/>'s
/// <c>Planes</c> field. S3 chunk 4 fix round 1 (K6): this pin now builds
/// that slice through the REAL production assembly —
/// <c>ClipFrameAssembler.Assemble</c>'s own
/// <c>outsideSlicesList.Add(new ClipViewSlice(slot, AabbOf(poly),
/// planes))</c> line, the exact construction
/// <c>ReassembleOutsideViewFromWalk</c> (the walk's real interior-root
/// producer) shares — instead of hand-constructing a
/// <see cref="ClipViewSlice"/> directly from <see
/// cref="ClipPlaneSet.From(CellView)"/>'s raw output: a hand-built slice
/// could pass even if Assemble's own packing/array-construction diverged
/// from that raw output, which is exactly the gap a prior round's
/// three-lens review found (a hand-built <c>ClipViewSlice</c> is not
/// proof the production path builds the same one). Same synthetic-view
/// helper as the exit-seal pin, a different (non-axis-aligned) synthetic
/// polygon so the two pins are not testing the identical input.
/// <c>Planes</c> field. S3 chunk 4 fix round 2 (L4): a prior round's pin
/// here built the slice through <c>ClipFrameAssembler.Assemble</c> — but
/// <c>Assemble</c> has ZERO production callers (it exists only for
/// isolated research/replay tests, per this file's own class header);
/// production builds an interior root's outside-view slices through
/// <c>BeginWalkFrame</c> + <c>ReassembleOutsideViewFromWalk</c>
/// (<c>RetailPViewPassExecutor.cs</c>'s <c>BeginWalkFrame</c> call,
/// <c>RetailPViewRenderer.cs</c>'s <c>ReassembleOutsideViewFromWalk</c>
/// call), so a pin through <c>Assemble</c> proves nothing about the code
/// that actually runs. This pin now drives that EXACT pair: a synthetic
/// <see cref="WalkPortalView"/> holding one pixel-space polygon (built
/// the way <c>WalkCopyViewTests</c> builds views), fed through
/// <c>BeginWalkFrame(frame, outdoorRoot: false)</c> then
/// <c>ReassembleOutsideViewFromWalk</c> — both of which now call the
/// SAME shared <c>ClipFrameAssembler.AppendOutsideSlice</c> helper
/// <c>Assemble</c> would have (L4's own de-duplication), so this pin
/// exercises the helper through the producer that actually runs.
/// MUTATION: perturbing <c>planes[0].W</c> INSIDE that shared helper (the
/// one place both producers pack a plane) breaks this pin — see the
/// commit body for the recorded failing assertion text. The pin's own
/// source contains no <c>Assemble(</c> call (grep-checked in the commit
/// body). Same non-axis-aligned synthetic polygon as before, kept
/// distinct from the exit-seal pin's input.
/// </summary>
[Fact]
public void ClipViewSlicePlanes_PunchFanPath_EqualsCpuViewPolygonEdgePlanes_ForASyntheticView()
{
const float ViewportWidth = 640f, ViewportHeight = 480f;
Vector2[] verts =
[
new(0f, 0.6f), new(-0.6f, -0.4f), new(0.5f, -0.5f), new(0.7f, 0.2f),
];
// The EXACT production assembly path: ClipFrameAssembler.Assemble
// packs the outside_view polygon into a slot and constructs the
// ClipViewSlice DrawWalkPunchFan reads back through
// clipAssembly.OutsideViewSlices[activeViewIndex].Planes.
var pvFrame = new PortalVisibilityFrame();
pvFrame.OutsideView.Add(new ViewPolygon(verts));
// Pixel-space points (origin top-left, +Y down) that ReassembleOutsideViewFromWalk's
// own inverse transform (px = (ndc+1)*W/2, py = (1-ndc)*H/2) maps back to `verts`.
var pixelPoints = new WalkScreenPoint[verts.Length];
for (int i = 0; i < verts.Length; i++)
{
float px = (verts[i].X + 1f) * ViewportWidth / 2f;
float py = (1f - verts[i].Y) * ViewportHeight / 2f;
pixelPoints[i] = new WalkScreenPoint(px, py, 0f, 1f);
}
var frame = ClipFrame.NoClip();
ClipFrameAssembly assembly = ClipFrameAssembler.Assemble(frame, pvFrame);
var walkView = new WalkPortalView();
Assert.True(WalkCopyView.Append(
walkView, pixelPoints, new SyntheticRayCaster(), Vector3.Zero));
// The EXACT production pair: BeginWalkFrame seeds an interior root's
// empty outside-view assembly; ReassembleOutsideViewFromWalk (the
// walk's real producer) fills it from the walk's own pixel-space
// view — the same two calls RetailPViewPassExecutor.cs and
// RetailPViewRenderer.cs make.
ClipFrameAssembly assembly = ClipFrameAssembler.BeginWalkFrame(
ClipFrame.NoClip(), outdoorRoot: false);
ClipFrameAssembler.ReassembleOutsideViewFromWalk(
assembly, walkView, ViewportWidth, ViewportHeight);
ClipViewSlice slice = Assert.Single(assembly.OutsideViewSlices);
Assert.True(slice.Planes.Length >= 3);
@ -286,6 +302,16 @@ public class ClipFrameLayoutTests
AssertEveryEdgeMidpointLiesOnSomeGpuPlane(verts, slice.Planes);
}
/// <summary>Trivial ray caster: only <c>WalkPortalView</c>'s stored pixel
/// points feed <see cref="ClipFrameAssembler.ReassembleOutsideViewFromWalk"/>
/// (via NDC conversion); the per-vertex plane a ray caster would seed is
/// unused by that path, so any non-degenerate direction works.</summary>
private sealed class SyntheticRayCaster : IWalkRayCaster
{
public Vector3 RayThrough(float screenX, float screenY) =>
Vector3.Normalize(new Vector3(screenX, screenY, 1000f));
}
/// <summary>
/// CPU/GPU equivalence: a point on a convex polygon's edge must sit
/// (a) non-negative under EVERY plane (still inside-or-on the region —

View file

@ -133,12 +133,15 @@ public sealed class VulkanShaderDescriptorContractTests
|| module.StartsWith("terrain_atmospheric.", StringComparison.Ordinal);
/// <summary>
/// The regression itself, named. <c>TerrainClip</c> is the only uniform block
/// <c>terrain_modern.vert</c> declares besides <c>SceneLighting</c>, so
/// asserting the module's uniform bindings as a set pins it exactly.
/// The regression itself, named — corrected for S3 chunk 4 fix round 2 (L3).
/// <c>terrain_modern.vert</c> used to also declare a screen-space clip block
/// at set 1 binding 2; that gate is deleted outright (no shader writer, no
/// GPU reader) and <c>SceneLighting</c> is now the ONLY uniform block the
/// module declares, so asserting the module's uniform bindings as a set
/// pins that directly.
/// </summary>
[Fact]
public void TerrainVertexShaderDeclaresItsClipBlockInTheUniformSet()
public void TerrainVertexShaderDeclaresOnlySceneLightingInTheUniformSet()
{
uint[] uniformBindings =
[
@ -152,9 +155,7 @@ public sealed class VulkanShaderDescriptorContractTests
.Order(),
];
Assert.Equal(
[GpuBindingModel.UniformSceneLighting, VulkanPipelineLayouts.UniformTerrainClip],
uniformBindings);
Assert.Equal([GpuBindingModel.UniformSceneLighting], uniformBindings);
}
/// <summary>

View file

@ -62,9 +62,19 @@ public sealed class VulkanShaderManifestTests
// SkyFogRuleTests). A deliberate default-path change, reviewed
// with the world-fog-range fix in the same commit.
["sky.frag.spv"] = "1c4ae77056837cbdc188f8cfcc4b0e8851647cdfaf398f25d8c8ff489ef84d57",
["sky.vert.spv"] = "3b51945fa4ff1be1604144df92866bdd47aade22f9dd90267591ef36adb28cde",
// sky.vert re-pinned 2026-09-03 (Campaign OVERHAUL S3 chunk 4 fix
// round 2, L3): the screen-space TerrainClip UBO (binding=2) and
// its gl_ClipDistance writes are deleted outright — retail draws
// the sky ONCE, unclipped (GameSky::Draw(sky,0) @0x0050633c), and
// that mechanism's only CPU-side writer was already retired at
// fix round 1's K3, leaving the shader-side declaration dead.
["sky.vert.spv"] = "7d67a9e3624d198b370d402b5c12e4ce925bf9b8e646ef5123636a86d5985ab5",
["terrain_modern.frag.spv"] = "7b3cdb01b837ed77ee20559a81c1ce5c9d5395300efcc072560ab0be3c5a1af9",
["terrain_modern.vert.spv"] = "9f4cb221ea6aed94a8d23af6cb8e3f3ed96c3cce6e50d135a72d3b55667b1557",
// terrain_modern.vert re-pinned 2026-09-03 (Campaign OVERHAUL S3
// chunk 4 fix round 2, L3): same deletion as sky.vert above —
// retail never view-clips terrain (LScape::draw draws whole
// landblocks; RenderDeviceD3D::DrawBlock @0x005a17c0).
["terrain_modern.vert.spv"] = "8a73d89ef0e51e550327b9ff8c24857e309103b1d491030cf0d4d8594b45068c",
["ui_text.frag.spv"] = "37a281bf80441cb425eaa3ad8e0b3a43cfa21b74b60973ed4201718b9dc102df",
["ui_text.vert.spv"] = "018ac64477cf7d4c3fc0c5878951b148c7bfeb6ee3a7eebb02381d7904877798",
["vk_probe.frag.spv"] = "c2dedbcc6dcc89744707b4b47138f1c31b38ef9088e584f1da07dd6953586c42",

View file

@ -18,7 +18,7 @@ namespace AcDream.App.Tests.Rendering.Gpu.Vk;
///
/// <para>The scissor is the trap. It does NOT flip with the viewport:
/// <c>vkCmdSetScissor</c> is always top-left-origin regardless of viewport sign,
/// while <c>NdcScissorRect.ToPixels</c> emits GL bottom-left rectangles. The V3
/// while every caller passes a GL-convention bottom-left rectangle. The V3
/// audit flagged this explicitly as a V6 acceptance item, and getting it wrong
/// shows up as a doorway aperture clipped from the wrong edge — which only a
/// scene containing one would reveal.</para>

View file

@ -14,29 +14,44 @@ namespace AcDream.App.Tests.Rendering;
/// looking out from inside. Mechanism model (2026-06-12 evidence sweep): for
/// an interior root the SEAL stamps the FULL raw dat portal polygon at true
/// depth (PortalDepthMaskRenderer, root-cell slice = full screen), while
/// terrain/sky COLOR is gated per fragment by the OutsideView region — the
/// same dat polygon run through ProjectToClip → ClipToRegion (1-px
/// terrain/sky COLOR used to be gated per fragment by the OutsideView region —
/// the same dat polygon run through ProjectToClip → ClipToRegion (1-px
/// MergeSubPixelVertices) → ClipPlaneSet.From (0.5° collinear merge) → planes,
/// with a Floor/Ceil pixel scissor (BeginDoorwayScissor) on the slice AABB on
/// top. Every one of those passes can only SHRINK the gate, so any shave shows
/// as a strip of clear color between the gate's top edge and the aperture's
/// rasterized top edge (the shell wall starts above it; the seal z-kills
/// everything beyond; nothing re-covers).
/// with a Floor/Ceil pixel scissor (the sky's own doorway scissor bracket)
/// on the slice AABB on top. Every one of those passes could only SHRINK the gate, so any
/// shave showed as a strip of clear color between the gate's top edge and the
/// aperture's rasterized top edge.
///
/// This harness measures that gap headlessly at the real Holtburg corner
/// building exit door (A9B4 0x0170, the HouseExitWalkReplay door): project the
/// aperture, run the production flood + assembler, then walk sample points
/// just inside the aperture's top edge downward until the gate admits them.
/// Plane-gap and scissor-gap are measured separately (mechanism attribution).
/// RETIRED MECHANISM (S3 chunk 4 fix round 2, L7): the scissor half of this
/// story no longer applies. Retail draws the sky and the landscape unclipped
/// (<c>LScape::draw</c> never installs a view before either — S3 chunk 3/4's
/// own findings), and acdream now matches that: the sky's own doorway
/// scissor bracket, <c>IWorldPassSurface.BeginScissor/EndScissor</c>, and
/// every per-slice terrain/sky/weather clip they used to bracket are deleted
/// outright. An
/// interior root's aperture exactness comes instead from the depth clear, the
/// exit seals, and the interior repaint (<c>WalkFrameDriver</c>'s interior
/// turn draws the real cell geometry back over whatever the unclipped
/// landscape painted through the doorway) — see the S3 chunk 4 plan section
/// for the retail citations.
///
/// VERDICT (2026-06-12, 147 eye/gaze combos): the CPU polygon pipeline is
/// sub-pixel exact (worst 0.54 px) — the W=0 clip port 987313a and both merge
/// passes are EXONERATED. The strip was the scissor box: the old
/// Floor(origin)+Ceiling(size) form cut up to 1 px off the TOP/RIGHT edges at
/// unlucky fractional alignments (captured live by this harness: top edge
/// y=0.7938 at 1080p → row 968 cut; right edge x=0.3503 at 1920 → column 1296
/// cut). Fixed by the conservative NdcScissorRect bound; the assertions below
/// pin both properties.
/// What remains below still pins something production reads: the outside-view
/// polygon pipeline (<c>ProjectToClip</c> → <c>ClipToRegion</c> →
/// <c>ClipPlaneSet.From</c>) that the KEPT punch-fan clip still consumes
/// (<c>RetailPViewPassExecutor.DrawWalkPunchFan</c> reads
/// <c>clipAssembly.OutsideViewSlices[activeViewIndex].Planes</c> — see
/// <c>ClipFrameLayoutTests</c>'s punch-fan equivalence pin for the synthetic-
/// view version of this same proof). This harness measures the PLANE gap
/// headlessly at the real Holtburg corner building exit door (A9B4 0x0170,
/// the HouseExitWalkReplay door): project the aperture, run the production
/// flood + assembler, then walk sample points just inside the aperture's top
/// edge downward until the plane gate admits them.
///
/// VERDICT (2026-06-12, 147 eye/gaze combos, plane half only — the original
/// sweep also measured a scissor gap, since retired): the CPU polygon
/// pipeline is sub-pixel exact (worst 0.54 px) — the W=0 clip port 987313a
/// and both merge passes are EXONERATED. PIN 2 below still asserts that
/// bound.
/// </summary>
[Trait("Lane", "InstalledDat")]
public class Issue130DoorwayStripTests
@ -108,7 +123,7 @@ public class Issue130DoorwayStripTests
_out.WriteLine(FormattableString.Invariant(
$" poly[{i}] world=({worldPoly[i].X:F3},{worldPoly[i].Y:F3},{worldPoly[i].Z:F3})"));
float worstPlaneGapPx = 0f, worstScissorGapPx = 0f;
float worstPlaneGapPx = 0f;
string worstDesc = "(none)";
// Eye sweep: back off the doorway along the inward normal at several
@ -155,21 +170,20 @@ public class Issue130DoorwayStripTests
}
evaluated++;
(float planeGapPx, float scissorGapPx, float atX) =
MeasureTopEdgeGap(aperture, asm.OutsideViewSlices, 1920, 1080);
(float planeGapPx, float atX) =
MeasureTopEdgeGap(aperture, asm.OutsideViewSlices, 1080);
if (planeGapPx > worstPlaneGapPx || scissorGapPx > worstScissorGapPx)
if (planeGapPx > worstPlaneGapPx)
{
worstDesc = FormattableString.Invariant(
$"d={d} h={h} lat={lat} gz={gz} minW={minW:F2} atX={atX:F3} slices={asm.OutsideViewSlices.Length} mode={asm.TerrainMode} outVerts={DescribePolys(pv.OutsideView)} apVerts={aperture.Length}");
worstPlaneGapPx = MathF.Max(worstPlaneGapPx, planeGapPx);
worstScissorGapPx = MathF.Max(worstScissorGapPx, scissorGapPx);
$"d={d} h={h} lat={lat} gz={gz} minW={minW:F2} atX={atX:F3} slices={asm.OutsideViewSlices.Length} outVerts={DescribePolys(pv.OutsideView)} apVerts={aperture.Length}");
worstPlaneGapPx = planeGapPx;
}
if (planeGapPx > 0.55f || scissorGapPx > 0.55f)
if (planeGapPx > 0.55f)
{
_out.WriteLine(FormattableString.Invariant(
$"GAP d={d} h={h} lat={lat} gz={gz}: planeGap={planeGapPx:F2}px scissorGap={scissorGapPx:F2}px atX={atX:F3} mode={asm.TerrainMode} outVerts={DescribePolys(pv.OutsideView)}"));
$"GAP d={d} h={h} lat={lat} gz={gz}: planeGap={planeGapPx:F2}px atX={atX:F3} outVerts={DescribePolys(pv.OutsideView)}"));
float apTop = TopBoundaryY(aperture, atX);
foreach (var slice in asm.OutsideViewSlices)
_out.WriteLine(FormattableString.Invariant(
@ -185,15 +199,10 @@ public class Issue130DoorwayStripTests
}
_out.WriteLine(FormattableString.Invariant(
$"evaluated={evaluated} worstPlaneGapPx={worstPlaneGapPx:F2} worstScissorGapPx={worstScissorGapPx:F2} @ {worstDesc}"));
$"evaluated={evaluated} worstPlaneGapPx={worstPlaneGapPx:F2} @ {worstDesc}"));
Assert.True(evaluated > 100, $"sweep degenerated: only {evaluated} eye/gaze combos evaluated");
// PIN 1 (#130): the scissor box never cuts a fragment the plane gate
// admits — conservative containment (AD-17's over-include doctrine).
// One probe step is ~0.11 px; anything beyond it is a real cut row.
Assert.True(worstScissorGapPx <= 0.15f, FormattableString.Invariant(
$"scissor under-covers the plane-admitted region by {worstScissorGapPx:F2}px @ {worstDesc}"));
// PIN 2 (canary): the CPU polygon pipeline (ProjectToClip → ClipToRegion
// PIN (canary): the CPU polygon pipeline (ProjectToClip → ClipToRegion
// merges → ClipPlaneSet planes) stays sub-pixel exact against the raw
// aperture projection. Observed 0.54 px worst (2026-06-12); the
// production vertex-merge floor is ~1 px — beyond 1.2 px means a new
@ -211,12 +220,14 @@ public class Issue130DoorwayStripTests
/// <summary>
/// For sample x positions across the aperture's projected top edge, find the
/// aperture boundary's top y, then walk downward until the gate admits the
/// point. Returns the worst gaps in 1080p pixels (plane gate and modeled
/// scissor gate measured independently), and the x of the worst plane gap.
/// aperture boundary's top y, then walk downward until the plane gate
/// admits the point. Returns the worst gap in 1080p pixels, and the x of
/// the worst gap. S3 chunk 4 fix round 2 (L7): the scissor-gap half this
/// used to measure alongside the plane gap is deleted — the scissor
/// mechanism it modeled no longer exists in production.
/// </summary>
private static (float planeGapPx, float scissorGapPx, float atX) MeasureTopEdgeGap(
Vector2[] aperture, ClipViewSlice[] slices, int fbW, int fbH,
private static (float planeGapPx, float atX) MeasureTopEdgeGap(
Vector2[] aperture, ClipViewSlice[] slices, int fbH,
ITestOutputHelper? debug = null)
{
const float Inset = 1e-4f; // dodge exact-boundary ambiguity
@ -226,9 +237,9 @@ public class Issue130DoorwayStripTests
float minX = float.MaxValue, maxX = float.MinValue;
foreach (var v in aperture) { minX = MathF.Min(minX, v.X); maxX = MathF.Max(maxX, v.X); }
float span = maxX - minX;
if (span <= 0.01f) return (0, 0, 0);
if (span <= 0.01f) return (0, 0);
float worstPlane = 0, worstScissor = 0, atX = 0;
float worstPlane = 0, atX = 0;
const int Samples = 160;
for (int s = 0; s <= Samples; s++)
{
@ -240,22 +251,15 @@ public class Issue130DoorwayStripTests
var p = new Vector2(x, topY - Inset);
float planeGap = GapBelow(p, q => AnySliceAdmitsPlanes(slices, q), StepY, CapY);
// The scissor question is "does the box cut pixels the PLANES would
// draw" — measure it from the planes-admitted top, not the aperture
// top (at slanted corners the aperture top can sit legitimately
// outside the gate polygon's column).
var pPlanes = new Vector2(p.X, p.Y - planeGap - Inset);
float scissorGap = GapBelow(pPlanes, q => AnySliceAdmitsScissor(slices, q, fbW, fbH), StepY, CapY);
if (debug is not null && scissorGap > 0.005f)
if (debug is not null && planeGap > 0.005f)
debug.WriteLine(FormattableString.Invariant(
$" sample x={x:F4} apTop={topY:F4} planeGap={planeGap * fbH / 2f:F2}px pPlanes=({pPlanes.X:F4},{pPlanes.Y:F4}) scissorGap={scissorGap * fbH / 2f:F2}px"));
$" sample x={x:F4} apTop={topY:F4} planeGap={planeGap * fbH / 2f:F2}px"));
if (planeGap > worstPlane) { worstPlane = planeGap; atX = x; }
worstScissor = MathF.Max(worstScissor, scissorGap);
}
// NDC y → pixels at the given framebuffer height.
return (worstPlane * fbH / 2f, worstScissor * fbH / 2f, atX);
return (worstPlane * fbH / 2f, atX);
}
private static float GapBelow(Vector2 start, Func<Vector2, bool> admitted, float step, float cap)
@ -272,7 +276,7 @@ public class Issue130DoorwayStripTests
// Production semantics: each OutsideView polygon is one slice; the union of
// slices is drawn. A slice with planes gates per fragment via
// gl_ClipDistance (dot((nx,ny,0,d),(x,y,z,1)) >= 0 for an NDC point);
// a planeless slice (scissor fallback) admits its whole NDC AABB.
// a planeless slice (>8-edge zero-plane fallback, ClipFrameAssembler.cs) admits its whole NDC AABB.
private static bool AnySliceAdmitsPlanes(ClipViewSlice[] slices, Vector2 p)
{
foreach (var slice in slices)
@ -294,22 +298,6 @@ public class Issue130DoorwayStripTests
return false;
}
// Production scissor (BeginDoorwayScissor → NdcScissorRect.ToPixels): a
// point is admitted when its pixel falls inside some slice's scissor box.
private static bool AnySliceAdmitsScissor(ClipViewSlice[] slices, Vector2 p, int fbW, int fbH)
{
int pixX = (int)MathF.Floor((p.X * 0.5f + 0.5f) * fbW);
int pixY = (int)MathF.Floor((p.Y * 0.5f + 0.5f) * fbH);
foreach (var slice in slices)
{
var box = NdcScissorRect.ToPixels(slice.NdcAabb, fbW, fbH);
if (pixX >= box.X && pixX < box.X + box.Width
&& pixY >= box.Y && pixY < box.Y + box.Height)
return true;
}
return false;
}
/// <summary>Highest boundary y of the polygon at vertical line x (NaN when
/// the line misses the polygon).</summary>
private static float TopBoundaryY(Vector2[] poly, float x)

View file

@ -1,80 +0,0 @@
using System;
using System.Numerics;
using AcDream.App.Rendering;
using Xunit;
namespace AcDream.App.Tests.Rendering;
/// <summary>
/// #130: the doorway-slice scissor must be a CONSERVATIVE outer bound of its
/// NDC AABB (AD-17: over-inclusion safe, under-inclusion is the bug class).
/// The old Floor(origin)+Ceiling(size) form put the far edge at
/// floor(min)+ceil(maxmin), up to one pixel short of the true max edge —
/// the doorway top-edge background strip.
/// </summary>
public class NdcScissorRectTests
{
/// <summary>Containment property: every pixel whose CENTER lies inside the
/// NDC box is inside the scissor box, across a dense grid of fractional
/// alignments at two framebuffer sizes.</summary>
[Theory]
[InlineData(1920, 1080)]
[InlineData(2560, 1440)]
public void EveryCenterInsidePixel_IsInsideTheBox(int fbW, int fbH)
{
for (int i = 0; i < 251; i++)
{
// Sweep fractional alignments of all four edges.
float f = i / 251f;
float minX = -0.83f + f * 0.0031f;
float minY = -0.71f + f * 0.0047f;
float maxX = 0.339f + f * 0.0043f;
float maxY = 0.7938f + f * 0.0029f;
var box = NdcScissorRect.ToPixels(new Vector4(minX, minY, maxX, maxY), fbW, fbH);
// Pixel-space extremes of center-inside pixels.
float x0 = (minX * 0.5f + 0.5f) * fbW, x1 = (maxX * 0.5f + 0.5f) * fbW;
float y0 = (minY * 0.5f + 0.5f) * fbH, y1 = (maxY * 0.5f + 0.5f) * fbH;
int loX = (int)MathF.Ceiling(x0 - 0.5f), hiX = (int)MathF.Floor(x1 - 0.5f);
int loY = (int)MathF.Ceiling(y0 - 0.5f), hiY = (int)MathF.Floor(y1 - 0.5f);
Assert.True(box.X <= loX, $"left cut: box.X={box.X} > loX={loX} (minX={minX})");
Assert.True(box.Y <= loY, $"bottom cut: box.Y={box.Y} > loY={loY} (minY={minY})");
Assert.True(box.X + box.Width > hiX, $"right cut: box ends {box.X + box.Width} <= hiX={hiX} (maxX={maxX})");
Assert.True(box.Y + box.Height > hiY, $"top cut: box ends {box.Y + box.Height} <= hiY={hiY} (maxY={maxY})");
// Over-inclusion stays bounded (≤1 px per edge).
Assert.True(box.X >= loX - 1 && box.Y >= loY - 1);
Assert.True(box.X + box.Width <= hiX + 2 && box.Y + box.Height <= hiY + 2);
}
}
[Fact]
public void CapturedRegression_TopEdgeRow968_At1080p()
{
// Issue130DoorwayStripTests live capture: aperture top y=0.7938 →
// pixel row 968 (center 968.5 < 968.65). The old formula ended the box
// at row 967 — the visible strip.
var box = NdcScissorRect.ToPixels(new Vector4(-0.339f, -0.743f, 0.339f, 0.7938f), 1920, 1080);
Assert.True(box.Y + box.Height > 968, $"top row 968 cut: box ends at {box.Y + box.Height}");
}
[Fact]
public void CapturedRegression_RightColumn1296_At1920()
{
// Issue130DoorwayStripTests live capture: gate right edge x=0.3507 →
// pixel column 1296 admitted by the plane gate; the old formula ended
// the box at column 1295.
var box = NdcScissorRect.ToPixels(new Vector4(-0.2845f, -1.0f, 0.3507f, 0.2630f), 1920, 1080);
Assert.True(box.X + box.Width > 1296, $"right column 1296 cut: box ends at {box.X + box.Width}");
}
[Fact]
public void DegenerateAndOffscreenBoxes_StayValid()
{
// Past-the-edge regions clamp to the screen and keep min 1 px size.
var box = NdcScissorRect.ToPixels(new Vector4(0.999f, 0.999f, 1.5f, 1.5f), 1920, 1080);
Assert.True(box.Width >= 1 && box.Height >= 1);
var inverted = NdcScissorRect.ToPixels(new Vector4(1f, 1f, -1f, -1f), 1920, 1080);
Assert.True(inverted.Width >= 1 && inverted.Height >= 1);
}
}

View file

@ -1,4 +1,5 @@
using System.Reflection;
using System.Reflection.Emit;
using AcDream.App.Composition;
using AcDream.App.Rendering;
using AcDream.App.Rendering.Sky;
@ -120,9 +121,10 @@ public sealed class RetailPViewPassExecutorTests
/// <c>WalkFrameDriverTranscriptTests</c>: <c>Collect_OutdoorRoot_...</c>
/// and <c>Collect_InteriorRoot_...</c>). This method now draws the
/// weather MESH and the rain PARTICLES only — the former per-outside-
/// view-slice loop that used to run before this call (<c>SetTerrainClip</c>
/// + <c>ClearClipRouting</c> + the old <c>DrawLandscapeSliceLate</c> leaf)
/// is deleted outright (§10.2): retail draws the weather mesh and its
/// view-slice loop that used to run before this call (the walk's own
/// screen-space terrain-clip writer + <c>ClearClipRouting</c> + the old
/// <c>DrawLandscapeSliceLate</c> leaf) is deleted outright (§10.2): retail
/// draws the weather mesh and its
/// rain particles ONCE, unclipped, never once per doorway aperture.
/// MUTATION: re-inlining a
/// <c>WalkTranscriptDump.PrintObjectCellTurn</c> call back into this
@ -153,9 +155,9 @@ public sealed class RetailPViewPassExecutorTests
/// <summary>
/// S3 chunk 4 (§10.2): the former per-outside-view-slice loop
/// (<c>SetTerrainClip</c> + <c>ClearClipRouting</c> + the old
/// <c>DrawLandscapeSliceLate</c> leaf, one call per active landscape
/// view) is deleted — <c>DrawLandscapeDynamicsPhase</c> now calls
/// (the walk's own screen-space terrain-clip writer +
/// <c>ClearClipRouting</c> + the old <c>DrawLandscapeSliceLate</c> leaf,
/// one call per active landscape view) is deleted — <c>DrawLandscapeDynamicsPhase</c> now calls
/// <see cref="RetailPViewPassExecutor.DrawWeatherOnce"/> exactly once,
/// unconditionally, with no loop of any kind around it. This
/// <c>Assert.Single</c> alone proved insufficient at fix round 1 (K1):
@ -222,6 +224,103 @@ public sealed class RetailPViewPassExecutorTests
&& callOffset < branch.Offset);
}
/// <summary>
/// S3 chunk 4 fix round 2 (L1, BLOCKING). Round 1's three-lens review
/// found that neither existing pin above actually looks at the
/// production CONDITION gating <c>DrawWeatherOnce</c>: restoring the
/// pre-fix gate <c>if (clipAssembly.OutsideViewSlices.Length != 0)</c> —
/// the exact regression K2 was supposed to close — leaves both green,
/// because both only ask "is the call site shaped correctly", never
/// "does the call site read <c>WalkFrameDriver.WeatherTurnFired</c>".
/// This pin reads the compiled condition directly: with <c>c</c> the
/// index of the <c>DrawWeatherOnce</c> call, (a) <c>calls[c-1]</c> must
/// be the <c>WeatherTurnFired</c> getter — the LAST call before the draw
/// — and (b) exactly one branch must sit strictly between that getter
/// call and the draw call, be a <c>brfalse</c>/<c>brfalse.s</c>, and
/// jump FORWARD past the draw call — the compiled shape of
/// <c>if (walkDriver.WeatherTurnFired) passes.DrawWeatherOnce(ctx);</c>
/// and nothing else (an inverted test, an unconditional call, or a
/// different condition entirely all fail one of the two checks).
/// MUTATION M1 (restores the pre-fix regression): change the gate back
/// to <c>if (clipAssembly.OutsideViewSlices.Length != 0)</c> — check (a)
/// fails because <c>calls[c-1]</c> is no longer the
/// <c>WeatherTurnFired</c> getter. MUTATION M2 (drops the gate
/// entirely): make the call unconditional — check (b) fails because no
/// branch sits between the getter call and the draw call (in fact the
/// getter call itself disappears with the gate, so check (a) fails
/// first). MUTATION M3 (inverts the condition): change the gate to
/// <c>if (!walkDriver.WeatherTurnFired)</c> — <c>calls[c-1]</c> is still
/// the getter (check (a) passes), but the compiler emits a
/// <c>brtrue</c>/<c>brtrue.s</c> to skip the draw instead of a
/// <c>brfalse</c>/<c>brfalse.s</c>, so check (b)'s opcode filter finds
/// nothing and <c>Assert.Single</c> fails on zero matches.
/// </summary>
[Fact]
public void DrawLandscapeDynamicsPhase_GatesDrawWeatherOnceOnWalkDriverWeatherTurnFired()
{
MethodInfo method = typeof(RetailPViewRenderer).GetMethod(
"DrawLandscapeDynamicsPhase",
BindingFlags.Instance | BindingFlags.NonPublic)!;
IReadOnlyList<CompiledCall> calls = CompiledCallGraph.Read(method);
int callIndex = RequiredCallIndex(
calls,
typeof(RetailPViewPassExecutor),
nameof(RetailPViewPassExecutor.DrawWeatherOnce));
Assert.True(callIndex > 0, "Expected a call before DrawWeatherOnce — the gate condition.");
CompiledCall condition = calls[callIndex - 1];
Assert.Equal(typeof(AcDream.App.Rendering.Walk.WalkFrameDriver), condition.Target.DeclaringType);
Assert.Equal("get_WeatherTurnFired", condition.Target.Name);
int conditionOffset = condition.Offset;
int drawOffset = calls[callIndex].Offset;
IReadOnlyList<CompiledBranch> branches = CompiledCallGraph.ReadBranches(method);
Assert.Single(
branches,
branch => branch.Offset > conditionOffset
&& branch.Offset < drawOffset
&& (branch.OpCode == OpCodes.Brfalse || branch.OpCode == OpCodes.Brfalse_S)
&& branch.TargetOffset > drawOffset);
}
/// <summary>
/// S3 chunk 4 fix round 2 (L8): the identical loop-shape question K1
/// asked of <see cref="RetailPViewPassExecutor.DrawWeatherOnce"/>'s call
/// site, applied to <see cref="RetailPViewPassExecutor.DrawWalkSky"/>'s
/// own <see cref="SkyRenderer.RenderSky"/> call — retail draws the sky
/// dome exactly once per frame too (K4's own doc comment on
/// <c>DrawWalkSky</c>), so nothing may wrap this call in a loop either.
/// Note for reviewers: <see cref="CompiledCallGraph.ReadBranches"/> reads
/// only <c>br</c>/<c>brtrue</c>/<c>brfalse</c>-family single-target
/// branches — it does not decode a compiled <c>switch</c> jump table,
/// but no C# loop construct (<c>for</c>/<c>foreach</c>/<c>while</c>/
/// <c>do</c>) ever compiles to one, so this pin's blind spot is not a
/// loop shape it could miss. MUTATION: wrapping the call in
/// <c>for (int i = 0; i &lt; 2; i++) { _sky?.RenderSky(...); }</c> makes
/// this fail; restoring the single unconditional call makes it pass
/// again.
/// </summary>
[Fact]
public void DrawWalkSky_RenderSkyCallSiteHasNoEnclosingBackwardBranch()
{
MethodInfo method = typeof(RetailPViewPassExecutor).GetMethod(
"DrawWalkSky",
BindingFlags.Instance | BindingFlags.NonPublic)!;
IReadOnlyList<CompiledCall> calls = CompiledCallGraph.Read(method);
int callIndex = RequiredCallIndex(
calls,
typeof(SkyRenderer),
nameof(SkyRenderer.RenderSky));
int callOffset = calls[callIndex].Offset;
IReadOnlyList<CompiledBranch> branches = CompiledCallGraph.ReadBranches(method);
Assert.DoesNotContain(
branches,
branch => branch.TargetOffset < branch.Offset
&& branch.TargetOffset <= callOffset
&& callOffset < branch.Offset);
}
/// <summary>
/// S3 chunk 1 fix round 2 (§11.6 H1): <see
/// cref="RetailPViewPassExecutor.ShouldDrawWeatherOnce"/> is

View file

@ -723,13 +723,22 @@ public sealed partial class WalkFrameDriverTests
/// separately at Replay — on an interior root whose landscape turn ran
/// with the gate open but whose reassembled outside-view slices ended
/// up empty, the transcript could report a weather turn the frame never
/// actually drew. <see cref="WalkFrameDriver.WeatherTurnFired"/> is exactly the flag
/// <c>RetailPViewRenderer.DrawLandscapeDynamicsPhase</c> now gates
/// <c>DrawWeatherOnce</c> on, so this test's flag assertion doubles as
/// the draw-side pin: gate closed -&gt; the flag stays false (so
/// <c>DrawWeatherOnce</c> would not fire either) AND no "OC" line
/// prints; gate open -&gt; the flag becomes true (so
/// <c>DrawWeatherOnce</c> would fire) AND exactly one "OC" line prints.
/// actually drew. <see cref="WalkFrameDriver.WeatherTurnFired"/> is
/// exactly the flag <c>RetailPViewRenderer.DrawLandscapeDynamicsPhase</c>
/// gates <c>DrawWeatherOnce</c> on: gate closed -&gt; the flag stays
/// false; gate open -&gt; the flag becomes true AND exactly one "OC"
/// line prints. CORRECTION (S3 chunk 4 fix round 2, L1): this test's
/// flag assertion does NOT double as the draw-side pin — it builds a
/// bare <see cref="WalkFrameDriver"/> and never touches
/// <c>DrawLandscapeDynamicsPhase</c>, so it cannot see whether that
/// method actually reads this flag (round 1 shipped with the pre-fix
/// gate <c>clipAssembly.OutsideViewSlices.Length != 0</c> silently
/// restored, and every test in this file stayed green). The real
/// draw-side pin is
/// <c>RetailPViewPassExecutorTests.DrawLandscapeDynamicsPhase_GatesDrawWeatherOnceOnWalkDriverWeatherTurnFired</c>,
/// which reads the compiled call graph of
/// <c>DrawLandscapeDynamicsPhase</c> itself and asserts it calls
/// <c>DrawWeatherOnce</c> gated on THIS getter.
/// </summary>
[Theory]
[InlineData(false)]

View file

@ -61,7 +61,6 @@ public class WalkOutsideViewReassemblyTests
ClipFrameAssembler.ReassembleOutsideViewFromWalk(asm, walkView, W, H);
ClipViewSlice slice = Assert.Single(asm.OutsideViewSlices);
Assert.Equal(TerrainClipMode.Planes, asm.TerrainMode);
Assert.True(asm.OutdoorVisible);
Assert.Equal(4, asm.OutsidePlaneCount);
Assert.Equal(slice.Slot, asm.OutdoorSlot);
@ -101,7 +100,6 @@ public class WalkOutsideViewReassemblyTests
ClipViewSlice slice = Assert.Single(asm.OutsideViewSlices);
Assert.Equal(new Vector4(-1f, -1f, 1f, 1f), slice.NdcAabb);
Assert.Equal(TerrainClipMode.Planes, asm.TerrainMode);
}
[Fact]
@ -115,7 +113,6 @@ public class WalkOutsideViewReassemblyTests
Assert.Empty(asm.OutsideViewSlices);
Assert.False(asm.OutdoorVisible);
Assert.False(asm.HasOutsideView);
Assert.Equal(TerrainClipMode.Skip, asm.TerrainMode);
Assert.Equal(0, asm.OutsidePlaneCount);
Assert.Equal(0, asm.OutdoorSlot);
}