Shaders: lower image_gather4_c_lz(_o) and remaining offset sample variants #123

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

@⁠davi713albano-coder on GitHub · 2026-11-24 21:39 UTC · original
davi713albano-coder:shader/image-gather-cmp-and-sample-offsets → main · +595 −38 · 3 files · 1 commits · open

Summary

Extends emit::lower::image to cover the remaining comparison-gather and offset-sample MIMG instructions:

  1. Lower image_gather4_c_lz (0x04f) and image_gather4_c_lz_o (0x05f) to DXIL dx.op.textureGatherCmp.f32 (opcode 74), marking the sampler as a comparison sampler (0x8000), extracting programmable 2D offsets when _o is set, passing dmask.trailing_zeros() and the comparison reference, and writing all four gathered channels.
  2. Lower the remaining offset (_o) sample variants: image_sample_l_o, image_sample_b_o, image_sample_d_o, image_sample_c_o (pixel shaders), and image_sample_c_lz_o.
  3. Decode the offset word with addr_u32(self, 0) (instead of addr_val, which masks with 0xFFFF under a16), support all offsets axes including 3D Z (bits 16..21), reject cube samples with texel offsets, and emit immediate -8..=7 offsets for all non-gather sample ops when the offset word is a constant in range (keeping the runtime sign-extension fallback for non-constant offsets and gathers).

Changes

  • crates/victory-shader/src/emit/lower.rs: add image_gather4_c_lz(_o) (op 74) and image_sample_{l,b,d,c,c_lz}_o, unify constant/runtime texel-offset decoding with addr_u32 and 3D Z support, and fix image_sample_l_o LOD lookup.
  • crates/victory-shader/src/emit/valu_tests.rs:
    • image_gather4_c_lz_and_offset_match_d3d12: synthetic compute tests for image_gather4_c_lz (dmask:0x1 and dmask:0x2) and image_gather4_c_lz_o (runtime positive and negative offsets) with dxil.dll validation and D3D12 WARP readback.
    • image_sample_offset_variants_match_d3d12: synthetic compute tests with D3D12 WARP readback for image_sample_l_o, image_sample_c_lz_o, and image_sample_d_o, plus pixel-shader dxil.dll validation and D3D12 graphics PSO creation for image_sample_b_o and image_sample_c_o.

Verification

  • Fork CI (windows-latest): https://github.com/davi713albano-coder/victory-fork/actions/runs/45492007121
    • cargo clippy --workspace --all-targets --locked -- -D warnings: passed
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed
    • cargo test --workspace --locked (including xtask asset-policy check, dxil.dll validation, and D3D12 WARP tests): 498 passed, 0 failed (image_gather4_c_lz_and_offset_match_d3d12 ... ok, image_sample_offset_variants_match_d3d12 ... ok)

(No title data used. AI-assisted.)

