The first commit converted the four members the issue named and left the other sites alone, reasoning that none had been observed failing. A 20-run complete-solution baseline disproved that within minutes: run 2 LiveEntityRuntimeTests.AnimationView_HotSpatialTraversal… run 14 StaticRenderProjectionJournalTests.ActiveAnimatedSynchronization… run 18 StaticRenderProjectionJournalTests.ActiveAnimatedSynchronization… run 19 CurrentRenderSceneOracleTests.SurfaceOverrideFingerprint… Both new names are the same shape as the four — one warm call, then a thousand-iteration loop inside the measured window — and neither had been recorded anywhere. "Not observed failing" only ever meant "not yet observed", and leaving known-shape sites in place would have guaranteed the acceptance gate failed. Run 19 is the sharper lesson: the issue named `SurfaceOverrideFingerprint_DictionaryHotPathAllocatesNothing`, and the first commit converted a *different* test in that same file, so the actually-named member was still on the old shape. Matching by file was not matching by test. Every strict-zero site in the assembly is now on the probe — ten tests. Two came out stricter rather than merely steadier: `StaticRenderProjectionJournalTests` was measuring a synchronise whose journal does **not** coalesce. Repeating it grew the journal by 1,000 entries per call — 192,000 by the end of a probe run — so the steady state the test claimed to measure did not exist and the single-call window had been hiding it. Its step is now the whole frame cycle, synchronise *and* drain, which puts `DrainTo` inside the measured window for the first time and asserts the journal ends empty. `RetailInboundEventDispatcherTests` asserted a hard-coded 1,001 callbacks. It now counts its own dispatches and pins the callback count against that, so the assertion still proves the fast path ran the callback every time without being coupled to a loop bound that no longer exists. Left alone deliberately: the four sites asserting a tolerance rather than zero — `CellViewDedupTests` and `PortalProjectionTests`. Their ceilings already absorb this noise and none has flaked; changing a bound in either direction is a separate decision from fixing a measurement. Worth noting that `PortalProjectionTests`' ceiling exists explicitly to tolerate "a tiered-JIT/ArrayPool bookkeeping transition ... to the first measured batch", which is exactly what the probe removes, so it could probably be tightened to zero now — recorded in the issue rather than done here. Solution build 0 warnings / 0 errors; App suite 3,941 passed / 3 skipped. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
145 lines
4.6 KiB
C#
145 lines
4.6 KiB
C#
using System.Numerics;
|
|
using AcDream.App.Rendering.Scene;
|
|
using AcDream.App.Streaming;
|
|
using AcDream.Core.Physics;
|
|
using AcDream.Core.World;
|
|
using DatReaderWriter.DBObjs;
|
|
|
|
namespace AcDream.App.Tests.Streaming;
|
|
|
|
public sealed class GpuWorldStateRenderTraversalTests
|
|
{
|
|
private const uint FirstLandblock = 0x1234FFFFu;
|
|
private const uint SecondLandblock = 0x1235FFFFu;
|
|
private const uint ReusedLandblock = 0x1236FFFFu;
|
|
|
|
[Fact]
|
|
public void TraversalKeys_MirrorResidentLandblockAndMutableBucketOrder()
|
|
{
|
|
var state = new GpuWorldState();
|
|
WorldEntity first = Entity(1, 0x80000001u);
|
|
WorldEntity moved = Entity(2, 0x80000002u);
|
|
WorldEntity secondLandblockEntity = Entity(3, 0x80000003u);
|
|
state.AddLandblock(Landblock(FirstLandblock, first, moved));
|
|
state.AddLandblock(Landblock(
|
|
SecondLandblock,
|
|
secondLandblockEntity));
|
|
|
|
AssertSort(state, first, landblockOrder: 1, entityIndex: 0);
|
|
AssertSort(state, moved, landblockOrder: 1, entityIndex: 1);
|
|
AssertSort(
|
|
state,
|
|
secondLandblockEntity,
|
|
landblockOrder: 2,
|
|
entityIndex: 0);
|
|
|
|
state.RemoveLiveEntityProjection(first);
|
|
|
|
AssertSort(state, moved, landblockOrder: 1, entityIndex: 0);
|
|
|
|
WorldEntity replacement = Entity(4, 0x80000004u);
|
|
state.AddLandblock(Landblock(SecondLandblock, replacement));
|
|
|
|
Assert.False(state.TryGetRenderTraversalSortKey(
|
|
secondLandblockEntity,
|
|
out _));
|
|
AssertSort(state, replacement, landblockOrder: 2, entityIndex: 0);
|
|
|
|
state.RemoveLandblock(FirstLandblock);
|
|
WorldEntity reused = Entity(5, 0x80000005u);
|
|
state.AddLandblock(Landblock(ReusedLandblock, reused));
|
|
|
|
AssertSort(state, reused, landblockOrder: 1, entityIndex: 0);
|
|
Assert.Equal(
|
|
[ReusedLandblock, SecondLandblock],
|
|
state.LandblockEntriesWithoutAnimatedIndex
|
|
.Select(static entry => entry.LandblockId)
|
|
.ToArray());
|
|
}
|
|
|
|
[Fact]
|
|
public void TraversalKey_IsUnavailableWhileProjectionIsPending()
|
|
{
|
|
var state = new GpuWorldState();
|
|
WorldEntity pending = Entity(1, 0x80000001u);
|
|
|
|
state.PlaceLiveEntityProjection(FirstLandblock, pending);
|
|
|
|
Assert.False(state.TryGetRenderTraversalSortKey(pending, out _));
|
|
}
|
|
|
|
[Fact]
|
|
public void StableRenderViews_AllocateOnlyWhenSpatialContentChanges()
|
|
{
|
|
var state = new GpuWorldState();
|
|
state.AddLandblock(Landblock(
|
|
FirstLandblock,
|
|
Entity(1, 0x80000001u)));
|
|
state.SetLandblockAabb(
|
|
FirstLandblock,
|
|
new Vector3(1f, 2f, 3f),
|
|
new Vector3(4f, 5f, 6f));
|
|
|
|
var entries = state.LandblockEntries;
|
|
var bounds = state.LandblockBounds;
|
|
_ = entries.Count;
|
|
_ = bounds.Count;
|
|
// #250: the measured window was a 1,000-iteration loop written inline.
|
|
ZeroAllocationProbe.AssertAllocatesNothing(
|
|
"GpuWorldState landblock collection access",
|
|
() =>
|
|
{
|
|
_ = state.LandblockEntries.Count;
|
|
_ = state.LandblockBounds.Count;
|
|
});
|
|
|
|
Assert.Same(entries, state.LandblockEntries);
|
|
Assert.Same(bounds, state.LandblockBounds);
|
|
|
|
state.AddLandblock(Landblock(
|
|
SecondLandblock,
|
|
Entity(2, 0x80000002u)));
|
|
|
|
Assert.Same(entries, state.LandblockEntries);
|
|
Assert.Same(bounds, state.LandblockBounds);
|
|
Assert.Equal(2, entries.Count);
|
|
Assert.Equal(2, bounds.Count);
|
|
}
|
|
|
|
private static void AssertSort(
|
|
GpuWorldState state,
|
|
WorldEntity entity,
|
|
uint landblockOrder,
|
|
int entityIndex)
|
|
{
|
|
Assert.True(state.TryGetRenderTraversalSortKey(
|
|
entity,
|
|
out RenderSortKey actual));
|
|
Assert.Equal(
|
|
RenderTraversalSortKey.Compose(landblockOrder, entityIndex),
|
|
actual);
|
|
}
|
|
|
|
private static LoadedLandblock Landblock(
|
|
uint landblockId,
|
|
params WorldEntity[] entities) =>
|
|
new(
|
|
landblockId,
|
|
new LandBlock(),
|
|
entities,
|
|
PhysicsDatBundle.Empty);
|
|
|
|
private static WorldEntity Entity(uint id, uint serverGuid) =>
|
|
new()
|
|
{
|
|
Id = id,
|
|
ServerGuid = serverGuid,
|
|
SourceGfxObjOrSetupId = 0x02000001u,
|
|
Position = Vector3.Zero,
|
|
Rotation = Quaternion.Identity,
|
|
MeshRefs =
|
|
[
|
|
new MeshRef(0x01000001u, Matrix4x4.Identity),
|
|
],
|
|
};
|
|
}
|