Shader: pack a16 image addresses as the hardware does; image_sample_d_cl #318

Closed
github-bot wants to merge 1 commit from gh-pr/318/head into gh-pr/318/base
Owner

@⁠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 merging

What

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, and image_addr_dwords in gfx10/fields.rs already counts them that way:

  • each extra word (texel offsets, bias, comparison value) takes a whole VGPR; a 16-bit bias sits in its low half,
  • each direction of an odd number of gradients is padded to whole VGPRs,
  • the coordinates (and level/clamp) begin a new VGPR.

The new image_address_place places each address by that layout. Effects:

  • a16 biased samples now translate instead of stopping with "a biased image sample with 16-bit coordinates"; the bias goes through legacyF16ToF32 like the coordinates,
  • a16 gathers with an offset word now read their coordinates from the VGPR after the offset (before, coordinate 0 came from the offset word),
  • non-a16 and non-sampling paths are unchanged ((k, None)).

image_sample_d_cl lowers to sampleGrad like image_sample_d, passing the clamp that follows the coordinates instead of undef.

Why

In a translate --validate census 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 test a16_image_addresses_pack_as_the_hardware_does covering biased/offset, 2D-gradient (+ clamp) and 3D-gradient layouts.
  • cargo clippy -p victory-shader: clean.
  • Not yet confirmed with a re-run of the census or in the title: the machine I could test on can't reach the world. A census run on your side would show how many of the 135 now emit and validate.
**@⁠xmvo** on GitHub · 2026-11-24 02:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/318) `xmvo:shader/a16-addresses-sample-d-cl` → `main` · +107 −20 · 1 files · 1 commits · closed without merging ## What **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, and `image_addr_dwords` in `gfx10/fields.rs` already counts them that way: - each extra word (texel offsets, bias, comparison value) takes a whole VGPR; a 16-bit bias sits in its low half, - each direction of an odd number of gradients is padded to whole VGPRs, - the coordinates (and level/clamp) begin a new VGPR. The new `image_address_place` places each address by that layout. Effects: - a16 biased samples now translate instead of stopping with "a biased image sample with 16-bit coordinates"; the bias goes through `legacyF16ToF32` like the coordinates, - a16 gathers with an offset word now read their coordinates from the VGPR after the offset (before, coordinate 0 came from the offset word), - non-a16 and non-sampling paths are unchanged (`(k, None)`). **`image_sample_d_cl`** lowers to `sampleGrad` like `image_sample_d`, passing the clamp that follows the coordinates instead of undef. ## Why In a `translate --validate` census 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 test `a16_image_addresses_pack_as_the_hardware_does` covering biased/offset, 2D-gradient (+ clamp) and 3D-gradient layouts. - `cargo clippy -p victory-shader`: clean. - **Not yet confirmed** with a re-run of the census or in the title: the machine I could test on can't reach the world. A census run on your side would show how many of the 135 now emit and validate.
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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:59:05 +00:00
github-bot closed this pull request 2026-11-26 03:59:05 +00:00
Author
Owner

@⁠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_place also 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 _g16 opcodes, and a16 packs the coordinates and the level/clamp only. LLVM's MC test llvm/test/MC/AMDGPU/gfx10_asm_mimg.s assembles

image_sample_d    v[0:3], v[0:4], s[0:7], s[8:11] dmask:0xf dim:SQ_RSRC_IMG_2D a16          ; 5 address dwords
image_sample_d_cl v[0:3], [v0, v1, v2, v3, v4, v6], s[0:7], s[8:11] dmask:0xf dim:SQ_RSRC_IMG_2D a16   ; 6

i.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 on main counts them packed too (gfx10/fields.rs), which is probably where both of us got it from.

image_sample_d_cl is 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.

