gpu: pipeline: honor --jobs and CPU count in repair_shaders instead of 768 MiB/proc RAM cap #465

Open
github-bot wants to merge 1 commit from github-bot/gh-465 into main AGit
Owner

@⁠lucamzanon on GitHub · 2026-12-04 14:06 UTC · original
lucamzanon:xmem/13-repair-shaders-jobs → main · +38 −3 · 2 files · 1 commits · open

Problem

When victory warm --jobs N runs known::repair_shaders(&dir), it currently ignores the --jobs argument and calls super::prepared::jobs(), which budgets 768 MiB per child pipeline-compiler process on top of an 8 GiB reserve:

(available_physical_ram() - 8 GiB) / 768 MiB

When run.sh play launches Wine inside systemd-run -p MemoryMax=... (e.g. MemoryMax=9846M on Linux), Wine reports ~8–9 GiB of available physical RAM, so prepared::jobs() collapses to 1. As a result, repair_shaders() spawns only 1 worker thread even when --jobs 8 was passed — turning a ~25,000-shader repair pass from ~35 seconds into ~8–10 minutes on a single core (observed live via ps -L on victory.exe warm --jobs 8).

Unlike child pipeline compiler processes, repair_shaders() runs lightweight in-process shader translation threads.

Change

  • Pass jobs: Option<usize> from apps/victory/src/warm.rs into known::repair_shaders(&dir, jobs).
  • Pick worker count via repair_workers_from(jobs, env_jobs, cpus):
    1. Explicit --jobs N (clamped 1..=64), else
    2. VICTORY_WARM_JOBS (clamped 1..=64), else
    3. std::thread::available_parallelism() (clamped 1..=16).
  • Early-return Ok(()) if ranges.is_empty().
  • Add unit test pipeline::known::tests::repair_workers_honors_jobs_then_env_then_cpus.

Verification

  • cargo check --locked -p victory (Windows MSVC cross-compile): clean.
  • victory-gpu unit tests under Wine (pipeline::known::tests): 6/6 pass.
  • cargo clippy --locked --no-deps --all-targets: 0 warnings in known.rs, no new warnings in warm.rs.
**@⁠lucamzanon** on GitHub · 2026-12-04 14:06 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/465) `lucamzanon:xmem/13-repair-shaders-jobs` → `main` · +38 −3 · 2 files · 1 commits · open ### Problem When `victory warm --jobs N` runs `known::repair_shaders(&dir)`, it currently ignores the `--jobs` argument and calls `super::prepared::jobs()`, which budgets **768 MiB per child pipeline-compiler process** on top of an 8 GiB reserve: ```rust (available_physical_ram() - 8 GiB) / 768 MiB ``` When `run.sh play` launches Wine inside `systemd-run -p MemoryMax=...` (e.g. `MemoryMax=9846M` on Linux), Wine reports ~8–9 GiB of available physical RAM, so `prepared::jobs()` collapses to **1**. As a result, `repair_shaders()` spawns **only 1 worker thread** even when `--jobs 8` was passed — turning a ~25,000-shader repair pass from ~35 seconds into ~8–10 minutes on a single core (observed live via `ps -L` on `victory.exe warm --jobs 8`). Unlike child pipeline compiler processes, `repair_shaders()` runs lightweight in-process shader translation threads. ### Change - Pass `jobs: Option<usize>` from `apps/victory/src/warm.rs` into `known::repair_shaders(&dir, jobs)`. - Pick worker count via `repair_workers_from(jobs, env_jobs, cpus)`: 1. Explicit `--jobs N` (clamped `1..=64`), else 2. `VICTORY_WARM_JOBS` (clamped `1..=64`), else 3. `std::thread::available_parallelism()` (clamped `1..=16`). - Early-return `Ok(())` if `ranges.is_empty()`. - Add unit test `pipeline::known::tests::repair_workers_honors_jobs_then_env_then_cpus`. ### Verification - `cargo check --locked -p victory` (Windows MSVC cross-compile): clean. - `victory-gpu` unit tests under Wine (`pipeline::known::tests`): **6/6 pass**. - `cargo clippy --locked --no-deps --all-targets`: 0 warnings in `known.rs`, no new warnings in `warm.rs`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 14:09:08 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-04 14:49 UTC · original

Checked 2dd0bfa. The count logic is fine and the tests pass on native Windows (MSVC, not Wine). One thing I'm not sure the change covers, plus a few small notes.

What changes and where

  • On main, repair_shaders took its thread count from prepared::jobs(), the helper meant for pipeline processes: VICTORY_WARM_JOBS if set, else min(free RAM minus 8 GiB divided by 768 MiB, cpus / 2) clamped to 1..=16 (prepared.rs:331-347). Free RAM comes from GlobalMemoryStatusEx ullAvailPhys (host.rs:147-154). The cap came in with ca97da2 together with repair_shaders, and I found no reason given for it beyond the doc comment, which talks about processes (prepared.rs:327-330).
  • With the PR it's --jobs, then VICTORY_WARM_JOBS, then available_parallelism clamped to 1..=16 (known.rs:523-529, 552-554). Explicit values are clamped to 1..=64, so --jobs 0 gives 1.
  • The workers are still in-process std:🧵:scope threads (known.rs:558), no new process spawning. repair_shaders has one caller (warm.rs:70), so the signature change touches nothing else.
  • The pipeline process count doesn't change, warm.rs:116 still uses preparation_jobs() when --jobs is missing.
  • The warm --these children (warm.rs:417) return at warm.rs:54-55 before reaching repair_shaders, so the new default doesn't get multiplied per child process.

