d3d12: LEONIDA_ASYNC_MIN_BYTES, only large pipelines asynchronous (RT-ASYNC-LARGE-ONLY) #2440

Open
github-bot wants to merge 1 commit from github-bot/gh-2440 into main AGit
Owner

@⁠OreoFR on GitHub · 2026-11-27 08:05 UTC · original
OreoFR:rt-async-large-only → main · +224 −4 · 9 files · 1 commits · open

Claimed in the coordination issue as: RT-ASYNC-LARGE-ONLY

What and why

LEONIDA_ASYNC_PIPELINES is all or nothing (runtime/shims/d3d12_pipeline_compile.h). On an RTX 4070 Laptop (NVIDIA 621.40), retail, wave64-emulated pack:

  • =1: the world phase is reached but the screen stays black. Every draw or dispatch whose pipeline is not built yet is skipped, including the small lighting and post programs. The Linux/Proton NVIDIA report in docs/running.md says the same.
  • =0: a submission waits for each of the ~700 ray-tracing compute programs (2-26 MB of SPIR-V, 2-3 minutes each in the driver). We measured 17 builds in 30 minutes, so the world start would take hours.

This adds LEONIDA_ASYNC_MIN_BYTES=<n>, used with LEONIDA_ASYNC_PIPELINES=1:

  • A pipeline under n bytes of SPIR-V (compute: its module; graphics: all its stages, the same size the large-compile rules use) takes the async-off path. It gets no record-time request, PipelineCompiles builds it at prepare, and a compile-helper build waits for its file.
  • A pipeline of n bytes or more is queued and its draws or dispatches are skipped until it is ready, as now.
  • The choice is made once per pipeline at create, in async_build. The decision lives in runtime/src/async_pipeline_size.h, which is pure stdlib.
  • Unset, 0, or text that isn't a decimal number (logged): every pipeline is asynchronous. The code path is the same as today.

What changed in d3d12_vulkan_device.cpp:

  • graphics_.async_build and pipeline_.async_build take the size into account.
  • Three places that asked the global switch now ask the PSO's own flag: the compile-helper "don't wait" decision in build_compute, the worker's publication in queue_build, and request_early.
  • With the variable unset, each flag equals the global switch for every PSO that reaches those paths, so nothing changes.

Graphics follows the same threshold, measured by the total size of all its stages. The NVIDIA report's black stretch was graphics pipelines of 1-2.6 MB compiling one at a time, so a threshold above that leaves them blocking as with =0, and one below makes them asynchronous.

Not changed: a large asynchronous build still goes through the compile gate and LargeModuleGate, so a mid-size build that a submission waits for can queue behind it there. The docs paragraph says so.

Tested

  • async_pipeline_size_test (new): parsing (unset, empty, 0, max, overflow, suffixes, signs, spaces, hex) and the decision (off, on with no threshold, below/at/above 2 MiB, 1 byte, 2^64-1).
  • d3d12_m4_compute --async-small-waits (new ctest d3d12_m4_compute_async_small_waits): async on, threshold over both modules, warm-up off, and every compile-worker job held by a job probe until the results are read. Both dispatches must run in place (all words match) and no build may reach the worker.
    • It fails without the threshold: with LEONIDA_ASYNC_MIN_BYTES=0 forced into the test, a build went to the compile worker.
  • The existing async GPU tests, each with LEONIDA_ASYNC_MIN_BYTES unset, 1, 2097152 and 1073741824: d3d12_compile_teardown, d3d12_m4_compute, d3d12_m4_compute --async-small-waits and d3d12_m4_compute --check-async-journal (with LEONIDA_ASYNC_PIPELINES=1). All pass. =2MiB logs that it is ignored.
  • Full ctest (RelWithDebInfo, Ninja, MSVC): 490 of 492 pass. xbox_present and d3d12_set_descriptor_heaps also fail on plain main d1dff7949 on this machine (both rebuilt from main and rerun).
  • The 13 tests/test_docs_*.py pass. scripts/check_no_game_data.py is clean on every changed file.
  • Retail: not yet. A build is handed to a tester with LEONIDA_ASYNC_PIPELINES=1 LEONIDA_ASYNC_MIN_BYTES=2097152; the result will be posted in #1608.

GPUs tested: NVIDIA GeForce RTX 4070 Laptop 8 GB, driver 621.40, Windows 11.

AI-assisted: yes (Claude Code, Claude Opus 5.5)

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: runtime only)

🤖 Generated with Claude Code

