Fix round 1 of the two the plan allows for S4-c2 (048d5b12f), addressing every item M1-M8/A1-A8 from the campaign branch's packet section 11. M1 (BLOCKING): ParticleRenderer.DeferToRetailAlphaQueue threw whenever a mesh-particle batch's TranslucencyKind.Opaque classification (mask 0x00) reached a non-Append DrawMesh row - a real, reachable outcome since TryAppendMeshDraws applies no IsOpaque-style pre-filter unlike WbDrawDispatcher's path. Deleted both throws (ParticleRenderer.cs, WbDrawDispatcher.cs SubmitToAlphaQueue), extracted the router-input derivation into internal static ParticleRenderer.RouteParticleSubmission (directly testable), and implemented rows 1/5's immediate draw by reusing the existing per-instance billboard/mesh draw code (new DrawImmediateParticleSubmissionRhi, no new renderer, no sort per A8). materialHasAlpha (row 4) is derived from CMaterial::CheckAlphaValues @0x005396a0 (Ghidra-verified 2026-09-04): has_alpha=0 only when Ambient.a==Diffuse.a==Specular.a==Emissive.a==1.0f, else 1 - and CMaterial::SetTranslucencySimple @0x005396f0 (reached from CPhysicsPart::SetTranslucency <- Particle::Update @0x0051c290's per-frame alpha-fade) sets all four channels to (1f - translucency) uniformly, so has_alpha == "this particle's current alpha isn't 1.0" - already carried in ColorArgb's top byte (Lerp(StartAlpha,EndAlpha,tLife), ParticleSystem.cs 1039-1041/1453). M3: SubmitToAlphaQueue now takes isBuildingShell + viewProjection and feeds Row 1's detailSurfaceActive gate for translucent building-shell instances (retail DrawBuilding @0x0059f2a0 installs building detail before its own shell subsets reach DrawMesh). Row 1 (detail on) draws the instance immediately at its own walk-stream AlphaSubmitMark via new DrawImmediateAlphaInstance/DrawImmediateAlphaInstanceRhi (reusing WriteDeferredAlphaEntrySlot + the drain's pipeline/detail code for slot 0); never touches _deferredAlpha/the queue for pure-Immediate submissions (fixes a latent leak: previously reserving a _deferredAlpha slot for every candidate meant a frame with ALL-immediate content never registered a source, so ResetAlphaSubmissions never ran). M3c: DrawPreparedAlphaBatchRhi's own per-command hasDetail/DrawBuildingDetailRangeRhi branch is deleted - detail-eligible content no longer reaches the drain (spec: delayed replay is always detailEnabled=0). New AD-120 register row for the "in place -> at the entity's own stream mark" granularity adaptation this introduces. M6: RetailPViewPassExecutor.SubmitOrDrawTransparentCellShell routes an EnvCell's transparent shell through the SAME RetailAlphaMeshRouter table (mask 0x02, detailSurfaceActive = EnvCellRenderer.TransparentDetailEnabled) instead of a hand-coded branch. Detail on: unchanged immediate draw. Detail off: appends ONE token per CELL via new EnvCellAlphaDrawSource (internal, delegate-based so it's unit-testable without a GPU harness), replayed through EnvCellRenderer.RenderTransparentOrdered at the next flush - RenderTransparentOrdered already replayed a cell's batch on demand, so no new deferred-replay abstraction was needed (the original landing's claim that one was required is corrected in the packet). M4: RetailAlphaEntry.IsFirstForList deleted. Retail's per-DrawMesh- invocation "first for this list" flag is trivially true for every subset retail ever appends (DrawMesh @0x0059d4a0 sets both flags true at entry, 0059d4cc/0059d4d0, clearing each independently after ITS OWN first append within that call, 0059d5ef) - the captures confirm it (new=1 on 9,685/10,556 AM lines, impossible under "first since last drain"). acdream's deleted isFirstForList = target.Count == 0 computed the wrong quantifier. One acdream append already IS one DrawMesh call, so the field carried no information and its own pin was vacuous (feedback_every_new_pin_must_be_ shown_to_fail) - deleted rather than kept as an always-true no-op. M5: split all six AlphaFlushTranscript_* KnownFailure Facts into live AlphaFlushSites_* (site+threshold sequence only, content-independent, unconditional pass) and AlphaFlushCounts_* (KnownFailure, full tuple incl. drained counts) sharing one RunAlphaFlushTranscriptReplay helper. Rewrote the KnownFailure reason honestly: THREE independent causes, not "harness content only" - (1) zero live mesh content, (2) acdream appends one entry per INSTANCE vs retail's one per SUBSET per DrawMesh call, (3) acdream's CLIP list is structurally empty for ordinary content (M2). Added ONE live valve pin (WalkFrameDriverTests.SortCellExit_ValveDrainsThroughReplayAtThe ExactBoundary, a Theory over 2250/2249) that goes through WalkFrameDriver. Replay's own SortCellExit arm, not RetailAlphaQueue.Flush called directly. M2/A2/M8c (register): ~~AP-34~~ restored as struck-through RETIRED (it had been deleted outright, not struck, breaking the register's own convention) citing residuals AP-238/AP-239/AP-240. The chunk-2 commit's "AP-236"/ "AP-237" collided with an id ALREADY filed-and-retired on main by an unrelated #132 fix (docs/ISSUES.md:19976) - ids are never reused, so both are renumbered: AP-236->AP-238 (EnvCell; rewritten per M6 - granularity-only residual now, "never through the shared queue" is retired), AP-237->AP-239 (mask-reconstruction gap; the dangling "AP-236b" citation in RetailAlphaMeshRouter.cs never matched either filed id and is corrected to AP-239). New AP-240 filed for M2: WbDrawDispatcher.IsOpaque filters ClipMap out upstream, so ordinary clip-mapped content never reaches retail's CLIP FIFO (draws immediately on the pre-existing OpaqueAlphaToCoverage pipeline instead) - no pipeline change this round, per the contract. AP section header recounted honestly: 159 active (was stale at 161); AD section 92 (was 91, +AD-120). M7: AP-239's only cited example (cloud GfxObj 0x01004C35, surface 0x08000023) is DISPROVEN - decoded Type=0x10114 has alpha-family bits that win in BOTH retail's real priority and acdream's reconstruction, so it never actually diverges. A 2026-09-04 scan of all 6,152 Portal-dat Surfaces found 27 real Translucent+Base1ClipMap-no-alpha-family instances (Type=0x14); cross-referencing GfxObjs found surface 0x08000015 on GfxObj 0x010001EC - cited in place of the disproven cloud example. M8: (a) RenderDeviceD3D::DrawBlock is @0x005a17c0 per symbols.json, not @0x005a18d0 (that is its per-land-cell loop head) - fixed across RetailAlphaQueue.cs, RetailPViewPassExecutor.cs, WalkEvents.cs, WalkFrameDriver.cs (x3), RetailFrameWalk.cs. (b) RetailAlphaQueue.cs's four FlushAlphaList addresses were labelled "return site" but are the CALL instruction's own address (x86 CALL rel32 is 5 bytes) - relabelled "call at X (returns to X+5)". (d) worldbuilder-inventory.md:420's AP-34 citation updated. A1: RetailPViewRenderer.cs's outdoor-root passes.FlushLandscapeAlpha() call (labelled LandscapeFlush) is deleted - retail's real LandscapeFlush (PView::DrawCells @0x005a4840's own FlushAlphaList(0f) @0x005a4872) sits strictly inside if (outside_view.view_count > 0) on the INTERIOR PView; an outdoor root never reaches it (terrace-edge capture: zero 005a4877 FL lines). Verified no opaque draw intervenes between this deletion point and RetailAlphaQueue.EndFrame()'s own RenderNormalMode pass-end flush (WorldSceneRenderer.cs: DrawPostWorldParticles's PView branch is an explicit no-op; only diagnostic wireframes follow) - #132's "drain after the finished opaque world" invariant is kept by that flush alone. A4: RetailAlphaQueue's ApplyScratchRetention call sites passed the ENTRY count as the SOURCE-count argument too (observedClip + observedAlpha twice), so _sources/_sourceDrawOffsets never shrank toward the real source count. Fixed to capture _sources.Count before Clear(). A5/A6/A7: WalkStaticStreamPopulatorTests.cs's stale "same viewer distance" banner corrected; two off-by-one entry counts in the packet's section 10 sequences corrected (foundry-deep x10->x11, holtburg-doorway-still x5->x6); WalkAlphaDepthTrace.cs's "new=" comment explains why IsNew is retained but never compared (M4's finding makes a per-subset comparison meaningless at acdream's per-instance granularity); RetailAlphaMeshRouterTests.cs's IndependentReferenceRoute (never actually independently-shaped) renamed to RestatedBranchTableRoute with an honest doc comment, and the unverified "flipped in turn and failed every time" claim deleted. A3 was resolved as a side effect of M1's SubmitToAlphaQueue doc-comment rewrite (the wrong "0x02/0x03, 0x04/0x05, 0x08/0x09" enumeration no longer exists); RetailAlphaMeshRouter.cs's own MaskFromTranslucencyKind comment updated in the same spirit (M1's particle-site Opaque-reachability finding). Mutation checks (each applied to a scratch-restored copy, confirmed failing, then byte-exact reverted - diffed against a /tmp backup after restore): - A1 (RetailPViewRendererTests.DrawInside_NeverCallsFlushLandscapeAlphaDirectly): restoring the deleted "if (ctx.RootCell.IsOutdoorNode) passes.FlushLandscapeAlpha();" line reintroduces a direct RetailPViewPassExecutor.FlushLandscapeAlpha call in DrawInside's compiled body. Actual failure: "Assert.DoesNotContain() Failure: Filter matched in collection ... CompiledCall { ... Target = Void FlushLandscapeAlpha() }". - A4 (RetailAlphaQueueTests.RetainedSourceCapacity_ConvergesToTheReal SourceCountNotTheEntryCount): reverting both ApplyScratchRetention calls to (observedClip + observedAlpha, observedClip + observedAlpha) - with 100 distinct sources in the spike frame (so _sources.Capacity grows to 128, past its initial 4) followed by three low-demand frames of 10 entries via ONE repeated source - makes sourceTarget compute from 10 (Math.Max(4,10*2)=20) instead of 1 (Math.Max(4,1*2)=4). Actual failure: "Expected the retained source-array capacity to converge toward the real source count (1), but it stayed at 20". (A single-source-only spike does NOT discriminate this bug - Math.Min(sourceTarget, _sources.Capacity) clamps both formulas to the same unchanged initial 4 - hence the 100-source setup.) - M5 valve (WalkFrameDriverTests.SortCellExit_ValveDrainsThroughReplayAt TheExactBoundary, 2250 case): flipping RetailAlphaQueue.Flush's no-op comparison from "<" to "<=" (S4-c1/c2's own boundary mutation) makes the 2250-entries case a no-op instead of draining. Actual failure: "Assert.Equal() Failure: Values differ Expected: 0 Actual: 2250". - M6 (EnvCellAlphaDrawSourceTests, both Facts): adding an immediate renderTransparentOrdered(new[]{cellId}) call inside EnvCellAlphaDrawSource.AddPendingCellId (simulating the M1/M3 "drew immediately instead of deferring" bug class) makes PendingCellToken_IsDrainedAtTheFlushAndNeverBeforeIt fail with "Assert.Empty() Failure: Collection was not empty Collection: [[4660]]" and ParticleAppendedBetweenTwoCellTokens_KeepsItsPositionInTheCombined Drain fail with 'Expected: string[] ["cell:256", "particle:7", "cell:512"] Actual: List<string> ["cell:256", "cell:512", "cell:256", "particle:7", "cell:512"]'. - M1 (ParticleRendererRouteTests.OpaqueClassifiedMeshBatch_WithMaterialAlpha _RoutesToAlphaAppend): hardcoding materialHasAlpha to false inside RouteParticleSubmission makes the Opaque-mask+has-alpha case route Immediate instead of Append. Actual failure: "Assert.Equal() Failure: Values differ Expected: Append Actual: Immediate". Gates (real output lines): - dotnet build AcDream.slnx -c Release -> "Build succeeded. 0 Warning(s) 0 Error(s)". - Hermetic lane (--filter "Lane!=InstalledDat&Lane!=PreparedPackage& Lane!=Live&Lane!=Manual&Lane!=Timing&Lane!=Windows&Lane!=Linux& Lane!=SystemFont&Purpose!=Diagnostic&Status!=KnownFailure") -> "Passed! - Failed: 0, Passed: 6864, Skipped: 0, Total: 6864". - InstalledDat lane (ACDREAM_RUN_INSTALLED_DAT_TESTS=1, ACDREAM_DAT_DIR="C:/Users/erikn/Documents/Asheron's Call", --filter "Lane=InstalledDat") -> "Failed: 10, Passed: 255, Skipped: 1, Total: 266" - the exact 4 pre-existing failures (TowerAscent_StaircaseStaysConeVisible_EveryStep, LayoutImporterMediaBearingChildSweepTests, LayoutImporterInvisibleSweep Tests, Oh_doorway_still_first_frame_diff) plus the six AlphaFlushCounts_* KnownFailure Facts, nothing else; all six AlphaFlushSites_* Facts pass inside this same lane (the whole WalkTraceConformanceTests partial class carries Lane=InstalledDat, so they cannot run hermetically). - Shader classes (VulkanShaderDescriptorContractTests, VulkanShaderManifestTests, RenderPackSpirvValidatorTests) -> "Passed! - Failed: 0, Passed: 32, Skipped: 0, Total: 32". - RetailAlphaQueueTests, RetailAlphaMeshRouterTests, RetailFrameWalkTests, WalkFrameDriverTests, ParticleRenderer*Tests, EnvCellRenderer*Tests (combined filter) -> "Passed! - Failed: 0, Passed: 120, Skipped: 0, Total: 120". - Register collision grep: AP-238/AP-239/AP-240/AD-120 each count exactly 1; ~~AP-34~~ count exactly 1; live totals AP=159, AD=92. Not done / deferred: none - all M1-M8/A1-A8 items landed; A8 was a no-action note. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
292 lines
14 KiB
C#
292 lines
14 KiB
C#
using AcDream.App.Rendering;
|
||
using AcDream.Core.Meshing;
|
||
|
||
namespace AcDream.App.Tests.Rendering;
|
||
|
||
/// <summary>
|
||
/// S4-c2: <see cref="RetailAlphaMeshRouter"/>'s port of retail
|
||
/// <c>D3DPolyRender::DrawMesh</c> @0x0059d4a0's branch table (spec §4).
|
||
/// </summary>
|
||
public sealed class RetailAlphaMeshRouterTests
|
||
{
|
||
/// <summary>
|
||
/// Hand-traced literal cases against the Ghidra-verified decomp — each
|
||
/// one differentiates exactly one row boundary, with the mutation each
|
||
/// guards against spelled out. delayMask is fixed at the real default
|
||
/// (0x0E) throughout, matching the contract's fixed axis.
|
||
/// </summary>
|
||
public static IEnumerable<object[]> RowBoundaryCases()
|
||
{
|
||
// Row 1a: sky wins outright even over a mask that would otherwise
|
||
// hit row 3. Mutation: dropping the sky check entirely returns
|
||
// Append(Alpha) instead.
|
||
yield return new object[]
|
||
{
|
||
true, false, false, (byte)0x02, false,
|
||
(int)RetailAlphaMeshAction.Immediate, (int)RetailAlphaList.Alpha, false,
|
||
};
|
||
|
||
// Row 1c: detailSurfaceActive wins outright even with multipass=true
|
||
// and a clip-bearing mask that would otherwise hit row 2. Mutation:
|
||
// dropping the detail check returns AppendClipAndImmediate instead.
|
||
yield return new object[]
|
||
{
|
||
false, true, true, (byte)0x08, false,
|
||
(int)RetailAlphaMeshAction.Immediate, (int)RetailAlphaList.Alpha, false,
|
||
};
|
||
|
||
// Row 2a: multipass + clip bit (exact 0x08) -> CLIP,
|
||
// overrideClipmap=true, ALSO immediate. Mutation: an `==` (exact
|
||
// mask match) instead of a bit test would still pass THIS case...
|
||
yield return new object[]
|
||
{
|
||
false, false, true, (byte)0x08, false,
|
||
(int)RetailAlphaMeshAction.AppendClipAndImmediate, (int)RetailAlphaList.Clip, true,
|
||
};
|
||
|
||
// ...but Row 2b (0x09 = clip bit + stipple bit) exposes an `==`
|
||
// mutation: it would fall through to row 3 (Append, no immediate
|
||
// pass) instead of also matching row 2's bit test.
|
||
yield return new object[]
|
||
{
|
||
false, false, true, (byte)0x09, false,
|
||
(int)RetailAlphaMeshAction.AppendClipAndImmediate, (int)RetailAlphaList.Clip, true,
|
||
};
|
||
|
||
// Row 2c: multipass=true but mask has NO clip bit (0x02) -> must
|
||
// fall through to row 3, not row 2. Mutation: a row-2 test that
|
||
// ignores the clip-bit requirement (fires on multipass alone) would
|
||
// return AppendClipAndImmediate here instead of plain Append(Alpha).
|
||
yield return new object[]
|
||
{
|
||
false, false, true, (byte)0x02, false,
|
||
(int)RetailAlphaMeshAction.Append, (int)RetailAlphaList.Alpha, false,
|
||
};
|
||
|
||
// Row 3a: alpha-family mask -> ALPHA, no immediate pass. Mutation:
|
||
// swapping the CLIP/ALPHA selection (always ALPHA regardless of bit
|
||
// 0x08) would still pass this one — paired with 3b below.
|
||
yield return new object[]
|
||
{
|
||
false, false, false, (byte)0x02, false,
|
||
(int)RetailAlphaMeshAction.Append, (int)RetailAlphaList.Alpha, false,
|
||
};
|
||
|
||
// Row 3b: clip-map mask -> CLIP (bit 0x08 selects the list even
|
||
// without multipass). Mutation: always routing row 3 to ALPHA
|
||
// regardless of the clip bit fails THIS case (expects Clip).
|
||
yield return new object[]
|
||
{
|
||
false, false, false, (byte)0x08, false,
|
||
(int)RetailAlphaMeshAction.Append, (int)RetailAlphaList.Clip, false,
|
||
};
|
||
|
||
// Row 3c: translucent-only mask (0x04, no clip bit) -> ALPHA.
|
||
yield return new object[]
|
||
{
|
||
false, false, false, (byte)0x04, false,
|
||
(int)RetailAlphaMeshAction.Append, (int)RetailAlphaList.Alpha, false,
|
||
};
|
||
|
||
// Row-3-inert-stipple: mask 0x01 (stipple bit ONLY, no alpha/clip/
|
||
// translucent bit) does NOT intersect the fixed default delay mask
|
||
// 0x0E (bit 0 is absent from 0x0E) — falls through to row 4.
|
||
// Mutation: including bit 0 in the effective delay test (treating
|
||
// 0x0E as if it were 0x0F) would make this case ALSO match row 3
|
||
// (Append) instead of falling to row 4's material-fallback decision.
|
||
yield return new object[]
|
||
{
|
||
false, false, false, (byte)0x01, true,
|
||
(int)RetailAlphaMeshAction.Append, (int)RetailAlphaList.Alpha, false,
|
||
};
|
||
|
||
// Row 4a: plain mask (0x00), material has_alpha true -> ALPHA
|
||
// fallback. Mutation: requiring the TRANSLUCENT bit (0x04) to
|
||
// ALREADY be set on the mask itself (rather than just checking the
|
||
// DELAY mask's own bit 0x04, which is fixed on regardless of the
|
||
// subset's mask) would make this case fall to row 5 (Immediate)
|
||
// instead.
|
||
yield return new object[]
|
||
{
|
||
false, false, false, (byte)0x00, true,
|
||
(int)RetailAlphaMeshAction.Append, (int)RetailAlphaList.Alpha, false,
|
||
};
|
||
|
||
// Row 4 vs 5: plain mask, material has_alpha FALSE -> row 4's own
|
||
// condition fails -> row 5 Immediate. Mutation: dropping the
|
||
// materialHasAlpha check from row 4 (treating it as "always append
|
||
// when mask is plain") would return Append here instead.
|
||
yield return new object[]
|
||
{
|
||
false, false, false, (byte)0x00, false,
|
||
(int)RetailAlphaMeshAction.Immediate, (int)RetailAlphaList.Alpha, false,
|
||
};
|
||
}
|
||
|
||
/// <summary>
|
||
/// <paramref name="expectedActionRaw"/>/<paramref name="expectedListRaw"/>
|
||
/// are boxed as <see langword="int"/> (not the internal enum types)
|
||
/// because <c>[Theory]</c> methods must be <see langword="public"/> and a
|
||
/// public method cannot expose an <see langword="internal"/> parameter
|
||
/// type — <see cref="RetailAlphaMeshAction"/>/<see cref="RetailAlphaList"/>
|
||
/// stay internal (this assembly's whole alpha-queue surface is internal).
|
||
/// </summary>
|
||
[Theory]
|
||
[MemberData(nameof(RowBoundaryCases))]
|
||
public void Route_MatchesTheHandTracedDecompBoundary(
|
||
bool sky, bool detail, bool multipass, byte mask, bool hasAlpha,
|
||
int expectedActionRaw, int expectedListRaw,
|
||
bool expectedOverrideClipmap)
|
||
{
|
||
var expectedAction = (RetailAlphaMeshAction)expectedActionRaw;
|
||
var expectedList = (RetailAlphaList)expectedListRaw;
|
||
RetailAlphaMeshDecision decision = RetailAlphaMeshRouter.Route(
|
||
sky, RetailAlphaMeshRouter.DefaultDelayMask, detail, multipass, mask, hasAlpha);
|
||
|
||
Assert.Equal(expectedAction, decision.Action);
|
||
if (expectedAction != RetailAlphaMeshAction.Immediate)
|
||
{
|
||
Assert.Equal(expectedList, decision.List);
|
||
Assert.Equal(expectedOverrideClipmap, decision.OverrideClipmap);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// S4-c2 fix round 1 (A7): this was documented as an "INDEPENDENTLY-
|
||
/// shaped reference derivation (a switch-driven truth table, not a copy
|
||
/// of <see cref="RetailAlphaMeshRouter.Route"/>'s own if-chain)" — false;
|
||
/// <see cref="RestatedBranchTableRoute"/> below is the SAME five-row
|
||
/// if-chain shape with different local variable names, not a switch or
|
||
/// lookup table. It is renamed and redocumented honestly rather than
|
||
/// rewritten into a literal 160-row table (spec §4's five rows over ten
|
||
/// masks × sky × detail × multipass × hasAlpha) — the per-row
|
||
/// <see cref="RowBoundaryCases"/> Theory above already carries one
|
||
/// mutation text per row boundary; this brute-force sweep's real value
|
||
/// is catching a copy-paste/off-by-one divergence BETWEEN the two
|
||
/// restatements (a typo in one that the other doesn't share), not an
|
||
/// independent verification of the spec itself. The claim that "each of
|
||
/// the five rows' conditions was flipped in turn and this test failed
|
||
/// every time" is deleted — that hand-verification was never re-run and
|
||
/// is not reproduced in this round's evidence.
|
||
/// </summary>
|
||
[Fact]
|
||
public void Route_MatchesRestatedBranchTableAcrossEveryCell()
|
||
{
|
||
byte[] masks = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09];
|
||
bool[] bothBools = [false, true];
|
||
int mismatches = 0;
|
||
var firstMismatch = "";
|
||
|
||
foreach (byte mask in masks)
|
||
foreach (bool sky in bothBools)
|
||
foreach (bool detail in bothBools)
|
||
foreach (bool multipass in bothBools)
|
||
foreach (bool hasAlpha in bothBools)
|
||
{
|
||
RetailAlphaMeshDecision actual = RetailAlphaMeshRouter.Route(
|
||
sky, RetailAlphaMeshRouter.DefaultDelayMask, detail, multipass, mask, hasAlpha);
|
||
RetailAlphaMeshDecision expected = RestatedBranchTableRoute(
|
||
sky, RetailAlphaMeshRouter.DefaultDelayMask, detail, multipass, mask, hasAlpha);
|
||
|
||
bool matches = actual.Action == expected.Action
|
||
&& (actual.Action == RetailAlphaMeshAction.Immediate
|
||
|| (actual.List == expected.List
|
||
&& actual.OverrideClipmap == expected.OverrideClipmap));
|
||
if (!matches && mismatches++ == 0)
|
||
{
|
||
firstMismatch =
|
||
$"sky={sky} detail={detail} multipass={multipass} mask=0x{mask:x2} "
|
||
+ $"hasAlpha={hasAlpha}: expected {expected}, got {actual}";
|
||
}
|
||
}
|
||
|
||
Assert.True(mismatches == 0, $"{mismatches} mismatches; first: {firstMismatch}");
|
||
}
|
||
|
||
/// <summary>Re-derivation of spec §4's table in independently-named
|
||
/// local variables (NOT a switch/lookup shape — see this Fact's own doc
|
||
/// comment above, A7).</summary>
|
||
private static RetailAlphaMeshDecision RestatedBranchTableRoute(
|
||
bool sky, byte delayMask, bool detail, bool multipass, byte mask, bool hasAlpha)
|
||
{
|
||
bool row1 = sky || delayMask == 0 || detail;
|
||
if (row1)
|
||
return new RetailAlphaMeshDecision(RetailAlphaMeshAction.Immediate, default, false);
|
||
|
||
bool clipBit = (mask & 0b1000) == 0b1000;
|
||
bool row2 = multipass switch
|
||
{
|
||
true => clipBit,
|
||
false => false,
|
||
};
|
||
if (row2)
|
||
return new RetailAlphaMeshDecision(RetailAlphaMeshAction.AppendClipAndImmediate, RetailAlphaList.Clip, true);
|
||
|
||
int intersect = delayMask & mask;
|
||
bool row3 = intersect != 0;
|
||
if (row3)
|
||
{
|
||
RetailAlphaList list = clipBit ? RetailAlphaList.Clip : RetailAlphaList.Alpha;
|
||
return new RetailAlphaMeshDecision(RetailAlphaMeshAction.Append, list, false);
|
||
}
|
||
|
||
bool delayHasTranslucentBit = (delayMask & 0b0100) == 0b0100;
|
||
bool row4 = delayHasTranslucentBit && hasAlpha;
|
||
if (row4)
|
||
return new RetailAlphaMeshDecision(RetailAlphaMeshAction.Append, RetailAlphaList.Alpha, false);
|
||
|
||
return new RetailAlphaMeshDecision(RetailAlphaMeshAction.Immediate, default, false);
|
||
}
|
||
|
||
/// <summary>
|
||
/// <see cref="RetailAlphaMeshRouter.MaskFromTranslucencyKind"/>'s
|
||
/// reachable mapping (opaque/ClipMap are pre-filtered upstream and never
|
||
/// actually call this from a live site, but the function itself must
|
||
/// still map them defensively).
|
||
/// </summary>
|
||
[Theory]
|
||
[InlineData(TranslucencyKind.AlphaBlend, RetailAlphaMeshRouter.MaskAlphaFamily)]
|
||
[InlineData(TranslucencyKind.Additive, RetailAlphaMeshRouter.MaskAlphaFamily)]
|
||
[InlineData(TranslucencyKind.InvAlpha, RetailAlphaMeshRouter.MaskAlphaFamily)]
|
||
[InlineData(TranslucencyKind.ClipMap, RetailAlphaMeshRouter.MaskClipMap)]
|
||
[InlineData(TranslucencyKind.Opaque, (byte)0)]
|
||
public void MaskFromTranslucencyKind_MapsEveryKind(TranslucencyKind kind, byte expectedMask)
|
||
=> Assert.Equal(expectedMask, RetailAlphaMeshRouter.MaskFromTranslucencyKind(kind));
|
||
|
||
/// <summary>Spec §2's priority chain: alpha-family bits win outright over
|
||
/// ClipMap and Translucent even when both are also present. Mutation
|
||
/// check: checking ClipMap before the alpha-family union would return
|
||
/// 0x08 here instead of 0x02.</summary>
|
||
[Fact]
|
||
public void ConstructSubsetMask_AlphaFamilyWinsOverClipMapAndTranslucent()
|
||
{
|
||
byte mask = RetailAlphaMeshRouter.ConstructSubsetMask(
|
||
hasAlphaFamilyBit: true, hasClipMapBit: true, hasTranslucentBit: true,
|
||
hasPositiveStippling: false);
|
||
Assert.Equal(RetailAlphaMeshRouter.MaskAlphaFamily, mask);
|
||
}
|
||
|
||
/// <summary>ClipMap wins over Translucent when no alpha-family bit is
|
||
/// present. Mutation check: checking Translucent before ClipMap would
|
||
/// return 0x04 here instead of 0x08.</summary>
|
||
[Fact]
|
||
public void ConstructSubsetMask_ClipMapWinsOverTranslucentWithoutAlphaFamily()
|
||
{
|
||
byte mask = RetailAlphaMeshRouter.ConstructSubsetMask(
|
||
hasAlphaFamilyBit: false, hasClipMapBit: true, hasTranslucentBit: true,
|
||
hasPositiveStippling: false);
|
||
Assert.Equal(RetailAlphaMeshRouter.MaskClipMap, mask);
|
||
}
|
||
|
||
/// <summary>Positive stippling ORs bit 0x01 onto whichever base mask
|
||
/// applies. Mutation check: forgetting the OR (or using an exclusive
|
||
/// select) would leave the base mask value (0x04) instead of 0x05.</summary>
|
||
[Fact]
|
||
public void ConstructSubsetMask_PositiveStipplingOrsIntoTheBaseMask()
|
||
{
|
||
byte mask = RetailAlphaMeshRouter.ConstructSubsetMask(
|
||
hasAlphaFamilyBit: false, hasClipMapBit: false, hasTranslucentBit: true,
|
||
hasPositiveStippling: true);
|
||
Assert.Equal((byte)(RetailAlphaMeshRouter.MaskTranslucent | RetailAlphaMeshRouter.MaskPositiveStipple), mask);
|
||
}
|
||
}
|