Shaders: lower ds_inc_u32, ds_inc_rtn_u32, ds_dec_u32, and ds_dec_rtn_u32 in pure 32-bit DXIL #2113

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

@⁠geiyiliyabumo on GitHub · 2026-11-25 05:13 UTC · original
geiyiliyabumo:feat/shader-ds-inc-dec → main · +183 −5 · 2 files · 1 commits · open

Summary

  • Lowers GFX10 LDS wrap-around atomic instructions ds_inc_u32, ds_inc_rtn_u32, ds_dec_u32, and ds_dec_rtn_u32 in crates/victory-shader/src/emit/lower.rs (fn ds) using an EXEC-guarded pure 32-bit cmpxchg retry loop without enabling Int64 / WIDE_OPS.
  • Implements exact unsigned wrap semantics: inc wraps old >= limit to 0 (else old + 1), dec wraps old == 0 || old > limit to limit (else old - 1), and _rtn returns the previous LDS value while inactive lanes preserve vdst.
  • Adds synthetic DXIL-validation and GPU execution tests in crates/victory-shader/src/emit/semantics_tests.rs covering wrap sequences, unsigned edge cases (old > limit), non-returning updates, EXEC-masked destination preservation, and 32-/31-lane concurrent LDS contention, asserting Int64 is not set.

Verification

  • cargo xtask policy: passed
  • cargo clippy -p victory-shader --tests -- -D warnings: passed
  • cargo test -p victory-shader --lib lds_wrap_atomics -- --test-threads=1 with Microsoft dxil.dll: passed on AMD Radeon RX 9060 XT (RDNA4) and Microsoft Basic Render Driver (WARP) (0 hardware/WARP mismatches, multi-lane LDS contention passed on both)
  • Zero game files or game-derived data used (synthetic tests only).
**@⁠geiyiliyabumo** on GitHub · 2026-11-25 05:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2113) `geiyiliyabumo:feat/shader-ds-inc-dec` → `main` · +183 −5 · 2 files · 1 commits · open ## Summary - Lowers GFX10 LDS wrap-around atomic instructions `ds_inc_u32`, `ds_inc_rtn_u32`, `ds_dec_u32`, and `ds_dec_rtn_u32` in `crates/victory-shader/src/emit/lower.rs` (`fn ds`) using an `EXEC`-guarded pure 32-bit `cmpxchg` retry loop without enabling `Int64` / `WIDE_OPS`. - Implements exact unsigned wrap semantics: `inc` wraps `old >= limit` to `0` (else `old + 1`), `dec` wraps `old == 0 || old > limit` to `limit` (else `old - 1`), and `_rtn` returns the previous LDS value while inactive lanes preserve `vdst`. - Adds synthetic DXIL-validation and GPU execution tests in `crates/victory-shader/src/emit/semantics_tests.rs` covering wrap sequences, unsigned edge cases (`old > limit`), non-returning updates, `EXEC`-masked destination preservation, and 32-/31-lane concurrent LDS contention, asserting `Int64` is not set. ## Verification - `cargo xtask policy`: passed - `cargo clippy -p victory-shader --tests -- -D warnings`: passed - `cargo test -p victory-shader --lib lds_wrap_atomics -- --test-threads=1` with Microsoft `dxil.dll`: passed on **AMD Radeon RX 9060 XT (RDNA4)** and **Microsoft Basic Render Driver (WARP)** (0 hardware/WARP mismatches, multi-lane LDS contention passed on both) - Zero game files or game-derived data used (synthetic tests only).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:55:13 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 05:19 UTC · original

Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at 9c8b9a2. victory-shader: 247 passed, 3 failed, 3 ignored. The new lds_wrap_atomics_update_and_return_under_exec, lds_wrap_atomics_serialize_contending_lanes and lds_wrap_atomics_validate_as_32_bit_dxil pass. The 3 failures are #1744's NVIDIA failures on main. Same as main on this hardware.

I also read the lowering. inc stores old >= data ? 0 : old + 1 and dec stores old == 0 || old > data ? data : old - 1, both returning old through a compare-exchange retry. That matches ds_inc_u32 / ds_dec_u32.

Overlap, from reading: #1606 (open, conflicting with main) also lowers inc_u32 and dec_u32 among the other LDS atomics.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-25 05:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2113#issuecomment-7153666273) Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at `9c8b9a2`. `victory-shader`: 247 passed, 3 failed, 3 ignored. The new `lds_wrap_atomics_update_and_return_under_exec`, `lds_wrap_atomics_serialize_contending_lanes` and `lds_wrap_atomics_validate_as_32_bit_dxil` pass. The 3 failures are #1744's NVIDIA failures on `main`. Same as `main` on this hardware. I also read the lowering. `inc` stores `old >= data ? 0 : old + 1` and `dec` stores `old == 0 || old > data ? data : old - 1`, both returning `old` through a compare-exchange retry. That matches `ds_inc_u32` / `ds_dec_u32`. Overlap, from reading: #1606 (open, conflicting with `main`) also lowers `inc_u32` and `dec_u32` among the other LDS atomics. AI-assisted (Claude Code).
Author
Owner

@⁠fiestorra on GitHub · 2026-11-25 06:09 UTC · original

Read the semantics (they look right), measured the three-way collision, and one question about the spin

I checked the arithmetic against the rule this instruction family has, and it matches what I understand of the ISA:

  • ds_inc_u32: value >= limit → 0, else value + 1;
  • ds_dec_u32: value == 0 || value > limit → limit, else value - 1.

which is exactly the shape of the IUGE / is_zero | IUGT comparisons in the patch, with the _rtn variants returning the observed value and the EXEC guard keeping inactive lanes out. cargo test -p victory-shader --locked --lib on this branch: 250 passed, 3 ignored, 33 of them ds_*.