**@⁠OreoFR** on GitHub · 2026-11-27 08:05 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2440) `OreoFR:rt-async-large-only` → `main` · +224 −4 · 9 files · 1 commits · open Claimed in the coordination issue as: [RT-ASYNC-LARGE-ONLY](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why `LEONIDA_ASYNC_PIPELINES` is all or nothing (`runtime/shims/d3d12_pipeline_compile.h`). On an RTX 4070 Laptop (NVIDIA 621.40), retail, wave64-emulated pack: - **`=1`:** the world phase is reached but the screen stays black. Every draw or dispatch whose pipeline is not built yet is skipped, including the small lighting and post programs. The Linux/Proton NVIDIA report in `docs/running.md` says the same. - **`=0`:** a submission waits for each of the ~700 ray-tracing compute programs (2-26 MB of SPIR-V, 2-3 minutes each in the driver). We measured 17 builds in 30 minutes, so the world start would take hours. This adds **`LEONIDA_ASYNC_MIN_BYTES=<n>`**, used with `LEONIDA_ASYNC_PIPELINES=1`: - A pipeline under n bytes of SPIR-V (compute: its module; graphics: all its stages, the same size the large-compile rules use) takes the async-off path. It gets no record-time request, `PipelineCompiles` builds it at prepare, and a compile-helper build waits for its file. - A pipeline of n bytes or more is queued and its draws or dispatches are skipped until it is ready, as now. - The choice is made once per pipeline at create, in `async_build`. The decision lives in `runtime/src/async_pipeline_size.h`, which is pure stdlib. - **Unset, `0`, or text that isn't a decimal number** (logged): every pipeline is asynchronous. The code path is the same as today. What changed in `d3d12_vulkan_device.cpp`: - `graphics_.async_build` and `pipeline_.async_build` take the size into account. - Three places that asked the global switch now ask the PSO's own flag: the compile-helper "don't wait" decision in `build_compute`, the worker's publication in `queue_build`, and `request_early`. - With the variable unset, each flag equals the global switch for every PSO that reaches those paths, so nothing changes. Graphics follows the same threshold, measured by the total size of all its stages. The NVIDIA report's black stretch was graphics pipelines of 1-2.6 MB compiling one at a time, so a threshold above that leaves them blocking as with `=0`, and one below makes them asynchronous. Not changed: a large asynchronous build still goes through the compile gate and `LargeModuleGate`, so a mid-size build that a submission waits for can queue behind it there. The docs paragraph says so. ### Tested - `async_pipeline_size_test` (new): parsing (unset, empty, 0, max, overflow, suffixes, signs, spaces, hex) and the decision (off, on with no threshold, below/at/above 2 MiB, 1 byte, 2^64-1). - `d3d12_m4_compute --async-small-waits` (new ctest `d3d12_m4_compute_async_small_waits`): async on, threshold over both modules, warm-up off, and every compile-worker job held by a job probe until the results are read. Both dispatches must run in place (all words match) and no build may reach the worker. - **It fails without the threshold:** with `LEONIDA_ASYNC_MIN_BYTES=0` forced into the test, a build went to the compile worker. - The existing async GPU tests, each with `LEONIDA_ASYNC_MIN_BYTES` unset, `1`, `2097152` and `1073741824`: `d3d12_compile_teardown`, `d3d12_m4_compute`, `d3d12_m4_compute --async-small-waits` and `d3d12_m4_compute --check-async-journal` (with `LEONIDA_ASYNC_PIPELINES=1`). All pass. `=2MiB` logs that it is ignored. - Full `ctest` (RelWithDebInfo, Ninja, MSVC): 490 of 492 pass. `xbox_present` and `d3d12_set_descriptor_heaps` also fail on plain `main` `d1dff7949` on this machine (both rebuilt from `main` and rerun). - The 13 `tests/test_docs_*.py` pass. `scripts/check_no_game_data.py` is clean on every changed file. - Retail: not yet. A build is handed to a tester with `LEONIDA_ASYNC_PIPELINES=1 LEONIDA_ASYNC_MIN_BYTES=2097152`; the result will be posted in #1608. GPUs tested: NVIDIA GeForce RTX 4070 Laptop 8 GB, driver 621.40, Windows 11. AI-assisted: yes (Claude Code, Claude Opus 5.5) ### 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: runtime only) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
With LEONIDA_ASYNC_PIPELINES=1 every pipeline not built yet has its draws
and dispatches skipped, the small lighting and post programs too, so the
world phase stays black while anything compiles; with it off a submission
waits minutes for each large ray-tracing compute program.

LEONIDA_ASYNC_MIN_BYTES=<n> (with async on): a pipeline under n bytes of
SPIR-V (compute: its module; graphics: all its stages) takes the path of
async off: no record-time request, PipelineCompiles builds it at prepare,
and a compile-helper build waits for its file. One of n bytes or more stays
asynchronous. Decided once per pipeline at create (async_build). Unset, 0
or not a number: every pipeline asynchronous, as before.

Tests: async_pipeline_size_test (parsing and decision);
d3d12_m4_compute --async-small-waits (both pipelines under the threshold,
compile worker held: no job reaches it and every word matches).
Docs: runtime/README.md row, docs/d3d12_vulkan.md, docs/running.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 08:06:45 +00:00
Author
Owner

@⁠OreoFR on GitHub · 2026-11-27 08:23 UTC · original

First retail result with this PR (RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11). Build: main d1dff7949 + #2412, #2418, #2260 (#2220, #2233), #2020, #2166, #1851, #2432 and this PR. Shaders: the current pack with DadaCap's one-lane-fold library. Settings: LEONIDA_ASYNC_PIPELINES=1 + LEONIDA_ASYNC_MIN_BYTES=2097152, LEONIDA_VALUE_WAIT_TIMEOUT_MS=30000, LEONIDA_MAP_READBACK=1, LEONIDA_HOST_IMAGE_COPY=0, LEONIDA_DEVICE_TYPE=6, LEONIDA_SERIAL_BIG_COMPILES=0, the recorded prewarm, no Aftermath, default title windows, 24 GB page file.

  • The world phase started about 4.5 min in, and the opening scene renders lit and in colour at about 940 s (seen on the desktop, not posted). It was washed out at first, at ~640 s.
  • With every pipeline async, the same build drew the world black.
  • With async off, the title waited on the 2-6 MB ray-tracing compute builds (17 in 30 min) and drew nothing.
  • Frame rate in the world: 0.1-0.2 frames/s. 17 builds over 2 MiB went async at 2-2.6 min each. No device loss to 940 s.

MEASURED (n=1). AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠OreoFR** on GitHub · 2026-11-27 08:23 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2440#issuecomment-7213489883) First retail result with this PR (RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11). Build: `main` d1dff7949 + #2412, #2418, #2260 (#2220, #2233), #2020, #2166, #1851, #2432 and this PR. Shaders: the current pack with DadaCap's one-lane-fold library. Settings: `LEONIDA_ASYNC_PIPELINES=1` + `LEONIDA_ASYNC_MIN_BYTES=2097152`, `LEONIDA_VALUE_WAIT_TIMEOUT_MS=30000`, `LEONIDA_MAP_READBACK=1`, `LEONIDA_HOST_IMAGE_COPY=0`, `LEONIDA_DEVICE_TYPE=6`, `LEONIDA_SERIAL_BIG_COMPILES=0`, the recorded prewarm, no Aftermath, default title windows, 24 GB page file. - The world phase started about 4.5 min in, and **the opening scene renders lit and in colour** at about 940 s (seen on the desktop, not posted). It was washed out at first, at ~640 s. - With every pipeline async, the same build drew the world black. - With async off, the title waited on the 2-6 MB ray-tracing compute builds (17 in 30 min) and drew nothing. - Frame rate in the world: 0.1-0.2 frames/s. 17 builds over 2 MiB went async at 2-2.6 min each. No device loss to 940 s. `MEASURED (n=1)`. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠OreoFR on GitHub · 2026-11-27 08:48 UTC · original

Repeat, same build and recipe: the opening scene renders again, from about 9 min in, and stays up to the end of the 20-minute run, with no device loss. Peak private bytes were 52 GB. MEASURED (n=2). AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠OreoFR** on GitHub · 2026-11-27 08:48 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2440#issuecomment-7213944158) Repeat, same build and recipe: the opening scene renders again, from about 9 min in, and stays up to the end of the 20-minute run, with no device loss. Peak private bytes were 52 GB. `MEASURED (n=2)`. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠OreoFR on GitHub · 2026-11-27 09:09 UTC · original

Threshold comparison, same build and recipe, 20 min each, world drawn in both:

LEONIDA_ASYNC_MIN_BYTES longest submission stall (replay) peak private bytes frames/s after 600 s
2097152 (2 MiB) 58.8 s 52.3 GB 0.086 mean, 0.20 max
1048576 (1 MiB) 17.6 s 39.1 GB 0.091 mean, 0.20 max

On this 8 GB laptop, 1 MiB looks better: shorter stalls when a mid-size pipeline is built in place, and less host memory. The frame rate is the same, because that comes from per-submission costs (textures 150-270 ms, heaps), not from compiles. MEASURED (n=1 each). AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠OreoFR** on GitHub · 2026-11-27 09:09 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2440#issuecomment-7214354975) Threshold comparison, same build and recipe, 20 min each, world drawn in both: | `LEONIDA_ASYNC_MIN_BYTES` | longest submission stall (replay) | peak private bytes | frames/s after 600 s | |---|---|---|---| | 2097152 (2 MiB) | 58.8 s | 52.3 GB | 0.086 mean, 0.20 max | | 1048576 (1 MiB) | **17.6 s** | **39.1 GB** | 0.091 mean, 0.20 max | On this 8 GB laptop, 1 MiB looks better: shorter stalls when a mid-size pipeline is built in place, and less host memory. The frame rate is the same, because that comes from per-submission costs (`textures` 150-270 ms, `heaps`), not from compiles. `MEASURED (n=1 each)`. AI-assisted (Claude Code, Claude Opus 5.5).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2440/head:github-bot/gh-2440'
git switch 'github-bot/gh-2440'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2440'
git switch 'github-bot/gh-2440'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2440'
git switch 'github-bot/gh-2440'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2440'
git switch 'main'
git merge --squash 'github-bot/gh-2440'
git switch 'main'
git merge --ff-only 'github-bot/gh-2440'
git switch 'main'
git merge 'github-bot/gh-2440'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.