Shaders: cube-map arrays sample layer 0, and the +X face for any layer above 0 #720

Open
opened 2026-11-26 04:13:53 +00:00 by github-bot · 16 comments
Owner

@⁠Dufftwt on GitHub · 2026-11-24 08:25 UTC · original

What's wrong

For a cube-map array, RDNA2 takes the face operand of image_sample* / image_gather4* (dim CUBE) as 8 × layer + face. Mesa's ac_nir_lower_tex_coords.c (prepare_cube_coords) builds it exactly that way: id = ffma(layer, 8.0, face).

The lowering treats that operand as a bare face id:

  • cube_direction (crates/victory-shader/src/emit/lower.rs:5923) converts it with FpToUi and matches it only against 0–5. For any layer ≥ 1, no face matches, so it falls back to +X.
  • dim 3 is always declared TextureCube (kind 5, :5427-5441), so the layer is never passed to the host.
  • image_get_resinfo on a cube reads 1 for the array size (:5636).

The code already marks this as a shortcut: (:5921). I'm filing it because the result isn't a refusal or a log line but silently wrong texels: layer 0's data, from the +X face.

Example

A 2-cube array, image_sample_lz with s = t = 1.5 and a face operand of 10.0 (layer 1, face 2 = +Y):

  • Console: the centre texel of layer 1's +Y face.
  • Ours: direction (1, 0, 0), the +X face, through a TextureCube handle on a cube-array view.

A shader of the encodings below lowers without any refusal today:

s_mov_b32 s5, 0
s_load_dwordx8 s[8:15], s[4:5], 0                   F40C0202 FA000000
s_load_dwordx4 s[20:23], s[4:5], 32                 F4080502 FA000020
(immediate sampler in s[16:19])
v1 = v2 = 1.5, v3 = 10.0 (0x41200000)
image_sample_lz v4, v[1:3], s[8:15], s[16:19] dmask:1 dim:CUBE    F09C0118 00820401
buffer_store_dword v4, off, s[20:23]                E0700000 80050400

