Recompiler: add HLSL parity for MSAA image load, msaa_load, and get_resinfo #3357

Closed
Kalmarv wants to merge 1 commit from upstream-pr/3357 into main
Kalmarv commented 2026-11-29 10:15:30 +00:00 (Migrated from github.com)

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.rs for multisampled MIMG instructions (DIM 6 Texture2DMS and DIM 7 Texture2DMSArray), matching the direct DXIL path in crates/xcl/src/gpu/dxil/lower_image.rs:

  • Reject unsupported multisampled operations (image_store, image_atomic_*, image_load_mip on DIM 6/7) and single-sampled image_msaa_load cleanly at translation time instead of emitting invalid HLSL.
  • Handle image_get_resinfo on DIM 6 (Texture2DMS, returning (w, h, 0, 1)) and DIM 7 (Texture2DMSArray, returning (w, h, elements, 1)), including D16=1 half-word packing.
  • Handle image_load and image_msaa_load on DIM 6 and DIM 7 across uint/int/float T# formats, querying GetDimensions for the sample count and guarding every sample load with [branch] if (s < sc) so out-of-range sample indices return 0 and Load stays in a separate basic block from GetDimensions, plus D16=1 packing.
  • Added gpu::dxil::msaa_tests::hlsl_msaa_image_ops_translate_and_run_on_gpu in crates/xcl/src/gpu/dxil/msaa_tests.rs covering clean rejection of unsupported ops, HLSL codegen, and GPU execution on Texture2DMS and Texture2DMSArray (including out-of-range samples and D16=1).

Why

Previously the HLSL fallback path in emit.rs failed translation on DIM 7 (Texture2DMSArray), image_msaa_load, and image_get_resinfo on DIM 6/7, emitted an unguarded Texture2DMS.Load(xy, sample) for DIM 6 image_load (undefined / faulting for out-of-range sample indices), and emitted invalid RWTexture2DMS / Load(int3(...)) HLSL for unsupported MSAA stores, atomics, and image_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.
  • Targeted CPU + GPU tests (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).
  • Full workspace GPU test suite (cargo test --workspace -- --test-threads=4, XCL_DXC_DIR set to DXC 1.9.2609.5) on NVIDIA GeForce RTX 5070 Ti: exit 0 (92.5 s).
  • Real-title 150 s regression smoke run on PR head (bf03c4b3c8e83ca40deba1f21a992127d9d4e31b, 0 minidumps, 0 display events):
xcl-smoke v1
commit: bf03c4b3c8e83ca40deba1f21a992127d9d4e31b
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1560 (PresentX 1560)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 34095 MB
  • Ancestor main 150 s baseline smoke run (f0e8fdd5c3942ddd399d5ee11384c8595c5aacff):
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

Not tested

  • AMD or Intel GPUs (tested on NVIDIA GeForce RTX 5070 Ti only).
  • image_load / image_msaa_load on sint (Texture2DMS<int4>) MSAA T#s on GPU (covered for float 2DMS and uint 2DMSArray; int uses the identical branch with asuint).
  • Real-title execution under forced HLSL fallback (XCL_DIRECT_DXIL=none); the smoke run used XCL_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.