**@⁠r4tedx** on GitHub · 2026-11-24 03:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/318#issuecomment-7120900066) 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_place` also 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 `_g16` opcodes, and a16 packs the coordinates and the level/clamp only. LLVM's MC test `llvm/test/MC/AMDGPU/gfx10_asm_mimg.s` assembles ``` image_sample_d v[0:3], v[0:4], s[0:7], s[8:11] dmask:0xf dim:SQ_RSRC_IMG_2D a16 ; 5 address dwords image_sample_d_cl v[0:3], [v0, v1, v2, v3, v4, v6], s[0:7], s[8:11] dmask:0xf dim:SQ_RSRC_IMG_2D a16 ; 6 ``` i.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 on `main` counts them packed too (`gfx10/fields.rs`), which is probably where both of us got it from. `image_sample_d_cl` is 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.
Author
Owner

@⁠ghost on GitHub · 2026-11-24 04:30 UTC · original

Tested 1d7bf9b with the title on an RX 9060 XT (RDNA4), Windows 11. Answering what these shaders stop at next.

Offline, victory translate --list on shaders.rpf, main d2a4bae vs this PR alone:

refusal main + #318
image_sample_d_cl 27 0
a biased image sample with 16-bit coordinates 108 0
an image address 2 27
vertex/pixel emitted (of 14,001) 12,272 12,316

The totals balance with none of the 27 image_sample_d_cl programs translating; the 44 new ones come from the biased-sample row.

In the world, #293's top pixel shader 7bdefdfde461f6e3 still fails at the same offset (0x4d24), now with an image address is not supported. That may be the a16 derivative packing in @⁠r4tedx's note. It matters: in a traced baseline world frame it dropped 655 ExecuteIndirect calls writing the G-buffer and depth, the largest single loss there.

AI-assisted (Claude Code, Claude Opus 5.5); no game data.

**@⁠ghost** on GitHub · 2026-11-24 04:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/318#issuecomment-7122079475) Tested `1d7bf9b` with the title on an RX 9060 XT (RDNA4), Windows 11. Answering what these shaders stop at next. Offline, `victory translate --list` on `shaders.rpf`, `main` `d2a4bae` vs this PR alone: | refusal | `main` | + #318 | |---|---|---| | `image_sample_d_cl` | 27 | 0 | | `a biased image sample with 16-bit coordinates` | 108 | 0 | | `an image address` | 2 | 27 | | vertex/pixel emitted (of 14,001) | 12,272 | 12,316 | The totals balance with none of the 27 `image_sample_d_cl` programs translating; the 44 new ones come from the biased-sample row. In the world, #293's top pixel shader `7bdefdfde461f6e3` still fails at the same offset (`0x4d24`), now with `an image address is not supported`. That may be the `a16` derivative packing in @⁠r4tedx's note. It matters: in a traced baseline world frame it dropped 655 `ExecuteIndirect` calls writing the G-buffer and depth, the largest single loss there. AI-assisted (Claude Code, Claude Opus 5.5); no game data.
Author
Owner

@⁠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_cl programs that stop at an 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: with 1d7bf9b the same 25 programs stop at an image address, which matches your 27 → 27.

#160 has that cube rule since b540f51. On the retail shaders its head 25e917b translates 23 of the 27 image_sample_d_cl programs (EduAzevedo's rerun); the 4 left stop at a cross-lane operation outside compute.

What I do not know is whether 7bdefdfde461f6e3 is one of the 23. You have the traced frame, so two numbers would settle the top row of #293: what victory translate --list gives for that hash on 25e917b, and, if it translates, how many of the 655 ExecuteIndirect calls then run.

From the documents, synthetic tests and the linked testers' measurements; nothing was run on the title here. AI-assisted.

**@⁠r4tedx** on GitHub · 2026-11-24 05:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/318#issuecomment-7123375495) @⁠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_cl` programs that stop at `an image address` ([result](https://git.gtahub.st/github/Marvisak--VIctory/pulls/160)): 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: with `1d7bf9b` the same 25 programs stop at `an image address`, which matches your 27 → 27. #160 has that cube rule since `b540f51`. On the retail shaders its head `25e917b` translates 23 of the 27 `image_sample_d_cl` programs ([EduAzevedo's rerun](https://git.gtahub.st/github/Marvisak--VIctory/pulls/160)); the 4 left stop at `a cross-lane operation outside compute`. What I do not know is whether `7bdefdfde461f6e3` is one of the 23. You have the traced frame, so two numbers would settle the top row of #293: what `victory translate --list` gives for that hash on `25e917b`, and, if it translates, how many of the 655 `ExecuteIndirect` calls then run. From the documents, synthetic tests and the linked testers' measurements; nothing was run on the title here. AI-assisted.
Author
Owner

