Recompiler: dispatch integer formats for non-comparison image_gather4 #3240

Open
Kalmarv wants to merge 1 commit from upstream-pr/3240 into main
Kalmarv commented 2026-11-28 23:44:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-28T23:44:44Z.


Non-comparison image_gather4* lowering (including UNORM=1 and explicit-LOD image_gather4_l) hardcoded Texture*<float4> / dx.op.textureGather.f32 and applied f32-to-f16 conversion when D16 was set. Gathering a UINT or SINT texture (such as R16_UINT) through a float4 handle mismatches the D3D12 SRV return type, and f32tof16 on integer values flushes results to zero.

What is in it

  • crates/xcl/src/gpu/dxil/lower_image.rs: dispatch non-comparison image_gather4* on img_cls((tw1 >> 20) & 0x1FF) (CompType::U32 / I32 / F32, matching image_load) across mimg, mimg_unorm_sample, and mimg_gather4_lod; emit integer border colors (0/1) for gather4_l and mask low 16 bits (x & 0xFFFF) instead of f32_to_f16 when d16 is set on integer formats; keep comparison gather4_c* float-only.
  • crates/xcl/src/gpu/recomp/emit.rs: match the 3-way img_cls dispatch (Texture*<uint4> / <int4> / <float4>) and integer d16 masking for non-comparison gather4 in the HLSL backend.
  • crates/xcl/src/gpu/recomp/tests.rs: add gpu_gather4_integer_formats covering R16_UINT, R16_UINT + D16, R32_SINT (Direct DXIL + HLSL), plus IMAGE_GATHER4_L and UNORM=1 (Direct DXIL).

Tested

  • Hardware / toolchain: NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1074), AMD Ryzen 9 9950X, Windows 11 Pro (Build 26200), rustc 1.99.0 (b940084d7), DXC 1.9.2609.5, debug tests / release smoke.
  • cargo test --workspace -- --test-threads=4: 2597 passed, 0 failed, 49 ignored.
  • SKIPPED GPU tests on RTX 5070 Ti (26 total): 21 no wave64 (wave32-only adapter), 3 #1426 per-lane f16 refusals (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32), 2 no heap windows (default XCL_HEAP_WINDOWS off). Zero no GPU or no DXC skips.
  • Targeted failing-before -> passing-after verification: gather4_dispatches_integer_and_float_formats (DXC 1.9 validated), gpu_gather4_integer_formats (Direct DXIL + HLSL on RTX 5070 Ti), gather4_lod_tests (5/5), and gpu_images_sample_load_store_atomic.
  • Real title smoke run executed with XCL_DIRECT_DXIL=all and DXC 1.9.2609.5 (1956 frames vs 1695 on main, 0 device removals, 0 crashes).

Regression run

xcl-smoke v1
commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1695 (PresentX 1695)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31546 MB
xcl-smoke v1
commit: 779ca19f4bdb735111f7c7d312aa4300fb3204a7
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1956 (PresentX 1956)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31960 MB

Not tested

  • AMD GPUs (RDNA2/3/4) and wave64-native hardware (no wave64 tests skipped on RTX 5070 Ti).
  • Cube / 3D integer image_gather4 variants and non-gather integer explicit-LOD image_sample_l / image_sample_lz instructions.

AI use

  • Antigravity (Google Gemini): implemented the Direct DXIL and HLSL lowering changes, wrote unit and GPU tests, ran the workspace test suite and title regression run on hardware, and drafted the PR description.