<!-- greyfinch-sync:ivall/xcl:issue:5549741710 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3357). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-29T10:15:30Z. --- **What changed** Added HLSL translator parity in `crates/xcl/src/gpu/recomp/emit.rs` for multisampled MIMG instructions (`DIM 6` `Texture2DMS` and `DIM 7` `Texture2DMSArray`), matching the direct DXIL path in `crates/xcl/src/gpu/dxil/lower_image.rs`: - Reject unsupported multisampled operations (`image_store`, `image_atomic_*`, `image_load_mip` on `DIM 6`/`7`) and single-sampled `image_msaa_load` cleanly at translation time instead of emitting invalid HLSL. - Handle `image_get_resinfo` on `DIM 6` (`Texture2DMS`, returning `(w, h, 0, 1)`) and `DIM 7` (`Texture2DMSArray`, returning `(w, h, elements, 1)`), including `D16=1` half-word packing. - Handle `image_load` and `image_msaa_load` on `DIM 6` and `DIM 7` across `uint`/`int`/`float` T# formats, querying `GetDimensions` for the sample count and guarding every sample load with `[branch] if (s < sc)` so out-of-range sample indices return `0` and `Load` stays in a separate basic block from `GetDimensions`, plus `D16=1` packing. - Added `gpu::dxil::msaa_tests::hlsl_msaa_image_ops_translate_and_run_on_gpu` in `crates/xcl/src/gpu/dxil/msaa_tests.rs` covering clean rejection of unsupported ops, HLSL codegen, and GPU execution on `Texture2DMS` and `Texture2DMSArray` (including out-of-range samples and `D16=1`). **Why** Previously the HLSL fallback path in `emit.rs` failed translation on `DIM 7` (`Texture2DMSArray`), `image_msaa_load`, and `image_get_resinfo` on `DIM 6`/`7`, emitted an unguarded `Texture2DMS.Load(xy, sample)` for `DIM 6` `image_load` (undefined / faulting for out-of-range sample indices), and emitted invalid `RWTexture2DMS` / `Load(int3(...))` HLSL for unsupported MSAA stores, atomics, and `image_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. - Targeted CPU + GPU tests (`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). - Full workspace GPU test suite (`cargo test --workspace -- --test-threads=4`, `XCL_DXC_DIR` set to DXC 1.9.2609.5) on NVIDIA GeForce RTX 5070 Ti: exit 0 (92.5 s). - Real-title 150 s regression smoke run on PR head (`bf03c4b3c8e83ca40deba1f21a992127d9d4e31b`, 0 minidumps, 0 display events): ``` xcl-smoke v1 commit: bf03c4b3c8e83ca40deba1f21a992127d9d4e31b gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 1560 (PresentX 1560) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 34095 MB ``` - Ancestor `main` 150 s baseline smoke run (`f0e8fdd5c3942ddd399d5ee11384c8595c5aacff`): ``` 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 ``` **Not tested** - AMD or Intel GPUs (tested on NVIDIA GeForce RTX 5070 Ti only). - `image_load` / `image_msaa_load` on `sint` (`Texture2DMS<int4>`) MSAA T#s on GPU (covered for `float` 2DMS and `uint` 2DMSArray; `int` uses the identical branch with `asuint`). - Real-title execution under forced HLSL fallback (`XCL_DIRECT_DXIL=none`); the smoke run used `XCL_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.
tiagonleal commented 2026-11-30 03:55:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by tiagonleal on 2026-11-30T03:55:13Z.


merge-check
base: f97120dc19
head: bf03c4b3c8
merge: 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, 2 no 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 at msaa_tests.rs:437, lane 0 HLSL D16 resinfo clobbered v56/v57, left (0, 0), right (287454020, 1432778632). The other six tests of gpu::dxil::msaa_tests pass with that setting.
review: whole diff read (+164/-2, gpu/recomp/emit.rs, gpu/dxil/msaa_tests.rs). Two things. First, runner::run_code_with returns through direct_kernel_full whenever 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 before gpu_ready() look at it. Second, when the HLSL does run (above), every assertion up to the D16 get_resinfo results 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 with 0x11223344 and 0x55667788, come back as 0. So the HLSL D16 get_resinfo writes 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)

  • Tiago
<!-- greyfinch-sync:ivall/xcl:comment:7268310495 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3357#issuecomment-7268310495). Originally posted by [tiagonleal](https://github.com/tiagonleal) on 2026-11-30T03:55:13Z. --- merge-check base: f97120dc196ca05e7f47e919d3675f7d5a2b478a head: bf03c4b3c8e83ca40deba1f21a992127d9d4e31b merge: 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`, 2 `no 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 at `msaa_tests.rs:437`, `lane 0 HLSL D16 resinfo clobbered v56/v57`, left `(0, 0)`, right `(287454020, 1432778632)`. The other six tests of `gpu::dxil::msaa_tests` pass with that setting. review: whole diff read (+164/-2, `gpu/recomp/emit.rs`, `gpu/dxil/msaa_tests.rs`). Two things. First, `runner::run_code_with` returns through `direct_kernel_full` whenever 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 before `gpu_ready()` look at it. Second, when the HLSL does run (above), every assertion up to the D16 `get_resinfo` results 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 with `0x11223344` and `0x55667788`, come back as 0. So the HLSL D16 `get_resinfo` writes 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) - Tiago
Foniass commented 2026-12-01 03:47:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:47:26Z.


