Skip to content

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

Merged
aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
OreoFR:rt-async-large-only
Nov 27, 2026
Merged

aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
OreoFR:rt-async-large-only

Conversation

@OreoFR

@OreoFR OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

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 Coordinating who works on what (continued from #14) #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

…-ASYNC-LARGE-ONLY)

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 <noreply@anthropic.com>
@OreoFR

OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

First retail result with this PR (RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11). Build: main d1dff79 + #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

OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

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

OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

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

@timbot103

Copy link
Copy Markdown
Contributor

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.

@aslan2142

Copy link
Copy Markdown
Collaborator

Merging.

Thanks @OreoFR.

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

@Tyrannys

Copy link
Copy Markdown
Contributor

Profile M data point for LEONIDA_ASYNC_PIPELINES=1 + LEONIDA_ASYNC_MIN_BYTES=2097152 (RTX 4070 SUPER 12 GB desktop, NVIDIA 621.01, Windows 11, 64 GB), in OreoFR's world recipe from #1608. Counts only. AI-assisted (Claude Code).

With this setting, the library precompiled (gta6rt --precompile-pipelines --big-threads 1 --skip-listed --filter library/: 1,674 programs, 0 failed; the largest, 13.7 MB of SPIR-V, took 1,356 s alone) and the 1,009 ray-hit programs on the skip list, four runs on the same stack got: c3-G1b and c3-G1b-ctl stayed on the story load (a stale local DirectStorage predictor profile, see #2502), c3-G1c reached the opening sequence, and c3-G1d (below) reached gameplay control. No draw or dispatch was lost to a pending build in a way that kept the screen black: the remaining problem is a near-white picture in gameplay, not a black one.

RUN c3-G1d | 2026-11-27 | Tyrannys | AI-assisted: Claude Code
BASE:        2859d0c9b + #2233 #2275 #2418 #2440 #2020 #2166 #2432 #2224 #2179 #2228 #1851 #1882 #2260 #2267 #1592 (+ local test fix) + #443 + #1705 + #2012 | shaders: library re-translated with w64-one-lane-fold; DirectStorage predictor profile regenerated after 2a491668a
MACHINE:     RTX 4070 SUPER 12 GB, desktop | NVIDIA 621.01 | Windows 11 | 64 GB
RECIPE:      OreoFR's world recipe (#1608, 2026-11-27 08:23) + DEVIATIONS: COMPILE_GATE=0 PIPELINE_PREWARM_ORDER=1 SHADOW_ALIAS_MS=1000 SKIP_COMPUTE=<1,009 ray-hit programs> RT_AS=off DEVICE_FAULT=1 TITLE_HUD=1 MEM_PROBE=60 FRAME_PACING=1 PRESENT_NO_TEAR=1 KEYBOARD_PAD=1 CAPTURE_LIMIT=80 | precompile: yes, library programs except the skip list
OS/DRIVER:   TdrDelay=60
TARGET:      textures phase ms per submission after 900 s; how far | PREDICTED: textures at least halved vs c3-G1c (474.6); < 1 frame/s; autosave prompt or gameplay
MEASURED:    full 1,804 s, PresentX 3,191 ok / 0 failed, 11.0 M D3D12 calls, 0 decompression errors, 0 device stalls, 0 presses besides the script (235)
             world-start pipeline burst ~270 s; letterboxed near-white cutscene from ~600 s; by ~1,200 s the game's own control hint
             ("move around / move the camera") over a screen that is almost all white (mean RGB 252-254) to the end
             after 900 s (means): textures 24.0 ms per submission (c3-G1c 474.6), heaps 12.8, shadows 19.7; 7.7 submissions/s; 0.30 frames/s
             process dedicated / shared (MiB, means): burst+0..180 s 10,777 / 1,446; +180..240 s 10,695 / 1,696; +240 s..end 10,759 / 2,345
             (shared max 7,107 after a +5,120 MiB rise at ~1,664 s); HUD VRAM 10.0-13.6 GB used vs a 10.7 GB budget
             3D engine mean: 8.4% (0..300 s), 9.8%, 59.9%, 29.8%; compute 0.0%, copy 0.0-1.0%
             skip list: 250 of the 1,009 skipped programs were requested, each first by ~600 s, none first requested during gameplay;
             their dispatches are dropped. Loop-guard hits: not observable (the translator's guard exits silently, no counter)
END:         time limit
CACHES:      warm (journal + session/heavy caches after G1b, G1b-ctl, G1c) | RUN 1 of 1
INSTRUMENTS: TITLE_HUD, MEM_PROBE=60, DEVICE_FAULT=1, Windows GPU performance counters every 10 s, gputaskman --json every 30 s
VERDICT:     prediction held (textures down ~95%; 0.30 frames/s; gameplay control reached, picture white)

@Tyrannys

Copy link
Copy Markdown
Contributor

CORRECTION to my comment above: "No draw or dispatch was lost to a pending build in a way that kept the screen black" is not measured: I did not count draws or dispatches skipped while their pipelines were pending. MEASURED is only that the screen was not black in gameplay (near-white, mean RGB 252-254 in the captures). Nothing else in that comment changes.

AI-assisted (Claude Code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants