Shaders: a biased sample of 16-bit coordinates reads its bias from its own VGPR #1245

Closed
nicogunvis-boop wants to merge 1 commit from upstream-pr/1245 into main
nicogunvis-boop commented 2026-11-24 16:46:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by nicogunvis-boop on 2026-11-24T16:46:16Z.


What

image_sample_b with a16 was refused with "a biased image sample with 16-bit coordinates". On GFX10, with a16, the words before the coordinates (texel offset, bias) still take a whole VGPR each. The bias is an f16 in the low half of its VGPR, and the packed 16-bit coordinates start at the next VGPR. An instance from the retail title, disassembled locally (registers only):

s_mov_b32 s13, 0xbc00          ; -1.0 as f16
v_mov_b32 v19, s13             ; bias VGPR
v_pack_b32_f16 v20, 0, 0       ; coordinates (u, v) as f16
image_sample_b v19, v[19:20], s[0:7], s[28:31] dmask:0x1 dim:SQ_RSRC_IMG_2D a16

Change (crates/victory-shader/src/emit/lower.rs)

  • The refusal is removed. The bias is read whole from its VGPR and, with a16, converted from the f16 in its low half (legacyF16ToF32).
  • Under a16, coordinates and gradients now start after first whole VGPRs (base = 2 * first address components) instead of at component first. This also changes where image_sample_o / image_gather4_lz_o with a16 read their coordinates: they previously read the offset VGPR's high half as the first coordinate. The offset word is now read whole in both paths.
  • Test: a_biased_sample_of_16_bit_coordinates_reads_the_bias_from_its_own_vgpr (synthetic program with the same instruction shape). Before the change it is refused.

Measured

victory translate --validate on the retail package (Windows 11, dxil.dll from SDK 10.0.26100):

before after
"a biased image sample with 16-bit coordinates" 108 0
VS/PS emitted 12,243 12,287
VS/PS validated 12,167 12,203

Of the 108 formerly refused programs, 36 now validate. The others stop on causes with open PRs: 48 "a scalar memory read as data", 16 "a lane mask read as data", 8 an input-signature validator error. No other program's outcome changed (25,891 compared).

cargo test -p victory-shader --lib emit::lower: 12 passed. cargo clippy -p victory-shader --all-targets -- -D warnings: clean.

Not yet checked in a running world frame (the world is black on main). Tested on an RTX 4070.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6586843895 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1245). Originally posted by [nicogunvis-boop](https://github.com/nicogunvis-boop) on 2026-11-24T16:46:16Z. --- ## What `image_sample_b` with `a16` was refused with "a biased image sample with 16-bit coordinates". On GFX10, with a16, the words before the coordinates (texel offset, bias) still take a whole VGPR each. The bias is an f16 in the low half of its VGPR, and the packed 16-bit coordinates start at the next VGPR. An instance from the retail title, disassembled locally (registers only): ``` s_mov_b32 s13, 0xbc00 ; -1.0 as f16 v_mov_b32 v19, s13 ; bias VGPR v_pack_b32_f16 v20, 0, 0 ; coordinates (u, v) as f16 image_sample_b v19, v[19:20], s[0:7], s[28:31] dmask:0x1 dim:SQ_RSRC_IMG_2D a16 ``` ## Change (`crates/victory-shader/src/emit/lower.rs`) - The refusal is removed. The bias is read whole from its VGPR and, with a16, converted from the f16 in its low half (`legacyF16ToF32`). - Under a16, coordinates and gradients now start after `first` whole VGPRs (`base = 2 * first` address components) instead of at component `first`. This also changes where `image_sample_o` / `image_gather4_lz_o` with a16 read their coordinates: they previously read the offset VGPR's high half as the first coordinate. The offset word is now read whole in both paths. - Test: `a_biased_sample_of_16_bit_coordinates_reads_the_bias_from_its_own_vgpr` (synthetic program with the same instruction shape). Before the change it is refused. ## Measured `victory translate --validate` on the retail package (Windows 11, dxil.dll from SDK 10.0.26100): | | before | after | |---|---:|---| | "a biased image sample with 16-bit coordinates" | 108 | 0 | | VS/PS emitted | 12,243 | 12,287 | | VS/PS validated | 12,167 | 12,203 | Of the 108 formerly refused programs, 36 now validate. The others stop on causes with open PRs: 48 "a scalar memory read as data", 16 "a lane mask read as data", 8 an input-signature validator error. No other program's outcome changed (25,891 compared). `cargo test -p victory-shader --lib emit::lower`: 12 passed. `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. Not yet checked in a running world frame (the world is black on `main`). Tested on an RTX 4070.
pablogonz12 commented 2026-11-24 17:04:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pablogonz12 on 2026-11-24T17:03:23Z.


Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main ffe310e plus #1017 — main's host build is broken without it (E0425 host_resource in victory-gpu), so the base is that pair. Ran the four-stage offline check (translate, dxil-spirv, spirv-val, RADV pipeline) over 768 programs: the 751-program world dump plus a 52-program BVH capture, 35 duplicate containers skipped.

translate valid SPIR-V RADV pipeline
base 666 / 768 656 656
your head 666 / 768 656 656

No program gained or lost and the failure table is identical to the base, reason for reason: nothing in this capture reaches the class you lower, so this is a no-regression result only (same 10 SPIR-V validation failures as the base).

Not tested: in-game.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7138616370 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1245#issuecomment-7138616370). Originally posted by [pablogonz12](https://github.com/pablogonz12) on 2026-11-24T17:03:23Z. --- Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main `ffe310e` plus #1017 — main's host build is broken without it (`E0425 host_resource` in `victory-gpu`), so the base is that pair. Ran the four-stage offline check (translate, dxil-spirv, spirv-val, RADV pipeline) over 768 programs: the 751-program world dump plus a 52-program BVH capture, 35 duplicate containers skipped. | | translate | valid SPIR-V | RADV pipeline | |---|---|---|---| | base | 666 / 768 | 656 | 656 | | your head | 666 / 768 | 656 | 656 | No program gained or lost and the failure table is identical to the base, reason for reason: nothing in this capture reaches the class you lower, so this is a no-regression result only (same 10 SPIR-V validation failures as the base). Not tested: in-game.
geiyiliyabumo commented 2026-11-24 18:05:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T17:35:07Z.


Independent verification of \e6dfe9c\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200) / Rust 1.98.1 MSVC:

  • Merge check vs \main\ (\ fe310e): clean
  • \cargo test -p victory-shader --lib: 121 passed, 0 failed, 1 ignored (including \_biased_sample_of_16_bit_coordinates_reads_the_bias_from_its_own_vgpr)
  • \cargo clippy -p victory-shader --all-targets -- -D warnings\ (default and --all-features): clean
  • \cargo xtask policy: 154 files ok

Two small notes from code review:

  • \extra_dword(self, 0)\ cleanly keeps _o\ offset words and _b\ bias in full VGPRs ahead of packed 16-bit coordinates; note this region of \Lower::image\ overlaps with #1209 (which also updates \image_sample_d\ so gradients stay full-dword \ 32\ under \16\ unless _g16\ is set—here \op == 63\ still routes gradients through \ddr_val/\ o_float).

AI-assisted; synthetic tests only, no game files.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139411622 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1245#issuecomment-7139411622). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T17:35:07Z. --- Independent verification of \e6dfe9c\ on **Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200\) / Rust 1.98.1 MSVC**: - Merge check vs \main\ (\ fe310e\): clean - \cargo test -p victory-shader --lib\: **121 passed, 0 failed, 1 ignored** (including \_biased_sample_of_16_bit_coordinates_reads_the_bias_from_its_own_vgpr\) - \cargo clippy -p victory-shader --all-targets -- -D warnings\ (default and \--all-features\): clean - \cargo xtask policy\: 154 files ok Two small notes from code review: - \extra_dword(self, 0)\ cleanly keeps \_o\ offset words and \_b\ bias in full VGPRs ahead of packed 16-bit coordinates; note this region of \Lower::image\ overlaps with #1209 (which also updates \image_sample_d\ so gradients stay full-dword \ 32\ under \16\ unless \_g16\ is set—here \op == 63\ still routes gradients through \ddr_val\/\ o_float\). *AI-assisted; synthetic tests only, no game files.*
Zipettte commented 2026-11-24 18:06:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T17:59:29Z.


Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 6751dc7: cargo test -p victory-shader passes, 121 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139997998 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1245#issuecomment-7139997998). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T17:59:29Z. --- Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 6751dc7: `cargo test -p victory-shader` passes, 121 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
upstream-sync closed this pull request 2026-11-25 01:06:00 +00:00
Marvisak commented 2026-11-25 01:08:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:35:30Z.


Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

a16 biased samples are in main's image(), with the same layout (bias f16 in its own VGPR, coordinates packed after).

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148671409 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1245#issuecomment-7148671409). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:35:30Z. --- Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. a16 biased samples are in main's image(), with the same layout (bias f16 in its own VGPR, coordinates packed after). If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

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