Review (head cd7e1158, diff read, not a merge-check: the PR description check fails, so not built or run here yet):

  • The smoke block names bf03c4b3, a commit from before the rebase (the head is cd7e1158), which is why PR description fails. It needs rerunning on the head.
  • AMD risk (from reading, not shown): HLSL pixel shaders with MSAA loads now put a GetDimensions before the Load, 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 no textureLoad shares a block with getDimensions in the compiled DXIL would cover it.
  • Nothing changes by default (direct DXIL already handles every MSAA op); HLSL fallback shaders and XCL_DIRECT_DXIL=0|1 get an extra GetDimensions and [branch] per DIM 6 load.
  • The sint branch isn't GPU-tested (the PR says so), Tested has no counts, AI use doesn't name the exact model, and XCL_DIRECT_DXIL=none isn't a real setting.

Fine: it matches direct DXIL's mimg_msaa and the MS get_resinfo. It rejects the same ops. msaa_load reads 4 consecutive samples of one channel and zeroes those past the count (fragment = sample, no FMASK). The GetDimensions argument order for Texture2DMS / Texture2DMSArray and 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.

<!-- greyfinch-sync:ivall/xcl:comment:7300065476 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3357#issuecomment-7300065476). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T03:47:26Z. --- Review (head cd7e1158, diff read, not a merge-check: the `PR description` check fails, so not built or run here yet): - **The smoke block names bf03c4b3, a commit from before the rebase** (the head is cd7e1158), which is why `PR description` fails. It needs rerunning on the head. - **AMD risk (from reading, not shown):** HLSL pixel shaders with MSAA loads now put a `GetDimensions` before the `Load`, 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 no `textureLoad` shares a block with `getDimensions` in the compiled DXIL would cover it. - Nothing changes by default (direct DXIL already handles every MSAA op); HLSL fallback shaders and `XCL_DIRECT_DXIL=0|1` get an extra `GetDimensions` and `[branch]` per DIM 6 load. - The sint branch isn't GPU-tested (the PR says so), **Tested** has no counts, AI use doesn't name the exact model, and `XCL_DIRECT_DXIL=none` isn't a real setting. Fine: it matches direct DXIL's `mimg_msaa` and the MS `get_resinfo`. It rejects the same ops. `msaa_load` reads 4 consecutive samples of one channel and zeroes those past the count (fragment = sample, no FMASK). The `GetDimensions` argument order for `Texture2DMS` / `Texture2DMSArray` and 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.
Foniass commented 2026-12-01 16:07:07 +00:00 (Migrated from github.com)

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


Test report (not a merge-check: PR description red)
base: b2b1f109d2
head: cd7e11585a
merge: 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.

<!-- greyfinch-sync:ivall/xcl:comment:7317064334 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3357#issuecomment-7317064334). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T16:07:07Z. --- Test report (not a merge-check: `PR description` red) base: b2b1f109d27e746a62ec95b04dd1f9924452e682 head: cd7e11585a0cfe387ed2f072609ffb24c753748e merge: 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.
bmjask commented 2026-12-02 01:44:26 +00:00 (Migrated from github.com)

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 3042

@@ -2998,19 +3023,62 @@ impl Em {
             4 => ("1DArray", format!("int2({}, {})", ic[0], ic[1]), format!("int3({}, {}, {mip})", ic[0], ic[1])),
             5 | 3 => ("2DArray", format!("int3({}, {}, {})", ic[0], ic[1], ic[2]), format!("int4({}, {}, {}, {mip})", ic[0], ic[1], ic[2])),
             6 => ("2DMS", format!("int2({}, {})", ic[0], ic[1]), String::new()),
+            7 => ("2DMSArray", format!("int3({}, {}, {})", ic[0], ic[1], ic[2]), String::new()),
             _ => return Err("MIMG dim"),
         };
         if dim == 3 && base.starts_with("load") {
             return Err("image_load cube");
         }
         self.line(&format!("uint {t}_cls = img_cls(({tw1} >> 20) & 0x1FFu);"));
