Shaders: biased samples with 16-bit coordinates #569

Closed
SAitken91 wants to merge 1 commit from upstream-pr/569 into main
SAitken91 commented 2026-11-24 05:03:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SAitken91 on 2026-11-24T05:03:35Z.


image_sample_b with a16 was refused up front ("a biased image sample with 16-bit coordinates"): 108 programs in shaders.rpf, mostly mirror-reflection and ped pixel shaders.

Change

  • With a16, the extra addresses (offset, bias, compare) still take a whole dword each. The bias is then f16 in the low half, matching LLVM's AMDGPU lowering ("Bias is of type half but occupies full 32-bit"). The packed coordinates start at the next dword.
  • The extras now count as two 16-bit halves each under a16, and the bias is converted from f16 (legacyF16ToF32) instead of being read as f32.
  • The early refusal is removed. Comparison samples with a16 are still refused, as before.
  • Side effect worth reviewing: a16 gathers with offsets (_o) now read their coordinates from the dword after the offset. Before, they were read from the offset dword's high half.

Results

victory translate --validate shaders.rpf: vertex/pixel validated 12172 → 12208 (44 more emitted). The error is gone from the list. The rest of the 108 stop at other cases further in.

Testing

  • cargo test -p victory-shader: 69 passed. Clippy and rustfmt are clean.
  • Not exercised at runtime.

This is independent of #539, #554, #563 and #565.

