Skip to content

vk_pipeline_check: bound 32 GiB Windows memory with 1 MiB budget cutoff, live headroom, and 2048 B/B estimate (SHADER-904) - #8001

Open
Wasler wants to merge 1 commit into
ItsNotRexed:mainfrom
Wasler:fix/windows-large-module-gate
Open

Wasler wants to merge 1 commit into
ItsNotRexed:mainfrom
Wasler:fix/windows-large-module-gate

Conversation

@Wasler

@Wasler Wasler commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in #7804 (SHADER-904 / #884 / #6089 follow-up).

What was wrong on Windows 32 GiB hosts

  1. The 4 MiB default cutoff skipped the heavy 1–4 MiB wave64-emulated modules. In the 26,503-entry translated corpus, 4,331 modules sit in 1–4 MiB (including all 820 1–4 MiB mesh shaders), while only 728 exceed 4 MiB. In budget mode (--large-parallel 0), those 1–4 MiB batches ran on every worker thread without entering LargeModuleGate, matching the multi-thread OOM crashes reported in RTX 4080 / NVIDIA 621.01: the corpus's two largest compute pipelines fail to compile (NVVM), a few take 8-16 GB and up to 26 min, and --jobs 14 crashed the driver #884 and Coordinating who works on what (35) (moved to #6214) #6089.
  2. The static estimate (512 B/B from RADV) undercounted Windows vendor driver memory by 3–4x. Calibrations on NVIDIA 610.88 (vk_pipeline_check: a Windows memory estimate, and a warning when a module cannot fit (SHADER-904) #6429) and 621.01 showed 2.5–2.7 MiB mesh modules peaking ~2.8 GiB commit alone and ~12.5 GiB across 4 threads (~1,040–1,150 B/B), and 15 MiB compute modules exceeding 24 GiB (~1,670 B/B).
  3. Commit limits and retained driver memory were invisible to the gate. Windows available_memory_bytes() checked only startup ullAvailPhys (ignoring ullAvailPageFile commit/job headroom and retained memory across earlier compiles), and Windows release_free_memory() did not trim the CRT heap (_heapmin()).
  4. Follow-up to PR vk_pipeline_check: a Windows memory estimate, and a warning when a module cannot fit (SHADER-904) #6429 review (replaces the stale CONFLICTING branch without bundled gallery changes): addresses @wasonidas's three review points — prints oversized warnings after acquiring the gate (with "alone among large modules" in budget mode), pins per-platform kBytesPerSpirvByte directly in tests, and documents Windows behavior in docs/pipeline_check.md. Leaves vk_pipeline_check: the large-module memory budget reads macOS's free memory #5167 (macOS) and @Teerth1's LARGE-MODULE-GATE-OVERFLOW untouched.

Changes

  • runtime/test/large_module_gate.h:
    • Set kBytesPerSpirvByte = 2048 on _WIN32 (512 elsewhere), with overflow-safe large_module_estimate().
    • Add testable windows_available_memory(avail_phys, avail_pagefile) taking max(1, min(avail_phys, avail_pagefile)) so commit/pagefile and job caps bound the budget alongside physical RAM; call _heapmin() on _WIN32 in release_free_memory().
    • Add live OS headroom awareness to LargeModuleGate (active_budget() refreshes against current OS memory when idle inflight == 0 and checks live / 4 * 3 before admitting additional concurrent modules).
    • Add oversized_module_exceeds_memory() and format_oversized_module_warning() helpers with accurate exclusive vs budget-mode wording.
  • runtime/test/vk_pipeline_check.cpp:
    • Default budget mode (--large-parallel 0 when OS memory is known, unless --large-module-bytes is passed explicitly) to gate modules over 1 MiB (1048576 B), while keeping 4 MiB when serialized (--large-parallel 1 or unknown OS memory) and honoring explicit --large-module-bytes N (0 disables) including in --isolate child propagation.
    • Pass &leonida::available_memory_bytes as the live headroom callback in budget mode.
    • Print and flush the oversized-module warning after acquiring the compile lock/gate ticket inside the active in-flight section.
  • runtime/test/large_module_gate_test.cpp, tests/test_vk_pipeline_check_isolate.py, docs/pipeline_check.md:
    • Pin platform kBytesPerSpirvByte, windows_available_memory, live headroom budget shrink/recovery, concurrent admission cutoff, and warning formatting/wording; test default 1 MiB budget cutoff vs 4 MiB exclusive cutoff and explicit overrides end-to-end on vk_pipeline_check; update docs/pipeline_check.md.

Verification

Host: Windows 11, Intel Core Ultra 5 235 (14 threads), 31.4 GiB RAM, NVIDIA GeForce RTX 5060 Ti (driver 621.01), MSVC 14.51.36231 (CMake+Ninja and standalone cl /W4). Counts, byte sizes, timings, and memory numbers only; no game data.

  • Unit, CLI, and doc checks (after final edit):
    • ctest --test-dir runtime/build --output-on-failure -R "pipeline_cache_file|large_module_gate|pipeline_summary|pipeline_cache_snapshot|vk_pipeline_check_cli|vk_pipeline_check_stack" -> 6/6 passed (large_module_gate, vk_pipeline_check_cli, vk_pipeline_check_stack, pipeline_cache_file, pipeline_summary, pipeline_cache_snapshot).
    • Standalone cl /nologo /std:c++20 /EHsc /W4 ... runtime/test/large_module_gate_test.cpp -> 0 warnings, large_module_gate: ok.
    • python -I tests/test_vk_pipeline_check_index.py -> 11/11 OK.
    • python -I tests/test_vk_pipeline_check_isolate.py -> 11/11 OK (incl. default 1 MiB budget threshold, --large-parallel 1 4 MiB, explicit --large-module-bytes 2097152, and 0).
    • python -I tests/test_make_game_pipelines.py -> 13/13 OK.
    • python -I tests/test_make_game_pipeline_batches.py -> 15/15 OK.
    • python -I tests/test_make_game_pipeline_preflight.py -> 16/16 (1 skipped) OK.
    • python -I tests/test_wave64_pipeline_audit.py -> 14/14 OK.
    • python -I tests/test_make_game_argparse.py -> 36/36 OK.
    • python -I tests/test_vk_subgroup_info.py -> 53/53 OK.
    • python -I tests/test_build_runtime_fallback.py -> 8/8 OK.
    • python -I tests/test_docs_repo_paths.py -> 3/3 OK; tests/test_docs_cli_flags.py unknown_flags on docs/pipeline_check.md -> [] (whole-repo test_docs_cli_flags.py and test_docs_links.py and test_text_write_line_endings.py have pre-existing failures on main in unrelated files docs/embedded_shaders.md, docs/dev-tools.md, docs/gpu_test_results.md, tools/leonida_tui.py, and tools/wave_diff.py).
    • python -I scripts/check_no_game_data.py on all 5 changed files and tests/test_check_no_game_data.py (8/8 OK) -> clean.
    • Synthetic 4-shader compute run (--cache-feedback --stats ... --large-module-bytes 1): 4/4 ok (0 hits unseeded, 4 hits seeded).
  • Live GPU A/B on 1.0.2.1 corpus (--wave64-emulate, empty isolated NV cache via __GL_SHADER_DISK_CACHE_PATH + __GL_SHADER_DISK_CACHE=0, default --jobs 7):
    • [19639, 19647) (8 mesh shaders, 2.54–2.72 MiB each; both runs stopped at fixed measurement timeout):
      • main (dde82f27e) baseline (90 s cap): large modules (over 4194304 bytes) (0 of 8 gated) -> 14,993.4 MiB peak WS / 16,052.4 MiB peak commit.
      • This PR (first 90 s / full 240 s cap): large modules (over 1048576 bytes) (8 of 8 gated) -> 5,333.0 MiB peak WS / 5,623.0 MiB peak commit at 90 s (-64.4% WS / -65.0% commit), 5,465.1 MiB peak WS / 6,465.0 MiB peak commit across 240 s.
    • [20767, 20768) (17.20 MiB compute module, --jobs 1, 8 s check): prints needs about 36.9 GB, 21.6 GB available: it compiles alone among large modules and may not fit immediately after acquiring the gate.

AI-assisted.

…shold, live headroom, and 2048 B/B estimate (SHADER-904)
@TieruYT

TieruYT commented Nov 23, 2026

Copy link
Copy Markdown

Windows, synthetic inputs. Tested 64dcdd2.

I compiled the large_module_gate C++ test with x64 MSVC (/O2 /std:c++17) and ran the executable 20 consecutive times, all successful. That covers the eight-thread admission test, shrinking and recovering simulated live headroom, and oversized-module admission. This was a CPU-side gate test; I did not measure driver memory peaks or compile a retail shader.

AI-assisted verification · GPT-6.2 Astra Medium

@KoertLichtendonk

Copy link
Copy Markdown
Contributor

Coordinator note: SHADER-904 already has an open PR, #6429 by @zxcvqwerasdf (opened 14:15 UTC), so this looks like a duplicate. Please compare the two and either close this one or say here what it adds. The maintainer decides which one is merged.

@memorypressure

Copy link
Copy Markdown

Tested head 64dcdd2 vs main dde82f2, rechecked vs dfe4e4a (clean). Python side: test_vk_pipeline_check_isolate skips entirely without the built binary (honest Ran 0 + skip, identical on main) — CI is the execution gate (5 checks pending). C++ review: kBytesPerSpirvByte=2048 under _WIN32 with the saturating large_module_estimate (no UINT64 overflow path), windows_available_memory = max(1, min(phys, pagefile)) consistent with the 0=unknown convention in both helpers, _heapmin() on _WIN32, budget refresh only at inflight==0 with the 3/4 check — all coherent with the body. check_no_game_data clean on all five files. Overlap: pairwise merge-tree vs #2366 (same two files) is CLEAN — different regions, later merger may need a trivial rebase. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@InCaseOf

Copy link
Copy Markdown

Tested 64dcdd2 on RX 5700 XT (RDNA1, gfx1010, RADV NAVI10), Mesa 26.3.1, Linux 6.18: pass

  • Runtime rebuilt from this branch (it changes C++).
  • ctest: 100% tests passed out of 61.
  • scripts/run_gpu_tests.py: 213/241 passed, 28 skipped, 0 failed.
  • w64_graphics.py over all fixtures: 29/29 ok.
  • tests/test_vk_pipeline_check_isolate.py: Ran 11 tests in 0.615s OK

LLVM llvm-mc 23.1.5, SPIRV-Tools v2026.4, Python 3.14; test programs built from main e36d4c4 unless rebuilt for the PR as noted. main e36d4c4 on the same GPU: run_gpu_tests.py 212/240, 28 skipped, 0 failed; w64_graphics.py 29/29; semantic suite 2 files failing (test_image_atomics_guard, test_image_store_d16). No game files.

AI-assisted (Claude Code).

@matheusfermiano-source

Copy link
Copy Markdown

Tested 64dcdd2cb (the PR's diff applied on main dde82f2), full python -I scripts/run_gpu_tests.py, each GPU compared with main on the same machine, CachyOS Linux: pass.

This PR changes runtime/test C++, so runtime/ was built from the PR's own tree for these runs (ctest 64/64 there).

GPU Driver main this PR Difference
AMD Radeon 660M (RDNA2 iGPU, gfx1035, Ryzen 5 7535HS), subgroup 32..64 RADV, Mesa 26.3.1 225/241 passed, 16 skipped 225/241 passed, 16 skipped same results as main
NVIDIA GeForce RTX 3050 Laptop (Ampere), subgroup 32 NVIDIA 620.73.04 192/241 passed, 48 skipped 192/241 passed, 48 skipped fails on main too: ms_wave_info_s3 (#6172)
  • Radeon 660M wave64 checks (PR applied, test programs built from main, which gives 225/241 emulated and 29 ok): LEONIDA_W64_EMULATE=1 run_gpu_tests.py 225/241 passed, 16 skipped; runtime/test/shaders/w64_graphics.py 29 ok, 0 SKIP, 0 other.
  • ctest -R "pipeline_cache_file|large_module_gate|pipeline_summary|pipeline_cache_snapshot|vk_pipeline_check_cli|vk_pipeline_check_stack" in this PR's Linux build: 5 matched, 5 passed. tests/test_vk_pipeline_check_index.py 11 passed, tests/test_vk_pipeline_check_isolate.py 11 passed, tests/test_make_game_pipelines.py 13 passed.
  • This PR's vk_pipeline_check over the suite's 247 translated shaders on both GPUs: "large modules (over 1048576 bytes)" (main: 4194304), cs: 113 modules ok, 0 failed, and on the RTX 3050 cs pipelines: 113 ok, 0 failed.

No game files. AI-assisted (Claude Code).

@slint6614-dev

Copy link
Copy Markdown
Contributor

AMD Windows check of 64dcdd2cb (AI-assisted). Windows 11 (10.0.26300), MSVC 2022 (Ninja, RelWithDebInfo), Python 3.12, Vulkan SDK 1.4.363.1, AMD Adrenalin 26.11.2: Radeon RX 9070 (RDNA4, Vulkan driver 2.0.416, LLPC) and Ryzen 9600X iGPU "AMD Radeon(TM) Graphics" (RDNA2 gfx1036, driver 2.0.353). Built large_module_gate_test and vk_pipeline_check from this branch.

  • large_module_gate_test.exe: large_module_gate: ok, exit 0.
  • py -3.12 -I tests/test_vk_pipeline_check_isolate.py -v with the built binary (so it actually runs, unlike the Linux skip): 11 tests OK with LEONIDA_VK_DEVICE="RX 9070" (24 s) and with the iGPU (18 s).
  • Negative control: the same test with LEONIDA_VK_PIPELINE_CHECK pointing at a vk_pipeline_check.exe built from an older main (561b65a): test_large_module_default_threshold_and_explicit_overrides fails (1 failure, 10 OK), so the test covers the new threshold.

@Wasler

Wasler commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@KoertLichtendonk Thanks for flagging the overlap — leaving this PR open for the maintainer alongside #6429 (the maintainer decides which lands). Here is the exact comparison of #6429 vs #8001:

Status of #6429

  • Currently CONFLICTING (0262f9681, untouched since 14:15 UTC) and accidentally bundles two unrelated gallery commits/files (tools/gallery.py, tests/test_gallery.py from #5963).
  • Three review items raised by @wasonidas on #6429 remain unaddressed (14:46 UTC).
  • Only changes kBytesPerSpirvByte = 2048 on _WIN32 and prints a pre-gate warning; leaves 1–4 MiB batches ungated, uses ullAvailPhys alone (ignoring commit limits), does not trim Windows CRT heap, and never re-reads OS headroom after startup.

What #8001 adds (clean MERGEABLE, no unrelated files)

  1. Fixes all three #6429 review points (@wasonidas):
    • Clean diff scoped strictly to large_module_gate, vk_pipeline_check, tests, and docs/pipeline_check.md.
    • Prints and flushes the oversized warning after acquiring the lock/ticket inside the active section, using "alone among large modules" in budget mode ("alone" only in exclusive mode) and only when actually serialized among large modules (large_exclusive || large_parallel == 0).
    • Documents Windows 2048 vs 512 elsewhere and explicitly pins per-platform constants + overflow-safe large_module_estimate() in large_module_gate_test.cpp.
  2. Fixes the 1–4 MiB wave64-emulated gate bypass (vk_pipeline_check.cpp):
    • #6429's 4 MiB threshold skips all 4,331 corpus modules in 1–4 MiB (including all 820 1–4 MiB mesh shaders; only 728 shaders exceed 4 MiB).
    • #8001 lowers the default cutoff to 1 MiB (1048576 B) in budget mode (--large-parallel 0 when OS memory is readable and --large-module-bytes isn't passed explicitly), while keeping 4 MiB for --large-parallel 1.
    • Measured A/B on Windows 11 / RTX 5060 Ti (621.01, 31.4 GiB RAM, default --jobs 7, isolated empty NV cache) on [19639, 19647) (8 wave64-emulated mesh shaders at 2.54–2.72 MiB each): 14,993.4 MiB WS / 16,052.4 MiB commit (0 gated under 4 MiB) → 5,333.0 MiB WS / 5,623.0 MiB commit at 90 s (-64.4% WS / -65.0% commit; 5,465.1 / 6,465.0 MiB over 240 s).
  3. Commit headroom, heap trim, and live OS memory backpressure (large_module_gate.h):
    • windows_available_memory() bounds _WIN32 available_memory_bytes() to max(1, min(ullAvailPhys, ullAvailPageFile)) (covering tight pagefile and job-object commit limits alongside physical RAM).
    • Calls _heapmin() in release_free_memory() on _WIN32.
    • Adds live OS headroom checks to LargeModuleGate (active_budget() refreshes on inflight == 0 and checks live / 4 * 3 before concurrent admission) so driver-retained memory shrinks concurrency automatically instead of relying solely on startup free RAM.

Five independent reviews/tests (@TieruYT, @memorypressure, @InCaseOf, @matheusfermiano-source, @slint6614-dev) have verified #8001 across Windows MSVC NVIDIA/AMD and Linux RADV/NVIDIA with no regressions (check_no_game_data clean, negative control confirmed). AI-assisted.

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