Revert "Campaign V slice V4a" - it lost world multisampling

This reverts ceec3bc4. Two independent reasons, either sufficient.

The rendering regression. The slice deleted TextRenderGlStateScope, which
saved GL_MULTISAMPLE and GL_SAMPLE_ALPHA_TO_COVERAGE on entry, disabled them
for the text pass, and restored them on exit (TextRenderGlStateScope.cs:111-112
and 153-154 at the parent commit). Its replacement bakes that state into the
text pipeline but nothing restores it, and GlGpuPassEncoder.Dispose does not
either. Every world renderer is still raw GL at this point in the campaign, so
from the first UI frame onward the world drew with multisampling disabled.

The offline pixel gate caught it: 1,791 of 563,200 compared pixels differed,
0.318% against a 0.001 threshold. The commit message attributed this to
wall-clock-driven ambient animation shifting phase, and committed through the
failure. That explanation does not survive its own control: capturing twice at
the reverted-to commit differs by 19 pixels and twice at the slice's own commit
by 8, while base-versus-head differs by 1,791 - a 224x gap that no shared-noise
source explains. An amplified difference image settles it visually: the changed
pixels are the silhouette edges of every tree, building and rock, with terrain
interiors, water and the entire UI untouched. That is the signature of losing
edge antialiasing, not of animated sprites.

This is the exact failure mode two existing memory notes already warn about -
a mid-frame renderer must set every GL state it uses rather than inherit it,
and issue #52's lesson that a rendering migration must audit per-pass GL state
before declaring itself done.

The scope. The brief was three small leaf renderers plus additive frame-
lifecycle wiring, roughly ten files. The commit changed 334 files with 3,665
insertions and 3,845 deletions, including 323 public-to-internal visibility
conversions across the App assembly, 55 test files, two retired conformance
tests, and a self-described temporary escape hatch for bridging raw-GL viewport
textures. Even without the regression, that is not separable into the part
worth keeping and the part worth dropping.

Reverting rather than patching because the good work here - the RHI frame
lifecycle wiring and a genuine render-state-cache staleness fix - is small
enough to redo cleanly against a tightened spec, while untangling it from 300+
files of unrelated churn is not.

Post-revert: Release build clean, App suite back to 3,843 passed / 3 skipped,
offline pixel gate passing at 19 differing pixels.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-07-27 18:27:52 +02:00
parent ceec3bc440
commit 9aaf97e785
334 changed files with 3841 additions and 3661 deletions