**@⁠davi713albano-coder** on GitHub · 2026-11-24 21:39 UTC · [original](https://github.com/fxceless/victory-fork/pull/123) `davi713albano-coder:shader/image-gather-cmp-and-sample-offsets` → `main` · +595 −38 · 3 files · 1 commits · open ### Summary Extends `emit::lower::image` to cover the remaining comparison-gather and offset-sample MIMG instructions: 1. Lower `image_gather4_c_lz` (`0x04f`) and `image_gather4_c_lz_o` (`0x05f`) to DXIL `dx.op.textureGatherCmp.f32` (opcode `74`), marking the sampler as a comparison sampler (`0x8000`), extracting programmable 2D offsets when `_o` is set, passing `dmask.trailing_zeros()` and the comparison reference, and writing all four gathered channels. 2. Lower the remaining offset (`_o`) sample variants: `image_sample_l_o`, `image_sample_b_o`, `image_sample_d_o`, `image_sample_c_o` (pixel shaders), and `image_sample_c_lz_o`. 3. Decode the offset word with `addr_u32(self, 0)` (instead of `addr_val`, which masks with `0xFFFF` under `a16`), support all `offsets` axes including 3D Z (`bits 16..21`), reject cube samples with texel offsets, and emit immediate `-8..=7` offsets for all non-gather sample ops when the offset word is a constant in range (keeping the runtime sign-extension fallback for non-constant offsets and gathers). ### Changes - `crates/victory-shader/src/emit/lower.rs`: add `image_gather4_c_lz(_o)` (`op 74`) and `image_sample_{l,b,d,c,c_lz}_o`, unify constant/runtime texel-offset decoding with `addr_u32` and 3D Z support, and fix `image_sample_l_o` LOD lookup. - `crates/victory-shader/src/emit/valu_tests.rs`: - `image_gather4_c_lz_and_offset_match_d3d12`: synthetic compute tests for `image_gather4_c_lz` (`dmask:0x1` and `dmask:0x2`) and `image_gather4_c_lz_o` (runtime positive and negative offsets) with `dxil.dll` validation and D3D12 WARP readback. - `image_sample_offset_variants_match_d3d12`: synthetic compute tests with D3D12 WARP readback for `image_sample_l_o`, `image_sample_c_lz_o`, and `image_sample_d_o`, plus pixel-shader `dxil.dll` validation and D3D12 graphics PSO creation for `image_sample_b_o` and `image_sample_c_o`. ### Verification - Fork CI (`windows-latest`): https://github.com/davi713albano-coder/victory-fork/actions/runs/45492007121 - `cargo clippy --workspace --all-targets --locked -- -D warnings`: passed - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passed - `cargo test --workspace --locked` (including `xtask` asset-policy check, `dxil.dll` validation, and D3D12 WARP tests): 498 passed, 0 failed (`image_gather4_c_lz_and_offset_match_d3d12 ... ok`, `image_sample_offset_variants_match_d3d12 ... ok`) *(No title data used. AI-assisted.)*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:33 +00:00
Author
Owner

@⁠adriaespii on GitHub · 2026-11-24 21:52 UTC · original

Independent test run on commit 46ea6e5 (AMD RDNA4) — both new hardware GPU tests fail:

  • Hardware: AMD Radeon RX 9070 (driver 32.0.32015.7029), AMD Ryzen 5 7600, Windows 11 Pro, Rust 1.98.1 (x86_64-pc-windows-msvc)
  • cargo clippy --workspace --all-targets -- -D warnings: 0 warnings
  • cargo test --workspace: victory-shader fails with 210 passed, 2 failed, 2 ignored:
    test emit::valu_tests::image_gather4_c_lz_and_offset_match_d3d12 ... FAILED
    assertion `left == right` failed: hardware: case 0 got [0.0, 0.0, 0.0, 0.0], want [1.0, 1.0, 0.0, 0.0]
    
    test emit::valu_tests::image_sample_offset_variants_match_d3d12 ... FAILED
    assertion `left == right` failed: hardware: case 0 got [0.0, 0.0, 0.0, 0.0], want [1.0, 0.0, 0.0, 0.0]
    

AI use: Antigravity (Gemini 4 Neon) ran clippy/tests locally and wrote this report.

**@⁠adriaespii** on GitHub · 2026-11-24 21:52 UTC · [original](https://github.com/fxceless/victory-fork/pull/123#issuecomment-7145492593) Independent test run on commit `46ea6e5` (AMD RDNA4) — **both new hardware GPU tests fail**: - **Hardware:** AMD Radeon RX 9070 (driver 32.0.32015.7029), AMD Ryzen 5 7600, Windows 11 Pro, Rust 1.98.1 (`x86_64-pc-windows-msvc`) - `cargo clippy --workspace --all-targets -- -D warnings`: 0 warnings - `cargo test --workspace`: `victory-shader` fails with 210 passed, **2 failed**, 2 ignored: ``` test emit::valu_tests::image_gather4_c_lz_and_offset_match_d3d12 ... FAILED assertion `left == right` failed: hardware: case 0 got [0.0, 0.0, 0.0, 0.0], want [1.0, 1.0, 0.0, 0.0] test emit::valu_tests::image_sample_offset_variants_match_d3d12 ... FAILED assertion `left == right` failed: hardware: case 0 got [0.0, 0.0, 0.0, 0.0], want [1.0, 0.0, 0.0, 0.0] ``` *AI use: Antigravity (Gemini 4 Neon) ran clippy/tests locally and wrote this report.*
Author
Owner

@⁠ezbyDev on GitHub · 2026-11-24 21:52 UTC · original

The two new tests fail on AMD hardware at this PR's head (46ea6e5), with nothing else applied:

cargo test -p victory-shader --lib -- gather4_c_lz sample_offset_variants

test emit::valu_tests::image_gather4_c_lz_and_offset_match_d3d12 ... FAILED
test emit::valu_tests::image_sample_offset_variants_match_d3d12 ... FAILED
assertion `left == right` failed: hardware: case 0 got [0.0, 0.0, 0.0, 0.0], want [1.0, 1.0, 0.0, 0.0]
assertion `left == right` failed: hardware: case 0 got [0.0, 0.0, 0.0, 0.0], want [1.0, 0.0, 0.0, 0.0]
test result: FAILED. 0 passed; 2 failed

Both fail at case 0 with all zeros, which looks like the translated program reading nothing rather than a precision difference. The rest of victory-shader (227 tests) passes on the same machine.

Setup: AMD Radeon RX 9060 XT 16 GB (RDNA4, native 64-lane waves), Adrenalin 32.0.32029.2010; i7-9700K; Windows 11 Pro 26300; Rust 1.98.1 (pinned); DXC from the Windows SDK 10.0.26100.

Not tested: NVIDIA (if they pass there, it would point at a wave-size or AMD driver difference); which of the cases after case 0 fail.

AI-assisted (Claude Code, Claude Opus 5.5): ran the tests on my machine and wrote this.

**@⁠ezbyDev** on GitHub · 2026-11-24 21:52 UTC · [original](https://github.com/fxceless/victory-fork/pull/123#issuecomment-7145503356) The two new tests fail on AMD hardware at this PR's head (`46ea6e5`), with nothing else applied: ``` cargo test -p victory-shader --lib -- gather4_c_lz sample_offset_variants test emit::valu_tests::image_gather4_c_lz_and_offset_match_d3d12 ... FAILED test emit::valu_tests::image_sample_offset_variants_match_d3d12 ... FAILED assertion `left == right` failed: hardware: case 0 got [0.0, 0.0, 0.0, 0.0], want [1.0, 1.0, 0.0, 0.0] assertion `left == right` failed: hardware: case 0 got [0.0, 0.0, 0.0, 0.0], want [1.0, 0.0, 0.0, 0.0] test result: FAILED. 0 passed; 2 failed ``` Both fail at case 0 with all zeros, which looks like the translated program reading nothing rather than a precision difference. The rest of `victory-shader` (227 tests) passes on the same machine. **Setup:** AMD Radeon RX 9060 XT 16 GB (RDNA4, native 64-lane waves), Adrenalin 32.0.32029.2010; i7-9700K; Windows 11 Pro 26300; Rust 1.98.1 (pinned); DXC from the Windows SDK 10.0.26100. **Not tested:** NVIDIA (if they pass there, it would point at a wave-size or AMD driver difference); which of the cases after case 0 fail. AI-assisted (Claude Code, Claude Opus 5.5): ran the tests on my machine and wrote this.
Author
Owner

@⁠arminkhaleghirod on GitHub · 2026-11-24 22:23 UTC · original

Merged onto main 90228a7 and ran victory translate --validate over the full title (26,148 programs) on Windows 11 / RTX 4080.

No change: every failure count matches main, and no new reason appears. What it changes at run time isn't covered by this check.

**@⁠arminkhaleghirod** on GitHub · 2026-11-24 22:23 UTC · [original](https://github.com/fxceless/victory-fork/pull/123#issuecomment-7146178583) Merged onto main 90228a7 and ran `victory translate --validate` over the full title (26,148 programs) on Windows 11 / RTX 4080. No change: every failure count matches main, and no new reason appears. What it changes at run time isn't covered by this check.
Author
Owner

@⁠davi713albano-coder on GitHub · 2026-11-25 04:08 UTC · original

Thanks @⁠adriaespii and @⁠ezbyDev for testing on RX 9070 / RX 9060 XT!

Root cause of the hardware failures:

  • sample_l_o (regular point sampler) passed on both GPUs, while image_gather4_c_lz, image_gather4_c_lz_o, and image_sample_c_lz_o returned [0.0, 0.0, 0.0, 0.0].
  • The tests were binding View::Texture (DXGI_FORMAT_R32G32B32A32_FLOAT) to a comparison sampler. Per D3D12 format support rules, SHADER_SAMPLE_COMPARISON / SHADER_GATHER_COMPARISON are only guaranteed on single-channel float/depth formats (such as DXGI_FORMAT_R32_FLOAT); AMD hardware returns 0.0 for comparison filtering on R32G32B32A32_FLOAT while WARP permits it.

Fix in the rebased commit (7871ce7):

  • Rebased onto latest main (310c6eb).
  • Added View::FloatTexture(u32, u32, &[f32]) (DXGI_FORMAT_R32_FLOAT) to the test harness in crates/victory-shader/src/emit/host.rs.
  • Updated the comparison-sampling tests (image_gather4_c_lz, image_gather4_c_lz_o, image_sample_c_lz_o) to bind View::FloatTexture while keeping non-comparison offset sampling tests on View::Texture.
  • Verified clippy, clippy --all-features, and cargo test --workspace --locked on windows-latest (DXIL validation + WARP execution). Would appreciate a re-test on AMD hardware when you have a moment!
**@⁠davi713albano-coder** on GitHub · 2026-11-25 04:08 UTC · [original](https://github.com/fxceless/victory-fork/pull/123#issuecomment-7152564228) Thanks @⁠adriaespii and @⁠ezbyDev for testing on RX 9070 / RX 9060 XT! Root cause of the hardware failures: - `sample_l_o` (regular point sampler) passed on both GPUs, while `image_gather4_c_lz`, `image_gather4_c_lz_o`, and `image_sample_c_lz_o` returned `[0.0, 0.0, 0.0, 0.0]`. - The tests were binding `View::Texture` (`DXGI_FORMAT_R32G32B32A32_FLOAT`) to a comparison sampler. Per D3D12 format support rules, `SHADER_SAMPLE_COMPARISON` / `SHADER_GATHER_COMPARISON` are only guaranteed on single-channel float/depth formats (such as `DXGI_FORMAT_R32_FLOAT`); AMD hardware returns `0.0` for comparison filtering on `R32G32B32A32_FLOAT` while WARP permits it. Fix in the rebased commit (`7871ce7`): - Rebased onto latest `main` (`310c6eb`). - Added `View::FloatTexture(u32, u32, &[f32])` (`DXGI_FORMAT_R32_FLOAT`) to the test harness in `crates/victory-shader/src/emit/host.rs`. - Updated the comparison-sampling tests (`image_gather4_c_lz`, `image_gather4_c_lz_o`, `image_sample_c_lz_o`) to bind `View::FloatTexture` while keeping non-comparison offset sampling tests on `View::Texture`. - Verified `clippy`, `clippy --all-features`, and `cargo test --workspace --locked` on `windows-latest` (DXIL validation + WARP execution). Would appreciate a re-test on AMD hardware when you have a moment!
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/host.rs
  • crates/victory-shader/src/emit/valu_tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-123'
git switch 'github-bot/gh-123'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-123'
git switch 'github-bot/gh-123'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-123'
git switch 'main'
git merge --squash 'github-bot/gh-123'
git switch 'main'
git merge --ff-only 'github-bot/gh-123'
git switch 'main'
git merge 'github-bot/gh-123'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.