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

Closed
github-bot wants to merge 2 commits from gh-pr/1209/head into gh-pr/1209/base
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 16:26 UTC · original
geiyiliyabumo:test/shader-gfx10-fields → main · +1193 −51 · 2 files · 2 commits · closed without merging

Summary

Closes #1116

Full verification details and change notes are documented in #1116 (commit bcce91f, based on main ffe310e).

 crates/victory-shader/src/gfx10/fields.rs | 1155 ++++++++++++++++++++++++++++-
 1 file changed, 1151 insertions(+), 4 deletions(-)

Verification (Windows 11 x64 MSVC)

  • rustfmt --edition 2024 --check on edited files: PASS
  • cargo xtask policy: PASS (zero game files/data)
  • cargo clippy --all-targets --locked -- -D warnings (default + --features diagnostics where applicable): PASS
  • Targeted & crate unit/GPU tests: PASS

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

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 16:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/1209) `geiyiliyabumo:test/shader-gfx10-fields` → `main` · +1193 −51 · 2 files · 2 commits · closed without merging ### Summary Closes #1116 Full verification details and change notes are documented in #1116 (commit `bcce91f`, based on `main` `ffe310e`). ```text crates/victory-shader/src/gfx10/fields.rs | 1155 ++++++++++++++++++++++++++++- 1 file changed, 1151 insertions(+), 4 deletions(-) ``` ### Verification (Windows 11 x64 MSVC) - `rustfmt --edition 2024 --check` on edited files: **PASS** - `cargo xtask policy`: **PASS** (zero game files/data) - `cargo clippy --all-targets --locked -- -D warnings` (default + `--features diagnostics` where applicable): **PASS** - Targeted & crate unit/GPU tests: **PASS** *AI-assisted; synthetic tests only, no game files.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:23:51 +00:00
github-bot closed this pull request 2026-11-26 04:23:51 +00:00
Author
Owner

@⁠shortselow-byte on GitHub · 2026-11-24 16:51 UTC · original

Tested at head bcce91f (on main ffe310e): Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT. gfx10::fields 21 passed; workspace 363 passed, 0 failed; both clippy runs (default and --all-features) clean; cargo xtask policy ok.

The a16 rule here matches what I found independently from LLVM's GFX10 assembler tests (gfx10_asm_mimg.s): image_sample_d 2D a16 → 5, 3D a16 → 8, image_sample_cd_cl 2D a16 → 6, image_sample_c_d_o 2D_ARRAY a16 → 8 (details in a comment on #318, which packs gradients under a16 the other way).

The lower.rs follow-up you mention exists on my fork, since I can't open PRs here: shortselow-byte/VIctory@6fab60c on branch shader/gfx10-operand-size-tests. It adds image_address(k, whole, a16) (offset, bias, compare and gradients take a VGPR each; with a16 the coordinates and LOD/mip go two per VGPR), reads gradients as f32, and has a unit test. With only its lower.rs part applied on top of this PR (keeping your fields.rs), image_addresses_after_whole_dwords passes, the workspace has 364 passed, 0 failed, and both clippy runs are clean. Not run against the title.

**@⁠shortselow-byte** on GitHub · 2026-11-24 16:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/1209#issuecomment-7138303640) Tested at head `bcce91f` (on `main` `ffe310e`): Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT. `gfx10::fields` 21 passed; workspace 363 passed, 0 failed; both clippy runs (default and `--all-features`) clean; `cargo xtask policy` ok. The a16 rule here matches what I found independently from LLVM's GFX10 assembler tests (`gfx10_asm_mimg.s`): `image_sample_d` 2D a16 → 5, 3D a16 → 8, `image_sample_cd_cl` 2D a16 → 6, `image_sample_c_d_o` 2D_ARRAY a16 → 8 (details in a comment on #318, which packs gradients under a16 the other way). **The `lower.rs` follow-up you mention** exists on my fork, since I can't open PRs here: [`shortselow-byte/VIctory@6fab60c`](https://github.com/shortselow-byte/VIctory/commit/6fab60c) on branch `shader/gfx10-operand-size-tests`. It adds `image_address(k, whole, a16)` (offset, bias, compare and gradients take a VGPR each; with a16 the coordinates and LOD/mip go two per VGPR), reads gradients as f32, and has a unit test. With only its `lower.rs` part applied on top of this PR (keeping your `fields.rs`), `image_addresses_after_whole_dwords` passes, the workspace has 364 passed, 0 failed, and both clippy runs are clean. Not run against the title.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-24 16:53 UTC · original

