feat(render): Campaign V slice V1 - OpenGL RHI backend (dark)

Implements GlGpuDevice and the rest of AcDream.App.Rendering.Gpu.Gl,
filling the V0-pinned IGpuDevice contract on OpenGL 4.3. This is the
first of the port slices described in
docs/plans/2026-07-27-vulkan-campaign.md: every later renderer port
(V2 onward) needs a real, driver-proven GL implementation of the RHI
to port onto, and the GL backend is deliberately built to be
behaviour-preserving rather than optimal, because that is what turns
each subsequent slice's pixel gate into a strict identity check
instead of a moving target. The Vulkan backend (V5+) is where the
actual efficiency gains land.

GlGpuDevice is a fresh root, not derived from Chorizite's
BaseGraphicsDevice/OpenGLGraphicsDevice - shedding that inheritance is
one of the things this campaign explicitly does. It owns its own
BindlessSupport instance rather than sharing the legacy WB render
path's, which is what lets it be constructed the moment a GL context
and a GpuFrameFlightController exist, with no dependency on when
WorldRenderCompositionPhase happens to detect bindless support later
in startup. The ring buffer keeps a managed staging array plus a real
GL buffer per flight slot and flushes with one BufferSubData
immediately before each Draw/DrawIndexed/MultiDrawIndexedIndirect
(never at bind time, since a renderer may still write after binding);
V1 throws on an over-capacity ring request rather than growing it,
since nothing consumes the device yet and a silent grow would hide a
future renderer's real working set. The texture table is a bump/free-
list allocator over a managed uvec2 handle array, gated through the
frame-flight retirement queue so a released slot cannot be reused
while a submitted frame might still read it. Push constants are
applied by uniform name on the currently-bound program, cached per
program, and explicitly re-applied whenever BindPipeline switches
programs - GL uniforms are per-program state, so the "survives
pipeline changes within a pass" guarantee the interface documents (a
freebie on Vulkan's shared pipeline layout) has to be emulated here.

BindlessSupport gained one additive method,
GetResidentHandle(texture, sampler), calling the same
ArbBindlessTexture.GetTextureSamplerHandle entry point
ManagedGLTextureArray already uses through a different path. The
existing GetResidentHandle(texture) cannot express
IGpuDevice.RegisterTexture's documented pair semantics ("the same
texture registered with two samplers occupies two slots"), so this
was the minimal change needed rather than a workaround.

The pure bookkeeping - ring watermark/alignment arithmetic, the
texture-slot allocator, render-state diffing, the push-constant field-
to-uniform-name table, and GL format mapping - lives in small GL-free
classes so it is unit-testable without a live context, following the
same seam pattern GpuFrameFlightController already uses for its fence
API. GlGpuTimerPool follows suit with an injectable timer-query API.

The device is constructed in HostInputCameraCompositionPhase
immediately after the frame-flight controller (the same phase that
already builds GpuFrameFlightController), rather than in
WorldRenderCompositionPhase as first considered: GlGpuDevice's self-
contained bindless detection means it has no ordering dependency on
the legacy WB path's BindlessSupport, so it can be proven against the
real driver as early as possible while keeping the composition change
to one phase. Composition, publication, and shutdown wiring follow
the existing acquire/publish/fault-injection pattern exactly, and GPU
device disposal is scheduled through the frame-flight retirement queue
before that queue itself is torn down. Nothing consumes the device
yet - that starts at V4a - so this slice's pixel gate is trivially a
tripwire.

App tests: 3834 passed / 3 skipped (V0 baseline 3785 + 49 new: ring,
texture-slot, render-state, push-constant, format-mapping, enum-
mapping, and timer-pool tests, plus one new fault-injection point in
the existing composition theory).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-07-27 15:11:04 +02:00
parent 90f7c6f2f4
commit 4f94ad7ddd
30 changed files with 2843 additions and 2 deletions

View file

@ -1,5 +1,6 @@
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;
@ -10,6 +11,7 @@ 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);
@ -20,6 +22,7 @@ internal interface IGameWindowHostInputCameraPublication
internal sealed record HostInputCameraResult(
GpuFrameFlightController GpuFrameFlights,
IGpuDevice GpuDevice,
WorldRenderDiagnostics WorldRenderDiagnostics,
SilkKeyboardSource? KeyboardSource,
SilkMouseSource? MouseSource,
@ -45,6 +48,7 @@ internal interface IHostInputCameraCompositionFactory
{
IFramebufferViewportTarget CreateViewportTarget(GL gl);
GpuFrameFlightController CreateGpuFrameFlights(GL gl);
IGpuDevice CreateGpuDevice(GL gl, GpuFrameFlightController frameFlights);
WorldRenderDiagnostics CreateWorldRenderDiagnostics(
GL gl,
IRenderFrameDiagnosticLog log);
@ -82,6 +86,12 @@ internal sealed class RetailHostInputCameraCompositionFactory
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) =>
@ -139,6 +149,7 @@ internal enum HostInputCameraCompositionPoint
{
ViewportBound,
GpuFrameFlightsPublished,
GpuDevicePublished,
KeyboardPublished,
KeyboardAttached,
MousePublished,
@ -220,6 +231,20 @@ internal sealed class HostInputCameraCompositionPhase :
_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,
@ -319,6 +344,7 @@ internal sealed class HostInputCameraCompositionPhase :
return new HostInputCameraResult(
gpuFrames,
gpuDevice,
diagnostics,
keyboard,
mouse,