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.Numerics;
namespace AcDream.App.UI;
@ -22,7 +22,7 @@ public enum ResizeEdges { None = 0, Left = 1, Right = 2, Top = 4, Bottom = 8 }
/// or <see cref="WorldKeyFallThrough"/> event fires so the game world
/// (camera, player controller) still receives input.
/// </summary>
internal sealed class UiRoot : UiElement
public sealed class UiRoot : UiElement
{
public UiRoot()
{
@ -32,7 +32,7 @@ internal sealed class UiRoot : UiElement
/// <summary>Single owner for named retained-window lifecycle and raise policy.</summary>
public RetailWindowManager WindowManager { get; }
// ── Device-level state ───────────────────────────────────────────────
// ── Device-level state ───────────────────────────────────────────────
public int MouseX { get; private set; }
public int MouseY { get; private set; }
public bool LeftButtonDown { get; private set; }
@ -42,7 +42,7 @@ internal sealed class UiRoot : UiElement
/// <summary>Widget currently receiving keyboard events.</summary>
public UiElement? KeyboardFocus { get; private set; }
/// <summary>The edit control activated by Tab/Enter when nothing is focused — retail's
/// <summary>The edit control activated by Tab/Enter when nothing is focused retail's
/// chat input "write mode" toggle. Set by the host once the chat window is built.</summary>
public UiElement? DefaultTextInput { get; set; }
@ -59,7 +59,7 @@ internal sealed class UiRoot : UiElement
/// True when the pointer is over a widget OR a widget holds mouse capture.
/// The host ORs this into the InputDispatcher's WantCaptureMouse gate so game
/// actions (movement, world-pick) are suppressed while the user interacts with
/// a retail window — mirrors ImGui's WantCaptureMouse.
/// a retail window mirrors ImGui's WantCaptureMouse.
/// </summary>
public bool WantsMouse => Captured is not null || HitTestTopDown(MouseX, MouseY).element is not null;
@ -111,9 +111,9 @@ internal sealed class UiRoot : UiElement
&& !target.HandlesClick;
}
}
private (GpuTextureSlot tex, int w, int h)? _dragGhost;
private (uint tex, int w, int h)? _dragGhost;
/// <summary>Snapshotted drag-ghost (tex,w,h), exposed for tests. See BeginDrag.</summary>
internal (GpuTextureSlot tex, int w, int h)? DragGhostForTest => _dragGhost;
internal (uint tex, int w, int h)? DragGhostForTest => _dragGhost;
private UiElement? _lastDragHoverTarget;
private int _pressX, _pressY;
private bool _dragCandidate;
@ -272,7 +272,7 @@ internal sealed class UiRoot : UiElement
return false;
}
// ── Per-frame pumping ────────────────────────────────────────────────
// ── Per-frame pumping ────────────────────────────────────────────────
public void Tick(double dt, long nowMs)
{
@ -303,7 +303,7 @@ internal sealed class UiRoot : UiElement
public void Draw(UiRenderContext ctx)
{
// Render children (panels) sorted by z-order — modal last so it
// Render children (panels) sorted by z-order modal last so it
// sits on top.
DrawSelfAndChildren(ctx);
// Second pass: open popups/menus draw ON TOP of the whole tree (so e.g. the
@ -324,12 +324,12 @@ internal sealed class UiRoot : UiElement
/// never intercepts hit-tests.</summary>
private void DrawDragGhost(UiRenderContext ctx)
{
if (_dragGhost is not { } g || !g.tex.IsAssigned) return;
if (_dragGhost is not { } g || g.tex == 0) return;
ctx.DrawSprite(g.tex, MouseX - g.w / 2f, MouseY - g.h / 2f, g.w, g.h,
0f, 0f, 1f, 1f, new Vector4(1f, 1f, 1f, GhostAlpha));
}
// ── Input entry points (called from GameWindow's Silk.NET handlers) ──
// ── Input entry points (called from GameWindow's Silk.NET handlers) ──
public void OnMouseMove(int x, int y)
{
@ -426,7 +426,7 @@ internal sealed class UiRoot : UiElement
if (target is null)
{
// Clicking the 3D world exits write mode (no submit) and returns control to
// the character — retail blurs the chat input on an outside click.
// the character retail blurs the chat input on an outside click.
if (btn == UiMouseButton.Left) SetKeyboardFocus(null);
WorldMouseFallThrough?.Invoke(btn, x, y, flags);
return;
@ -473,7 +473,7 @@ internal sealed class UiRoot : UiElement
}
else if (target.CapturesPointerDrag || target.HandlesClick)
{
// The pressed widget owns its pointer interaction — either an interior drag (e.g. text
// The pressed widget owns its pointer interaction either an interior drag (e.g. text
// selection, CapturesPointerDrag) or a click it must receive (e.g. a UiButton,
// HandlesClick). Either way do NOT move the ancestor window. The already-dispatched
// MouseDown + SetCapture(target) let the target handle it; on release OnMouseUp emits
@ -513,7 +513,7 @@ internal sealed class UiRoot : UiElement
// Deliver TARGET-LOCAL coords (consistent with MouseMove/MouseUp, which use
// target.ScreenPosition). HitTestTopDown's lx/ly are relative to the TOP-LEVEL
// child, so for a nested target (e.g. the chat view inset inside its window)
// they'd be offset by the child's position — which mis-anchored drag-select.
// they'd be offset by the child's position which mis-anchored drag-select.
var sp = target.ScreenPosition;
var e = new UiEvent(target.EventId, target, rawType,
Data0: (int)flags, Data1: (int)(x - sp.X), Data2: (int)(y - sp.Y));
@ -615,7 +615,7 @@ internal sealed class UiRoot : UiElement
return;
}
// No capture — give the world a chance.
// No capture give the world a chance.
WorldMouseFallThrough?.Invoke(btn, x, y, flags);
}
@ -687,7 +687,7 @@ internal sealed class UiRoot : UiElement
BubbleEvent(KeyboardFocus, in e);
}
// ── Focus + capture ─────────────────────────────────────────────────
// ── Focus + capture ─────────────────────────────────────────────────
public void SetKeyboardFocus(UiElement? e)
{
@ -726,12 +726,12 @@ internal sealed class UiRoot : UiElement
PointerCaptureChanged?.Invoke(previous, null);
}
// ── Window manager (named top-level windows: Show / Hide / Toggle) ───
// ── Window manager (named top-level windows: Show / Hide / Toggle) ───
// Registry state lives in RetailWindowManager; methods below are compatibility forwarders.
/// <summary>Register a top-level window under a name for Show/Hide/Toggle.
/// Does NOT add it to the tree — the caller mounts via AddChild and controls
/// Does NOT add it to the tree the caller mounts via AddChild and controls
/// initial Visible. Idempotent registration returns the existing typed handle;
/// replacement performs full lifecycle teardown of the prior registration.</summary>
public RetailWindowHandle RegisterWindow(
@ -788,7 +788,7 @@ internal sealed class UiRoot : UiElement
WindowResized?.Invoke(handle.Name, window);
}
// ── Drag-drop (retail event chain 0x15 → 0x21 → 0x1C → 0x3E) ────────
// ── Drag-drop (retail event chain 0x15 → 0x21 → 0x1C → 0x3E) ────────
private void BeginDrag(UiElement source)
{
@ -796,7 +796,7 @@ internal sealed class UiRoot : UiElement
if (payload is null) { _dragCandidate = false; return; }
DragSource = source;
DragPayload = payload;
_dragGhost = source.GetDragGhost(); // snapshot NOW — the DragBegin handler may empty the source cell
_dragGhost = source.GetDragGhost(); // snapshot NOW the DragBegin handler may empty the source cell
var e = new UiEvent(source.EventId, source, UiEventType.DragBegin, Payload: payload);
source.OnEvent(in e);
// Retail UIElement_ItemList::ItemList_BeginDrag @ 0x004E32D0 selects an
@ -843,7 +843,7 @@ internal sealed class UiRoot : UiElement
var (t, lx, ly) = HitTestTopDown(x, y);
if (t is not null)
{
// Dropped on a real element — deliver DropReleased; the hit cell's handler places.
// Dropped on a real element deliver DropReleased; the hit cell's handler places.
// A non-item target's OnEvent ignores it, so an off-bar drop leaves the lift's removal.
var e = new UiEvent(source!.EventId, t, UiEventType.DropReleased,
Data1: (int)lx, Data2: (int)ly, Payload: payload);
@ -859,7 +859,7 @@ internal sealed class UiRoot : UiElement
_lastDragHoverTarget = null;
}
// ── Hover / tooltip ─────────────────────────────────────────────────
// ── Hover / tooltip ─────────────────────────────────────────────────
private void UpdateHover(int x, int y)
{
@ -892,7 +892,7 @@ internal sealed class UiRoot : UiElement
}
}
// ── Helpers ─────────────────────────────────────────────────────────
// ── Helpers ─────────────────────────────────────────────────────────
public void FireEvent(int type, UiElement target, object? payload = null)
{