test(render): Phase U.4 — cover ResolveEntitySlot clip-slot resolution
Code review flagged the gate-critical per-instance slot resolution as untested. Add RED→GREEN cases (live=unclipped slot 0, cell-static→cell slot, non-visible→cull, outdoor-stab→OutsideView/cull, routing-inactive→all slot 0). Note the full-cell-id-space invariant at ResolveEntitySlot; fix a stale RenderInsideOut comment in EnvCellRenderer. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7993e064a0
commit
354ca746ad
3 changed files with 259 additions and 22 deletions
|
|
@ -764,8 +764,11 @@ public sealed unsafe class EnvCellRenderer : IDisposable
|
|||
/// <summary>
|
||||
/// Draws all visible EnvCells (and their static objects) for the given pass.
|
||||
/// When <paramref name="filter"/> is non-null, only cells whose CellId is in
|
||||
/// the set are drawn — used for indoor RenderInsideOut to restrict to camera-
|
||||
/// building cells.
|
||||
/// the set are drawn. As of Phase U.4 this is the portal-visibility SHELL
|
||||
/// filter (the drawable visible cells from the PView traversal; each cell's
|
||||
/// shell instances are clip-gated to its CellClip slot by the caller's
|
||||
/// binding=3 map). NOTE: this is NOT the old two-pipe RenderInsideOut approach
|
||||
/// — that flat camera-inside-building stencil pass was deleted in Phase U.1.
|
||||
/// Source: WB EnvCellRenderManager.cs:399-511 (verbatim minus selection highlights).
|
||||
/// </summary>
|
||||
public void Render(WbRenderPass renderPass, HashSet<uint>? filter)
|
||||
|
|
|
|||
|
|
@ -346,7 +346,9 @@ public sealed unsafe class WbDrawDispatcher : IDisposable
|
|||
// Phase U.4 CULL sentinel returned by ResolveEntitySlot: the entity's instances
|
||||
// are dropped entirely (not emitted into the binding=0 instance buffer NOR the
|
||||
// binding=3 slot buffer), matching the existing frustum / visible-cell cull.
|
||||
private const int ClipSlotCull = -1;
|
||||
// Internal (not private) so the clip-slot unit tests can assert against it
|
||||
// directly — see WbDrawDispatcherClipSlotTests.
|
||||
internal const int ClipSlotCull = -1;
|
||||
|
||||
/// <summary>
|
||||
/// Phase U.4: resolve the clip slot for one entity per the slot/gate policy.
|
||||
|
|
@ -355,27 +357,74 @@ public sealed unsafe class WbDrawDispatcher : IDisposable
|
|||
/// <item>ServerGuid != 0 (live dynamic: player / NPC / items / doors) ⇒ slot 0
|
||||
/// (UNCLIPPED — retail draws live-dynamic unclipped; depth only).</item>
|
||||
/// <item>ParentCellId != null (cell static) ⇒ the cell's slot, or CULL when the
|
||||
/// cell isn't in <c>cellIdToSlot</c> (not visible / nothing-visible).</item>
|
||||
/// cell isn't in <paramref name="cellIdToSlot"/> (not visible / nothing-visible).</item>
|
||||
/// <item>ParentCellId == null (outdoor scenery / building shell) ⇒ the OutsideView
|
||||
/// slot when <c>outdoorVisible</c>, else CULL.</item>
|
||||
/// slot when <paramref name="outdoorVisible"/>, else CULL.</item>
|
||||
/// </list>
|
||||
/// Only called when <c>_clipRoutingActive</c> (indoor root). On the U.3 / outdoor
|
||||
/// path every instance is slot 0 and nothing is culled.
|
||||
/// path every instance is slot 0 and nothing is culled — see
|
||||
/// <see cref="ResolveSlotForFrame"/>, which gates on that flag.
|
||||
/// <para>
|
||||
/// INVARIANT: <paramref name="parentCellId"/> and the keys of
|
||||
/// <paramref name="cellIdToSlot"/> MUST live in the same FULL cell-id space
|
||||
/// (<c>lbMask | OtherCellId</c>, e.g. <c>0xA9B40164</c>). A bare-low-byte
|
||||
/// ParentCellId (e.g. <c>0x64</c>) would never match a full-id key and would
|
||||
/// silently CULL every indoor stab — cf. the L.2e bare-low-byte finding in
|
||||
/// CLAUDE.md where player CellId was tracked without its landblock prefix.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <c>internal static</c> + pure (reads no instance state) so the clip-slot
|
||||
/// unit tests exercise every branch without a GL context. The caller hands in
|
||||
/// the routing fields it would otherwise read from <c>_cellIdToSlot</c> etc.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
private int ResolveEntitySlot(WorldEntity entity)
|
||||
internal static int ResolveEntitySlot(
|
||||
uint serverGuid,
|
||||
uint? parentCellId,
|
||||
IReadOnlyDictionary<uint, int> cellIdToSlot,
|
||||
int outdoorSlot,
|
||||
bool outdoorVisible)
|
||||
{
|
||||
// Live-dynamic entities render unclipped regardless of cell — retail draws
|
||||
// the player / NPCs / dropped items through the depth buffer without portal
|
||||
// clipping. ServerGuid is the live-dynamic marker (0 for dat-hydrated).
|
||||
if (entity.ServerGuid != 0)
|
||||
if (serverGuid != 0)
|
||||
return 0;
|
||||
|
||||
if (entity.ParentCellId is uint parentCell)
|
||||
return _cellIdToSlot!.TryGetValue(parentCell, out int slot) ? slot : ClipSlotCull;
|
||||
if (parentCellId is uint parentCell)
|
||||
return cellIdToSlot.TryGetValue(parentCell, out int slot) ? slot : ClipSlotCull;
|
||||
|
||||
// Outdoor scenery / building shell (no ParentCellId). Indoor root: gate to
|
||||
// the OutsideView slot, or cull when nothing outdoors is visible.
|
||||
return _outdoorVisible ? _outdoorSlot : ClipSlotCull;
|
||||
return outdoorVisible ? outdoorSlot : ClipSlotCull;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Phase U.4: the call-site clip-slot decision for one entity, returning the
|
||||
/// <c>(Slot, Culled)</c> pair the per-entity loop body consumes. Wraps
|
||||
/// <see cref="ResolveEntitySlot"/> with the <paramref name="clipRoutingActive"/>
|
||||
/// gate: when routing is INACTIVE (outdoor root / no portal frame), every entity
|
||||
/// is slot 0 and nothing is clip-culled — the bit-identical-to-U.3 property, so
|
||||
/// the resolver (and <paramref name="cellIdToSlot"/>) is bypassed entirely.
|
||||
/// When active, a CULL sentinel maps to <c>(0, culled=true)</c> — the slot value
|
||||
/// is never emitted for a culled entity.
|
||||
/// <c>internal static</c> + pure so the whole policy (including the routing-
|
||||
/// inactive branch) is unit-testable — see WbDrawDispatcherClipSlotTests.
|
||||
/// </summary>
|
||||
internal static (uint Slot, bool Culled) ResolveSlotForFrame(
|
||||
bool clipRoutingActive,
|
||||
uint serverGuid,
|
||||
uint? parentCellId,
|
||||
IReadOnlyDictionary<uint, int>? cellIdToSlot,
|
||||
int outdoorSlot,
|
||||
bool outdoorVisible)
|
||||
{
|
||||
if (!clipRoutingActive)
|
||||
return (0u, false);
|
||||
|
||||
int resolved = ResolveEntitySlot(serverGuid, parentCellId, cellIdToSlot!, outdoorSlot, outdoorVisible);
|
||||
bool culled = resolved == ClipSlotCull;
|
||||
return (culled ? 0u : (uint)resolved, culled);
|
||||
}
|
||||
|
||||
public static Matrix4x4 ComposePartWorldMatrix(
|
||||
|
|
@ -775,17 +824,11 @@ public sealed unsafe class WbDrawDispatcher : IDisposable
|
|||
// Phase U.4: resolve this entity's clip slot ONCE per entity
|
||||
// (constant across its tuples). On the U.3 / outdoor path
|
||||
// (_clipRoutingActive false) every entity is slot 0, never culled.
|
||||
if (_clipRoutingActive)
|
||||
{
|
||||
int resolved = ResolveEntitySlot(entity);
|
||||
_currentEntityCulled = resolved == ClipSlotCull;
|
||||
_currentEntitySlot = _currentEntityCulled ? 0u : (uint)resolved;
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentEntityCulled = false;
|
||||
_currentEntitySlot = 0u;
|
||||
}
|
||||
// The whole decision (including the routing-active gate) lives in
|
||||
// the pure ResolveSlotForFrame helper so it's unit-testable.
|
||||
(_currentEntitySlot, _currentEntityCulled) = ResolveSlotForFrame(
|
||||
_clipRoutingActive, entity.ServerGuid, entity.ParentCellId,
|
||||
_cellIdToSlot, _outdoorSlot, _outdoorVisible);
|
||||
}
|
||||
prevTupleEntityId = entity.Id;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue