shader: a16 leaves image gradients 32-bit; only _g16 packs them (#320) #322

Merged
gagarinyury merged 2 commits from upstream-pr/322 into main 2026-11-27 13:05:59 +00:00
gagarinyury commented 2026-11-27 11:27:03 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by gagarinyury on 2026-11-27T11:27:03Z.


What this changes

Refs #320

On GFX10, a16 packs a sample's coordinates, level and clamp, not its explicit gradients: those stay 32-bit, one VGPR each, and only the _g16 opcodes pack them. LLVM sizes image_sample_d ... a16 that way on gfx1010, gfx1013 and gfx1030 (2D: four gradient VGPRs, then x and y as one f16 pair; the three VGPRs we assumed are rejected).

  • gfx10/fields.rs (image_addr_dwords): gradients count 32-bit unless the opcode is _g16, independent of a16.
  • emit/lower.rs (image_op): addr_val reads the gradients as whole VGPRs and packs only what follows them; sampleGrad takes them as f32. The "16-bit gradients of a 1D or 3D image" refusal goes, since 1D and 3D gradients with a16 are ordinary 32-bit values.
  • gfx10/opcodes.rs: names image_sample_cd_g16 to image_sample_c_cd_cl_o_g16 (0xe8 to 0xef). They stay untranslated, as the other _g16 and _cd samples are.

How it was tested

  • gfx10::tests::image_gradients_stay_32_bit_with_a16: address sizes of ten samples against llvm-mc -mcpu=gfx1030 (1D/2D/3D/cube, _o, _g16 with and without a16, _cd_g16). Fails on main (image_sample_d 2D a16: 3 dwords instead of 5).
  • sample_tests::gradients_stay_32_bit_with_16_bit_coordinates: sampleGrad takes the gradients from v2 to v5 as constants with a16, and a 1D one translates. Fails on main (the gradients are f16 halves; the 1D sample is refused).
  • cargo test -p victory-shader (332 passed), cargo clippy --no-deps -p victory-shader --all-targets -- -D warnings, cargo xtask policy.
  • Not run here: the Windows-target clippy gate (that target is not installed on this Mac) and the HLE/loader tests, which this change does not touch. No game run: the shape is checked without it.

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none: the sizes are LLVM's)
  • New diagnostics are behind a VICTORY_* variable and documented (none added)
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5525838586 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/322). Originally posted by [gagarinyury](https://github.com/gagarinyury) on 2026-11-27T11:27:03Z. --- ## What this changes Refs #320 On GFX10, `a16` packs a sample's coordinates, level and clamp, not its explicit gradients: those stay 32-bit, one VGPR each, and only the `_g16` opcodes pack them. LLVM sizes `image_sample_d ... a16` that way on gfx1010, gfx1013 and gfx1030 (2D: four gradient VGPRs, then x and y as one f16 pair; the three VGPRs we assumed are rejected). - `gfx10/fields.rs` (`image_addr_dwords`): gradients count 32-bit unless the opcode is `_g16`, independent of `a16`. - `emit/lower.rs` (`image_op`): `addr_val` reads the gradients as whole VGPRs and packs only what follows them; `sampleGrad` takes them as f32. The "16-bit gradients of a 1D or 3D image" refusal goes, since 1D and 3D gradients with `a16` are ordinary 32-bit values. - `gfx10/opcodes.rs`: names `image_sample_cd_g16` to `image_sample_c_cd_cl_o_g16` (0xe8 to 0xef). They stay untranslated, as the other `_g16` and `_cd` samples are. ## How it was tested - `gfx10::tests::image_gradients_stay_32_bit_with_a16`: address sizes of ten samples against `llvm-mc -mcpu=gfx1030` (1D/2D/3D/cube, `_o`, `_g16` with and without `a16`, `_cd_g16`). Fails on main (`image_sample_d` 2D a16: 3 dwords instead of 5). - `sample_tests::gradients_stay_32_bit_with_16_bit_coordinates`: `sampleGrad` takes the gradients from v2 to v5 as constants with `a16`, and a 1D one translates. Fails on main (the gradients are f16 halves; the 1D sample is refused). - `cargo test -p victory-shader` (332 passed), `cargo clippy --no-deps -p victory-shader --all-targets -- -D warnings`, `cargo xtask policy`. - Not run here: the Windows-target clippy gate (that target is not installed on this Mac) and the HLE/loader tests, which this change does not touch. No game run: the shape is checked without it. ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none: the sizes are LLVM's) - [x] New diagnostics are behind a `VICTORY_*` variable and documented (none added)
LakshanSivakumar commented 2026-11-27 12:00:36 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T12:00:36Z.


Thank you. The comparison with llvm-mc for gfx1010, gfx1013 and gfx1030 is the evidence I wanted, and the two tests are the right ones.

I ran every shader by output on 797409f4 (33,625 containers, against main c1b95875): nothing gained, nothing lost, nothing changed. So no shader in my dump of the game uses a gradient sample with a16; the change is right by the ISA but has no effect on the game today. That makes it safe, and also means the game cannot test it.

Before I merge: I have approved your workflow, so please check it is green. And please add the 1D array and 2D array cases to the address-size test, and say how kind maps to them in lower.rs; image_addr_dwords and the new gradients count are two separate pieces of code and the test should make them agree.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7217729761 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/322#issuecomment-7217729761). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T12:00:36Z. --- Thank you. The comparison with `llvm-mc` for gfx1010, gfx1013 and gfx1030 is the evidence I wanted, and the two tests are the right ones. I ran every shader by output on 797409f4 (33,625 containers, against main c1b95875): nothing gained, nothing lost, nothing changed. So no shader in my dump of the game uses a gradient sample with `a16`; the change is right by the ISA but has no effect on the game today. That makes it safe, and also means the game cannot test it. Before I merge: I have approved your workflow, so please check it is green. And please add the 1D array and 2D array cases to the address-size test, and say how `kind` maps to them in `lower.rs`; `image_addr_dwords` and the new `gradients` count are two separate pieces of code and the test should make them agree.
gagarinyury commented 2026-11-27 12:06:21 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by gagarinyury on 2026-11-27T12:06:21Z.


Workflow is green (797409f). Added the 1D and 2D array cases (1d5fbee): the decoder test has both with and without a16 (3/4 and 6/7 VGPRs, from llvm-mc), and the sample test samples both array kinds with a16 and checks that the gradients come from whole VGPRs. In image_op, dim 4 is kind 6 with 2 coordinates and dim 5 is kind 7 with 3; the slice is not spatial, so gradients is 2 × (coords − 1) = 2 and 4, as image_addr_dwords' DIMS gives (1 and 2 a direction). If gradients disagreed with the decoder's size, the coordinates would be read past the address range and the lowering would refuse "an image address", so the sample test ties the two.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7217845201 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/322#issuecomment-7217845201). Originally posted by [gagarinyury](https://github.com/gagarinyury) on 2026-11-27T12:06:21Z. --- Workflow is green (797409f). Added the 1D and 2D array cases (1d5fbee): the decoder test has both with and without a16 (3/4 and 6/7 VGPRs, from llvm-mc), and the sample test samples both array kinds with a16 and checks that the gradients come from whole VGPRs. In `image_op`, `dim` 4 is `kind` 6 with 2 coordinates and `dim` 5 is `kind` 7 with 3; the slice is not spatial, so `gradients` is 2 × (coords − 1) = 2 and 4, as `image_addr_dwords`' DIMS gives (1 and 2 a direction). If `gradients` disagreed with the decoder's size, the coordinates would be read past the address range and the lowering would refuse "an image address", so the sample test ties the two.
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
LakshanSivakumar/Native-Victory-macOS!322
No description provided.