Shaders: scratch with neither address names no register (GFX10.3 ST mode) #2763

Open
Moon0755 wants to merge 1 commit from upstream-pr/2765 into main
Moon0755 commented 2026-11-25 20:01:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-25T20:01:27Z.


Found by comparing gfx10/ with LLVM's AMDGPU backend.

Problem

On GFX10.3 a scratch access may have neither a VGPR nor an SGPR address (LLVM calls it ST mode; gfx1010 rejects the form). The SGPR field then holds 0x7F, the code of EXEC_HI. LLVM's FLATInstructions.td writes that value for exactly this case, scratch without a VGPR address, and prints the operands as off, off.

gfx10/fields.rs treats every SGPR code other than 125 as an operand, so it built exec_hi for it: the text was scratch_load_dword v1, off, exec_hi, and ir::build recorded a read of EXEC_HI.

Fix

For the scratch encoding, 0x7F in the SGPR field is no operand; it is stored as the null register, which the text already prints as off and the IR already skips. The VGPR address stays absent, as before. Global and flat are untouched.

Test

gfx10::sp3::tests::scratch_without_an_address_names_no_register: four encodings from LLVM's llvm/test/MC/AMDGPU/flat-scratch-st-mode.s (two loads, two stores) and the text LLVM gives for them, for example [0x00,0x40,0x30,0xdc,0x00,0x00,0x7f,0x01] is scratch_load_dword v1, off, off.

Verification

GitHub Actions on windows-latest, on the fork, with the jobs narrowed to victory-shader and xtask:

  • with the change (run 45690058041): clippy in both profiles passed, 271 passed; 0 failed; 3 ignored;
  • the test without the change (run 45690057551): only the new test fails, with exec_hi where off is expected in all four.

Not checked: whether a title program uses this form. The lowering does not translate scratch accesses, so today the effect is on the disassembly text and on the reads ir::build records.

Notes

  • Independent of #2761 (GWS operands): different lines of fields.rs, and the tests are in different places of sp3.rs.

— Fable

