feat(render): Campaign V slice V6j commit 2 - Dereth draws on Vulkan
The three world renderers' submission arms, both pass executors, and the
composition that reaches them. This is the unit three predecessors stopped at.
What it produces. ACDREAM_RENDER_BACKEND=vulkan on the offline scene renders
terrain with blended textures and road overlays, the water edge, static world
meshes, procedural scenery, and the complete retained UI - the same frame the GL
pixel gate captures, from the same camera, minus the sky. artifacts/v6j-vk2.
The shape, and why it is not V4c's. Section 5.5.6 chose option (B) after NVIDIA
rendered the V4c binary 10/10 where AMD's GL stack did not: GL keeps its raw
world path through to V10 as a documented fork confined to the submission seam,
and the RHI world path ships on Vulkan. So V4c's and V4d-2's content returns as a
SECOND arm rather than a replacement. The GL arm issues the same GL statements in
the same order against the same objects; the encoder arm lives in three .Rhi.cs
partials and is entered by one branch per submission site.
Three differences from V4c, each because the tree moved under it. There is no
binding-9 texture table - V4t put the slot on the device and Vulkan binds set 2,
so the arm that used to intern bindless handles simply has nothing to do. The
pipelines carry the device's sample count rather than 1, because Vulkan requires
rasterizationSamples to match the pass and alpha-to-coverage is a no-op at one
sample. And no renderer opens a pass.
That last one is structural, not tidiness. Under MSAA the frame's one backbuffer
pass resolves into the swapchain image and stores DONT_CARE into the multisampled
scratch, so a second pass declaring Load would load undefined contents; the
backend also permits one open pass per frame. VulkanWorldScenePhase therefore
opens the pass, publishes the encoder on VulkanWorldPassScope for exactly the
span of the inner WorldSceneRenderer, and every renderer borrows it.
Three sections are frame-global on GL and cannot be on Vulkan: the SceneLighting
UBO, the per-cell clip regions, and the terrain clip block. GL binds each to a
global binding point and every consumer inherits it. Vulkan binds a descriptor
set per draw, and a renderer's own binds are what select the scope those sections
must land in - so their writers PUBLISH into WorldFrameSections and each renderer
binds them inside the pass, after its own binds. SceneLightingUboBinding's
per-flight-slot buffer pool disappears with it: a ring allocation is already
distinct memory that lives until the frame retires, which is the property the
pool existed to provide.
Both pass executors became backend-neutral rather than gaining twins. Everything
they do is delegation to a renderer except four concerns - the clip-frame
publication, the doorway scissor, gl_ClipDistance enablement, and retail's
interior depth clear - so those four move behind IWorldPassSurface and retail's
ordering, which is what these classes are actually for, is written once. The GL
implementation issues the statements the executors used to issue inline.
Clip distances are no-ops on the Vulkan arm, and that is safe rather than a
divergence: Vulkan activates every element the shader declares, and all three
world vertex shaders already write 1.0 into every slot past the active count.
The interior depth clear becomes vkCmdClearAttachments, reached through the scope
so the pinned contract stays frozen and the backend-only verb stays in the
backend. The hook for it was already committed at V6i-3 with a cref to a type
that did not exist yet; it exists now.
The collision-wireframe DebugLineRenderer is composed as null on the Vulkan arm.
DrawAndPublish flushes it INSIDE the world phase and it opens its own pass, which
the one-pass rule forbids. The toggle is DevTools-only and DevTools is not
composed there, so nothing is lost - composing it would throw on the first
wireframe frame rather than silently misdraw.
Two seams widened rather than invented. GameWindowGraphics answers whether the
backend has a world-pass seam, because the three composition phases that need it
already borrow that handle and "does this backend work that way" is what the type
exists to answer. And MeshSourceReady replaces the anyVao != 0 gate with the same
question in backend-neutral form - V6i-3 published HasStores for exactly this -
so the predicate evaluates identically on GL.
What is NOT here, and is expected. Sky and weather are still raw GL (V4f), so the
Vulkan frame's sky is the atmosphere fog clear. Particles (V4e), the paperdoll and
appraisal viewports and the portal depth mask (V4g) likewise. The executors
already accepted all of them as absent.
Gates. Release build green. App tests 4,112 passed / 3 skipped, the unchanged
baseline; complete Release suite 9,175 / 5. Strict GL offline pixel gate against
847f14ae: 5.50e-05, 31 differing pixels of 563,200, inside the documented 9-31
band and 18x under the threshold. Characterised rather than accepted, because 31
is the band's top: cross-commit pairs measured 21, 29 and 31 while same-commit
controls measured 12 and 20, and maximumChannelDelta is 46-52 in every comparison
INCLUDING the pure controls - so the few large-delta pixels are a property of the
capture, and a cross-commit pair at 21 against a same-commit pair at 20 is not
what a systematic shift looks like. GL connected repeat gate at 3 runs: 3/3
RENDERED on the desktop witness and 3/3 on the client capture. One offline Vulkan
run with VK_LAYER_KHRONOS_validation proven inserted by the loader: zero
validation errors, zero warnings, a captured world frame, and a graceful close.
Coverage gap, stated rather than assumed. The offline scene is a fixed outdoor
view, so EnvCellRenderer's Vulkan arm draws nothing in it - dungeon interiors are
half of this slice and are unproven by anything automated, exactly as they were
for V4c. The deferred-alpha path and the doorway scissor are likewise untouched
by this scene. They join the accumulated user-gate debt in plan section 5.1.
No divergence-register row: no retail-facing behaviour changes.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
81fe5e1b63
commit
f84eef3256
22 changed files with 2566 additions and 264 deletions
|
|
@ -17,7 +17,7 @@ namespace AcDream.App.Rendering;
|
|||
/// Total ~6-8 GL calls per frame for terrain regardless of visible
|
||||
/// landblock count.
|
||||
/// </summary>
|
||||
public sealed unsafe class TerrainModernRenderer : IDisposable
|
||||
public sealed unsafe partial class TerrainModernRenderer : IDisposable
|
||||
{
|
||||
// VertsPerLandblock MUST stay divisible by 6 — terrain_modern.vert uses
|
||||
// `gl_VertexID % 6` to pick the cell-corner index (BL/BR/TR/TL), and
|
||||
|
|
@ -32,9 +32,12 @@ public sealed unsafe class TerrainModernRenderer : IDisposable
|
|||
private const int IndexSize = sizeof(uint);
|
||||
private const float LandblockSize = LandblockMesh.LandblockSize; // 192
|
||||
|
||||
private readonly GL _gl;
|
||||
private readonly BindlessSupport _bindless;
|
||||
private readonly Shader _shader;
|
||||
// Campaign V slice V6j: null on the RHI arm, where every statement below that
|
||||
// reaches one of these is forked into TerrainModernRenderer.Rhi.cs. The GL arm
|
||||
// executes exactly what it did before.
|
||||
private readonly GL? _gl;
|
||||
private readonly BindlessSupport? _bindless;
|
||||
private readonly Shader? _shader;
|
||||
private readonly TerrainAtlas _atlas;
|
||||
|
||||
/// <summary>A.5 T22.5: exposes the terrain atlas so callers can update
|
||||
|
|
@ -264,7 +267,7 @@ public sealed unsafe class TerrainModernRenderer : IDisposable
|
|||
if (_dynamicBufferCursor == frameBuffers.Count)
|
||||
{
|
||||
uint buffer = TrackedGlResource.CreateBuffer(
|
||||
_gl,
|
||||
_gl!,
|
||||
$"creating terrain indirect buffer for frame slot {_dynamicFrameSlot}");
|
||||
try
|
||||
{
|
||||
|
|
@ -273,7 +276,7 @@ public sealed unsafe class TerrainModernRenderer : IDisposable
|
|||
catch
|
||||
{
|
||||
TrackedGlResource.DeleteBuffer(
|
||||
_gl,
|
||||
_gl!,
|
||||
buffer,
|
||||
0,
|
||||
"rolling back terrain indirect buffer");
|
||||
|
|
@ -363,6 +366,12 @@ public sealed unsafe class TerrainModernRenderer : IDisposable
|
|||
nint vboByteOffset = (nint)(slot * VertsPerLandblock * VertexSize);
|
||||
nint eboByteOffset = (nint)(slot * IndicesPerLandblock * IndexSize);
|
||||
|
||||
if (_gl is null)
|
||||
{
|
||||
UploadRhiLandblock(slot, bakedVerts, bakedIndices);
|
||||
}
|
||||
else
|
||||
{
|
||||
fixed (TerrainVertex* p = bakedVerts)
|
||||
{
|
||||
TrackedGlResource.UpdateBufferSubData(
|
||||
|
|
@ -386,6 +395,7 @@ public sealed unsafe class TerrainModernRenderer : IDisposable
|
|||
p,
|
||||
$"uploading terrain indices for 0x{landblockId:X8}");
|
||||
}
|
||||
}
|
||||
|
||||
_slots[slot] = new SlotData
|
||||
{
|
||||
|
|
@ -461,24 +471,23 @@ public sealed unsafe class TerrainModernRenderer : IDisposable
|
|||
ndcClipAabb);
|
||||
}
|
||||
if (_visibleSlots.Count == 0) return;
|
||||
ActivateNextIndirectBuffer();
|
||||
|
||||
// Build DEIC array.
|
||||
if (_deicScratch.Length < _visibleSlots.Count)
|
||||
_deicScratch = new DrawElementsIndirectCommand[Math.Max(_visibleSlots.Count, 64)];
|
||||
for (int i = 0; i < _visibleSlots.Count; i++)
|
||||
// Campaign V slice V6j: the command array is built the same way on both
|
||||
// arms; only where it lands differs. The RHI arm writes it into a frame
|
||||
// ring slice, which retires the per-frame-slot indirect buffer pool
|
||||
// structurally — every allocation within a frame is already distinct
|
||||
// memory that outlives the draw recorded against it.
|
||||
BuildIndirectCommands();
|
||||
if (_gl is null)
|
||||
{
|
||||
var data = _slots[_visibleSlots[i]]!;
|
||||
_deicScratch[i] = new DrawElementsIndirectCommand
|
||||
{
|
||||
Count = (uint)data.IndexCount,
|
||||
InstanceCount = 1u,
|
||||
FirstIndex = data.FirstIndex,
|
||||
BaseVertex = 0, // baked into indices on upload
|
||||
BaseInstance = 0,
|
||||
};
|
||||
if (!_dynamicFrameStarted)
|
||||
throw new InvalidOperationException("BeginFrame must be called before drawing terrain.");
|
||||
DrawRhi(viewProjection, _visibleSlots.Count);
|
||||
return;
|
||||
}
|
||||
|
||||
ActivateNextIndirectBuffer();
|
||||
|
||||
// Grow indirect buffer if needed.
|
||||
if (_visibleSlots.Count > _indirectCapacity)
|
||||
{
|
||||
|
|
@ -515,7 +524,7 @@ public sealed unsafe class TerrainModernRenderer : IDisposable
|
|||
// renderers in the unified pipeline. Retail's LScape::update_viewpoint
|
||||
// pre-positions terrain to the outdoor landcell, but acdream uses the
|
||||
// unified camera matrix everywhere, so no separate viewpoint divergence can occur.
|
||||
_shader.Use();
|
||||
_shader!.Use();
|
||||
UploadTextureTilingOnce();
|
||||
// Campaign V slice V6f-2: bind the tiling UBO every draw, not once. GL's
|
||||
// uniform-buffer binding points are global and shared with the sky's
|
||||
|
|
@ -582,11 +591,38 @@ public sealed unsafe class TerrainModernRenderer : IDisposable
|
|||
_gl.Disable(EnableCap.CullFace);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds this frame's <c>DrawElementsIndirectCommand</c> array from the
|
||||
/// visible slot list. Pure CPU, identical on both arms.
|
||||
/// </summary>
|
||||
private void BuildIndirectCommands()
|
||||
{
|
||||
if (_deicScratch.Length < _visibleSlots.Count)
|
||||
_deicScratch = new DrawElementsIndirectCommand[Math.Max(_visibleSlots.Count, 64)];
|
||||
for (int i = 0; i < _visibleSlots.Count; i++)
|
||||
{
|
||||
var data = _slots[_visibleSlots[i]]!;
|
||||
_deicScratch[i] = new DrawElementsIndirectCommand
|
||||
{
|
||||
Count = (uint)data.IndexCount,
|
||||
InstanceCount = 1u,
|
||||
FirstIndex = data.FirstIndex,
|
||||
BaseVertex = 0, // baked into indices on upload
|
||||
BaseInstance = 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed)
|
||||
return;
|
||||
_retirementLedger.RetryPendingPublications();
|
||||
if (_gl is null)
|
||||
{
|
||||
DisposeRhi();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_disposeResources is null)
|
||||
{
|
||||
|
|
@ -727,7 +763,7 @@ public sealed unsafe class TerrainModernRenderer : IDisposable
|
|||
fixed (byte* p = block)
|
||||
{
|
||||
TrackedGlResource.UpdateBufferSubData(
|
||||
_gl,
|
||||
_gl!,
|
||||
BufferTargetARB.UniformBuffer,
|
||||
_tilingUbo,
|
||||
0,
|
||||
|
|
@ -764,7 +800,7 @@ public sealed unsafe class TerrainModernRenderer : IDisposable
|
|||
{
|
||||
GlGpuDevice device = GpuDevice;
|
||||
device.FlushTextureTable();
|
||||
_gl.BindBufferBase(
|
||||
_gl!.BindBufferBase(
|
||||
GLEnum.ShaderStorageBuffer,
|
||||
GpuBindingModel.StorageTextureTable,
|
||||
device.TextureTableGlName);
|
||||
|
|
@ -781,7 +817,7 @@ public sealed unsafe class TerrainModernRenderer : IDisposable
|
|||
{
|
||||
if (_sharedClipBinding.IsValid)
|
||||
{
|
||||
_sharedClipBinding.Bind(_gl);
|
||||
_sharedClipBinding.Bind(_gl!);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -790,12 +826,12 @@ public sealed unsafe class TerrainModernRenderer : IDisposable
|
|||
var zero = stackalloc byte[ClipFrame.TerrainUboBytes];
|
||||
for (int i = 0; i < ClipFrame.TerrainUboBytes; i++) zero[i] = 0;
|
||||
uint fallback = TrackedGlResource.CreateBuffer(
|
||||
_gl,
|
||||
_gl!,
|
||||
"creating terrain fallback clip UBO");
|
||||
try
|
||||
{
|
||||
TrackedGlResource.AllocateBufferStorage(
|
||||
_gl,
|
||||
_gl!,
|
||||
BufferTargetARB.UniformBuffer,
|
||||
fallback,
|
||||
0,
|
||||
|
|
@ -808,14 +844,14 @@ public sealed unsafe class TerrainModernRenderer : IDisposable
|
|||
catch
|
||||
{
|
||||
TrackedGlResource.DeleteBuffer(
|
||||
_gl,
|
||||
_gl!,
|
||||
fallback,
|
||||
0,
|
||||
"rolling back terrain fallback clip UBO");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
_gl.BindBufferBase(BufferTargetARB.UniformBuffer,
|
||||
_gl!.BindBufferBase(BufferTargetARB.UniformBuffer,
|
||||
ClipFrame.TerrainClipUboBinding, _fallbackClipUbo);
|
||||
}
|
||||
|
||||
|
|
@ -825,7 +861,7 @@ public sealed unsafe class TerrainModernRenderer : IDisposable
|
|||
long eboBytes = checked((long)capacitySlots * IndicesPerLandblock * IndexSize);
|
||||
|
||||
TrackedGlResource.AllocateBufferStorage(
|
||||
_gl,
|
||||
_gl!,
|
||||
BufferTargetARB.ArrayBuffer,
|
||||
_globalVbo,
|
||||
_globalVboCapacityBytes,
|
||||
|
|
@ -835,7 +871,7 @@ public sealed unsafe class TerrainModernRenderer : IDisposable
|
|||
_globalVboCapacityBytes = vboBytes;
|
||||
|
||||
TrackedGlResource.AllocateBufferStorage(
|
||||
_gl,
|
||||
_gl!,
|
||||
BufferTargetARB.ElementArrayBuffer,
|
||||
_globalEbo,
|
||||
_globalEboCapacityBytes,
|
||||
|
|
@ -847,7 +883,7 @@ public sealed unsafe class TerrainModernRenderer : IDisposable
|
|||
|
||||
private void ConfigureVao(uint vao, uint vbo, uint ebo)
|
||||
{
|
||||
_gl.BindVertexArray(vao);
|
||||
_gl!.BindVertexArray(vao);
|
||||
_gl.BindBuffer(BufferTargetARB.ArrayBuffer, vbo);
|
||||
_gl.BindBuffer(BufferTargetARB.ElementArrayBuffer, ebo);
|
||||
|
||||
|
|
@ -1002,6 +1038,11 @@ public sealed unsafe class TerrainModernRenderer : IDisposable
|
|||
{
|
||||
if (newCapacity <= _alloc.Capacity)
|
||||
return;
|
||||
if (_gl is null)
|
||||
{
|
||||
EnsureRhiCapacity(newCapacity);
|
||||
return;
|
||||
}
|
||||
|
||||
var grownSlots = new SlotData?[newCapacity];
|
||||
Array.Copy(_slots, grownSlots, _slots.Length);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue