[PR #2220] runtime: record the order of first pipeline requests (LEONIDA_PIPELINE_ORDER_LOG=1, RT-PIPELINE-PREWARM-ORDER phase 1) #2224

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2220
Author: @MoonEyes
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: feat/pipeline-order-recorder


📝 Commits (7)

  • 40e94eb runtime: pipeline order recorder and replay request hook (RT-PIPELINE-PREWARM-ORDER, phase 1)
  • 7a4d1f7 runtime: record the order of first pipeline requests behind LEONIDA_PIPELINE_ORDER_LOG=1
  • cdbbb39 Merge remote-tracking branch 'origin/main' into feat/pipeline-order-recorder
  • dcdcade runtime: address review of the pipeline order recorder
  • 0babd17 Merge remote-tracking branch 'origin/main' into feat/pipeline-order-recorder
  • 4263427 Record the library entry of each compute pipeline in the order log
  • 6b281fc Merge remote-tracking branch 'origin/main' into feat/pipeline-order-recorder

📊 Changes

9 files changed (+1759 additions, -0 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+24 -0)
📝 runtime/CMakeLists.txt (+13 -0)
📝 runtime/README.md (+1 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+123 -0)
➕ runtime/src/pipeline_order.h (+653 -0)
📝 runtime/src/vulkan_replay.h (+9 -0)
➕ runtime/test/pipeline_order_test.cpp (+714 -0)
➕ runtime/test/replay_pipeline_order_hook_test.cpp (+213 -0)
📝 tests/test_docs_env_vars.py (+9 -0)

📄 Description

Claimed in the coordination issue as: RT-PIPELINE-PREWARM-ORDER, phase 1 (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7176167646)

What and why

Nothing builds graphics or mesh pipelines ahead of their first draw today, and the compute warm-up orders by module size, not by what the title asks for first. Before proposing any reordering, this measures how much lead time the title gives: a passive recorder, off unless LEONIDA_PIPELINE_ORDER_LOG=1.

  • runtime/src/pipeline_order.h: for each pipeline and variant (the unbound-slot mask of a graphics pipeline, 0 for compute) that a dispatch or draw names for the first time in a run, one line is appended to pipeline_order.log beside pipeline_cache.session.bin: the PSO's description key (a SHA-256, with a mesh pipeline's MS folded in), the variant, creation and first-use times in milliseconds since the process started, the build time, and whether the handle was ready already. Each line ends with an FNV-1a checksum; a cut or damaged line is skipped on read. At most 8192 lines per run; a file past 8 MiB is set aside as pipeline_order.log.prev.
  • runtime/src/vulkan_replay.h: ComputePipeline and GraphicsPipeline get a requested callback, called where a submission is prepared, also for a handle that exists already. Null when the variable is unset, so a run without it carries no hook.
  • The hook never blocks and allocates nothing: "first" is decided by one compare-and-swap in a table made at start. The only lock is a non-blocking try_lock in the readiness callbacks, on the first request of a pipeline and of a variant. A thread of its own appends every 250 ms.
  • At exit (after the exit cache write, or at the device's release) one line gives the counts: [rt] pipeline-order: requested N, already ready M, median lead X ms -> <path of the file>.
  • Record only: no build, order or cache file changes. The file holds hashes and numbers, no shader or game data, and stays local.
  • Documented in runtime/README.md and docs/d3d12_vulkan.md; tests/test_docs_env_vars.py checks that the variable is read and named in both.

Queuing builds in the recorded order is a follow-up that I will only propose if the recorded numbers show a gain.

Tested

Windows 11, MSVC (Visual Studio 2022), RelWithDebInfo, at 0babd17b8: main merged in at a73a57e13 (which has #2098), full clean rebuild. No game files needed.

  • pipeline_order_test (new, CPU only, 21 test functions): passes.
  • replay_pipeline_order_hook_test (new, no GPU): passes.
  • ctest -R "compile|pipeline" -j 4: 22 tests selected, 22 passed, 0 failed.
  • d3d12_compile_teardown_test passes with the variable unset (no pipeline-order line printed) and with LEONIDA_PIPELINE_ORDER_LOG=1 (the counts line is printed after the exit cache write).
  • python -I tests/test_docs_env_vars.py: 5 tests, OK.
  • python -I scripts/check_no_game_data.py on the 9 changed files: clean. git diff --check: clean.
  • Before the last merge of main (at dcdcade32), three mutants of pipeline_order.h were replayed on a throwaway copy, and each is caught: no newline written after a cut file (test_cut_file_then_new_session), the writer skipping an unpublished slot (test_flush_stops_at_unpublished), the session version not checked (test_unknown_session_version). pipeline_order.h and its test did not change in that merge.

The merge of main had three conflicts: the LEONIDA_ASYNC_PIPELINES paragraph of docs/d3d12_vulkan.md (main's text kept, this paragraph after it), the test list in runtime/CMakeLists.txt (both kept) and build_compute in runtime/shims/d3d12_vulkan_device.cpp, where the recorder now gets its build time from #2098's ComputeBuild::ms.

Not tested: the full ctest suite; a GCC or Clang build (CI will tell); the order of the log close relative to the exit cache write has no automated test (seen in the test's output only); a compute build with #2098's compile helper (LEONIDA_COMPILE_HELPER=1, off by default): the build time recorded is that of the call that returned the pipeline, so it leaves out the helper's own compile, whether the build was answered as deferred and finished later or waited for. For every compute build the time is now ComputeBuild::ms, which also counts the wait for the compile gate and the journal write, not only the driver's create. No recorded numbers from the title are quoted here.

GPUs tested: NVIDIA GeForce RTX 4060, driver 610.88, Windows 11

AI-assisted: yes (Claude Code, Claude Fable 5.2, wrote the code and tests; a second agent replayed mutants and reviewed it)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • 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, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code


🔄 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/2220 **Author:** [@MoonEyes](https://github.com/MoonEyes) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/pipeline-order-recorder` --- ### 📝 Commits (7) - [`40e94eb`](https://github.com/ubiquitarianism/leonida/commit/40e94ebb20782fdb942c1ca377740c070e74cee6) runtime: pipeline order recorder and replay request hook (RT-PIPELINE-PREWARM-ORDER, phase 1) - [`7a4d1f7`](https://github.com/ubiquitarianism/leonida/commit/7a4d1f772104f015d84057f8274942bea4fce1b9) runtime: record the order of first pipeline requests behind LEONIDA_PIPELINE_ORDER_LOG=1 - [`cdbbb39`](https://github.com/ubiquitarianism/leonida/commit/cdbbb39554eb5743bf285aab07862920ec5c938f) Merge remote-tracking branch 'origin/main' into feat/pipeline-order-recorder - [`dcdcade`](https://github.com/ubiquitarianism/leonida/commit/dcdcade3260bbbae9d4458df75e2785cb401f63c) runtime: address review of the pipeline order recorder - [`0babd17`](https://github.com/ubiquitarianism/leonida/commit/0babd17b8a7c020f2cc27d3b1250326f996f9c07) Merge remote-tracking branch 'origin/main' into feat/pipeline-order-recorder - [`4263427`](https://github.com/ubiquitarianism/leonida/commit/4263427b463337307aba8f73afb70e6c563b659d) Record the library entry of each compute pipeline in the order log - [`6b281fc`](https://github.com/ubiquitarianism/leonida/commit/6b281fc25d69b9058a412253a5ccd9dc7335c886) Merge remote-tracking branch 'origin/main' into feat/pipeline-order-recorder ### 📊 Changes **9 files changed** (+1759 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+24 -0) 📝 `runtime/CMakeLists.txt` (+13 -0) 📝 `runtime/README.md` (+1 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+123 -0) ➕ `runtime/src/pipeline_order.h` (+653 -0) 📝 `runtime/src/vulkan_replay.h` (+9 -0) ➕ `runtime/test/pipeline_order_test.cpp` (+714 -0) ➕ `runtime/test/replay_pipeline_order_hook_test.cpp` (+213 -0) 📝 `tests/test_docs_env_vars.py` (+9 -0) </details> ### 📄 Description Claimed in the coordination issue as: RT-PIPELINE-PREWARM-ORDER, phase 1 (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7176167646) ### What and why Nothing builds graphics or mesh pipelines ahead of their first draw today, and the compute warm-up orders by module size, not by what the title asks for first. Before proposing any reordering, this measures how much lead time the title gives: a passive recorder, off unless `LEONIDA_PIPELINE_ORDER_LOG=1`. - `runtime/src/pipeline_order.h`: for each pipeline and variant (the unbound-slot mask of a graphics pipeline, 0 for compute) that a dispatch or draw names for the first time in a run, one line is appended to `pipeline_order.log` beside `pipeline_cache.session.bin`: the PSO's description key (a SHA-256, with a mesh pipeline's MS folded in), the variant, creation and first-use times in milliseconds since the process started, the build time, and whether the handle was ready already. Each line ends with an FNV-1a checksum; a cut or damaged line is skipped on read. At most 8192 lines per run; a file past 8 MiB is set aside as `pipeline_order.log.prev`. - `runtime/src/vulkan_replay.h`: `ComputePipeline` and `GraphicsPipeline` get a `requested` callback, called where a submission is prepared, also for a handle that exists already. Null when the variable is unset, so a run without it carries no hook. - The hook never blocks and allocates nothing: "first" is decided by one compare-and-swap in a table made at start. The only lock is a non-blocking `try_lock` in the readiness callbacks, on the first request of a pipeline and of a variant. A thread of its own appends every 250 ms. - At exit (after the exit cache write, or at the device's release) one line gives the counts: `[rt] pipeline-order: requested N, already ready M, median lead X ms -> <path of the file>`. - Record only: no build, order or cache file changes. The file holds hashes and numbers, no shader or game data, and stays local. - Documented in `runtime/README.md` and `docs/d3d12_vulkan.md`; `tests/test_docs_env_vars.py` checks that the variable is read and named in both. Queuing builds in the recorded order is a follow-up that I will only propose if the recorded numbers show a gain. ### Tested Windows 11, MSVC (Visual Studio 2022), RelWithDebInfo, at `0babd17b8`: `main` merged in at `a73a57e13` (which has #2098), full clean rebuild. No game files needed. - `pipeline_order_test` (new, CPU only, 21 test functions): passes. - `replay_pipeline_order_hook_test` (new, no GPU): passes. - `ctest -R "compile|pipeline" -j 4`: 22 tests selected, 22 passed, 0 failed. - `d3d12_compile_teardown_test` passes with the variable unset (no `pipeline-order` line printed) and with `LEONIDA_PIPELINE_ORDER_LOG=1` (the counts line is printed after the exit cache write). - `python -I tests/test_docs_env_vars.py`: 5 tests, OK. - `python -I scripts/check_no_game_data.py` on the 9 changed files: clean. `git diff --check`: clean. - Before the last merge of `main` (at `dcdcade32`), three mutants of `pipeline_order.h` were replayed on a throwaway copy, and each is caught: no newline written after a cut file (`test_cut_file_then_new_session`), the writer skipping an unpublished slot (`test_flush_stops_at_unpublished`), the session version not checked (`test_unknown_session_version`). `pipeline_order.h` and its test did not change in that merge. The merge of `main` had three conflicts: the `LEONIDA_ASYNC_PIPELINES` paragraph of `docs/d3d12_vulkan.md` (main's text kept, this paragraph after it), the test list in `runtime/CMakeLists.txt` (both kept) and `build_compute` in `runtime/shims/d3d12_vulkan_device.cpp`, where the recorder now gets its build time from #2098's `ComputeBuild::ms`. Not tested: the full ctest suite; a GCC or Clang build (CI will tell); the order of the log close relative to the exit cache write has no automated test (seen in the test's output only); a compute build with #2098's compile helper (`LEONIDA_COMPILE_HELPER=1`, off by default): the build time recorded is that of the call that returned the pipeline, so it leaves out the helper's own compile, whether the build was answered as deferred and finished later or waited for. For every compute build the time is now `ComputeBuild::ms`, which also counts the wait for the compile gate and the journal write, not only the driver's create. No recorded numbers from the title are quoted here. GPUs tested: NVIDIA GeForce RTX 4060, driver 610.88, Windows 11 AI-assisted: yes (Claude Code, Claude Fable 5.2, wrote the code and tests; a second agent replayed mutants and reviewed it) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [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`, with how it was confirmed. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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#2224
No description provided.