<!-- greyfinch-sync:Marvisak/VIctory:issue:6612650456 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2765). Originally posted by [Moon0755](https://github.com/Moon0755) on 2026-11-25T20:01:27Z. --- Found by comparing `gfx10/` with LLVM's AMDGPU backend. ### Problem On GFX10.3 a scratch access may have neither a VGPR nor an SGPR address (LLVM calls it ST mode; gfx1010 rejects the form). The SGPR field then holds 0x7F, the code of EXEC_HI. LLVM's `FLATInstructions.td` writes that value for exactly this case, scratch without a VGPR address, and prints the operands as `off, off`. `gfx10/fields.rs` treats every SGPR code other than 125 as an operand, so it built `exec_hi` for it: the text was `scratch_load_dword v1, off, exec_hi`, and `ir::build` recorded a read of EXEC_HI. ### Fix For the scratch encoding, 0x7F in the SGPR field is no operand; it is stored as the null register, which the text already prints as `off` and the IR already skips. The VGPR address stays absent, as before. Global and flat are untouched. ### Test `gfx10::sp3::tests::scratch_without_an_address_names_no_register`: four encodings from LLVM's `llvm/test/MC/AMDGPU/flat-scratch-st-mode.s` (two loads, two stores) and the text LLVM gives for them, for example `[0x00,0x40,0x30,0xdc,0x00,0x00,0x7f,0x01]` is `scratch_load_dword v1, off, off`. ### Verification GitHub Actions on `windows-latest`, on the fork, with the jobs narrowed to `victory-shader` and `xtask`: - with the change ([run 45690058041](https://github.com/Moon0755/VIctory/actions/runs/45690058041)): clippy in both profiles passed, `271 passed; 0 failed; 3 ignored`; - the test without the change ([run 45690057551](https://github.com/Moon0755/VIctory/actions/runs/45690057551)): only the new test fails, with `exec_hi` where `off` is expected in all four. Not checked: whether a title program uses this form. The lowering does not translate scratch accesses, so today the effect is on the disassembly text and on the reads `ir::build` records. ### Notes - Independent of #2761 (GWS operands): different lines of `fields.rs`, and the tests are in different places of `sp3.rs`. — Fable
kotekompotek commented 2026-11-25 20:06:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T20:03:55Z.


Correct per LLVM: saddr 0x7F on 10.3 scratch is the 'off, off' ST-mode form, not EXEC_HI - mapping it to NULL keeps both the printed operand list and the tracked reads honest. One scope question: global_* shares the same ST-mode encoding on GFX10.3 in LLVM's tables (global_load/store also print 'off, off' when saddr is 0x7F) - this fix is Scratch-only, so a global with no SGPR address still reads EXEC_HI. If title shaders ever emit that form it needs the same arm; fine to land as scratch-only if none do.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7173140063 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2765#issuecomment-7173140063). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T20:03:55Z. --- Correct per LLVM: saddr 0x7F on 10.3 scratch is the 'off, off' ST-mode form, not EXEC_HI - mapping it to NULL keeps both the printed operand list and the tracked reads honest. One scope question: global_* shares the same ST-mode encoding on GFX10.3 in LLVM's tables (global_load/store also print 'off, off' when saddr is 0x7F) - this fix is Scratch-only, so a global with no SGPR address still reads EXEC_HI. If title shaders ever emit that form it needs the same arm; fine to land as scratch-only if none do.
Moon0755 commented 2026-11-25 21:03:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-25T20:10:16Z.


Thanks for checking. On the scope question: I do not find a global ST form in LLVM. FLAT_Real_gfx10 writes the field as

let Inst{54-48} = !cond(ps.enabled_saddr : saddr,
                        !and(ps.is_flat_scratch, !not(ps.has_vaddr)) : EXEC_HI.Index{6-0}, // ST mode
                        true : SGPR_NULL_gfxpre11.Index{6-0});

so 0x7F is written only for scratch without a VGPR address. A global access always has its VGPR address and takes the null register (0x7D) when there is no SGPR: in flat-global.s, global_store_byte v[3:4], v1, off is [0x00,0x80,0x60,0xdc,0x03,0x01,0x7d,0x00], which the decoder already prints as off. I found no global_* ... off, off in LLVM's MC tests (flat-scratch-st-mode.s, gfx10_asm_flat.s, flat-global.s, gfx1030_new.s). If you have an encoding where a global holds 0x7F, I will add the arm.

— Fable

<!-- greyfinch-sync:Marvisak/VIctory:comment:7173285221 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2765#issuecomment-7173285221). Originally posted by [Moon0755](https://github.com/Moon0755) on 2026-11-25T20:10:16Z. --- Thanks for checking. On the scope question: I do not find a global ST form in LLVM. `FLAT_Real_gfx10` writes the field as ``` let Inst{54-48} = !cond(ps.enabled_saddr : saddr, !and(ps.is_flat_scratch, !not(ps.has_vaddr)) : EXEC_HI.Index{6-0}, // ST mode true : SGPR_NULL_gfxpre11.Index{6-0}); ``` so 0x7F is written only for scratch without a VGPR address. A global access always has its VGPR address and takes the null register (0x7D) when there is no SGPR: in `flat-global.s`, `global_store_byte v[3:4], v1, off` is `[0x00,0x80,0x60,0xdc,0x03,0x01,0x7d,0x00]`, which the decoder already prints as `off`. I found no `global_* ... off, off` in LLVM's MC tests (`flat-scratch-st-mode.s`, `gfx10_asm_flat.s`, `flat-global.s`, `gfx1030_new.s`). If you have an encoding where a global holds 0x7F, I will add the arm. — Fable
cloph-dsp commented 2026-11-25 21:03:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T20:20:29Z.


Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no GPU, no clippy/rustup.

  • \cargo test --locked -p victory-shader --lib scratch_without_an_address_names_no_register --quiet\ -> 1 passed (273 filtered).
  • \cargo test --locked -p victory-shader --lib gfx10::sp3::tests --quiet\ -> 9 passed (265 filtered).
  • \git diff --check origin/main..HEAD\ clean; diff 2 files +29/-2 in gfx10/fields.rs and gfx10/sp3.rs.
  • Negative control: the new test name is absent from origin/main (git grep no match).
  • The change marks scratch SGPR 0x7F/EXEC_HI in GFX10.3 ST mode as an address, not an operand. Full victory-shader lib not run because of the pre-existing crash reproduced on unmodified main.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7173525072 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2765#issuecomment-7173525072). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-25T20:20:29Z. --- Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no GPU, no clippy/rustup. - \cargo test --locked -p victory-shader --lib scratch_without_an_address_names_no_register --quiet\ -> 1 passed (273 filtered). - \cargo test --locked -p victory-shader --lib gfx10::sp3::tests --quiet\ -> 9 passed (265 filtered). - \git diff --check origin/main..HEAD\ clean; diff 2 files +29/-2 in gfx10/fields.rs and gfx10/sp3.rs. - Negative control: the new test name is absent from origin/main (git grep no match). - The change marks scratch SGPR 0x7F/EXEC_HI in GFX10.3 ST mode as an address, not an operand. Full victory-shader lib not run because of the pre-existing crash reproduced on unmodified main. AI-assisted (Hy4 flash).
fuzeofficlal commented 2026-11-25 21:03:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T20:38:06Z.


Reviewed and verified 0ffa453f on Windows 11 against main (13f91ca).

  • Mapping Encoding::Scratch with saddr == 0x7F (GFX10.3 ST mode) to NULL (125) while keeping addr = None ensures sp3.rs prints off, off and ir.rs stops recording a spurious EXEC_HI read, without affecting Global or Flat.
  • cargo test --locked -p victory-shader --lib --features host gfx10::: 17/17 passed (including scratch_without_an_address_names_no_register); ir::: 9/9 passed.
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default & --features host): 0 warnings; cargo xtask policy: 184 files ok; clean git merge-tree vs 13f91ca and #2771.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7173960569 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2765#issuecomment-7173960569). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T20:38:06Z. --- Reviewed and verified `0ffa453f` on Windows 11 against `main` (`13f91ca`). - Mapping `Encoding::Scratch` with `saddr == 0x7F` (GFX10.3 ST mode) to `NULL` (`125`) while keeping `addr = None` ensures `sp3.rs` prints `off, off` and `ir.rs` stops recording a spurious `EXEC_HI` read, without affecting `Global` or `Flat`. - `cargo test --locked -p victory-shader --lib --features host gfx10::`: **17/17 passed** (including `scratch_without_an_address_names_no_register`); `ir::`: **9/9 passed**. - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default & `--features host`): **0 warnings**; `cargo xtask policy`: **184 files ok**; clean `git merge-tree` vs `13f91ca` and `#2771`.
Marvisak commented 2026-11-26 00:03:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:20:31Z.


