Skip to content

vk_pipeline_check: a hard per-process memory cap on Windows, so a runaway driver compile can't exhaust the system's memory - #8371

Open
Nostyxx wants to merge 3 commits into
ItsNotRexed:mainfrom
Nostyxx:fix/pipeline-check-memory-cap
Open

Nostyxx wants to merge 3 commits into
ItsNotRexed:mainfrom
Nostyxx:fix/pipeline-check-memory-cap

Conversation

@Nostyxx

@Nostyxx Nostyxx commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

New BUILD item, claimed in the coordination issue: #8186 (comment)

What and why

vk_pipeline_check's large-module budget (large_module_gate.h, refined by #6429 / #8001) estimates a module's memory before it enters the driver. It can't stop one module that allocates far past the estimate, and on Windows such a module takes the whole machine down with it, not just the checker.

Measured on Windows 11, RTX 3080 (NVIDIA 621.14), 32 GB RAM, during make_game.py's pipelines stage on my own 1.0.2.1 copy (wave64-emulated corpus): one RTShadowTrace32TemporalHQ_Tiled compute module, retried alone by the stage, took the checker to about 69 GB of private bytes. Windows reached its commit limit, other running programs and WerFault.exe failed with 0xC000012D (STATUS_COMMITMENT_LIMIT), and the display driver reset.

This puts the checker into a job object with JOB_OBJECT_LIMIT_PROCESS_MEMORY, so past the cap the driver's allocations fail inside the checker. The driver then returns an error (as NVIDIA does here) or the checker dies, which the existing crash path already handles (--inflight-file, --isolate, the stage's retry alone).

Changes

  • runtime/test/process_memory_cap.h (new): default_process_memory_cap() (the physical memory size on Windows, 0 elsewhere) and apply_process_memory_cap(bytes, error), which creates the job, sets the limit and assigns the current process. No-op off Windows: a Linux container or systemd-run -p MemoryMax=... already caps the process, and the budget reads that limit.
  • runtime/test/vk_pipeline_check.cpp: --memory-cap-mb N (default: physical memory; 0 = off), applied right after argument parsing, before any Vulkan call, and passed to --isolate children (which are in the same job anyway; the limit applies per process). A failure to set the job is a warning, not an error. The cap is printed on stderr at start.
  • runtime/test/process_memory_cap_test.cpp + runtime/CMakeLists.txt: test process_memory_cap. On Windows it caps its own process at 256 MiB and checks that a 512 MiB commit fails while 32 MiB still succeeds, and that a nested 128 MiB cap (an --isolate child inside the parent's job) applies too; elsewhere it checks the functions are no-ops. No Vulkan device.
  • docs/pipeline_check.md: a section on the cap with the measurement below.

make_game.py needs no change: the pipelines stage runs the checker without the option, so it gets the default cap.

Tested

Windows 11 (build 26200), MSVC 14.51 (VS 18 Build Tools), RelWithDebInfo, RTX 3080 with NVIDIA 621.14.

  • ctest -R "process_memory_cap|large_module_gate|vk_pipeline_check_cli": 3/3 pass.

  • The module from the incident, alone: vk_pipeline_check <work>/shaders/spirv cache.bin --start 20880 --count 1 --jobs 1 --memory-cap-mb 16384, sampling the checker's private bytes and the system's free commit every 0.5 s:

    cap checker's peak private bytes outcome
    none (main) about 69 GB system commit exhausted, other programs failed with 0xC000012D, display driver reset
    16384 MiB 16.0 GB after 70 s the driver reported NVVM compilation failed: 3; cs pipelines: 0 ok, 1 failed; the checker exited normally; at least 9.9 GB of system commit stayed free
  • Docs tests: test_docs_repo_paths passes with the new file. test_docs_cli_flags, test_docs_design_rows and test_docs_links fail identically on unchanged main (embedded_shaders.md, README.md, dev-tools.md), unrelated to this change.

  • scripts/check_no_game_data.py on the changed files: clean.

Counts and error classes only; no game data. AI-assisted (Claude Code).

…ct), so a runaway driver compile fails the checker instead of exhausting the system's commit
@jeangoes

