d3d12: large pipelines compile side by side within a memory budget (RT-BIG-COMPUTE-BUDGET) #1889

Manually merged
github merged 4 commits from gh-pr/1889/head into gh-pr/1889/base 2026-11-26 10:10:09 +00:00
Owner

@⁠TheGeogeo on GitHub · 2026-11-25 14:31 UTC · original
TheGeogeo:perf/big-compute-budget → main · +2609 −224 · 13 files · 4 commits · merged 2026-11-25 22:01 UTC

Claimed in the coordination issue as: RT-BIG-COMPUTE-BUDGET (#1608)

Depends on: #1742 (conflicts with it in five hunks: vulkan_backend.h 1, vulkan_replay.h 2, replay_pipeline_compiles_test.cpp 2; 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 of d3d12_vulkan_device.cpp, on top of the one it has with main alone; whichever lands second needs a rebase, and neither builds on the other.), #2098 (conflicts with it in six hunks: d3d12_vulkan_device.cpp 5, vulkan_replay.h 1; its build_compute_pipeline keeps the big_compile mutex 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:

  • Admission. A large pipeline's estimate is 512 bytes for each byte of SPIR-V (the number vk_pipeline_check already 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.
  • Order. They get in in the order they came; while the first in line does not fit, the next behind it that does may pass, as long as all that have passed it would fit the budget together with it, so a stream of small ones does not keep it out (0bf7ef80, after Snooozs's measurement). What a submission waits for goes before the warm-up, also between two of the submission's compiles, and the warm-up takes a quarter of the budget at most.
  • No deadlock. A thread that waits for its place holds no PSO lock (the code before this held it while it waited for big_compile), and a thread that has a place never waits for one. Nothing takes resource_mutex_ while it has a place.
  • The submission. PipelineCompiles::build gives 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.
  • Settings. LEONIDA_SERIAL_BIG_COMPILES=1 keeps the path of before (one at a time, the mutex and the chain); =0 has no limit, which now includes the graphics chain; unset is the budget. LEONIDA_BIG_COMPILE_BUDGET_MB fixes the budget.
  • LargeModuleGate moves from runtime/test to runtime/src, where it gets a second constructor. A forwarding header keeps vk_pipeline_check and 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 of main 0d80bc5d and the branch on it (22 GB of RAM free; the budget is then 16 GB, so the threads are the limit):

    main branch peak private memory over the start, main / branch
    16 modules of 256 KiB 4.0 to 4.8 s 0.75 to 0.81 s +14 to 56 / +228 to 242 MiB
    16 modules of 512 KiB 10.2 to 11.4 s 2.0 to 2.2 s +76 to 83 / +381 to 400 MiB
    15 modules of 1 MiB 29.2 to 31.2 s 5.8 to 6.1 s +140 to 147 / +656 to 676 MiB
    12 modules of 0.5 to 2 MiB 38.9 to 39.9 s 8.0 to 10.5 s +222 to 250 / +534 to 559 MiB

    One 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.md measured 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 with LEONIDA_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), seven d3d12_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 in replay_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 ctest of main 71a769d7 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 from main 0d80bc5d; up to aa8018b7 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_descriptor is not run on both sides: its source does not compile here without glslangValidator (LEONIDA_TEST_NULL_DESCRIPTORS_SPV is not defined then), which is on main.

  • test_ctest_registration, test_docs_links, test_docs_cli_flags, test_text_write_line_endings, git diff --check and check_no_game_data.py pass. Trial merges: no conflict hunk added against #1577, #1495, #1504, #1706, #1579, #1600, #1514, #1391, #1209, #218, #1821, #1833 and #1886; five against #1742.

  • aa8018b7 merged with main e18b59a5 (no conflict), same build settings, RTX 3080: big_compile_gate, large_module_gate, replay_pipeline_compiles and its _strict, pipeline_workers, d3d12_pipeline_workers and its _eager, and the seven d3d12_big_compute* pass. Full ctest: 379 tests, 365 pass, 13 skip, none fails, vk_null_descriptor not run as above. main e18b59a5 alone was not built for this. The measurements and mutants above were not repeated.

  • 0bf7ef80 (the passing rule, on aa8018b7), same build settings, RTX 3080: five new cases in big_compile_gate (the first fails on aa8018b7), 30 of 30 runs pass, and 14 of 14 mutants of the rule fail. big_compile_gate, large_module_gate, pipeline_workers, replay_pipeline_compiles and its _strict, d3d12_pipeline_workers and its _eager, the seven d3d12_big_compute* and the two vk_pipeline_check tests pass. Trial merges with main 72006d61 and with #2077 (044d9ba5, built on this): no conflict; with #1742 (d33ada43) five hunks and #1756 (90506453) one, as before, and with #2098 (9f98dcc6) six. The full ctest, the timings and the GPU mutants were not repeated on it.

  • Trial merges of aa8018b7's merge (on main e48ff037) with the 280 open pull requests that touch the same files: only #1742 (five hunks) and #1756 (one) conflict where main alone does not. #1886, #1821 and #1706 stay clean; #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

  • 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. (none added)
**@⁠TheGeogeo** on GitHub · 2026-11-25 14:31 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1889) `TheGeogeo:perf/big-compute-budget` → `main` · +2609 −224 · 13 files · 4 commits · merged 2026-11-25 22:01 UTC Claimed in the coordination issue as: RT-BIG-COMPUTE-BUDGET (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) Depends on: #1742 (conflicts with it in five hunks: `vulkan_backend.h` 1, `vulkan_replay.h` 2, `replay_pipeline_compiles_test.cpp` 2; 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 of `d3d12_vulkan_device.cpp`, on top of the one it has with `main` alone; whichever lands second needs a rebase, and neither builds on the other.), #2098 (conflicts with it in six hunks: `d3d12_vulkan_device.cpp` 5, `vulkan_replay.h` 1; its `build_compute_pipeline` keeps the `big_compile` mutex 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](https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/1547) names the big library compute programs as the likely remainder, [QemmHD](https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/1577) saw four pipelines of about 1.0 MB take 31.6 s one after another, and [DadaCap](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) about 15 inline compiles of 2 to 5 s in a row with a warm-up thread waiting on the same mutex. [huangzhuoyue](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) described a memory-budgeted gate that prefers demand compiles and reported that it removed the stalls on their machine; a [review note](https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/1577) on #1577 asks for a priority-aware gate as well. Now large pipelines wait for memory instead of for each other: - **Admission.** A large pipeline's estimate is 512 bytes for each byte of SPIR-V (the number `vk_pipeline_check` already 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. - **Order.** They get in in the order they came; while the first in line does not fit, the next behind it that does may pass, as long as all that have passed it would fit the budget together with it, so a stream of small ones does not keep it out (0bf7ef80, after [Snooozs's measurement](https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/1889)). What a submission waits for goes before the warm-up, also between two of the submission's compiles, and the warm-up takes a quarter of the budget at most. - **No deadlock.** A thread that waits for its place holds no PSO lock (the code before this held it while it waited for `big_compile`), and a thread that has a place never waits for one. Nothing takes `resource_mutex_` while it has a place. - **The submission.** `PipelineCompiles::build` gives 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. - **Settings.** `LEONIDA_SERIAL_BIG_COMPILES=1` keeps the path of before (one at a time, the mutex and the chain); `=0` has no limit, which now includes the graphics chain; unset is the budget. `LEONIDA_BIG_COMPILE_BUDGET_MB` fixes the budget. - `LargeModuleGate` moves from `runtime/test` to `runtime/src`, where it gets a second constructor. A forwarding header keeps `vk_pipeline_check` and 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 of `main` 0d80bc5d and the branch on it (22 GB of RAM free; the budget is then 16 GB, so the threads are the limit): | | `main` | branch | peak private memory over the start, `main` / branch | |---|---|---|---| | 16 modules of 256 KiB | 4.0 to 4.8 s | 0.75 to 0.81 s | +14 to 56 / +228 to 242 MiB | | 16 modules of 512 KiB | 10.2 to 11.4 s | 2.0 to 2.2 s | +76 to 83 / +381 to 400 MiB | | 15 modules of 1 MiB | 29.2 to 31.2 s | 5.8 to 6.1 s | +140 to 147 / +656 to 676 MiB | | 12 modules of 0.5 to 2 MiB | 38.9 to 39.9 s | 8.0 to 10.5 s | +222 to 250 / +534 to 559 MiB | One 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.md` measured 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 with `LEONIDA_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), seven `d3d12_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 in `replay_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 `ctest` of `main` 71a769d7 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 from `main` 0d80bc5d; up to aa8018b7 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_descriptor` is not run on both sides: its source does not compile here without `glslangValidator` (`LEONIDA_TEST_NULL_DESCRIPTORS_SPV` is not defined then), which is on `main`. - `test_ctest_registration`, `test_docs_links`, `test_docs_cli_flags`, `test_text_write_line_endings`, `git diff --check` and `check_no_game_data.py` pass. Trial merges: no conflict hunk added against #1577, #1495, #1504, #1706, #1579, #1600, #1514, #1391, #1209, #218, #1821, #1833 and #1886; five against #1742. - aa8018b7 merged with `main` e18b59a5 (no conflict), same build settings, RTX 3080: `big_compile_gate`, `large_module_gate`, `replay_pipeline_compiles` and its `_strict`, `pipeline_workers`, `d3d12_pipeline_workers` and its `_eager`, and the seven `d3d12_big_compute*` pass. Full `ctest`: 379 tests, 365 pass, 13 skip, none fails, `vk_null_descriptor` not run as above. `main` e18b59a5 alone was not built for this. The measurements and mutants above were not repeated. - 0bf7ef80 (the passing rule, on aa8018b7), same build settings, RTX 3080: five new cases in `big_compile_gate` (the first fails on aa8018b7), 30 of 30 runs pass, and 14 of 14 mutants of the rule fail. `big_compile_gate`, `large_module_gate`, `pipeline_workers`, `replay_pipeline_compiles` and its `_strict`, `d3d12_pipeline_workers` and its `_eager`, the seven `d3d12_big_compute*` and the two `vk_pipeline_check` tests pass. Trial merges with `main` 72006d61 and with #2077 (044d9ba5, built on this): no conflict; with #1742 (d33ada43) five hunks and #1756 (90506453) one, as before, and with #2098 (9f98dcc6) six. The full `ctest`, the timings and the GPU mutants were not repeated on it. - Trial merges of aa8018b7's merge (on `main` e48ff037) with the 280 open pull requests that touch the same files: only #1742 (five hunks) and #1756 (one) conflict where `main` alone does not. #1886, #1821 and #1706 stay clean; #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](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) 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 - [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. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (none added)
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.
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.
Brings #1889 up to date with main after #1742 (the pipeline compile unlock),
resolving the five conflicts as described in the guide on the PR:
https://github.com/ubiquitarianism/leonida/pull/1889#issuecomment-7175252290

