feat(render): Campaign V slice V4a - port TextRenderer/BitmapFont/DebugLineRenderer/TextureCache onto IGpuDevice
TextRenderer, BitmapFont, DebugLineRenderer, and TextureCache's UI-texture
upload path (GetOrUploadRenderSurface/UploadRgba8) now issue every draw and
resource creation through the pinned IGpuDevice/IGpuFrame/IGpuPassEncoder
RHI contract instead of raw GL. This is the RHI's first real production
consumer - V0-V3 only established the contract, GL backend skeleton, and a
shader-dialect migration with no live GL exercise. TextRenderer owns one
IGpuPipeline (ui_text shader, straight-alpha blend, depth disabled) and
allocates a per-bucket ring each Flush; BitmapFont's atlas texture is
created and uploaded via device.CreateTexture/.Upload; DebugLineRenderer
mirrors the same one-pipeline-per-Flush shape for its line-list draws.
World-path TextureCache methods (GetOrUpload, the raw-GL layer-array
upload) are untouched - still legacy GL, still out of scope.
Frame lifecycle: GpuDeviceFrameLifetime (RenderFrameOrchestrator.cs) wraps
IGpuDevice.BeginFrame()/IGpuFrame.End() inside the existing
IRenderFrameLifetime bracket HostInputCameraCompositionPhase already opens
per callback, additively - no frame-graph restructuring. Ported renderers
reach the frame via ICurrentGpuFrameSource, a plain interface (not a
delegate field) so WorldSceneDiagnosticsController keeps passing its
existing "no stored window/delegate" architectural-conformance test.
Two real bugs surfaced by actually exercising the RHI against a live GL
context (nothing here was previously reachable before this slice):
- GlGpuDevice.BeginFrame() now resets the render-state cache every frame.
The cache assumes it is the sole writer of GL program/blend/depth/cull
state, which was true while it had zero real consumers, but every
still-legacy renderer (WbDrawDispatcher, terrain, particles, EnvCells)
mutates that same GL state directly and never informs the cache. Once a
legacy renderer ran between two RHI binds, the cache's belief about the
current GL program went stale, so a later BindPipeline(text shader)
skipped re-issuing glUseProgram and the following push-constant upload
threw GL_INVALID_OPERATION against whatever program was actually bound.
Reset() at the frame boundary is the same defensive move BeginPass
already makes after a forced clear (see its comment); it costs one
redundant state application on the frame's first bind.
- GL_MULTISAMPLE has no representation in the pinned contract. Added a
GL-backend-internal Multisample field to GlRenderStateSnapshot/Changes,
computed from GpuPipelineDescription.SampleCount at BindPipeline time -
mirrors how Vulkan bakes MSAA into the pipeline instead of a separate
toggle.
Collateral, scoped to keep the port real rather than a stub:
- GpuTextureSlot (Unassigned = uint.MaxValue, NOT 0) now flows through
every consumer of TextureCache.GetOrUploadRenderSurface/UploadRgba8 and
TextRenderer.DrawSprite - the entire retained UI layer, since a pervasive
Func<uint,(uint,int,int)> sprite-resolve delegate threads through nearly
every UI element/controller. Every prior `== 0` / `!= 0` "no texture"
check became `.IsAssigned` / `!.IsAssigned`; slot 0 is a real assigned
slot (the device's default white texture), so the old sentinel would
have produced live visual regressions if left in place.
- GpuTextureSlot/IGpuDevice/IGpuFrame are internal, so ~270 previously
public AcDream.App types that touched them (directly or transitively)
are now internal too - safe, since AcDream.App is an exe with no
external project references; only the two test projects consume it, via
InternalsVisibleTo. A handful of unrelated types the sweep caught
(ElementInfo/ImportedLayout's property-bag hierarchy, several enums used
as public [Theory] parameters, CursorFeedbackSnapshot's DragAcceptState)
were reverted back to public where making them internal would have
either cascaded into unrelated files or broken xUnit's public-member
discovery.
- ExternalViewportTextureBridge (new) registers the still-raw-GL FBO
color textures PrivateEntityViewportRenderer/PaperdollViewportRenderer
produce (V4g's scope) into the device's texture table for
UiViewport.TextureHandle, via a temporary
GlGpuDevice.RegisterExternalColorTexture escape hatch (internal, not
part of IGpuDevice) deleted when V4g ports those viewports.
- TextRenderGlStateScope.cs and its test deleted: the pipeline description
now bakes what it used to restore by hand.
- ResourceCleanupGroupTests/GlTextureOwnershipTests: the two source-text
conformance tests keyed to TextRenderer's old multi-resource
construction shape (Shader + per-flight FrameBufferSet array + white
texture + tracked VAO/VBO, all via ResourceCleanupGroup) no longer apply
- that shape is gone, replaced by one IGpuPipeline created through
IGpuDevice. The construction-order test is deleted; the checked-commit
texture-creation check now targets GlGpuTexture (which already used
the same GlResourceCommand.CreateName primitive before this slice).
Gates:
- dotnet build -c Release: 0 warnings, 0 errors (AcDream.App has
TreatWarningsAsErrors).
- dotnet test tests/AcDream.App.Tests -c Release: 3,840 passed / 3
skipped (was 3,843/3 entering this slice - net 3 fewer tests:
TextRendererFailureSafetyTests.cs deleted (2, tested the now-deleted
TextRenderGlStateScope) plus the one retired ResourceCleanupGroupTests
method). Full solution: 8,908 passed / 5 skipped across all nine test
projects.
- Offline pixel gate (tools/run-offline-pixel-gate.ps1, parent ec414d60
vs this commit): differing fraction 0.318% (1,791/563,200 compared
pixels), above the 0.001 threshold. Investigated pixel-by-pixel rather
than waved through: a diff heatmap plus 4x crops at the differing
clusters show zero differences anywhere in the retained UI, terrain,
scenery, or static meshes - every differing pixel sits on continuously-
animated ambient content (flying-insect sprites over the swamp, foliage
sparkle/dew glints) whose exact phase depends on elapsed wall-clock
time, the same category the gate's own sky-masking rationale already
documents and the campaign doc's coverage table explicitly excludes
("Not covered - particles"). Confirming evidence: two same-commit
captures at HEAD compare clean against each other (0.0025%), and two
same-commit captures at the parent compare clean against each other
(0.0044%) - only base-vs-head is consistently elevated, which is what
frame-pacing drift from genuinely new per-frame RHI work (BeginFrame,
ring resets, the render-state reset above) would produce against a
fixed wall-clock capture deadline, not a rendering defect. Recommend a
quick user visual check of this capture pair alongside the automated
result, matching how V2c's particle work was already handled in this
campaign (flagged for user visual confirmation rather than blocked on
an automated gate that cannot cover animated content).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
ec414d60cd
commit
ceec3bc440
334 changed files with 3660 additions and 3840 deletions
|
|
@ -1,20 +1,20 @@
|
|||
// ClipFrame.cs
|
||||
// ClipFrame.cs
|
||||
//
|
||||
// Phase U.3: the GPU-side container + uploader for the SHARED per-frame clip
|
||||
// data consumed by mesh_modern.vert (SSBO binding=2) and terrain_modern.vert
|
||||
// (UBO binding=2). This is the "shared" half of the U.3 clip mechanism; the
|
||||
// per-instance slot index buffer (SSBO binding=3) is PER-RENDERER and owned by
|
||||
// each renderer (WbDrawDispatcher / EnvCellRenderer), parallel to its instance
|
||||
// buffer — it is NOT here.
|
||||
// buffer — it is NOT here.
|
||||
//
|
||||
// === The contract (both shader sides obey) ===================================
|
||||
// binding=2 mesh SSBO holds an array of CellClip, one per "slot":
|
||||
// struct CellClip { uint count; uint _p0; uint _p1; uint _p2; vec4 planes[8]; };
|
||||
// std430 layout: count at byte 0, three pad uints at 4/8/12, planes[8] at 16
|
||||
// (vec4 stride 16) → 144 bytes per slot. Slot 0 is RESERVED = no-clip (count 0).
|
||||
// (vec4 stride 16) → 144 bytes per slot. Slot 0 is RESERVED = no-clip (count 0).
|
||||
// binding=2 terrain UBO holds the single OutsideView region:
|
||||
// layout(std140) { int uTerrainClipCount; vec4 uTerrainClipPlanes[8]; };
|
||||
// std140 layout: count at byte 0 (padded to 16), planes[8] at 16 → 144 bytes.
|
||||
// std140 layout: count at byte 0 (padded to 16), planes[8] at 16 → 144 bytes.
|
||||
//
|
||||
// In U.3 a ClipFrame is built via NoClip(): one slot (slot 0, count 0) and a
|
||||
// terrain count of 0. Everything renders exactly as before. U.4 populates real
|
||||
|
|
@ -40,16 +40,16 @@ namespace AcDream.App.Rendering;
|
|||
/// std430 / std140 byte layout. Per-instance slot buffers (binding=3) are owned by
|
||||
/// each renderer, not here.
|
||||
/// </summary>
|
||||
public sealed class ClipFrame : IDisposable
|
||||
internal sealed class ClipFrame : IDisposable
|
||||
{
|
||||
// ---- Layout constants (mirror mesh_modern.vert + terrain_modern.vert) ----
|
||||
|
||||
/// <summary>Max planes per clip region — matches the shader's <c>planes[8]</c>
|
||||
/// <summary>Max planes per clip region — matches the shader's <c>planes[8]</c>
|
||||
/// and GL's guaranteed <c>GL_MAX_CLIP_DISTANCES >= 8</c>.</summary>
|
||||
public const int MaxPlanes = 8;
|
||||
|
||||
/// <summary>std430 stride of one <c>CellClip</c>: 16 (count + 3 pad uints) +
|
||||
/// 8 × 16 (vec4 planes) = 144 bytes.</summary>
|
||||
/// 8 × 16 (vec4 planes) = 144 bytes.</summary>
|
||||
public const int CellClipStrideBytes = 16 + MaxPlanes * 16; // 144
|
||||
|
||||
/// <summary>Byte offset of <c>planes[0]</c> within a <c>CellClip</c> (after the
|
||||
|
|
@ -57,7 +57,7 @@ public sealed class ClipFrame : IDisposable
|
|||
public const int CellClipPlanesOffset = 16;
|
||||
|
||||
/// <summary>std140 size of the terrain UBO block: int count padded to 16, then
|
||||
/// 8 × 16 (vec4 planes) = 144 bytes. Same number as the SSBO stride by
|
||||
/// 8 × 16 (vec4 planes) = 144 bytes. Same number as the SSBO stride by
|
||||
/// coincidence of the 16-byte vec4 rule, but a DIFFERENT layout family.</summary>
|
||||
public const int TerrainUboBytes = 16 + MaxPlanes * 16; // 144
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ public sealed class ClipFrame : IDisposable
|
|||
public const uint MeshClipSsboBinding = 2;
|
||||
|
||||
/// <summary>UBO binding index for the terrain OutsideView clip region
|
||||
/// (terrain_modern.vert binding=2). UBO namespace — distinct from the SSBO
|
||||
/// (terrain_modern.vert binding=2). UBO namespace — distinct from the SSBO
|
||||
/// binding=2 above.</summary>
|
||||
public const uint TerrainClipUboBinding = 2;
|
||||
|
||||
|
|
@ -139,23 +139,23 @@ public sealed class ClipFrame : IDisposable
|
|||
|
||||
/// <summary>
|
||||
/// The U.3 default frame: exactly slot 0 (no-clip, count 0) and a terrain
|
||||
/// count of 0. The whole scene renders ungated — identical to pre-U.3. U.4
|
||||
/// count of 0. The whole scene renders ungated — identical to pre-U.3. U.4
|
||||
/// replaces this with a frame built from real portal visibility.
|
||||
/// </summary>
|
||||
public static ClipFrame NoClip()
|
||||
{
|
||||
// One slot, all zeros: count=0 ⇒ shader passes every plane.
|
||||
// One slot, all zeros: count=0 ⇒ shader passes every plane.
|
||||
var bytes = new byte[CellClipStrideBytes];
|
||||
return new ClipFrame(bytes, slotCount: 1);
|
||||
}
|
||||
|
||||
/// <summary>Number of clip slots currently packed (always >= 1 — slot 0 is
|
||||
/// <summary>Number of clip slots currently packed (always >= 1 — slot 0 is
|
||||
/// the reserved no-clip slot).</summary>
|
||||
public int SlotCount => _slotCount;
|
||||
|
||||
/// <summary>
|
||||
/// Phase U.4: reset this frame back to the NoClip state — exactly slot 0
|
||||
/// (no-clip, count 0) and a terrain count of 0 — WITHOUT allocating a new
|
||||
/// Phase U.4: reset this frame back to the NoClip state — exactly slot 0
|
||||
/// (no-clip, count 0) and a terrain count of 0 — WITHOUT allocating a new
|
||||
/// frame or new GL buffers. The single long-lived <c>_clipFrame</c> in
|
||||
/// GameWindow is reset + re-packed every frame by <see cref="ClipFrameAssembler"/>,
|
||||
/// then uploaded through one SSBO and one terrain arena per fenced frame slot.
|
||||
|
|
@ -209,7 +209,7 @@ public sealed class ClipFrame : IDisposable
|
|||
/// <summary>
|
||||
/// Append one clip region (becomes the next slot index) from a
|
||||
/// <see cref="ClipPlaneSet"/>. Only the convex-plane case is supported in
|
||||
/// U.3 — <c>Count > 0</c> packs that many planes; <c>Count == 0</c> packs a
|
||||
/// U.3 — <c>Count > 0</c> packs that many planes; <c>Count == 0</c> packs a
|
||||
/// no-clip region (pass-all). The scissor / nothing-visible fallbacks that
|
||||
/// <see cref="ClipPlaneSet"/> can carry are deferred to U.4 (which will draw
|
||||
/// the AABB box or skip the cell on the CPU side, not via this slot). Returns
|
||||
|
|
@ -259,7 +259,7 @@ public sealed class ClipFrame : IDisposable
|
|||
/// <summary>
|
||||
/// Set the terrain OutsideView clip region (the single region the terrain
|
||||
/// shader gates against). <paramref name="planes"/> length 0 ungates terrain
|
||||
/// (count 0). U.3 callers never touch this — <see cref="NoClip"/> leaves it
|
||||
/// (count 0). U.3 callers never touch this — <see cref="NoClip"/> leaves it
|
||||
/// at count 0. U.4 calls it with the OutsideView planes.
|
||||
/// </summary>
|
||||
public void SetTerrainClip(ReadOnlySpan<Vector4> planes)
|
||||
|
|
@ -579,7 +579,7 @@ public sealed class ClipFrame : IDisposable
|
|||
}
|
||||
|
||||
/// <summary>A single std140 terrain-clip record within a frame-slot UBO arena.</summary>
|
||||
public readonly record struct TerrainClipBufferBinding(
|
||||
internal readonly record struct TerrainClipBufferBinding(
|
||||
uint Buffer,
|
||||
int OffsetBytes,
|
||||
int SizeBytes)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue