shaders(emit): rewrite LDS atomic subtracts for NVIDIA compiler #62

Manually merged
github merged 1 commit from gh-pr/62/head into gh-pr/62/base 2026-12-01 20:05:49 +00:00
Owner

@⁠Androtim on GitHub · 2026-11-28 18:17 UTC · original
Androtim:feat/iter76-nvidia-lds-atomic-sub → main · +215 −0 · 4 files · 1 commits · merged 2026-11-29 04:46 UTC

Summary

Rewrites group-shared (LDS) atomic subtracts in victory-shader (crates/victory-shader/src/emit/lower.rs and bitcode.rs) so NVIDIA drivers accept pipelines such as weatherParticle:CS_BeginUpdate:

  • Adds Module::negated in crates/victory-shader/src/emit/bitcode.rs to detect integer negations (sub 0, x).
  • In Lower::ds_atomic, rewrites both Rmw::Sub and Rmw::Add of a negated operand via Lower::lds_subtract, emitting x * waveReadLaneFirst.i32(-1) (flags::WAVE_OPS) and atomicrmw add instead of an atomic subtract that NVIDIA's driver (621.x) rejects with E_OUTOFMEMORY.
  • Adds hardware execution & DXIL validation test emit::lds_sub_tests::lds_subtracts_make_pipelines_and_give_the_console_old_values (crates/victory-shader/src/emit/lds_sub_tests.rs, wired in emit/mod.rs).