Suggested fix

  1. Split the operand: layer = floor(face × 0.125) and id = face − 8 × layer, then pass id to cube_direction.
  2. When the shader can be an array (the operand isn't a bare v_cubeid_f32 result; titles build it with v_fma/v_fmac/v_madak by 8.0), declare TextureCubeArray (DXIL kind 9) and pass the layer as coordinate 3. GFX10 MIMG has no DA bit, so the kind has to be inferred like this, or taken from the bound view.
  3. In image_get_resinfo, return the array size for kind 9. I'm not sure whether titles expect it in cubes or in faces.

Not tested: on a GPU. A WARP test with a cube-array view whose texels hold 10 × layer + face would show it: a face operand of 10.0 should read 12.0, and gives 0.0 today. A face operand of 2.0, the control, should already pass.

#109, #138, #317 and #563 touch cube sampling, and #568 adds null cube-array descriptors; none decodes the layer.

**@⁠Dufftwt** on GitHub · 2026-11-24 08:25 UTC · [original](https://github.com/Marvisak/VIctory/issues/720) ## What's wrong For a cube-map **array**, RDNA2 takes the face operand of `image_sample*` / `image_gather4*` (dim `CUBE`) as `8 × layer + face`. Mesa's `ac_nir_lower_tex_coords.c` (`prepare_cube_coords`) builds it exactly that way: `id = ffma(layer, 8.0, face)`. The lowering treats that operand as a bare face id: - `cube_direction` (`crates/victory-shader/src/emit/lower.rs:5923`) converts it with `FpToUi` and matches it only against 0–5. For any layer ≥ 1, no face matches, so it falls back to **+X**. - dim 3 is always declared `TextureCube` (kind 5, `:5427-5441`), so the layer is never passed to the host. - `image_get_resinfo` on a cube reads 1 for the array size (`:5636`). The code already marks this as a `shortcut:` (`:5921`). I'm filing it because the result isn't a refusal or a log line but silently wrong texels: layer 0's data, from the +X face. ## Example A 2-cube array, `image_sample_lz` with s = t = 1.5 and a face operand of 10.0 (layer 1, face 2 = +Y): - Console: the centre texel of layer 1's +Y face. - Ours: direction (1, 0, 0), the +X face, through a `TextureCube` handle on a cube-array view. A shader of the encodings below lowers without any refusal today: ``` s_mov_b32 s5, 0 s_load_dwordx8 s[8:15], s[4:5], 0 F40C0202 FA000000 s_load_dwordx4 s[20:23], s[4:5], 32 F4080502 FA000020 (immediate sampler in s[16:19]) v1 = v2 = 1.5, v3 = 10.0 (0x41200000) image_sample_lz v4, v[1:3], s[8:15], s[16:19] dmask:1 dim:CUBE F09C0118 00820401 buffer_store_dword v4, off, s[20:23] E0700000 80050400 ``` ## Suggested fix 1. Split the operand: `layer = floor(face × 0.125)` and `id = face − 8 × layer`, then pass `id` to `cube_direction`. 2. When the shader can be an array (the operand isn't a bare `v_cubeid_f32` result; titles build it with `v_fma`/`v_fmac`/`v_madak` by 8.0), declare `TextureCubeArray` (DXIL kind 9) and pass the layer as coordinate 3. GFX10 MIMG has no DA bit, so the kind has to be inferred like this, or taken from the bound view. 3. In `image_get_resinfo`, return the array size for kind 9. I'm not sure whether titles expect it in cubes or in faces. **Not tested:** on a GPU. A WARP test with a cube-array view whose texels hold `10 × layer + face` would show it: a face operand of 10.0 should read 12.0, and gives 0.0 today. A face operand of 2.0, the control, should already pass. ## Related #109, #138, #317 and #563 touch cube sampling, and #568 adds null cube-array descriptors; none decodes the layer.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:53 +00:00
Author
Owner

@⁠XFlawless1 on GitHub · 2026-11-24 08:54 UTC · original

Fix on a fork, since PRs are closed: XFlawless1:shaders/cube-array-layers (one commit, ed1e064, on 58fed37).

What it does, following your suggested fix:

  1. cube_direction splits the operand: slice = floor(op × 0.125), face = op − 8 × slice (exact, powers of two), and returns the slice.
  2. A cube sample declares TextureCubeArray (kind 9) and passes the slice as coordinate 3 when its face operand is a multiply-add by 8.0 (v_fma/v_fmac/v_fmamk/v_fmaak/v_mad/v_mac/v_madmk/v_madak, 8.0 as a literal, inline or constant register in either multiplied operand) or a constant ≥ 8. Anything else, e.g. a bare v_cubeid_f32 result, stays TextureCube as today.
  3. Not done: image_get_resinfo and a16 cube samples stay plain cubes (marked shortcut:), since resinfo has no face operand to infer from.

Tests (synthetic, no title data): the test host gets a cube-array SRV view, and two new tests in valu_tests.rs sample 1×1-face cubes whose texels hold 10 × cube + face:

  • cube_array_samples_read_the_slice_and_face_of_the_operand: v_fma_f32 v3, slice, 8.0, face on a 3-cube array, slices 0–2 and several faces. Passes; fails without the change (slice 1, face 2, exactly the case above).
  • cube_samples_read_the_face_of_a_bare_operand: faces 0–5 on a plain cube view still read correctly.

Tested ed1e064 on Windows 11 / RTX 5080 (hardware adapter) and WARP: cargo test -p victory-shader 91 passed, 0 failed (with #719's one-line fix applied locally, not in the commit); cargo clippy -p victory-shader --all-targets clean; cargo xtask policy clean.

AI-assisted (Claude Code); the test results are real runs on my machine.

**@⁠XFlawless1** on GitHub · 2026-11-24 08:54 UTC · [original](https://github.com/Marvisak/VIctory/issues/720#issuecomment-7126706685) Fix on a fork, since PRs are closed: [`XFlawless1:shaders/cube-array-layers`](https://github.com/XFlawless1/VIctory/tree/shaders/cube-array-layers) (one commit, [`ed1e064`](https://github.com/XFlawless1/VIctory/commit/ed1e0645d621fee4c3fb838ea794bb78864d6ec8), on `58fed37`). What it does, following your suggested fix: 1. `cube_direction` splits the operand: `slice = floor(op × 0.125)`, `face = op − 8 × slice` (exact, powers of two), and returns the slice. 2. A cube sample declares `TextureCubeArray` (kind 9) and passes the slice as coordinate 3 when its face operand is a multiply-add by 8.0 (`v_fma`/`v_fmac`/`v_fmamk`/`v_fmaak`/`v_mad`/`v_mac`/`v_madmk`/`v_madak`, 8.0 as a literal, inline or constant register in either multiplied operand) or a constant ≥ 8. Anything else, e.g. a bare `v_cubeid_f32` result, stays `TextureCube` as today. 3. Not done: `image_get_resinfo` and a16 cube samples stay plain cubes (marked `shortcut:`), since resinfo has no face operand to infer from. Tests (synthetic, no title data): the test host gets a cube-array SRV view, and two new tests in `valu_tests.rs` sample 1×1-face cubes whose texels hold `10 × cube + face`: - `cube_array_samples_read_the_slice_and_face_of_the_operand`: `v_fma_f32 v3, slice, 8.0, face` on a 3-cube array, slices 0–2 and several faces. Passes; **fails without the change** (`slice 1, face 2`, exactly the case above). - `cube_samples_read_the_face_of_a_bare_operand`: faces 0–5 on a plain cube view still read correctly. Tested `ed1e064` on Windows 11 / RTX 5080 (hardware adapter) and WARP: `cargo test -p victory-shader` 91 passed, 0 failed (with #719's one-line fix applied locally, not in the commit); `cargo clippy -p victory-shader --all-targets` clean; `cargo xtask policy` clean. AI-assisted (Claude Code); the test results are real runs on my machine.
Author
Owner

@⁠Altorru on GitHub · 2026-11-24 08:52 UTC · original · edited 2026-11-24 08:57 UTC

I put a candidate fix on a fork branch: https://github.com/Altorru/VIctory/tree/fix/cube-array-sampling (commit c2197db, updated with 4ff3639).

It follows the 8 * layer + face form through v_mov and treats an 8.0 in the first two sources of v_fma/v_fmac/v_madak as the array encoding, then declares TextureCubeArray, masks the face with & 7, and passes floor(face / 8) as the fourth coordinate. The face is located after any offset, bias, comparison reference or gradients, so the _o, _b, _c and _d forms are covered. A size query has no face operand; it takes the array dimension from another image use of the same descriptor, so image_get_resinfo reports the layer count. Synthetic tests cover the encoding and the descriptor link.

Verified on macOS: cargo test -p victory-shader (73 passed, 1 ignored) and cargo xtask policy (152 files). No GPU here, so the WARP cube-array check is still needed.

The branch is stacked on #719 because main's shader test target does not compile without it. I did not open a PR while creation is collaborators-only.

Remaining limit: the inference needs an 8.0 literal in one of the first two sources (not an SGPR), and a size query can only infer array-ness when the same descriptor is sampled somewhere in the shader.

**@⁠Altorru** on GitHub · 2026-11-24 08:52 UTC · [original](https://github.com/Marvisak/VIctory/issues/720#issuecomment-7126678282) · edited 2026-11-24 08:57 UTC I put a candidate fix on a fork branch: https://github.com/Altorru/VIctory/tree/fix/cube-array-sampling (commit c2197db, updated with 4ff3639). It follows the `8 * layer + face` form through `v_mov` and treats an `8.0` in the first two sources of `v_fma`/`v_fmac`/`v_madak` as the array encoding, then declares `TextureCubeArray`, masks the face with `& 7`, and passes `floor(face / 8)` as the fourth coordinate. The face is located after any offset, bias, comparison reference or gradients, so the `_o`, `_b`, `_c` and `_d` forms are covered. A size query has no face operand; it takes the array dimension from another image use of the same descriptor, so `image_get_resinfo` reports the layer count. Synthetic tests cover the encoding and the descriptor link. Verified on macOS: `cargo test -p victory-shader` (73 passed, 1 ignored) and `cargo xtask policy` (152 files). No GPU here, so the WARP cube-array check is still needed. The branch is stacked on #719 because main's shader test target does not compile without it. I did not open a PR while creation is collaborators-only. Remaining limit: the inference needs an `8.0` literal in one of the first two sources (not an SGPR), and a size query can only infer array-ness when the same descriptor is sampled somewhere in the shader.
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 09:18 UTC · original

Tested the unmodified combined head 0df11b0 on an RTX 4090 (driver 615.78.8) through Wine 11.22 and vkd3d-proton 3.1. Both GPU readback tests ran and passed. All six tested cube-array selectors returned the expected 10 × layer + face texel, and faces 0–5 still sampled correctly on the plain cube.

DXGI's WARP enumeration selected the same NVIDIA adapter here, so this is one hardware result. The run covers sampling; a numeric readback of the array-layer count from image_get_resinfo remains open.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 09:18 UTC · [original](https://github.com/Marvisak/VIctory/issues/720#issuecomment-7127241048) Tested the unmodified combined head `0df11b0` on an RTX 4090 (driver 615.78.8) through Wine 11.22 and vkd3d-proton 3.1. Both GPU readback tests ran and passed. All six tested cube-array selectors returned the expected `10 × layer + face` texel, and faces 0–5 still sampled correctly on the plain cube. DXGI's WARP enumeration selected the same NVIDIA adapter here, so this is one hardware result. The run covers sampling; a numeric readback of the array-layer count from `image_get_resinfo` remains open.
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-24 09:28 UTC · original

Tested the unmodified combined head a376c42 on native Windows 11 build 26300.9974, RTX 4070 Ti with driver 621.01, Rust 1.98.1 (MSVC), and DXIL validator 1.9.2602.17.

cargo test --locked -p victory-shader --lib cube -- --test-threads=1 --nocapture

All 6 tests passed. Both sampling readback tests ran on the RTX 4070 Ti and on WARP (Microsoft Basic Render Driver), with no adapter skips. The constant-face unit test also passed.

The size-query test checks descriptor inference. Numeric image_get_resinfo readback remains untested. No game data used. AI-assisted test setup and reporting.

**@⁠DrDarkDK** on GitHub · 2026-11-24 09:28 UTC · [original](https://github.com/Marvisak/VIctory/issues/720#issuecomment-7127463876) Tested the unmodified combined head `a376c42` on native Windows 11 build 26300.9974, RTX 4070 Ti with driver 621.01, Rust 1.98.1 (MSVC), and DXIL validator 1.9.2602.17. `cargo test --locked -p victory-shader --lib cube -- --test-threads=1 --nocapture` All 6 tests passed. Both sampling readback tests ran on the RTX 4070 Ti and on WARP (Microsoft Basic Render Driver), with no adapter skips. The constant-face unit test also passed. The size-query test checks descriptor inference. Numeric `image_get_resinfo` readback remains untested. No game data used. AI-assisted test setup and reporting.
Author
Owner

@⁠Altorru on GitHub · 2026-11-24 09:09 UTC · original · edited 2026-11-24 09:34 UTC

@⁠MichaelSmithAI @⁠DrDarkDK — thanks for the hardware and WARP passes on the combined branch. I added the missing numeric resinfo readback: the shader samples the same cube-array descriptor first (so the array dimension is inferred), then runs image_get_resinfo with dmask 0x4 and expects the cube count 3 for a 3-cube array.

Combined branch: https://github.com/Altorru/VIctory/tree/merge/cube-array-sampling (head 392b4b6, merge commit 46af980). It is stacked on #719.

Verified on macOS: cargo test -p victory-shader 75 passed, 1 ignored; cargo check --all-targets; cargo xtask policy 152 files. The new GPU test is cfg(windows); please run cargo test --locked -p victory-shader --lib cube -- --test-threads=1 on this head on WARP/hardware and tell me whether the cube count is 3 (or 18 if D3D returns face layers). No PR while creation is collaborators-only.

**@⁠Altorru** on GitHub · 2026-11-24 09:09 UTC · [original](https://github.com/Marvisak/VIctory/issues/720#issuecomment-7127042592) · edited 2026-11-24 09:34 UTC @⁠MichaelSmithAI @⁠DrDarkDK — thanks for the hardware and WARP passes on the combined branch. I added the missing numeric resinfo readback: the shader samples the same cube-array descriptor first (so the array dimension is inferred), then runs image_get_resinfo with dmask 0x4 and expects the cube count 3 for a 3-cube array. Combined branch: https://github.com/Altorru/VIctory/tree/merge/cube-array-sampling (head 392b4b6, merge commit 46af980). It is stacked on #719. Verified on macOS: cargo test -p victory-shader 75 passed, 1 ignored; cargo check --all-targets; cargo xtask policy 152 files. The new GPU test is cfg(windows); please run cargo test --locked -p victory-shader --lib cube -- --test-threads=1 on this head on WARP/hardware and tell me whether the cube count is 3 (or 18 if D3D returns face layers). No PR while creation is collaborators-only.
Author
Owner

@⁠Altorru on GitHub · 2026-11-24 09:40 UTC · original

Correction after checking D3D/console semantics: TextureCubeArray.GetDimensions reports the number of cubes, while the console's image_get_resinfo counts array layers in faces. Head a51d7c3 now multiplies resinfo's layer channel by 6 for a cube array, and the test expects 18 for a 3-cube array. The earlier 3 expectation in 392b4b6 was wrong.

Combined branch: https://github.com/Altorru/VIctory/tree/merge/cube-array-sampling (head a51d7c3).

macOS: cargo test -p victory-shader 75 passed, 1 ignored; cargo check -p victory-shader --all-targets; cargo xtask policy 152 files. The GPU test is cfg(windows).

@⁠MichaelSmithAI @⁠DrDarkDK please rerun cargo test --locked -p victory-shader --lib cube -- --test-threads=1 on WARP/hardware: cube_array_resinfo_reads_the_face_count should now read 18. No PR while creation is collaborators-only.

**@⁠Altorru** on GitHub · 2026-11-24 09:40 UTC · [original](https://github.com/Marvisak/VIctory/issues/720#issuecomment-7127737906) Correction after checking D3D/console semantics: `TextureCubeArray.GetDimensions` reports the number of cubes, while the console's `image_get_resinfo` counts array layers in faces. Head `a51d7c3` now multiplies resinfo's layer channel by 6 for a cube array, and the test expects **18** for a 3-cube array. The earlier `3` expectation in `392b4b6` was wrong. Combined branch: https://github.com/Altorru/VIctory/tree/merge/cube-array-sampling (head `a51d7c3`). macOS: `cargo test -p victory-shader` 75 passed, 1 ignored; `cargo check -p victory-shader --all-targets`; `cargo xtask policy` 152 files. The GPU test is `cfg(windows)`. @⁠MichaelSmithAI @⁠DrDarkDK please rerun `cargo test --locked -p victory-shader --lib cube -- --test-threads=1` on WARP/hardware: `cube_array_resinfo_reads_the_face_count` should now read 18. No PR while creation is collaborators-only.
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-24 09:45 UTC · original

Reran the cube tests on unmodified a51d7c3 on native Windows 11 build 26300.9974, RTX 4070 Ti driver 621.01, and WARP (Microsoft Basic Render Driver).

cargo test --locked -p victory-shader --lib cube -- --test-threads=1 --nocapture

All 8 tests passed with no adapter skips. cube_array_resinfo_reads_the_face_count read back 18 on both adapters, and both sampling readback tests still pass.

Synthetic tests only. AI-assisted test execution and reporting.

**@⁠DrDarkDK** on GitHub · 2026-11-24 09:45 UTC · [original](https://github.com/Marvisak/VIctory/issues/720#issuecomment-7127842849) Reran the cube tests on unmodified `a51d7c3` on native Windows 11 build 26300.9974, RTX 4070 Ti driver 621.01, and WARP (Microsoft Basic Render Driver). `cargo test --locked -p victory-shader --lib cube -- --test-threads=1 --nocapture` All 8 tests passed with no adapter skips. `cube_array_resinfo_reads_the_face_count` read back 18 on both adapters, and both sampling readback tests still pass. Synthetic tests only. AI-assisted test execution and reporting.
Author
Owner

@⁠Altorru on GitHub · 2026-11-24 09:55 UTC · original

Confirmed on a51d7c3: @⁠DrDarkDK reports all 8 cube tests passing on the RTX 4070 Ti and WARP, with cube_array_resinfo_reads_the_face_count reading 18 on both adapters. The fork branch is ready as a patch; still no PR while creation is limited to collaborators. Thanks for the hardware/WARP runs.

**@⁠Altorru** on GitHub · 2026-11-24 09:55 UTC · [original](https://github.com/Marvisak/VIctory/issues/720#issuecomment-7128075493) Confirmed on `a51d7c3`: @⁠DrDarkDK reports all 8 cube tests passing on the RTX 4070 Ti and WARP, with `cube_array_resinfo_reads_the_face_count` reading **18** on both adapters. The fork branch is ready as a patch; still no PR while creation is limited to collaborators. Thanks for the hardware/WARP runs.
Author
Owner

@⁠AwkGrep256 on GitHub · 2026-11-24 12:41 UTC · original

@⁠Dufftwt measured both on an RDNA2 iGPU (gfx1036), raw dispatches through the kernel driver, wave32 and wave64 (identical results).

Setup as you described: a cube array of 2 cubes (12 faces), R32_SFLOAT, linear, 4x4 per face, every texel of layer L, face F = 10 × L + F. T# with TYPE CUBE, DEPTH = 11 (last layer, in faces), BASE_ARRAY 0, point sampling. As a layout check, image_load ... dim:CUBE at slice 0–11 read 0–5 and 10–15, as expected.

1. Face operand of image_sample_lz ... dim:CUBE (s = t = 1.5): it's 8 × layer + face.

face operand read 8 × L + F 6 × L + F
8.0 10 10 12
10.0 12 12 14
0–5 0–5 same same
9, 11, 12, 13 11, 13, 14, 15 match no

Out-of-range values clamp: 6.0 and 7.0 read 5 (face clamped to 5 in the same layer), and 14.0 and 15.0 read 15 (layer 1, face 5).

2. image_get_resinfo ... dim:CUBE, mip 0: [4, 4, 12, 1]. The array size comes back as 12, the face count (DEPTH + 1), not 2 cubes. So a console shader that wants cubes divides by 6 itself, the way Mesa does after resinfo, and the lowering should return faces here (cubes × 6 if the host query gives cubes).

Not covered: BASE_ARRAY ≠ 0, mips, and image_gather4. I can run those too if they matter. The probe is about 150 lines on top of my raw dispatch harness, and I can share it.

**@⁠AwkGrep256** on GitHub · 2026-11-24 12:41 UTC · [original](https://github.com/Marvisak/VIctory/issues/720#issuecomment-7131778627) @⁠Dufftwt measured both on an RDNA2 iGPU (gfx1036), raw dispatches through the kernel driver, wave32 and wave64 (identical results). Setup as you described: a cube array of 2 cubes (12 faces), R32_SFLOAT, linear, 4x4 per face, every texel of layer L, face F = `10 × L + F`. T# with TYPE CUBE, DEPTH = 11 (last layer, in faces), BASE_ARRAY 0, point sampling. As a layout check, `image_load ... dim:CUBE` at slice 0–11 read 0–5 and 10–15, as expected. **1. Face operand of `image_sample_lz ... dim:CUBE` (s = t = 1.5): it's `8 × layer + face`.** | face operand | read | `8 × L + F` | `6 × L + F` | |---|---|---|---| | 8.0 | **10** | 10 | 12 | | 10.0 | **12** | 12 | 14 | | 0–5 | 0–5 | same | same | | 9, 11, 12, 13 | 11, 13, 14, 15 | match | no | Out-of-range values clamp: 6.0 and 7.0 read 5 (face clamped to 5 in the same layer), and 14.0 and 15.0 read 15 (layer 1, face 5). **2. `image_get_resinfo ... dim:CUBE`, mip 0: `[4, 4, 12, 1]`.** The array size comes back as **12, the face count** (DEPTH + 1), not 2 cubes. So a console shader that wants cubes divides by 6 itself, the way Mesa does after resinfo, and the lowering should return faces here (cubes × 6 if the host query gives cubes). Not covered: BASE_ARRAY ≠ 0, mips, and `image_gather4`. I can run those too if they matter. The probe is about 150 lines on top of my raw dispatch harness, and I can share it.
Author
Owner

@⁠Dufftwt on GitHub · 2026-11-24 12:44 UTC · original

@⁠AwkGrep256 thank you, that's exactly what was missing: answers from real RDNA2 hardware to both questions.

  • Face operand: 8 × layer + face. Both fork fixes, Altorru's merge/cube-array-sampling and XFlawless1's shaders/cube-array-layers, decode it that way.
  • image_get_resinfo: the array size comes back as the face count (12 for 2 cubes). That matches Altorru's head a51d7c3, which multiplies D3D's cube count by 6 (18 for 3 cubes, read back on an RTX 4070 Ti and on WARP above). XFlawless1's branch still reports a plain cube there (marked shortcut:).

One detail from your table that neither branch matches yet: face values 6 and 7 clamp to face 5 (−Z) of the same layer. In both branches cube_direction compares the face with 0–5 for equality and falls back to the +X row otherwise. So 6.0 reads face 0 instead of face 5, and 14.0 reads layer 1's face 0 instead of its face 5. A face from v_cubeid is never 6 or 7, so this is an edge case. Still, it's a one-line change: test the −Z column with an unsigned f >= 5 instead of f == 5.

If it's easy, BASE_ARRAY ≠ 0 would be the most useful extra case: whether the layer in the operand counts from the view's first face or from the start of the resource, since titles can bind a sub-range of a cube array. Mips and gather4 seem less likely to differ.

Your harness sounds useful beyond this issue too. Several shader fixes here were checked only against the ISA document or Mesa, so a way to run single instructions on real RDNA2 would help settle the next question like this one.

**@⁠Dufftwt** on GitHub · 2026-11-24 12:44 UTC · [original](https://github.com/Marvisak/VIctory/issues/720#issuecomment-7131863957) @⁠AwkGrep256 thank you, that's exactly what was missing: answers from real RDNA2 hardware to both questions. - **Face operand:** `8 × layer + face`. Both fork fixes, Altorru's [`merge/cube-array-sampling`](https://github.com/Altorru/VIctory/tree/merge/cube-array-sampling) and XFlawless1's [`shaders/cube-array-layers`](https://github.com/XFlawless1/VIctory/tree/shaders/cube-array-layers), decode it that way. - **`image_get_resinfo`:** the array size comes back as the face count (12 for 2 cubes). That matches Altorru's head `a51d7c3`, which multiplies D3D's cube count by 6 (18 for 3 cubes, read back on an RTX 4070 Ti and on WARP above). XFlawless1's branch still reports a plain cube there (marked `shortcut:`). One detail from your table that neither branch matches yet: **face values 6 and 7 clamp to face 5 (−Z) of the same layer.** In both branches `cube_direction` compares the face with 0–5 for equality and falls back to the +X row otherwise. So 6.0 reads face 0 instead of face 5, and 14.0 reads layer 1's face 0 instead of its face 5. A face from `v_cubeid` is never 6 or 7, so this is an edge case. Still, it's a one-line change: test the −Z column with an unsigned `f >= 5` instead of `f == 5`. If it's easy, `BASE_ARRAY ≠ 0` would be the most useful extra case: whether the layer in the operand counts from the view's first face or from the start of the resource, since titles can bind a sub-range of a cube array. Mips and gather4 seem less likely to differ. Your harness sounds useful beyond this issue too. Several shader fixes here were checked only against the ISA document or Mesa, so a way to run single instructions on real RDNA2 would help settle the next question like this one.
Author
Owner

@⁠AwkGrep256 on GitHub · 2026-11-24 12:46 UTC · original

@⁠Dufftwt BASE_ARRAY ≠ 0, same 2-cube texture (DEPTH = 11, the last face), run with BASE_ARRAY 6 and 3, wave32.

The layer counts from the view's first face, even when that isn't a multiple of 6. One rule fits all 87 results across BASE_ARRAY 0, 3 and 6:

face   = min(f % 8, 5)
first  = min(BASE_ARRAY + 6 * (f / 8), DEPTH - 5)   // the cube is clamped to stay inside the view
texel  = face (first + face) of the resource
BASE_ARRAY operand 0–5 read slices operand 8–11 read slices resinfo array size
0 0–5 6–9 12
3 3–8 6–9 (clamped: 3 + 6 = 9 would run past face 11) 9
6 6–11 6–9 (clamped) 6

resinfo returns DEPTH - BASE_ARRAY + 1, the view's face count, not rounded to whole cubes. image_load dim:CUBE takes its slice relative to BASE_ARRAY as well, and reads 0 past DEPTH.

So for the lowering: the host view's first array slice already covers BASE_ARRAY, and the layer from the operand is relative to it. The clamp only matters for out-of-range layers.

**@⁠AwkGrep256** on GitHub · 2026-11-24 12:46 UTC · [original](https://github.com/Marvisak/VIctory/issues/720#issuecomment-7131902076) @⁠Dufftwt BASE_ARRAY ≠ 0, same 2-cube texture (DEPTH = 11, the last face), run with BASE_ARRAY 6 and 3, wave32. **The layer counts from the view's first face**, even when that isn't a multiple of 6. One rule fits all 87 results across BASE_ARRAY 0, 3 and 6: ``` face = min(f % 8, 5) first = min(BASE_ARRAY + 6 * (f / 8), DEPTH - 5) // the cube is clamped to stay inside the view texel = face (first + face) of the resource ``` | BASE_ARRAY | operand 0–5 read slices | operand 8–11 read slices | `resinfo` array size | |---|---|---|---| | 0 | 0–5 | 6–9 | 12 | | 3 | 3–8 | 6–9 (clamped: 3 + 6 = 9 would run past face 11) | 9 | | 6 | 6–11 | 6–9 (clamped) | 6 | `resinfo` returns `DEPTH - BASE_ARRAY + 1`, the view's face count, not rounded to whole cubes. `image_load dim:CUBE` takes its slice relative to BASE_ARRAY as well, and reads 0 past DEPTH. So for the lowering: the host view's first array slice already covers BASE_ARRAY, and the layer from the operand is relative to it. The clamp only matters for out-of-range layers.
Author
Owner

@⁠Dufftwt on GitHub · 2026-11-24 12:48 UTC · original

@⁠AwkGrep256 that's a complete answer, thank you. Read against VIctory, it means the host already behaves like the hardware for every view a title can create, except for one detail:

  • The layer counts from the view's first face. Host views are made from the title's own D3D12_SHADER_RESOURCE_VIEW_DESC (srv_desc, descriptor/host.rs), so BASE_ARRAY arrives as First2DArrayFace, and D3D's cube index is relative to it too. Nothing to change.
  • resinfo = DEPTH − BASE_ARRAY + 1. A D3D cube-array view always holds whole cubes (NumCubes), so for any title-made view that's NumCubes × 6, exactly what Altorru's a51d7c3 returns. Your BASE_ARRAY 3, DEPTH 11 case (9 faces) is a view D3D can't describe, so it can't reach us through the API.
  • The cube is clamped inside the view. For whole-cube views, min(BASE + 6 × layer, DEPTH − 5) is the same as D3D clamping the cube index to NumCubes − 1, so that matches too.
  • The face is clamped to 5 (min(f % 8, 5)). This is the one place both fork fixes differ, as in my comment above (6 and 7 fall back to +X).

So #720 is settled: Altorru's branch plus that one-line face clamp matches RDNA2 for everything a title can bind.

**@⁠Dufftwt** on GitHub · 2026-11-24 12:48 UTC · [original](https://github.com/Marvisak/VIctory/issues/720#issuecomment-7131948503) @⁠AwkGrep256 that's a complete answer, thank you. Read against VIctory, it means the host already behaves like the hardware for every view a title can create, except for one detail: - **The layer counts from the view's first face.** Host views are made from the title's own `D3D12_SHADER_RESOURCE_VIEW_DESC` (`srv_desc`, `descriptor/host.rs`), so `BASE_ARRAY` arrives as `First2DArrayFace`, and D3D's cube index is relative to it too. Nothing to change. - **`resinfo` = `DEPTH − BASE_ARRAY + 1`.** A D3D cube-array view always holds whole cubes (`NumCubes`), so for any title-made view that's `NumCubes × 6`, exactly what Altorru's `a51d7c3` returns. Your `BASE_ARRAY 3, DEPTH 11` case (9 faces) is a view D3D can't describe, so it can't reach us through the API. - **The cube is clamped inside the view.** For whole-cube views, `min(BASE + 6 × layer, DEPTH − 5)` is the same as D3D clamping the cube index to `NumCubes − 1`, so that matches too. - **The face is clamped to 5** (`min(f % 8, 5)`). This is the one place both fork fixes differ, as in my comment above (6 and 7 fall back to +X). So #720 is settled: Altorru's branch plus that one-line face clamp matches RDNA2 for everything a title can bind.
Author
Owner

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

@⁠Dufftwt I packaged the cube-array probe with the source, Linux run instructions, and the original captures. I reran it on the Radeon 610M and all 116 cases passed. The saved results can also be checked without a GPU. It uses a synthetic texture and needs no game files.

Download the source bundle

**@⁠AwkGrep256** on GitHub · 2026-11-24 13:18 UTC · [original](https://github.com/Marvisak/VIctory/issues/720#issuecomment-7132637967) @⁠Dufftwt I packaged the cube-array probe with the source, Linux run instructions, and the original captures. I reran it on the Radeon 610M and all 116 cases passed. The saved results can also be checked without a GPU. It uses a synthetic texture and needs no game files. [Download the source bundle](https://github.com/AwkGrep256/VIctory/releases/download/rdna2-cube-probe-v1/rdna2-cube-probe.tar.gz)
Author
Owner

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

@⁠AwkGrep256 thank you, 116 of 116 on the 610M and synthetic data only is exactly the kind of check this project needs. One suggestion: the same files as a browsable repository or branch, not only a tarball, would let people read the harness before running it on their machine. They'd also be easy to link from future issues like this one.

**@⁠Dufftwt** on GitHub · 2026-11-24 13:19 UTC · [original](https://github.com/Marvisak/VIctory/issues/720#issuecomment-7132657162) @⁠AwkGrep256 thank you, 116 of 116 on the 610M and synthetic data only is exactly the kind of check this project needs. One suggestion: the same files as a browsable repository or branch, not only a tarball, would let people read the harness before running it on their machine. They'd also be easy to link from future issues like this one.
Author
Owner

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

@⁠Dufftwt I put the same probe files and saved results on a branch. The README has the steps to run it on Linux or check the captures without a GPU.

Browse the source

**@⁠AwkGrep256** on GitHub · 2026-11-24 13:28 UTC · [original](https://github.com/Marvisak/VIctory/issues/720#issuecomment-7132873879) @⁠Dufftwt I put the same probe files and saved results on a branch. The README has the steps to run it on Linux or check the captures without a GPU. [Browse the source](https://github.com/AwkGrep256/VIctory/tree/rdna2-cube-probe)
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:47 UTC · original

Automated triage for the maintainers.

Confirmed on current main. In crates/victory-shader/src/emit/lower.rs, Lower::cube_direction still converts the face operand with FpToUi and compares it only with 0–5. Any operand of 8 or more (layer ≥ 1) falls back to the +X row, and cube samples are still declared as a plain cube. The function carries the shortcut: note "the view is taken as a cube, not a cube array". The RDNA2 hardware measurements in the comments settle the semantics: the operand is 8 × layer + face, the face is clamped to 5, the layer counts from the view's first face, and image_get_resinfo reports faces, not cubes.

The fix is in an open pull request: #1256 decodes slice and face, clamps faces 6 and 7 to 5, declares TextureCubeArray, and scales image_get_resinfo by 6. It's labelled as needing a rebase onto current main. The fork branches in the comments (Altorru, XFlawless1) carry earlier versions of the same change. Pull requests are open to everyone, so further work should go there.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:47 UTC · [original](https://github.com/Marvisak/VIctory/issues/720#issuecomment-7149962104) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T13:28:10Z at=2026-11-25T01:49:45Z --> Automated triage for the maintainers. Confirmed on current `main`. In `crates/victory-shader/src/emit/lower.rs`, `Lower::cube_direction` still converts the face operand with `FpToUi` and compares it only with 0–5. Any operand of 8 or more (layer ≥ 1) falls back to the +X row, and cube samples are still declared as a plain cube. The function carries the `shortcut:` note "the view is taken as a cube, not a cube array". The RDNA2 hardware measurements in the comments settle the semantics: the operand is `8 × layer + face`, the face is clamped to 5, the layer counts from the view's first face, and `image_get_resinfo` reports faces, not cubes. The fix is in an open pull request: #1256 decodes slice and face, clamps faces 6 and 7 to 5, declares `TextureCubeArray`, and scales `image_get_resinfo` by 6. It's labelled as needing a rebase onto current `main`. The fork branches in the comments (Altorru, XFlawless1) carry earlier versions of the same change. Pull requests are open to everyone, so further work should go there. --- _Generated by [Claude Code](https://claude.ai/code)_
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#720
No description provided.