shader: lower buffer_atomic_sub as an add of the negated data (#363) #367

Manually merged
github merged 1 commit from github-bot/gh-364 into main 2026-11-27 16:13:16 +00:00 AGit
Owner

@⁠tiagonogueiraa-bit on GitHub · 2026-11-27 14:13 UTC · original
tiagonogueiraa-bit:shader-buffer-atomic-sub → main · +77 −2 · 3 files · 1 commits · merged 2026-11-27 16:04 UTC

Refs #366

Shape. buffer_atomic_sub was refused by name, because DXIL's AtomicBinOp has no subtraction.

Change. In Lower::buffer it is now atomicBinOp add (0) of 0 - data, marked by the ATOMIC_SUB sentinel. Modulo 2^32 the dword left is the same, and with glc the value returned is the old one either way. Every other buffer atomic is unchanged.

By-output corpus sweep. 12,020 containers from my own boot-to-menus run (Series S), native host options, main 905e7aa against this head:

Stage Gained Lost Changed Other reason now
compute 3 0 0 0
pixel 0 0 0 0
vertex 0 0 0 0

Gained: 49b8b58b93edb335, b1454a15c3e09497, dfc4a2c9e8be67ba.

Test. heap_tests::a_buffer_atomic_sub_leaves_the_difference_and_returns_the_old_value (victory-gpu, on Metal with MSC 4.0 beta 3). Lane 0 subtracts 3 from a raw UAV dword with glc and stores the returned value next to it:

  • 10 gives [7, 10];
  • 1 gives [0xfffffffe, 1].

On main it fails at translation.

Checks.

  • cargo test -p victory-shader -p victory-hle -p victory -p victory-gpu -p victory-metal -p xtask: 955 passed, 0 failed, 10 ignored.
  • Windows clippy -D warnings: clean.
  • cargo xtask policy: ok.

The 64-bit, image and global _sub forms are not covered, because no shader in the corpus uses them. docs/native-host.md has a short section on this. @⁠Olima34, for the board.

**@⁠tiagonogueiraa-bit** on GitHub · 2026-11-27 14:13 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/364) `tiagonogueiraa-bit:shader-buffer-atomic-sub` → `main` · +77 −2 · 3 files · 1 commits · merged 2026-11-27 16:04 UTC Refs #366 **Shape.** `buffer_atomic_sub` was refused by name, because DXIL's `AtomicBinOp` has no subtraction. **Change.** In `Lower::buffer` it is now `atomicBinOp` add (0) of `0 - data`, marked by the `ATOMIC_SUB` sentinel. Modulo 2^32 the dword left is the same, and with `glc` the value returned is the old one either way. Every other buffer atomic is unchanged. **By-output corpus sweep.** 12,020 containers from my own boot-to-menus run (Series S), native host options, main `905e7aa` against this head: | Stage | Gained | Lost | Changed | Other reason now | |---|---|---|---|---| | compute | 3 | 0 | 0 | 0 | | pixel | 0 | 0 | 0 | 0 | | vertex | 0 | 0 | 0 | 0 | Gained: `49b8b58b93edb335`, `b1454a15c3e09497`, `dfc4a2c9e8be67ba`. **Test.** `heap_tests::a_buffer_atomic_sub_leaves_the_difference_and_returns_the_old_value` (`victory-gpu`, on Metal with MSC 4.0 beta 3). Lane 0 subtracts 3 from a raw UAV dword with `glc` and stores the returned value next to it: - 10 gives `[7, 10]`; - 1 gives `[0xfffffffe, 1]`. On main it fails at translation. **Checks.** - `cargo test -p victory-shader -p victory-hle -p victory -p victory-gpu -p victory-metal -p xtask`: 955 passed, 0 failed, 10 ignored. - Windows clippy `-D warnings`: clean. - `cargo xtask policy`: ok. The 64-bit, image and global `_sub` forms are not covered, because no shader in the corpus uses them. `docs/native-host.md` has a short section on this. @⁠Olima34, for the board.
DXIL's AtomicBinOp has no subtraction, so buffer_atomic_sub was refused
by name. It is now atomicBinOp add of 0 - data. Modulo 2^32 that leaves
the same dword, and the old value returned with glc is the same.

Corpus sweep (12,020 shaders, main 905e7aa): 3 compute shaders gained,
no regressions, no changed outputs.

Refs #363
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 14:16:42 +00:00
github manually merged commit 3cd8b67f32 into main 2026-11-27 16:13:16 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 16:05 UTC · original

Merged in be7dc1b5 with the other shader PRs from tonight. Ran the tests (native arm64), Windows clippy, the policy check and a release build on the merged tree, and swept my full corpus of 21,600 shaders before and after: 0 lost, 352 newly translated, every changed output accounted for. I have not run the game on it yet. Thanks.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 16:05 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/364#issuecomment-7222838607) Merged in be7dc1b5 with the other shader PRs from tonight. Ran the tests (native arm64), Windows clippy, the policy check and a release build on the merged tree, and swept my full corpus of 21,600 shaders before and after: 0 lost, 352 newly translated, every changed output accounted for. I have not run the game on it yet. Thanks.
This discussion has been locked. Commenting is limited to contributors.
No description provided.