Repository navigation
Runtime: no heap allocation per barrier, clear or copy in replay (Depends on #893) - #901
Conversation
|
Tested
So about 35–40% off the frame on Zen 3, a little more than the 14700K's 20%. The allocation counts match yours exactly. Code read: this looks right to me. One small thing, not blocking: the default move leaves a moved-from AI-assisted (Claude Code). |
|
Tested 8f45677 on AMD RDNA2 iGPU and RTX 5070: pass. Windows 11 Home 10.0.26300, MSVC 14.44.35207, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, Ninja RelWithDebInfo (
AI-assisted (Claude Code). No game files. |
execute built a new std::vector<PreparedList> on every call, so every
command's detail::Prepared entry (1288 bytes on main now) was made in
fresh memory and freed again: replay_cpu_bench measures that at 274-292
ns per command on an i7-14700K, against 85 ns refilled in kept storage,
over half of the layer's whole CPU cost per command. The queue now keeps
the vector as a member (per queue, like its command buffers: one execute
at a time on a queue, as acquire() and submit() already assume) and
resizes it to the list count; prepare refills each list's entries in
place, where the per-entry vectors also keep their capacity.
replay_cpu_bench mirrors the change and reports both floors (entries in
kept storage and made fresh). Its frame goes from 425 to 194 ns per
command (a 21,504-command frame from 9.1 ms to 4.2 ms).
d3d12_vulkan_device_test executes {B, A}, then {B} alone, and checks
that only B ran the second time: with storage that only grows, a stale A
is replayed after B and the test fails (checked).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three allocations replay_cpu_bench (ItsNotRexed#878) found on the hot path: - detail::current returned a std::vector<LayoutPiece> for every transition, clear and copy in emit, though the answer is nearly always one piece (two with separate depth/stencil). LayoutPieces keeps two inline and spills to the heap beyond that, with the same interface (begin/end, size, push_back, clear), so `auto pieces = current(...)` callers compile as is. LayoutTracker::pieces takes either container. - detail::clip built a new vector with push_back (two allocations for two rectangles); it now writes into the kept entry's p.rects. - CommandList::append took const Command& and copied the temporary the recording calls build, so a rectangle clear's vector was allocated twice; an rvalue overload moves it. replay_cpu_bench, i7-14700K, on top of ItsNotRexed#893: the frame goes from 194 to 173 ns per command, emit from 48 to 33 ns; emit makes no allocation per command in the frame (0.43 before) and prepare 0.07 (0.26), and recording makes one only for a rectangle clear's own rectangles. d3d12_state_map_test checks LayoutPieces against the vector path, including the spill at four pieces. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8f45677 to
9d47be3
Compare
|
Rebased onto #893's new head (9d47be3 on 9df4eda, on On top of #893: frame 194 → 173 ns/cmd, emit 48 → 33 ns; emit allocations per command 0.43 → 0, prepare 0.26 → 0.07 (i7-14700K). Tested 9d47be3 on RTX 5070, driver 621.01, Windows 11, MSVC 14.44, Vulkan SDK 1.4.363: |
Depends on: #893 (and through it #878; this branch carries both commits). Claim.
What
Three heap allocations that
replay_cpu_benchfound on the hot path, each removed without changing a caller's code:emit.detail::currentreturned astd::vector<LayoutPiece>for every transition, clear and copy, even though the answer is nearly always one piece (two with separate depth and stencil). The newLayoutPieceskeeps two inline and spills to the heap beyond that. Its interface is the same:begin/end,size,operator[],push_back,clear. Soauto pieces = current(...)callers compile unchanged, including the ones Runtime: compute path and graphics draws on Vulkan (D3D-3, D3D-4, milestone M1) #291 and the PRs stacked on it add (Runtime: CreateHeap and CreatePlacedResource on the Vulkan layer (D3D-16) #286, Runtime: variable rate shading on Vulkan, RSSetShadingRate and the shading-rate image (D3D-32) #469, Runtime: primitive restart from the PSO's IBStripCutValue (D3D-57) #572, Runtime: SetSamplePositions and the centre sample pattern on VK_EXT_sample_locations #848, Runtime: viewport and scissor arrays (RSSetViewports, RSSetScissorRects) #873).LayoutTracker::piecesis now a template, so it still fills astd::vectorfor its existing test.prepare.detail::clipbuilt a new vector withpush_back, which meant two allocations for two rectangles. It now writes into the entry'sp.rects, which since Runtime: VulkanQueue keeps its PreparedList storage between executions (layer CPU cost per command halved) #893 keeps its storage between executions. It has one caller.CommandList::append(const Command&)copied the temporary that every recording call builds, so a rectangle clear's vector was allocated twice. Anappend(Command&&)overload moves it, and the recording calls pick it up as they are.Numbers
replay_cpu_bench, i7-14700K, Windows 11, MSVC 14.44, RelWithDebInfo, three runs:Together with #893, a 21k-command frame goes from 4.2–6.2 ms to about 1.7 ms of layer CPU time. The one allocation left in the frame is a rectangle clear's own
rectswhile recording.Not changed: the UAV clear's
prepare(about 94 ns) is mostlyuav_clear::putwriting one bit at a time. A frame has few UAV clears, and that file is where the clear-accuracy work happens, so I left it. Enhanced texture barriers still build astd::vector<VkImageMemoryBarrier2>each time.Tests
d3d12_state_map_test:LayoutPiecesgives the same pieces as the vector path for the four-piece separate-depth/stencil case, which takes the spill path. It also checks the one-piece case, and that the two inline pieces are kept, in order, when a third spills.ctest -E loader29/29.loader_testis excluded because it hangs on this PC; that's unrelated and also happens onmain.d3d12_vulkan_device_test(including Runtime: VulkanQueue keeps its PreparedList storage between executions (layer CPU cost per command halved) #893's multi-list block) andd3d12_com_testwithLEONIDA_VK_VALIDATION=1pass with 0 validation errors.AI-assisted (Claude Code).
🤖 Generated with Claude Code