Shaders: cube-map arrays sample layer 0, and the +X face for any layer above 0 #720
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory#720
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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*(dimCUBE) as8 × layer + face. Mesa'sac_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 withFpToUiand matches it only against 0–5. For any layer ≥ 1, no face matches, so it falls back to +X.TextureCube(kind 5,:5427-5441), so the layer is never passed to the host.image_get_resinfoon 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_lzwith s = t = 1.5 and a face operand of 10.0 (layer 1, face 2 = +Y):TextureCubehandle on a cube-array view.A shader of the encodings below lowers without any refusal today:
Suggested fix
layer = floor(face × 0.125)andid = face − 8 × layer, then passidtocube_direction.v_cubeid_f32result; titles build it withv_fma/v_fmac/v_madakby 8.0), declareTextureCubeArray(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.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 + facewould 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.
@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, on58fed37).What it does, following your suggested fix:
cube_directionsplits the operand:slice = floor(op × 0.125),face = op − 8 × slice(exact, powers of two), and returns the slice.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 barev_cubeid_f32result, staysTextureCubeas today.image_get_resinfoand a16 cube samples stay plain cubes (markedshortcut:), 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.rssample 1×1-face cubes whose texels hold10 × cube + face:cube_array_samples_read_the_slice_and_face_of_the_operand:v_fma_f32 v3, slice, 8.0, faceon 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
ed1e064on Windows 11 / RTX 5080 (hardware adapter) and WARP:cargo test -p victory-shader91 passed, 0 failed (with #719's one-line fix applied locally, not in the commit);cargo clippy -p victory-shader --all-targetsclean;cargo xtask policyclean.AI-assisted (Claude Code); the test results are real runs on my machine.
@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 + faceform throughv_movand treats an8.0in the first two sources ofv_fma/v_fmac/v_madakas the array encoding, then declaresTextureCubeArray, masks the face with& 7, and passesfloor(face / 8)as the fourth coordinate. The face is located after any offset, bias, comparison reference or gradients, so the_o,_b,_cand_dforms are covered. A size query has no face operand; it takes the array dimension from another image use of the same descriptor, soimage_get_resinforeports the layer count. Synthetic tests cover the encoding and the descriptor link.Verified on macOS:
cargo test -p victory-shader(73 passed, 1 ignored) andcargo 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.0literal 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.@MichaelSmithAI on GitHub · 2026-11-24 09:18 UTC · original
Tested the unmodified combined head
0df11b0on 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 expected10 × layer + facetexel, 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_resinforemains open.@DrDarkDK on GitHub · 2026-11-24 09:28 UTC · original
Tested the unmodified combined head
a376c42on 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 --nocaptureAll 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_resinforeadback remains untested. No game data used. AI-assisted test setup and reporting.@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:40 UTC · original
Correction after checking D3D/console semantics:
TextureCubeArray.GetDimensionsreports the number of cubes, while the console'simage_get_resinfocounts array layers in faces. Heada51d7c3now multiplies resinfo's layer channel by 6 for a cube array, and the test expects 18 for a 3-cube array. The earlier3expectation in392b4b6was wrong.Combined branch: https://github.com/Altorru/VIctory/tree/merge/cube-array-sampling (head
a51d7c3).macOS:
cargo test -p victory-shader75 passed, 1 ignored;cargo check -p victory-shader --all-targets;cargo xtask policy152 files. The GPU test iscfg(windows).@MichaelSmithAI @DrDarkDK please rerun
cargo test --locked -p victory-shader --lib cube -- --test-threads=1on WARP/hardware:cube_array_resinfo_reads_the_face_countshould now read 18. No PR while creation is collaborators-only.@DrDarkDK on GitHub · 2026-11-24 09:45 UTC · original
Reran the cube tests on unmodified
a51d7c3on 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 --nocaptureAll 8 tests passed with no adapter skips.
cube_array_resinfo_reads_the_face_countread back 18 on both adapters, and both sampling readback tests still pass.Synthetic tests only. AI-assisted test execution and reporting.
@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, withcube_array_resinfo_reads_the_face_countreading 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.@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:CUBEat 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's8 × layer + face.8 × L + F6 × L + FOut-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.@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.
8 × layer + face. Both fork fixes, Altorru'smerge/cube-array-samplingand XFlawless1'sshaders/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 heada51d7c3, 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 (markedshortcut:).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_directioncompares 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 fromv_cubeidis never 6 or 7, so this is an edge case. Still, it's a one-line change: test the −Z column with an unsignedf >= 5instead off == 5.If it's easy,
BASE_ARRAY ≠ 0would 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.
@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:
resinfoarray sizeresinforeturnsDEPTH - BASE_ARRAY + 1, the view's face count, not rounded to whole cubes.image_load dim:CUBEtakes 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.
@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:
D3D12_SHADER_RESOURCE_VIEW_DESC(srv_desc,descriptor/host.rs), soBASE_ARRAYarrives asFirst2DArrayFace, 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'sNumCubes × 6, exactly what Altorru'sa51d7c3returns. YourBASE_ARRAY 3, DEPTH 11case (9 faces) is a view D3D can't describe, so it can't reach us through the API.min(BASE + 6 × layer, DEPTH − 5)is the same as D3D clamping the cube index toNumCubes − 1, so that matches too.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.
@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
@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.
@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
@Marvisak on GitHub · 2026-11-25 01:47 UTC · original
Automated triage for the maintainers.
Confirmed on current
main. Incrates/victory-shader/src/emit/lower.rs,Lower::cube_directionstill converts the face operand withFpToUiand 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 theshortcut:note "the view is taken as a cube, not a cube array". The RDNA2 hardware measurements in the comments settle the semantics: the operand is8 × layer + face, the face is clamped to 5, the layer counts from the view's first face, andimage_get_resinforeports 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 scalesimage_get_resinfoby 6. It's labelled as needing a rebase onto currentmain. 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