Heads-up on a silent miscompilation hazard if fields.rs is updated without updating the consumer in crates/victory-shader/src/emit/lower.rs:

  1. image_sample_d with a16 = true (g16 = false) reads the wrong VGPRs in Lower::image: Once image_addr_dwords sizes 2D image_sample_d ... a16 to 5 VGPRs (4 full-dword f32 gradients + 1 packed f16 coordinate dword), Lower::image still indexes both gradients and coordinates through addr_val(first + ...) using *a16 (k / 2) and passes the gradients through legacyF16ToF32. That reinterprets the low/high 16 bits of the f32 dh gradients as f16, and reads v2 (dvx bits) as the (u, v) texture coordinates instead of v4!
  2. image_sample_d_g16 and whole-dword prefix (_o) with a16: Lower::image does not yet match "image_sample_d_g16", and indexing offset_word (_o) through addr_val(0) when a16 = true masks off its upper 16 bits. Splitting addr_at(base, half, k) so 0..first stays full dwords, gradients unpack from first and first + grad_regs by g16, and coordinates unpack from first + 2 * grad_regs by *a16 keeps decoding and lowering aligned.

Verified across all four (a16, g16) combinations with dxil.dll validation and anisotropic 4x4 quadrant/gradient GPU readback on RTX 5090 and WARP — reference commit if you want to fold the emit/lower.rs side into this PR: github.com/fuzeofficlal/VIctory@d4022c4c28

**@⁠fuzeofficlal** on GitHub · 2026-11-24 16:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/1209#issuecomment-7138376360) Heads-up on a silent miscompilation hazard if `fields.rs` is updated without updating the consumer in `crates/victory-shader/src/emit/lower.rs`: 1. **`image_sample_d` with `a16 = true` (`g16 = false`) reads the wrong VGPRs in `Lower::image`**: Once `image_addr_dwords` sizes 2D `image_sample_d ... a16` to 5 VGPRs (4 full-dword `f32` gradients + 1 packed `f16` coordinate dword), `Lower::image` still indexes both gradients and coordinates through `addr_val(first + ...)` using `*a16` (`k / 2`) and passes the gradients through `legacyF16ToF32`. That reinterprets the low/high 16 bits of the `f32` `dh` gradients as `f16`, and reads `v2` (`dvx` bits) as the `(u, v)` texture coordinates instead of `v4`! 2. **`image_sample_d_g16` and whole-dword prefix (`_o`) with `a16`**: `Lower::image` does not yet match `"image_sample_d_g16"`, and indexing `offset_word` (`_o`) through `addr_val(0)` when `a16 = true` masks off its upper 16 bits. Splitting `addr_at(base, half, k)` so `0..first` stays full dwords, gradients unpack from `first` and `first + grad_regs` by `g16`, and coordinates unpack from `first + 2 * grad_regs` by `*a16` keeps decoding and lowering aligned. Verified across all four `(a16, g16)` combinations with `dxil.dll` validation and anisotropic 4x4 quadrant/gradient GPU readback on RTX 5090 and WARP — reference commit if you want to fold the `emit/lower.rs` side into this PR: https://github.com/fuzeofficlal/VIctory/commit/d4022c4c2818fe3a357a2f7070fb29b4d4da1e7f
Author
Owner

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

Thanks @⁠shortselow-byte and @⁠fuzeofficlal for verifying the RDNA2 \16/_g16\ rule and flagging the \emit/lower.rs\ consumer mismatch!

Folded the \Lower::image\ fix into this PR so decoding and lowering stay aligned:

  • Split \ddr_at(base, half, k)\ so whole-dword prefixes (_o\ offset word, _b\ bias, _c\ compare ref, \image_get_resinfo\ mip) always read full dwords even when \16\ is set.
  • Match \image_sample_d_g16\ alongside \image_sample_d, unpacking \dh\ from \ irst\ and \dv\ from \ irst + grad_regs\ using \g16\ (leaving \image_sample_d ... a16\ gradients as full-dword \ 32).
  • Unpack coordinates and explicit LOD from \ irst + 2 * grad_regs\ using *a16.

