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

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

@⁠Moon0755 on GitHub · 2026-11-25 20:01 UTC · original
Moon0755:fix/scratch-st-mode → main · +29 −2 · 2 files · 1 commits · open

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

**@⁠Moon0755** on GitHub · 2026-11-25 20:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2765) `Moon0755:fix/scratch-st-mode` → `main` · +29 −2 · 2 files · 1 commits · open 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
A scratch access with no VGPR and no SGPR address holds 0x7F, EXEC_HI's
code, in the SGPR field (LLVM writes it for exactly that case and prints
`off, off`). The decoder took it for an operand: the text named exec_hi
and the IR read it.

Test: `scratch_without_an_address_names_no_register`, encodings from
LLVM's flat-scratch-st-mode.s.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:13:43 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 20:03 UTC · original

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.

**@⁠kotekompotek** on GitHub · 2026-11-25 20:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2765#issuecomment-7173140063) 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.
Author
Owner

@⁠Moon0755 on GitHub · 2026-11-25 20:10 UTC · original

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

**@⁠Moon0755** on GitHub · 2026-11-25 20:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/2765#issuecomment-7173285221) 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
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-25 20:20 UTC · original

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).

**@⁠cloph-dsp** on GitHub · 2026-11-25 20:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2765#issuecomment-7173525072) 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).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 20:38 UTC · original

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.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 20:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2765#issuecomment-7173960569) 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`.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:20 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 23:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2765#issuecomment-7177430299) <!-- 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)_
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-26 00:49 UTC · original · approved these changes

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).

**@⁠DenRakEiw** on GitHub · 2026-11-26 00:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2765#pullrequestreview-6067059138) · **approved these changes** 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).
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 09:30 UTC · original

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.
**@⁠futurepro62** on GitHub · 2026-11-26 09:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2765#issuecomment-7188075575) 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.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 12:26 UTC · original · approved these changes

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 12:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2765#pullrequestreview-6074098132) · **approved these changes** 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 can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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