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

Open
opened 2026-11-26 04:35:25 +00:00 by github-bot · 4 comments
Owner

@⁠davi713albano-coder on GitHub · 2026-11-24 18:52 UTC · original

Summary

In emit::lower::image:

  1. Comparison gathers image_gather4_c_lz (0x04f) and image_gather4_c_lz_o (0x05f) were unsupported, even though image_gather4_lz(_o) and comparison samplers (image_sample_c(_lz)) were already lowered.
  2. Immediate-offset (_o) variants of the already-lowered sample opcodes (image_sample_lz_o, image_sample_l_o, image_sample_b_o, image_sample_d_o, image_sample_c_o, image_sample_c_lz_o) were unsupported, because constant-offset decoding lived only inside the op == 60 arm and bias/lod indexing assumed offset_word == false (and a16 address unpacking did not separate whole-dword leading address words from packed 16-bit gradients/coordinates/LOD).

This branch lowers all of them cleanly to DXIL SM 6.6.

Changes (shader/image-gather-cmp-and-sample-offsets, commit 572bcbe)

  • crates/victory-shader/src/emit/lower.rs:
    • Lower image_gather4_c_lz and image_gather4_c_lz_o to dx.op.textureGatherCmp.f32 (opcode 74), marking the sampler as a comparison sampler (0x8000), supporting programmable 2D offsets (_o) via sign-extended 6-bit X/Y extraction, passing dmask.trailing_zeros() and the comparison reference, and writing all 4 gathered channels (matches!(op, 73 | 74)).
    • Lower image_sample_lz_o, image_sample_l_o, image_sample_b_o, image_sample_d_o, image_sample_c_o (pixel shaders), and image_sample_c_lz_o by lifting constant texel-offset decoding (-8..=7) ahead of match op (rejecting cube samples/gathers with texel offsets).
    • Split full-dword leading MIMG address words (offset, bias, cmp) from a16-packed gradients (dx/dy) and coordinates/LOD to match gfx10::fields::image_addr_dwords, fixing bias and lod indexing when _o is present.
  • crates/victory-shader/src/emit/valu_tests.rs:
    • Add 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 (+2,+1) and negative (-1,-1) offsets) with dxil.dll validation + container hash check and live D3D12 WARP readback.
    • Add image_sample_offset_variants_match_d3d12: synthetic compute tests with live D3D12 WARP readback for image_sample_lz_o, image_sample_l_o, image_sample_c_lz_o, and image_sample_d_o, plus synthetic pixel shader dxil.dll validation and live D3D12 graphics PSO creation for image_sample_b_o and image_sample_c_o.

Branch & Verification

(No game data used. AI-assisted.)

