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

Closed
xmvo wants to merge 1 commit from upstream-pr/318 into main
xmvo commented 2026-11-24 02:15:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by xmvo on 2026-11-24T02:15:58Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6573086041 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/318). Originally posted by [xmvo](https://github.com/xmvo) on 2026-11-24T02:15:58Z. --- ## 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.
r4tedx commented 2026-11-24 06:55:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-24T03:14:15Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7120900066 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/318#issuecomment-7120900066). Originally posted by [r4tedx](https://github.com/r4tedx) on 2026-11-24T03:14:15Z. --- 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.
nullmarsh commented 2026-11-24 06:55:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by nullmarsh on 2026-11-24T04:30:17Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122079475 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/318#issuecomment-7122079475). Originally posted by [nullmarsh](https://github.com/nullmarsh) on 2026-11-24T04:30:17Z. --- 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.
r4tedx commented 2026-11-24 06:56:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-24T05:53:43Z.


@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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123375495 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/318#issuecomment-7123375495). Originally posted by [r4tedx](https://github.com/r4tedx) on 2026-11-24T05:53:43Z. --- @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://github.com/Marvisak/VIctory/pull/160#issuecomment-7120988076)): 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://github.com/Marvisak/VIctory/pull/160#issuecomment-7121615299)); 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.
nullmarsh commented 2026-11-24 06:56:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by nullmarsh on 2026-11-24T06:54:13Z.


@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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7124408758 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/318#issuecomment-7124408758). Originally posted by [nullmarsh](https://github.com/nullmarsh) on 2026-11-24T06:54:13Z. --- @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.
slint6614-dev commented 2026-11-24 08:02:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by slint6614-dev on 2026-11-24T07:23:40Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7124942245 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/318#issuecomment-7124942245). Originally posted by [slint6614-dev](https://github.com/slint6614-dev) on 2026-11-24T07:23:40Z. --- 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.
shortselow-byte commented 2026-11-24 15:03:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by shortselow-byte on 2026-11-24T14:12:34Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7134008754 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/318#issuecomment-7134008754). Originally posted by [shortselow-byte](https://github.com/shortselow-byte) on 2026-11-24T14:12:34Z. --- 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).
upstream-sync closed this pull request 2026-11-24 23:04:04 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!318
No description provided.