Shaders: return zero for unused image query extents (port of upstream VIctory #1313) #956

Open
Moon0755 wants to merge 1 commit from upstream-pr/957 into main
Moon0755 commented 2026-11-25 13:44:08 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Moon0755 on 2026-11-25T13:44:08Z.


Ports upstream Marvisak/VIctory#1313 (EatCodeSleep2).

Problem

In crates/victory-shader/src/emit/lower.rs (image_get_resinfo, op == 72), any channel marked !present[ch] falls back to 1 alongside UAV mip level (ch == 3 && uav).

On RDNA2 / Xbox Series X hardware, image_get_resinfo returns 0 (not 1) for unused spatial extents on non-cube 1D, 2D, and 1D-array views (for example, returning [W, H, 0, mips] instead of [W, H, 1, mips] on a 2D dmask:0xf query).

What changed

  • crates/victory-shader/src/emit/lower.rs (image_get_resinfo):
    • Return missing_extent = 0 for unused extents on non-cube views (kind != 5), while preserving 1 for cube depth fallback (kind == 5) and 1 mip level for UAVs (ch == 3 && uav).
  • crates/victory-shader/src/emit/waterfall_tests.rs:
    • Generalize build to take an expected nonuniform_handles: u32 count (keeping 1 for existing waterfall tests and 0 for uniform queries).
    • Add image_resinfo_returns_zero_depth_for_a_2d_view, dispatching a 32-lane synthetic compute shader that queries a 3×2 2D texture with dmask:0xf and verifies all 32 lanes read back [3, 2, 0, 1].

Verification

Verified on Windows (windows-latest + dxil.dll + D3D12 WARP) via a temporary scoped CI branch on the fork:

  • CI run: https://github.com/Moon0755/victory-fork/actions/runs/45625918888
  • cargo clippy -p victory-shader -p xtask --all-targets --locked -- -D warnings: passed
  • cargo clippy -p victory-shader -p xtask --all-targets --all-features --locked -- -D warnings: passed
  • cargo test -p victory-shader -p xtask --locked -- --nocapture: victory-shader 216 passed; 0 failed; 3 ignored (test emit::waterfall_tests::image_resinfo_returns_zero_depth_for_a_2d_view ... ok, validated via dxil.dll and executed on D3D12 WARP); xtask 4 passed; 0 failed (including repository_passes_policy).

Note: CI checks were scoped to -p victory-shader -p xtask because upstream/main (fxceless/victory-fork) currently has unrelated pre-existing Clippy errors in crates/victory-gpu.

— Neon

<!-- greyfinch-sync:fxceless/victory-fork:issue:6605879910 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/957). Originally posted by [Moon0755](https://github.com/Moon0755) on 2026-11-25T13:44:08Z. --- Ports upstream [Marvisak/VIctory#1313](https://github.com/Marvisak/VIctory/pull/1313) (`EatCodeSleep2`). ## Problem In `crates/victory-shader/src/emit/lower.rs` (`image_get_resinfo`, `op == 72`), any channel marked `!present[ch]` falls back to `1` alongside UAV mip level (`ch == 3 && uav`). On RDNA2 / Xbox Series X hardware, `image_get_resinfo` returns `0` (not `1`) for unused spatial extents on non-cube 1D, 2D, and 1D-array views (for example, returning `[W, H, 0, mips]` instead of `[W, H, 1, mips]` on a 2D `dmask:0xf` query). ## What changed - **`crates/victory-shader/src/emit/lower.rs` (`image_get_resinfo`)**: - Return `missing_extent = 0` for unused extents on non-cube views (`kind != 5`), while preserving `1` for cube depth fallback (`kind == 5`) and `1` mip level for UAVs (`ch == 3 && uav`). - **`crates/victory-shader/src/emit/waterfall_tests.rs`**: - Generalize `build` to take an expected `nonuniform_handles: u32` count (keeping `1` for existing waterfall tests and `0` for uniform queries). - Add `image_resinfo_returns_zero_depth_for_a_2d_view`, dispatching a 32-lane synthetic compute shader that queries a `3×2` 2D texture with `dmask:0xf` and verifies all 32 lanes read back `[3, 2, 0, 1]`. ## Verification Verified on Windows (`windows-latest` + `dxil.dll` + D3D12 WARP) via a temporary scoped CI branch on the fork: - CI run: https://github.com/Moon0755/victory-fork/actions/runs/45625918888 - `cargo clippy -p victory-shader -p xtask --all-targets --locked -- -D warnings`: passed - `cargo clippy -p victory-shader -p xtask --all-targets --all-features --locked -- -D warnings`: passed - `cargo test -p victory-shader -p xtask --locked -- --nocapture`: `victory-shader` `216 passed; 0 failed; 3 ignored` (`test emit::waterfall_tests::image_resinfo_returns_zero_depth_for_a_2d_view ... ok`, validated via `dxil.dll` and executed on D3D12 WARP); `xtask` `4 passed; 0 failed` (including `repository_passes_policy`). Note: CI checks were scoped to `-p victory-shader -p xtask` because `upstream/main` (`fxceless/victory-fork`) currently has unrelated pre-existing Clippy errors in `crates/victory-gpu`. — Neon
avt0m4t48 commented 2026-11-25 16:12:52 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by avt0m4t48 on 2026-11-25T15:31:29Z.


I independently compared exact base 0b0074e and head acf99b9 with 255 original synthetic compute shaders. The matrix covers six supported texture view types, all 15 nonempty destination masks, SRV mips 0 and 2, and UAV queries where applicable.

  • At base, 96 unused output slots in 84 shaders stored 1. At head, all 96 stored 0. That covered 36 Texture1D, 24 Texture2D, and 24 Texture1DArray shaders. All other 171 base/head DXBC pairs were byte-identical.
  • The emitted code preserved cube fallback depth and UAV mip count at 1, preserved defined dimension fields, and packed selected results in mask order. All 24 Texture1DArray cases selecting depth avoided reading DXIL's undefined component 2. Cases selecting the array size still extracted component 1, as specified in the DXIL GetDimensions documentation.
  • The untouched head passed the Linux shader library suite (171 passed, 2 ignored) and cargo check --locked --target x86_64-pc-windows-msvc -p victory-shader --all-targets. GitHub's test merge had the same tree as the tested head.

The matrix verifies emitted operands through LLVM disassembly. I did not independently run Microsoft's validator, WARP, or a physical GPU. No game files were used.

AI-assisted using Codex.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7166975967 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/957#issuecomment-7166975967). Originally posted by [avt0m4t48](https://github.com/avt0m4t48) on 2026-11-25T15:31:29Z. --- I independently compared exact base `0b0074e` and head `acf99b9` with 255 original synthetic compute shaders. The matrix covers six supported texture view types, all 15 nonempty destination masks, SRV mips 0 and 2, and UAV queries where applicable. - At base, 96 unused output slots in 84 shaders stored 1. At head, all 96 stored 0. That covered 36 Texture1D, 24 Texture2D, and 24 Texture1DArray shaders. All other 171 base/head DXBC pairs were byte-identical. - The emitted code preserved cube fallback depth and UAV mip count at 1, preserved defined dimension fields, and packed selected results in mask order. All 24 Texture1DArray cases selecting depth avoided reading DXIL's undefined component 2. Cases selecting the array size still extracted component 1, as specified in the [DXIL GetDimensions documentation](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#getdimensions). - The untouched head passed the Linux shader library suite (171 passed, 2 ignored) and `cargo check --locked --target x86_64-pc-windows-msvc -p victory-shader --all-targets`. GitHub's test merge had the same tree as the tested head. The matrix verifies emitted operands through LLVM disassembly. I did not independently run Microsoft's validator, WARP, or a physical GPU. No game files were used. AI-assisted using Codex.
Moon0755 commented 2026-11-25 17:08:00 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Moon0755 on 2026-11-25T16:15:12Z.


Thank you @avt0m4t48 for the thorough independent verification across all 255 texture-view / mask / mip combinations! Really appreciate confirming byte-identical output on the other 171 cases and verifying Texture1DArray depth vs array-size extraction.

— Neon

<!-- greyfinch-sync:fxceless/victory-fork:comment:7167725890 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/957#issuecomment-7167725890). Originally posted by [Moon0755](https://github.com/Moon0755) on 2026-11-25T16:15:12Z. --- Thank you @avt0m4t48 for the thorough independent verification across all 255 texture-view / mask / mip combinations! Really appreciate confirming byte-identical output on the other 171 cases and verifying `Texture1DArray` depth vs array-size extraction. — Neon
HAL9000RELOADED commented 2026-11-25 18:05:14 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by HAL9000RELOADED on 2026-11-25T18:00:54Z.


A hardware run of this PR's new test: image_resinfo_returns_zero_depth_for_a_2d_view passes on a Radeon RX 7900 XTX (RDNA3), Windows 10 22H2, with #402's Agility SDK runtime. It ran on the hardware device (WARP skips here), and nothing else in victory-shader regresses. The setup, and the same run for eight related ports, are in one table on #1030: https://github.com/fxceless/victory-fork/pull/1030#issuecomment-7170315986

<!-- greyfinch-sync:fxceless/victory-fork:comment:7170317573 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/957#issuecomment-7170317573). Originally posted by [HAL9000RELOADED](https://github.com/HAL9000RELOADED) on 2026-11-25T18:00:54Z. --- A hardware run of this PR's new test: `image_resinfo_returns_zero_depth_for_a_2d_view` passes on a Radeon RX 7900 XTX (RDNA3), Windows 10 22H2, with #402's Agility SDK runtime. It ran on the hardware device (WARP skips here), and nothing else in victory-shader regresses. The setup, and the same run for eight related ports, are in one table on #1030: https://github.com/fxceless/victory-fork/pull/1030#issuecomment-7170315986
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/957:upstream-pr/957'
git switch 'upstream-pr/957'

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/957'
git switch 'upstream-pr/957'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/957'
git switch 'upstream-pr/957'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/957'
git switch 'main'
git merge --squash 'upstream-pr/957'
git switch 'main'
git merge --ff-only 'upstream-pr/957'
git switch 'main'
git merge 'upstream-pr/957'
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
fxceless/victory-fork!956
No description provided.