Shaders: s_min/s_max set SCC when S0 is chosen, not when the result is non-zero #634

Open
11run11 wants to merge 1 commit from upstream-pr/634 into a-publier
11run11 commented 2026-11-27 15:22:28 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by 11run11 on 2026-11-27T15:22:28Z.


s_min_{i,u}32 and s_max_{i,u}32 set SCC from their comparison: SCC = 1 when S0 is the value chosen. The lowering returned no SCC for them, so SCC fell back to "result ≠ 0". min(0, 5) therefore gave SCC 0 instead of 1, and max(0, 5) gave SCC 1 instead of 0. Any s_cselect, s_cbranch_scc* or carry-in that reads SCC after one of these took the wrong side.

The change

  • emit/lower.rs: the min/max arm returns its comparison as SCC (Some(t)), as the add/sub arms do with their carry.
  • TRANSLATOR_VERSION 2 → 3, because programs that read that SCC translate differently.
  • New test scalar_min_max_set_scc_when_the_first_source_is_chosen (emit/valu_tests.rs) checks all four ops on six input pairs, including results of 0 with S0 chosen and signed/unsigned edges. It fails before the change (hardware: s_min_i32 0x0, 0x5, left: 0, right: 1) and passes after.

Tested

Windows 11, RX 9070 XT, Rust 1.98.1.

  • cargo test -p victory-shader: 303 passed, 0 failed on hardware and WARP.
  • One existing test, size_tests::the_record_count_of_a_structured_buffer_read_by_index, crashes the test process (STATUS_ACCESS_VIOLATION) on this machine both with and without this change, so I skipped it. It looks like a driver issue, not related to this change.

The bug was first reported as AvatarManz #404. This implementation is written independently from the ISA definition.

Not included

v_readlane_b32/v_writelane_b32 should use only S1[4:0] or S1[5:0] as the lane. That touches the cross-wave exchange paths and needs separate work.

CI

Belobug's own ci.yml, unmodified, passes on this branch in my fork (Clippy with -D warnings, default and diagnostics tests): https://github.com/11run11/VIctory-Belobug-11run/actions/runs/46028870175 (commit 13388d9).

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:5529059318 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/634). Originally posted by [11run11](https://github.com/11run11) on 2026-11-27T15:22:28Z. --- `s_min_{i,u}32` and `s_max_{i,u}32` set SCC from their comparison: SCC = 1 when S0 is the value chosen. The lowering returned no SCC for them, so SCC fell back to "result ≠ 0". `min(0, 5)` therefore gave SCC 0 instead of 1, and `max(0, 5)` gave SCC 1 instead of 0. Any `s_cselect`, `s_cbranch_scc*` or carry-in that reads SCC after one of these took the wrong side. ## The change - `emit/lower.rs`: the min/max arm returns its comparison as SCC (`Some(t)`), as the add/sub arms do with their carry. - `TRANSLATOR_VERSION` 2 → 3, because programs that read that SCC translate differently. - New test `scalar_min_max_set_scc_when_the_first_source_is_chosen` (`emit/valu_tests.rs`) checks all four ops on six input pairs, including results of 0 with S0 chosen and signed/unsigned edges. It fails before the change (`hardware: s_min_i32 0x0, 0x5, left: 0, right: 1`) and passes after. ## Tested Windows 11, RX 9070 XT, Rust 1.98.1. - `cargo test -p victory-shader`: 303 passed, 0 failed on hardware and WARP. - One existing test, `size_tests::the_record_count_of_a_structured_buffer_read_by_index`, crashes the test process (`STATUS_ACCESS_VIOLATION`) on this machine both with and without this change, so I skipped it. It looks like a driver issue, not related to this change. The bug was first reported as AvatarManz #404. This implementation is written independently from the ISA definition. ## Not included `v_readlane_b32`/`v_writelane_b32` should use only S1[4:0] or S1[5:0] as the lane. That touches the cross-wave exchange paths and needs separate work. ## CI Belobug's own `ci.yml`, unmodified, passes on this branch in my fork (Clippy with `-D warnings`, default and diagnostics tests): https://github.com/11run11/VIctory-Belobug-11run/actions/runs/46028870175 (commit 13388d9).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/634:upstream-pr/634'
git switch 'upstream-pr/634'

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.

git switch 'a-publier'
git merge --no-ff 'upstream-pr/634'
git switch 'upstream-pr/634'
git rebase 'a-publier'
git switch 'a-publier'
git merge --ff-only 'upstream-pr/634'
git switch 'upstream-pr/634'
git rebase 'a-publier'
git switch 'a-publier'
git merge --no-ff 'upstream-pr/634'
git switch 'a-publier'
git merge --squash 'upstream-pr/634'
git switch 'a-publier'
git merge --ff-only 'upstream-pr/634'
git switch 'a-publier'
git merge 'upstream-pr/634'
git push origin 'a-publier'
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
Belobug/VIctory-Belobug-AMD!634
No description provided.