Shaders: an atomic subtraction on group memory is a compare-exchange loop on NVIDIA (port of Marvisak/VIctory#3619) #1939

Manually merged
github merged 1 commit from github-bot/gh-1939 into main 2026-11-30 14:16:22 +00:00 AGit
Owner

@⁠futurepro62 on GitHub · 2026-11-29 03:35 UTC · original
futurepro62:atomic-sub-loops-nvidia → main · +247 −0 · 6 files · 1 commits · merged 2026-11-30 14:12 UTC

Port of Marvisak/VIctory#3619 by @⁠notquiteog (commit 47bdeca, author kept) onto this fork's main.

Problem

On NVIDIA cards one of the title's compute pipelines is never made: weatherParticle:CS_BeginUpdate (compute 7f61193d2c0e5f22). The driver refuses it with E_OUTOFMEMORY in every run:

WARN victory_gpu::pipeline::host: host pipeline refused error=Not enough memory resources are available to complete this operation. (0x8007000E) shaders=[compute 7f61193d2c0e5f22]

So its dispatches are dropped. Upstream found the cause: NVIDIA's compiler rejects an atomic subtraction on group-shared memory (atomicrmw sub, or atomicrmw add of a negated value). It isn't really memory.

Change (as upstream, adapted)

  • Module::atomic_subtracts (emit/bitcode.rs) rewrites those atomics as a compare-exchange loop with the same result. It runs in Shader::finish before the flags are read (emit/shader.rs).
  • Only on an NVIDIA adapter (vendor 0x10DE, host::default_adapter_vendor). VICTORY_ATOMIC_SUB_LOOP=1 or =0 overrides it. Other hosts get exactly today's code.
  • Adapted: this fork's shader_cache.rs differs from upstream's. host_settings() is added next to KEYED, and the switch goes into build()'s key bytes (atomic_sub_loops=), so translations made with and without it are never mixed. victory translate sets it only with VICTORY_ATOMIC_SUB_LOOP=1, because that tool doesn't link victory-gpu here.

Testing

On this branch (main 568c5e5 + this commit):

  • cargo build --release --locked -p victory: ok (the warnings are all in files this doesn't touch).
  • cargo test --release --locked -p victory-gpu --lib shader_cache: 4 passed, 0 failed (includes the keyed-switch tests).
  • cargo test --release --locked -p victory-shader --lib atomic: 8 passed, 0 failed.
  • Whole archive offline, same exe with the switch off and on, empty caches: VICTORY_HOST_WAVE=32 VICTORY_VIEW_LIMIT=1000000 [VICTORY_ATOMIC_SUB_LOOP=1] victory translate <game>/shaders.rpf --validate --list. Both give 25,616 validated and 0 validator errors. Exactly one program changes output, weatherParticle:CS_BeginUpdate (7f61193d2c0e5f22), and none is lost.

In game, on a local build that is not this branch. Fork main 9300875 (2026-11-28 morning) + #339 + #348 (with the fallback-order fix posted there) + this port (1f10565, the same change). Current main wasn't played. Earlier today it dropped 75 compute programs on this card (#1435), which made it a poor place to judge a weather effect; that count is down to 2 on 568c5e5.

  • RTX 5070 Ti 16 GB, driver as of 2026-11-28, Windows 11 26300, Series X profile, 4K, DLSS Performance, frame generation 4x.
  • victory warm --these <the pipeline> with the port: made ... 1. Without it, every attempt was refused.
  • After a full victory warm, about 76 minutes of play: no pipeline refused line, no device removal. Frame-time median 71.4 ms (the frame-generation pacing on this setup), mean 71.9 ms, as without the port.
  • Not compared: the weather particles side by side.

Upstream report from the same tests: Marvisak/VIctory#3619 (comment of 2026-11-29).

🤖 Generated with Claude Code

**@⁠futurepro62** on GitHub · 2026-11-29 03:35 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1939) `futurepro62:atomic-sub-loops-nvidia` → `main` · +247 −0 · 6 files · 1 commits · merged 2026-11-30 14:12 UTC Port of Marvisak/VIctory#3619 by @⁠notquiteog (commit `47bdeca`, author kept) onto this fork's `main`. ### Problem On NVIDIA cards one of the title's compute pipelines is never made: `weatherParticle:CS_BeginUpdate` (compute `7f61193d2c0e5f22`). The driver refuses it with `E_OUTOFMEMORY` in every run: ``` WARN victory_gpu::pipeline::host: host pipeline refused error=Not enough memory resources are available to complete this operation. (0x8007000E) shaders=[compute 7f61193d2c0e5f22] ``` So its dispatches are dropped. Upstream found the cause: NVIDIA's compiler rejects an atomic subtraction on group-shared memory (`atomicrmw sub`, or `atomicrmw add` of a negated value). It isn't really memory. ### Change (as upstream, adapted) - `Module::atomic_subtracts` (`emit/bitcode.rs`) rewrites those atomics as a compare-exchange loop with the same result. It runs in `Shader::finish` before the flags are read (`emit/shader.rs`). - Only on an NVIDIA adapter (vendor `0x10DE`, `host::default_adapter_vendor`). `VICTORY_ATOMIC_SUB_LOOP=1` or `=0` overrides it. Other hosts get exactly today's code. - **Adapted:** this fork's `shader_cache.rs` differs from upstream's. `host_settings()` is added next to `KEYED`, and the switch goes into `build()`'s key bytes (`atomic_sub_loops=`), so translations made with and without it are never mixed. `victory translate` sets it only with `VICTORY_ATOMIC_SUB_LOOP=1`, because that tool doesn't link `victory-gpu` here. ### Testing **On this branch (`main` `568c5e5` + this commit):** - `cargo build --release --locked -p victory`: ok (the warnings are all in files this doesn't touch). - `cargo test --release --locked -p victory-gpu --lib shader_cache`: 4 passed, 0 failed (includes the keyed-switch tests). - `cargo test --release --locked -p victory-shader --lib atomic`: 8 passed, 0 failed. - Whole archive offline, same exe with the switch off and on, empty caches: `VICTORY_HOST_WAVE=32 VICTORY_VIEW_LIMIT=1000000 [VICTORY_ATOMIC_SUB_LOOP=1] victory translate <game>/shaders.rpf --validate --list`. Both give 25,616 validated and 0 validator errors. Exactly one program changes output, `weatherParticle:CS_BeginUpdate` (`7f61193d2c0e5f22`), and none is lost. **In game, on a local build that is not this branch.** Fork `main` 9300875 (2026-11-28 morning) + #339 + #348 (with the fallback-order fix posted there) + this port (`1f10565`, the same change). Current `main` wasn't played. Earlier today it dropped 75 compute programs on this card (#1435), which made it a poor place to judge a weather effect; that count is down to 2 on `568c5e5`. - RTX 5070 Ti 16 GB, driver as of 2026-11-28, Windows 11 26300, Series X profile, 4K, DLSS Performance, frame generation 4x. - `victory warm --these <the pipeline>` with the port: `made ... 1`. Without it, every attempt was refused. - After a full `victory warm`, about 76 minutes of play: no `pipeline refused` line, no device removal. Frame-time median 71.4 ms (the frame-generation pacing on this setup), mean 71.9 ms, as without the port. - Not compared: the weather particles side by side. Upstream report from the same tests: Marvisak/VIctory#3619 (comment of 2026-11-29). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Ported from Marvisak/VIctory#3619 (47bdeca) onto this fork's nightly.
shader_cache.rs and emit/shader.rs kept this fork's versions; the switch
(host_settings, VICTORY_ATOMIC_SUB_LOOP) goes into build()'s key bytes,
and the rewrite runs before the module clean-up reads the flags. The
offline translate tool sets it only with VICTORY_ATOMIC_SUB_LOOP=1 (it
does not link victory-gpu here).

RTX 5070 Ti: weatherParticle CS_BeginUpdate (7f61193d2c0e5f22) is now
made by the driver (it was refused with E_OUTOFMEMORY every run). Whole
shaders.rpf with the switch on: only that program changes output; 25,570
validated as before.

(cherry picked from commit 47bdeca)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 03:39:04 +00:00
Author
Owner

@⁠tupacfan04 on GitHub · 2026-11-29 06:57 UTC · original

Tested on an RTX 5070 12 GB (driver 621.40, Windows 11): this cures the refusal here.

Cherry-picked onto main e1f2eb6 (author kept), fresh victory preload, then four 6-minute Series X runs (1440p, DLSS Quality, no frame generation, 30 cap, ray tracing on).

build runs host pipeline refused ... (0x8007000E) shaders=[compute 7f61193d2c0e5f22]
main e1f2eb6 1 1 line (as in every earlier run on this card)
main + this PR 4 0 lines in all four

Tests on the cherry-pick: GPU 628 passed, shader 399 passed (8 ignored, atomic_subtractions_become_loops among those passing), loader 50 passed.

Three notes from reading the diff, none blocking:

  • The vendor is read from adapter 0, not from the adapter the device was made on. On a laptop with an Intel adapter first and the NVIDIA card second, the rewrite would stay off unless VICTORY_ATOMIC_SUB_LOOP=1 is set.
  • It rewrites every atomic subtraction in the module, not only those on group memory. That is harmless as far as I can see, but the title says group memory.
  • atomic_sub_loops= joins the cache key, so everyone on NVIDIA needs a new preload after this lands. Worth a line in the release notes.

I could not judge the weather particles by eye (unattended runs), only that the pipeline is now made.

🤖 Generated with Claude Code

**@⁠tupacfan04** on GitHub · 2026-11-29 06:57 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1939#issuecomment-7252168715) Tested on an RTX 5070 12 GB (driver 621.40, Windows 11): this cures the refusal here. Cherry-picked onto main `e1f2eb6` (author kept), fresh `victory preload`, then four 6-minute Series X runs (1440p, DLSS Quality, no frame generation, 30 cap, ray tracing on). | build | runs | `host pipeline refused ... (0x8007000E) shaders=[compute 7f61193d2c0e5f22]` | |---|---|---| | main `e1f2eb6` | 1 | 1 line (as in every earlier run on this card) | | main + this PR | 4 | 0 lines in all four | Tests on the cherry-pick: GPU 628 passed, shader 399 passed (8 ignored, `atomic_subtractions_become_loops` among those passing), loader 50 passed. Three notes from reading the diff, none blocking: - The vendor is read from adapter 0, not from the adapter the device was made on. On a laptop with an Intel adapter first and the NVIDIA card second, the rewrite would stay off unless `VICTORY_ATOMIC_SUB_LOOP=1` is set. - It rewrites every atomic subtraction in the module, not only those on group memory. That is harmless as far as I can see, but the title says group memory. - `atomic_sub_loops=` joins the cache key, so everyone on NVIDIA needs a new preload after this lands. Worth a line in the release notes. I could not judge the weather particles by eye (unattended runs), only that the pipeline is now made. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@⁠nick0451 on GitHub · 2026-11-29 12:57 UTC · original

Heads-up for merging: merged onto current main 829188e9, this branch (b6ce5d7e) no longer builds:

error[E0599]: no variant, associated function, or constant named `Sub` found for enum `bitcode::Rmw`
   --> crates\victory-shader\src\emit\bitcode.rs:649:40   (and :683:37)

So Rmw::Sub isn't in main's bitcode::Rmw any more (or never was on this base). It needs a rebase onto main, or the variant added with it. (Seen while building a batch of shader PRs on main + one local fix; GitHub shows no conflict, because the break is semantic, not textual.)

🤖 Generated with Claude Code

**@⁠nick0451** on GitHub · 2026-11-29 12:57 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1939#issuecomment-7256180007) Heads-up for merging: merged onto current main `829188e9`, this branch (`b6ce5d7e`) no longer builds: ``` error[E0599]: no variant, associated function, or constant named `Sub` found for enum `bitcode::Rmw` --> crates\victory-shader\src\emit\bitcode.rs:649:40 (and :683:37) ``` So `Rmw::Sub` isn't in main's `bitcode::Rmw` any more (or never was on this base). It needs a rebase onto main, or the variant added with it. (Seen while building a batch of shader PRs on main + one local fix; GitHub shows no conflict, because the break is semantic, not textual.) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github manually merged commit d62c7d5567 into main 2026-11-30 14:16:22 +00:00
Author
Owner

@⁠tyr0nsur on GitHub · 2026-11-30 20:26 UTC · original

This PR shows as merged (merge commit d62c7d55, 2026-11-30 14:12), but that commit is not in the current main history (e1251c31), and atomic_subtracts / VICTORY_ATOMIC_SUB_LOOP are not in the tree. main has Lower::lds_sub for ds_sub_u32 instead, and Rmw::Sub is gone, so a cherry-pick of b6ce5d7e no longer builds. Meanwhile every RTX 50 log I could find from the v2026.11.30 builds still refuses 7f61193d2c0e5f22 with E_OUTOFMEMORY, while the one RTX 4060 run that asked for it made it. Details and the per-log table are in #4450.

AI-assisted with Claude Code.

**@⁠tyr0nsur** on GitHub · 2026-11-30 20:26 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1939#issuecomment-7290919729) This PR shows as merged (merge commit `d62c7d55`, 2026-11-30 14:12), but that commit is not in the current `main` history (e1251c31), and `atomic_subtracts` / `VICTORY_ATOMIC_SUB_LOOP` are not in the tree. `main` has `Lower::lds_sub` for `ds_sub_u32` instead, and `Rmw::Sub` is gone, so a cherry-pick of b6ce5d7e no longer builds. Meanwhile every RTX 50 log I could find from the v2026.11.30 builds still refuses `7f61193d2c0e5f22` with `E_OUTOFMEMORY`, while the one RTX 4060 run that asked for it made it. Details and the per-log table are in #4450. AI-assisted with Claude Code.
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/trustno1-coder--VIctory-NVIDIA!1939
No description provided.