View file

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using AcDream.Core.Combat;
using AcDream.Core.Items;
@ -8,7 +8,7 @@ using AcDream.Core.Selection;
namespace AcDream.App.UI.Layout;
/// <summary>
/// Binds the imported gmToolbarUI window (LayoutDesc 0x21000016) to live data —
/// Binds the imported gmToolbarUI window (LayoutDesc 0x21000016) to live data
/// the gm*UI::PostInit analogue. Finds the 18 shortcut slots (UiItemList) by id,
/// populates them from the persisted PlayerDescription shortcuts
/// (UpdateFromPlayerDesc), re-binds deferred slots when an item's CreateObject
@ -24,7 +24,7 @@ namespace AcDream.App.UI.Layout;
/// <c>CreateObject</c> resolves a formerly-unknown guid.
/// </para>
/// </summary>
internal sealed class ToolbarController : IItemListDragHandler, IRetainedPanelController
public sealed class ToolbarController : IItemListDragHandler, IRetainedPanelController
{
// Slot element ids in slot-index order (toolbar LayoutDesc 0x21000016, pre-dump).
// Row 1 = slots 0-8 (0x100001A7..0x100001AF), Row 2 = slots 9-17 (0x100006B7..0x100006BF).
@ -39,7 +39,7 @@ internal sealed class ToolbarController : IItemListDragHandler, IRetainedPanelCo
// SelectedObjectController owns the health/mana meters and both stack controls,
// including retail's initial-hidden state and selection-driven visibility.
// Four mutually-exclusive combat-mode indicator elements — exactly one visible at a time.
// Four mutually-exclusive combat-mode indicator elements exactly one visible at a time.
// Index 0 = NonCombat (peace), 1 = Melee, 2 = Missile, 3 = Magic.
// Retail ref: gmToolbarUI::RecvNotice_SetCombatMode (acclient_2013_pseudo_c.txt:196632-196669)
// SetVisible's exactly one element depending on the incoming mode.
@ -64,9 +64,9 @@ internal sealed class ToolbarController : IItemListDragHandler, IRetainedPanelCo
private readonly ClientObjectTable _repo;
private readonly CombatState? _combatState;
private readonly ShortcutStore _store;
private readonly Func<ItemType, uint, uint, uint, uint, GpuTextureSlot> _iconIds; // (itemType, icon, underlay, overlay, effects) → GL tex
private readonly Func<ItemType, uint, uint, uint, uint, GpuTextureSlot>? _dragIconIds;
private readonly Action<uint> _useItem; // guid → fire UseObject
private readonly Func<ItemType, uint, uint, uint, uint, uint> _iconIds; // (itemType, icon, underlay, overlay, effects) → GL tex
private readonly Func<ItemType, uint, uint, uint, uint, uint>? _dragIconIds;
private readonly Action<uint> _useItem; // guid fire UseObject
private readonly Action<ShortcutEntry>? _sendAddShortcut;
private readonly Action<uint>? _sendRemoveShortcut; // (index)
private readonly ItemInteractionController? _itemInteraction;
@ -83,8 +83,8 @@ internal sealed class ToolbarController : IItemListDragHandler, IRetainedPanelCo
// Retail ref: UIElement_UIItem::SetShortcutNum (acclient_2013_pseudo_c.txt:229465);
// gmToolbarUI::RecvNotice_SetCombatMode (196610-196621) re-stamps ghosting.
// Occupancy branch (decomp 229481):
// occupied → regular 0x10000042 / ghosted 0x10000043
// empty → background digit 0x1000005e (stance-independent)
// occupied regular 0x10000042 / ghosted 0x10000043
// empty background digit 0x1000005e (stance-independent)
private uint[]? _regularDigits;
private uint[]? _ghostedDigits;
private uint[]? _emptyDigits;
@ -94,7 +94,7 @@ internal sealed class ToolbarController : IItemListDragHandler, IRetainedPanelCo
ImportedLayout layout,
ClientObjectTable repo,
ShortcutStore shortcuts,
Func<ItemType, uint, uint, uint, uint, GpuTextureSlot> iconIds,
Func<ItemType, uint, uint, uint, uint, uint> iconIds,
Action<uint> useItem,
CombatState? combatState,
uint[]? regularDigits,
@ -110,7 +110,7 @@ internal sealed class ToolbarController : IItemListDragHandler, IRetainedPanelCo
Func<uint>? playerGuid = null,
Action<uint, uint, int>? sendPutItemInContainer = null,
UiDatFont? ammoFont = null,
Func<ItemType, uint, uint, uint, uint, GpuTextureSlot>? dragIconIds = null)
Func<ItemType, uint, uint, uint, uint, uint>? dragIconIds = null)
{
_repo = repo;
_combatState = combatState;
@ -193,7 +193,7 @@ internal sealed class ToolbarController : IItemListDragHandler, IRetainedPanelCo
_examineButton.OnClick = () => _itemInteraction?.ExamineSelectedOrEnterMode(_selectedObjectId());
// Port of gmToolbarUI::RecvNotice_SetCombatMode (acclient_2013_pseudo_c.txt:196632-196669):
// exactly one indicator visible at a time. Default to NonCombat (peace) — the player
// exactly one indicator visible at a time. Default to NonCombat (peace) the player
// always spawns in peace mode; retail has not yet called SetVisible when PostInit runs.
SetCombatMode(CombatMode.NonCombat);
@ -204,7 +204,7 @@ internal sealed class ToolbarController : IItemListDragHandler, IRetainedPanelCo
_selection.Changed += OnSelectionChanged;
// D.5.4: the table now holds ALL objects (creatures, NPCs, etc.), so filter
// to our 18 shortcut guids — else every creature spawn in a busy zone
// to our 18 shortcut guids else every creature spawn in a busy zone
// needlessly re-populates the bar (gmToolbarUI::SetDelayedShortcutNum pattern).
repo.ObjectAdded += OnRepositoryObjectChanged;
repo.ObjectUpdated += OnRepositoryObjectChanged;
@ -310,22 +310,22 @@ internal sealed class ToolbarController : IItemListDragHandler, IRetainedPanelCo
/// if the shortcut list is refreshed outside the repo-event path.
/// </summary>
/// <param name="layout">Imported toolbar layout (LayoutDesc 0x21000016).</param>
/// <param name="repo">Live item repository — must stay alive for the controller's lifetime.</param>
/// <param name="repo">Live item repository must stay alive for the controller's lifetime.</param>
/// <param name="shortcuts">
/// Runtime-owned retail shortcut manager. The toolbar borrows this exact
/// mutable owner; it never reconstructs another slot map.
/// </param>
/// <param name="iconIds">Resolves (itemType, iconId, underlayId, overlayId, effects) → GL texture handle.</param>
/// <param name="iconIds">Resolves (itemType, iconId, underlayId, overlayId, effects) GL texture handle.</param>
/// <param name="useItem">Callback fired when a bound slot is clicked; receives the item guid.</param>
/// <param name="combatState">
/// Optional live combat state — when provided, the toolbar subscribes to
/// Optional live combat state when provided, the toolbar subscribes to
/// <see cref="CombatState.CombatModeChanged"/> and updates the four mutually-exclusive
/// combat-mode indicator elements accordingly.
/// Pass null to skip live wiring (e.g. in unit tests that don't exercise the indicator).
/// </param>
/// <param name="regularDigits">
/// Regular digit DID array (property 0x10000042 from LayoutDesc 0x21000037 element
/// 0x1000034A under composite 0x10000346). Index i → slot label digit (i+1) RenderSurface id.
/// 0x1000034A under composite 0x10000346). Index i slot label digit (i+1) RenderSurface id.
/// Null if the dat lookup failed (no digits drawn). Retail reference:
/// UIElement_UIItem::SetShortcutNum (acclient_2013_pseudo_c.txt:229465).
/// </param>
@ -333,14 +333,14 @@ internal sealed class ToolbarController : IItemListDragHandler, IRetainedPanelCo
/// <param name="emptyDigits">
/// Empty-slot background digit DID array (property 0x1000005e, stance-independent).
/// Used when a slot is EMPTY (ItemId == 0). Retail ref: UIElement_UIItem::SetShortcutNum
/// (decomp 229481) — else branch when m_elem_Icon->m_state == 0x1000001c (empty state).
/// (decomp 229481) else branch when m_elem_Icon->m_state == 0x1000001c (empty state).
/// Null if the dat lookup failed (empty slots draw no digit, which is safe).
/// </param>
public static ToolbarController Bind(
ImportedLayout layout,
ClientObjectTable repo,
ShortcutStore shortcuts,
Func<ItemType, uint, uint, uint, uint, GpuTextureSlot> iconIds,
Func<ItemType, uint, uint, uint, uint, uint> iconIds,
Action<uint> useItem,
CombatState? combatState = null,
uint[]? regularDigits = null,
@ -356,7 +356,7 @@ internal sealed class ToolbarController : IItemListDragHandler, IRetainedPanelCo
Func<uint>? playerGuid = null,
Action<uint, uint, int>? sendPutItemInContainer = null,
UiDatFont? ammoFont = null,
Func<ItemType, uint, uint, uint, uint, GpuTextureSlot>? dragIconIds = null)
Func<ItemType, uint, uint, uint, uint, uint>? dragIconIds = null)
{
var c = new ToolbarController(layout, repo, shortcuts, iconIds, useItem, combatState,
regularDigits, ghostedDigits, emptyDigits, itemInteraction,
@ -427,15 +427,15 @@ internal sealed class ToolbarController : IItemListDragHandler, IRetainedPanelCo
if (list is null) continue;
var item = _repo.Get(guid);
if (item is null) continue; // deferred: ObjectAdded re-calls Populate
GpuTextureSlot tex = _iconIds(item.Type, item.IconId, item.IconUnderlayId, item.IconOverlayId, item.Effects);
GpuTextureSlot? dragTex = _dragIconIds?.Invoke(
item.Type, item.IconId, item.IconUnderlayId, item.IconOverlayId, item.Effects);
uint tex = _iconIds(item.Type, item.IconId, item.IconUnderlayId, item.IconOverlayId, item.Effects);
uint dragTex = _dragIconIds?.Invoke(
item.Type, item.IconId, item.IconUnderlayId, item.IconOverlayId, item.Effects) ?? 0u;
list.Cell.SetItem(guid, tex, entry, dragTex);
}
// Re-stamp slot number labels after any item change.
// Digit SPRITE SOURCE depends on occupancy (decomp UIElement_UIItem::SetShortcutNum:229481):
// occupied → regular 0x10000042 / ghosted 0x10000043; empty → background 0x1000005e.
// occupied → regular 0x10000042 / ghosted 0x10000043; empty → background 0x1000005e.
// The digit is ALWAYS shown on top-row slots (SetVisible(1) at decomp 229511).
RestampShortcutNumbers();
}
@ -450,7 +450,7 @@ internal sealed class ToolbarController : IItemListDragHandler, IRetainedPanelCo
/// </summary>
public void SetCombatMode(CombatMode mode)
{
// Index → mode mapping matches CombatIndicatorIds declaration order:
// Index mode mapping matches CombatIndicatorIds declaration order:
// 0 = NonCombat (peace), 1 = Melee, 2 = Missile, 3 = Magic.
bool[] show =
{
@ -475,14 +475,14 @@ internal sealed class ToolbarController : IItemListDragHandler, IRetainedPanelCo
/// <summary>
/// Push digit-array references and shortcut-number state into every slot cell.
/// Top row (indices 0–8): SetShortcutNum(i, _shortcutsGhosted) — numbers 1–9 always shown
/// Top row (indices 08): SetShortcutNum(i, _shortcutsGhosted) — numbers 19 always shown
/// (the digit is ALWAYS visible, SetVisible(1) at decomp 229511; only the sprite
/// SOURCE differs by occupancy — see UIElement_UIItem::SetShortcutNum decomp 229481).
/// Bottom row (indices 9–17): ClearShortcutNum() — retail shows no numbers there.
/// SOURCE differs by occupancy see UIElement_UIItem::SetShortcutNum decomp 229481).
/// Bottom row (indices 917): ClearShortcutNum() — retail shows no numbers there.
/// Retail ref: UIElement_UIItem::SetShortcutNum (acclient_2013_pseudo_c.txt:229465);
/// gmToolbarUI::RecvNotice_SetCombatMode (196610-196621).
/// Occupancy → source: occupied → regular 0x10000042 / ghosted 0x10000043;
/// empty → background 0x1000005e (decomp 229481/229493).
/// Occupancy → source: occupied → regular 0x10000042 / ghosted 0x10000043;
/// empty background 0x1000005e (decomp 229481/229493).
/// </summary>
private void RestampShortcutNumbers()
{
@ -494,7 +494,7 @@ internal sealed class ToolbarController : IItemListDragHandler, IRetainedPanelCo
cell.GhostedDigits = _ghostedDigits;
cell.EmptyDigits = _emptyDigits;
if (i < 9)
cell.SetShortcutNum(i, _shortcutsGhosted); // top row: slot labels 1–9 always shown
cell.SetShortcutNum(i, _shortcutsGhosted); // top row: slot labels 19 always shown
else
cell.ClearShortcutNum(); // bottom row: no slot labels
}
@ -503,7 +503,7 @@ internal sealed class ToolbarController : IItemListDragHandler, IRetainedPanelCo
/// <summary>
/// Wire the <see cref="UiItemSlot.Clicked"/> callback on a slot cell so that
/// clicking a bound item fires <see cref="_useItem"/> with the slot's current guid.
/// Mirrors retail's <c>gmToolbarUI</c> click → <c>UseShortcut</c> dispatch.
/// Mirrors retail's <c>gmToolbarUI</c> click <c>UseShortcut</c> dispatch.
/// </summary>
private void WireClick(UiItemList list)
{
@ -662,12 +662,12 @@ internal sealed class ToolbarController : IItemListDragHandler, IRetainedPanelCo
return true;
}
// ── IItemListDragHandler (B.2 live handler) ──────────────────────────────
// ── IItemListDragHandler (B.2 live handler) ──────────────────────────────
// Retail: gmToolbarUI is the m_dragHandler for every shortcut slot list.
// Retail model (remove-on-lift / place-on-drop / no-restore):
// lift → RemoveShortcut (0x019D) + store.Remove (slot empties immediately)
// drop → AddShortcut (0x019C) + optional swap of evicted item into source
// off-bar release → the lift's removal stands (no restore)
// lift RemoveShortcut (0x019D) + store.Remove (slot empties immediately)
// drop AddShortcut (0x019C) + optional swap of evicted item into source
// off-bar release the lift's removal stands (no restore)
// Retail ref: gmToolbarUI::HandleDropRelease acclient_2013_pseudo_c.txt:197971
/// <inheritdoc/>
@ -678,7 +678,7 @@ internal sealed class ToolbarController : IItemListDragHandler, IRetainedPanelCo
if (payload.ObjId != 0 && _selectedObjectId() != payload.ObjId)
_selectItem?.Invoke(payload.ObjId);
// Retail RecvNotice_ItemListBeginDrag → RemoveShortcut (0x004bd930/0x004bd450): the lifted
// Retail RecvNotice_ItemListBeginDrag RemoveShortcut (0x004bd930/0x004bd450): the lifted
// shortcut leaves the bar (+ wire) the instant the drag starts; it's re-placed only on a
// drop onto a slot. Off-bar release leaves it removed.
_sendRemoveShortcut?.Invoke((uint)payload.SourceSlot);