acdream/src/AcDream.App/Composition/HostInputCameraComposition.cs
Erik 8a7a0837e1 feat(render): Vulkan campaign V11 step 2 — delete the OpenGL backend
Vulkan is the sole, user-signed-off backend (V10 landed) and step 1
already removed ImGui/Studio/DevTools. This step deletes the GL
rendering backend itself: every Gpu/Gl/** implementation, the Wb
ManagedGL*/GLHelpers/GLSLShader/GLStateScope/RenderStateCache/
BindlessSupport family, Shader/ShaderProgramConstruction/SamplerCache,
RenderBootstrap, and RenderFrameGlStateController.

GameWindow.cs's Run()/CreateGraphics()/CreateBackbufferReader()/
OnLoad() collapse to their Vulkan-only arm; GameWindowGraphics loses
its OpenGlGameWindowGraphics subclass. RuntimeOptions.RenderBackend and
RenderBackendKind (incl. the Gl member of GpuBackendKind) are gone —
there is nothing left to select between. The five world-draw dual-arm
renderers (WbDrawDispatcher, EnvCellRenderer, TerrainModernRenderer,
ParticleRenderer, SkyRenderer) and the composition roots
(WorldRenderComposition, HostInputCameraComposition,
LivePresentationComposition, FrameRootComposition) collapse to their
RHI-only arm. GL-only diagnostic properties with a live external reader
(DynamicBufferCount and friends) simplify to a documented `=> 0`/no-op
rather than disappearing, since the reader is out of this commit's
scope.

A few GL-flavored mechanisms turned out to be backend-neutral once
isolated: GlConstructionCleanupLedger is renamed
ResourceConstructionCleanupLedger (exception-chain walking has nothing
to do with GL), and GlfwNativePlatformProbe moved out of the otherwise
GL-only GraphicalCapabilityRecord.cs into
GraphicalWindowBackendSelection.cs before the rest of that file was
deleted.