Upstream reference: Hasusmogus/cool_fox@5b8e20c (#129).

Rig Specs Tested On

  • CPU: Intel Core i7-13700F
  • GPU & VRAM: NVIDIA GeForce RTX 4060 Ti (8 GiB VRAM)
  • System RAM: 32 GiB
  • OS & GPU Driver: Windows 11 Build 26300, NVIDIA driver 32.0.16.2124

Run Settings & Profile

  • Build & Commit SHA: release & diagnostics @ 50b4481
  • Console Profile & Internal Resolution / Scale: series-s — quality (0.6666667, 540p internal / 960x540 captured frames)
  • Ray Tracing: off
  • Upscaling: DLSS quality (Streamline 2.14.16)
  • Frame Generation: off
  • Launcher Command / Preset & Extra VICTORY_* Overrides: verify-world.ps1 (WorldSeconds=75, AutoNudgeMenu, VICTORY_CACHE_DIR=D:\victory-data\cache-minivi)
  • Scene / Area & Session Length: Open-world exterior + character deck scene (first_world_frame=8664, 75s in-world / 15 windows, up to 11503 draws/frame)

Measurements & Verification

  • Base FPS (without Frame Gen): 11.4 fps median (9.95 fps mean, 0.9 fps min, 87.5 ms median frame time; +2.50 fps vs 8.9 fps baseline)
  • Frame-Gen FPS (if enabled): N/A (framegen=false)
  • VRAM / RAM Usage: 5775 MB peak (5743.5 MB median) / 6820 MB min budget (0 MB over budget; -89 MB vs 5864 MB baseline)
  • Texture Streaming & Pipeline Drops: 43980 uploaded, 1719 final waiting (-5402 vs 7121 baseline); 258 median pipeline drops (261.0 baseline); mapped() rate 33.17 ms/s (longest 15.2 ms); visually verified 19/24 lit frames (luma=105.86, edge_energy=7.01, 0.0% near-black/magenta; note run 1 hit transient 285 pipeline drops vs 261.0 baseline with 0 OUTOFMEMORY errors, rerun r2 passed 11/11 gates cleanly).
  • Crashes / DRED Resets: 0 (no_host_texture_errors=0, untranslated_shaders=2)
  • Automated Checks:
    • cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy (298 files ok)
    • cargo +1.98.1-x86_64-pc-windows-gnu test -p xtask --locked (6 passed; 0 failed)
    • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --locked -- -D warnings
    • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features diagnostics --locked -- -D warnings
    • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader --lib lds_sub_tests --locked -- --nocapture --test-threads=1 (1 passed; 0 failed on RTX 4060 Ti 32-lane hardware)
    • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader --lib wave64_tests --locked -- --test-threads=1 (12 passed; 0 failed)
    • cargo +1.98.1-x86_64-pc-windows-gnu build --release -p victory --bin victory --locked + objdump -p (Windows system DLLs only)
**@⁠Androtim** on GitHub · 2026-11-28 18:17 UTC · [original](https://github.com/Androtim/MiniVI/pull/62) `Androtim:feat/iter76-nvidia-lds-atomic-sub` → `main` · +215 −0 · 4 files · 1 commits · merged 2026-11-29 04:46 UTC ## Summary Rewrites group-shared (LDS) atomic subtracts in `victory-shader` (`crates/victory-shader/src/emit/lower.rs` and `bitcode.rs`) so NVIDIA drivers accept pipelines such as `weatherParticle:CS_BeginUpdate`: - Adds `Module::negated` in `crates/victory-shader/src/emit/bitcode.rs` to detect integer negations (`sub 0, x`). - In `Lower::ds_atomic`, rewrites both `Rmw::Sub` and `Rmw::Add` of a negated operand via `Lower::lds_subtract`, emitting `x * waveReadLaneFirst.i32(-1)` (`flags::WAVE_OPS`) and `atomicrmw add` instead of an atomic subtract that NVIDIA's driver (`621.x`) rejects with `E_OUTOFMEMORY`. - Adds hardware execution & DXIL validation test `emit::lds_sub_tests::lds_subtracts_make_pipelines_and_give_the_console_old_values` (`crates/victory-shader/src/emit/lds_sub_tests.rs`, wired in `emit/mod.rs`). Upstream reference: `Hasusmogus/cool_fox@5b8e20c` (#129). ## Rig Specs Tested On - **CPU:** Intel Core i7-13700F - **GPU & VRAM:** NVIDIA GeForce RTX 4060 Ti (8 GiB VRAM) - **System RAM:** 32 GiB - **OS & GPU Driver:** Windows 11 Build 26300, NVIDIA driver 32.0.16.2124 ## Run Settings & Profile - **Build & Commit SHA:** `release` & `diagnostics` @ `50b4481` - **Console Profile & Internal Resolution / Scale:** `series-s` — `quality` (`0.6666667`, 540p internal / 960x540 captured frames) - **Ray Tracing:** `off` - **Upscaling:** `DLSS quality` (Streamline 2.14.16) - **Frame Generation:** `off` - **Launcher Command / Preset & Extra `VICTORY_*` Overrides:** `verify-world.ps1` (`WorldSeconds=75`, `AutoNudgeMenu`, `VICTORY_CACHE_DIR=D:\victory-data\cache-minivi`) - **Scene / Area & Session Length:** Open-world exterior + character deck scene (`first_world_frame=8664`, 75s in-world / 15 windows, up to `11503` draws/frame) ## Measurements & Verification - **Base FPS (without Frame Gen):** `11.4 fps` median (`9.95 fps` mean, `0.9 fps` min, `87.5 ms` median frame time; `+2.50 fps` vs `8.9 fps` baseline) - **Frame-Gen FPS (if enabled):** N/A (`framegen=false`) - **VRAM / RAM Usage:** `5775 MB` peak (`5743.5 MB` median) / `6820 MB` min budget (`0 MB` over budget; `-89 MB` vs `5864 MB` baseline) - **Texture Streaming & Pipeline Drops:** `43980` uploaded, `1719` final waiting (`-5402` vs `7121` baseline); `258` median pipeline drops (`261.0` baseline); `mapped()` rate `33.17 ms/s` (longest `15.2 ms`); visually verified `19/24` lit frames (`luma=105.86`, `edge_energy=7.01`, `0.0%` near-black/magenta; note run 1 hit transient `285` pipeline drops vs `261.0` baseline with 0 `OUTOFMEMORY` errors, rerun `r2` passed `11/11` gates cleanly). - **Crashes / DRED Resets:** `0` (`no_host_texture_errors=0`, `untranslated_shaders=2`) - **Automated Checks:** - [x] `cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy` (`298 files ok`) - [x] `cargo +1.98.1-x86_64-pc-windows-gnu test -p xtask --locked` (`6 passed; 0 failed`) - [x] `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --locked -- -D warnings` - [x] `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features diagnostics --locked -- -D warnings` - [x] `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader --lib lds_sub_tests --locked -- --nocapture --test-threads=1` (`1 passed; 0 failed` on RTX 4060 Ti 32-lane hardware) - [x] `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader --lib wave64_tests --locked -- --test-threads=1` (`12 passed; 0 failed`) - [x] `cargo +1.98.1-x86_64-pc-windows-gnu build --release -p victory --bin victory --locked` + `objdump -p` (Windows system DLLs only)
Rewrites group-shared (LDS) atomicrmw sub and atomicrmw add of integer negations (sub 0, x) as atomicrmw add of x * WaveReadLaneFirst(-1). NVIDIA driver 621.x refuses pipelines containing LDS atomic subtracts with E_OUTOFMEMORY (breaking weatherParticle CS_BeginUpdate). Adapted from Hasusmogus/cool_fox@5b8e20c (#129). Verified on RTX 4060 Ti via emit::lds_sub_tests and 75s open-world run (11/11 gates PASS).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 20:05:47 +00:00
github manually merged commit 50b4481136 into gh-pr/62/base 2026-12-01 20:05:49 +00:00
Author
Owner

@⁠Androtim on GitHub · 2026-11-28 18:35 UTC · original

Automated triage for the maintainers (not an approval).

Verdict: needs-gpu-test · CI (check): passing

Review Summary

Logic, DXIL emission, and test coverage look clean, and CI is passing. Because this PR modifies shader codegen (victory-shader) to work around an NVIDIA driver compiler failure on group-shared atomic subtracts, it should get a local real-GPU verification pass before merging.

Code Review Notes

  • crates/victory-shader/src/emit/bitcode.rs (Module::negated): Cleanly matches Op::Bin(Bin::Sub, zero, x) where self.int_value(zero) == Some(0) and returns Some(x).
  • crates/victory-shader/src/emit/lower.rs (Lower::ds_atomic, Lower::lds_subtract):
    • Intercepts both Some(Rmw::Sub) (ds_sub_u32 / ds_sub_rtn_u32) and Some(Rmw::Add) with a negated operand (self.s.m.negated(v0)), routing them to lds_subtract.
    • Emits waveReadLaneFirst.i32(-1) (opcode 118, Attr::NoUnwind), sets flags::WAVE_OPS, multiplies x * -1 (exact modular negation in 32-bit two's complement), and executes atomicrmw add. Since lds_subtract runs inside begin_guarded(guard), all active lanes participating in the atomic see -1.
  • crates/victory-shader/src/emit/lds_sub_tests.rs & emit/mod.rs:
    • Adds a targeted #[cfg(all(test, windows))] hardware + DXIL validation test covering both ds_sub_rtn_u32 and ds_add_rtn_u32 of 0 - (t + 1), verifying pipeline creation, final LDS value (START - total), and that returned old values form an exact chain.

Verification Needed

  • Run the new lds_sub_tests test and a local GPU smoke test (especially on NVIDIA 621.x+ drivers where weatherParticle:CS_BeginUpdate previously failed with E_OUTOFMEMORY, and sanity-check on non-NVIDIA GPUs if available).

Generated with Antigravity CLI (agy).

**@⁠Androtim** on GitHub · 2026-11-28 18:35 UTC · [original](https://github.com/Androtim/MiniVI/pull/62#issuecomment-7243904740) <!-- minivi-triage v1 head=50b44811364873c8cbc427a759eb11384171599c verdict=needs-gpu-test ci=passing at=2026-11-28T18:35:45Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Review Summary Logic, DXIL emission, and test coverage look clean, and CI is passing. Because this PR modifies shader codegen (`victory-shader`) to work around an NVIDIA driver compiler failure on group-shared atomic subtracts, it should get a local real-GPU verification pass before merging. ### Code Review Notes - **`crates/victory-shader/src/emit/bitcode.rs` (`Module::negated`)**: Cleanly matches `Op::Bin(Bin::Sub, zero, x)` where `self.int_value(zero) == Some(0)` and returns `Some(x)`. - **`crates/victory-shader/src/emit/lower.rs` (`Lower::ds_atomic`, `Lower::lds_subtract`)**: - Intercepts both `Some(Rmw::Sub)` (`ds_sub_u32` / `ds_sub_rtn_u32`) and `Some(Rmw::Add)` with a negated operand (`self.s.m.negated(v0)`), routing them to `lds_subtract`. - Emits `waveReadLaneFirst.i32(-1)` (opcode `118`, `Attr::NoUnwind`), sets `flags::WAVE_OPS`, multiplies `x * -1` (exact modular negation in 32-bit two's complement), and executes `atomicrmw add`. Since `lds_subtract` runs inside `begin_guarded(guard)`, all active lanes participating in the atomic see `-1`. - **`crates/victory-shader/src/emit/lds_sub_tests.rs` & `emit/mod.rs`**: - Adds a targeted `#[cfg(all(test, windows))]` hardware + DXIL validation test covering both `ds_sub_rtn_u32` and `ds_add_rtn_u32` of `0 - (t + 1)`, verifying pipeline creation, final LDS value (`START - total`), and that returned old values form an exact chain. ### Verification Needed - Run the new `lds_sub_tests` test and a local GPU smoke test (especially on NVIDIA 621.x+ drivers where `weatherParticle:CS_BeginUpdate` previously failed with `E_OUTOFMEMORY`, and sanity-check on non-NVIDIA GPUs if available). --- _Generated with Antigravity CLI (`agy`)._
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 04:46 UTC · original

Automated RTX 4060 Ti 8 GB A/B hardware verification passed (playtest/wave2 vs origin/main 1ab5d84):

  • Hardware cargo test (RTX 4060 Ti): victory-shader lds_sub (1/1), emit::wave64_tests (14/14), victory-gpu (505/505) — 520 passed, 0 failed.
  • Automated 45s in-world A/B (scripts/verify-world.ps1, DLSS Quality + golden autosave):
    • FPS: 13.45 fps (77.25 ms) vs 3.20 fps (308.8 ms) baseline (+10.25 fps / 4.2x faster)
    • Draws: max_draws=3122 vs 2994
    • Stability: 0 crashes / 0 DRED
    • VRAM: 6174 / 6903 MB (-25 MB vs baseline, 0 MB over budget)
    • Texture backlog: final_waiting=7638 vs 12258 (-4620)
    • Visual check: Clean rendered frames (frame-7969.png, frame-8409.png), no regressions vs origin/main.
**@⁠Androtim** on GitHub · 2026-11-29 04:46 UTC · [original](https://github.com/Androtim/MiniVI/pull/62#issuecomment-7250853391) Automated RTX 4060 Ti 8 GB A/B hardware verification passed (`playtest/wave2` vs `origin/main` `1ab5d84`): - **Hardware `cargo test` (RTX 4060 Ti):** `victory-shader` `lds_sub` (1/1), `emit::wave64_tests` (14/14), `victory-gpu` (505/505) — **520 passed, 0 failed**. - **Automated 45s in-world A/B (`scripts/verify-world.ps1`, DLSS Quality + golden autosave):** - **FPS:** **13.45 fps** (`77.25 ms`) vs **3.20 fps** (`308.8 ms`) baseline (**+10.25 fps / 4.2x faster**) - **Draws:** `max_draws=3122` vs `2994` - **Stability:** `0` crashes / `0` DRED - **VRAM:** `6174 / 6903 MB` (`-25 MB` vs baseline, `0 MB` over budget) - **Texture backlog:** `final_waiting=7638` vs `12258` (`-4620`) - **Visual check:** Clean rendered frames (`frame-7969.png`, `frame-8409.png`), no regressions vs `origin/main`.
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Androtim--MiniVI!62
No description provided.