Shaders: lower image_gather4_c_lz and image_gather4_c_lz_o (MIMG 0x4f, 0x5f) #1489
No reviewers
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!1489
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1489"
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?
@AscilCH on GitHub · 2026-11-24 18:22 UTC · original
AscilCH:fix/image-gather4-cmp-lz→main· +314 −10 · 2 files · 1 commits · openSummary
Lower GFX10 comparison gather instructions
image_gather4_c_lz(MIMG 0x4f) andimage_gather4_c_lz_o(MIMG 0x5f) inLower::image()(crates/victory-shader/src/emit/lower.rs) to DXILdx.op.textureGatherCmp.f32(opcode74).(Complementary to #383 and #694, which do not cover comparison gather instructions.)
Reproduction (Before Fix)
Lowering a synthetic compute shader using
image_gather4_c_lzfailed with:Implementation
"image_gather4_c_lz" | "image_gather4_c_lz_o"to DXIL opcode74(textureGatherCmp.f32), settingcmp = matches!(op, 64 | 65 | 74)so the sampler handle is annotated as a comparison sampler (0x8000) andfirstaccounts for both optional_ooffset word and comparison reference value.dx.op.textureGatherCmp.f32passing the comparison reference fromaddr_val(self, first - 1)asf32, and unpack all four gathered comparison results (matches!(op, 73 | 74)).!matches!(kind, 2 | 5 | 7)).offset_word && kind == 5).op == 74 && *dmask != 1), since D3D12 hardware and WARP ignorechannel != 0ontextureGatherCmpand always compare channel 0.Test
Added synthetic end-to-end test
emit::valu_tests::image_gather4_c_lz_and_offset_match_rdna2:dxil.dllvalidation for 2Dimage_gather4_c_lzacross multiple comparison thresholds verifying all 4 bilinear footprint slots.dxil.dllvalidation for 2Dimage_gather4_c_lz_owith both positive and negative 6-bit sign-extended programmable offsets(-1, +1)and(+1, -1).dxil.dllvalidation for Cube (dim = 3)image_gather4_c_lz.dmask = 0x2, cube_o, and 1D gather.Verification
rustfmt --edition 2024 --check crates/victory-shader/src/emit/valu_tests.rsand modified lines oflower.rs: cleancargo test -p victory-shader --locked image_gather4_c_lz_and_offset_match_rdna2(hardware + WARP +dxil.dll): passedVICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1: 121 passed, 0 failedcargo xtask policy: 154 files okcargo clippy --workspace --all-targets --locked -- -D warnings: cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean@matheusfermiano-source on GitHub · 2026-11-24 18:28 UTC · original
A note for anyone running this on Linux: under Proton,
image_gather4_c_lz_and_offset_match_rdna2fails on both of my GPUs. The cause is the test's texture, not the lowering.Head
e0a052c, first case (constants=[0x40f00000, 0x3f000000, 0x3f000000, 0]), want[1.0, 1.0, 0.0, 0.0]:[0.0, 0.0, 0.0, 0.0][9.0, 10.0, 6.0, 5.0], the raw texels with no comparisonThe test gathers from an RGBA32F color texture (
View::Texture) through a comparison sampler. On both drivers,vulkaninfo --show-formatslistsFORMAT_FEATURE_2_SAMPLED_IMAGE_DEPTH_COMPARISON_BITonly for depth formats, not forR32G32B32A32_SFLOATorR32_SFLOAT. So vkd3d-proton has no supported way to honor the comparison on that texture, and each driver does something different.The rest of the suite on the Radeon: 119 passed, and the only other failure is
emit::tests::stub_pipeline_is_created, as onmain(vkd3d-proton accepts a zeroed DXIL hash; see #1218). Nothing that passes onmainfails.If the test host had a depth resource read as
R32_FLOAT(the way shadow maps are usually bound), the test would probably run under Proton too. I have not tried that.Built on Linux with llvm-mingw for
x86_64-pc-windows-gnullvm(Rust 1.98.1);dxil.dllfrom DXC 1.9.2609 was loaded. Synthetic tests only, no game files. AI-assisted (Claude Code, Opus 5.5); every run was on this machine.@Comtesse1 on GitHub · 2026-11-24 18:47 UTC · original
Native Windows readback: all six comparison gathers match with an R32_FLOAT fixture
On PR head
e0a052c, I tested the same six synthetic cases on an RTX 3080 (driver 621.01, Windows 11 build 26300) and separately on Microsoft WARP. On both devices, D3D12 reports ordinary gather but not comparison gather for the originalR32G32B32A32_FLOATformat. I skipped that unsupported configuration rather than treating its output as a reference.I kept the PR's shaders, comparison sampler, coordinates, thresholds, offsets, and expected vectors unchanged. The test-only change uploads the same red texels to a typed
R32_FLOATtexture with a matching SRV, which both devices report supports comparison gather. All 6/6 cases (24/24 returned components) matched on each device, in each of two independent processes. For the first case (reference 7.5), both returned[1, 1, 0, 0]. The offset cases passed too.I would change the test fixture before diagnosing a lowering bug from the four-channel result. This is native D3D12 only: no Proton, Xbox, game, full suite, or depth-stencil rendering test. The attachment includes the test-only patch, per-case readbacks, format-query source and reproduction commands.
AI use: OpenAI Codex (GPT-5.5) prepared the instrumentation and report and ran the tests on this machine.
VIctory-1489-RTX3080-readbacks.zip
@wwwwwwww3333333 on GitHub · 2026-11-24 19:17 UTC · original
A third driver for the same failure: RX 6750 XT (RDNA2, gfx1031), AMD driver 32.0.21045.29003, i5-13400F, Windows 11, Rust 1.98.1 MSVC. Head
e0a052con mainffe310e(clean merge). Native D3D12, no Proton.image_gather4_c_lz_and_offset_match_rdna2fails on the hardware adapter at the first case: constants[0x40f00000, 0x3f000000, 0x3f000000, 0], got[0.0, 0.0, 0.0, 0.0], want[1.0, 1.0, 0.0, 0.0]. The rest of victory-shader passes: 120 passed, 1 failed.So with the RGBA32F
View::Texturefixture, the results are:[9, 10, 6, 5](@DenRakEiw).Two different answers across three drivers for one input, which is what an unsupported comparison-gather format looks like rather than a lowering bug. It agrees with @Comtesse1's finding that every case matches once the fixture is a typed R32_FLOAT texture. I haven't run that patch on AMD.
Synthetic tests only, no game files. AI-assisted (Claude picked the PRs and wrote the batch script; I ran it on my machine).
@steven-seagull27 on GitHub · 2026-11-24 20:11 UTC · original · edited 2026-11-24 20:20 UTC
I tested the depth-texture suggestion on PR head
e0a052cunder native Windows 11 (build 26300.10075, NVIDIA driver32.0.16.2124, Rust1.98.1MSVC). All six comparison-gather cases passed on the RTX 5080 with the depth texture. On this machine WARP passed all six with either texture.At UV
(0.5, 0.5)with reference7.5, the RTX 5080 returned the raw texels[9, 10, 6, 5]from the color texture and the expected[1, 1, 0, 0]from the depth texture. I recorded each adapter’s identity and readbacks independently for the three ordinary gathers and three offset cases. The emitted shaders passed DXIL validation with SDK10.0.26100.0.The patch adds a depth-capable
R32_TYPELESSresource to the test host, exposes it through anR32_FLOATSRV, and seeds it with the original red-channel values. Both runs used the same shader, sampler, thresholds and offsets. Download the patch · View the diffFrom the PR checkout, after downloading
depth-texture.patch:I verified the downloaded patch applies cleanly to
e0a052c. With it applied, the shader library suite reported 121 passed, 0 failed and 1 ignored. Four optional compiler-comparison tests reported a skip within that pass count.@sinan-cmyk on GitHub · 2026-11-24 20:14 UTC · original
The new test fails on NVIDIA (Ada) and passes on WARP
Result:
image_gather4_c_lz_and_offset_match_rdna2fails on NVIDIA and passes on WARP. I merged heade0a052contomainffe310e. The test fails 2 out of 2 times on the RTX 4070 SUPER and passes withVICTORY_WARP=1.On NVIDIA, the gather returns the raw texel values instead of the comparison results. That suggests the host sampler bound for the test is not a comparison sampler there, or the comparison state is dropped on this path, and WARP compares anyway. Only the comparison form is affected. The rest of the suite passes.
Offline. I merged the head onto
mainffe310e(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11, compared program by program (25,889 programs). Validated: 21,724 on both, 0 gained, 0 lost, no failure reason changed. That is expected for a fix whose instructions sit behind earlier failures.Machine: RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter; Windows 11 25H2; Rust 1.98.1. The rest of
cargo test --locked -p victory-shader --libpasses. No game data. AI-assisted (Claude Code).@steven-seagull27 on GitHub · 2026-11-24 21:16 UTC · original
@AscilCH I put the tested depth-texture fixture in one commit on my fork, based directly on your PR head
e0a052c. With your PR branch checked out, you can apply it with:I verified the cherry-pick in a clean checkout of
e0a052cand reran the focused test successfully:The change is confined to the synthetic fixture and its test host. With the depth texture, all six comparison-gather cases matched on both the RTX 5080 and WARP. Per-adapter results
@wwwwwwww3333333 on GitHub · 2026-11-24 21:51 UTC · original
The R32_FLOAT fixture also fixes it on AMD. RX 6750 XT (RDNA2, gfx1031, AMD driver 32.0.21045.29003), Windows 11, Rust 1.98.1 MSVC, head
e0a052con mainffe310e. In my earlier run the original RGBA32F fixture returned zeros here. With the comparison gather reading a typed R32_FLOAT texture,image_gather4_c_lz_and_offset_match_rdna2passes on the hardware adapter and on WARP, and victory-shader passes 121/121.cargo clippy -p victory-shader --all-targets -- -D warningsis clean.So the same fix now holds on NVIDIA (@Comtesse1, @remigiuszbyczkowski-svg), AMD and WARP. The patch I used adds a
View::RedTextureto the test harness rather than a depth texture. @steven-seagull27's depth-texture commit should do the same job.Patch I ran (test harness + the test's fixture)
Unit tests only, no game files. AI-assisted (Claude; I ran it on my machine).
@Marvisak on GitHub · 2026-11-25 01:29 UTC · original
Automated triage for the maintainers.
Needs rebase. This pull request conflicts with
main(conflicting:crates/victory-shader/src/emit/lower.rs,crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the currentmain.Generated by Claude Code
@steven-seagull27 on GitHub · 2026-11-26 02:30 UTC · original
@AscilCH I resolved the three conflicts on your comparison-gather branch against
mainat63bcca43. This tested merge commit keeps your original commit and the depth-fixture commit. The test now uses main’s shared builder/validator, which supplies the newer shader metadata.All six depth readbacks matched on each of RTX 5080 (621.40) and Windows WARP (10.0.26100.10068), in three fresh processes. That includes both signed offsets,
(-1,+1)and(+1,-1). The cube module validated. The non-red, 1D and offset-cube refusal checks passed. The separate explicit-LOD hardware test on RTX still has the same lane-0 mismatch as unchangedmain; it passes on WARP on both revisions. Strict shader Clippy and asset policy passed.With your PR branch checked out, this fast-forwards it:
I also tested your signed-offset fixture on #1687. Its red results agree, but its non-red masks translated and read red on both devices. A joint integration commit retains your red-only guard and fixtures alongside #1687’s additional offset sample support, with both authors’ commits in the history. This gives maintainers the option of reviewing the overlap once.
AI-assisted with Codex. All inputs were synthetic.
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.Merge
Merge the changes and update on Forgejo.