feat(render): Campaign V slice V6a - Vulkan memory, buffers, rings and the frame timeline
The first of V6's three commits, and the half of the Vulkan backend that has nothing to do with drawing: where memory comes from, how per-frame data reaches the GPU, and what makes it safe to reuse either. Plan sections: 4.2 (bindings layer and the no-VMA decision), 4.3 (memory: arena, staging ring, per-frame data), 4.8 (sync and the frame). The allocator is hand-rolled, roughly as 4.2 sizes it. Silk ships no VMA, and a third-party binding would be a native binary to carry across win-x64, linux-x64 and CI lavapipe for an allocation profile that is genuinely tame: two mesh arena buffers, one staging ring, a per-flight ring buffer each, a few render targets and a texture pool. What a custom allocator buys instead is exact accounting - every byte is attributable to a memory type and a block - which is what GpuMemoryTracker will want and what VMA would obscure. Placement, block policy and heap choice are pure types with no Vulkan handle in sight: VulkanMemoryBlockFreeList is first-fit with coalescing on release, VulkanMemoryTypePool decides when a request is large enough to warrant a block of its own, and VulkanMemoryTypeSelection maps each GpuMemoryResidency onto a preference order of property masks. VulkanDeviceMemoryAllocator turns their answers into vkAllocateMemory and one persistent vkMapMemory per host-visible block. That split is deliberate: an allocator's real failure modes are arithmetic - a mis-coalesced neighbour, an alignment that eats a block's tail, a double release that quietly corrupts the used-byte count - and arithmetic does not need a GPU to be wrong. Twenty-two tests cover exactly those. The HostWritable row of the selection table is the campaign's CPU win stated as data. It prefers a memory type that is both DEVICE_LOCAL and HOST_VISIBLE - resizable BAR, present on the RX 9070 XT - so per-frame data is written once, straight into memory the GPU reads, and falls back to ordinary host-visible coherent memory when no such type exists. GpuCapabilityRecord's SupportsPersistentlyMappedRings is the first capability that is true on this backend and false on GL. Mapping is per block, never per allocation, because Vulkan permits a memory object to be mapped once - mapping per buffer would need one VkDeviceMemory per buffer, which is precisely the allocation-count explosion the design exists to avoid. VulkanRingBufferState is markedly simpler than its GL sibling, and the difference IS the point. GlRingBufferState has to track a dirty watermark and prove its upload never overlaps an in-flight read, because a ring allocation there writes into a managed array that is later copied into a GL buffer. Here the allocation hands back memory the GPU reads directly: there is no upload step to track. What is left is a cursor. VulkanUploadQueue accumulates transfers rather than issuing them, for two reasons that both come from Vulkan rather than from taste: copies must be recorded into a command buffer, and they must be recorded outside a dynamic-rendering block. So requests queue and drain at the one moment both hold - immediately before a pass begins - which is the direct analogue of the GL backend's flush-before-every-draw discipline at the granularity Vulkan needs. The drain emits one batched buffer barrier for the whole batch, one of the four to six 4.8 budgets per frame. Staging exhaustion falls back to a temporary dedicated buffer retired through the ledger. Section 4.3 already specifies that for oversized uploads; extending it to "the ring is full of unretired frames" is the same shape and is a policy rather than a workaround - the transfer stays correct and ordered, it just costs one allocation. VulkanFrameFlightController is the mechanical port 4.8 promised. GL's array of fences becomes one timeline semaphore whose value is the frame serial, "has this slot retired?" becomes "is the counter at least serial minus two?", and the SortedDictionary retirement ledger keeps its keys because those keys were already frame serials. One subtlety is worth stating: a release is filed against the frame currently being RECORDED, not the last one completed, because commands already recorded into the open frame may still read the resource. A test pins that, since getting it wrong frees memory a pending command buffer reads and the symptom would appear somewhere else entirely. Frame acquire ordering is the other subtlety. TryBeginFrame waits on the flight slot BEFORE acquiring its swapchain image, so the slot's acquire semaphore is provably idle - signalling a semaphore a pending submit still waits on is the classic Vulkan deadlock. When the acquire fails the serial is still signalled through an empty submit, because a serial that never completes makes every later frame wait forever. The device is a partial class split along the V6 commit boundary: everything here is memory and frames, while textures and the descriptor table (V6b) and pipelines, passes and readback (V6c) throw with the slice named rather than returning something that fails later and further away. Nothing constructs this device yet - VulkanBringUpHost still presents its clear colour - so the GL path executes not one new statement. VK_EXT_debug_utils naming arrives with the allocator rather than at V6c, because every resource wants a name from birth and the campaign has already spent days on defects only visible from outside the API. It stays optional: absent extension means every call is a no-op and no call site checks. Gates: Release build clean, App suite 4014 passed / 3 skipped (3981 baseline plus 33 new). One Issue181WallPressEquilibriumTests failure in the full run is the known #250 zero-allocation flake and passes on a single run. Offline pixel gate against the parent is a tripwire here - the backend is dark and no GL code path changed - and is reported with the slice. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
78b0e14214
commit
fb9c6693dc
13 changed files with 3040 additions and 0 deletions
|
|
@ -32,6 +32,10 @@
|
|||
the rest of the Silk family so the shared Silk.NET.Core does not fork. -->
|
||||
<PackageReference Include="Silk.NET.Vulkan" Version="2.23.0" />
|
||||
<PackageReference Include="Silk.NET.Vulkan.Extensions.KHR" Version="2.23.0" />
|
||||
<!-- Campaign V slice V6: VK_EXT_debug_utils object naming and command labels.
|
||||
Optional at runtime (VulkanDebugNames.Disabled when absent), but the
|
||||
entry points have to be loadable for the dev-tools path to name anything. -->
|
||||
<PackageReference Include="Silk.NET.Vulkan.Extensions.EXT" Version="2.23.0" />
|
||||
<PackageReference Include="Silk.NET.Windowing" Version="2.23.0" />
|
||||
<PackageReference Include="Silk.NET.Input" Version="2.23.0" />
|
||||
<PackageReference Include="Silk.NET.OpenAL" Version="2.23.0" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue