Shaders: lower ds_inc_u32, ds_inc_rtn_u32, ds_dec_u32, and ds_dec_rtn_u32 in pure 32-bit DXIL #2111
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2113"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-25T05:13:26Z.
Summary
ds_inc_u32,ds_inc_rtn_u32,ds_dec_u32, andds_dec_rtn_u32incrates/victory-shader/src/emit/lower.rs(fn ds) using anEXEC-guarded pure 32-bitcmpxchgretry loop without enablingInt64/WIDE_OPS.incwrapsold >= limitto0(elseold + 1),decwrapsold == 0 || old > limittolimit(elseold - 1), and_rtnreturns the previous LDS value while inactive lanes preservevdst.crates/victory-shader/src/emit/semantics_tests.rscovering wrap sequences, unsigned edge cases (old > limit), non-returning updates,EXEC-masked destination preservation, and 32-/31-lane concurrent LDS contention, assertingInt64is not set.Verification
cargo xtask policy: passedcargo clippy -p victory-shader --tests -- -D warnings: passedcargo test -p victory-shader --lib lds_wrap_atomics -- --test-threads=1with Microsoftdxil.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)Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T05:18:09Z.
Review: APPROVED
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, withdxil.dllvalidator):cargo test -p victory-shader --lib lds_wrap_atomics_— 3 passed, 0 failed on both RTX 5090 hardware andVICTORY_D3D12_WARP=1(lds_wrap_atomics_update_and_return_under_execandlds_wrap_atomics_serialize_contending_lanes)cargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (183 files ok)Clean pure-32-bit DXIL lowering of
ds_inc_u32,ds_inc_rtn_u32,ds_dec_u32, andds_dec_rtn_u32verified under contention and EXEC masking on hardware and WARP. Looks great.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T05:19:48Z.
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 newlds_wrap_atomics_update_and_return_under_exec,lds_wrap_atomics_serialize_contending_lanesandlds_wrap_atomics_validate_as_32_bit_dxilpass. The 3 failures are #1744's NVIDIA failures onmain. Same asmainon this hardware.I also read the lowering.
incstoresold >= data ? 0 : old + 1anddecstoresold == 0 || old > data ? data : old - 1, both returningoldthrough a compare-exchange retry. That matchesds_inc_u32/ds_dec_u32.Overlap, from reading: #1606 (open, conflicting with
main) also lowersinc_u32anddec_u32among the other LDS atomics.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T06:33:46Z.
Review: APPROVED
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.144 passed / 0 failed / 2 ignored. ds_inc/dec_u32 + rtn variants lowered — atomic increment/decrement return-value ops.
Imported from Marvisak/VIctory. Originally posted by fiestorra on 2026-11-25T06:09:26Z.
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, elsevalue + 1;ds_dec_u32:value == 0 || value > limit → limit, elsevalue - 1.which is exactly the shape of the
IUGE/is_zero | IUGTcomparisons in the patch, with the_rtnvariants returning the observed value and theEXECguard keeping inactive lanes out.cargo test -p victory-shader --locked --libon this branch: 250 passed, 3 ignored, 33 of themds_*.One thing I would like to see in the tests, because it is where a wrong reading survives everything else: the boundary pairs.
incatvalue == limitandincatlimit - 1, and the same fordecatlimit,limit + 1and0.>=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
cmpxchguntil it succeeds: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 dsand to the same test file, and they conflict with each other: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.
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T08:46:07Z.
Offline measurement on a retail dump
Result: no count change against
main.I merged head
9c8b9a2bontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 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).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T10:42:50Z.
Automated triage for the maintainers.
Needs rebase. This PR no longer merges cleanly into
main:mainhas moved since the last triage, and the branch now conflicts incrates/victory-shader/src/emit/lower.rsandcrates/victory-shader/src/emit/semantics_tests.rs. It will be reviewed again once it is rebased onto currentmain.Previous verdict for this head: merge candidate.
Generated by Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.