Shaders: unpack a16 image coordinates and gradients after whole 32-bi… #1479

Closed
Texbirds wants to merge 1 commit from upstream-pr/1480 into main
Texbirds commented 2026-11-24 18:18:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-24T18:18:33Z.


…t address words

Problem

In crates/victory-shader/src/emit/lower.rs, mimg indexed all address components through a single flat addr_val(k) using regs[k / 2] when a16 is set. On GFX10 (matching gfx10/fields.rs), texel offset (_o), bias (_b), compare reference (_c), and image_get_resinfo mip level are always full 32-bit VGPRs even under a16, and explicit gradients (_d) pad dh and dv to whole VGPRs separately (2 * spatial.div_ceil(2)).

As a result, under a16:

  • image_sample_o / image_gather4_lz_o truncated the 32-bit offset word to 16 bits (breaking constant offset extraction and 3D offsets) and read the first coordinate from the upper 16 bits of the offset VGPR.
  • image_sample_b read bias as a 16-bit half and shifted coordinates into the bias VGPR.
  • image_sample_d with odd spatial dimensions (1D/3D) read dv and coordinates from the wrong halves/VGPRs.

Fix

  • Split address reads into whole_val(k) (full 32-bit VGPRs for _o, _b, _c, and image_get_resinfo) and packed_val(base, k) (2×16-bit packed components under a16 starting at VGPR base).
  • Compute deriv_stride = spatial.div_ceil(2) and coords_base = first + derivs_regs to match gfx10/fields.rs exactly.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6588496935 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1480). Originally posted by [Texbirds](https://github.com/Texbirds) on 2026-11-24T18:18:33Z. --- …t address words ### Problem In `crates/victory-shader/src/emit/lower.rs`, `mimg` indexed all address components through a single flat `addr_val(k)` using `regs[k / 2]` when `a16` is set. On GFX10 (matching `gfx10/fields.rs`), texel offset (`_o`), bias (`_b`), compare reference (`_c`), and `image_get_resinfo` mip level are always full 32-bit VGPRs even under `a16`, and explicit gradients (`_d`) pad `dh` and `dv` to whole VGPRs separately (`2 * spatial.div_ceil(2)`). As a result, under `a16`: - `image_sample_o` / `image_gather4_lz_o` truncated the 32-bit offset word to 16 bits (breaking constant offset extraction and 3D offsets) and read the first coordinate from the upper 16 bits of the offset VGPR. - `image_sample_b` read bias as a 16-bit half and shifted coordinates into the bias VGPR. - `image_sample_d` with odd spatial dimensions (1D/3D) read `dv` and coordinates from the wrong halves/VGPRs. ### Fix - Split address reads into `whole_val(k)` (full 32-bit VGPRs for `_o`, `_b`, `_c`, and `image_get_resinfo`) and `packed_val(base, k)` (2×16-bit packed components under `a16` starting at VGPR `base`). - Compute `deriv_stride = spatial.div_ceil(2)` and `coords_base = first + derivs_regs` to match `gfx10/fields.rs` exactly.
catminou4 commented 2026-11-24 19:03:34 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and were not run here; lowering/structure coverage only.

The a16 coordinate/gradient unpacking looks systematic — packed_val for component pairs, whole_val for offsets/bias/lod/reference — and all 96 macOS tests pass, but this PR adds no test at all (only lower.rs changes). Coordinate unpacking for a16 images is exactly the kind of change that silently corrupts gathers/gradients when the VGPR pairing is off. Could you add a valu case (hardware + WARP) covering image_gather4/image_sample with a16 coords, or point at existing coverage? Without it I'd rather not approve.

<!-- greyfinch-sync:Marvisak/VIctory:review:6045235360 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1480#pullrequestreview-6045235360). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T18:42:19Z. **Review:** COMMENTED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), `cargo test -p victory-shader --locked` → 96 passed, 0 failed. Execution/valu tests are `#[cfg(all(test, windows))]` and were not run here; lowering/structure coverage only. The a16 coordinate/gradient unpacking looks systematic — `packed_val` for component pairs, `whole_val` for offsets/bias/lod/reference — and all 96 macOS tests pass, but this PR adds no test at all (only `lower.rs` changes). Coordinate unpacking for `a16` images is exactly the kind of change that silently corrupts gathers/gradients when the VGPR pairing is off. Could you add a valu case (hardware + WARP) covering `image_gather4`/`image_sample` with `a16` coords, or point at existing coverage? Without it I'd rather not approve.
sinan-cmyk commented 2026-11-24 21:03:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T20:13:27Z.


Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head b32a5d5 onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 21,724 with this PR.

No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 120, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143213969 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1480#issuecomment-7143213969). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T20:13:27Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head b32a5d5 onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on `main`, 21,724 with this PR. No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 120, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 01:06:40 +00:00
Marvisak commented 2026-11-25 01:08:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:41:01Z.


Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

a16 address unpacking with whole VGPRs for offset, bias and compare and per-direction gradients: main already does this (lower.rs 7366-7392 extra, 7839).

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148767468 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1480#issuecomment-7148767468). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:41:01Z. --- Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. a16 address unpacking with whole VGPRs for offset, bias and compare and per-direction gradients: main already does this (lower.rs 7366-7392 `extra`, 7839). If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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!1479
No description provided.