Copy link
Copy Markdown

Tested 1ec48c5 on Windows 11 (MSVC 14.44, Vulkan SDK 1.4.363.0, 32 GB RAM) with Intel UHD 730 (101.7085) and RTX 4060 (621.14), against its merge base 47428cc where it matters. Synthetic input only: the 248 translated test fixtures from run_gpu_tests.py.

  • ctest -R "process_memory_cap|large_module_gate|vk_pipeline_check_cli": 3/3 pass.
  • vk_pipeline_check <fixtures> --jobs 1, RTX 4060: default cap (prints memory cap: 32534 MiB), --memory-cap-mb 0 and 256 all give the same result (cs 113/113 pipelines ok, exit 0). With --memory-cap-mb 48 it stops cleanly at vkCreateDevice -3, exit 1.
  • Same on the UHD 730: the checker dies with 0xC0000005 in every mode, including --memory-cap-mb 0 and on the merge base, so not from this PR. With --isolate, the PR and the base give identical results: 9 compute modules crash Intel's driver (cs_imgatomic, cs_imgatomic3d, cs_imgload, cs_imgload_d16, cs_imgstore, cs_m4_fill, cs_m4_indirect, cs_resinfo, cs_sample_lz_int_d16), and the bisection names them with the cap applied in the children, which is the crash path the PR description relies on. With --memory-cap-mb 48 the UHD process ends with 0xC0000409 instead of a Vulkan error, so on this driver a cap that's too small shows up as a crash, not as vkCreateDevice failing.

Not covered: a real runaway module (no game files here), so the cap was never reached during a pipeline compile.

AI-assisted run.

@GonZiin

GonZiin commented Nov 23, 2026

Copy link
Copy Markdown

AI-assisted defensive review of 1ec48c53. The portable process_memory_cap_test passed on Linux. I reviewed Windows job handling statically. vk_pipeline_check.cpp:893 continues into Vulkan when job assignment fails, including after a nonzero --memory-cap-mb is explicitly requested. That leaves an operator who requested containment with only a warning. Please fail setup before Vulkan when an explicitly requested cap cannot be installed and add coverage of that failure path.

@user9517

Copy link
Copy Markdown

Tested 1ec48c5 on Windows 11 (26300), VS 2022 (RelWithDebInfo), Vulkan SDK 1.4.363.1, 96 GB RAM, on two GPUs: an RTX 5090 (621.24) and an AMD gfx1036 iGPU (26.11.2). This adds AMD and a large-RAM machine to @jeangoes's run. The input was synthetic: the fixtures that run_gpu_tests.py translates.

  • CTest. The full runtime suite passes 270/273. The 3 failures are d3d12_vulkan_device, d3d12_indirect_dispatch_count and d3d12_depth_resolve. They fail the same way on the merge base 47428cc in two runs each, so this PR doesn't cause them. process_memory_cap, large_module_gate, vk_pipeline_check_cli and vk_pipeline_check_stack pass.
  • Default cap. It prints memory cap: 95859 MiB, and the results match --memory-cap-mb 0. The same is true with --isolate, with and without a cap, on both GPUs.
  • The cap reached during a pipeline compile, on a small scale (RTX 5090).
    • With --memory-cap-mb 64, the device is created, then PIPELINE FAIL cs_imgstore_r9g9b9e5 (cs w32, -1). The checker reports 0 ok, 1 failed and exits normally. That is the failure path the PR is meant to produce, though for a far smaller module than the one in the incident.
    • 96 MiB and above passes. 32 and 48 MiB stop at vkCreateDevice -1 / -2.
    • On the AMD iGPU, 64 MiB still passes.

