Shaders: ds_sub_u32 adds the negated value (DXIL has no atomic subtraction); test the LDS atomics against their definitions #638

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

@⁠Gruzzberry on GitHub · 2026-11-25 03:40 UTC · original
Gruzzberry:gz/lds-atomics-isa → main · +107 −0 · 2 files · 1 commits · open

Summary

ds_sub_u32 and ds_sub_rtn_u32 were emitted as an LLVM atomicrmw sub. DXIL's atomic operations are add, and, or, xor, min, max, unsigned min and max, and exchange; there is no subtraction (the global atomics in the same file already add the negated value for that reason). With the shader's WaveSize left out so that WARP takes the pipeline at all (as #78 does for one-thread groups), the first dispatch of a program with ds_sub removes the WARP device (The GPU device instance has been suspended), which fails every GPU test after it in the process. The LDS path now adds 0 - value, which returns the same old value and leaves the same new one.

The title's shader pack contains no program with ds_sub (a victory translate run over all 26,148 programs counted none), so nothing the title does changes; this is a latent defect found by the test below, and any other title's shader with the instruction would have hit it.

What is in it

  • crates/victory-shader/src/emit/lower.rs: in the LDS atomic lowering, Rmw::Sub becomes Rmw::Add of 0 - v0. Eleven lines with the comment.
  • crates/victory-shader/src/emit/valu_tests.rs: lds_atomics_match_the_rdna2_definitions runs the 32-bit LDS atomics the translator lowers (add sub and or xor min_i32 max_i32 min_u32 max_u32 cmpst) on one dword over 128 cases (initial value and two operands from 0 1 2 5 0x7fffffff 0x80000000 0xfffffffe 0xffffffff), in both forms: without a result (the new content is read back) and _rtn (the old content comes back), against the definitions in Rust. Like the other one-thread LDS tests it runs on the hardware adapter only (WARP refuses the WaveSize(32) such a shader declares) and skips under VICTORY_WARP=1.

ds_rsub, ds_inc, ds_dec and ds_mskor have no lowering (the pipeline is refused with "an LDS operation"); they are not in the table and not touched here.

Tested

  • Machine: NVIDIA GeForce RTX 4070 12 GB, Intel i7-13700K, 64 GB, Windows 11 26200, Rust 1.98.1. Branch rebased on c96b4f2, one commit.
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean. Without --all-features it fails on c96b4f2 itself (placed_filler_twins in victory-gpu/src/resource.rs is never used); this change adds no warning.
  • cargo xtask policy: 169 files ok.
  • cargo test --workspace --locked on the RTX 4070 (default adapter, run directly): victory-shader 213 passed, 2 failed (emit::rect::tests::the_rectangle_stage_is_a_geometry_shader and rectangles_are_drawn_whole, the PSV0 validator issue of #61); every other crate passes. c96b4f2 without this change: 212 passed, the same 2 failed.
  • VICTORY_WARP=1 cargo test --workspace --locked (every GPU test on WARP): victory-shader 209 passed, 6 failed. The same 6 fail on c96b4f2 (208 passed): the two emit::rect ones, and ds_min_max_f32_order_floats_and_return_the_old_value, v_permlane16_and_x16_read_the_lanes_their_selectors_pick, whole_wave_f64_sum_and_cvt_f32_f64 and a_lane_mask_joined_with_a_number_is_read_as_the_number_it_is, which need a 32-lane device that VICTORY_WARP=1 takes away. No new failure.

Not tested

  • Whether the removed device happens on NVIDIA/AMD drivers too: the new test passes on the RTX 4070 with the change, and I did not run it there without it (no AMD card here). The rewrite is valid DXIL on every device either way.
  • The 64-bit LDS atomics and the float ones.

AI use

Claude Code (Claude Sonnet 5.5) found the defect with the test, wrote the change and the test, and ran the checks above on my machine. The reference functions follow the RDNA2 instruction set document. Nothing is taken from the game.

🤖 Generated with Claude Code

🤖 Generated with Claude Code

**@⁠Gruzzberry** on GitHub · 2026-11-25 03:40 UTC · [original](https://github.com/fxceless/victory-fork/pull/638) `Gruzzberry:gz/lds-atomics-isa` → `main` · +107 −0 · 2 files · 1 commits · open ## Summary `ds_sub_u32` and `ds_sub_rtn_u32` were emitted as an LLVM `atomicrmw sub`. DXIL's atomic operations are add, and, or, xor, min, max, unsigned min and max, and exchange; there is no subtraction (the global atomics in the same file already add the negated value for that reason). With the shader's `WaveSize` left out so that WARP takes the pipeline at all (as #78 does for one-thread groups), the first dispatch of a program with `ds_sub` removes the WARP device (`The GPU device instance has been suspended`), which fails every GPU test after it in the process. The LDS path now adds `0 - value`, which returns the same old value and leaves the same new one. The title's shader pack contains no program with `ds_sub` (a `victory translate` run over all 26,148 programs counted none), so nothing the title does changes; this is a latent defect found by the test below, and any other title's shader with the instruction would have hit it. ## What is in it - `crates/victory-shader/src/emit/lower.rs`: in the LDS atomic lowering, `Rmw::Sub` becomes `Rmw::Add` of `0 - v0`. Eleven lines with the comment. - `crates/victory-shader/src/emit/valu_tests.rs`: `lds_atomics_match_the_rdna2_definitions` runs the 32-bit LDS atomics the translator lowers (`add sub and or xor min_i32 max_i32 min_u32 max_u32 cmpst`) on one dword over 128 cases (initial value and two operands from `0 1 2 5 0x7fffffff 0x80000000 0xfffffffe 0xffffffff`), in both forms: without a result (the new content is read back) and `_rtn` (the old content comes back), against the definitions in Rust. Like the other one-thread LDS tests it runs on the hardware adapter only (WARP refuses the `WaveSize(32)` such a shader declares) and skips under `VICTORY_WARP=1`. `ds_rsub`, `ds_inc`, `ds_dec` and `ds_mskor` have no lowering (the pipeline is refused with "an LDS operation"); they are not in the table and not touched here. ## Tested - Machine: NVIDIA GeForce RTX 4070 12 GB, Intel i7-13700K, 64 GB, Windows 11 26200, Rust 1.98.1. Branch rebased on `c96b4f2`, one commit. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean. Without `--all-features` it fails on `c96b4f2` itself (`placed_filler_twins` in `victory-gpu/src/resource.rs` is never used); this change adds no warning. - `cargo xtask policy`: 169 files ok. - `cargo test --workspace --locked` on the RTX 4070 (default adapter, run directly): `victory-shader` 213 passed, 2 failed (`emit::rect::tests::the_rectangle_stage_is_a_geometry_shader` and `rectangles_are_drawn_whole`, the PSV0 validator issue of #61); every other crate passes. `c96b4f2` without this change: 212 passed, the same 2 failed. - `VICTORY_WARP=1 cargo test --workspace --locked` (every GPU test on WARP): `victory-shader` 209 passed, 6 failed. The same 6 fail on `c96b4f2` (208 passed): the two `emit::rect` ones, and `ds_min_max_f32_order_floats_and_return_the_old_value`, `v_permlane16_and_x16_read_the_lanes_their_selectors_pick`, `whole_wave_f64_sum_and_cvt_f32_f64` and `a_lane_mask_joined_with_a_number_is_read_as_the_number_it_is`, which need a 32-lane device that `VICTORY_WARP=1` takes away. No new failure. ## Not tested - Whether the removed device happens on NVIDIA/AMD drivers too: the new test passes on the RTX 4070 with the change, and I did not run it there without it (no AMD card here). The rewrite is valid DXIL on every device either way. - The 64-bit LDS atomics and the float ones. ## AI use Claude Code (Claude Sonnet 5.5) found the defect with the test, wrote the change and the test, and ran the checks above on my machine. The reference functions follow the RDNA2 instruction set document. Nothing is taken from the game. 🤖 Generated with [Claude Code](https://claude.com/claude-code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
ds_sub_u32 and ds_sub_rtn_u32 were emitted as an `atomicrmw sub`. DXIL's
atomic operations are add, and, or, xor, min, max, unsigned min and max and
exchange (the global atomics here already add the negated value for the same
reason). Run on WARP with the shader's WaveSize left out (as #78 does for
one-thread groups, so that WARP takes the pipeline at all), the first
dispatch of a ds_sub program removes the device (DXGI_ERROR_DEVICE_REMOVED),
which fails every GPU test after it in the process. The LDS path now adds
(0 - value), which returns the same old value and leaves the same new one.
The title's shader pack has no program with ds_sub (a translate run over all
26148 programs counted none), so nothing there changes; a shader of another
title with the instruction would have hit it.

The new test runs the 32-bit LDS atomics the translator lowers (add, sub,
and, or, xor, min and max signed and unsigned, compare-and-store) on one
dword over 128 cases of initial value and operands from the 32-bit edges, in
both the form without a result (the new content is read back) and the _rtn
form (the old content comes back), against the definitions in Rust. With
the change every operation agrees on WARP (the run above); before it the
first ds_sub case removes the device. Like the other single-thread LDS tests
it runs on the hardware adapter only (WARP refuses the WaveSize(32) such a
shader declares). ds_rsub, ds_inc, ds_dec and ds_mskor have no lowering and
are not in the table.

Assisted-by: Claude Code (Claude Sonnet 5.5)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:47:54 +00:00
Author
Owner

@⁠HAL9000RELOADED on GitHub · 2026-11-25 13:00 UTC · original

An AMD run of this PR's new tests. lds_atomics_match_the_rdna2_definitions passes (hardware only, as the description says) on a Radeon RX 7900 XTX (RDNA3), Windows 10 22H2, with the Agility SDK runtime from #402. They ran on the hardware device; WARP skips on this machine. Nothing else in the workspace regresses.

The setup, and the same run for eight related shader PRs, are in one table on #637: #637

**@⁠HAL9000RELOADED** on GitHub · 2026-11-25 13:00 UTC · [original](https://github.com/fxceless/victory-fork/pull/638#issuecomment-7163154714) An AMD run of this PR's new tests. `lds_atomics_match_the_rdna2_definitions` passes (hardware only, as the description says) on a Radeon RX 7900 XTX (RDNA3), Windows 10 22H2, with the Agility SDK runtime from #402. They ran on the hardware device; WARP skips on this machine. Nothing else in the workspace regresses. The setup, and the same run for eight related shader PRs, are in one table on #637: https://git.gtahub.st/github/fxceless--victory-fork/pulls/637
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/638/head:github-bot/gh-638'
git switch 'github-bot/gh-638'

Merge

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