Shaders: fix GFX10 independent a16/g16 gradient dword packing in fields.rs with 21 tests #1116

Open
opened 2026-11-26 04:20:25 +00:00 by github-bot · 3 comments
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 15:52 UTC · original

Summary

Fixes a real GFX10/RDNA2 image_addr_dwords bug in crates/victory-shader/src/gfx10/fields.rs (previously 0 unit tests) where a16 and _g16 gradient packing were conflated, and adds 21 deterministic synthetic unit tests covering a 47-case image-address matrix plus per-encoding field decoding.

Because external PR creation is currently restricted (collaborators_only), the CI-green branch is ready on my fork for cherry-pick / review:

  • Branch: geiyiliyabumo/VIctory@test/shader-gfx10-fields
  • Commit: geiyiliyabumo/VIctory@bcce91f (based on main ffe310e)

Changes (crates/victory-shader/src/gfx10/fields.rs)

  • Bug fix: On GFX10, a16 and _g16 are independent (a16 packs coordinates/LOD/clamp/mip; _g16 opcodes pack gradients, matching LLVM's getAddrSizeMIMGOp). Previously image_addr_dwords packed gradients under a16 and failed to pack them for _g16 without a16 (e.g. image_sample_d 2D with a16=true returned 3 instead of 5 dwords; _g16 without a16 returned 6 instead of 4).
  • Tests (+21 synthetic): 47-case image-address matrix plus field-decoding tests across SOP/SOPK/SOPP, SMEM, SDWA, DPP16/DPP8, VOP3B, VOP3P, VINTRP, DS, MUBUF/MTBUF, MIMG/NSA, FLAT/GLOBAL/SCRATCH, and EXP.
  • (Note for follow-up): crates/victory-shader/src/emit/lower.rs:5631 appears to share the same stale a16 assumption when reading gradient VGPRs.

Verification (Windows 11 x64 MSVC)

  • rustfmt --edition 2024 --check crates/victory-shader/src/gfx10/fields.rs: PASS
  • cargo xtask policy: PASS (154 files ok)
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: PASS (0 warnings)
  • cargo test -p victory-shader --locked -- gfx10::fields::: 21 passed, 0 failed (victory-shader 141 passed, 1 ignored)

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

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 15:52 UTC · [original](https://github.com/Marvisak/VIctory/issues/1116) ### Summary Fixes a real GFX10/RDNA2 `image_addr_dwords` bug in `crates/victory-shader/src/gfx10/fields.rs` (previously 0 unit tests) where `a16` and `_g16` gradient packing were conflated, and adds 21 deterministic synthetic unit tests covering a 47-case image-address matrix plus per-encoding field decoding. Because external PR creation is currently restricted (`collaborators_only`), the CI-green branch is ready on my fork for cherry-pick / review: - **Branch**: `geiyiliyabumo/VIctory@test/shader-gfx10-fields` - **Commit**: `geiyiliyabumo/VIctory@bcce91f` (based on `main` `ffe310e`) ### Changes (`crates/victory-shader/src/gfx10/fields.rs`) - **Bug fix**: On GFX10, `a16` and `_g16` are independent (`a16` packs coordinates/LOD/clamp/mip; `_g16` opcodes pack gradients, matching LLVM's `getAddrSizeMIMGOp`). Previously `image_addr_dwords` packed gradients under `a16` and failed to pack them for `_g16` without `a16` (e.g. `image_sample_d` 2D with `a16=true` returned 3 instead of 5 dwords; `_g16` without `a16` returned 6 instead of 4). - **Tests (+21 synthetic)**: 47-case image-address matrix plus field-decoding tests across SOP/SOPK/SOPP, SMEM, SDWA, DPP16/DPP8, VOP3B, VOP3P, VINTRP, DS, MUBUF/MTBUF, MIMG/NSA, FLAT/GLOBAL/SCRATCH, and EXP. - *(Note for follow-up)*: `crates/victory-shader/src/emit/lower.rs:5631` appears to share the same stale `a16` assumption when reading gradient VGPRs. ### Verification (Windows 11 x64 MSVC) - `rustfmt --edition 2024 --check crates/victory-shader/src/gfx10/fields.rs`: **PASS** - `cargo xtask policy`: **PASS** (`154 files ok`) - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: **PASS** (0 warnings) - `cargo test -p victory-shader --locked -- gfx10::fields::`: **21 passed, 0 failed** (`victory-shader` `141 passed, 1 ignored`) *AI-assisted; synthetic tests only, no game files.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:20:25 +00:00
Author
Owner

@⁠kackosa on GitHub · 2026-11-24 17:17 UTC · original

Here is the follow-up fix addressing the stale a16 assumption in crates/victory-shader/src/emit/lower.rs:5631 noted in the issue description, ensuring gradient and coordinate VGPR unpacking works with independent a16 and _g16:

Matches image_sample_d, image_sample_d_o, image_sample_d_g16, and image_sample_d_o_g16 to op 63 (sampleGrad.f32).
Fixed offset_word detection for opcodes with o followed by other tokens (name.split('').any(|t| t == "o")).
Separated gradient and coordinate unpacking: gradients unpack from f16 only when _g16 is set (packed per direction); coordinates unpack from f16 only when a16 is set.
Fixed 32-bit dwords (offset, bias, cmp) so they aren't truncated by a16.
Added lowering tests for all 4 permutations of (g16, a16).

Complete patch:

0001-fix-gfx10-independent-a16-g16-gradient-packing.patch

**@⁠kackosa** on GitHub · 2026-11-24 17:17 UTC · [original](https://github.com/Marvisak/VIctory/issues/1116#issuecomment-7138961364) Here is the follow-up fix addressing the stale a16 assumption in crates/victory-shader/src/emit/lower.rs:5631 noted in the issue description, ensuring gradient and coordinate VGPR unpacking works with independent a16 and _g16: Matches image_sample_d, image_sample_d_o, image_sample_d_g16, and image_sample_d_o_g16 to op 63 (sampleGrad.f32). Fixed offset_word detection for opcodes with _o followed by other tokens (name.split('_').any(|t| t == "o")). Separated gradient and coordinate unpacking: gradients unpack from f16 only when _g16 is set (packed per direction); coordinates unpack from f16 only when a16 is set. Fixed 32-bit dwords (offset, bias, cmp) so they aren't truncated by a16. Added lowering tests for all 4 permutations of (g16, a16). Complete patch: [0001-fix-gfx10-independent-a16-g16-gradient-packing.patch](https://github.com/user-attachments/files/35359434/0001-fix-gfx10-independent-a16-g16-gradient-packing.patch)
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:03 UTC · original · edited 2026-11-26 03:46 UTC

Automated triage for the maintainers.

Still present on main (63bcca4): image_addr_dwords in crates/victory-shader/src/gfx10/fields.rs packs gradients two per dword whenever a16 is set and ignores the _g16 opcodes. The lowering follows the same rule: the sampleGrad arm of image lowering in emit/lower.rs reads 16-bit gradients under a16, and the _g16 sample opcodes are refused at lowering. @⁠DrDarkDK's check on #1535 shows the effect: an a16 image_sample_d_o sampled the wrong texel.

Now addressed by open PR #2372 (labelled triage: merge candidate). It carries both halves in one PR: #1209's fields.rs commits cherry-picked with their author kept, plus the lowering change, with a GPU test that fails on main (an a16 image_sample_d reads 4000 instead of 3066). The 2026-11-26 comment offers a further fix on a fork (2d45b56) for an a16 mip-query case on #2372's head, posted in that PR's discussion; it belongs in review there.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 10:03 UTC · [original](https://github.com/Marvisak/VIctory/issues/1116#issuecomment-7159171687) · edited 2026-11-26 03:46 UTC <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-26T03:25:47Z at=2026-11-26T03:47:00Z --> Automated triage for the maintainers. Still present on `main` (63bcca4): `image_addr_dwords` in `crates/victory-shader/src/gfx10/fields.rs` packs gradients two per dword whenever `a16` is set and ignores the `_g16` opcodes. The lowering follows the same rule: the `sampleGrad` arm of image lowering in `emit/lower.rs` reads 16-bit gradients under `a16`, and the `_g16` sample opcodes are refused at lowering. @⁠DrDarkDK's check on #1535 shows the effect: an `a16` `image_sample_d_o` sampled the wrong texel. **Now addressed by open PR #2372** (labelled `triage: merge candidate`). It carries both halves in one PR: #1209's `fields.rs` commits cherry-picked with their author kept, plus the lowering change, with a GPU test that fails on `main` (an `a16` `image_sample_d` reads 4000 instead of 3066). The 2026-11-26 comment offers a further fix on a fork (`2d45b56`) for an `a16` mip-query case on #2372's head, posted in that PR's discussion; it belongs in review there. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 03:25 UTC · original

#2372 is the open PR carrying the independent gradient and coordinate packing changes for this issue. I tested the remaining a16 mip-query regression on its exact head 3c7c10f. The same Windows/WARP fixture reads 0×0 for two packed mip operands before the follow-up and 4×2 and 2×1 after 2d45b56. The fixture also passes on upstream 63bcca4 and in the patched merge. I posted the commit and test details in the existing PR discussion.

Please retain the Git author when moving the follow-up, or add this trailer if you fold it into another commit.

Co-authored-by: andrewpozdnakov7-jpg [email protected]

AI-assisted with Codex.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 03:25 UTC · [original](https://github.com/Marvisak/VIctory/issues/1116#issuecomment-7181711440) #2372 is the open PR carrying the independent gradient and coordinate packing changes for this issue. I tested the remaining a16 mip-query regression on its exact head `3c7c10f`. The same Windows/WARP fixture reads `0×0` for two packed mip operands before the follow-up and `4×2` and `2×1` after [2d45b56](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/2d45b568c4654c301c2ff699ea5d07f5a7a93ba9). The fixture also passes on upstream `63bcca4` and in the patched merge. I posted the commit and test details in the [existing PR discussion](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2372). Please retain the Git author when moving the follow-up, or add this trailer if you fold it into another commit. Co-authored-by: andrewpozdnakov7-jpg <[email protected]> AI-assisted with Codex.
This discussion has been locked. Commenting is limited to contributors.
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#1116
No description provided.