<!-- greyfinch-sync:ivall/xcl:issue:5545737142 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3240). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-28T23:44:44Z. --- Non-comparison `image_gather4*` lowering (including `UNORM=1` and explicit-LOD `image_gather4_l`) hardcoded `Texture*<float4>` / `dx.op.textureGather.f32` and applied `f32`-to-`f16` conversion when `D16` was set. Gathering a `UINT` or `SINT` texture (such as `R16_UINT`) through a float4 handle mismatches the D3D12 SRV return type, and `f32tof16` on integer values flushes results to zero. **What is in it** - `crates/xcl/src/gpu/dxil/lower_image.rs`: dispatch non-comparison `image_gather4*` on `img_cls((tw1 >> 20) & 0x1FF)` (`CompType::U32` / `I32` / `F32`, matching `image_load`) across `mimg`, `mimg_unorm_sample`, and `mimg_gather4_lod`; emit integer border colors (`0`/`1`) for `gather4_l` and mask low 16 bits (`x & 0xFFFF`) instead of `f32_to_f16` when `d16` is set on integer formats; keep comparison `gather4_c*` float-only. - `crates/xcl/src/gpu/recomp/emit.rs`: match the 3-way `img_cls` dispatch (`Texture*<uint4>` / `<int4>` / `<float4>`) and integer `d16` masking for non-comparison `gather4` in the HLSL backend. - `crates/xcl/src/gpu/recomp/tests.rs`: add `gpu_gather4_integer_formats` covering `R16_UINT`, `R16_UINT` + `D16`, `R32_SINT` (Direct DXIL + HLSL), plus `IMAGE_GATHER4_L` and `UNORM=1` (Direct DXIL). **Tested** - Hardware / toolchain: NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1074), AMD Ryzen 9 9950X, Windows 11 Pro (Build 26200), rustc 1.99.0 (b940084d7), DXC 1.9.2609.5, debug tests / release smoke. - `cargo test --workspace -- --test-threads=4`: 2597 passed, 0 failed, 49 ignored. - `SKIPPED` GPU tests on RTX 5070 Ti (26 total): 21 `no wave64` (wave32-only adapter), 3 `#1426` per-lane f16 refusals (`V_MUL_F16`, `V_PK_MUL_F16`, `V_CVT_F16_F32`), 2 `no heap windows` (default `XCL_HEAP_WINDOWS` off). Zero `no GPU` or `no DXC` skips. - Targeted failing-before -> passing-after verification: `gather4_dispatches_integer_and_float_formats` (DXC 1.9 validated), `gpu_gather4_integer_formats` (Direct DXIL + HLSL on RTX 5070 Ti), `gather4_lod_tests` (5/5), and `gpu_images_sample_load_store_atomic`. - Real title smoke run executed with `XCL_DIRECT_DXIL=all` and DXC 1.9.2609.5 (`1956` frames vs `1695` on main, `0` device removals, `0` crashes). **Regression run** ``` xcl-smoke v1 commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 1695 (PresentX 1695) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 31546 MB ``` ``` xcl-smoke v1 commit: 779ca19f4bdb735111f7c7d312aa4300fb3204a7 gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 1956 (PresentX 1956) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 31960 MB ``` **Not tested** - AMD GPUs (RDNA2/3/4) and wave64-native hardware (`no wave64` tests skipped on RTX 5070 Ti). - Cube / 3D integer `image_gather4` variants and non-gather integer explicit-LOD `image_sample_l` / `image_sample_lz` instructions. **AI use** - Antigravity (Google Gemini): implemented the Direct DXIL and HLSL lowering changes, wrote unit and GPU tests, ran the workspace test suite and title regression run on hardware, and drafted the PR description.
Foniass commented 2026-12-01 07:12:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:12:15Z.