Pre-game path

run.rs:148 calls prepare_start, which spawns warm --jobs <prepared::jobs()> (prepared.rs:349-352). So under run.sh play the child already gets the RAM-capped number as an explicit --jobs. If that number is 1 under MemoryMax, the PR still runs repair on 1 thread there. The only difference from main is that the child uses the parent's value instead of computing it again. Where did the --jobs 8 in your ps -L run come from? From a manual victory warm --jobs 8, or did the parent pick 8 and the child then got less? VICTORY_WARM_JOBS is empty in run.conf.default (run.conf.default:288), and when set it already applied to repair on main through prepared.rs:333. If the goal is to fix the play case, the fix probably needs to go in prepared::warm or in how repair picks its default, not only in honoring --jobs.

Memory

The only path that really changes by default is a standalone warm with no --jobs, which is what run.sh warm runs (warm --used, run.sh:275). That's where the PR does give its speedup, because the RAM term can no longer drop the count to 1. But there the repair threads go from the RAM-capped half of the cores to all cores up to 16, and the memory guard is gone. I didn't measure how much memory a translation thread uses, and I didn't run a repair. There is a precedent though. victory shaders runs the same shader_cache::precompile on every logical core with no memory limit (translate.rs:449-450, d3d12x.rs:42, shader_cache.rs:165), so threads with no memory cap are already accepted for this work. The count tops out at 16 by default and 64 when set explicitly. The same available_parallelism call was already used on main (prepared.rs:339). Whatever it returns on a host with processor groups or restricted affinity, the result is clamped to 16 by default, so it can't push the count up.

Small things

  • The VICTORY_WARM_JOBS parsing is now duplicated (known.rs:524 and prepared.rs:333-338).
  • An explicit value over 64 is clamped for repair but not for processes (warm.rs:116 only does .max(1)). Harmless, just inconsistent.
  • The --jobs help at main.rs:131-132 and docs/SETTINGS.md:111-118 still describe it only as a process count.
  • The threads == 0 early return only fires on an empty catalogue, same as main's outcome.

Tests (native Windows, MSVC)

  • cargo test -p victory-gpu --lib pipeline gives 38 passed, 2 failed. The 2 are pipeline::host::tests::a_mesh_pipeline_loads_from_the_library and depth_bounds_pipeline_loads_and_filters_draws, known failures on main. repair_workers_honors_jobs_then_env_then_cpus passes.
  • I added a local test, not pushed, for usize::MAX, env "0", "", "-1", "100", --jobs 0 with env set, and 1 cpu. All gave what I expected (64, 1, cpus, cpus, 64, 1, 1). known::tests has 7/7 passing with it.
  • cargo check --locked -p victory is clean, and the warm tests in the victory crate pass 4/4.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-04 14:49 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/465#issuecomment-7414908833) Checked 2dd0bfa. The count logic is fine and the tests pass on native Windows (MSVC, not Wine). One thing I'm not sure the change covers, plus a few small notes. What changes and where - On main, repair_shaders took its thread count from prepared::jobs(), the helper meant for pipeline processes: VICTORY_WARM_JOBS if set, else min(free RAM minus 8 GiB divided by 768 MiB, cpus / 2) clamped to 1..=16 (prepared.rs:331-347). Free RAM comes from GlobalMemoryStatusEx ullAvailPhys (host.rs:147-154). The cap came in with ca97da2 together with repair_shaders, and I found no reason given for it beyond the doc comment, which talks about processes (prepared.rs:327-330). - With the PR it's --jobs, then VICTORY_WARM_JOBS, then available_parallelism clamped to 1..=16 (known.rs:523-529, 552-554). Explicit values are clamped to 1..=64, so --jobs 0 gives 1. - The workers are still in-process std::thread::scope threads (known.rs:558), no new process spawning. repair_shaders has one caller (warm.rs:70), so the signature change touches nothing else. - The pipeline process count doesn't change, warm.rs:116 still uses preparation_jobs() when --jobs is missing. - The `warm --these` children (warm.rs:417) return at warm.rs:54-55 before reaching repair_shaders, so the new default doesn't get multiplied per child process. Pre-game path run.rs:148 calls prepare_start, which spawns `warm --jobs <prepared::jobs()>` (prepared.rs:349-352). So under run.sh play the child already gets the RAM-capped number as an explicit --jobs. If that number is 1 under MemoryMax, the PR still runs repair on 1 thread there. The only difference from main is that the child uses the parent's value instead of computing it again. Where did the --jobs 8 in your ps -L run come from? From a manual `victory warm --jobs 8`, or did the parent pick 8 and the child then got less? VICTORY_WARM_JOBS is empty in run.conf.default (run.conf.default:288), and when set it already applied to repair on main through prepared.rs:333. If the goal is to fix the play case, the fix probably needs to go in prepared::warm or in how repair picks its default, not only in honoring --jobs. Memory The only path that really changes by default is a standalone warm with no --jobs, which is what run.sh warm runs (`warm --used`, run.sh:275). That's where the PR does give its speedup, because the RAM term can no longer drop the count to 1. But there the repair threads go from the RAM-capped half of the cores to all cores up to 16, and the memory guard is gone. I didn't measure how much memory a translation thread uses, and I didn't run a repair. There is a precedent though. `victory shaders` runs the same shader_cache::precompile on every logical core with no memory limit (translate.rs:449-450, d3d12x.rs:42, shader_cache.rs:165), so threads with no memory cap are already accepted for this work. The count tops out at 16 by default and 64 when set explicitly. The same available_parallelism call was already used on main (prepared.rs:339). Whatever it returns on a host with processor groups or restricted affinity, the result is clamped to 16 by default, so it can't push the count up. Small things - The VICTORY_WARM_JOBS parsing is now duplicated (known.rs:524 and prepared.rs:333-338). - An explicit value over 64 is clamped for repair but not for processes (warm.rs:116 only does .max(1)). Harmless, just inconsistent. - The --jobs help at main.rs:131-132 and docs/SETTINGS.md:111-118 still describe it only as a process count. - The threads == 0 early return only fires on an empty catalogue, same as main's outcome. Tests (native Windows, MSVC) - cargo test -p victory-gpu --lib pipeline gives 38 passed, 2 failed. The 2 are pipeline::host::tests::a_mesh_pipeline_loads_from_the_library and depth_bounds_pipeline_loads_and_filters_draws, known failures on main. repair_workers_honors_jobs_then_env_then_cpus passes. - I added a local test, not pushed, for usize::MAX, env "0", "", "-1", "100", --jobs 0 with env set, and 1 cpu. All gave what I expected (64, 1, cpus, cpus, 64, 1, 1). known::tests has 7/7 passing with it. - cargo check --locked -p victory is clean, and the warm tests in the victory crate pass 4/4. AI-assisted: yes