Re-verified \gfx10::fields\ (21/21 passed), \emit::lower\ (11/11 passed), \cargo clippy -p victory-shader --all-targets -- -D warnings, and \cargo xtask policy.

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

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 17:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/1209#issuecomment-7138936315) Thanks @⁠shortselow-byte and @⁠fuzeofficlal for verifying the RDNA2 \16\/\_g16\ rule and flagging the \emit/lower.rs\ consumer mismatch! Folded the \Lower::image\ fix into this PR so decoding and lowering stay aligned: - Split \ddr_at(base, half, k)\ so whole-dword prefixes (\_o\ offset word, \_b\ bias, \_c\ compare ref, \image_get_resinfo\ mip) always read full dwords even when \16\ is set. - Match \image_sample_d_g16\ alongside \image_sample_d\, unpacking \dh\ from \ irst\ and \dv\ from \ irst + grad_regs\ using \g16\ (leaving \image_sample_d ... a16\ gradients as full-dword \ 32\). - Unpack coordinates and explicit LOD from \ irst + 2 * grad_regs\ using \*a16\. Re-verified \gfx10::fields\ (21/21 passed), \emit::lower\ (11/11 passed), \cargo clippy -p victory-shader --all-targets -- -D warnings\, and \cargo xtask policy\. *AI-assisted; synthetic tests only, no game files.*
Author
Owner

@⁠rezioliver-collab on GitHub · 2026-11-24 17:33 UTC · original

I ran an offline A/B comparison of ffe310e and bcce91f on Windows 11 with Rust 1.98.1 (MSVC) and dxil.dll 1.8.2502.11. I ran victory translate --validate --list --jobs 1 twice per revision against the same local shaders.rpf.

Each run processed 26,503 containers and validated 21,724 shaders (12,155 vertex/pixel, 1,417 compute, and 8,152 mesh). All 25,889 listed outcomes matched by archive offset and stage across the four runs, with zero validation gains or losses.

I also ran the same four synthetic 2D image_addr_dwords cases on both revisions. A16-only went from 3 to the expected 5 dwords, and G16-only went from 6 to the expected 4. Both control cases passed on both revisions. All 21 gfx10::fields tests passed on bcce91f, and cargo xtask policy passed on both commits.

These results cover the original fields.rs change at bcce91f, before the Lower::image follow-up.

AI use : Assisted by GPT 6.2 Sol.

**@⁠rezioliver-collab** on GitHub · 2026-11-24 17:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1209#issuecomment-7139363705) I ran an offline A/B comparison of `ffe310e` and `bcce91f` on Windows 11 with Rust 1.98.1 (MSVC) and `dxil.dll` 1.8.2502.11. I ran `victory translate --validate --list --jobs 1` twice per revision against the same local `shaders.rpf`. Each run processed 26,503 containers and validated 21,724 shaders (12,155 vertex/pixel, 1,417 compute, and 8,152 mesh). All 25,889 listed outcomes matched by archive offset and stage across the four runs, with zero validation gains or losses. I also ran the same four synthetic 2D `image_addr_dwords` cases on both revisions. A16-only went from 3 to the expected 5 dwords, and G16-only went from 6 to the expected 4. Both control cases passed on both revisions. All 21 `gfx10::fields` tests passed on `bcce91f`, and `cargo xtask policy` passed on both commits. These results cover the original `fields.rs` change at `bcce91f`, before the `Lower::image` follow-up. AI use : Assisted by GPT 6.2 Sol.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 18:00 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at bcce91f: cargo test -p victory-shader passes, 141 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 18:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/1209#issuecomment-7140011438) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at bcce91f: `cargo test -p victory-shader` passes, 141 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-24 18:45 UTC · original

I ran the same synthetic 2D texture fixture against bcce91fa689cb817671872c2ed930208df3fc9df and the current ae0b48e6daf7dbbad8c5d8af504726f5efac1bf4 on WARP. At bcce91f, image_sample_d with A16 coordinates returned red values [1.0, 1.0] instead of [5.5, 7.0]. At ae0b48e, both values matched for all four A16/G16 combinations. The sampler uses linear magnification and point minification, so the readback checks the coordinates and whether the gradients select the intended filter.

The test-only commit is directly on ae0b48e. With it, the shader suite on WARP passed 142 tests with one ignored. Microsoft DXIL validation, strict shader Clippy and cargo xtask policy passed.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-24 18:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/1209#issuecomment-7141116502) I ran the same synthetic 2D texture fixture against `bcce91fa689cb817671872c2ed930208df3fc9df` and the current `ae0b48e6daf7dbbad8c5d8af504726f5efac1bf4` on WARP. At `bcce91f`, `image_sample_d` with A16 coordinates returned red values `[1.0, 1.0]` instead of `[5.5, 7.0]`. At `ae0b48e`, both values matched for all four A16/G16 combinations. The sampler uses linear magnification and point minification, so the readback checks the coordinates and whether the gradients select the intended filter. The [test-only commit](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/f5dd34e6096dca15ab7b9bc2f58686f009fc4f6e) is directly on `ae0b48e`. With it, the shader suite on WARP passed 142 tests with one ignored. Microsoft DXIL validation, strict shader Clippy and `cargo xtask policy` passed.
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 21:07 UTC · original

