Shaders: decode cube-array slice and face in image lowering #1256

Open
github-bot wants to merge 1 commit from github-bot/gh-1256 into main AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-24 16:49 UTC · original
fuzeofficlal:fix/cubemap-array-sampling-720 → main · +1174 −40 · 4 files · 1 commits · open

Fixes #720.

Summary

RDNA2 MIMG carries no separate dimension bit for cube-map arrays (dim:CUBE = 3 is shared by TextureCube and TextureCubeArray): the compiler packs the third coordinate operand as 8 * slice + face and expects channel 2 of image_get_resinfo to report the view's face count (NumCubes * 6).

  • Infer TextureCubeArray (DXIL kind 9) when a dim == 3 sample or gather4 builds its face operand by multiplying by 8.0 (covering literal, inline, omod, SGPR/VGPR constant sources, and a16 half-float coordinates) or from a constant >= 8.0, when image_get_resinfo has a live channel-2 read, or when another cube site shares the same descriptor slot. Plain TextureCube sites remain kind 5.
  • Decode slice and face matching RDNA2 hardware behavior: split the face operand into idx & 7 with unsigned clamping of face IDs 6 and 7 to face 5 (-Z), and pass float(idx >> 3) as the fourth sampling coordinate while keeping integer texel offsets undef for kind 9.
  • Scale image_get_resinfo channel 2 by 6 on TextureCubeArray handles so D3D12's cube count matches RDNA2's face count.

Verification

  • Synthetic DXIL lowering + dxil.dll validation tests across image_sample* (_lz, _l, _b, _c_lz, a16), image_gather4_lz, and standalone / descriptor-linked image_get_resinfo.
  • End-to-end synthetic GPU readback tests (2-cube / 12-face and 3-cube / 18-face textures, all layers × face IDs 0..8 including 6, 7 -> 5 clamping, gather4, resinfo, and plain TextureCube non-regression) executed across:
    • NVIDIA GeForce RTX 5090
    • AMD Radeon(TM) Graphics
    • D3D12 WARP
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings and cargo xtask policy pass.
**@⁠fuzeofficlal** on GitHub · 2026-11-24 16:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/1256) `fuzeofficlal:fix/cubemap-array-sampling-720` → `main` · +1174 −40 · 4 files · 1 commits · open Fixes #720. ### Summary RDNA2 `MIMG` carries no separate dimension bit for cube-map arrays (`dim:CUBE` = 3 is shared by `TextureCube` and `TextureCubeArray`): the compiler packs the third coordinate operand as `8 * slice + face` and expects channel 2 of `image_get_resinfo` to report the view's face count (`NumCubes * 6`). - **Infer `TextureCubeArray` (DXIL kind 9)** when a `dim == 3` sample or `gather4` builds its face operand by multiplying by `8.0` (covering literal, inline, `omod`, SGPR/VGPR constant sources, and `a16` half-float coordinates) or from a constant `>= 8.0`, when `image_get_resinfo` has a live channel-2 read, or when another cube site shares the same descriptor slot. Plain `TextureCube` sites remain kind 5. - **Decode slice and face matching RDNA2 hardware behavior**: split the face operand into `idx & 7` with unsigned clamping of face IDs `6` and `7` to face `5` (`-Z`), and pass `float(idx >> 3)` as the fourth sampling coordinate while keeping integer texel offsets `undef` for kind 9. - **Scale `image_get_resinfo` channel 2 by 6** on `TextureCubeArray` handles so D3D12's cube count matches RDNA2's face count. ### Verification - Synthetic DXIL lowering + `dxil.dll` validation tests across `image_sample*` (`_lz`, `_l`, `_b`, `_c_lz`, `a16`), `image_gather4_lz`, and standalone / descriptor-linked `image_get_resinfo`. - End-to-end synthetic GPU readback tests (2-cube / 12-face and 3-cube / 18-face textures, all layers × face IDs `0..8` including `6, 7 -> 5` clamping, `gather4`, `resinfo`, and plain `TextureCube` non-regression) executed across: - **NVIDIA GeForce RTX 5090** - **AMD Radeon(TM) Graphics** - **D3D12 WARP** - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` and `cargo xtask policy` pass.
RDNA2 encodes the face operand of `dim:CUBE` samples and gathers on a
cube-map array as `8 * slice + face`, with no separate array dimension
bit in MIMG, and reports `image_get_resinfo` channel 2 in faces rather
than cubes.

Infer `TextureCubeArray` (DXIL kind 9) when a cube sample or gather
builds its face operand by multiplying by 8.0 or from a constant at or
above 8.0, when `image_get_resinfo` has a live channel-2 read, or when
another cube access on the same descriptor is an array. Split the face
operand into `face & 7` (clamping 6 and 7 to face 5, as on RDNA2) and
`face >> 3` as the fourth sampling coordinate, keep integer offsets
undef for kind 9, and scale D3D's cube count by 6 for `resinfo`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:25:16 +00:00
Author
Owner

@⁠pablogonz12 on GitHub · 2026-11-24 17:03 UTC · original

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.

**@⁠pablogonz12** on GitHub · 2026-11-24 17:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/1256#issuecomment-7138615034) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:20 UTC · original · edited 2026-11-26 01:18 UTC

Automated triage for the maintainers.

Merge candidate (kept). The new head (e516804) is the same change as one commit on current main, and it merges cleanly. The inference now lives in its own module, emit/lower/cube_array.rs (cube_arrays).

The behaviour is unchanged from the last review. A dim == 3 site becomes TextureCubeArray (kind 9) when its face operand is 8 × slice + face, a constant of at least 8, or a live resinfo channel 2, or when it shares a descriptor with such a site. cube_direction splits the operand into idx & 7 and idx >> 3, and resinfo channel 2 is scaled by 6. A plain cube still lowers as kind 5.

One more thing in the new head: cube gathers with an offset are now refused ("a cube gather with an offset"). The clamp of face ids 6 and 7 to face 5 still has no stated hardware reference. It would be welcome, but it doesn't block.

CI: passing (check). Recommending a look, not approving.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/1256#issuecomment-7149440660) · edited 2026-11-26 01:18 UTC <!-- victory-triage v1 head=e516804dd820547504fc99ca25ca66394bb3ed9d verdict=merge-candidate at=2026-11-26T01:18:56Z --> Automated triage for the maintainers. **Merge candidate (kept).** The new head (`e516804`) is the same change as one commit on current `main`, and it merges cleanly. The inference now lives in its own module, `emit/lower/cube_array.rs` (`cube_arrays`). The behaviour is unchanged from the last review. A `dim == 3` site becomes `TextureCubeArray` (kind 9) when its face operand is `8 × slice + face`, a constant of at least 8, or a live resinfo channel 2, or when it shares a descriptor with such a site. `cube_direction` splits the operand into `idx & 7` and `idx >> 3`, and resinfo channel 2 is scaled by 6. A plain cube still lowers as kind 5. One more thing in the new head: cube gathers with an offset are now refused (`"a cube gather with an offset"`). The clamp of face ids 6 and 7 to face 5 still has no stated hardware reference. It would be welcome, but it doesn't block. CI: passing (`check`). Recommending a look, not approving. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1256/head:github-bot/gh-1256'
git switch 'github-bot/gh-1256'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1256'
git switch 'github-bot/gh-1256'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1256'
git switch 'github-bot/gh-1256'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1256'
git switch 'main'
git merge --squash 'github-bot/gh-1256'
git switch 'main'
git merge --ff-only 'github-bot/gh-1256'
git switch 'main'
git merge 'github-bot/gh-1256'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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!1256
No description provided.