Skip to content

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

Merged
aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
OreoFR:rt-async-min-bytes-graphics
Nov 27, 2026
Merged

aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
OreoFR:rt-async-min-bytes-graphics

Conversation

@OreoFR

@OreoFR OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

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 d3d12: LEONIDA_ASYNC_MIN_BYTES, only large pipelines asynchronous (RT-ASYNC-LARGE-ONLY) #2440 measures them. Compute keeps LEONIDA_ASYNC_MIN_BYTES.
  • 0: every graphics pipeline is asynchronous, as LEONIDA_ASYNC_PIPELINES=1 was before d3d12: LEONIDA_ASYNC_MIN_BYTES, only large pipelines asynchronous (RT-ASYNC-LARGE-ONLY) #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 d3d12: LEONIDA_ASYNC_MIN_BYTES, only large pipelines asynchronous (RT-ASYNC-LARGE-ONLY) #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. d3d12: LEONIDA_ASYNC_MIN_BYTES, only large pipelines asynchronous (RT-ASYNC-LARGE-ONLY) #2440's build shows the same rate (all-async dispatch skip, see below).
  • Full ctest (RelWithDebInfo, Ninja, MSVC, -j 4, before the rebase onto d3d12: a pool of compile workers for the pipeline compiler (RT-ASYNC-COMPILE-POOL) #2233): 492 of 495 pass.
  • 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 Coordinating who works on what (continued from #14) #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

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 27, 2026
…or graphics (RT-ASYNC-MIN-BYTES-GRAPHICS)

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 <noreply@anthropic.com>
@OreoFR
OreoFR force-pushed the rt-async-min-bytes-graphics branch from 1c18cd2 to d42c373 Compare November 27, 2026 13:43
@OreoFR

OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Updated onto main ec91d695c (rebased; only conflict was d3d12_pipeline_workers_test.cpp with #2260's prewarm test, both kept). Async/pipeline ctests pass with the variables unset and set; the docs tests pass. AI-assisted (Claude Code, Claude Opus 5.5).

@OreoFR

OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

RUN gfx0 | 2026-11-27 | OreoFR | AI-assisted: Claude Code (Claude Opus 5.5)
BASE: main ec91d69 + #1851 #2020 #2166 + this PR + a local window-retire commit (#2465) and a diagnostic commit | shaders: pack with #2447
MACHINE: RTX 4070 Laptop 8 GB, laptop (profile M) | NVIDIA 621.40 | Windows 11 | 40 GB
RECIPE: documented + DEVIATIONS: ASYNC_PIPELINES=1 ASYNC_MIN_BYTES=1048576 ASYNC_MIN_BYTES_GRAPHICS=0 VALUE_WAIT_TIMEOUT_MS=30000 MAP_READBACK=1 HOST_IMAGE_COPY=0 DEVICE_TYPE=6 PIPELINE_PREWARM_ORDER=1 | precompile: no
TARGET: synchronous graphics compiles at draw; display stop | PREDICTED: 0 sync draw compiles; display holds past ~255 s
MEASURED: sync draw compiles 0 (control, same tree without the variable: 270, none over 1 s); all went to the draw worker (1,316). Display stop at ~212 s (control ~255 s). Releaser over 1 s inside a gate Signal 8 times in both.
END: time limit (600 s), 0 device lost
CACHES: warm | RUN 1 of 1
INSTRUMENTS: thread stacks at 230/280/330/380 s, compile trace
VERDICT: prediction held for the compiles, missed for the stop: on this machine the stop is not caused by synchronous graphics compiles (single GPU submissions take 4-19 s at the stop instead). The PR does what it says; the case it targets (a releaser compiling for minutes, reported by nicoco23) did not occur here.

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and tested at d42c37335 (merged cleanly onto main ec91d695c).

Everything looks clean:

  • Every graphics and mesh pipeline creation path (regular, stream PSO, and derived PSO) routes through PipelineState::create_graphics() --> async_replay_compile(true, spirv_bytes), and compute routes through async_replay_compile(false, spirv_bytes).
  • parse_thresholds() and async_min_bytes() handle unset, empty, 0, UINT64_MAX, overflow, malformed values, and over-length env strings consistently, preserving exact prior behaviour when LEONIDA_ASYNC_MIN_BYTES_GRAPHICS is unset.
  • Note on the CI check failure: the failed Python tests on that run were unrelated Windows runner temp-path failures (test_bink_names.py, test_world_names.py, etc.), not caused by this PR.

Verified locally on Windows 11 (MSVC 19.44.35230.0, Ninja Release, NVIDIA GeForce RTX 5070, driver 610.88, Vulkan 1.4.341; note VK_LAYER_KHRONOS_validation is not installed locally so Vulkan validation layers did not run):

  • async_pipeline_size (CPU): passed
  • d3d12_pipeline_workers, d3d12_pipeline_workers_async_graphics_zero, d3d12_pipeline_workers_async_graphics_unset (GPU): 3/3 passed
  • scripts/check_no_game_data.py and git diff --check: clean

No findings.

AI-assisted.

@OreoFR

OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @lixonik. A game-run regression check with the variable unset (main ec91d69 vs + this PR, same recipe and caches) is queued on the RTX 4070 Laptop and will be posted here. AI-assisted (Claude Code, Claude Opus 5.5).

@djrolfes

Copy link
Copy Markdown
Contributor

Independent Linux/Wine + NVIDIA RTX 3070 Ti check at head d42c37335 (merged cleanly onto origin/main ec91d695c in a local integration stack alongside #2463, #2470, #2469, #2461, #2126, #2091, and two local V# patches).

  • Environment: Linux 7.2.15, wine-11.22, clang-cl + xwin cross-build, NVIDIA GeForce RTX 3070 Ti 8 GB, driver 620.73.04, Ryzen 7 5800X, 32 GB RAM.
  • Offline CTest (zero game files): all passed on RTX 3070 Ti under Wine:
    • async_pipeline_size (4.49 s)
    • d3d12_pipeline_workers (9.11 s), d3d12_pipeline_workers_eager (6.47 s)
    • d3d12_pipeline_workers_async_graphics_zero (6.16 s)
    • d3d12_pipeline_workers_async_graphics_unset (6.07 s)
    • d3d12_m4_compute (6.16 s), d3d12_m4_compute_async_small_waits (6.06 s)
    • d3d12_compile_pool (5.80 s)
  • Retail run (1,800.4 s, time limit, warm caches, no skip list / no stubs):
    • Flags: LEONIDA_ASYNC_PIPELINES=1, LEONIDA_ASYNC_MIN_BYTES=2097152, LEONIDA_ASYNC_MIN_BYTES_GRAPHICS=0, LEONIDA_COMPUTE_WARMUP=0, LEONIDA_ARENA_MB=1024, LEONIDA_GEOMETRY_MB=2048, LEONIDA_VALUE_WAIT_TIMEOUT_MS=30000, LEONIDA_MAP_READBACK=1, LEONIDA_DEVICE_TYPE=6, LEONIDA_TITLE_WATCHDOG=0 (+ local KICK RVAs).
    • Stability: 0 VK_ERROR_DEVICE_LOST, 0 device-stall, 0 gpu-stall, 0 exceptions, peak VRAM 7,767 / 8,192 MiB, 3,104 PresentX, GLCache grew +109.1 MiB to 1,069.9 MiB, 276 compute pipelines journaled (+137).
    • What #2467 did: startup line confirmed compute < 2097152 B synchronous and graphics < 0 (LEONIDA_ASYNC_MIN_BYTES_GRAPHICS) asynchronous; 0 synchronous graphics compiles occurred (draw-worker handled graphics builds).
    • Separate origin/main bottleneck observed (not caused by #2467): PresentX stopped advancing around t=570 s (loading fade-out) because queue_build (d3d12_vulkan_device.cpp:12975-12977, 13429) passes Work::demand (instead of Work::speculative) to LargeModuleGate for dispatch-worker (>= 2 MiB) and draw-worker builds. In this run, 79 of 164 synchronous < 2 MiB compute builds unblocked immediately right when a >= 2 MiB async dispatch-worker build finished (34 builds, up to 112.1 s each), stalling synchronous submissions behind background RT compiles. Filing/claiming that separately in #1608.

AI-assisted.

@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 27, 2026
@OreoFR

OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Game-run regression A/B requested for this PR. The two arms share the build recipe, shader pack, settings and caches; only this PR differs, with LEONIDA_ASYNC_MIN_BYTES_GRAPHICS unset. The numbers were recomputed from the raw run logs by a second agent on the same machine. AI-assisted (Claude Code, Claude Opus 5.5).

RUN regA | 2026-11-27 | OreoFR | AI-assisted: Claude Code (Claude Opus 5.5)
BASE:        main ec91d695c | shaders: main translation + #2447 (one-lane) pack
MACHINE:     RTX 4070 Laptop 8 GB, laptop (profile M) | NVIDIA 621.40 | Windows 11 | 40 GB
RECIPE:      documented + DEVIATIONS: ASYNC_PIPELINES=1 ASYNC_MIN_BYTES=1048576 VALUE_WAIT_TIMEOUT_MS=30000 MAP_READBACK=1 DEVICE_TYPE=6 PIPELINE_PREWARM_ORDER=1 DEVICE_FAULT=1 | precompile: partial journal
OS/DRIVER:   TdrDelay 60
TARGET:      regression check | PREDICTED: world reached, no loss, same as main
MEASURED:    world (first indirect draw) between 223 and 229 s | 600 s | 8,990 submissions | last >=1 fps window at 223 s
END:         time limit | 0 device lost, 0 exceptions | gpu-stall lines 10, device-stall 2
CACHES:      warm | RUN 1 of 1
INSTRUMENTS: device fault checkpoints, thread stacks at 230/280/330/380 s
VERDICT:     held

RUN reg2467 | same, BASE: main ec91d695c + this PR (d42c37335), LEONIDA_ASYNC_MIN_BYTES_GRAPHICS unset
MEASURED:    world between 233 and 240 s | 600 s | 10,016 submissions | last >=1 fps window at 240 s
END:         time limit | 0 device lost, 0 exceptions | gpu-stall lines 11, device-stall 4
             startup line confirms graphics threshold = compute threshold (1048576) when the variable is unset
VERDICT:     no regression seen (n=1 each; the display stop right after world entry is the known stop, present in both arms)

@aslan2142
aslan2142 merged commit c0201a8 into ProjectLeonida:main Nov 27, 2026
7 of 12 checks passed
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