Test files with no surviving subject are deleted outright
(GraphicalCapabilityRequirementsTests, ShaderProgramConstructionTests,
PortalDepthShaderParityTests, TextureCacheBindlessTests,
TextRendererFailureSafetyTests, ClipFrameUploadTests, every
Gpu/Gl/*Tests, GlTextureOwnershipTests, RenderFrameGlStateControllerTests);
others get their dead GL-only members trimmed while their live
assertions stay (ClipFrameLayoutTests' MeshClipSsboBinding check now
reads GpuBindingModel.StorageClipRegions, the same binding index under
its new backend-neutral name; GpuResourceRetirementTransactionTests
drops its OpenGLGraphicsDevice-subclassing test double and the two GL
queue tests it existed for). EnvCellRendererTests' construction helper
now builds a real ObjectMeshManager via VulkanMeshPipelineDevice
instead of passing null through a null-forgiving operator, since the
RHI constructor never tolerated a null mesh manager and the old GL
constructor (which did) is gone.

Deferred to the next two steps, deliberately not touched here: the
Silk.NET.OpenGL/.Extensions.ARB package references, IMeshPipelineDevice.Gl
(WbMeshAdapter's GL? threading stays in place), Chorizite.Core's stale
csproj comment (the package itself is still load-bearing —
TextureFormat and friends are used well beyond the deleted
ManagedGLUniformBuffer), and the CI/gate scripts.

Build: `dotnet build AcDream.slnx -c Release` — 0 warnings, 0 errors.
Tests: full-solution `dotnet test` green across every project
(App.Tests 3937/3940 + 3 skips, Core.Tests 3296/3298 + 2 skips, all
others 100%); the 2 App.Tests names that flake under full-suite
parallel execution (#250-family, documented pre-existing) pass in
isolation.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-29 02:19:53 +02:00

361 lines
15 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;
namespace AcDream.App.Composition;
internal interface IGameWindowHostInputCameraPublication
{
void PublishGpuFrameFlights(GpuFrameFlightController? value);
void PublishGpuDevice(IGpuDevice value);
void PublishGpuFrameLifetime(GpuDeviceFrameLifetime 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);
}
/// <param name="GpuFrameFlights">
/// The GL fence/slot ring, or null on a backend whose RHI device owns its own
/// flight control. Campaign V slice V6h: <see cref="Retirement"/> and
/// <see cref="FrameSlots"/> are the backend-neutral views every consumer should
/// take; this field exists because GL's teardown ledger still names the
/// controller itself.
/// </param>
internal sealed record HostInputCameraResult(
GpuFrameFlightController? GpuFrameFlights,
IGpuResourceRetirementQueue Retirement,
IRenderFrameSlotSource FrameSlots,
IGpuDevice GpuDevice,
GpuDeviceFrameLifetime GpuFrameLifetime,
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);
/// <summary>
/// The construction seam every backend differs at. Campaign V slice V6h widened
/// the first four members from <c>GL</c> to <see cref="GameWindowGraphics"/> —
/// they are the whole of what a backend has to supply before the composition
/// pipeline is identical again.
/// </summary>
internal interface IHostInputCameraCompositionFactory
{
IFramebufferViewportTarget CreateViewportTarget(GameWindowGraphics graphics);
/// <summary>The GL fence ring, or null when the backend's RHI device owns its flights.</summary>
GpuFrameFlightController? CreateGpuFrameFlights(GameWindowGraphics graphics);
IGpuDevice CreateGpuDevice(
GameWindowGraphics graphics,
GpuFrameFlightController? frameFlights);
/// <summary>Where per-frame resource release is queued. GL's ring, or the RHI device's own.</summary>
IGpuResourceRetirementQueue CreateRetirement(
GameWindowGraphics graphics,
GpuFrameFlightController? frameFlights,
IGpuDevice device);
/// <summary>The ring slot renderers index their per-flight buffers by.</summary>
IRenderFrameSlotSource CreateFrameSlots(
GameWindowGraphics graphics,
GpuFrameFlightController? frameFlights,
IGpuDevice device);
/// <summary>The raw-GL state tripwire, or null on a backend that has no GL state.</summary>
WorldRenderDiagnostics? CreateWorldRenderDiagnostics(
GameWindowGraphics graphics,
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 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<GameWindowGraphics, IInputContext>,
HostInputCameraResult>
{
private readonly HostInputCameraDependencies _dependencies;
private readonly IGameWindowHostInputCameraPublication _publication;
private readonly IHostInputCameraCompositionFactory? _injectedFactory;
private readonly Action<HostInputCameraCompositionPoint>? _faultInjection;
private IHostInputCameraCompositionFactory _factory =
new VulkanHostInputCameraCompositionFactory();
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));
_injectedFactory = factory;
_faultInjection = faultInjection;
}
/// <summary>
/// The Vulkan factory is the only one left since the raw-GL arm was
/// deleted at Campaign V slice V11; an injected factory (composition
/// tests) still wins.
/// </summary>
private static IHostInputCameraCompositionFactory DefaultFactoryFor(
GameWindowGraphics graphics) =>
new VulkanHostInputCameraCompositionFactory();
public HostInputCameraResult Compose(
GameWindowPlatformResult<GameWindowGraphics, 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<GameWindowGraphics, IInputContext> platform,
CompositionAcquisitionScope scope)
{
GameWindowGraphics graphics = platform.Graphics;
IInputContext input = platform.Input;
_factory = _injectedFactory ?? DefaultFactoryFor(graphics);
_dependencies.FramebufferResize.BindViewport(
_factory.CreateViewportTarget(graphics));
Fault(HostInputCameraCompositionPoint.ViewportBound);
// Null on a backend whose RHI device owns its own frame flights
// (Vulkan's timeline semaphore). The publication still runs so the
// teardown ledger records the same slot either way.
GpuFrameFlightController? gpuFrames = scope.AcquireOptional(
"GPU frame flights",
() => _factory.CreateGpuFrameFlights(graphics),
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(graphics, gpuFrames),
static value => value.Dispose()).Publish(
_publication.PublishGpuDevice);
Fault(HostInputCameraCompositionPoint.GpuDevicePublished);
IGpuResourceRetirementQueue retirement =
_factory.CreateRetirement(graphics, gpuFrames, gpuDevice);
IRenderFrameSlotSource frameSlots =
_factory.CreateFrameSlots(graphics, gpuFrames, gpuDevice);
// Campaign V slice V4a: drives IGpuDevice.BeginFrame()/IGpuFrame.End()
// once per rendered frame, additively over the existing
// GpuFrameFlightController-driven fence/slot bracket (see the class
// comment) — RenderFrameOrchestrator's IRenderFrameLifetime is wired
// to THIS wrapper instead of gpuFrames directly at FrameRootComposition,
// and the IGpuFrame it exposes is what TextRenderer/DebugLineRenderer
// reach through ICurrentGpuFrameSource. Owns no disposable resource of
// its own — gpuDevice's own scope.Acquire entry above disposes it.
var gpuFrameLifetime = new GpuDeviceFrameLifetime(gpuDevice);
_publication.PublishGpuFrameLifetime(gpuFrameLifetime);
WorldRenderDiagnostics? diagnostics =
_factory.CreateWorldRenderDiagnostics(
graphics,
_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,
retirement,
frameSlots,
gpuDevice,
gpuFrameLifetime,
diagnostics,
keyboard,
mouse,
cursor,
dispatcher,
camera,
pointer);
}
private void Fault(HostInputCameraCompositionPoint point) =>
_faultInjection?.Invoke(point);
}