Author
Owner

@⁠lucamzanon on GitHub · 2026-12-05 04:31 UTC · original

Thanks @⁠Kal0s-design for verifying on native Windows MSVC!

To answer your question about --jobs 8 in our ps -L capture: on our 46 GB Linux desktop, the parent victory.exe run computed prepared::jobs() = 8 (cpus/2) and spawned victory.exe warm --jobs 8, while inside the child repair_shaders() ignored --jobs 8 and recomputed prepared::jobs() under the systemd-run -p MemoryMax=9846M cgroup where Wine reported ~8–9 GiB free, collapsing to 1 thread.

You also raise a great point for hosts where even the parent sees low free RAM under MemoryMax and passes --jobs 1 to warm (since prepared::jobs() caps child PSO processes at 768 MiB each): in that case repair_shaders() would still get 1 from --jobs 1 unless repair ignores the process RAM cap or prepare_start passes separate counts. That said, honoring --jobs first already fixes the parent-passes-N / child-recomputes-1 bug and standalone run.sh warm (warm --used), while keeping explicit --jobs respected.

**@⁠lucamzanon** on GitHub · 2026-12-05 04:31 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/465#issuecomment-7431893795) Thanks @⁠Kal0s-design for verifying on native Windows MSVC! To answer your question about `--jobs 8` in our `ps -L` capture: on our 46 GB Linux desktop, the parent `victory.exe run` computed `prepared::jobs() = 8` (`cpus/2`) and spawned `victory.exe warm --jobs 8`, while inside the child `repair_shaders()` ignored `--jobs 8` and recomputed `prepared::jobs()` under the `systemd-run -p MemoryMax=9846M` cgroup where Wine reported ~8–9 GiB free, collapsing to **1 thread**. You also raise a great point for hosts where even the parent sees low free RAM under `MemoryMax` and passes `--jobs 1` to `warm` (since `prepared::jobs()` caps child PSO processes at 768 MiB each): in that case `repair_shaders()` would still get `1` from `--jobs 1` unless `repair` ignores the process RAM cap or `prepare_start` passes separate counts. That said, honoring `--jobs` first already fixes the parent-passes-N / child-recomputes-1 bug and standalone `run.sh warm` (`warm --used`), while keeping explicit `--jobs` respected.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/465/head:github-bot/gh-465'
git switch 'github-bot/gh-465'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-465'
git switch 'github-bot/gh-465'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-465'
git switch 'github-bot/gh-465'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-465'
git switch 'main'
git merge --squash 'github-bot/gh-465'
git switch 'main'
git merge --ff-only 'github-bot/gh-465'
git switch 'main'
git merge 'github-bot/gh-465'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.