Repository navigation
d3d12: large pipelines compile side by side within a memory budget (RT-BIG-COMPUTE-BUDGET) - #1889
Conversation
…re speculative (RT-BIG-COMPUTE-BUDGET) LargeModuleGate moves to runtime/src (a forwarding header keeps vk_pipeline_check and its test as they are) and gets a second constructor, whose budget is read whenever a place is given or returned. Its modules get in in the order they came, a speculative one only while no demand waits and within a quarter of the budget. large_compile_budget_bytes() is three quarters of the smaller of the free RAM and the room under the commit limit. CPU test: the bound, one always, order, priority, every wake-up, the budget of the moment and the setting.
…T-BIG-COMPUTE-BUDGET) Compute modules over 128 KiB and graphics pipelines of 1 MiB of SPIR-V or more wait at one gate for the process until their estimates fit the memory that is free, instead of one at a time. PipelineCompiles::build gives a submission as many lanes for them as can be in at once, largest first, and fills the rest with small ones. A thread that waits for its place holds no PSO's lock, and one that has a place waits for none. The warm-up's compiles are speculative. LEONIDA_SERIAL_BIG_COMPILES=1 keeps one at a time, 0 has no limit, LEONIDA_BIG_COMPILE_BUDGET_MB fixes the budget.
…LAS BLAS-VA translation (#1723) & boot_bench RAGE9 BLAS tracking - Add runtime/src/large_module_gate.h & runtime/test/big_compile_gate_test.cpp (adapted from TheGeogeo, ProjectLeonida/mandy#1889, RT-BIG-COMPUTE-BUDGET, GPL-3.0): dynamic RAM/commit-budgeted admission (512 B/SPIR-V byte, 3/4 free RAM/commit room), demand-over-speculative FIFO priority, Demand RAII guard, and process-wide helper. - Wire PipelineCompiles::build(run, budget) + VulkanContext::set_large_compiles() in vulkan_replay.h and vulkan_backend.h while preserving Wave 9B (#1877) and Wave 9C (#1874/#1264). - Port XDXR TLAS BLAS-address translation (FLAG_TRANSLATE / blas_address / XdxrBlasTable) from Moriz82, ProjectLeonida/mandy#1723 (GPL-3.0) across xdxr_build.comp, xdxr_build.inc, xdxr_build.h, vulkan_replay.h, vulkan_backend.h (stage_xdxr_table + set_xdxr_blas_table_provider), and add out-of-arena TLAS instance verification in d3d12_xdxr_rt_test.cpp. - Update ops/boot_bench.py to count RehydrateRaytracingAccelerationStructureBatched2X RAGE9 rehydration ok lines in rt_as_builds (not rt_as_skipped) with --selftest coverage.
|
Two measurements on this branch, from the header alone ( A module that fits can wait behind one that doesn't. The estimate is 4 to 6 times what I measured on NVIDIA (85 to 131 bytes of memory per byte of SPIR-V against 512), so a 12 GB budget holds far fewer builds than it could. AI-assisted (Claude Code, Claude Opus 5.5). |
… a bound (RT-BIG-COMPUTE-BUDGET)
|
Thanks for the two measurements. A module that fits behind one that doesn't: you are right, and there is no reason to keep it strict. 0bf7ef8: while the first in line does not fit, the next behind it that does may pass, as long as everything that has passed it would fit the budget together with it. So no ageing rule is needed: with the budget as it is, the first in line waits at most for what was in when it became the first, however many small ones come after it, and one larger than the budget is not passed. Your case (1000, 900 held, 400, then 50) now lets the 50 in (50 + 400 fits). Same for the warm-up within its quarter; the fixed budget of Windows 11, MSVC 14.52, RTX 3080, NVIDIA 621.24: The estimate: I kept 512. The 85 to 131 in the header are synthetic modules on one NVIDIA driver; RADV took about 330 ( The description is updated for this head. AI-assisted (Claude Code). |
|
#1742 is merged, so this branch now conflicts with
AI-assisted (Claude Code, Claude Opus 5.5). |
Brings ProjectLeonida#1889 up to date with main after ProjectLeonida#1742 (the pipeline compile unlock), resolving the five conflicts as described in the guide on the PR: ProjectLeonida#1889 (comment) - vulkan_replay.h: PipelineCompiles::build takes both the large-compile budget and main's `prior` compiles; build_pipelines passes the budget, and main's check_compiled_pipelines / finish_compiled_pipelines stay. - vulkan_backend.h: execute_now takes the large-compile demand and passes the budget to the pass-0 compile, and pass 1 passes the budget too. set_large_compiles locks pipeline_mutex_, since ProjectLeonida#1742 moved the pipeline state under that lock. - replay_pipeline_compiles_test.cpp: both test blocks kept, and the prior_compiles_reuse call passes an empty budget. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merged, thanks! Since #1742 had landed, I merged
AI-assisted (Claude Code, Claude Opus 5.5). |
…POOL) PipelineCompiler ran every LEONIDA_ASYNC_PIPELINES=1 build, the compute warm-up and the cache checkpoint on one below-normal thread, so one long driver compile held every pipeline a submission asked for behind it, and their draws and dispatches were skipped meanwhile. - LEONIDA_COMPILE_THREADS workers: unset, half the logical processors, at least 2 and at most 8; 1 is the one thread there was, with the same order of jobs. - At most N-1 workers in heavy builds (the warm-up's, and demanded builds of large modules), so one is left for a small build a submission asked for. - One very large build (1 MiB of SPIR-V or more) at a time, demanded or not: LEONIDA_COMPILE_HEAVY_MAX. - One job of a PSO at a time, which keeps after_running and the lifetime rules as they are. - A checkpoint starts only when no worker is in a build; has_compile_waiter counts a build that is running. - Large builds wait at the memory gate of ProjectLeonida#1889 inside their job, as before. Tests: pipeline_compiler_pool (the rules, with made-up jobs, no GPU), d3d12_compile_pool (a GPU, the large build held in flight) and d3d12_compile_teardown, the last two with the default, 1 and 4 workers. d3d12_big_compute's warm-up case no longer assumes one warm-up thread. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claimed in the coordination issue as: RT-BIG-COMPUTE-BUDGET (#1608 (comment))
Depends on: #1742 (conflicts with it in five hunks:
vulkan_backend.h1,vulkan_replay.h2,replay_pipeline_compiles_test.cpp2; whichever lands second needs a rebase. It is about the resource lock while pipelines compile and this is about how many large ones compile at once, so neither builds on the other.), #1756 (conflicts with it in one hunk ofd3d12_vulkan_device.cpp, on top of the one it has withmainalone; whichever lands second needs a rebase, and neither builds on the other.), #2098 (conflicts with it in six hunks:d3d12_vulkan_device.cpp5,vulkan_replay.h1; itsbuild_compute_pipelinekeeps thebig_compilemutex that this replaces, so whichever lands second has to put the gate there as well. Neither builds on the other.)What and why
Continues #1547 (merged), which compiles a submission's pipelines side by side but left the large ones one after another: compute modules over 128 KiB of SPIR-V behind one process-wide mutex (
big_compile), and graphics pipelines of 1 MiB or more in one chain per submission, because a compile takes hundreds of bytes of memory for each byte of SPIR-V.That is what the testers still see at the world start: OreoFR names the big library compute programs as the likely remainder, QemmHD saw four pipelines of about 1.0 MB take 31.6 s one after another, and DadaCap about 15 inline compiles of 2 to 5 s in a row with a warm-up thread waiting on the same mutex. huangzhuoyue described a memory-budgeted gate that prefers demand compiles and reported that it removed the stalls on their machine; a review note on #1577 asks for a priority-aware gate as well.
Now large pipelines wait for memory instead of for each other:
vk_pipeline_checkalready uses). It gets in when the estimates of those in the driver and its own fit a budget: three quarters of the smaller of the free RAM and the room under the commit limit, read again whenever a place is given or returned. One always gets in when none is, so a pipeline larger than the budget compiles alone. An estimate counts in full until its compile ends, so what a driver has not allocated yet is not promised twice. Unknown memory means one at a time.big_compile), and a thread that has a place never waits for one. Nothing takesresource_mutex_while it has a place.PipelineCompiles::buildgives it as many jobs for large pipelines as its smallest could be in at once, largest first; where the next one does not fit, the job compiles small ones in the meantime. Graphics and compute share the budget. Draws, dispatches and refused pipelines behave as before.LEONIDA_SERIAL_BIG_COMPILES=1keeps the path of before (one at a time, the mutex and the chain);=0has no limit, which now includes the graphics chain; unset is the budget.LEONIDA_BIG_COMPILE_BUDGET_MBfixes the budget.LargeModuleGatemoves fromruntime/testtoruntime/src, where it gets a second constructor. A forwarding header keepsvk_pipeline_checkand its test as they are, byte for byte, and its fixed budget behaves as before.Tested
Windows 11 (10.0.26300), MSVC 14.52, RelWithDebInfo, Visual Studio 18 2026 generator. No game files: synthetic compute modules of real work (integer instructions, branches, loops, buffer loads), whose results are known on the CPU and checked.
First submission, programs never compiled before,
LEONIDA_COMPUTE_WARMUP=0, 8 workers and the submitting thread, three alternating runs each ofmain0d80bc5 and the branch on it (22 GB of RAM free; the budget is then 16 GB, so the threads are the limit):mainmain/ branchOne compile alone takes 85 to 131 bytes of peak private memory for each byte of SPIR-V on this driver (128 KiB to 4 MiB; 1 MiB takes 2.2 s, 4 MiB 30 to 34 s), so the 512 of the estimate is generous here. It comes from RADV, where
docs/pipeline_check.mdmeasured about 330.Less memory, by the fixed budget (15 modules of 1 MiB): 3840 MiB, seven at once, 6.9 s and a peak of +474 MiB; 1536 MiB, two at once, 18.5 s and +202 MiB; 0, 30.5 s and +152 MiB (
main's path: 28.6 s and +143 MiB withLEONIDA_SERIAL_BIG_COMPILES=1). Holding 12 GiB of commit that no RAM backs moved the free commit room from 22.4 to 10.1 GiB and the budget from 13.2 to 7.6 GiB, with the same RAM free.New tests:
big_compile_gate(CPU: the bound, one always, arrival order, priority, every wake-up, the budget of the moment, estimates reserved, settings), sevend3d12_big_compute*(GPU, one for each setting: fixed budget, nothing fits, from the machine, one at a time, no limit, warm-up, compiled at creation), and cases inreplay_pipeline_compiles(the lanes). The GPU tests read the stored values back, hold the driver's calls to count what is in it, refuse one compile, use two queues, and destroy the device while its workers wait. They skip without a Vulkan device and below the 144-byte push constants.Each new test fails for the changes that should fail it: 45 CPU and 21 GPU mutants (the bound, the one-always rule, the priority, every wake-up, the lock order, the settings) all fail, the originals pass 30 repeated runs in each setting.
Full
ctestofmain71a769d and of the branch on it, compared test by test: 366 tests before (352 pass, 13 skip), 374 after (360, 13), no failure, no other status. The measurements and mutants above are frommain0d80bc5; up to aa8018b the branch's own code has not changed since, only an include, the place of a CMake block, a comment and the tests.vk_null_descriptoris not run on both sides: its source does not compile here withoutglslangValidator(LEONIDA_TEST_NULL_DESCRIPTORS_SPVis not defined then), which is onmain.test_ctest_registration,test_docs_links,test_docs_cli_flags,test_text_write_line_endings,git diff --checkandcheck_no_game_data.pypass. Trial merges: no conflict hunk added against d3d12: parallel PipelineCompiler workers with reserved demand lane (RT-PIPELINE-COMPILER-WORKERS) #1577, [integration] RT-PALMETTO-PARITY: #984 story-load boot on current main, plus the pipeline-library translator fixes #1495, RT-NULL-BARRIER-CLEAR: console null-resource barriers and null-view clears no longer drop the submission #1504, runtime: report in-flight Vulkan pipeline builds on request (RT-VULKAN-COMPILE-STATUS) #1706, tests: resolve a writable temp dir instead of crashing on C:\Windows #1579, tests: derive every test's scratch folder from test_temp_dir::temp_dir, not GetTempPath (TEST-TEMPDIR-STRIPPED-ENV) #1600, vk_pipeline_check: check --mesh-compute entries as compute pipelines #1514, vk_pipeline_check: cap Windows isolation job commit #1391, vk_pipeline_check: cap Linux isolation worker address space (PIPELINE-LINUX-ISOLATE-AS-LIMIT) #1209, d3d12: persist the runtime Vulkan pipeline cache across launches #218, runtime: fix PipelineWorkers stack use-after-free on OOM in start() (RT-PIPELINE-WORKERS-OOM-UAF) #1821, vk_pipeline_check: choose robustBufferAccess and VK_EXT_robustness2 as the runtime does (RT-PIPELINE-CHECK-ROBUSTNESS) #1833 and d3d12: the session pipeline cache is saved up to 4 GiB, checkpoints included (RT-SESSION-CACHE-LIMIT) #1886; five against runtime: unlock resource_mutex while compiling unbuilt pipelines #1742.aa8018b merged with
maine18b59a (no conflict), same build settings, RTX 3080:big_compile_gate,large_module_gate,replay_pipeline_compilesand its_strict,pipeline_workers,d3d12_pipeline_workersand its_eager, and the sevend3d12_big_compute*pass. Fullctest: 379 tests, 365 pass, 13 skip, none fails,vk_null_descriptornot run as above.maine18b59a alone was not built for this. The measurements and mutants above were not repeated.0bf7ef8 (the passing rule, on aa8018b), same build settings, RTX 3080: five new cases in
big_compile_gate(the first fails on aa8018b), 30 of 30 runs pass, and 14 of 14 mutants of the rule fail.big_compile_gate,large_module_gate,pipeline_workers,replay_pipeline_compilesand its_strict,d3d12_pipeline_workersand its_eager, the sevend3d12_big_compute*and the twovk_pipeline_checktests pass. Trial merges withmain72006d6 and with d3d12: a pool of workers for the pipeline compiler (RT-ASYNC-COMPILE-POOL) #2077 (044d9ba, built on this): no conflict; with runtime: unlock resource_mutex while compiling unbuilt pipelines #1742 (d33ada4) five hunks and d3d12: finish CompileActivity before checkpointing and retry deferred cache snapshots #1756 (9050645) one, as before, and with Improve post-load GPU memory and pipeline handling (RT-POST-LOAD-GPU-MEMORY) #2098 (9f98dcc) six. The fullctest, the timings and the GPU mutants were not repeated on it.Trial merges of aa8018b's merge (on
maine48ff03) with the 280 open pull requests that touch the same files: only runtime: unlock resource_mutex while compiling unbuilt pipelines #1742 (five hunks) and d3d12: finish CompileActivity before checkpointing and retry deferred cache snapshots #1756 (one) conflict wheremainalone does not. d3d12: the session pipeline cache is saved up to 4 GiB, checkpoints included (RT-SESSION-CACHE-LIMIT) #1886, runtime: fix PipelineWorkers stack use-after-free on OOM in start() (RT-PIPELINE-WORKERS-OOM-UAF) #1821 and runtime: report in-flight Vulkan pipeline builds on request (RT-VULKAN-COMPILE-STATUS) #1706 stay clean; d3d12: parallel PipelineCompiler workers with reserved demand lane (RT-PIPELINE-COMPILER-WORKERS) #1577 is closed.Not run: the title. I do not have the package, so the effect on the world start, and the peak memory there, are for someone who has it to measure (DadaCap reports about ten side by side with
LEONIDA_SERIAL_BIG_COMPILES=0, 25 GB private and 27 of 62 GB of RAM free). The modules are synthetic; a real program may take more memory for each byte, and how much of the 512 that uses is not known. Other GPUs and drivers were not run, and without a Vulkan SDK the Khronos validation layer did not run either.With several large compiles at once the submission's small pipelines compile after them when every thread has one, which does not change when the submission is done, and another queue's submission compiles its own on its own thread meanwhile.
GPUs tested: NVIDIA GeForce RTX 3080, driver 621.24, Windows 11 (10.0.26300).
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (none added)