Repository navigation
Runtime: recording a draw allocates nothing (D3D-289) - #2471
requiemsnkrp wants to merge 2 commits into
Conversation
- command_list.h: a draw's render targets and vertex-buffer views move out of the recorded Draw into two arrays the CommandList keeps for all its draws (DrawRange: first, count). CommandList::draw takes them as spans and emplaces the Draw directly, so it no longer copies two vectors into a temporary Command and again into the list; CommandList::render_targets / vertex_buffers read them back, ExecuteBundle moves a bundle's draws to the parent's copies and Reset keeps the arrays' storage. One recorded Command: 328 -> 296 bytes. - d3d12_com.cpp: record_draw passes the list's render targets and 32 vertex slots as spans instead of building two vectors per draw. vulkan_replay.h: prepare_draw reads the two spans; what is replayed is unchanged. - replay_cpu_bench: "draw" and "draw indexed" rows (scene pipeline and geometry arena as in ItsNotRexed#2123), checked on every run to record with no heap allocation. Ryzen 5 5600X, median of 5 runs: draw record 315.1 -> 47.5 ns and 6 -> 0 allocations, draw indexed 312.1 -> 48.4 ns and 6 -> 0; prepare and emit unchanged. - command_list_test: draw arrays are copies, ExecuteBundle rebases them, an empty draw adds nothing. - d3d12_vulkan.md: where a draw's arrays live. AI-assisted.
|
Independent check of 2dfc268 on Windows 11 build 26300, MSVC 19.44, SDK 10.0.26100.0, i7-14700KF, RTX 5070 driver 621.24.
Synthetic fixtures only. AI-assisted review. |
|
Tested 2dfc268 (merged on current main) on RTX 3090, driver 616.56, Windows 11 23H2: pass. MSVC 2022 / Ninja, Vulkan SDK 1.4.363. AI-assisted test run. |
|
Tested 2dfc268 (merged onto main 4947579) on NVIDIA GeForce RTX 4060 Ti, driver 610.88 (32.0.16.1088), Windows 11 26200, MSVC 14.51.36231 (VS 2026), Vulkan SDK 1.4.363.0: pass
AI-assisted (Claude). |
|
Tested the merge of PR #2471 head 2dfc268 with
No game files used. Ran with an AI agent on my machine. |
|
Tested 2dfc268 on AMD Radeon RX 7600 (RDNA3), AMD 26.11.2 (LLPC), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8: command_list_test passes.
AI-assisted (Claude Code, reviewed with Codex). No game files. |
|
Tested Windows runtime under Wine 11.21 (clang-cl 23.1.4 + xwin, SDK 10.0.26100): builds clean. Full Linux (GCC 16.2.1):
The AI-assisted (Claude Code). No game files used. |
|
Windows + GPU check: AMD Radeon RX 9070 (RDNA4), Windows 11, MSVC Release, Vulkan SDK 1.4.363. Tested head 2dfc268 merged onto AI-assisted (Claude Code); runs on my machine. |
|
Tested 2dfc268, merged onto
AI-assisted (Claude Code). |
|
Tested 2dfc268 on AMD Radeon RX 7900 XTX (RDNA3, Navi 31), AMD driver 26.11.2, Vulkan 1.4.359, Windows 11: pass apart from a failure inherited from the base.
Tools: MSVC 14.44 ( |
|
@gkissel thanks for the careful numbers. I looked into
AI-assisted (Claude). |
|
Code review of 2dfc268 (read only, no runs): looks right to me, nothing blocking. What I checked:
One heads-up: this overlaps my #2123 in the same two files.
The two combine cleanly: AI-assisted (Claude Code). |
|
Tested 2dfc268 on Windows 11 (26200), MSVC 19.4x (VS 2022 Build Tools), Ninja RelWithDebInfo, on both GPUs of a two-GPU PC:
That failure doesn't look like this PR's. The PR doesn't touch |
|
@requiemsnkrp thanks, that explains my +22%. My run was Linux/GCC on a 5800H, so it matches what you saw under GCC. The row never calls the changed code, and the effect disappears when the buffer is pinned to the same address, so it's heap placement and not this PR. I withdraw the concern about |
Conflict in CommandList::execute_bundle: main now copies a stretch [first, last) of the bundle's commands (bundle draws are deferred calls played on the parent). The draws in the copied stretch get their render targets and vertex buffers copied from the bundle's arrays into the parent's, so a stretch copies only its own draws' runs; command_list_test checks two stretches of a bundle.
|
Merged Retested on RTX 3060 with
Full ctest ( AI-assisted (Claude). |
|
Tested 2dfc268 on RTX 5070, driver 621.24, Windows 11 26H2 (26300), MSVC 14.52 (VS Build Tools 18), RelWithDebInfo, with |
|
Tested 1291ae1 under Wine 11.21 (Fedora 45) on AMD Radeon 610M (RDNA2 iGPU, RADV Mesa 26.2.6) and NVIDIA RTX 4070 Ti (615.78.08): pass This adds AMD and Linux to the Windows NVIDIA checks above. The Windows runtime was cross-built with clang-cl 23.1.5 and xwin (MSVC 14.44, SDK 10.0.26100), and its ctest suite was run under Wine and Xvfb, one GPU at a time with
Not run, because they fail in this environment on every commit:
#2483, which targets the same item (D3D-289), was merged at 20:00 UTC, after this run. This head is based on AI-assisted (Claude Code); numbers copied from the run logs. |
|
Tested 1291ae1 on an RX 9070 (RDNA4), AMD 26.11.1 (LLPC), Vulkan 1.4.359, Windows 11: pass Full ctest run: 130/130 passed. Two things I noticed along the way, in case they're useful:
AI-assisted |
|
@lunisahdidouch thanks. On the AI-assisted (Claude). |
What and why
D3D-289 (claim; @traeb0n had first refusal and was asked, no answer). Recording a draw allocated on the heap on every call:
leonida::Drawowned two vectors (render targets, the 32 vertex-buffer slots), built atd3d12_com.cpp:927-928, copied into a temporaryCommandbydraw(const Draw&)→append(const Command&), and copied again bycommands_.push_back. 6 allocations per draw onmain(the finding's 4 was measured on top of #901, which already moves inappend).Drawholds twoDrawRange {first, count}instead of vectors; theCommandListkeeps one array for all its draws' render targets and one for their vertex buffers.Resetclears them and keeps their storage, so once grown, recording a draw allocates nothing.CommandList::draw(const Draw&, span<const TargetView>, span<const VertexBufferView>)copies the spans in and builds theCommandin place;render_targets(draw)/vertex_buffers(draw)read them back;execute_bundlecopies a bundle's arrays into the parent and shifts its draw ranges.record_draw(D3D12 layer) passesrender_targets_and the 32-slot array as spans;prepare_drawreads the spans. What is recorded and replayed is unchanged (all 32 slots still stored). OneCommandshrinks from 328 to 296 bytes.docs/d3d12_vulkan.md: where a draw's arrays live, and that the bench checks it.Bench
replay_cpu_benchonmainhas no draw row yet (#2123 adds it), so the bench gets "draw" and "draw indexed" rows here, with #2123's draw scene setup. Ryzen 5 5600X, median of 5 runs (each a median of 25 reps):No other row changed its allocation counts; times within noise. The prepare/emit allocations are replay-side (#893, #2123), left alone. The two draw rows now fail the bench (and
replay_cpu_bench --self-test, thereplay_cpu_bench_selftestctest) if recording a draw allocates.Tested
command_list_test: new block — a draw's arrays are copies,ExecuteBundleshifts a bundle's draw ranges, an empty draw adds nothing.d3d12_com(segfault),d3d12_debug_markers,d3d12_indirect_rt,d3d12_draw, all failing the same way onmain4eb6155 without this PR (d3d12_draw: "bundle blend pixel (0, 0): got 127,0,127,255, expected red 64", also onmain).Conflicts expected with #2123 (
replay_cpu_bench.cppdraw scene,prepare_drawinvulkan_replay.h); happy to rebase whichever lands second.No game files. AI-assisted (Claude).