[PR #2260] runtime: prewarm graphics pipelines in recorded order on the compile pool (RT-PIPELINE-PREWARM-ORDER phase 2) #2265

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

📋 Pull Request Information

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

Base: main ← Head: claude/pipeline-prewarm-order


📝 Commits (10+)

  • 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
  • a83f385 d3d12: a pool of compile workers for the pipeline compiler (RT-ASYNC-COMPILE-POOL)
  • 2d56b68 d3d12: the checkpoint's second look also sees a running demanded build
  • 6e9c33e Merge remote-tracking branch 'upstream/pr2220' into claude/pipeline-prewarm-order
  • d864cab runtime: prewarm graphics pipelines in the order an earlier run asked for them (RT-PIPELINE-PREWARM-ORDER phase 2)
  • 6f2b52e d3d12: prewarm console streams kept for their first bind (on-demand)

📊 Changes

14 files changed (+3005 additions, -50 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+54 -0)
📝 runtime/CMakeLists.txt (+33 -0)
📝 runtime/README.md (+7 -1)
📝 runtime/shims/d3d12_pipeline_compile.h (+174 -40)
📝 runtime/shims/d3d12_vulkan_device.cpp (+203 -5)
➕ runtime/src/pipeline_order.h (+595 -0)
➕ runtime/src/pipeline_prewarm.h (+171 -0)
📝 runtime/src/vulkan_replay.h (+9 -0)
➕ runtime/test/d3d12_compile_pool_test.cpp (+499 -0)
📝 runtime/test/d3d12_pipeline_workers_test.cpp (+127 -4)
➕ runtime/test/pipeline_order_test.cpp (+606 -0)
➕ runtime/test/pipeline_prewarm_test.cpp (+305 -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 2 (in-game) (claim); split agreed with MoonEyes on #2220

Depends on: #2233, #2220

This branch has both merged in. Until they land, the diff against main shows their changes too; this pull request's own changes are d864cab47 and 6f2b52e56.

What and why

Our boots reach the first world frame, but the world then draws a frame or so a minute while graphics pipelines build at their first draw. #2220 records which pipelines the title asks for first (LEONIDA_PIPELINE_ORDER_LOG=1). This reads that record at the next boot and builds those pipelines, mostly graphics, ahead of their first draw, in the order the earlier run asked for them, on #2233's compile workers.

  • runtime/src/pipeline_prewarm.h (new, no device): the plan. It reads an order log with #2220's reader (pipeline_order::parse) and takes, from the runs recorded on this GPU (vendor and device id), the one with the most records (the newest on a tie). Graphics and mesh records are kept in recorded order, each (key, variant) once. Compute records are left to the compute warm-up and to MoonEyes' --order-file for gta6rt --precompile-pipelines (the split on #2220).
  • Budget: records are taken in order until their recorded build times add up to LEONIDA_PIPELINE_PREWARM_BUDGET_MS (default 300000; a record with no build time counts 1000 ms), and at most LEONIDA_PIPELINE_PREWARM_MAX_ENTRIES (default 4096).
  • Never ahead of a demanded build: when the title creates a PSO whose description key is in the plan, each recorded variant is queued with queue_build as a warm-up at priority 1 + rank. With #2233's rules that is after every demanded build, one warm-up at a time, and none while a demanded build runs. That is MoonEyes' compile-gate finding in #1608 (07:32): a create in flight holds every submission at the gate, so a warm-up must not start while the title waits for a build. Prewarms go ahead of the compute warm-up's size order and before the cache checkpoint. A variant 0 already built at create is skipped.
  • Ignored with a message: a missing or unreadable file, a file with no readable record, or one recorded on another GPU gives no plan and one [rt] pipeline-prewarm: line. A damaged line is skipped (#2220's checksums), and so are line types a v1 reader does not know: the E lines MoonEyes is adding for the precompiler are dropped before parsing, so they are not counted as damage. On success the line gives the counts (variants, pipelines, recorded build time, how many were over the budget, compute records left out).
  • Switch: LEONIDA_PIPELINE_PREWARM_ORDER=<file>, or 1 for pipeline_order.log beside the session cache. The plan is read when the device starts, before #2220's recorder opens the same file, so both variables can be on in the same run (it then records the prewarmed run as a new session).
  • The order key (order_key, #2220) is now also computed when only the prewarm is on.
  • A console stream kept for its first bind (LEONIDA_PIPELINE_COMPILE=on-demand) whose pipeline is in the plan has its parse queued as its first prewarm job, so it gets the same lead as other PSOs (ecox982745's review: 0 of 8 before the first bind otherwise). A bind that comes first waits for that parse, which it would have done itself.
  • Teardown: a queued prewarm holds no reference, as any queued build: a PSO released first drops it (last_release), and the device's cancel waits for a running one.

Limits:

  • A prewarm already running when the title submits still holds the compile gate, as any warm-up does. The pool keeps that to one at a time and starts none while a demanded build runs, but it does not cut a running one short. LEONIDA_COMPILE_GATE=0 removes the wait.
  • A pipeline is only prewarmed once the title has created its PSO: the log names pipelines by the key of their description, not by SPIR-V, so there is nothing to build before that.
  • A root signature the runtime does not know is hashed by address (see #2220), so such a pipeline's key can change between runs and it is then not found.

Tested

  • New CPU test pipeline_prewarm (no device). The plan cases are:

    • order kept, with repeats and compute records left out;
    • the largest run on this GPU chosen, and another GPU's run not read;
    • budget and entry limit respected;
    • a missing file, garbled text, a damaged line, another GPU's log and an empty file each give no plan (or skip the line) with a message;
    • E lines skipped without counting as damage.

    On the compile workers, with jobs that wait at gates:

    • prewarms queued out of order (as the title creates the PSOs) build in recorded order, after the demanded build that was running;
    • a demanded build submitted while a prewarm runs starts at once on the free worker, and the remaining prewarms wait until it is done.
      It passed 9 runs of 9. Each plan rule was broken by hand in turn (8 mutants: prewarms at priority 0, no budget, no entry limit, E lines kept, the first run instead of the largest, any GPU's run, compute records kept, repeats kept), and the test failed for every one.
  • With #2233 and #2220 merged, these pass: pipeline_prewarm, pipeline_order, replay_pipeline_order_hook, d3d12_compile_pool, d3d12_compile_teardown (pool and one worker), d3d12_big_compute (all 7 settings), d3d12_m4_compute, d3d12_pipeline_workers and d3d12_pipeline_workers_eager: 16 of 16. A boot was running on this machine, so the full suite was not run.

  • Device test prewarm_from_recorded_order in d3d12_pipeline_workers_test (RTX 4070 SUPER): a first device records the order, then console-stream PSOs (slot 86) with an eight-entry plan build those eight before any command is recorded, with the ordinary stream and with on-demand, and nothing without a plan; the image matches and each pipeline is built once. The on-demand case fails without the on-demand fix (0 of 8).

  • python -I tests/test_docs_env_vars.py, tests/test_ctest_registration.py, scripts/check_no_game_data.py on the changed files: pass.

Not tested here: a real boot. Our boot session will measure it on the game (time to the first world frame and frames per minute after it, with and without the prewarm) and post the numbers.

GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 621.01, Windows 11

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly. (Stacked on #2233 and #2220, both merged in; main merges cleanly.)
  • 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/2260 **Author:** [@Tyrannys](https://github.com/Tyrannys) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `claude/pipeline-prewarm-order` --- ### 📝 Commits (10+) - [`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 - [`a83f385`](https://github.com/ubiquitarianism/leonida/commit/a83f38508f535a2de95a15f91071139de2c26fee) d3d12: a pool of compile workers for the pipeline compiler (RT-ASYNC-COMPILE-POOL) - [`2d56b68`](https://github.com/ubiquitarianism/leonida/commit/2d56b685ac69d0447cb5bb560e132ad354d8779d) d3d12: the checkpoint's second look also sees a running demanded build - [`6e9c33e`](https://github.com/ubiquitarianism/leonida/commit/6e9c33e079dcd9154851db31a7b4672dd1b2b001) Merge remote-tracking branch 'upstream/pr2220' into claude/pipeline-prewarm-order - [`d864cab`](https://github.com/ubiquitarianism/leonida/commit/d864cab47e3d0e5a6f9dabab4c71a8feae106a72) runtime: prewarm graphics pipelines in the order an earlier run asked for them (RT-PIPELINE-PREWARM-ORDER phase 2) - [`6f2b52e`](https://github.com/ubiquitarianism/leonida/commit/6f2b52e5635c070f3f9d0d12710b3ff2e90f71ee) d3d12: prewarm console streams kept for their first bind (on-demand) ### 📊 Changes **14 files changed** (+3005 additions, -50 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+54 -0) 📝 `runtime/CMakeLists.txt` (+33 -0) 📝 `runtime/README.md` (+7 -1) 📝 `runtime/shims/d3d12_pipeline_compile.h` (+174 -40) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+203 -5) ➕ `runtime/src/pipeline_order.h` (+595 -0) ➕ `runtime/src/pipeline_prewarm.h` (+171 -0) 📝 `runtime/src/vulkan_replay.h` (+9 -0) ➕ `runtime/test/d3d12_compile_pool_test.cpp` (+499 -0) 📝 `runtime/test/d3d12_pipeline_workers_test.cpp` (+127 -4) ➕ `runtime/test/pipeline_order_test.cpp` (+606 -0) ➕ `runtime/test/pipeline_prewarm_test.cpp` (+305 -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 2 (in-game) ([claim](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7189801811)); split agreed with MoonEyes on #2220 Depends on: #2233, #2220 This branch has both merged in. Until they land, the diff against `main` shows their changes too; this pull request's own changes are d864cab47 and 6f2b52e56. ### What and why Our boots reach the first world frame, but the world then draws a frame or so a minute while graphics pipelines build at their first draw. #2220 records which pipelines the title asks for first (`LEONIDA_PIPELINE_ORDER_LOG=1`). This reads that record at the next boot and builds those pipelines, mostly graphics, ahead of their first draw, in the order the earlier run asked for them, on #2233's compile workers. - `runtime/src/pipeline_prewarm.h` (new, no device): the plan. It reads an order log with #2220's reader (`pipeline_order::parse`) and takes, from the runs recorded on this GPU (vendor and device id), the one with the most records (the newest on a tie). Graphics and mesh records are kept in recorded order, each (key, variant) once. Compute records are left to the compute warm-up and to MoonEyes' `--order-file` for `gta6rt --precompile-pipelines` (the split on #2220). - **Budget:** records are taken in order until their recorded build times add up to `LEONIDA_PIPELINE_PREWARM_BUDGET_MS` (default 300000; a record with no build time counts 1000 ms), and at most `LEONIDA_PIPELINE_PREWARM_MAX_ENTRIES` (default 4096). - **Never ahead of a demanded build:** when the title creates a PSO whose description key is in the plan, each recorded variant is queued with `queue_build` as a warm-up at priority `1 + rank`. With #2233's rules that is after every demanded build, one warm-up at a time, and none while a demanded build runs. That is MoonEyes' compile-gate finding in #1608 (07:32): a create in flight holds every submission at the gate, so a warm-up must not start while the title waits for a build. Prewarms go ahead of the compute warm-up's size order and before the cache checkpoint. A variant 0 already built at create is skipped. - **Ignored with a message:** a missing or unreadable file, a file with no readable record, or one recorded on another GPU gives no plan and one `[rt] pipeline-prewarm:` line. A damaged line is skipped (#2220's checksums), and so are line types a v1 reader does not know: the `E` lines MoonEyes is adding for the precompiler are dropped before parsing, so they are not counted as damage. On success the line gives the counts (variants, pipelines, recorded build time, how many were over the budget, compute records left out). - **Switch:** `LEONIDA_PIPELINE_PREWARM_ORDER=<file>`, or `1` for `pipeline_order.log` beside the session cache. The plan is read when the device starts, before #2220's recorder opens the same file, so both variables can be on in the same run (it then records the prewarmed run as a new session). - The order key (`order_key`, #2220) is now also computed when only the prewarm is on. - A console stream kept for its first bind (`LEONIDA_PIPELINE_COMPILE=on-demand`) whose pipeline is in the plan has its parse queued as its first prewarm job, so it gets the same lead as other PSOs (ecox982745's review: 0 of 8 before the first bind otherwise). A bind that comes first waits for that parse, which it would have done itself. - Teardown: a queued prewarm holds no reference, as any queued build: a PSO released first drops it (`last_release`), and the device's cancel waits for a running one. Limits: - A prewarm already running when the title submits still holds the compile gate, as any warm-up does. The pool keeps that to one at a time and starts none while a demanded build runs, but it does not cut a running one short. `LEONIDA_COMPILE_GATE=0` removes the wait. - A pipeline is only prewarmed once the title has created its PSO: the log names pipelines by the key of their description, not by SPIR-V, so there is nothing to build before that. - A root signature the runtime does not know is hashed by address (see #2220), so such a pipeline's key can change between runs and it is then not found. ### Tested - New CPU test `pipeline_prewarm` (no device). The plan cases are: - order kept, with repeats and compute records left out; - the largest run on this GPU chosen, and another GPU's run not read; - budget and entry limit respected; - a missing file, garbled text, a damaged line, another GPU's log and an empty file each give no plan (or skip the line) with a message; - `E` lines skipped without counting as damage. On the compile workers, with jobs that wait at gates: - prewarms queued out of order (as the title creates the PSOs) build in recorded order, after the demanded build that was running; - a demanded build submitted while a prewarm runs starts at once on the free worker, and the remaining prewarms wait until it is done. It passed 9 runs of 9. Each plan rule was broken by hand in turn (8 mutants: prewarms at priority 0, no budget, no entry limit, `E` lines kept, the first run instead of the largest, any GPU's run, compute records kept, repeats kept), and the test failed for every one. - With #2233 and #2220 merged, these pass: `pipeline_prewarm`, `pipeline_order`, `replay_pipeline_order_hook`, `d3d12_compile_pool`, `d3d12_compile_teardown` (pool and one worker), `d3d12_big_compute` (all 7 settings), `d3d12_m4_compute`, `d3d12_pipeline_workers` and `d3d12_pipeline_workers_eager`: 16 of 16. A boot was running on this machine, so the full suite was not run. - Device test `prewarm_from_recorded_order` in `d3d12_pipeline_workers_test` (RTX 4070 SUPER): a first device records the order, then console-stream PSOs (slot 86) with an eight-entry plan build those eight before any command is recorded, with the ordinary stream and with on-demand, and nothing without a plan; the image matches and each pipeline is built once. The on-demand case fails without the on-demand fix (0 of 8). - `python -I tests/test_docs_env_vars.py`, `tests/test_ctest_registration.py`, `scripts/check_no_game_data.py` on the changed files: pass. Not tested here: a real boot. Our boot session will measure it on the game (time to the first world frame and frames per minute after it, with and without the prewarm) and post the numbers. GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 621.01, Windows 11 AI-assisted: yes (Claude Code) ### Checklist - [ ] Based on current `main` and merges cleanly. (Stacked on #2233 and #2220, both merged in; `main` merges cleanly.) - [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#2265
No description provided.