Shaders: GFX10 FLAT offsets ignore bit 11 #1635

Merged
davutsimsekk merged 1 commit from upstream-pr/1636 into main 2026-11-25 00:23:28 +00:00
davutsimsekk commented 2026-11-24 20:13:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by davutsimsekk on 2026-11-24T20:13:55Z.


GFX10 FLAT offsets are 11-bit and unsigned; the hardware ignores bit 11, unlike GLOBAL/SCRATCH which use a 12-bit signed offset. The decoder already masked with 0x7FF, but nothing said why and nothing pinned it.

This adds the comment and a regression test: flat_load_dword v0, v[1:2] with 0xDC30_0800 decodes as offset 0, and 0xDC30_0FFF as 0x7FF. No behaviour change.

Test

flat_offsets_ignore_bit_eleven in gfx10::tests.

  • cargo test -p victory-shader --lib: 121 passed, 0 failed, 1 ignored
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean
  • rustfmt --edition 2024 --check on both changed files: clean
  • The title was not run.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6590521958 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1636). Originally posted by [davutsimsekk](https://github.com/davutsimsekk) on 2026-11-24T20:13:55Z. --- GFX10 FLAT offsets are 11-bit and unsigned; the hardware ignores bit 11, unlike GLOBAL/SCRATCH which use a 12-bit signed offset. The decoder already masked with `0x7FF`, but nothing said why and nothing pinned it. This adds the comment and a regression test: `flat_load_dword v0, v[1:2]` with `0xDC30_0800` decodes as offset 0, and `0xDC30_0FFF` as 0x7FF. No behaviour change. ## Test `flat_offsets_ignore_bit_eleven` in `gfx10::tests`. - `cargo test -p victory-shader --lib`: 121 passed, 0 failed, 1 ignored - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean - `rustfmt --edition 2024 --check` on both changed files: clean - The title was not run.
DenRakEiw commented 2026-11-24 21:02:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T20:26:25Z.

Review: APPROVED


Verified locally merged onto origin/main (Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-shader --lib gfx10:: — 13 passed, 0 failed (including flat_offsets_use_all_twelve_bits)
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok

Clean 12-bit FLAT offset mask fix with targeted regression test. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6046818098 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1636#pullrequestreview-6046818098). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-24T20:26:25Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory-shader --lib gfx10::` — 13 passed, 0 failed (including `flat_offsets_use_all_twelve_bits`) - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok Clean 12-bit FLAT offset mask fix with targeted regression test. Looks good. AI-assisted (Gemini 4 Neon).
TinkerBell-90 commented 2026-11-24 21:02:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TinkerBell-90 on 2026-11-24T20:27:26Z.

Review: COMMENTED


Tested ba2c202 against its base ffe310e on Linux x86-64 with Rust 1.98.1 (native target for the tests; clippy also run for x86_64-pc-windows-msvc).

I think the old mask is the intended one. On GFX10 the FLAT segment offset is 11 bits, unsigned, and the hardware ignores bit 11. Only GLOBAL and SCRATCH use all twelve bits, signed:

  • LLVM 21.1.8, AMDGPUAsmParser::validateFlatOffset: "For pre-GFX12 FLAT instructions the offset must be positive; MSB is ignored and forced to zero."
  • LLVM's gfx1030 syntax reference (AMDGPUAsmGFX1030.rst) gives flat_load_dword an offset11 (0..2047), and global_load_dword / scratch_load_dword an offset12s.
  • llvm-mc -triple=amdgcn -mcpu=gfx1030 refuses flat_load_dword v0, v[1:2] offset:2048 (also 4095 and -1) with "expected a 11-bit unsigned offset", and assembles global_load_dword v0, v[1:2], off offset:-2048.

LLVM's disassembler prints the raw field (offset:2048 for 0xDC300800), so a disassembler round trip does not settle it; the assembler rule does. So 0xDC30_0800 is a flat load at offset 0 on the GPU, which is what main decodes. With this change it decodes as 2048.

cargo test -p victory-shader --lib --locked:

Tree Result
base ffe310e 96 passed, 1 ignored
head ba2c202 97 passed, 1 ignored
base + this PR's test only flat_offsets_use_all_twelve_bits fails: left 0, right 2048
base + a reversed test (below) passes: offsets 0 and 2047, SP3 flat_load_dword v0, v[1:2] and flat_load_dword v0, v[1:2] inst_offset:2047
head + the reversed test fails: offsets 2048 and 4095, SP3 inst_offset:2048 and inst_offset:4095
// bit 11 of a FLAT segment offset is ignored on GFX10
assert_eq!(offset(0xDC30_0800), 0);
assert_eq!(offset(0xDC30_0FFF), 0x7FF);

(offset is the closure from this PR's test.) cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings is clean, and both changed files pass rustfmt --edition 2024 --check.

The reach on main is small: flat_* is not lowered (Err("flat memory") in emit/lower.rs), and the address tracking in resource.rs only takes global_*, whose arm this PR does not change. Today only the SP3 text of the shader-info --disasm listing changes. It would matter once flat segment loads are lowered.

Suggestion: keep 0x7FF, add a one-line comment that bit 11 is ignored for the FLAT segment, and turn the test around as above. I could not get AMD's RDNA2 ISA guide from here to quote it, so the LLVM sources are my reference.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:review:6046832831 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1636#pullrequestreview-6046832831). Originally posted by [TinkerBell-90](https://github.com/TinkerBell-90) on 2026-11-24T20:27:26Z. **Review:** COMMENTED --- Tested `ba2c202` against its base `ffe310e` on Linux x86-64 with Rust 1.98.1 (native target for the tests; clippy also run for `x86_64-pc-windows-msvc`). I think the old mask is the intended one. On GFX10 the FLAT segment offset is 11 bits, unsigned, and the hardware ignores bit 11. Only GLOBAL and SCRATCH use all twelve bits, signed: - LLVM 21.1.8, `AMDGPUAsmParser::validateFlatOffset`: "For pre-GFX12 FLAT instructions the offset must be positive; MSB is ignored and forced to zero." - LLVM's gfx1030 syntax reference (`AMDGPUAsmGFX1030.rst`) gives `flat_load_dword` an `offset11` (0..2047), and `global_load_dword` / `scratch_load_dword` an `offset12s`. - `llvm-mc -triple=amdgcn -mcpu=gfx1030` refuses `flat_load_dword v0, v[1:2] offset:2048` (also 4095 and -1) with "expected a 11-bit unsigned offset", and assembles `global_load_dword v0, v[1:2], off offset:-2048`. LLVM's disassembler prints the raw field (`offset:2048` for `0xDC300800`), so a disassembler round trip does not settle it; the assembler rule does. So `0xDC30_0800` is a flat load at offset 0 on the GPU, which is what `main` decodes. With this change it decodes as 2048. `cargo test -p victory-shader --lib --locked`: | Tree | Result | |---|---| | base `ffe310e` | 96 passed, 1 ignored | | head `ba2c202` | 97 passed, 1 ignored | | base + this PR's test only | `flat_offsets_use_all_twelve_bits` fails: left 0, right 2048 | | base + a reversed test (below) | passes: offsets 0 and 2047, SP3 `flat_load_dword v0, v[1:2]` and `flat_load_dword v0, v[1:2] inst_offset:2047` | | head + the reversed test | fails: offsets 2048 and 4095, SP3 `inst_offset:2048` and `inst_offset:4095` | ```rust // bit 11 of a FLAT segment offset is ignored on GFX10 assert_eq!(offset(0xDC30_0800), 0); assert_eq!(offset(0xDC30_0FFF), 0x7FF); ``` (`offset` is the closure from this PR's test.) `cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings` is clean, and both changed files pass `rustfmt --edition 2024 --check`. The reach on `main` is small: `flat_*` is not lowered (`Err("flat memory")` in `emit/lower.rs`), and the address tracking in `resource.rs` only takes `global_*`, whose arm this PR does not change. Today only the SP3 text of the `shader-info --disasm` listing changes. It would matter once flat segment loads are lowered. Suggestion: keep `0x7FF`, add a one-line comment that bit 11 is ignored for the FLAT segment, and turn the test around as above. I could not get AMD's RDNA2 ISA guide from here to quote it, so the LLVM sources are my reference. AI-assisted.
geiyiliyabumo commented 2026-11-24 21:03:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T20:46:54Z.


Verified head ba2c202 merged cleanly onto main (ffe310e) on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, gfx1200) + WARP / Rust 1.98.1 MSVC:

  • cargo test -p victory-shader --lib: 121 passed, 0 failed, 1 ignored (new FLAT 12-bit offset test + full GPU/WARP shader suite pass).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.

AI-assisted; synthetic tests only, no game files.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7144047127 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1636#issuecomment-7144047127). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T20:46:54Z. --- Verified head `ba2c202` merged cleanly onto `main` (`ffe310e`) on **Windows 11 / AMD Radeon RX 9060 XT (RDNA4, `gfx1200`) + WARP / Rust 1.98.1 MSVC**: - `cargo test -p victory-shader --lib`: **121 passed, 0 failed, 1 ignored** (new FLAT 12-bit offset test + full GPU/WARP shader suite pass). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. *AI-assisted; synthetic tests only, no game files.*
upstream-sync changed title from [PR #1636] Shaders: FLAT offsets keep all twelve bits to [PR #1636] Shaders: GFX10 FLAT offsets ignore bit 11 2026-11-24 21:28:09 +00:00
davutsimsekk commented 2026-11-24 21:28:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by davutsimsekk on 2026-11-24T21:12:46Z.


Thanks, you're right. I kept \

<!-- greyfinch-sync:Marvisak/VIctory:comment:7144628730 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1636#issuecomment-7144628730). Originally posted by [davutsimsekk](https://github.com/davutsimsekk) on 2026-11-24T21:12:46Z. --- Thanks, you're right. I kept \
catminou4 commented 2026-11-24 22:01:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T21:42:49Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 97 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows.

GFX10 FLAT offsets ignore bit 11 (the GFX10 flat-address quirk): flat_offsets_ignore_bit_eleven unit test. +1 macOS test.

<!-- greyfinch-sync:Marvisak/VIctory:review:6047882092 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1636#pullrequestreview-6047882092). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T21:42:49Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 97 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows. GFX10 FLAT offsets ignore bit 11 (the GFX10 flat-address quirk): flat_offsets_ignore_bit_eleven unit test. +1 macOS test.
upstream-sync closed this pull request 2026-11-25 01:06:58 +00:00
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!1635
No description provided.