replay_cpu_bench: stop overstating a draw 2.1x and a frame 1.9x (measure the layer, not the harness) #58

Closed
leonida/mandy
Andretuta wants to merge 0 commits from old-pr/9780 into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

Andretuta commented 2026-11-24 02:09:57 +00:00

Carried over from old PR 9780 by pes7 in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9780, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
pes7: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

The layer's own CPU benchmark was overstating a draw by 2.1x and a frame by 1.9x, so anything optimized against it was optimized against the wrong number. This makes it measure the layer.

replay_cpu_bench's draw rows built a fresh DrawViews with make_shared inside the timed lambda — an allocation and a value-initialised block of 8 render-target views and 32 vertex-buffer views per draw. The layer does not do that: d3d12_com.cpp's draw_views() rebuilds the block only when the render targets or the vertex buffers change, and a steady-state draw copies the shared_ptr.

What changes

The steady-state kinds share one block; a state change keeps its own rows (draw, views rebuilt, draw indexed, views rebuilt), so the old case stays measured. The frame records the steady-state draw, which is what a frame does.

Measured, same build, same machine

ns per command before after
draw 389.4 record / 786.8 total, alloc 1.00 30.4 / 242.9, alloc 0.00
draw indexed 494.8 / 1036.4 31.2 / 248.3
frame (37,888 commands) 851.2 → 32,249.7 µs 446.0 → 16,898.4 µs

With the views cost out of the way the profile reads differently: prepare (138.6 ns) is the expensive part of a draw, record is 30.4 ns. Before, record looked like the hot spot because the benchmark's own make_shared sat in it.

This is the tool used to conclude that the remaining substantial lever is the size of one prepared entry (detail::Prepared is 1016 bytes, Command 296, PreparedDraw 312 — ~1.6 KB per draw per frame, measured in #8504 with the per-command cost rising 99 → 253 ns as the set outgrows cache), and to reject two changes that sounded good and measured flat.

replay_cpu_bench --self-test: 15 kinds and a 296-command frame, ok. No runtime/src change; no GPU, no game data.

cc @ItsNotRexed @KoertLichtendonk

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md. (Not applicable: no translation change.)
> Carried over from **old PR 9780** by `pes7` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9780`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `pes7`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): **The layer's own CPU benchmark was overstating a draw by 2.1x and a frame by 1.9x**, so anything optimized against it was optimized against the wrong number. This makes it measure the layer. `replay_cpu_bench`'s `draw` rows built a fresh `DrawViews` with `make_shared` **inside the timed lambda** — an allocation and a value-initialised block of 8 render-target views and 32 vertex-buffer views per draw. The layer does not do that: `d3d12_com.cpp`'s `draw_views()` rebuilds the block only when the render targets or the vertex buffers change, and a steady-state draw copies the `shared_ptr`. ### What changes The steady-state kinds share one block; a state change keeps its own rows (`draw, views rebuilt`, `draw indexed, views rebuilt`), so the old case stays measured. The frame records the steady-state draw, which is what a frame does. ### Measured, same build, same machine | ns per command | before | after | |---|---|---| | `draw` | 389.4 record / 786.8 total, alloc 1.00 | **30.4 / 242.9, alloc 0.00** | | `draw indexed` | 494.8 / 1036.4 | 31.2 / **248.3** | | frame (37,888 commands) | 851.2 → **32,249.7 µs** | 446.0 → **16,898.4 µs** | With the views cost out of the way the profile reads differently: `prepare` (138.6 ns) is the expensive part of a draw, `record` is 30.4 ns. Before, `record` looked like the hot spot because the benchmark's own `make_shared` sat in it. This is the tool used to conclude that the remaining substantial lever is the size of one prepared entry (`detail::Prepared` is 1016 bytes, `Command` 296, `PreparedDraw` 312 — ~1.6 KB per draw per frame, measured in `#8504` with the per-command cost rising 99 → 253 ns as the set outgrows cache), and to reject two changes that sounded good and measured flat. `replay_cpu_bench --self-test`: 15 kinds and a 296-command frame, ok. No `runtime/src` change; no GPU, no game data. cc `@ItsNotRexed` `@KoertLichtendonk` ### Checklist - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`. (Not applicable: no translation change.)
MoonEyes commented 2026-11-30 18:01:31 +00:00

Maintainer review: the benchmark change still appears relevant in current main, but this PR is not ready to merge. It remains a draft and all current CI checks were cancelled; the reported measurements are historical. Please confirm ownership, update against current main, rerun the focused self-test and required validation, then mark ready.

Maintainer review: the benchmark change still appears relevant in current main, but this PR is not ready to merge. It remains a draft and all current CI checks were cancelled; the reported measurements are historical. Please confirm ownership, update against current main, rerun the focused self-test and required validation, then mark ready.
aslan2142 reviewed 2026-12-01 11:15:24 +00:00
aslan2142 left a comment
No description provided.
The `runtime/test/replay_cpu_bench.cpp` fix is still relevant on `main` and merges cleanly, but this carried-over PR remains a draft with all CI checks cancelled. Please confirm ownership, rebase/update onto current `main`, run CI to green, and mark ready for review. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 12:05:53 +00:00

Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review.

(AI-assisted triage.)

Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review. *(AI-assisted triage.)*
aslan2142 commented 2026-12-01 16:20:35 +00:00

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.
Sign in to join this conversation.
No description provided.