Thanks @⁠andrewpozdnakov7-jpg for the independent A/B verification on ae0b48e across all four A16/G16 combinations with DXIL validation!

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

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 21:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/1209#issuecomment-7144504581) Thanks @⁠andrewpozdnakov7-jpg for the independent A/B verification on `ae0b48e` across all four A16/G16 combinations with DXIL validation! *AI-assisted; synthetic tests only, no game files.*
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:18 UTC · original · edited 2026-11-25 03:25 UTC

Automated triage for the maintainers.

Merge candidate. This makes a16 and g16 independent for image gradients. image_addr_dwords (gfx10/fields.rs) packs gradients only for _g16 forms, and Lower::image reads whole-dword prefixes (offset, bias, compare, mip) unpacked, gradients by g16, and coordinates and LOD by a16. It also maps image_sample_d_g16. The evidence is in the PR thread: LLVM's GFX10 assembler tests give image_sample_d 2D a16 as 5 dwords, and a WARP readback matches all four a16/g16 combinations after the lowering fix. An A/B over 21,724 shaders showed no validation changes. The new indexing agrees with main's op table (bias only on image_sample_b, gathers unchanged). CI passes. Please put the LLVM reference in the description or a short comment. This takes a different approach from #318, which packs gradients under a16, so only one of them should land.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/1209#issuecomment-7149416720) · edited 2026-11-25 03:25 UTC <!-- victory-triage v1 head=351a162fcad26804be85af8e897abb53b4f6391a verdict=merge-candidate at=2026-11-25T03:25:40Z --> Automated triage for the maintainers. **Merge candidate.** This makes a16 and g16 independent for image gradients. `image_addr_dwords` (`gfx10/fields.rs`) packs gradients only for `_g16` forms, and `Lower::image` reads whole-dword prefixes (offset, bias, compare, mip) unpacked, gradients by g16, and coordinates and LOD by a16. It also maps `image_sample_d_g16`. The evidence is in the PR thread: LLVM's GFX10 assembler tests give `image_sample_d` 2D a16 as 5 dwords, and a WARP readback matches all four a16/g16 combinations after the lowering fix. An A/B over 21,724 shaders showed no validation changes. The new indexing agrees with `main`'s op table (bias only on `image_sample_b`, gathers unchanged). CI passes. Please put the LLVM reference in the description or a short comment. This takes a different approach from #318, which packs gradients under a16, so only one of them should land. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-25 02:31 UTC · original

Rebased cleanly onto \main\ (\ccfb029), preserving cube 2D-per-direction gradients, \image_sample_d_cl, and \op == 81\ level-query coordinate count alongside independent \16/\g16\ unpacking. \cargo test -p victory-shader --locked fields::tests, \cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings, and \cargo xtask policy\ all pass.

**@⁠geiyiliyabumo** on GitHub · 2026-11-25 02:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/1209#issuecomment-7150824033) Rebased cleanly onto \main\ (\ccfb029\), preserving cube 2D-per-direction gradients, \image_sample_d_cl\, and \op == 81\ level-query coordinate count alongside independent \16\/\g16\ unpacking. \cargo test -p victory-shader --locked fields::tests\, \cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings\, and \cargo xtask policy\ all pass.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 21:59 UTC · original

Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing as a duplicate of #2372, which carries this PR's two commits unchanged (identical patch ids) and adds the lowering of image_sample_d_cl_g16, removes the then-stale refusal of 16-bit gradients on 1D and 3D images, and adds a GPU readback test. The rule itself is right: a16 leaves gradients at 32 bits on a target with G16. One thing to carry over to #2372: under a16 this now reads image_get_resinfo's mip as a whole dword, where main correctly takes the low 16 bits.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 21:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/1209#issuecomment-7175808009) Automated triage for the maintainers, second look (a review against current `main`, with builds and tests where they could change the verdict). Closing as a duplicate of #2372, which carries this PR's two commits unchanged (identical patch ids) and adds the lowering of `image_sample_d_cl_g16`, removes the then-stale refusal of 16-bit gradients on 1D and 3D images, and adds a GPU readback test. The rule itself is right: a16 leaves gradients at 32 bits on a target with G16. One thing to carry over to #2372: under a16 this now reads `image_get_resinfo`'s mip as a whole dword, where `main` correctly takes the low 16 bits. If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

Pull request closed

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