shader: a16 leaves image gradients 32-bit; only _g16 packs them (#320) #322
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/322"
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 LakshanSivakumar/Native-Victory-macOS. Originally posted by gagarinyury on 2026-11-27T11:27:03Z.
What this changes
Refs #320
On GFX10,
a16packs a sample's coordinates, level and clamp, not its explicit gradients: those stay 32-bit, one VGPR each, and only the_g16opcodes pack them. LLVM sizesimage_sample_d ... a16that 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 ofa16.emit/lower.rs(image_op):addr_valreads the gradients as whole VGPRs and packs only what follows them;sampleGradtakes them as f32. The "16-bit gradients of a 1D or 3D image" refusal goes, since 1D and 3D gradients witha16are ordinary 32-bit values.gfx10/opcodes.rs: namesimage_sample_cd_g16toimage_sample_c_cd_cl_o_g16(0xe8 to 0xef). They stay untranslated, as the other_g16and_cdsamples are.How it was tested
gfx10::tests::image_gradients_stay_32_bit_with_a16: address sizes of ten samples againstllvm-mc -mcpu=gfx1030(1D/2D/3D/cube,_o,_g16with and withouta16,_cd_g16). Fails on main (image_sample_d2D a16: 3 dwords instead of 5).sample_tests::gradients_stay_32_bit_with_16_bit_coordinates:sampleGradtakes the gradients from v2 to v5 as constants witha16, 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.Checklist
VICTORY_*variable and documented (none added)Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T12:00:36Z.
Thank you. The comparison with
llvm-mcfor 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 mainc1b95875): nothing gained, nothing lost, nothing changed. So no shader in my dump of the game uses a gradient sample witha16; 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
kindmaps to them inlower.rs;image_addr_dwordsand the newgradientscount are two separate pieces of code and the test should make them agree.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. Inimage_op,dim4 iskind6 with 2 coordinates anddim5 iskind7 with 3; the slice is not spatial, sogradientsis 2 × (coords − 1) = 2 and 4, asimage_addr_dwords' DIMS gives (1 and 2 a direction). Ifgradientsdisagreed 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.