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

Manually merged
github merged 1 commit from github-bot/gh-2440 into gh-pr/2440/base 2026-11-27 10:53:02 +00:00 AGit
Owner

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

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 · merged 2026-11-27 10:47 UTC 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).
Author
Owner

@⁠timbot103 on GitHub · 2026-11-27 10:41 UTC · original

Independently checked head 76099a22f on Windows 11 Pro 26200, MSVC 2022 (19.44.35230.0, RelWithDebInfo, Ninja), Vulkan SDK 1.4.363.0, WSL llvm-mc 21.1.8, no game files.

Local build & dual-GPU verification:

  • Clean build of async_pipeline_size_test and d3d12_m4_compute_test with zero new warnings in the PR-modified files.
  • async_pipeline_size_test: PASS (async_pipeline_size_test: ok).
  • d3d12_m4_compute_test (both default and --async-small-waits) with LEONIDA_VK_VALIDATION=1:
    • NVIDIA GeForce RTX 5080 (driver 616.64, subgroup 32..32): default 1924/1924 words matched (error 0); --async-small-waits 1924/1924 words matched (error 0), 0 validation errors.
    • AMD Radeon(TM) Graphics (driver 25.10.30.02, subgroup 32..64): default 1924/1924 words matched (error 0); --async-small-waits 1924/1924 words matched (error 0), 0 validation errors.

Code review notes:

  • parse_min_bytes (runtime/src/async_pipeline_size.h) handles exact UINT64_MAX overflow guarding and cleanly rejects signs, whitespace, suffixes, hex, and non-ASCII bytes; function-local static init is thread-safe, graphics sums all stages' post-patch SPIR-V sizes, and every former global async check now reads the per-PSO async_build flag.
  • One optional test-strength suggestion: d3d12_m4_compute_async_small_waits verifies worker_jobs == 0 when the threshold is above both modules, without a positive control proving the held job probe intercepts a queued job when a module is at/above the threshold. Setting LEONIDA_ASYNC_MIN_BYTES between the two modules' sizes (or adding a --async-held-control case without the threshold expecting >= 1 held job) would exercise both sides of the gate.

Overall looks sound and clean. AI-assisted.

**@⁠timbot103** on GitHub · 2026-11-27 10:41 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2440#issuecomment-7216181065) Independently checked head `76099a22f` on Windows 11 Pro 26200, MSVC 2022 (`19.44.35230.0`, RelWithDebInfo, Ninja), Vulkan SDK `1.4.363.0`, WSL `llvm-mc 21.1.8`, no game files. **Local build & dual-GPU verification:** - Clean build of `async_pipeline_size_test` and `d3d12_m4_compute_test` with zero new warnings in the PR-modified files. - `async_pipeline_size_test`: **PASS** (`async_pipeline_size_test: ok`). - `d3d12_m4_compute_test` (both default and `--async-small-waits`) with `LEONIDA_VK_VALIDATION=1`: - **NVIDIA GeForce RTX 5080** (driver `616.64`, subgroup `32..32`): default **1924/1924 words matched (error 0)**; `--async-small-waits` **1924/1924 words matched (error 0)**, 0 validation errors. - **AMD Radeon(TM) Graphics** (driver `25.10.30.02`, subgroup `32..64`): default **1924/1924 words matched (error 0)**; `--async-small-waits` **1924/1924 words matched (error 0)**, 0 validation errors. **Code review notes:** - `parse_min_bytes` (`runtime/src/async_pipeline_size.h`) handles exact `UINT64_MAX` overflow guarding and cleanly rejects signs, whitespace, suffixes, hex, and non-ASCII bytes; function-local static init is thread-safe, graphics sums all stages' post-patch SPIR-V sizes, and every former global async check now reads the per-PSO `async_build` flag. - **One optional test-strength suggestion:** `d3d12_m4_compute_async_small_waits` verifies `worker_jobs == 0` when the threshold is above both modules, without a positive control proving the held job probe intercepts a queued job when a module is at/above the threshold. Setting `LEONIDA_ASYNC_MIN_BYTES` between the two modules' sizes (or adding a `--async-held-control` case without the threshold expecting `>= 1` held job) would exercise both sides of the gate. Overall looks sound and clean. AI-assisted.
github-bot changed target branch from main to gh-pr/2440/base 2026-11-27 10:53:01 +00:00
github manually merged commit 76099a22f6 into gh-pr/2440/base 2026-11-27 10:53:02 +00:00
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-27 10:47 UTC · original

Merging.

  • Why: LEONIDA_ASYNC_MIN_BYTES lets small compute pipelines build on the calling thread instead of going to the compile worker. Nothing changes while the variable is unset.
  • The new test does its job: d3d12_m4_compute_async_small_waits fails on main (one build reached the compile worker) and passes with this change.
  • Tested on main 2859d0c9b + #2418, #2440, #2432 and #2439, integrated RDNA2 GPU (RADV, Mesa 26.3.1):
    • Windows suite under Wine: 425 pass, 25 fail. The only changes against the stored baseline are xdxr_build_check (a timeout under load) and xmem_no_write_watch, both flaky here.
    • Linux runtime ctest: 115 of 116, the same timeout.
  • Not tested: no game run from this head.

Thanks @⁠OreoFR.

AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)

**@⁠aslan2142** on GitHub · 2026-11-27 10:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2440#issuecomment-7216317870) Merging. - **Why:** `LEONIDA_ASYNC_MIN_BYTES` lets small compute pipelines build on the calling thread instead of going to the compile worker. Nothing changes while the variable is unset. - **The new test does its job:** `d3d12_m4_compute_async_small_waits` fails on `main` (one build reached the compile worker) and passes with this change. - **Tested on `main` `2859d0c9b` + #2418, #2440, #2432 and #2439**, integrated RDNA2 GPU (RADV, Mesa 26.3.1): - Windows suite under Wine: 425 pass, 25 fail. The only changes against the stored baseline are `xdxr_build_check` (a timeout under load) and `xmem_no_write_watch`, both flaky here. - Linux runtime `ctest`: 115 of 116, the same timeout. - **Not tested:** no game run from this head. Thanks @⁠OreoFR. AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)
This discussion has been locked. Commenting is limited to contributors.
No description provided.