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

Closed
Andretuta wants to merge 1 commit from upstream-pr/58 into main
Andretuta commented 2026-11-24 02:09:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T02:09:57Z.


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.)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5464741282 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/58). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T02:09:57Z. --- > 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T18:01:31Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7287207455 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/58#issuecomment-7287207455). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T18:01:31Z. --- 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 commented 2026-12-01 11:15:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:15:24Z.

Review: COMMENTED


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.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130127978 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/58#pullrequestreview-6130127978). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:15:24Z. **Review:** COMMENTED --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:05:53Z.


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.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7310645831 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/58#issuecomment-7310645831). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:05:53Z. --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:20:35Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317444228 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/58#issuecomment-7317444228). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:20:35Z. --- 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.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!58
No description provided.