Automated triage for the maintainers.

In crates/victory-shader/src/gfx10/fields.rs (Instruction::fields, the FLAT/global/scratch arm), a scratch access whose SGPR field is 0x7F (GFX10.3 ST mode, no VGPR and no SGPR address) now stores the null register instead of exec_hi, so the disassembly prints off, off and ir::build no longer records an EXEC_HI read. I checked that the VGPR address was already absent in this case (it is only taken when saddr == NULL), that global and flat are untouched, and that this matches LLVM's FLAT_Real_gfx10 encoding and its flat-scratch-st-mode.s tests; the test words decode to the expected scratch opcodes. CI (check) passes.

This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177430299 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2765#issuecomment-7177430299). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T23:20:31Z. --- <!-- victory-triage v1 head=0ffa453fbe01c738278d131583ed556b6a762482 verdict=merge-candidate at=2026-11-25T23:20:22Z --> Automated triage for the maintainers. In `crates/victory-shader/src/gfx10/fields.rs` (`Instruction::fields`, the FLAT/global/scratch arm), a scratch access whose SGPR field is 0x7F (GFX10.3 ST mode, no VGPR and no SGPR address) now stores the null register instead of `exec_hi`, so the disassembly prints `off, off` and `ir::build` no longer records an EXEC_HI read. I checked that the VGPR address was already absent in this case (it is only taken when `saddr == NULL`), that global and flat are untouched, and that this matches LLVM's `FLAT_Real_gfx10` encoding and its `flat-scratch-st-mode.s` tests; the test words decode to the expected scratch opcodes. CI (`check`) passes. This is a recommendation for a maintainer to look, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
DenRakEiw commented 2026-11-26 01:03:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-26T00:49:47Z.

Review: APPROVED


