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

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/1256 into main
fuzeofficlal commented 2026-11-24 16:49:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T16:49:33Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5476505428 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1256). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-24T16:49:33Z. --- 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.
DenRakEiw commented 2026-11-24 16:56:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T16:56:56Z.

Review: APPROVED


Tested head 18a1073 (fast-forward on main ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC):

  • cargo test -p victory-shader emit::lower: 12 passed, 0 failed (including cube_array_encodings_and_linked_resinfo_lower)
  • cargo clippy -p victory-shader --all-targets: 0 warnings
  • cargo xtask policy: ok

Clean cube-array slice/face decoding in image lowering. Approving.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6043699552 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1256#pullrequestreview-6043699552). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-24T16:56:56Z. **Review:** APPROVED --- Tested head `18a1073` (fast-forward on `main` `ffe310e`) on Windows 11 x64 (Rust 1.98.1 MSVC): - `cargo test -p victory-shader emit::lower`: **12 passed, 0 failed** (including `cube_array_encodings_and_linked_resinfo_lower`) - `cargo clippy -p victory-shader --all-targets`: **0 warnings** - `cargo xtask policy`: ok Clean cube-array slice/face decoding in image lowering. Approving. AI-assisted (Gemini 4 Neon).
pablogonz12 commented 2026-11-24 17:04:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pablogonz12 on 2026-11-24T17:03:19Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7138615034 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1256#issuecomment-7138615034). Originally posted by [pablogonz12](https://github.com/pablogonz12) on 2026-11-24T17:03:19Z. --- 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.
Marvisak commented 2026-11-25 02:05:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:20:05Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149440660 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1256#issuecomment-7149440660). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:20:05Z. --- <!-- 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)_
andrewpozdnakov7-jpg commented 2026-11-27 12:37:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T12:37:31Z.


I combined exact #1256 e516804 and #2372 3e624cc on main 63bcca4. The integration branch is 76ef8b4 and preserves both heads.

The two changes expose a face-operand lookup issue. After resolving the merge, a test of cube_arrays with 32-bit derivatives and a16 coordinates found zero array sites for a face operand of 10. The inference divided the gradient prefix by two along with the coordinates. It now counts the actual gradient VGPRs first, then finds the face in the coordinate registers. The same test passes for all four a16/g16 combinations.

A new readback uses a two-cube array with four mip levels. All 16 WARP cases returned the expected layer, face and mip tag, including the clamped face and minimum LOD cases. All nine cube tests and the separate a16 mip query passed. Full shader suite: 327 passed, 5 failed, 3 ignored. The five are existing WARP gather, permute and edge-flag failures. Strict shader Clippy and asset policy passed. For the face 6/7 hardware reference, see the RDNA2 results in #720.

If folding in the resolution or the new regressions, please retain Git attribution or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

AI-assisted with Codex. Synthetic fixtures only.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7218478633 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1256#issuecomment-7218478633). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T12:37:31Z. --- I combined exact #1256 `e516804` and #2372 `3e624cc` on main `63bcca4`. The [integration branch](https://github.com/andrewpozdnakov7-jpg/VIctory/tree/review/cube-arrays-and-gradient-packing) is `76ef8b4` and preserves both heads. The two changes expose a face-operand lookup issue. After resolving the merge, a test of `cube_arrays` with 32-bit derivatives and `a16` coordinates found zero array sites for a face operand of 10. The inference divided the gradient prefix by two along with the coordinates. It now counts the actual gradient VGPRs first, then finds the face in the coordinate registers. The same test passes for all four `a16`/`g16` combinations. A new readback uses a two-cube array with four mip levels. All 16 WARP cases returned the expected layer, face and mip tag, including the clamped face and minimum LOD cases. All nine cube tests and the separate `a16` mip query passed. Full shader suite: 327 passed, 5 failed, 3 ignored. The five are existing WARP gather, permute and edge-flag failures. Strict shader Clippy and asset policy passed. For the face 6/7 hardware reference, see [the RDNA2 results in #720](https://github.com/Marvisak/VIctory/issues/720#issuecomment-7131902076). If folding in the resolution or the new regressions, please retain Git attribution or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`. AI-assisted with Codex. Synthetic fixtures only.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1256:upstream-pr/1256'
git switch 'upstream-pr/1256'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1256'
git switch 'upstream-pr/1256'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1256'
git switch 'upstream-pr/1256'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1256'
git switch 'main'
git merge --squash 'upstream-pr/1256'
git switch 'main'
git merge --ff-only 'upstream-pr/1256'
git switch 'main'
git merge 'upstream-pr/1256'
git push origin 'main'
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!1256
No description provided.