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>
359 lines
13 KiB
C#
359 lines
13 KiB
C#
using AcDream.App.Input;
|
|
using AcDream.App.Rendering;
|
|
using AcDream.App.Rendering.Gpu;
|
|
using AcDream.UI.Abstractions.Input;
|
|
using Silk.NET.Input;
|
|
using Silk.NET.Maths;
|
|
using Silk.NET.OpenGL;
|
|
|
|
namespace AcDream.App.Composition;
|
|
|
|
internal interface IGameWindowHostInputCameraPublication
|
|
{
|
|
void PublishGpuFrameFlights(GpuFrameFlightController value);
|
|
void PublishGpuDevice(IGpuDevice value);
|
|
void PublishKeyboardSource(SilkKeyboardSource value);
|
|
void PublishMouseSource(SilkMouseSource value);
|
|
void PublishMouseLookCursor(IMouseLookCursor value);
|
|
void PublishInputDispatcher(InputDispatcher value);
|
|
void PublishCameraController(CameraController value);
|
|
void PublishCameraPointerInput(CameraPointerInputController value);
|
|
}
|
|
|
|
internal sealed record HostInputCameraResult(
|
|
GpuFrameFlightController GpuFrameFlights,
|
|
IGpuDevice GpuDevice,
|
|
WorldRenderDiagnostics WorldRenderDiagnostics,
|
|
SilkKeyboardSource? KeyboardSource,
|
|
SilkMouseSource? MouseSource,
|
|
IMouseLookCursor? MouseLookCursor,
|
|
InputDispatcher? InputDispatcher,
|
|
CameraController CameraController,
|
|
CameraPointerInputController? CameraPointerInput);
|
|
|
|
internal sealed record HostInputCameraDependencies(
|
|
FramebufferResizeController FramebufferResize,
|
|
Vector2D<int> InitialFramebufferSize,
|
|
HostQuiescenceGate HostQuiescence,
|
|
IInputCaptureSource InputCapture,
|
|
KeyBindings KeyBindings,
|
|
DispatcherMovementInputSource MovementInput,
|
|
DispatcherCameraInputSource CameraInput,
|
|
LocalPlayerModeState LocalPlayerMode,
|
|
ChaseCameraInputState ChaseCameraInput,
|
|
PointerPositionState PointerPosition,
|
|
IRenderFrameDiagnosticLog RenderDiagnosticLog);
|
|
|
|
internal interface IHostInputCameraCompositionFactory
|
|
{
|
|
IFramebufferViewportTarget CreateViewportTarget(GL gl);
|
|
GpuFrameFlightController CreateGpuFrameFlights(GL gl);
|
|
IGpuDevice CreateGpuDevice(GL gl, GpuFrameFlightController frameFlights);
|
|
WorldRenderDiagnostics CreateWorldRenderDiagnostics(
|
|
GL gl,
|
|
IRenderFrameDiagnosticLog log);
|
|
SilkKeyboardSource CreateKeyboardSource(
|
|
IKeyboard keyboard,
|
|
HostQuiescenceGate quiescence);
|
|
SilkMouseSource CreateMouseSource(
|
|
IMouse mouse,
|
|
IInputCaptureSource capture,
|
|
IKeyboardSource? keyboard,
|
|
HostQuiescenceGate quiescence);
|
|
IMouseLookCursor CreateMouseLookCursor(IMouse mouse);
|
|
InputDispatcher CreateInputDispatcher(
|
|
IKeyboardSource keyboard,
|
|
IMouseSource mouse,
|
|
KeyBindings bindings);
|
|
CameraController CreateCameraController();
|
|
IFramebufferCameraTarget CreateCameraTarget(CameraController camera);
|
|
CameraPointerInputController CreateCameraPointerInput(
|
|
IReadOnlyList<IMouse> mice,
|
|
HostQuiescenceGate quiescence,
|
|
IInputCaptureSource capture,
|
|
LocalPlayerModeState playerMode,
|
|
CameraController camera,
|
|
ChaseCameraInputState chase,
|
|
IMouseSource mouse,
|
|
PointerPositionState pointer);
|
|
}
|
|
|
|
internal sealed class RetailHostInputCameraCompositionFactory
|
|
: IHostInputCameraCompositionFactory
|
|
{
|
|
public IFramebufferViewportTarget CreateViewportTarget(GL gl) =>
|
|
new SilkFramebufferViewportTarget(gl);
|
|
|
|
public GpuFrameFlightController CreateGpuFrameFlights(GL gl) => new(gl);
|
|
|
|
public IGpuDevice CreateGpuDevice(GL gl, GpuFrameFlightController frameFlights) =>
|
|
new AcDream.App.Rendering.Gpu.Gl.GlGpuDevice(
|
|
gl,
|
|
frameFlights,
|
|
Path.Combine(AppContext.BaseDirectory, "Rendering", "Shaders"));
|
|
|
|
public WorldRenderDiagnostics CreateWorldRenderDiagnostics(
|
|
GL gl,
|
|
IRenderFrameDiagnosticLog log) =>
|
|
new(new SilkRenderGlStateReader(gl), log);
|
|
|
|
public SilkKeyboardSource CreateKeyboardSource(
|
|
IKeyboard keyboard,
|
|
HostQuiescenceGate quiescence) =>
|
|
SilkKeyboardSource.CreateDetached(keyboard, quiescence);
|
|
|
|
public SilkMouseSource CreateMouseSource(
|
|
IMouse mouse,
|
|
IInputCaptureSource capture,
|
|
IKeyboardSource? keyboard,
|
|
HostQuiescenceGate quiescence) =>
|
|
SilkMouseSource.CreateDetached(mouse, capture, keyboard, quiescence);
|
|
|
|
public IMouseLookCursor CreateMouseLookCursor(IMouse mouse) =>
|
|
new SilkMouseLookCursor(mouse);
|
|
|
|
public InputDispatcher CreateInputDispatcher(
|
|
IKeyboardSource keyboard,
|
|
IMouseSource mouse,
|
|
KeyBindings bindings) =>
|
|
InputDispatcher.CreateDetached(keyboard, mouse, bindings);
|
|
|
|
public CameraController CreateCameraController() =>
|
|
new(new OrbitCamera(), new FlyCamera());
|
|
|
|
public IFramebufferCameraTarget CreateCameraTarget(CameraController camera) =>
|
|
new CameraFramebufferTarget(camera);
|
|
|
|
public CameraPointerInputController CreateCameraPointerInput(
|
|
IReadOnlyList<IMouse> mice,
|
|
HostQuiescenceGate quiescence,
|
|
IInputCaptureSource capture,
|
|
LocalPlayerModeState playerMode,
|
|
CameraController camera,
|
|
ChaseCameraInputState chase,
|
|
IMouseSource mouse,
|
|
PointerPositionState pointer) =>
|
|
CameraPointerInputController.Create(
|
|
mice,
|
|
quiescence,
|
|
capture,
|
|
playerMode,
|
|
camera,
|
|
chase,
|
|
mouse,
|
|
pointer,
|
|
new EnvironmentInputMonotonicClock());
|
|
}
|
|
|
|
internal enum HostInputCameraCompositionPoint
|
|
{
|
|
ViewportBound,
|
|
GpuFrameFlightsPublished,
|
|
GpuDevicePublished,
|
|
KeyboardPublished,
|
|
KeyboardAttached,
|
|
MousePublished,
|
|
MouseAttached,
|
|
MouseLookCursorPublished,
|
|
DispatcherPublished,
|
|
DispatcherAttached,
|
|
MovementInputBound,
|
|
CameraInputBound,
|
|
CameraPublished,
|
|
CameraTargetBound,
|
|
InitialFramebufferApplied,
|
|
CameraPointerPublished,
|
|
CameraPointerAttached,
|
|
}
|
|
|
|
/// <summary>
|
|
/// Production Phase 1. Callback-bearing owners publish to the lifetime shell
|
|
/// before attachment, so a side-effecting event accessor cannot leave an
|
|
/// unreachable subscription after partial startup failure.
|
|
/// </summary>
|
|
internal sealed class HostInputCameraCompositionPhase :
|
|
IHostInputCameraCompositionPhase<
|
|
GameWindowPlatformResult<GL, IInputContext>,
|
|
HostInputCameraResult>
|
|
{
|
|
private readonly HostInputCameraDependencies _dependencies;
|
|
private readonly IGameWindowHostInputCameraPublication _publication;
|
|
private readonly IHostInputCameraCompositionFactory _factory;
|
|
private readonly Action<HostInputCameraCompositionPoint>? _faultInjection;
|
|
|
|
public HostInputCameraCompositionPhase(
|
|
HostInputCameraDependencies dependencies,
|
|
IGameWindowHostInputCameraPublication publication,
|
|
IHostInputCameraCompositionFactory? factory = null,
|
|
Action<HostInputCameraCompositionPoint>? faultInjection = null)
|
|
{
|
|
_dependencies = dependencies
|
|
?? throw new ArgumentNullException(nameof(dependencies));
|
|
_publication = publication
|
|
?? throw new ArgumentNullException(nameof(publication));
|
|
_factory = factory ?? new RetailHostInputCameraCompositionFactory();
|
|
_faultInjection = faultInjection;
|
|
}
|
|
|
|
public HostInputCameraResult Compose(
|
|
GameWindowPlatformResult<GL, IInputContext> platform)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(platform);
|
|
var scope = new CompositionAcquisitionScope();
|
|
try
|
|
{
|
|
HostInputCameraResult result = ComposeCore(platform, scope);
|
|
scope.Complete();
|
|
return result;
|
|
}
|
|
catch (Exception failure)
|
|
{
|
|
scope.RollbackAndThrow(failure);
|
|
throw new System.Diagnostics.UnreachableException();
|
|
}
|
|
}
|
|
|
|
private HostInputCameraResult ComposeCore(
|
|
GameWindowPlatformResult<GL, IInputContext> platform,
|
|
CompositionAcquisitionScope scope)
|
|
{
|
|
GL gl = platform.Graphics;
|
|
IInputContext input = platform.Input;
|
|
|
|
_dependencies.FramebufferResize.BindViewport(
|
|
_factory.CreateViewportTarget(gl));
|
|
Fault(HostInputCameraCompositionPoint.ViewportBound);
|
|
|
|
GpuFrameFlightController gpuFrames = scope.Acquire(
|
|
"GPU frame flights",
|
|
() => _factory.CreateGpuFrameFlights(gl),
|
|
static value => value.Dispose()).Publish(
|
|
_publication.PublishGpuFrameFlights);
|
|
Fault(HostInputCameraCompositionPoint.GpuFrameFlightsPublished);
|
|
|
|
// Constructed the moment a GL context and the frame flight controller
|
|
// exist — it owns its own BindlessSupport detection (see
|
|
// GlGpuDevice's class comment), so unlike the legacy WB render path it
|
|
// has no dependency on WorldRenderCompositionPhase running first.
|
|
// Nothing consumes this device yet (Campaign V slice V1); it is
|
|
// proven against the real driver here and torn down with the render
|
|
// stack so later slices (starting at V4a) have somewhere to plug in.
|
|
IGpuDevice gpuDevice = scope.Acquire(
|
|
"GPU device (RHI)",
|
|
() => _factory.CreateGpuDevice(gl, gpuFrames),
|
|
static value => value.Dispose()).Publish(
|
|
_publication.PublishGpuDevice);
|
|
Fault(HostInputCameraCompositionPoint.GpuDevicePublished);
|
|
|
|
WorldRenderDiagnostics diagnostics =
|
|
_factory.CreateWorldRenderDiagnostics(
|
|
gl,
|
|
_dependencies.RenderDiagnosticLog);
|
|
|
|
IKeyboard? firstKeyboard = input.Keyboards.FirstOrDefault();
|
|
IMouse? firstMouse = input.Mice.FirstOrDefault();
|
|
SilkKeyboardSource? keyboard = null;
|
|
SilkMouseSource? mouse = null;
|
|
IMouseLookCursor? cursor = null;
|
|
InputDispatcher? dispatcher = null;
|
|
CameraPointerInputController? pointer = null;
|
|
|
|
if (firstKeyboard is not null)
|
|
{
|
|
keyboard = scope.Acquire(
|
|
"keyboard source",
|
|
() => _factory.CreateKeyboardSource(
|
|
firstKeyboard,
|
|
_dependencies.HostQuiescence),
|
|
static value => value.Dispose()).Publish(
|
|
_publication.PublishKeyboardSource);
|
|
Fault(HostInputCameraCompositionPoint.KeyboardPublished);
|
|
keyboard.Attach();
|
|
Fault(HostInputCameraCompositionPoint.KeyboardAttached);
|
|
}
|
|
|
|
if (firstMouse is not null)
|
|
{
|
|
mouse = scope.Acquire(
|
|
"mouse source",
|
|
() => _factory.CreateMouseSource(
|
|
firstMouse,
|
|
_dependencies.InputCapture,
|
|
keyboard,
|
|
_dependencies.HostQuiescence),
|
|
static value => value.Dispose()).Publish(
|
|
_publication.PublishMouseSource);
|
|
Fault(HostInputCameraCompositionPoint.MousePublished);
|
|
mouse.Attach();
|
|
Fault(HostInputCameraCompositionPoint.MouseAttached);
|
|
|
|
cursor = _factory.CreateMouseLookCursor(firstMouse);
|
|
_publication.PublishMouseLookCursor(cursor);
|
|
Fault(HostInputCameraCompositionPoint.MouseLookCursorPublished);
|
|
}
|
|
|
|
if (keyboard is not null && mouse is not null)
|
|
{
|
|
dispatcher = scope.Acquire(
|
|
"input dispatcher",
|
|
() => _factory.CreateInputDispatcher(
|
|
keyboard,
|
|
mouse,
|
|
_dependencies.KeyBindings),
|
|
static value => value.Dispose()).Publish(
|
|
_publication.PublishInputDispatcher);
|
|
Fault(HostInputCameraCompositionPoint.DispatcherPublished);
|
|
dispatcher.Attach();
|
|
Fault(HostInputCameraCompositionPoint.DispatcherAttached);
|
|
|
|
_dependencies.MovementInput.Bind(dispatcher);
|
|
Fault(HostInputCameraCompositionPoint.MovementInputBound);
|
|
_dependencies.CameraInput.Bind(dispatcher);
|
|
Fault(HostInputCameraCompositionPoint.CameraInputBound);
|
|
}
|
|
|
|
CameraController camera = _factory.CreateCameraController();
|
|
_publication.PublishCameraController(camera);
|
|
Fault(HostInputCameraCompositionPoint.CameraPublished);
|
|
_dependencies.FramebufferResize.BindCamera(
|
|
_factory.CreateCameraTarget(camera));
|
|
Fault(HostInputCameraCompositionPoint.CameraTargetBound);
|
|
_dependencies.FramebufferResize.Resize(
|
|
_dependencies.InitialFramebufferSize);
|
|
Fault(HostInputCameraCompositionPoint.InitialFramebufferApplied);
|
|
|
|
if (mouse is not null && firstMouse is not null)
|
|
{
|
|
pointer = scope.Acquire(
|
|
"camera pointer input",
|
|
() => _factory.CreateCameraPointerInput(
|
|
input.Mice,
|
|
_dependencies.HostQuiescence,
|
|
_dependencies.InputCapture,
|
|
_dependencies.LocalPlayerMode,
|
|
camera,
|
|
_dependencies.ChaseCameraInput,
|
|
mouse,
|
|
_dependencies.PointerPosition),
|
|
static value => value.Dispose()).Publish(
|
|
_publication.PublishCameraPointerInput);
|
|
Fault(HostInputCameraCompositionPoint.CameraPointerPublished);
|
|
pointer.AttachRaw();
|
|
Fault(HostInputCameraCompositionPoint.CameraPointerAttached);
|
|
}
|
|
|
|
return new HostInputCameraResult(
|
|
gpuFrames,
|
|
gpuDevice,
|
|
diagnostics,
|
|
keyboard,
|
|
mouse,
|
|
cursor,
|
|
dispatcher,
|
|
camera,
|
|
pointer);
|
|
}
|
|
|
|
private void Fault(HostInputCameraCompositionPoint point) =>
|
|
_faultInjection?.Invoke(point);
|
|
}
|