d3d12: LEONIDA_ASYNC_MIN_BYTES_GRAPHICS, a separate async threshold for graphics (RT-ASYNC-MIN-BYTES-GRAPHICS) #2467
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2467"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-27T13:18:58Z.
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>. WithLEONIDA_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>:LEONIDA_ASYNC_MIN_BYTES.0: every graphics pipeline is asynchronous, asLEONIDA_ASYNC_PIPELINES=1was before #2440.LEONIDA_ASYNC_MIN_BYTES, so nothing changes. Text that isn't a decimal number is ignored the same way, with a log line.runtime/src/async_pipeline_size.h(pure stdlib):MinBytes,parse_thresholdsand a per-kindasynchronous.shims/d3d12_pipeline_compile.h: reads both variables once.d3d12_vulkan_device.cpp:graphics_.async_buildandpipeline_.async_buildsay which kind they are.Tested
async_pipeline_size_test: parsing of the graphics variable:0, set without the general one, above compute's;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+ graphics0, 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 ctestd3d12_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.--async-graphics-unset(ctestd3d12_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 onmain.d3d12_compile_teardown,d3d12_compile_pool,d3d12_m4_compute,d3d12_m4_compute_async_small_waits,d3d12_m4_compute --check-async-journalandd3d12_pipeline_workers, run with:GRAPHICS=0;MIN_BYTES=2097152+GRAPHICS=0;GRAPHICS=1073741824;GRAPHICS=abc.teardown,m4_computeand the journal check ran with and withoutLEONIDA_ASYNC_PIPELINES=1. All pass on the rebased branch.d3d12_m4_computewithLEONIDA_ASYNC_PIPELINES=1and no threshold failed 7 of 8 runs. #2440's build shows the same rate (all-async dispatch skip, see below).ctest(RelWithDebInfo, Ninja, MSVC,-j 4, before the rebase onto #2233): 492 of 495 pass.xbox_presentandd3d12_set_descriptor_heapsalso fail onmainon this machine (noted in #2440).dxgi_waitable_latencypassed 3 of 3 when rerun on its own (a timing test under-j 4).-std=c++20 -Wall -Wextra, Vulkan SDK include) onasync_pipeline_size_test.cppandd3d12_pipeline_workers_test.cpp: no diagnostics in user code. The 13tests/test_docs_*.pypass.scripts/check_no_game_data.pyis clean on every changed file.0vs unset on the same build follows in #1608.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
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: runtime only)🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-27T13:43:19Z.
Updated onto main
ec91d695c(rebased; only conflict wasd3d12_pipeline_workers_test.cppwith #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).Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-27T14:23:22Z.
RUN gfx0 | 2026-11-27 | OreoFR | AI-assisted: Claude Code (Claude Opus 5.5)
BASE: main
ec91d695c+ #1851 #2020 #2166 + this PR + a local window-retire commit (#2465) and a diagnostic commit | shaders: pack with #2447MACHINE: 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.
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-27T15:20:37Z.
Review: COMMENTED
Reviewed and tested at
d42c37335(merged cleanly ontomainec91d695c).Everything looks clean:
PipelineState::create_graphics()-->async_replay_compile(true, spirv_bytes), and compute routes throughasync_replay_compile(false, spirv_bytes).parse_thresholds()andasync_min_bytes()handle unset, empty,0,UINT64_MAX, overflow, malformed values, and over-length env strings consistently, preserving exact prior behaviour whenLEONIDA_ASYNC_MIN_BYTES_GRAPHICSis unset.checkfailure: 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_validationis not installed locally so Vulkan validation layers did not run):async_pipeline_size(CPU): passedd3d12_pipeline_workers,d3d12_pipeline_workers_async_graphics_zero,d3d12_pipeline_workers_async_graphics_unset(GPU): 3/3 passedscripts/check_no_game_data.pyandgit diff --check: cleanNo findings.
AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-27T15:22:09Z.
Thanks @lixonik. A game-run regression check with the variable unset (main
ec91d695cvs + 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).Imported from ubiquitarianism/leonida. Originally posted by djrolfes on 2026-11-27T15:57:06Z.
Independent Linux/Wine + NVIDIA RTX 3070 Ti check at head
d42c37335(merged cleanly ontoorigin/mainec91d695cin a local integration stack alongside#2463,#2470,#2469,#2461,#2126,#2091, and two local V# patches).7.2.15,wine-11.22,clang-cl+xwincross-build, NVIDIA GeForce RTX 3070 Ti 8 GB, driver620.73.04, Ryzen 7 5800X, 32 GB RAM.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)1,800.4 s, time limit, warm caches, no skip list / no stubs):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).VK_ERROR_DEVICE_LOST, 0device-stall, 0gpu-stall, 0 exceptions, peak VRAM7,767 / 8,192 MiB,3,104PresentX,GLCachegrew+109.1 MiBto1,069.9 MiB,276compute pipelines journaled (+137).#2467did: startup line confirmedcompute < 2097152 Bsynchronous andgraphics < 0(LEONIDA_ASYNC_MIN_BYTES_GRAPHICS) asynchronous;0synchronous graphics compiles occurred (draw-workerhandled graphics builds).origin/mainbottleneck observed (not caused by#2467):PresentXstopped advancing aroundt=570 s(loading fade-out) becausequeue_build(d3d12_vulkan_device.cpp:12975-12977,13429) passesWork::demand(instead ofWork::speculative) toLargeModuleGatefordispatch-worker(>= 2 MiB) anddraw-workerbuilds. In this run,79of164synchronous< 2 MiBcompute builds unblocked immediately right when a>= 2 MiBasyncdispatch-workerbuild finished (34builds, up to112.1 seach), stalling synchronous submissions behind background RT compiles. Filing/claiming that separately in#1608.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-27T16:16:57Z.
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_GRAPHICSunset. 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).