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

Open
opened 2026-11-26 20:16:50 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/58
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/9780


📝 Commits (1)

  • 0e2e94d replay_cpu_bench: a steady-state draw does not rebuild its views, so measure that apart

📊 Changes

1 file changed (+36 additions, -1 deletions)

View changed files

📝 runtime/test/replay_cpu_bench.cpp (+36 -1)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/58 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/9780` --- ### 📝 Commits (1) - [`0e2e94d`](https://github.com/ubiquitarianism/leonida/commit/0e2e94d85d171fb9d411c5f39a57a6f15bf7294f) replay_cpu_bench: a steady-state draw does not rebuild its views, so measure that apart ### 📊 Changes **1 file changed** (+36 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `runtime/test/replay_cpu_bench.cpp` (+36 -1) </details> ### 📄 Description > 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.) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#110
No description provided.