Recompiler: add HLSL parity for MSAA image load, msaa_load, and get_resinfo #3357
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3357"
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?
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T10:15:30Z.
What changed
Added HLSL translator parity in
crates/xcl/src/gpu/recomp/emit.rsfor multisampled MIMG instructions (DIM 6Texture2DMSandDIM 7Texture2DMSArray), matching the direct DXIL path incrates/xcl/src/gpu/dxil/lower_image.rs:image_store,image_atomic_*,image_load_miponDIM 6/7) and single-sampledimage_msaa_loadcleanly at translation time instead of emitting invalid HLSL.image_get_resinfoonDIM 6(Texture2DMS, returning(w, h, 0, 1)) andDIM 7(Texture2DMSArray, returning(w, h, elements, 1)), includingD16=1half-word packing.image_loadandimage_msaa_loadonDIM 6andDIM 7acrossuint/int/floatT# formats, queryingGetDimensionsfor the sample count and guarding every sample load with[branch] if (s < sc)so out-of-range sample indices return0andLoadstays in a separate basic block fromGetDimensions, plusD16=1packing.gpu::dxil::msaa_tests::hlsl_msaa_image_ops_translate_and_run_on_gpuincrates/xcl/src/gpu/dxil/msaa_tests.rscovering clean rejection of unsupported ops, HLSL codegen, and GPU execution onTexture2DMSandTexture2DMSArray(including out-of-range samples andD16=1).Why
Previously the HLSL fallback path in
emit.rsfailed translation onDIM 7(Texture2DMSArray),image_msaa_load, andimage_get_resinfoonDIM 6/7, emitted an unguardedTexture2DMS.Load(xy, sample)forDIM 6image_load(undefined / faulting for out-of-range sample indices), and emitted invalidRWTexture2DMS/Load(int3(...))HLSL for unsupported MSAA stores, atomics, andimage_load_mip. Any shader falling back from direct DXIL to HLSL with MSAA image instructions either failed translation/DXC compilation or produced undefined out-of-range sample reads.Tested
cargo check --workspace --all-targets: 0 errors, 0 new warnings.cargo test -p xcl --lib -- msaa_tests gpu_image_get_resinfo_dim_2d_of_an_msaa_tsharp gpu_image_get_resinfo_past_last_level) on NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1074, Windows 11 Pro Build 26200, DXC 1.9.2609.5): 9 passed, 0 failed, 0 ignored (0.41 s).cargo test --workspace -- --test-threads=4,XCL_DXC_DIRset to DXC 1.9.2609.5) on NVIDIA GeForce RTX 5070 Ti: exit 0 (92.5 s).bf03c4b3c8e83ca40deba1f21a992127d9d4e31b, 0 minidumps, 0 display events):main150 s baseline smoke run (f0e8fdd5c3942ddd399d5ee11384c8595c5aacff):Not tested
image_load/image_msaa_loadonsint(Texture2DMS<int4>) MSAA T#s on GPU (covered forfloat2DMS anduint2DMSArray;intuses the identical branch withasuint).XCL_DIRECT_DXIL=none); the smoke run usedXCL_DIRECT_DXIL=all.AI use
Implemented and verified with Antigravity (Gemini) assistance; all changes, generated HLSL, and real-GPU test/smoke results were directly reviewed and run on local hardware.
Imported from ivall/xcl. Originally posted by tiagonleal on 2026-11-30T03:55:13Z.
merge-check
base:
f97120dc19head:
bf03c4b3c8merge: clean
build: cargo build --workspace -> ok (also
cargo build --release -p xcl)tests: cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4 -> 2842 passed, 0 failed, 51 ignored; SKIPPED: 24 lines (22
no wave64, 2no heap windows), the same as on the base; failing: none. Base alone on this PC: 2841 passed, 0 failed, 51 ignored. But the new test passes in the suite only because its GPU half runs the direct DXIL backend by default, and with the HLSL path selected it fails:XCL_DIRECT_DXIL=0 cargo test -p xcl --lib gpu::dxil::msaa_tests::hlsl_msaa_image_ops_translate_and_run_on_gpu -- --exact-> FAILED 4 of 4 atmsaa_tests.rs:437,lane 0 HLSL D16 resinfo clobbered v56/v57, left(0, 0), right(287454020, 1432778632). The other six tests ofgpu::dxil::msaa_testspass with that setting.review: whole diff read (+164/-2,
gpu/recomp/emit.rs,gpu/dxil/msaa_tests.rs). Two things. First,runner::run_code_withreturns throughdirect_kernel_fullwhenever direct DXIL is enabled, which is the default, so the GPU half of the new test never compiles or runs the HLSL this PR adds; only the text checks beforegpu_ready()look at it. Second, when the HLSL does run (above), every assertion up to the D16get_resinforesults passes, including the MSAA loads, the array case and the out-of-range sample, and then the last one fails: the two registers after the D16 result, which the test fills with0x11223344and0x55667788, come back as 0. So the HLSL D16get_resinfowrites two registers more than the direct DXIL one. Seen on NVIDIA wave32 only; I have no AMD card to say whether it is the same there.performance: only shaders on the HLSL path are affected.
scripts/smoke.ps1, 60 s of a retail title, release: 1696 frames and 16091 MB peak commit against 1635 and 1680 frames on the base; no device removal, no crash. That run does not reach these operations.verdict: not yet: with the HLSL path selected (XCL_DIRECT_DXIL=0) the PR's own test fails 4 of 4 on the D16 get_resinfo register check, and by default its GPU half does not run the HLSL at all
hardware / tool and model: RTX 5070 Ti 16 GB (617.42, wave32), Ryzen 7 9800X3D, 32 GB, Windows 11 26300, rustc 1.100.0 / Claude Code (Claude Fable 5.2 ran the build, suite, tests and smoke and wrote this; Claude Opus 5.5 read the diff first, and I checked its main points in the merged source)
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:47:26Z.
Review (head
cd7e1158, diff read, not a merge-check: thePR descriptioncheck fails, so not built or run here yet):bf03c4b3, a commit from before the rebase (the head iscd7e1158), which is whyPR descriptionfails. It needs rerunning on the head.GetDimensionsbefore theLoad, the pattern the direct DXIL path avoids for the amdxc crash (#1900) with an explicit block split. Here, avoiding it depends on DXC keeping the[branch]body as its own block. Nothing checks that, and it wasn't run on AMD. A test that notextureLoadshares a block withgetDimensionsin the compiled DXIL would cover it.XCL_DIRECT_DXIL=0|1get an extraGetDimensionsand[branch]per DIM 6 load.XCL_DIRECT_DXIL=noneisn't a real setting.Fine: it matches direct DXIL's
mimg_msaaand the MSget_resinfo. It rejects the same ops.msaa_loadreads 4 consecutive samples of one channel and zeroes those past the count (fragment = sample, no FMASK). TheGetDimensionsargument order forTexture2DMS/Texture2DMSArrayand the D16 packing are right. The test fails on main.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T16:07:07Z.
Test report (not a merge-check:
PR descriptionred)base:
b2b1f109d2head:
cd7e11585amerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2903 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: not repeated here; my review of this same head is at https://github.com/xcl-dev/xcl/pull/3357#issuecomment-7300065476, and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main.
performance: no smoke run.
assessment: merges, builds and passes the whole suite on current main (0 failed); the findings in my review stand
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.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T01:44:26Z.
Code review location:
crates/xcl/src/gpu/recomp/emit.rs; line 3042The MSAA load and resinfo paths pick Texture2DMS or Texture2DMSArray from the instruction's DIM alone and never check the T# TYPE (14 vs 15). The DIM 0/1 resinfo path (~3003) branches on TYPE because the two can disagree. A DIM 7 image_load on a TYPE 14 (non-array) T#, DIM 6 on a TYPE 15 T#, or DIM 6 on a plain 2D TYPE 9 T# binds the heap SRV with a different dimension than its descriptor, which is undefined in D3D12 and can fault on AMD.
{t}_okonly checks TYPE >= 8. The DIM 7 case is new in this PR.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T01:44:26Z.
Code review location:
crates/xcl/src/gpu/recomp/emit.rs; line 2959Not certain about this one:
image_get_resinfoon DIM 6/7 never reads the mip operand and always returns (w, h, depth, 1), while the neighbouring get_resinfo path zeroes the sizes when the level is past the last (if (mipv >= n), and the comment at ~2991 says RDNA2 returns 0 there). A shader asking for mip 1 of a Texture2DMS gets full sizes instead of 0, so a loop over levels until 0 gets the wrong result or never ends. Direct DXIL (lower_image.rs:1465) has the same gap, so the two backends agree, but both may differ from hardware.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T01:44:26Z.
Review: COMMENTED
Review of
cd7e1158: 2 finding(s). 2 are inline.These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T19:39:23Z.
Closing: HLSL-only parity PR whose own
XCL_DIRECT_DXIL=0tests fail; direct DXIL is the active path.Pull request closed