Skip to content

Shaders: biased samples with 16-bit coordinates - #569

Closed
SAitken91 wants to merge 1 commit into
Marvisak:mainfrom
SAitken91:shader/a16-biased-sample
Closed

SAitken91 wants to merge 1 commit into
Marvisak:mainfrom
SAitken91:shader/a16-biased-sample

Conversation

@SAitken91

Copy link
Copy Markdown
Contributor

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

image_sample_b with a16 was refused ("a biased image sample with 16-bit
coordinates"). With a16 the extra addresses (offset, bias, compare)
still take a whole dword each, a bias being f16 in the low half (as
LLVM's AMDGPU backend lays it out), and the packed coordinates start at
the next dword. The extras now count two 16-bit halves each with a16,
and the bias converts from f16.

This also moves the coordinates of a16 gathers with offsets (`_o`) to
the dword after the offset; they were read from the offset dword's
high half.

translate --validate on shaders.rpf: vertex/pixel 12172 -> 12208
validated (44 more emitted); the error is gone from the list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KoLolX3

KoLolX3 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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

iurysf commented Nov 24, 2026

Copy link
Copy Markdown

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 mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
…oordinates

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@slint6614-dev

Copy link
Copy Markdown

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 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

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

@Marvisak

Copy link
Copy Markdown
Owner

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.

@Marvisak Marvisak closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants