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

Merged
tiagonogueiraa-bit merged 1 commit from upstream-pr/364 into main 2026-11-27 16:04:49 +00:00
tiagonogueiraa-bit commented 2026-11-27 14:13:35 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by tiagonogueiraa-bit on 2026-11-27T14:13:35Z.


Refs #363

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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5528076824 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/364). Originally posted by [tiagonogueiraa-bit](https://github.com/tiagonogueiraa-bit) on 2026-11-27T14:13:35Z. --- Refs #363 **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.
LakshanSivakumar commented 2026-11-27 16:05:11 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:05:11Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7222838607 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/364#issuecomment-7222838607). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T16:05:11Z. --- 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.
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
LakshanSivakumar/Native-Victory-macOS!364
No description provided.