Shader: pack a16 image addresses as the hardware does; image_sample_d_cl #318
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!318
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/318/head"
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?
@xmvo on GitHub · 2026-11-24 02:15 UTC · original
xmvo:shader/a16-addresses-sample-d-cl→main· +107 −20 · 1 files · 1 commits · closed without mergingWhat
a16 address layout. With
a16,image()read the address VGPRs as one continuous run of 16-bit pairs (k / 2). The hardware packs them differently, andimage_addr_dwordsingfx10/fields.rsalready counts them that way:The new
image_address_placeplaces each address by that layout. Effects:legacyF16ToF32like the coordinates,(k, None)).image_sample_d_cllowers tosampleGradlikeimage_sample_d, passing the clamp that follows the coordinates instead of undef.Why
In a
translate --validatecensus of the title's shaders, these were the reasons for 108 programs (biased a16) and 27 programs (image_sample_d_cl, e.g.PS_DeferredTextured_AlphaClipNC).Testing
cargo test -p victory-shader: all pass, plus a new testa16_image_addresses_pack_as_the_hardware_doescovering biased/offset, 2D-gradient (+ clamp) and 3D-gradient layouts.cargo clippy -p victory-shader: clean.With a16 the address VGPRs were read as one run of 16-bit pairs. The hardware (and image_addr_dwords, which counts them) gives each extra word (texel offsets, bias, comparison value) a whole VGPR, pads each direction of an odd number of gradients to whole VGPRs and begins the coordinates in a new VGPR. image_address_place now places each address that way, so a16 biased samples translate (the bias is the f16 in its word's low half) and a16 gathers with an offset word read their coordinates from the right VGPR. image_sample_d_cl lowers to sampleGrad with the clamp that follows the coordinates. In a census of the title's shaders these stopped 108 ("a biased image sample with 16-bit coordinates") and 27 (image_sample_d_cl) programs.@r4tedx on GitHub · 2026-11-24 03:14 UTC · original
Review note on the address layout. This PR reads the a16 bias as an f16 in the low half of its dword, which matches LLVM. But
image_address_placealso packs the derivatives when a16 is set (the test expects(dx.x, dx.y) (dy.x, dy.y) (u, v) (clamp)for 2D). On GFX10.3 the two are independent: derivatives are 16-bit only in the_g16opcodes, and a16 packs the coordinates and the level/clamp only. LLVM's MC testllvm/test/MC/AMDGPU/gfx10_asm_mimg.sassemblesi.e. four 32-bit derivatives, then one dword of packed coordinates (and clamp). With the packing here the coordinates are read from dword 2 instead of dword 4. I made the same mistake in #160 and fixed it there (
7265593); the decoder onmaincounts them packed too (gfx10/fields.rs), which is probably where both of us got it from.image_sample_d_clis a row of #293 (about 53 draws per frame), so whether the title's three shaders use a16 there is something a tester could say (yes/no).From the documents and synthetic tests only; I have no copy of the title and have not run this on console hardware.
@ghost on GitHub · 2026-11-24 04:30 UTC · original
Tested
1d7bf9bwith the title on an RX 9060 XT (RDNA4), Windows 11. Answering what these shaders stop at next.Offline,
victory translate --listonshaders.rpf,maind2a4baevs this PR alone:mainimage_sample_d_cla biased image sample with 16-bit coordinatesan image addressThe totals balance with none of the 27
image_sample_d_clprograms translating; the 44 new ones come from the biased-sample row.In the world, #293's top pixel shader
7bdefdfde461f6e3still fails at the same offset (0x4d24), now withan image address is not supported. That may be thea16derivative packing in @r4tedx's note. It matters: in a traced baseline world frame it dropped 655ExecuteIndirectcalls writing the G-buffer and depth, the largest single loss there.AI-assisted (Claude Code, Claude Opus 5.5); no game data.
@r4tedx on GitHub · 2026-11-24 05:53 UTC · original
@nullmarsh thank you for running it. On
7bdefdfde461f6e3: I do not think it is the a16 packing from my note above.EduAzevedo looked at the
image_sample_d_clprograms that stop atan image address(result): every such sample is on a cube, with eight address registers and no a16. That is two gradients per direction (the face coordinates'), then the three coordinates and the clamp, where the translator expects three gradients per direction on a cube and runs past the operand list. The same measurement covered this PR's head: with1d7bf9bthe same 25 programs stop atan image address, which matches your 27 → 27.#160 has that cube rule since
b540f51. On the retail shaders its head25e917btranslates 23 of the 27image_sample_d_clprograms (EduAzevedo's rerun); the 4 left stop ata cross-lane operation outside compute.What I do not know is whether
7bdefdfde461f6e3is one of the 23. You have the traced frame, so two numbers would settle the top row of #293: whatvictory translate --listgives for that hash on25e917b, and, if it translates, how many of the 655ExecuteIndirectcalls then run.From the documents, synthetic tests and the linked testers' measurements; nothing was run on the title here. AI-assisted.
@ghost on GitHub · 2026-11-24 06:54 UTC · original
@r4tedx It is one of them. In game on AMD RDNA4 (RX 9060 XT, Windows 11):
d2a4bae+ #135 + #365 + #500 + a local per-draw trace,diag, with and without #160 at25e917b. 12 traced world frames per run from a 1,000-draw trigger, 2 runs each.7bdefdfde461f6e3withimage_sample_d_cl is not supportedat0x4d24. Every operation on its pipelines is anExecuteIndirectand all are dropped: 692 and 1,017 in the two runs.image_sample_d_clrefusals go from 3 programs to 0.No visible change: in both arms 3–4 of the 12 frames show the title card and the rest are black. No device loss in these four runs (each stopped after its 12 frames).
AI-assisted (Claude Code, Claude Opus 5.5); no game data.
@slint6614-dev on GitHub · 2026-11-24 07:23 UTC · original
Measured on the full retail shader pack (26,503 containers) with
victory translate --validate, against maind2a4bae:cargo test -p victory-shaderAll four clear the 108 "biased image sample with 16-bit coordinates" programs identically. #73 and #318 also clear the 27
image_sample_d_clrefusals, but those programs then stop on another reason (emitted count unchanged). #306 additionally clears 15 of the 16 validator error kinds (only the mesh 32 KiB output size remains, see #459); it overlaps #554/#565/#381. Windows 11, dxil.dll from SDK 10.0.26100.@shortselow-byte on GitHub · 2026-11-24 14:12 UTC · original
A data point on the gradient layout under a16, from LLVM's GFX10 assembler
tests (llvm/test/MC/AMDGPU/gfx10_asm_mimg.s):
image_sample_d2Dv[0:4])image_sample_d3Dimage_sample_cd_cl2Dimage_sample_c_d_o2D_ARRAYAll four match "a16 packs coordinates and LOD/clamp only; gradients stay
32-bit unless the opcode is a
_g16one". The assembler accepts widervaddr ranges than needed, so this is evidence rather than proof, and I did
not find the lowering code in LLVM that states the rule.
A branch with this layout and unit tests for
image_addr_dwords:https://github.com/shortselow-byte/VIctory/tree/shader/gfx10-operand-size-tests
(not run against the title).
Pull request closed