Two notes:

  1. The large-module budget ignores the cap. With --memory-cap-mb 64, the checker still prints up to 16 at once within 52.4 GB (3/4 of the 69.9 GB available). With the default cap this doesn't matter, because the cap is physical memory and the budget is below it. With an explicit lower cap, though, the gate admits modules in parallel that together can't fit under it. Taking min(available memory, cap) as the budget would keep the two consistent.
  2. A cap too small for the driver gives an unclear error. A bare vkCreateDevice -1 doesn't point at the cap; on Intel it's a crash, per @jeangoes. A one-line hint after a device-creation failure when a cap is set, such as "try a larger --memory-cap-mb", would help.

Conflict with #8001. Merging this with #8001 conflicts in vk_pipeline_check.cpp, in the list of options passed to --isolate children. #8001 passes --large-module-bytes only when it was set explicitly; this PR adds --memory-cap-mb. The fix is mechanical: keep both. This PR merges cleanly with current main.

Not covered: a real runaway module, because I have no translated shaders from the game.

AI-assisted.

@Nostyxx

Nostyxx commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks both. Pushed e151fc731.

@GonZiin: agreed, fixed. An explicit --memory-cap-mb N (N > 0) that can't be set up is now an error before any Vulkan call: error: cannot set the memory cap of --memory-cap-mb N (...), exit 2. The default cap failing stays a warning, since nobody asked for it. --isolate children get the option only when it was given explicitly, so the default never turns into a hard failure inside a child. Coverage: a test hook VK_PIPELINE_CHECK_SIMULATE_CAP_FAILURE=1 (works on every platform, so Linux CI runs it too) and three new cases in check_vk_pipeline_cli.cmake: explicit cap failing -> exit 2 before the index is read; default cap failing -> warning, then the run reaches the (deliberately malformed) index; --memory-cap-mb 0 -> no cap, nothing set up. Also --memory-cap-mb -1 / 16GiB as usage errors.

@jeangoes: thanks for the RTX 4060 / UHD 730 runs. I added your finding to docs/pipeline_check.md: a cap far below what the driver itself needs ends the process with 0xC0000409 on the UHD 730 instead of failing vkCreateDevice, so keep the cap in gigabytes.

Re-tested on Windows 11, MSVC 14.51, RTX 3080 (621.14): ctest -R "process_memory_cap|large_module_gate|vk_pipeline_check_cli" 3/3. AI-assisted.