merge-check
base: d0832e614f
head: 779ca19f4b
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2892 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (lower_image.rs +173/-30, recomp/emit.rs +42/-7, tests). It changes the default path: every non-comparison gather4 now reads the format table once and carries three guarded copies of its body (uint, sint, float), chosen at run time from the T#'s format (wave-uniform, SGPR-based); for gather4_l each copy has 2 GetDimensions and 4 textureLoads. Sampling and gather4_c* are unchanged. Findings: (1) the cost isn't measured: shaders get bigger and slower to compile, and the only evidence is one NVIDIA smoke run whose +15 % frames is within noise. (2) The PR's CI is red only in pipeline_library / warm_library (the test race main fixed in 2c003dd6, not in this PR's base); they pass in the run above. (3) AI use says "Antigravity (Google Gemini)", not an exact model. (4) Nit: an unused .enumerate() and let _ = i; at emit.rs ~2797. Fine: it uses the same uint / sint / float dispatch and integer D16 low-16-bit masking as image_load, textureGather / textureLoad pick the i32 overload from the texture's type, gather4 / _lz / _o / UNORM=1 / gather4_l are covered with gather4_c* left float, both backends match, the T# words come from SGPRs that waterfall collapse never touches (it refuses loops whose SRSRC overlaps them), and the tests fail without the fix (the GPU one compares exact texel values; it skipped with "no wave64" in CI).
performance: 60 s smoke of a retail title, main d0832e61 vs this merge (0d5dbfcd): 1516 -> 1431 frames shown (94 %; last presents per 2 s: 61 60 60), peak commit 18133 -> 16436 MB, 0 device removals, 0 crashes. A first run of this PR's suite hit the intermittent lib-test crash right after gpu::agility::tests::create_device_sets_dred_first (0xc0000005 in the NVIDIA driver) also seen on unrelated PRs today; this rerun is clean.
verdict: safe to merge (after a CI rerun on current main; the extra per-gather shader size and compile cost isn't measured, and the description should name the AI model)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7303767339 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3240#issuecomment-7303767339). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T07:12:15Z. --- merge-check base: d0832e614fa7d6ae027bb4feb27ccb9121f54a8f head: 779ca19f4bdb735111f7c7d312aa4300fb3204a7 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2892 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none review: read the whole diff (lower_image.rs +173/-30, recomp/emit.rs +42/-7, tests). It changes the default path: every non-comparison gather4 now reads the format table once and carries three guarded copies of its body (uint, sint, float), chosen at run time from the T#'s format (wave-uniform, SGPR-based); for `gather4_l` each copy has 2 GetDimensions and 4 textureLoads. Sampling and `gather4_c*` are unchanged. Findings: (1) the cost isn't measured: shaders get bigger and slower to compile, and the only evidence is one NVIDIA smoke run whose +15 % frames is within noise. (2) The PR's CI is red only in pipeline_library / warm_library (the test race main fixed in 2c003dd6, not in this PR's base); they pass in the run above. (3) AI use says "Antigravity (Google Gemini)", not an exact model. (4) Nit: an unused `.enumerate()` and `let _ = i;` at emit.rs ~2797. Fine: it uses the same uint / sint / float dispatch and integer D16 low-16-bit masking as image_load, textureGather / textureLoad pick the i32 overload from the texture's type, gather4 / _lz / _o / UNORM=1 / gather4_l are covered with gather4_c* left float, both backends match, the T# words come from SGPRs that waterfall collapse never touches (it refuses loops whose SRSRC overlaps them), and the tests fail without the fix (the GPU one compares exact texel values; it skipped with "no wave64" in CI). performance: 60 s smoke of a retail title, main d0832e61 vs this merge (0d5dbfcd): 1516 -> 1431 frames shown (94 %; last presents per 2 s: 61 60 60), peak commit 18133 -> 16436 MB, 0 device removals, 0 crashes. A first run of this PR's suite hit the intermittent lib-test crash right after gpu::agility::tests::create_device_sets_dred_first (0xc0000005 in the NVIDIA driver) also seen on unrelated PRs today; this rerun is clean. verdict: safe to merge (after a CI rerun on current main; the extra per-gather shader size and compile cost isn't measured, and the description should name the AI model) hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 AI-written and posted by Foniass without a human check of each point.
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/3240:upstream-pr/3240'
git switch 'upstream-pr/3240'

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/3240'
git switch 'upstream-pr/3240'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3240'
git switch 'upstream-pr/3240'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3240'
git switch 'main'
git merge --squash 'upstream-pr/3240'
git switch 'main'
git merge --ff-only 'upstream-pr/3240'
git switch 'main'
git merge 'upstream-pr/3240'
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
xcl-dev/xcl!3240
No description provided.