d3d12: LEONIDA_ASYNC_MIN_BYTES_GRAPHICS, a separate async threshold for graphics (RT-ASYNC-MIN-BYTES-GRAPHICS) #2467

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

@⁠OreoFR on GitHub · 2026-11-27 13:18 UTC · original
OreoFR:rt-async-min-bytes-graphics → main · +268 −26 · 10 files · 1 commits · open

Claimed in the coordination issue as: RT-ASYNC-MIN-BYTES-GRAPHICS

Depends on: nothing (#2440 merged).

What and why

#2440 added LEONIDA_ASYNC_MIN_BYTES=<n>. With LEONIDA_ASYNC_PIPELINES=1, a pipeline under n bytes of SPIR-V is built where it is needed. Graphics and compute use the same threshold.

@⁠MoonEyes's thread dumps (RTX 4060, 1 MiB threshold) show what goes wrong with a shared threshold. The draw thread builds lazy graphics variants under 1 MiB in place (PipelineState::variant -> build -> vkCreateGraphicsPipelines). Each takes 2.5-11 s, and they run back to back, so no present comes for about 100 s. The image only needs the small compute pipelines (lighting, post) to be built in place. A graphics pipeline that isn't built yet only costs a skipped draw.

This adds LEONIDA_ASYNC_MIN_BYTES_GRAPHICS=<n>:

  • Graphics and mesh pipelines use this threshold, measured by the total size of their stages, as #2440 measures them. Compute keeps LEONIDA_ASYNC_MIN_BYTES.
  • 0: every graphics pipeline is asynchronous, as LEONIDA_ASYNC_PIPELINES=1 was before #2440.
  • Unset or empty: graphics take LEONIDA_ASYNC_MIN_BYTES, so nothing changes. Text that isn't a decimal number is ignored the same way, with a log line.
  • Startup log: one line states both thresholds and whether the graphics one was set.
  • Code:
    • runtime/src/async_pipeline_size.h (pure stdlib): MinBytes, parse_thresholds and a per-kind asynchronous.
    • shims/d3d12_pipeline_compile.h: reads both variables once.
    • d3d12_vulkan_device.cpp: graphics_.async_build and pipeline_.async_build say which kind they are.
    • Nothing else in the async paths changes.

Tested

  • async_pipeline_size_test: parsing of the graphics variable:
    • unset, empty, 0, set without the general one, above compute's;
    • text that isn't a number falls back to compute's threshold;
    • the general one invalid.
      It also checks the per-kind decision. With graphics unset, both kinds decide exactly as #2440 for every tested size and threshold. With 1 MiB + graphics 0, every graphics pipeline is async, while compute under 1 MiB waits and compute at 1 MiB or more is async.
  • d3d12_pipeline_workers_test --async-graphics-zero (new ctest d3d12_pipeline_workers_async_graphics_zero). Setup: LEONIDA_ASYNC_PIPELINES=1, LEONIDA_ASYNC_MIN_BYTES=1 GiB, LEONIDA_ASYNC_MIN_BYTES_GRAPHICS=0, every compile-worker job held by the job probe. The pipelines are 48 graphics (16 through a variant, 3 of them large) and 16 compute.
    • The first submission runs all 16 dispatches in place and writes every buffer word.
    • No graphics create reaches the driver, and the image stays as cleared.
    • Once the worker is let go, a later submission draws every cell, and compute is not built again.
    • It fails without the change. With the graphics decision forced back to the compute threshold, the image check fails.
  • --async-graphics-unset (ctest d3d12_pipeline_workers_async_graphics_unset): same setup with the graphics variable removed. The first submission draws everything in place and the worker gets no job, as on main.
  • Async GPU tests, variables unset and set. d3d12_compile_teardown, d3d12_compile_pool, d3d12_m4_compute, d3d12_m4_compute_async_small_waits, d3d12_m4_compute --check-async-journal and d3d12_pipeline_workers, run with:
    • both variables unset;
    • GRAPHICS=0;
    • MIN_BYTES=2097152 + GRAPHICS=0;
    • GRAPHICS=1073741824;
    • GRAPHICS=abc.
      teardown, m4_compute and the journal check ran with and without LEONIDA_ASYNC_PIPELINES=1. All pass on the rebased branch.
    • Before the rebase, plain d3d12_m4_compute with LEONIDA_ASYNC_PIPELINES=1 and no threshold failed 7 of 8 runs. #2440's build shows the same rate (all-async dispatch skip, see below).
  • Full ctest (RelWithDebInfo, Ninja, MSVC, -j 4, before the rebase onto #2233): 492 of 495 pass.
    • xbox_present and d3d12_set_descriptor_heaps also fail on main on this machine (noted in #2440).
    • dxgi_waitable_latency passed 3 of 3 when rerun on its own (a timing test under -j 4).
  • Static checks: clang-tidy (VS LLVM, -std=c++20 -Wall -Wextra, Vulkan SDK include) on async_pipeline_size_test.cpp and d3d12_pipeline_workers_test.cpp: no diagnostics in user code. The 13 tests/test_docs_*.py pass. scripts/check_no_game_data.py is clean on every changed file.
  • Retail: not yet. An A/B of graphics 0 vs unset on the same build follows in #1608.
AGENT-MSG | 2026-11-27 13:18 UTC | OreoFR | AI-assisted: Claude Code (Claude Opus 5.5)
BASE:     f5c3ea2e0 + this PR + none
MACHINE:  RTX 4070 Laptop 8 GB, laptop | 621.40 | Windows 11 | 40 GB
RECIPE:   none (no game run) + DEVIATIONS: none
ASK:      none
RETURNED: unit + GPU tests above; graphics=0 with compute over its threshold: 16/16 dispatches in place, 0 graphics creates, draws after the worker is let go
RUNS:     0, read-only (no game run)
EVIDENCE: GPU test results MEASURED (n=1 per setting, n=3 for --async-graphics-zero after rebase); all-async m4_compute flake MEASURED (n=8, this branch and #2440's build, 1/8 pass each); "unset = unchanged" READ IN CODE (async_pipeline_size.h parse_thresholds) and MEASURED by the per-kind test; draw-thread stall cause from @MoonEyes's dumps, ASSUMED here until the retail A/B

GPUs tested: NVIDIA GeForce RTX 4070 Laptop 8 GB (profile M, laptop), 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 13:18 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2467) `OreoFR:rt-async-min-bytes-graphics` → `main` · +268 −26 · 10 files · 1 commits · open Claimed in the coordination issue as: [RT-ASYNC-MIN-BYTES-GRAPHICS](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) Depends on: nothing (#2440 merged). ### What and why #2440 added `LEONIDA_ASYNC_MIN_BYTES=<n>`. With `LEONIDA_ASYNC_PIPELINES=1`, a pipeline under n bytes of SPIR-V is built where it is needed. Graphics and compute use the same threshold. @⁠MoonEyes's thread dumps (RTX 4060, 1 MiB threshold) show what goes wrong with a shared threshold. The draw thread builds lazy graphics variants under 1 MiB in place (`PipelineState::variant` -> `build` -> `vkCreateGraphicsPipelines`). Each takes 2.5-11 s, and they run back to back, so no present comes for about 100 s. The image only needs the small compute pipelines (lighting, post) to be built in place. A graphics pipeline that isn't built yet only costs a skipped draw. This adds **`LEONIDA_ASYNC_MIN_BYTES_GRAPHICS=<n>`**: - **Graphics and mesh pipelines** use this threshold, measured by the total size of their stages, as #2440 measures them. **Compute** keeps `LEONIDA_ASYNC_MIN_BYTES`. - **`0`:** every graphics pipeline is asynchronous, as `LEONIDA_ASYNC_PIPELINES=1` was before #2440. - **Unset or empty:** graphics take `LEONIDA_ASYNC_MIN_BYTES`, so nothing changes. Text that isn't a decimal number is ignored the same way, with a log line. - **Startup log:** one line states both thresholds and whether the graphics one was set. - **Code:** - `runtime/src/async_pipeline_size.h` (pure stdlib): `MinBytes`, `parse_thresholds` and a per-kind `asynchronous`. - `shims/d3d12_pipeline_compile.h`: reads both variables once. - `d3d12_vulkan_device.cpp`: `graphics_.async_build` and `pipeline_.async_build` say which kind they are. - Nothing else in the async paths changes. ### Tested - **`async_pipeline_size_test`:** parsing of the graphics variable: - unset, empty, `0`, set without the general one, above compute's; - text that isn't a number falls back to compute's threshold; - the general one invalid. It also checks the per-kind decision. With graphics unset, both kinds decide exactly as #2440 for every tested size and threshold. With `1 MiB` + graphics `0`, every graphics pipeline is async, while compute under 1 MiB waits and compute at 1 MiB or more is async. - **`d3d12_pipeline_workers_test --async-graphics-zero`** (new ctest `d3d12_pipeline_workers_async_graphics_zero`). Setup: `LEONIDA_ASYNC_PIPELINES=1`, `LEONIDA_ASYNC_MIN_BYTES=1 GiB`, `LEONIDA_ASYNC_MIN_BYTES_GRAPHICS=0`, every compile-worker job held by the job probe. The pipelines are 48 graphics (16 through a variant, 3 of them large) and 16 compute. - The first submission runs all 16 dispatches in place and writes every buffer word. - No graphics create reaches the driver, and the image stays as cleared. - Once the worker is let go, a later submission draws every cell, and compute is not built again. - **It fails without the change.** With the graphics decision forced back to the compute threshold, the image check fails. - **`--async-graphics-unset`** (ctest `d3d12_pipeline_workers_async_graphics_unset`): same setup with the graphics variable removed. The first submission draws everything in place and the worker gets no job, as on `main`. - **Async GPU tests, variables unset and set.** `d3d12_compile_teardown`, `d3d12_compile_pool`, `d3d12_m4_compute`, `d3d12_m4_compute_async_small_waits`, `d3d12_m4_compute --check-async-journal` and `d3d12_pipeline_workers`, run with: - both variables unset; - `GRAPHICS=0`; - `MIN_BYTES=2097152` + `GRAPHICS=0`; - `GRAPHICS=1073741824`; - `GRAPHICS=abc`. `teardown`, `m4_compute` and the journal check ran with and without `LEONIDA_ASYNC_PIPELINES=1`. All pass on the rebased branch. - Before the rebase, plain `d3d12_m4_compute` with `LEONIDA_ASYNC_PIPELINES=1` and no threshold failed 7 of 8 runs. #2440's build shows the same rate (all-async dispatch skip, see below). - **Full `ctest`** (RelWithDebInfo, Ninja, MSVC, `-j 4`, before the rebase onto #2233): 492 of 495 pass. - `xbox_present` and `d3d12_set_descriptor_heaps` also fail on `main` on this machine (noted in #2440). - `dxgi_waitable_latency` passed 3 of 3 when rerun on its own (a timing test under `-j 4`). - **Static checks:** clang-tidy (VS LLVM, `-std=c++20 -Wall -Wextra`, Vulkan SDK include) on `async_pipeline_size_test.cpp` and `d3d12_pipeline_workers_test.cpp`: no diagnostics in user code. The 13 `tests/test_docs_*.py` pass. `scripts/check_no_game_data.py` is clean on every changed file. - **Retail:** not yet. An A/B of graphics `0` vs unset on the same build follows in #1608. ``` AGENT-MSG | 2026-11-27 13:18 UTC | OreoFR | AI-assisted: Claude Code (Claude Opus 5.5) BASE: f5c3ea2e0 + this PR + none MACHINE: RTX 4070 Laptop 8 GB, laptop | 621.40 | Windows 11 | 40 GB RECIPE: none (no game run) + DEVIATIONS: none ASK: none RETURNED: unit + GPU tests above; graphics=0 with compute over its threshold: 16/16 dispatches in place, 0 graphics creates, draws after the worker is let go RUNS: 0, read-only (no game run) EVIDENCE: GPU test results MEASURED (n=1 per setting, n=3 for --async-graphics-zero after rebase); all-async m4_compute flake MEASURED (n=8, this branch and #2440's build, 1/8 pass each); "unset = unchanged" READ IN CODE (async_pipeline_size.h parse_thresholds) and MEASURED by the per-kind test; draw-thread stall cause from @MoonEyes's dumps, ASSUMED here until the retail A/B ``` GPUs tested: NVIDIA GeForce RTX 4070 Laptop 8 GB (profile M, laptop), 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, graphics and mesh pipelines (all their stages) now take
LEONIDA_ASYNC_MIN_BYTES_GRAPHICS when it is set, and LEONIDA_ASYNC_MIN_BYTES otherwise, so
nothing changes while it is unset. Compute keeps LEONIDA_ASYNC_MIN_BYTES. 0 makes every graphics
pipeline asynchronous. One startup line states both thresholds; text that is not a number is
ignored with a log line.

Thread dumps from a retail run showed the draw thread building lazy graphics variants under the
1 MiB threshold in place, 2.5-11 s each, back to back, with no present for about 100 s. A skipped
draw costs one draw. The image needs the small lighting and post compute programs, and those
are still built in place.

Tests: async_pipeline_size_test covers the per-kind decision and the unset fallback;
d3d12_pipeline_workers_test --async-graphics-zero / --async-graphics-unset (new ctests) hold
the compile worker with compute over its threshold.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 13:19:52 +00:00
This pull request has changes conflicting with the target branch.
  • runtime/test/d3d12_pipeline_workers_test.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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