… cap below 256 MiB is a usage error, and a failed vkCreateDevice under a cap names it (review of ItsNotRexed#8371)
@Nostyxx

Nostyxx commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@user9517 thanks, both notes taken. Pushed in the latest commit:

  1. The budget follows the cap. Under a cap smaller than the available memory, the large-module budget is 3/4 of the cap. The startup line says which: up to 6 at once within 6.4 GB (3/4 of the 8.6 GB allowed by --memory-cap-mb) with --memory-cap-mb 8192 on my RTX 3080.
  2. Too-small caps. A hint alone wouldn't help much: on my RTX 3080 (621.14) every cap below 128 MiB ends the process with 0xC0000409 before vkCreateDevice returns (32/48/64 MiB all crash, 128 passes), like @jeangoes's UHD 730. So --memory-cap-mb below 256 (other than 0) is now a usage error, exit 2, before the cap is set up: error: --memory-cap-mb 64 is below 256 MiB, too small for a Vulkan driver to start (0 = no cap). Your 5090 numbers (96 MiB) and jeangoes's (48 MiB) are in the comment beside the limit. The hint you suggested is there too, for drivers that do return an error from vkCreateDevice under a cap. CLI test: 1, 64 and 255 MiB give the error.

#8001: noted. Whichever of the two lands second gets the mechanical fix in the --isolate child options (keep both: #8001's explicit-only --large-module-bytes and the explicit-only --memory-cap-mb here, which now follows the same pattern).

Re-tested on Windows 11, MSVC 14.51, RTX 3080 (621.14): ctest -R "process_memory_cap|large_module_gate|vk_pipeline_check_cli" 3/3; 64 MiB -> usage error, 256 MiB and 8 GiB -> 1/1 pipeline ok with the budget from the cap. AI-assisted.

@Raxstreams Raxstreams left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Independent check of 5b8efed5656091929a0b619d90bba439d4c58464, synthetic inputs only.

Windows 11 25H2, MSVC 19.44, RTX 3080 Ti (617.14): large_module_gate, process_memory_cap, and vk_pipeline_check_cli passed (3/3). The CLI test's simulated cap setup failure returns 2 before reading the index for an explicit cap. A single SPIR-V compute pipeline passed under --isolate at 256 and 1024 MiB, with the child reporting the budget derived from the cap. A missing Vulkan ICD manifest made the child report setup failure (exit 1), while the existing simulated-abort hook produced a module failure with child status 3. The build host was already in a Windows job, so I used the checked-in failure hook for the cap-assignment failure case.

Linux result (Ubuntu 24.04 on WSL2, GCC 13.3, llvmpipe): the option claims to enforce a cap even though the Linux implementation of apply_process_memory_cap returns success without applying one. With the same minimal shader, the default run succeeded and budgeted from 16.0 GB of available memory. --memory-cap-mb 256 also returned 0, printed “256 MiB per checker process”, and budgeted from the requested value. --memory-cap-mb 64 was rejected before reading the index. This contradicts the off-Windows behavior described in docs/pipeline_check.md and could make a caller think its explicit limit was installed. Could the option's validation, success line and budget override be restricted to Windows, or could an explicit nonzero cap report that it is unsupported off Windows?

AI-assisted (Codex).

@akimfomin

Copy link
Copy Markdown

Windows follow-up on the #8001 conflict. I trial-merged 5b8efed5 with 64dcdd2c and resolved the single conflict by keeping both explicit-only arguments in the --isolate child command. The combined process_memory_cap, large_module_gate and CLI checks passed with portable LLVM/MinGW.

On RTX 4070 Ti SUPER (617.14, Windows 11 28000.3501), the combined checker compiled the same small synthetic compute pipeline with --isolate in three modes. With --memory-cap-mb 512 --large-module-bytes 1, the child reported the 1-byte cutoff and a budget derived from the 512 MiB cap. Defaults reported the 1 MiB cutoff. Passing 0 for both explicitly removed both messages. All three runs had one successful pipeline and exit 0. This was a propagation check with a tiny module. AI-assisted (Codex).

@Ysergic

Ysergic commented Nov 23, 2026

Copy link
Copy Markdown

Independent Linux check of 5b8efed. Bazzite 45 x86-64, RTX 3070 / NVIDIA 620.73.04, Python 3.15.2, GCC 16.2.1; built this head's checker against the pinned Vulkan headers. Synthetic inputs only.

  • Targeted CTest (process_memory_cap, large_module_gate, vk_pipeline_check_cli): 3/3 passed.
  • test_vk_pipeline_check_isolate.py on the RTX 3070: 10/10 passed, including simulated driver crashes and child setup failures.
  • Five hand-written compute pipelines passed in each of default, --memory-cap-mb 0, 256 and 8192 modes. --isolate --isolate-batch 2 with an explicit 256 MiB option also passed all five.
  • With VK_PIPELINE_CHECK_SIMULATE_CAP_FAILURE=1, an explicit 1024 MiB cap returned 2 before index processing; default and explicit 0 continued successfully. Explicit 255 MiB returned 2 before the index.
  • The 256 MiB option constrained the large-module budget to 3/4 of the cap, including in isolated runs. At 8192 MiB the detected available-memory budget was already lower, so it remained the limiting budget.

These checks pass on Linux. They exercise CLI/error propagation and the portable paths only: process_memory_cap.h deliberately does not install a hard cap off Windows. I did not validate Windows job-object enforcement, a runaway driver compilation, or game-corpus behavior. No merge approval implied.

AI-assisted with Codex.

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.

7 participants