Shaders: ds_sub_u32 adds the negated value (DXIL has no atomic subtraction); test the LDS atomics against their definitions #638
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!638
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-638"
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?
@Gruzzberry on GitHub · 2026-11-25 03:40 UTC · original
Gruzzberry:gz/lds-atomics-isa→main· +107 −0 · 2 files · 1 commits · openSummary
ds_sub_u32andds_sub_rtn_u32were emitted as an LLVMatomicrmw 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'sWaveSizeleft out so that WARP takes the pipeline at all (as #78 does for one-thread groups), the first dispatch of a program withds_subremoves the WARP device (The GPU device instance has been suspended), which fails every GPU test after it in the process. The LDS path now adds0 - value, which returns the same old value and leaves the same new one.The title's shader pack contains no program with
ds_sub(avictory translaterun 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::SubbecomesRmw::Addof0 - v0. Eleven lines with the comment.crates/victory-shader/src/emit/valu_tests.rs:lds_atomics_match_the_rdna2_definitionsruns 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 from0 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 theWaveSize(32)such a shader declares) and skips underVICTORY_WARP=1.ds_rsub,ds_inc,ds_decandds_mskorhave no lowering (the pipeline is refused with "an LDS operation"); they are not in the table and not touched here.Tested
c96b4f2, one commit.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean. Without--all-featuresit fails onc96b4f2itself (placed_filler_twinsinvictory-gpu/src/resource.rsis never used); this change adds no warning.cargo xtask policy: 169 files ok.cargo test --workspace --lockedon the RTX 4070 (default adapter, run directly):victory-shader213 passed, 2 failed (emit::rect::tests::the_rectangle_stage_is_a_geometry_shaderandrectangles_are_drawn_whole, the PSV0 validator issue of #61); every other crate passes.c96b4f2without this change: 212 passed, the same 2 failed.VICTORY_WARP=1 cargo test --workspace --locked(every GPU test on WARP):victory-shader209 passed, 6 failed. The same 6 fail onc96b4f2(208 passed): the twoemit::rectones, andds_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_f64anda_lane_mask_joined_with_a_number_is_read_as_the_number_it_is, which need a 32-lane device thatVICTORY_WARP=1takes away. No new failure.Not tested
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
@HAL9000RELOADED on GitHub · 2026-11-25 13:00 UTC · original
An AMD run of this PR's new tests.
lds_atomics_match_the_rdna2_definitionspasses (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
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.