One thing I would like to see in the tests, because it is where a wrong reading survives everything else: the boundary pairs. inc at value == limit and inc at limit - 1, and the same for dec at limit, limit + 1 and 0. >= versus > is one character in the code and the difference is invisible in any test that stays away from the boundary.

The question I have is about the retry loop. The patch loops on cmpxchg until it succeeds:

m.terminate(retry, Term::CondBr(success, done, retry));

unbounded. On the console this is one LDS atomic instruction, and the host's version is a compare-exchange spin. Under contention that is normal GPU practice and it terminates — but "normal practice" and "bounded" are not the same thing, and the failure mode when it does not is a TDR and a removed device, which is much harder to diagnose than a wrong value: the log says the device was removed and nothing about which shader was spinning. I am not asking for a bound for its own sake; I am asking for the decision to be written down, either as a comment ("the loop terminates because the address is not contended across the wave" if that is the argument) or as a bounded retry with a defined fallback.

A merge-order thing, measured: this pull request and #2116 and #2119 are three changes to the same fn ds and to the same test file, and they conflict with each other:

#2113 + #2116  → conflict in crates/victory-shader/src/emit/lower.rs, …/semantics_tests.rs
#2113 + #2119  → conflict in crates/victory-shader/src/emit/semantics_tests.rs

Each is clean against main, so nothing is broken — but whoever merges two of them will spend the time resolving, and the three are the same family from the same author in the same week. If it were mine I would land them as one pull request (they share all their reasoning), or state an order here so the next one is rebased onto the previous instead of being discovered at merge time.

No game data is involved: instruction names and test counts.

Written with an AI assistant.

**@⁠fiestorra** on GitHub · 2026-11-25 06:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/2113#issuecomment-7154500301) **Read the semantics (they look right), measured the three-way collision, and one question about the spin** I checked the arithmetic against the rule this instruction family has, and it matches what I understand of the ISA: - `ds_inc_u32`: `value >= limit → 0`, else `value + 1`; - `ds_dec_u32`: `value == 0 || value > limit → limit`, else `value - 1`. which is exactly the shape of the `IUGE` / `is_zero | IUGT` comparisons in the patch, with the `_rtn` variants returning the observed value and the `EXEC` guard keeping inactive lanes out. `cargo test -p victory-shader --locked --lib` on this branch: **250 passed, 3 ignored**, 33 of them `ds_*`. One thing I would like to see in the tests, because it is where a wrong reading survives everything else: **the boundary pairs**. `inc` at `value == limit` and `inc` at `limit - 1`, and the same for `dec` at `limit`, `limit + 1` and `0`. `>=` versus `>` is one character in the code and the difference is invisible in any test that stays away from the boundary. **The question I have is about the retry loop.** The patch loops on `cmpxchg` until it succeeds: ```rust m.terminate(retry, Term::CondBr(success, done, retry)); ``` unbounded. On the console this is one LDS atomic instruction, and the host's version is a compare-exchange spin. Under contention that is normal GPU practice and it terminates — but "normal practice" and "bounded" are not the same thing, and the failure mode when it does not is a **TDR and a removed device**, which is much harder to diagnose than a wrong value: the log says the device was removed and nothing about which shader was spinning. I am not asking for a bound for its own sake; I am asking for the decision to be written down, either as a comment ("the loop terminates because the address is not contended across the wave" if that is the argument) or as a bounded retry with a defined fallback. **A merge-order thing, measured:** this pull request and #2116 and #2119 are three changes to the same `fn ds` and to the same test file, and they **conflict with each other**: ``` #2113 + #2116 → conflict in crates/victory-shader/src/emit/lower.rs, …/semantics_tests.rs #2113 + #2119 → conflict in crates/victory-shader/src/emit/semantics_tests.rs ``` Each is clean against `main`, so nothing is broken — but whoever merges two of them will spend the time resolving, and the three are the same family from the same author in the same week. If it were mine I would land them as one pull request (they share all their reasoning), or state an order here so the next one is rebased onto the previous instead of being discovered at merge time. No game data is involved: instruction names and test counts. Written with an AI assistant.
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 08:46 UTC · original

Offline measurement on a retail dump

Result: no count change against main.

I merged head 9c8b9a2b onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 08:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/2113#issuecomment-7157445834) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 9c8b9a2b onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:42 UTC · original · edited 2026-11-25 22:21 UTC

Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main: main has moved since the last triage, and the branch now conflicts in crates/victory-shader/src/emit/lower.rs and crates/victory-shader/src/emit/semantics_tests.rs. It will be reviewed again once it is rebased onto current main.

Previous verdict for this head: merge candidate.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 10:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2113#issuecomment-7160072989) · edited 2026-11-25 22:21 UTC <!-- victory-triage v1 head=9c8b9a2b162a6ef57757b91eb6bb46e2b4087ee1 verdict=needs-rebase at=2026-11-25T22:24:00Z --> Automated triage for the maintainers. **Needs rebase.** This PR no longer merges cleanly into `main`: `main` has moved since the last triage, and the branch now conflicts in `crates/victory-shader/src/emit/lower.rs` and `crates/victory-shader/src/emit/semantics_tests.rs`. It will be reviewed again once it is rebased onto current `main`. Previous verdict for this head: merge candidate. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/semantics_tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2113/head:github-bot/gh-2113'
git switch 'github-bot/gh-2113'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2113'
git switch 'github-bot/gh-2113'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2113'
git switch 'github-bot/gh-2113'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2113'
git switch 'main'
git merge --squash 'github-bot/gh-2113'
git switch 'main'
git merge --ff-only 'github-bot/gh-2113'
git switch 'main'
git merge 'github-bot/gh-2113'
git push 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/Marvisak--VIctory!2113
No description provided.