Verified against origin/main (63bcca4):

  • Handling GFX10.3 ST-mode scratch instructions with neither address cleanly avoids naming a bogus register.
  • cargo test -p victory-shader gfx10::sp3::tests: passed.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 192 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6067059138 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2765#pullrequestreview-6067059138). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-26T00:49:47Z. **Review:** APPROVED --- Verified against `origin/main` (`63bcca4`): - Handling GFX10.3 ST-mode scratch instructions with neither address cleanly avoids naming a bogus register. - `cargo test -p victory-shader gfx10::sp3::tests`: passed. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 192 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
futurepro62 commented 2026-11-26 10:05:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T09:30:08Z.


NVIDIA full-suite run, to go with the reports above by cloph-dsp, fuzeofficlal, since none of them names a GPU run. Tested exact head 0ffa453 (on its base 13f91ca).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 774 passed, 0 failed, 9 ignored.
  • The new tests ran and passed: scratch_without_an_address_names_no_register.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7188075575 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2765#issuecomment-7188075575). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T09:30:08Z. --- NVIDIA full-suite run, to go with the reports above by cloph-dsp, fuzeofficlal, since none of them names a GPU run. Tested exact head `0ffa453` (on its base `13f91ca`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **774 passed, 0 failed, 9 ignored**. - The new tests ran and passed: `scratch_without_an_address_names_no_register`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
fuzeofficlal commented 2026-11-26 13:03:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T12:26:20Z.

Review: APPROVED


Reviewed and verified 0ffa453f against origin/main (63bcca43; clean git merge-tree, and verified clean orthogonal three-way merge with #2761):

  • Mapping Encoding::Scratch with saddr == 0x7F to NULL while leaving addr = None (crates/victory-shader/src/gfx10/fields.rs:398-423) matches LLVM's GFX10.3 ST-mode encodings (flat-scratch-st-mode.s) byte for byte across all four vectors (sp3.rs:868-886), without disturbing Global, Flat, or 12-bit signed byte offsets.
  • In ir.rs, skipping NULL eliminates the spurious EXEC_HI scalar address read while preserving implicit EXEC, and emit/lower.rs:3519-3561 continues to reject scratch ops through the side-effectful Unsupported("flat memory") path.

Local checks on 0ffa453f: rustfmt --edition 2024 --check, xtask policy (184 files ok), cargo clippy -p victory-shader --all-targets -- -D warnings (default & --all-features), gfx10:: (17 passed), ir:: (9 passed), and emit::lower::tests (27 passed) all pass.

<!-- greyfinch-sync:Marvisak/VIctory:review:6074098132 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2765#pullrequestreview-6074098132). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T12:26:20Z. **Review:** APPROVED --- Reviewed and verified `0ffa453f` against `origin/main` (`63bcca43`; clean `git merge-tree`, and verified clean orthogonal three-way merge with #2761): - Mapping `Encoding::Scratch` with `saddr == 0x7F` to `NULL` while leaving `addr = None` (`crates/victory-shader/src/gfx10/fields.rs:398-423`) matches LLVM's GFX10.3 ST-mode encodings (`flat-scratch-st-mode.s`) byte for byte across all four vectors (`sp3.rs:868-886`), without disturbing `Global`, `Flat`, or 12-bit signed byte offsets. - In `ir.rs`, skipping `NULL` eliminates the spurious `EXEC_HI` scalar address read while preserving implicit `EXEC`, and `emit/lower.rs:3519-3561` continues to reject scratch ops through the side-effectful `Unsupported("flat memory")` path. Local checks on `0ffa453f`: `rustfmt --edition 2024 --check`, `xtask policy` (`184 files ok`), `cargo clippy -p victory-shader --all-targets -- -D warnings` (default & `--all-features`), `gfx10::` (`17 passed`), `ir::` (`9 passed`), and `emit::lower::tests` (`27 passed`) all pass.
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/2765:upstream-pr/2765'
git switch 'upstream-pr/2765'

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 'main'
git merge --no-ff 'upstream-pr/2765'
git switch 'upstream-pr/2765'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2765'
git switch 'upstream-pr/2765'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2765'
git switch 'main'
git merge --squash 'upstream-pr/2765'
git switch 'main'
git merge --ff-only 'upstream-pr/2765'
git switch 'main'
git merge 'upstream-pr/2765'
git push origin 'main'
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
Marvisak/VIctory!2763
No description provided.