Ready branch: biased image samples with a16 (and the a16 layout of extra address words) #861

Closed
opened 2026-11-26 04:14:04 +00:00 by github-bot · 4 comments
Owner

@⁠anasssssssss1 on GitHub · 2026-11-24 12:52 UTC · original

Branch (PRs are collaborator-only): anasssssssss1:fix-a16-bias, one commit on main ffe310e.

What

image_sample_b with a16 stopped the program ("a biased image sample with 16-bit coordinates"). Lowering it needs the address layout the hardware uses with a16, which the sample path did not follow for any extra word:

  • With a16, the extra words (texel offset, bias, z-compare) keep a whole VGPR each; only gradients and coordinates are packed two per VGPR, and the coordinates start on a fresh VGPR. Each gradient direction is padded to whole VGPRs. (LLVM's AMDGPU backend packs it this way: packImage16bitOpsToDwords, "bias is of type half but occupies full 32-bit".)
  • The bias is an f16 in the low half of its VGPR.

addr_val indexed every logical address as if all were packed, so an a16 sample with an offset word read its coordinates from the wrong halves; that path was already allowed (image_sample_o with a16). The sample path now maps each logical address through slot(), and reads extra words whole (extra()). Without a16 every index is unchanged. image_sample_l's level also goes through slot() (unchanged today, as first and the gradients are 0 there).

Measured

victory translate over the title's shaders.rpf (v1.0.2.1), against main ffe310e:

before after
vertex and pixel programs emitted 12231 of 14027 12275 of 14027
a biased image sample with 16-bit coordinates 108 0

(64 of the 108 now stop at a later reason.) The emitted programs pass dxil.dll validation apart from the PSV0 container mismatch every program shows with the 10.0.22621 SDK validator, on main too.

Checks

cargo clippy --workspace --all-targets --locked -- -D warnings, the same with --all-features, and cargo test --workspace --locked on Windows 11, RTX 4050 Laptop.

**@⁠anasssssssss1** on GitHub · 2026-11-24 12:52 UTC · [original](https://github.com/Marvisak/VIctory/issues/861) Branch (PRs are collaborator-only): [`anasssssssss1:fix-a16-bias`](https://github.com/anasssssssss1/VIctory/commits/fix-a16-bias), one commit on `main` `ffe310e`. ## What `image_sample_b` with `a16` stopped the program ("a biased image sample with 16-bit coordinates"). Lowering it needs the address layout the hardware uses with `a16`, which the sample path did not follow for any extra word: - With `a16`, the extra words (texel offset, bias, z-compare) keep a **whole VGPR each**; only gradients and coordinates are packed two per VGPR, and the coordinates start on a fresh VGPR. Each gradient direction is padded to whole VGPRs. (LLVM's AMDGPU backend packs it this way: `packImage16bitOpsToDwords`, "bias is of type half but occupies full 32-bit".) - The bias is an f16 in the low half of its VGPR. `addr_val` indexed every logical address as if all were packed, so an `a16` sample with an offset word read its coordinates from the wrong halves; that path was already allowed (`image_sample_o` with `a16`). The sample path now maps each logical address through `slot()`, and reads extra words whole (`extra()`). Without `a16` every index is unchanged. `image_sample_l`'s level also goes through `slot()` (unchanged today, as `first` and the gradients are 0 there). ## Measured `victory translate` over the title's `shaders.rpf` (v1.0.2.1), against `main` `ffe310e`: | | before | after | |---|---|---| | vertex and pixel programs emitted | 12231 of 14027 | 12275 of 14027 | | `a biased image sample with 16-bit coordinates` | 108 | 0 | (64 of the 108 now stop at a later reason.) The emitted programs pass `dxil.dll` validation apart from the PSV0 container mismatch every program shows with the 10.0.22621 SDK validator, on `main` too. ## Checks `cargo clippy --workspace --all-targets --locked -- -D warnings`, the same with `--all-features`, and `cargo test --workspace --locked` on Windows 11, RTX 4050 Laptop.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:05 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-24 13:03 UTC · original

I compared e6cff92 with ffe310e and #160 at 6ad7e15 using generated mipmapped textures. Each entry below is the RGBA readback match count on both an RTX 5090 and WARP.

Test Main ffe310e This branch e6cff92 #160 6ad7e15
image_sample_o a16, constant offset (+1, -1) Lowering refuses the offset 32/32 32/32
image_sample_b a16, bias 0 or +1 in the low half and 0x7e00 in the high half Lowering refuses a16 bias 32/32 32/32
Plain 2D image_sample_d a16, four f32 gradient words and one packed UV word 0/32 0/32 32/32

The gradient mismatch is already present on main. Both main and this branch produced validator-accepted DXIL that sampled mip 3 for lane 0, where the fixture expects mip 0. The two implicit-derivative compute controls exercised actual host readback under the fixture's existing validator allowance for this shader stage.

Test-only commit adds the two passing a16 offset and bias controls to #160's existing sampling tests. The gradient control was already there.

**@⁠fuzeofficlal** on GitHub · 2026-11-24 13:03 UTC · [original](https://github.com/Marvisak/VIctory/issues/861#issuecomment-7132278479) I compared `e6cff92` with `ffe310e` and #160 at `6ad7e15` using generated mipmapped textures. Each entry below is the RGBA readback match count on both an RTX 5090 and WARP. | Test | Main `ffe310e` | This branch `e6cff92` | #160 `6ad7e15` | | --- | --- | --- | --- | | `image_sample_o a16`, constant offset `(+1, -1)` | Lowering refuses the offset | 32/32 | 32/32 | | `image_sample_b a16`, bias `0` or `+1` in the low half and `0x7e00` in the high half | Lowering refuses a16 bias | 32/32 | 32/32 | | Plain 2D `image_sample_d a16`, four f32 gradient words and one packed UV word | 0/32 | 0/32 | 32/32 | The gradient mismatch is already present on main. Both main and this branch produced validator-accepted DXIL that sampled mip 3 for lane 0, where the fixture expects mip 0. The two implicit-derivative compute controls exercised actual host readback under the fixture's existing validator allowance for this shader stage. [Test-only commit](https://github.com/fuzeofficlal/VIctory/commit/62e06a1c10a39dcba7e302ba9f20ee7e7c2ba3d9) adds the two passing a16 offset and bias controls to #160's existing sampling tests. The gradient control was already there.
Author
Owner

@⁠Sunkiller-qc on GitHub · 2026-11-24 13:09 UTC · original

#569 (SAitken91, open) is the same fix: image_sample_b with a16 is refused with "a biased image sample with 16-bit coordinates", and with a16 the extra addresses (offset, bias, compare) still take a whole VGPR each. It reports 108 programs in shaders.rpf. #306 also enables a16 biased samples as part of a larger change. fuzeofficlal's readback table above would be useful on #569 too, so the two can be compared directly.

**@⁠Sunkiller-qc** on GitHub · 2026-11-24 13:09 UTC · [original](https://github.com/Marvisak/VIctory/issues/861#issuecomment-7132420680) #569 (SAitken91, open) is the same fix: `image_sample_b` with a16 is refused with "a biased image sample with 16-bit coordinates", and with a16 the extra addresses (offset, bias, compare) still take a whole VGPR each. It reports 108 programs in shaders.rpf. #306 also enables a16 biased samples as part of a larger change. fuzeofficlal's readback table above would be useful on #569 too, so the two can be compared directly.
Author
Owner

@⁠anasssssssss1 on GitHub · 2026-11-24 13:11 UTC · original

Correction, and closing this as superseded.

r4tedx/VIctory:integration/testers (92bc27b) already lowers biased a16 samples, with the extra words a dword each as here, and with one difference that makes it the better one: on GFX10.3 the derivatives are 16-bit only in the g16 opcodes, not because a16 is set (LLVM's lowerImage keeps the two apart where the target has G16). My branch packs the derivatives whenever a16 is set, which is wrong for image_sample_d* with a16 on this GPU. The other cases (offset, bias, coordinates) agree.

Please take the testers tree's version rather than fix-a16-bias.

**@⁠anasssssssss1** on GitHub · 2026-11-24 13:11 UTC · [original](https://github.com/Marvisak/VIctory/issues/861#issuecomment-7132475596) Correction, and closing this as superseded. `r4tedx/VIctory:integration/testers` (`92bc27b`) already lowers biased `a16` samples, with the extra words a dword each as here, and with one difference that makes it the better one: on GFX10.3 the derivatives are 16-bit only in the `g16` opcodes, not because `a16` is set (LLVM's `lowerImage` keeps the two apart where the target has G16). My branch packs the derivatives whenever `a16` is set, which is wrong for `image_sample_d*` with `a16` on this GPU. The other cases (offset, bias, coordinates) agree. Please take the testers tree's version rather than `fix-a16-bias`.
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 13:02 UTC · original · edited 2026-11-24 13:13 UTC

Daniel checked the A16 bias layout numerically in a Wave64 compute shader on the focused #180 gradient integration. The bias register held +1.0 in the low half and +2.0 in the high half, with the packed coordinates in the next register. The gradient-only baseline (0831e88) refused this sample at byte 104. With your A16 change, the emitted SampleGrad shader passed Microsoft DXV without a fixed wave size.

On an RTX 4090 under Wine/vkd3d-proton 3.2, 32 lanes sampled mip 0 and the other 32 sampled mip 2. All 64 outputs matched the independently compiled DXC reference. This checks bias and address decoding together on the compute path. Your vertex/pixel corpus counts and the shader's effect on a rendered game frame are separate measurements. Integration commit

Daniel also tested a 1D A16 sample with explicit gradients. Microsoft DXV accepted both versions. On the same RTX 4090, baseline 0831e88 read padding as a derivative and selected mip 2 for all 64 lanes. With the corrected register layout at 9aa5338, 32 lanes selected mip 0 (9.0) and 32 selected mip 2 (81.0), matching the independent DXC reference in every lane. This case demonstrates a sampling error that an emission or validation count would miss. No title run was involved.
A separate patterned 2D texture checked the signed texel offset and coordinate placement. The baseline refused the constant (+1, −2) offset at byte 76 as nonconstant. On the port, Microsoft DXV accepted the same shader, and all 64 lanes read value 21 from texel (5, 2), exactly matching DXC. The offset and packed coordinates occupied separate registers with distinct halfwords.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 13:02 UTC · [original](https://github.com/Marvisak/VIctory/issues/861#issuecomment-7132259104) · edited 2026-11-24 13:13 UTC Daniel checked the A16 bias layout numerically in a Wave64 compute shader on the focused #180 gradient integration. The bias register held +1.0 in the low half and +2.0 in the high half, with the packed coordinates in the next register. The gradient-only baseline (`0831e88`) refused this sample at byte 104. With your A16 change, the emitted SampleGrad shader passed Microsoft DXV without a fixed wave size. On an RTX 4090 under Wine/vkd3d-proton 3.2, 32 lanes sampled mip 0 and the other 32 sampled mip 2. All 64 outputs matched the independently compiled DXC reference. This checks bias and address decoding together on the compute path. Your vertex/pixel corpus counts and the shader's effect on a rendered game frame are separate measurements. [Integration commit](https://github.com/MichaelSmithAI/VIctory/commit/9aa53383e556faa6a3f6f11c8b5a89cca5cc591c) Daniel also tested a 1D A16 sample with explicit gradients. Microsoft DXV accepted both versions. On the same RTX 4090, baseline `0831e88` read padding as a derivative and selected mip 2 for all 64 lanes. With the corrected register layout at `9aa5338`, 32 lanes selected mip 0 (9.0) and 32 selected mip 2 (81.0), matching the independent DXC reference in every lane. This case demonstrates a sampling error that an emission or validation count would miss. No title run was involved. A separate patterned 2D texture checked the signed texel offset and coordinate placement. The baseline refused the constant (+1, −2) offset at byte 76 as nonconstant. On the port, Microsoft DXV accepted the same shader, and all 64 lanes read value 21 from texel (5, 2), exactly matching DXC. The offset and packed coordinates occupied separate registers with distinct halfwords.
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#861
No description provided.