Shaders: fix GFX10 independent a16/g16 gradient dword packing in fields.rs with 21 tests #1209
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1209"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T16:26:00Z.
Summary
Closes #1116
Full verification details and change notes are documented in #1116 (commit
bcce91f, based onmainffe310e).Verification (Windows 11 x64 MSVC)
rustfmt --edition 2024 --checkon edited files: PASScargo xtask policy: PASS (zero game files/data)cargo clippy --all-targets --locked -- -D warnings(default +--features diagnosticswhere applicable): PASSAI-assisted; synthetic tests only, no game files.
Imported from Marvisak/VIctory. Originally posted by shortselow-byte on 2026-11-24T16:51:03Z.
Tested at head
bcce91f(onmainffe310e): Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT.gfx10::fields21 passed; workspace 363 passed, 0 failed; both clippy runs (default and--all-features) clean;cargo xtask policyok.The a16 rule here matches what I found independently from LLVM's GFX10 assembler tests (
gfx10_asm_mimg.s):image_sample_d2D a16 → 5, 3D a16 → 8,image_sample_cd_cl2D a16 → 6,image_sample_c_d_o2D_ARRAY a16 → 8 (details in a comment on #318, which packs gradients under a16 the other way).The
lower.rsfollow-up you mention exists on my fork, since I can't open PRs here:shortselow-byte/VIctory@6fab60con branchshader/gfx10-operand-size-tests. It addsimage_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 itslower.rspart applied on top of this PR (keeping yourfields.rs),image_addresses_after_whole_dwordspasses, the workspace has 364 passed, 0 failed, and both clippy runs are clean. Not run against the title.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T16:53:53Z.
Heads-up on a silent miscompilation hazard if
fields.rsis updated without updating the consumer incrates/victory-shader/src/emit/lower.rs:image_sample_dwitha16 = true(g16 = false) reads the wrong VGPRs inLower::image: Onceimage_addr_dwordssizes 2Dimage_sample_d ... a16to 5 VGPRs (4 full-dwordf32gradients + 1 packedf16coordinate dword),Lower::imagestill indexes both gradients and coordinates throughaddr_val(first + ...)using*a16(k / 2) and passes the gradients throughlegacyF16ToF32. That reinterprets the low/high 16 bits of thef32dhgradients asf16, and readsv2(dvxbits) as the(u, v)texture coordinates instead ofv4!image_sample_d_g16and whole-dword prefix (_o) witha16:Lower::imagedoes not yet match"image_sample_d_g16", and indexingoffset_word(_o) throughaddr_val(0)whena16 = truemasks off its upper 16 bits. Splittingaddr_at(base, half, k)so0..firststays full dwords, gradients unpack fromfirstandfirst + grad_regsbyg16, and coordinates unpack fromfirst + 2 * grad_regsby*a16keeps decoding and lowering aligned.Verified across all four
(a16, g16)combinations withdxil.dllvalidation and anisotropic 4x4 quadrant/gradient GPU readback on RTX 5090 and WARP — reference commit if you want to fold theemit/lower.rsside into this PR:github.com/fuzeofficlal/VIctory@d4022c4c28Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T17:16:00Z.
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:
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.
Imported from Marvisak/VIctory. Originally posted by rezioliver-collab on 2026-11-24T17:33:07Z.
I ran an offline A/B comparison of
ffe310eandbcce91fon Windows 11 with Rust 1.98.1 (MSVC) anddxil.dll1.8.2502.11. I ranvictory translate --validate --list --jobs 1twice per revision against the same localshaders.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_dwordscases 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 21gfx10::fieldstests passed onbcce91f, andcargo xtask policypassed on both commits.These results cover the original
fields.rschange atbcce91f, before theLower::imagefollow-up.AI use : Assisted by GPT 6.2 Sol.
Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T18:00:02Z.
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-shaderpasses, 141 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-24T18:45:47Z.
I ran the same synthetic 2D texture fixture against
bcce91fa689cb817671872c2ed930208df3fc9dfand the currentae0b48e6daf7dbbad8c5d8af504726f5efac1bf4on WARP. Atbcce91f,image_sample_dwith A16 coordinates returned red values[1.0, 1.0]instead of[5.5, 7.0]. Atae0b48e, 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 andcargo xtask policypassed.Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T21:07:21Z.
Thanks @andrewpozdnakov7-jpg for the independent A/B verification on
ae0b48eacross all four A16/G16 combinations with DXIL validation!AI-assisted; synthetic tests only, no game files.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:18:38Z.
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_g16forms, andLower::imagereads whole-dword prefixes (offset, bias, compare, mip) unpacked, gradients by g16, and coordinates and LOD by a16. It also mapsimage_sample_d_g16. The evidence is in the PR thread: LLVM's GFX10 assembler tests giveimage_sample_d2D 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 withmain's op table (bias only onimage_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
Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-25T02:31:01Z.
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.Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T03:56:29Z.
Review: APPROVED
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.165 passed / 0 failed / 2 ignored. GFX10 independent a16/g16 gradient dword packing fixed in field… — +21 new tests, the largest test addition in the old backlog; gradient packing is exactly the kind of subtle encoding that needs this coverage.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T21:59:59Z.
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 readsimage_get_resinfo's mip as a whole dword, wheremaincorrectly 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