**@⁠davi713albano-coder** on GitHub · 2026-11-24 18:52 UTC · [original](https://github.com/Marvisak/VIctory/issues/1535) ### Summary In `emit::lower::image`: 1. Comparison gathers `image_gather4_c_lz` (`0x04f`) and `image_gather4_c_lz_o` (`0x05f`) were unsupported, even though `image_gather4_lz(_o)` and comparison samplers (`image_sample_c(_lz)`) were already lowered. 2. Immediate-offset (`_o`) variants of the already-lowered sample opcodes (`image_sample_lz_o`, `image_sample_l_o`, `image_sample_b_o`, `image_sample_d_o`, `image_sample_c_o`, `image_sample_c_lz_o`) were unsupported, because constant-offset decoding lived only inside the `op == 60` arm and `bias`/`lod` indexing assumed `offset_word == false` (and `a16` address unpacking did not separate whole-dword leading address words from packed 16-bit gradients/coordinates/LOD). This branch lowers all of them cleanly to DXIL SM 6.6. ### Changes (`shader/image-gather-cmp-and-sample-offsets`, commit `572bcbe`) - `crates/victory-shader/src/emit/lower.rs`: - Lower `image_gather4_c_lz` and `image_gather4_c_lz_o` to `dx.op.textureGatherCmp.f32` (opcode `74`), marking the sampler as a comparison sampler (`0x8000`), supporting programmable 2D offsets (`_o`) via sign-extended 6-bit X/Y extraction, passing `dmask.trailing_zeros()` and the comparison reference, and writing all 4 gathered channels (`matches!(op, 73 | 74)`). - Lower `image_sample_lz_o`, `image_sample_l_o`, `image_sample_b_o`, `image_sample_d_o`, `image_sample_c_o` (pixel shaders), and `image_sample_c_lz_o` by lifting constant texel-offset decoding (`-8..=7`) ahead of `match op` (rejecting cube samples/gathers with texel offsets). - Split full-dword leading MIMG address words (`offset`, `bias`, `cmp`) from `a16`-packed gradients (`dx`/`dy`) and coordinates/LOD to match `gfx10::fields::image_addr_dwords`, fixing `bias` and `lod` indexing when `_o` is present. - `crates/victory-shader/src/emit/valu_tests.rs`: - Add `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 `(+2,+1)` and negative `(-1,-1)` offsets) with `dxil.dll` validation + container hash check and live D3D12 WARP readback. - Add `image_sample_offset_variants_match_d3d12`: synthetic compute tests with live D3D12 WARP readback for `image_sample_lz_o`, `image_sample_l_o`, `image_sample_c_lz_o`, and `image_sample_d_o`, plus synthetic pixel shader `dxil.dll` validation and live D3D12 graphics PSO creation for `image_sample_b_o` and `image_sample_c_o`. ### Branch & Verification - **Branch:** https://github.com/davi713albano-coder/VIctory/tree/shader/image-gather-cmp-and-sample-offsets - **Compare against `main` (`ffe310e`):** https://github.com/Marvisak/VIctory/compare/main...davi713albano-coder:VIctory:shader/image-gather-cmp-and-sample-offsets - **Unmodified upstream CI (`windows-latest`):** https://github.com/davi713albano-coder/VIctory/actions/runs/45463144180 - `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): 344 passed, 0 failed (`image_gather4_c_lz_and_offset_match_d3d12 ... ok`, `image_sample_offset_variants_match_d3d12 ... ok`) *(No game data used. AI-assisted.)*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:35:25 +00:00
Author
Owner

@⁠Paull007 on GitHub · 2026-11-24 19:28 UTC · original

Shaders: lower image_gather4_c_lz(_o) and the _o sample variants

Refs #1535

image_gather4_c_lz / _c_lz_o → textureGatherCmp (comparison sampler, programmable 2D offsets, all four channels)
image_sample_lz_o, _l_o, _b_o, _d_o, _c_o, _c_lz_o are now lowered, with the constant offset decoded for every sample; offsets on cubes are refused
Bias and LOD are read after the offset word
a16: offset, bias and compare words stay whole dwords, and gradients and coordinates pack per group, matching image_addr_dwords. This fixes wrong coordinates for a16 image_sample_o / image_gather4_lz_o and wrong a16 1D/3D gradients for image_sample_d

Testing: cargo test -p victory-shader passes (6 new tests in emit/image_tests.rs), and I checked the emitted DXIL by hand. Not yet validated with dxil.dll or on a GPU or WARP. AI-assisted, no game data used.
AI assisted

0001-Shaders-comparison-gathers-and-the-offset-variants-o.patch

**@⁠Paull007** on GitHub · 2026-11-24 19:28 UTC · [original](https://github.com/Marvisak/VIctory/issues/1535#issuecomment-7142151096) Shaders: lower image_gather4_c_lz(_o) and the _o sample variants Refs #1535 image_gather4_c_lz / _c_lz_o → textureGatherCmp (comparison sampler, programmable 2D offsets, all four channels) image_sample_lz_o, _l_o, _b_o, _d_o, _c_o, _c_lz_o are now lowered, with the constant offset decoded for every sample; offsets on cubes are refused Bias and LOD are read after the offset word a16: offset, bias and compare words stay whole dwords, and gradients and coordinates pack per group, matching image_addr_dwords. This fixes wrong coordinates for a16 image_sample_o / image_gather4_lz_o and wrong a16 1D/3D gradients for image_sample_d Testing: cargo test -p victory-shader passes (6 new tests in emit/image_tests.rs), and I checked the emitted DXIL by hand. Not yet validated with dxil.dll or on a GPU or WARP. AI-assisted, no game data used. AI assisted [0001-Shaders-comparison-gathers-and-the-offset-variants-o.patch](https://github.com/user-attachments/files/35368813/0001-Shaders-comparison-gathers-and-the-offset-variants-o.patch)
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-24 19:57 UTC · original

I checked image_sample_d_o on 572bcbe with a 4×4 point-sampled texture. The shader uses UV (0.625, 0.625), zero gradients, and texel offset (+1,+1). Both versions passed DXIL validation.

  • a16 off: sampled texel (3,3), returning the expected 15.0.
  • a16 on, opcode still non-G16: sampled texel (1,1), returning 5.0. The coordinates are exactly representable in either format, so the expected value is still 15.0.

The RTX 4070 Ti and WARP agreed. This is the #1116 packing issue showing up in the new offset path: a16 packs the coordinates, while this opcode still takes four full-width gradient registers.

AI-assisted with Codex.

**@⁠DrDarkDK** on GitHub · 2026-11-24 19:57 UTC · [original](https://github.com/Marvisak/VIctory/issues/1535#issuecomment-7142845466) I checked `image_sample_d_o` on `572bcbe` with a 4×4 point-sampled texture. The shader uses UV `(0.625, 0.625)`, zero gradients, and texel offset `(+1,+1)`. Both versions passed DXIL validation. - `a16` off: sampled texel `(3,3)`, returning the expected `15.0`. - `a16` on, opcode still non-G16: sampled texel `(1,1)`, returning `5.0`. The coordinates are exactly representable in either format, so the expected value is still `15.0`. The RTX 4070 Ti and WARP agreed. This is the #1116 packing issue showing up in the new offset path: `a16` packs the coordinates, while this opcode still takes four full-width gradient registers. *AI-assisted with Codex.*
Author
Owner

@⁠Paull007 on GitHub · 2026-11-24 20:02 UTC · original

Shaders: lower image_gather4_c_lz(_o) and _o sample variants

Refs #1535, #1116

Comparison gathers → textureGatherCmp; _lz_o, _l_o, _b_o, _d_o, _c_o, _c_lz_o samples now lowered with constant offsets
a16 and _g16 packed independently, so gradients stay whole f32 under a16 (fixes a16 image_sample_d_o sampling the wrong texel)

Tests pass, including a regression test for the a16 case. AI-assisted, no game data.

0001-Shaders-comparison-gathers-and-the-offset-variants-o.patch

**@⁠Paull007** on GitHub · 2026-11-24 20:02 UTC · [original](https://github.com/Marvisak/VIctory/issues/1535#issuecomment-7142958688) Shaders: lower image_gather4_c_lz(_o) and _o sample variants Refs #1535, #1116 Comparison gathers → textureGatherCmp; _lz_o, _l_o, _b_o, _d_o, _c_o, _c_lz_o samples now lowered with constant offsets a16 and _g16 packed independently, so gradients stay whole f32 under a16 (fixes a16 image_sample_d_o sampling the wrong texel) Tests pass, including a regression test for the a16 case. AI-assisted, no game data. [0001-Shaders-comparison-gathers-and-the-offset-variants-o.patch](https://github.com/user-attachments/files/35372179/0001-Shaders-comparison-gathers-and-the-offset-variants-o.patch)
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:26 UTC · original

Automated triage for the maintainers.

In scope. On main (940d32f), image lowering in crates/victory-shader/src/emit/lower.rs takes image_sample_o, image_gather4_lz_o and image_gather4_l_o, but not image_gather4_c_lz(_o) or the other _o sample variants; those are refused by name.

Open PRs already carry this: #1687 has the same title, and #1489 lowers image_gather4_c_lz(_o) alone. PRs are open to everyone now; @⁠davi713albano-coder and @⁠Paull007, please bring your branch and patch onto one of those, or open one PR, rather than adding a third.

@⁠DrDarkDK's check above (an a16 image_sample_d_o sampling the wrong texel) is the gradient packing problem in #1116; its fields.rs half is #1209, and the lowering half should land with it.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 10:26 UTC · [original](https://github.com/Marvisak/VIctory/issues/1535#issuecomment-7159692533) <!-- victory-issue-triage v1 verdict=tracked seen=2026-11-24T20:02:33Z at=2026-11-25T09:50:38Z --> Automated triage for the maintainers. In scope. On `main` (`940d32f`), image lowering in `crates/victory-shader/src/emit/lower.rs` takes `image_sample_o`, `image_gather4_lz_o` and `image_gather4_l_o`, but not `image_gather4_c_lz(_o)` or the other `_o` sample variants; those are refused by name. Open PRs already carry this: #1687 has the same title, and #1489 lowers `image_gather4_c_lz(_o)` alone. PRs are open to everyone now; @⁠davi713albano-coder and @⁠Paull007, please bring your branch and patch onto one of those, or open one PR, rather than adding a third. @⁠DrDarkDK's check above (an `a16` `image_sample_d_o` sampling the wrong texel) is the gradient packing problem in #1116; its `fields.rs` half is #1209, and the lowering half should land with it. --- _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#1535
No description provided.