- 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 #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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:10:06 +00:00
github manually merged commit 712714bef2 into gh-pr/1889/base 2026-11-26 10:10:09 +00:00
Author
Owner

@⁠Snooozs on GitHub · 2026-11-25 20:01 UTC · original

Two measurements on this branch, from the header alone (large_module_gate.h at the current head) and from a boot.

A module that fits can wait behind one that doesn't. enter() with a read budget admits only queue.begin(). Budget 1000, one ticket of 900 held, then a 400 (does not fit, head of the queue), then a 50 (950 <= 1000): the 50 was not admitted within 300 ms, in 3 of 3 runs of a small CPU-only program (MSVC 19, LargeModuleGate with a fixed read_budget). It is FIFO by design as I read it, so the question is only whether to keep it: in a boot of mine (RTX 5060 Ti 16 GB, 32 GB RAM, earlier head of this PR) a stack snapshot had 10 threads in LargeModuleGate::enter and one compiling. Letting a later waiter pass when it fits would need an ageing rule so the large one still gets in.

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. LEONIDA_BIG_COMPILE_BUDGET_MB=16000 avoids both effects here, at the price of RAM: with it a world-start burst took free RAM under 2.5 GB on this machine.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠Snooozs** on GitHub · 2026-11-25 20:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1889#issuecomment-7173084713) Two measurements on this branch, from the header alone (`large_module_gate.h` at the current head) and from a boot. **A module that fits can wait behind one that doesn't.** `enter()` with a read budget admits only `queue.begin()`. Budget 1000, one ticket of 900 held, then a 400 (does not fit, head of the queue), then a 50 (950 <= 1000): the 50 was not admitted within 300 ms, in 3 of 3 runs of a small CPU-only program (MSVC 19, `LargeModuleGate` with a fixed `read_budget`). It is FIFO by design as I read it, so the question is only whether to keep it: in a boot of mine (RTX 5060 Ti 16 GB, 32 GB RAM, earlier head of this PR) a stack snapshot had 10 threads in `LargeModuleGate::enter` and one compiling. Letting a later waiter pass when it fits would need an ageing rule so the large one still gets in. **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. `LEONIDA_BIG_COMPILE_BUDGET_MB=16000` avoids both effects here, at the price of RAM: with it a world-start burst took free RAM under 2.5 GB on this machine. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠TheGeogeo on GitHub · 2026-11-25 21:03 UTC · original

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. 0bf7ef80: 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 vk_pipeline_check and the gate's interface are unchanged.

