Preserve Z offsets in 3D texture samples #2676

Merged
masteraapjes merged 1 commit from upstream-pr/2676 into main 2026-11-30 14:12:01 +00:00
masteraapjes commented 2026-11-29 15:52:58 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by masteraapjes on 2026-11-29T15:52:58Z.


What it changes

image_sample_*_o extracts only X/Y from the packed texel-offset word. For
3D textures it silently samples at Z offset zero. With A16 coordinates, the
offset word is also incorrectly unpacked as a half coordinate, losing its
upper bits. The pixel immediate-offset path likewise stops after two axes.

Read the offset as a whole 32-bit VGPR, decode all three signed six-bit fields,
and include Z when making pixel offsets immediate. The axis count still
excludes array slices and gives cube samples no offsets. Translator source
fingerprinting automatically invalidates the affected shader-cache keys.

The bit layout follows AMD RDNA 2 ISA section 8.2.5 (page 73).

How it was tested

  • Windows, Rust 1.98.1, NVIDIA GeForce RTX 3090 and D3D12 WARP; synthetic
    wave32 compute shaders, plus pixel-shader lowering checks. No game files.
  • Before: the new GPU regression fails on WARP for offset [0,0,1]: it reads
    [8,8,8,1] instead of [8,8,9,1].
  • After: all 32 GPU sample results match exactly (eight cases, normal/A16
    coordinates, WARP/hardware). Covers zero, signed Z, mixed XYZ and reserved
    bits, using a generated 3D texture whose RGB records its texel coordinates.
  • Three companion IR tests cover computed signed-six-bit limits, full-word
    offsets with A16, 1D/2D array dimensions, and all three pixel immediates.
  • Full shader library suite: cargo test --locked -p victory-shader --features diagnostics --lib: 466 passed, 0 failed, 9 ignored.
  • cargo test --locked -p victory-shader --features diagnostics sample_offsets -- --nocapture: all four regressions passed.
  • Staged asset policy: all five changed files passed. git diff --check passed.
  • Clippy passes when only the existing unused-import, immutable-condition and
    too-many-arguments lints are allowed on the command line; no lint settings
    were changed in the source or CI.
  • Strict Clippy is blocked by pre-existing unused imports, the immutable
    condition in lower/analysis.rs, and native.rs's eight-argument test helper.

GPU regressions use the existing SM 6.6 immediate range [-8,7]. IR tests check
six-bit decoding; this does not add host legalization for wider or dynamic
sample offsets. In-game appearance has not been measured.

Checked for overlap

  • Searched open PRs for the opcodes, 3D offsets and changed paths.
    Related: #2522 handles cube-array sampling; #2387 handles array LOD
    coordinates. Neither corrects packed XYZ offset decoding.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5552401941 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2676). Originally posted by [masteraapjes](https://github.com/masteraapjes) on 2026-11-29T15:52:58Z. --- ## What it changes `image_sample_*_o` extracts only X/Y from the packed texel-offset word. For 3D textures it silently samples at Z offset zero. With A16 coordinates, the offset word is also incorrectly unpacked as a half coordinate, losing its upper bits. The pixel immediate-offset path likewise stops after two axes. Read the offset as a whole 32-bit VGPR, decode all three signed six-bit fields, and include Z when making pixel offsets immediate. The axis count still excludes array slices and gives cube samples no offsets. Translator source fingerprinting automatically invalidates the affected shader-cache keys. The bit layout follows [AMD RDNA 2 ISA section 8.2.5 (page 73)](https://docs.amd.com/api/khub/documents/Et~wpu9g~Ffl7d9q0QZ~Og/content). ## How it was tested - Windows, Rust 1.98.1, NVIDIA GeForce RTX 3090 and D3D12 WARP; synthetic wave32 compute shaders, plus pixel-shader lowering checks. No game files. - Before: the new GPU regression fails on WARP for offset [0,0,1]: it reads [8,8,8,1] instead of [8,8,9,1]. - After: all 32 GPU sample results match exactly (eight cases, normal/A16 coordinates, WARP/hardware). Covers zero, signed Z, mixed XYZ and reserved bits, using a generated 3D texture whose RGB records its texel coordinates. - Three companion IR tests cover computed signed-six-bit limits, full-word offsets with A16, 1D/2D array dimensions, and all three pixel immediates. - Full shader library suite: `cargo test --locked -p victory-shader --features diagnostics --lib`: 466 passed, 0 failed, 9 ignored. - `cargo test --locked -p victory-shader --features diagnostics sample_offsets -- --nocapture`: all four regressions passed. - Staged asset policy: all five changed files passed. `git diff --check` passed. - Clippy passes when only the existing unused-import, immutable-condition and too-many-arguments lints are allowed on the command line; no lint settings were changed in the source or CI. - Strict Clippy is blocked by pre-existing unused imports, the immutable condition in lower/analysis.rs, and native.rs's eight-argument test helper. GPU regressions use the existing SM 6.6 immediate range [-8,7]. IR tests check six-bit decoding; this does not add host legalization for wider or dynamic sample offsets. In-game appearance has not been measured. ## Checked for overlap - [x] Searched open PRs for the opcodes, 3D offsets and changed paths. Related: #2522 handles cube-array sampling; #2387 handles array LOD coordinates. Neither corrects packed XYZ offset decoding.
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
trustno1-coder/VIctory-NVIDIA!2676
No description provided.