Written with the help of Claude (AI).

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6575024885 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/569). Originally posted by [SAitken91](https://github.com/SAitken91) on 2026-11-24T05:03:35Z. --- `image_sample_b` with a16 was refused up front ("a biased image sample with 16-bit coordinates"): 108 programs in shaders.rpf, mostly mirror-reflection and ped pixel shaders. ## Change - With a16, the extra addresses (offset, bias, compare) still take a whole dword each. The bias is then f16 in the low half, matching LLVM's AMDGPU lowering ("Bias is of type half but occupies full 32-bit"). The packed coordinates start at the next dword. - The extras now count as two 16-bit halves each under a16, and the bias is converted from f16 (`legacyF16ToF32`) instead of being read as f32. - The early refusal is removed. Comparison samples with a16 are still refused, as before. - **Side effect worth reviewing:** a16 gathers with offsets (`_o`) now read their coordinates from the dword after the offset. Before, they were read from the offset dword's high half. ## Results `victory translate --validate shaders.rpf`: vertex/pixel validated 12172 → 12208 (44 more emitted). The error is gone from the list. The rest of the 108 stop at other cases further in. ## Testing - `cargo test -p victory-shader`: 69 passed. Clippy and rustfmt are clean. - Not exercised at runtime. This is independent of #539, #554, #563 and #565. Written with the help of Claude (AI). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
KoLolX3 commented 2026-11-24 06:56:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KoLolX3 on 2026-11-24T05:31:48Z.


Check on Linux, not Windows: pass. Head aed963792 merged onto main d2a4bae1f (clean merge).

  • Native tests of the seven crates that build on Linux (core, formats, game, loader, pe, pipeline, shader): PR 92 passed, 7 failed, main 92 passed, 7 failed.
  • Windows cross type-check of the whole workspace (cargo xwin check --workspace --target x86_64-pc-windows-msvc, covers victory-gpu, victory-hle and the app): PR ok, main ok.
  • Tests this PR adds: 0 (so the native result only shows the existing tests still pass; the change itself is not covered by a test here).
  • rustfmt: unformatted hunks, PR 168, main 168.
  • Failing on main here as well (not this PR): 7 tests in victory-loader and victory-pe that parse their own test binary as a PE image, which is an ELF file on Linux.
  • Not run: victory-gpu / victory-hle tests and the game itself.

On: AMD Ryzen 7 5700, 62 GB RAM, Artix Linux 7.3.4-artix1-2, rustc 1.98.1 (the repo's pinned toolchain), cargo-xwin 0.24.1. No game data. Automated check only: the code itself was not reviewed.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123033368 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/569#issuecomment-7123033368). Originally posted by [KoLolX3](https://github.com/KoLolX3) on 2026-11-24T05:31:48Z. --- Check on Linux, not Windows: **pass**. Head `aed963792` merged onto `main` `d2a4bae1f` (clean merge). - Native tests of the seven crates that build on Linux (`core`, `formats`, `game`, `loader`, `pe`, `pipeline`, `shader`): PR `92 passed, 7 failed`, `main` `92 passed, 7 failed`. - Windows cross type-check of the whole workspace (`cargo xwin check --workspace --target x86_64-pc-windows-msvc`, covers `victory-gpu`, `victory-hle` and the app): PR ok, `main` ok. - Tests this PR adds: 0 (so the native result only shows the existing tests still pass; the change itself is not covered by a test here). - rustfmt: unformatted hunks, PR 168, `main` 168. - Failing on `main` here as well (not this PR): 7 tests in `victory-loader` and `victory-pe` that parse their own test binary as a PE image, which is an ELF file on Linux. - Not run: `victory-gpu` / `victory-hle` tests and the game itself. On: AMD Ryzen 7 5700, 62 GB RAM, Artix Linux 7.3.4-artix1-2, rustc 1.98.1 (the repo's pinned toolchain), cargo-xwin 0.24.1. No game data. Automated check only: the code itself was not reviewed.
iurysf commented 2026-11-24 06:56:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by iurysf on 2026-11-24T06:17:07Z.


Tested offline against main d2a4bae with victory translate --list --validate over the title's shaders.rpf + executable (26,096 programs), dxil.dll 1.9.2602.17:

  • Translation failures: 3,733 on main -> 3,689 with this PR (-44, all pixel). "a biased image sample with 16-bit coordinates" disappears (108 -> 0). The freed programs mostly stop next at "a scalar memory read as data" (573 -> 621) and "a lane mask read as data" (206 -> 222).
  • Emitted: vertex+pixel 12,284 -> 12,328 (+44). Of those, 8 fail DXIL validation with "Container part 'Program Input Signature' does not match expected for module", so validated goes 12,184 -> 12,220 (+36, not +44). No program that validated on main fails now.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123775412 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/569#issuecomment-7123775412). Originally posted by [iurysf](https://github.com/iurysf) on 2026-11-24T06:17:07Z. --- Tested offline against main `d2a4bae` with `victory translate --list --validate` over the title's `shaders.rpf` + executable (26,096 programs), dxil.dll 1.9.2602.17: - Translation failures: 3,733 on main -> 3,689 with this PR (-44, all pixel). "a biased image sample with 16-bit coordinates" disappears (108 -> 0). The freed programs mostly stop next at "a scalar memory read as data" (573 -> 621) and "a lane mask read as data" (206 -> 222). - Emitted: vertex+pixel 12,284 -> 12,328 (+44). Of those, **8 fail DXIL validation** with "Container part 'Program Input Signature' does not match expected for module", so validated goes 12,184 -> 12,220 (+36, not +44). No program that validated on main fails now. AI-assisted.
mercuryVM commented 2026-11-24 08:02:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T07:10:56Z.

Review: APPROVED


Tested aed9637 on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (264 passed, 0 failed). victory translate <title exe> --validate --pipelines gives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines. These 12 do not use a16 samples, so I could not reproduce the shaders.rpf figures.

  • The address layout matches LLVM's AMDGPU MIMG lowering. Under a16, each extra argument (offset, bias, z-compare) still takes a whole VGPR, and a bias sits as f16 in the low half. Counting extras as 2 halves each gives the right first packed coordinate. Converting the bias with legacyF16ToF32 rather than reading it as f32 is right for that layout.
  • The side effect you flag looks like a fix to me, not a regression. With a16 and an offset, the old code read the first coordinate from the offset dword's high half. By the same layout rule, the coordinates start in the next dword.
  • Comparison samples with a16 stay refused.

No issues found.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6035081257 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/569#pullrequestreview-6035081257). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T07:10:56Z. **Review:** APPROVED --- Tested aed9637 on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (264 passed, 0 failed). `victory translate <title exe> --validate --pipelines` gives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines. These 12 do not use a16 samples, so I could not reproduce the shaders.rpf figures. - The address layout matches LLVM's AMDGPU MIMG lowering. Under a16, each extra argument (offset, bias, z-compare) still takes a whole VGPR, and a bias sits as f16 in the low half. Counting extras as 2 halves each gives the right first packed coordinate. Converting the bias with `legacyF16ToF32` rather than reading it as f32 is right for that layout. - The side effect you flag looks like a fix to me, not a regression. With a16 and an offset, the old code read the first coordinate from the offset dword's high half. By the same layout rule, the coordinates start in the next dword. - Comparison samples with a16 stay refused. No issues found. AI-assisted (Claude Code).
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:37Z.


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:7124941022 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/569#issuecomment-7124941022). Originally posted by [slint6614-dev](https://github.com/slint6614-dev) on 2026-11-24T07:23:37Z. --- 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.
catminou4 commented 2026-11-24 13:01:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T12:44:22Z.

Review: COMMENTED


This enables image_sample_b* (biased image sample) with 16-bit coordinates, which was previously rejected. The operand-layout reasoning in the comment is coherent: with a16, each whole-dword extra (texel offset word, the bias itself, compare value) occupies two 16-bit slots, hence first = 2 * extras, and the bias is read with to_float instead of as_float because it sits in the low half as f16.

Two things before this can be approved:

  1. No test coverage. The diff adds no valu_tests case for a biased image sample with a16 coordinates — this is exactly the kind of operand-indexing change that silently reads the wrong VGPRs if the 2 * extras math is off. A host-execution test (the run_wave_cs-style harness or an image-sample variant) would pin it.
  2. I can't execute SM 6.6 image-sample paths on macOS (execution tests are Windows-gated), so the verification above is static only.

Test-merge with current main (ffe310e) is clean; cargo test -p victory-shader --locked (macOS arm64, rustc 1.98.1) → 96 passed / 0 failed — existing tests unaffected, but they don't touch the new path.

<!-- greyfinch-sync:Marvisak/VIctory:review:6039402497 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/569#pullrequestreview-6039402497). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T12:44:22Z. **Review:** COMMENTED --- This enables `image_sample_b*` (biased image sample) with 16-bit coordinates, which was previously rejected. The operand-layout reasoning in the comment is coherent: with `a16`, each whole-dword extra (texel offset word, the bias itself, compare value) occupies two 16-bit slots, hence `first = 2 * extras`, and the bias is read with `to_float` instead of `as_float` because it sits in the low half as f16. Two things before this can be approved: 1. **No test coverage.** The diff adds no `valu_tests` case for a biased image sample with a16 coordinates — this is exactly the kind of operand-indexing change that silently reads the wrong VGPRs if the `2 * extras` math is off. A host-execution test (the `run_wave_cs`-style harness or an image-sample variant) would pin it. 2. I can't execute SM 6.6 image-sample paths on macOS (execution tests are Windows-gated), so the verification above is static only. Test-merge with current main (`ffe310e`) is clean; `cargo test -p victory-shader --locked` (macOS arm64, rustc 1.98.1) → **96 passed / 0 failed** — existing tests unaffected, but they don't touch the new path.
SAitken91 commented 2026-11-24 14:04:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SAitken91 on 2026-11-24T13:42:33Z.


@catminou4 agreed on the missing test. The layout follows LLVM's AMDGPU MIMG lowering (bias is f16 in the low half of a whole dword under a16; offset and compare stay whole dwords), which mercuryVM checked against the same reference on RTX 5070 earlier; the gain is measured on the title's shaders (+36 VS/PS validated) but no test executes an a16 biased sample yet. A Windows-gated host-execution case with a16 coordinates and a non-zero bias would pin the 2 * extras indexing.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7133220846 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/569#issuecomment-7133220846). Originally posted by [SAitken91](https://github.com/SAitken91) on 2026-11-24T13:42:33Z. --- @catminou4 agreed on the missing test. The layout follows LLVM's AMDGPU MIMG lowering (bias is f16 in the low half of a whole dword under a16; offset and compare stay whole dwords), which mercuryVM checked against the same reference on RTX 5070 earlier; the gain is measured on the title's shaders (+36 VS/PS validated) but no test executes an a16 biased sample yet. A Windows-gated host-execution case with a16 coordinates and a non-zero bias would pin the `2 * extras` indexing.
upstream-sync closed this pull request 2026-11-25 01:04:16 +00:00
Marvisak commented 2026-11-25 01:07:45 +00:00 (Migrated from github.com)

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


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() (extras keep a VGPR each, bias converted with legacyF16ToF32).

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:7148488607 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/569#issuecomment-7148488607). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:25:06Z. --- 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() (extras keep a VGPR each, bias converted with legacyF16ToF32). 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!569
No description provided.