Windows 11, MSVC 14.52, RTX 3080, NVIDIA 621.24: big_compile_gate has five cases for it (the first one fails on aa8018b7, in(little)), passes 30 of 30 runs, and 14 of 14 mutants of the new rule fail. large_module_gate, pipeline_workers, replay_pipeline_compiles and its _strict, d3d12_pipeline_workers and its _eager, the seven d3d12_big_compute* and the two vk_pipeline_check tests pass. The full ctest and the timings were not repeated. The head merges cleanly with main db1a22d2 and with #2077 at 044d9ba5.

The estimate: I kept 512. The 85 to 131 in the header are synthetic modules on one NVIDIA driver; RADV took about 330 (docs/pipeline_check.md), and what a real program takes is not known. If your 85 to 131 is from your own run, which programs was it? For your 16000 MiB run, the free RAM before the burst and the bytes of SPIR-V in the driver at that moment would give the real number, and that would be the reason to change it.

The description is updated for this head.

AI-assisted (Claude Code).

**@⁠TheGeogeo** on GitHub · 2026-11-25 21:03 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1889#issuecomment-7174546076) 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. 0bf7ef80: 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 `vk_pipeline_check` and the gate's interface are unchanged. Windows 11, MSVC 14.52, RTX 3080, NVIDIA 621.24: `big_compile_gate` has five cases for it (the first one fails on aa8018b7, `in(little)`), passes 30 of 30 runs, and 14 of 14 mutants of the new rule fail. `large_module_gate`, `pipeline_workers`, `replay_pipeline_compiles` and its `_strict`, `d3d12_pipeline_workers` and its `_eager`, the seven `d3d12_big_compute*` and the two `vk_pipeline_check` tests pass. The full `ctest` and the timings were not repeated. The head merges cleanly with `main` db1a22d2 and with #2077 at 044d9ba5. **The estimate:** I kept 512. The 85 to 131 in the header are synthetic modules on one NVIDIA driver; RADV took about 330 (`docs/pipeline_check.md`), and what a real program takes is not known. If your 85 to 131 is from your own run, which programs was it? For your 16000 MiB run, the free RAM before the burst and the bytes of SPIR-V in the driver at that moment would give the real number, and that would be the reason to change it. The description is updated for this head. AI-assisted (Claude Code).
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 21:34 UTC · original

