Repository navigation
Runtime: VulkanQueue keeps its PreparedList storage between executions (layer CPU cost per command halved) - #893
Conversation
quackottu
left a comment
There was a problem hiding this comment.
Tested e550911 on NVIDIA GeForce RTX 5070, driver 621.24, Windows 11 Pro (26300), VS 2022 Build Tools, Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1 and LEONIDA_D3D12=vulkan: pass
ctest -C RelWithDebInfo: 100% tests passed, 0 tests failed out of 33d3d12_vulkan_device_test(changed here): exit=0 validation=0 | [rt] d3d12: upload heaps in VRAM (DEVICE_LOCAL | HOST_VISIBLE, Resizable BAR)- 32 test programs in the build pass with 0 validation errors
- Not run (they take an input file, not covered here): vk_binary_occlusion_test
d3d12_clear_testfails (R8G8B8A8_UNORM/SNORM 0.5 ties and a D16 clear byte differ from WARP) exactly as onmain4a36bb1 here, so not from this PR; #521 addresses it
Implicit Vulkan layers (overlays) were off through an empty VK_IMPLICIT_LAYER_PATH.
|
Tested
So on Zen 3 the entry floor drops by about 55 ns per command (run 2 was noisy on both rows), about 1.2 ms of the 4.5–4.9 ms frame. Absolute numbers are roughly twice the 14700K's, but the kept/fresh ratio is about the same (2.2–2.3×). Allocations per command in the frame match yours (0.19 / 0.19 / 0.43). Code read: the change looks right to me. One small thing: the description's list of open PRs that touch AI-assisted (Claude Code). |
|
Tested e550911 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>
e550911 to
9df4eda
Compare
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>
|
Rebased onto What changed in the rebase:
Tested 9df4eda on RTX 5070, driver 621.01, Windows 11, MSVC 14.44, Vulkan SDK 1.4.363: |
Depends on: #878 (the benchmark; this branch carries its commit). Follow-up to my
PreparedListfinding (claim).What
VulkanQueue::executebuilt a newstd::vector<PreparedList>on every call. So every command'sdetail::Preparedentry (528 bytes) was made in fresh memory and freed at the end, roughly 11 MB per 21k-command frame. The queue now keeps that vector as a member,prepared_. It's guarded by the context mutex, whichexecutealready holds, and resized to the list count each call.preparealready refillslist,commandsandunpredicated_copies, so entries are rewritten in place. The per-entry vectors also keep their capacity, which removes the allocations copies and UAV clears made inprepare. The change is the declaration line plus one member. The open PRs that touchexecute(#306, #419, #856, #860) edit theprepare/emitcall lines, not this one.Memory: a queue now holds on to its largest execution's entries, about 528 bytes per command (11 MB for 21k commands), instead of allocating that much every frame.
Numbers
replay_cpu_benchfrom #878, i7-14700K, Windows 11, MSVC 14.44, RelWithDebInfo, three runs each:The benchmark now mirrors the kept storage, and prints both floors: entries refilled in kept storage, about 26 ns, and made fresh, about 110 ns. Full output after:
Tests
d3d12_vulkan_device_testgains a block that executes{B, A}, then{B}alone, on its own fence so the main fence's values are untouched. B clears blue and A red, so the target must end blue. Negative control: with storage that only grows, the stale A is replayed after B, and the block fails withgot ff 00 00 ff, want 00 00 ff ff(checked, then reverted).ctest -E loader29/29.loader_testis excluded because it hangs on this PC; that's unrelated and also happens onmain.d3d12_vulkan_device_testandd3d12_com_testwithLEONIDA_VK_VALIDATION=1pass with 0 validation errors.AI-assisted (Claude Code).
🤖 Generated with Claude Code