+        if ms {
+            // Multisampled `image_load` / `image_msaa_load`: guard each sample load with
+            // `[branch] if (s < sample_count)` so out-of-range sample indices read 0 and
+            // `Load` stays in a separate block from `GetDimensions` (matching Direct DXIL).
+            let frag = ic[if dim == 7 { 3 } else { 2 }].clone();
+            let extra = if dim == 7 { format!("{t}_e, ") } else { String::new() };
+            self.line(&format!("uint4 {t}_r = uint4(0u, 0u, 0u, 0u);"));
+            let branch = |vt: &str, cast: &str| {
+                let decl = format!(
+                    "Texture{rty}<{vt}4> {t}_T = ResourceDescriptorHeap[NonUniformResourceIndex({tw0})]; uint {t}_w, {t}_h, {extra}{t}_sc; {t}_T.GetDimensions({t}_w, {t}_h, {extra}{t}_sc); uint {t}_f = {frag};"

The 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}_ok only checks TYPE >= 8. The DIM 7 case is new in this PR.

<!-- greyfinch-sync:ivall/xcl:review-comment:4763589388 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3357#discussion_r4763589388). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T01:44:26Z. **Code review location:** `crates/xcl/src/gpu/recomp/emit.rs`; line 3042 ~~~~diff @@ -2998,19 +3023,62 @@ impl Em { 4 => ("1DArray", format!("int2({}, {})", ic[0], ic[1]), format!("int3({}, {}, {mip})", ic[0], ic[1])), 5 | 3 => ("2DArray", format!("int3({}, {}, {})", ic[0], ic[1], ic[2]), format!("int4({}, {}, {}, {mip})", ic[0], ic[1], ic[2])), 6 => ("2DMS", format!("int2({}, {})", ic[0], ic[1]), String::new()), + 7 => ("2DMSArray", format!("int3({}, {}, {})", ic[0], ic[1], ic[2]), String::new()), _ => return Err("MIMG dim"), }; if dim == 3 && base.starts_with("load") { return Err("image_load cube"); } self.line(&format!("uint {t}_cls = img_cls(({tw1} >> 20) & 0x1FFu);")); + if ms { + // Multisampled `image_load` / `image_msaa_load`: guard each sample load with + // `[branch] if (s < sample_count)` so out-of-range sample indices read 0 and + // `Load` stays in a separate block from `GetDimensions` (matching Direct DXIL). + let frag = ic[if dim == 7 { 3 } else { 2 }].clone(); + let extra = if dim == 7 { format!("{t}_e, ") } else { String::new() }; + self.line(&format!("uint4 {t}_r = uint4(0u, 0u, 0u, 0u);")); + let branch = |vt: &str, cast: &str| { + let decl = format!( + "Texture{rty}<{vt}4> {t}_T = ResourceDescriptorHeap[NonUniformResourceIndex({tw0})]; uint {t}_w, {t}_h, {extra}{t}_sc; {t}_T.GetDimensions({t}_w, {t}_h, {extra}{t}_sc); uint {t}_f = {frag};" ~~~~ --- The 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}_ok` only checks TYPE >= 8. The DIM 7 case is new in this PR.
bmjask commented 2026-12-02 01:44:26 +00:00 (Migrated from github.com)

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 2959

@@ -2948,6 +2948,31 @@ impl Em {
             return Ok(());
         }
 
+        let ms = matches!(dim, 6 | 7);
+        if ms && !matches!(base, "load" | "msaa_load" | "get_resinfo") {
+            return Err("MIMG MSAA store / atomic / load_mip");
+        }
+        if base == "msaa_load" && !ms {
+            return Err("image_msaa_load on a single-sampled dim");
+        }
+
+        if base == "get_resinfo" && ms {

Not certain about this one: image_get_resinfo on 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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4763589396 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3357#discussion_r4763589396). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T01:44:26Z. **Code review location:** `crates/xcl/src/gpu/recomp/emit.rs`; line 2959 ~~~~diff @@ -2948,6 +2948,31 @@ impl Em { return Ok(()); } + let ms = matches!(dim, 6 | 7); + if ms && !matches!(base, "load" | "msaa_load" | "get_resinfo") { + return Err("MIMG MSAA store / atomic / load_mip"); + } + if base == "msaa_load" && !ms { + return Err("image_msaa_load on a single-sampled dim"); + } + + if base == "get_resinfo" && ms { ~~~~ --- Not certain about this one: `image_get_resinfo` on 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.
bmjask commented 2026-12-02 01:44:26 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:ivall/xcl:review:6143375369 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3357#pullrequestreview-6143375369). Originally posted by [bmjask](https://github.com/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._
Kalmarv commented 2026-12-02 19:39:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T19:39:23Z.


Closing: HLSL-only parity PR whose own XCL_DIRECT_DXIL=0 tests fail; direct DXIL is the active path.

<!-- greyfinch-sync:ivall/xcl:comment:7356516417 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3357#issuecomment-7356516417). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-12-02T19:39:23Z. --- Closing: HLSL-only parity PR whose own `XCL_DIRECT_DXIL=0` tests fail; direct DXIL is the active path.

Pull request closed

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!3357
No description provided.