#1742 is merged, so this branch now conflicts with main in five places (three files). Here is how to resolve each one so both changes stay in.

  • runtime/src/vulkan_replay.h, PipelineCompiles::build: main added lookup() and contains_ticket(), and build(run, prior) now skips jobs already tried in prior (the pass before) and returns early when nothing is left. This branch changed build(run, read_budget) to sort the large ones and count lanes against the budget. Keep lookup() and contains_ticket() from main. Give build both parameters, for example build(Run&& run, const std::function<std::uint64_t()>& read_budget = {}, const PipelineCompiles* prior = nullptr). In the body, first fill single and large with the prior->lookup(...) skip from main, then if (single.empty() && large.empty()) return;, then your lane and budget code. build_serial(prior) stays as main has it.
  • runtime/src/vulkan_replay.h, check_compiled_pipelines / build_pipelines: main split the old build_pipelines into check_compiled_pipelines(compiles, result, prior) and finish_compiled_pipelines(...). The new build_pipelines(..., run, prior) and build_pipelines_serial(..., prior) sit just below the conflict. Take main's side of the conflict and drop this branch's copy of the build_pipelines head. Then add the budget to main's build_pipelines: build_pipelines(compiles, lists, result, run, budget = {}, prior = nullptr), which calls compiles.build(run, budget, prior).
  • runtime/src/vulkan_backend.h, VulkanQueue::execute_now: main no longer compiles after the prepare loop. It now runs two passes. On pass 0, with compiles not empty, it releases tracker_lock and resource_lock, compiles with compiles.build(run_compiles) (or compiles.build_serial() without workers) and holds only the new pipeline_lock. Pass 1 prepares again and calls build_pipelines(..., run_compiles, prior), which reuses pass 0's outcomes. This branch's block after the loop (demand + build_pipelines(..., large_compile_budget_)) has no place left. Take main's side (the empty one) and move your two pieces into pass 0:
    • take demand (when context_.large_compile_demand_ && compiles.any_large()) just before the if (context_.pipeline_workers_) that compiles, and demand.reset() right after it;
    • call compiles.build(run_compiles, context_.large_compile_budget_);
    • in pass 1, pass context_.large_compile_budget_ to build_pipelines(..., run_compiles, context_.large_compile_budget_, prior). Pass 1 normally compiles nothing new, so it doesn't need demand.
  • runtime/src/vulkan_backend.h, set_large_compiles (merges without a conflict, but needs a change): #1742 moved pipeline_workers_ and the pipeline maps from resource_mutex_ to a new pipeline_mutex_ (order: state_mutex_ -> pipeline_mutex_ -> resource_mutex_ -> tracker_mutex_ -> submit_mutex_). It also reads large_compile_budget_/large_compile_demand_ while it compiles, with resource_lock released. So set_large_compiles should take std::unique_lock lock(pipeline_mutex_) like set_pipeline_workers next to it, not resource_mutex_. While you are there, update the "No deadlock" note in the description: a compile now holds pipeline_mutex_ shared instead of resource_mutex_. As far as I can see, enter_build and build_compute take neither lock while they hold a place.
  • runtime/test/replay_pipeline_compiles_test.cpp, the new cases: main added prior_compiles_reuse(workers) and serial_stops_at_refused_draw(). This branch added Shop and the budget_* cases at the same spot. Keep both blocks, one after the other. Both sides end inside a function whose } comes after the conflict, so add a } after serial_stops_at_refused_draw before // ---- Large pipelines within a budget. ----. With the parameter order above, change the one build_pipelines call in prior_compiles_reuse from ..., run, &first) to ..., run, {}, &first).
  • runtime/test/replay_pipeline_compiles_test.cpp, main(): keep serial_stops_at_refused_draw(); from main as well as your six budget_*(); calls.
  • After resolving: build gta6rt_d3d12_com and the tests, then run big_compile_gate, large_module_gate, replay_pipeline_compiles, replay_pipeline_compiles_strict, replay_pipeline_compile_unlock (new from #1742; it covers the unlocked compile), pipeline_workers, d3d12_pipeline_workers, d3d12_pipeline_workers_eager and the seven d3d12_big_compute*.
  • Checked locally, nothing pushed: I merged 0bf7ef80 onto main f9642954f and resolved it as above. It builds with clang-cl, and the tests listed above pass under Wine on lavapipe and on the RADV gfx1036 iGPU (17 with the two vk_pipeline_check tests). A trial merge on today's main ab2fb71cb shows the same five conflicts.
  • Not reviewed yet: the new commit 0bf7ef80 (the gate's passing rule) has not been reviewed. We will review it once the conflicts are resolved, so this guide is not an approval of it.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-25 21:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1889#issuecomment-7175252290) #1742 is merged, so this branch now conflicts with `main` in five places (three files). Here is how to resolve each one so both changes stay in. - **`runtime/src/vulkan_replay.h`, `PipelineCompiles::build`:** `main` added `lookup()` and `contains_ticket()`, and `build(run, prior)` now skips jobs already tried in `prior` (the pass before) and returns early when nothing is left. This branch changed `build(run, read_budget)` to sort the large ones and count lanes against the budget. Keep `lookup()` and `contains_ticket()` from `main`. Give `build` both parameters, for example `build(Run&& run, const std::function<std::uint64_t()>& read_budget = {}, const PipelineCompiles* prior = nullptr)`. In the body, first fill `single` and `large` with the `prior->lookup(...)` skip from `main`, then `if (single.empty() && large.empty()) return;`, then your lane and budget code. `build_serial(prior)` stays as `main` has it. - **`runtime/src/vulkan_replay.h`, `check_compiled_pipelines` / `build_pipelines`:** `main` split the old `build_pipelines` into `check_compiled_pipelines(compiles, result, prior)` and `finish_compiled_pipelines(...)`. The new `build_pipelines(..., run, prior)` and `build_pipelines_serial(..., prior)` sit just below the conflict. Take `main`'s side of the conflict and drop this branch's copy of the `build_pipelines` head. Then add the budget to `main`'s `build_pipelines`: `build_pipelines(compiles, lists, result, run, budget = {}, prior = nullptr)`, which calls `compiles.build(run, budget, prior)`. - **`runtime/src/vulkan_backend.h`, `VulkanQueue::execute_now`:** `main` no longer compiles after the prepare loop. It now runs two passes. On pass 0, with `compiles` not empty, it releases `tracker_lock` and `resource_lock`, compiles with `compiles.build(run_compiles)` (or `compiles.build_serial()` without workers) and holds only the new `pipeline_lock`. Pass 1 prepares again and calls `build_pipelines(..., run_compiles, prior)`, which reuses pass 0's outcomes. This branch's block after the loop (`demand` + `build_pipelines(..., large_compile_budget_)`) has no place left. Take `main`'s side (the empty one) and move your two pieces into pass 0: - take `demand` (when `context_.large_compile_demand_ && compiles.any_large()`) just before the `if (context_.pipeline_workers_)` that compiles, and `demand.reset()` right after it; - call `compiles.build(run_compiles, context_.large_compile_budget_)`; - in pass 1, pass `context_.large_compile_budget_` to `build_pipelines(..., run_compiles, context_.large_compile_budget_, prior)`. Pass 1 normally compiles nothing new, so it doesn't need `demand`. - **`runtime/src/vulkan_backend.h`, `set_large_compiles` (merges without a conflict, but needs a change):** #1742 moved `pipeline_workers_` and the pipeline maps from `resource_mutex_` to a new `pipeline_mutex_` (order: `state_mutex_` -> `pipeline_mutex_` -> `resource_mutex_` -> `tracker_mutex_` -> `submit_mutex_`). It also reads `large_compile_budget_`/`large_compile_demand_` while it compiles, with `resource_lock` released. So `set_large_compiles` should take `std::unique_lock lock(pipeline_mutex_)` like `set_pipeline_workers` next to it, not `resource_mutex_`. While you are there, update the "No deadlock" note in the description: a compile now holds `pipeline_mutex_` shared instead of `resource_mutex_`. As far as I can see, `enter_build` and `build_compute` take neither lock while they hold a place. - **`runtime/test/replay_pipeline_compiles_test.cpp`, the new cases:** `main` added `prior_compiles_reuse(workers)` and `serial_stops_at_refused_draw()`. This branch added `Shop` and the `budget_*` cases at the same spot. Keep both blocks, one after the other. Both sides end inside a function whose `}` comes after the conflict, so add a `}` after `serial_stops_at_refused_draw` before `// ---- Large pipelines within a budget. ----`. With the parameter order above, change the one `build_pipelines` call in `prior_compiles_reuse` from `..., run, &first)` to `..., run, {}, &first)`. - **`runtime/test/replay_pipeline_compiles_test.cpp`, `main()`:** keep `serial_stops_at_refused_draw();` from `main` as well as your six `budget_*();` calls. - **After resolving:** build `gta6rt_d3d12_com` and the tests, then run `big_compile_gate`, `large_module_gate`, `replay_pipeline_compiles`, `replay_pipeline_compiles_strict`, `replay_pipeline_compile_unlock` (new from #1742; it covers the unlocked compile), `pipeline_workers`, `d3d12_pipeline_workers`, `d3d12_pipeline_workers_eager` and the seven `d3d12_big_compute*`. - **Checked locally, nothing pushed:** I merged `0bf7ef80` onto `main` `f9642954f` and resolved it as above. It builds with clang-cl, and the tests listed above pass under Wine on lavapipe and on the RADV gfx1036 iGPU (17 with the two `vk_pipeline_check` tests). A trial merge on today's `main` `ab2fb71cb` shows the same five conflicts. - **Not reviewed yet:** the new commit `0bf7ef80` (the gate's passing rule) has not been reviewed. We will review it once the conflicts are resolved, so this guide is not an approval of it. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 22:01 UTC · original

Merged, thanks! Since #1742 had landed, I merged main into your branch (712714bef), resolving the five conflicts as in the guide above, plus one missing } in the test file.

  • Reviewed 0bf7ef80: a fitting compile passes the first in line only while all that passed it plus the first fit the budget, so the first waits at most for what was running when it reached the front, and one larger than the whole budget is never passed.
  • Tested: the full Windows suite under Wine on lavapipe and RADV (gfx1036 iGPU), on exactly this tree: no test went from pass to fail, and big_compile_gate and the seven d3d12_big_compute* tests pass on both.
  • Checked on main cb699500a + 712714bef: it merges cleanly; the semantic suite passes (491 files, 6,312 tests, 0 files failed); the 15 docs and writer tests pass; check_no_game_data.py is clean on the 13 changed files.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-25 22:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1889#issuecomment-7175834026) Merged, thanks! Since #1742 had landed, I merged `main` into your branch (`712714bef`), resolving the five conflicts as in the guide above, plus one missing `}` in the test file. - **Reviewed `0bf7ef80`:** a fitting compile passes the first in line only while all that passed it plus the first fit the budget, so the first waits at most for what was running when it reached the front, and one larger than the whole budget is never passed. - **Tested:** the full Windows suite under Wine on lavapipe and RADV (gfx1036 iGPU), on exactly this tree: no test went from pass to fail, and `big_compile_gate` and the seven `d3d12_big_compute*` tests pass on both. - **Checked on `main` `cb699500a` + `712714bef`:** it merges cleanly; the semantic suite passes (491 files, 6,312 tests, 0 files failed); the 15 docs and writer tests pass; `check_no_game_data.py` is clean on the 13 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.