@⁠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 at 25e917b. 12 traced world frames per run from a 1,000-draw trigger, 2 runs each.

  • Without #160, the runtime log refuses 7bdefdfde461f6e3 with image_sample_d_cl is not supported at 0x4d24. Every operation on its pipelines is an ExecuteIndirect and all are dropped: 692 and 1,017 in the two runs.
  • With #160, the runtime log says it translates. All operations on its pipelines run, none dropped for any reason: 1,017 and 692 (the same two scenes, caught in the other order).
  • The runtime log's image_sample_d_cl refusals 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.

**@⁠ghost** on GitHub · 2026-11-24 06:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/318#issuecomment-7124408758) @⁠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 at `25e917b`. 12 traced world frames per run from a 1,000-draw trigger, 2 runs each. - **Without #160**, the runtime log refuses `7bdefdfde461f6e3` with `image_sample_d_cl is not supported` at `0x4d24`. Every operation on its pipelines is an `ExecuteIndirect` and all are dropped: 692 and 1,017 in the two runs. - **With #160**, the runtime log says it translates. All operations on its pipelines run, none dropped for any reason: 1,017 and 692 (the same two scenes, caught in the other order). - The runtime log's `image_sample_d_cl` refusals 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.
Author
Owner

@⁠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 main d2a4bae:

VS/PS validated CS validated MS validated cargo test -p victory-shader
main 12172 1670 8129 ok
#569 12208 1670 8129 ok
#73 12208 1670 8129 ok
#318 12208 1670 8129 ok
#306 12316 1693 8138 ok

All four clear the 108 "biased image sample with 16-bit coordinates" programs identically. #73 and #318 also clear the 27 image_sample_d_cl refusals, 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.

**@⁠slint6614-dev** on GitHub · 2026-11-24 07:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/318#issuecomment-7124942245) Measured on the full retail shader pack (26,503 containers) with `victory translate --validate`, against main d2a4bae: | | VS/PS validated | CS validated | MS validated | `cargo test -p victory-shader` | |---|---|---|---|---| | main | 12172 | 1670 | 8129 | ok | | #569 | 12208 | 1670 | 8129 | ok | | #73 | 12208 | 1670 | 8129 | ok | | #318 | 12208 | 1670 | 8129 | ok | | #306 | 12316 | 1693 | 8138 | ok | All four clear the 108 "biased image sample with 16-bit coordinates" programs identically. #73 and #318 also clear the 27 `image_sample_d_cl` refusals, 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.
Author
Owner

@⁠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):

instruction (a16) LLVM's vaddr packed gradients would give
image_sample_d 2D 5 (v[0:4]) 3
image_sample_d 3D 8 6
image_sample_cd_cl 2D 6 4
image_sample_c_d_o 2D_ARRAY 8 6

All four match "a16 packs coordinates and LOD/clamp only; gradients stay
32-bit unless the opcode is a _g16 one". The assembler accepts wider
vaddr 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).

**@⁠shortselow-byte** on GitHub · 2026-11-24 14:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/318#issuecomment-7134008754) A data point on the gradient layout under a16, from LLVM's GFX10 assembler tests (llvm/test/MC/AMDGPU/gfx10_asm_mimg.s): | instruction (a16) | LLVM's vaddr | packed gradients would give | |---|---|---| | `image_sample_d` 2D | 5 (`v[0:4]`) | 3 | | `image_sample_d` 3D | 8 | 6 | | `image_sample_cd_cl` 2D | 6 | 4 | | `image_sample_c_d_o` 2D_ARRAY | 8 | 6 | All four match "a16 packs coordinates and LOD/clamp only; gradients stay 32-bit unless the opcode is a `_g16` one". The assembler accepts wider vaddr 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

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