Skip to content

Direct DXIL: MSAA loads clamp out-of-range sample indices before loading - #1908

Open
bmjask wants to merge 2 commits into
xcl-dev:mainfrom
bmjask:fix/msaa-sample-clamp-main
Open

bmjask wants to merge 2 commits into
xcl-dev:mainfrom
bmjask:fix/msaa-sample-clamp-main

Conversation

@bmjask

@bmjask bmjask commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #1679.

What is in it

  • Direct DXIL MSAA image loads now clamp an out-of-range sample index to sample 0 before the load. The result for such indices is still zeroed afterwards, so visible behavior for valid indices is unchanged, but the load itself never addresses a sample past the texture's count.
  • Based on main after dxil: emit MSAA textureLoad before getDimensions to avoid amdxc64 crash #1900 and keeps its ordering: the sample count (getDimensions) is read in its own block, and the clamped textureLoads start a new block, so no textureLoad follows getDimensions in one basic block. direct_msaa_loads_precede_get_dimensions still passes.
  • TRANSLATOR_VERSION 7 -> 8 so cached direct containers re-key.
  • Patch as suggested by @imnicho in the Direct DXIL: geometry mode, MSAA loads and directed f32 rounding #1679 review. Thanks!

Tested

  • RTX 4090, Windows 11, Rust stable
  • cargo test -p xcl --lib msaa -- --include-ignored: 6 passed, incl. gpu_direct_msaa_image_loads on the GPU and direct_msaa_loads_precede_get_dimensions
  • cargo test -p xcl --lib gpu::dxil: 101 passed, 0 failed, 3 ignored
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu::recomp: 261 passed, 0 failed, 18 ignored
  • cargo build --workspace and cargo test --workspace -- --test-threads=4: 0 failed (xcl lib: 927 passed, 25 ignored)

Regression run
scripts/smoke.ps1, 60 s, XCL_PRESS_AT=2:B,4:B,6:B,8:B XCL_PRESS_A_AT=10,15,20,25,30,40 (B presses at 2/4/6/8 s, A presses at 10/15/20/25/30/40 s), run back to back. main is a release build of origin/main (20cf130); PR is a release build of the head (215528e). Each block comes from its own checkout's scripts/smoke.ps1.

main:

xcl-smoke v1
commit: 20cf13022f764208384c610c2ae6a3f4eed201a2
gpu: NVIDIA GeForce RTX 4090
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1139 (PresentX 1139)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18898 MB

PR:

xcl-smoke v1
commit: 215528eefe24c75cd336197e909393749fc15220
gpu: NVIDIA GeForce RTX 4090
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1227 (PresentX 1228)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 18919 MB

Not tested

AI use

  • Claude Code (Claude Opus 5.5): applied the reviewer's patch on current main, ran tests and smoke, wrote this description

🤖 Generated with Claude Code

image_msaa_load / image_load on MSAA resources issued Texture2DMS.Load with
sample indices at or past the resource's count and only zeroed the result
afterwards. An out-of-range ld2dms index is undefined, and RDNA4 faults on it
(gpu_direct_msaa_image_loads, STATUS_ACCESS_VIOLATION on RX 9070 / 9070 XT).
The load now takes sample 0 for those lanes; the result mask is unchanged.
Patch as suggested by imnicho in review. TRANSLATOR_VERSION 7 -> 8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HKEY-Funk-Machine

Copy link
Copy Markdown

@bmjask @imnicho retested as asked: on the RX 9070, gpu_direct_msaa_image_loads still ends the process with 0xc0000005 on #1908 at b5cfa8c. It's the same as on 758e341, in debug and in release. I also split the test to find which instruction does it: every load from a multisampled texture crashes, including a plain IMAGE_LOAD with an in-range sample index. So the out-of-range clamp can't be the fix on this card.

The test's program reduced to one MIMG instruction at a time (local change only: S_ENDPGM after the one instruction, same T#s and VGPRs as the test):

# instruction result
0 IMAGE_LOAD 2D MSAA, DMASK 0xF (sample = fragment 0..3, count 4) 0xc0000005
1 IMAGE_MSAA_LOAD 2D MSAA 0xc0000005
2 IMAGE_GET_RESINFO 2D MSAA passes
3 IMAGE_LOAD 2D MSAA array, DMASK 0x1 (sample 0..1, count 2) 0xc0000005
4 IMAGE_MSAA_LOAD 2D MSAA array 0xc0000005
5 IMAGE_GET_RESINFO 2D MSAA array passes
6 IMAGE_MSAA_LOAD D16 0xc0000005

In every crashing case, translation and check() (validation) finish, and the access violation comes inside runner::run_with_statics, so at pipeline creation or dispatch. The size queries on the same two textures (same descriptors) run fine. So it looks like the direct path's Texture2DMS / Texture2DMSArray load itself (dx.op.textureLoad with a sample index) that the AMD driver doesn't take. It doesn't look like texture creation or binding. A compare that might help: the same multisampled load through the HLSL path on this card, to see whether DXC's form of Texture2DMS.Load differs from ours (the sample-index operand, or the offsets / unused coordinate). I haven't done that.

Tested

  • Clean PR head b5cfa8c (on main 689f2db). XCL_REQUIRE_GPU=1 cargo test -p xcl --lib gpu::dxil::msaa_tests -- --test-threads=1: direct_msaa_store_is_rejected ... ok, gpu_direct_msaa_image_loads exits 0xc0000005. Release, the test alone: same.
  • The per-instruction table: the same test with a local, uncommitted change that keeps only one MIMG instruction, debug.
  • AMD Radeon RX 9070 (RDNA4, native wave64), driver 32.0.32015.7029, Ryzen 9 7945HX3D, 32 GB, Windows 11 Pro 26300, Rust 1.100.0, DXC 1.9.2602.17.

Not tested: which module faults (no dump), pipeline creation vs dispatch, the HLSL-path compare above, other AMD generations.

AI use: Claude Code (Claude Opus 5.5) ran the tests, made the local bisect change and wrote this comment.

@imnicho

imnicho commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

@HKEY-Funk-Machine thank you for the retest and for splitting the program - that settles it. @bmjask the patch I suggested on #1679 does not fix the crash, and my heads-up there that main "will still crash" for want of it had the cause wrong. #1900 (merged at 23:08 UTC) has it: AMD's compiler fails when dx.op.getDimensions comes before dx.op.textureLoad on a dynamically indexed heap Texture2DMS in the same block, whatever the sample index.

Two consequences for this PR:

Not tested: anything on AMD (I have no such card); the "different blocks" form is taken from #1900's description, not run by me.

AI use: Claude Code with Claude Fable 5.2 read #1900 and this thread and wrote this comment.

@Melow-code Melow-code left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clamp-to-0 approach is reasonable, but the RX 9070 crash report from HKEY-Funk-Machine suggests the access violation is not caused by the sample index alone. Agree with imnicho that this should wait for #1900 and an RDNA4 investigation.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
@eizispark

eizispark commented Nov 24, 2026 •

Copy link
Copy Markdown

Hardware test report — commit 215528e

Re-verified 215528eefe24c75cd336197e909393749fc15220 (rebased onto main 20cf13022f764208384c610c2ae6a3f4eed201a2): pass — splitting dx.op.getDimensions into its own block before br(loads_block) avoids the amdxc64.dll 0xc0000005 crash on AMD RDNA4 while clamping out-of-range MSAA sample indices (gpu_direct_msaa_image_loads and direct_msaa_loads_precede_get_dimensions both pass).

Tested

  • Hardware: Windows 11 x64, AMD Ryzen 7 9800X3D, AMD Radeon RX 9070 XT (RDNA4, native wave32 + wave64, driver 32.0.32015.16001), 32 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09) (stable-x86_64-pc-windows-msvc), debug tests + release smoke
  • cargo test -p xcl --lib msaa -- --include-ignored --test-threads=1: 6 passed, 0 failed, 0 ignored (0 skipped: gpu::dxil::msaa_tests::gpu_direct_msaa_image_loads, direct_msaa_loads_precede_get_dimensions, msaa_texture_ops_run, render_target_sample_ops_validate, direct_msaa_store_is_rejected, and hle::d3d12x::vram::tests::reserved_needs_tiled_format_and_tiled_msaa)
  • Unfiltered cargo test --workspace --no-fail-fast -- --test-threads=4: 974 passed, 2 failed, 45 ignored (8 skipped), matching main 20cf130 (0 new failures; the 2 failures are the pre-existing #1679 AMD fuzz seeds gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 and fuzz_validate_and_gpu_3; 8 skipped = 6 lower_dxil f16/f32 #1426-semantics sub-cases, pso_measurement_compiles_an_exact_synthetic_record 0x887A002D, and heap_window_out_of_memory_falls_back_to_the_switch_form)
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu::recomp -- --test-threads=4: 261 passed, 0 failed, 18 ignored (6 skipped)

Regression run
main (20cf13022f764208384c610c2ae6a3f4eed201a2):

xcl-smoke v1
commit: 20cf13022f764208384c610c2ae6a3f4eed201a2
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1678 (PresentX 1678)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14859 MB

PR (215528eefe24c75cd336197e909393749fc15220):

xcl-smoke v1
commit: 215528eefe24c75cd336197e909393749fc15220
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1679 (PresentX 1679)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14858 MB

Not tested

  • retail run with XCL_SHADER_BACKEND=dxil / XCL_DIRECT_DXIL=1, NVIDIA/Intel GPUs, Wine/vkd3d-proton, gameplay past the menus

AI use

  • Antigravity (Google DeepMind, Gemini 4 Carbon) ran the MSAA tests, workspace test suite, and 60-second retail smoke pair and updated this report.

(Updated from earlier check on b5cfa8c)

@HKEY-Funk-Machine

Copy link
Copy Markdown

Update: on main 20cf130 (with #1900), msaa_tests passes on the RX 9070: 5 passed, 0 failed, including gpu_direct_msaa_image_loads (debug, XCL_REQUIRE_GPU=1 cargo test -p xcl --lib gpu::dxil::msaa_tests -- --test-threads=1). That fits #1900's root cause (getDimensions before textureLoad in one block), and the single-instruction loads above likely still emitted the sample-count query. So #1908's clamp isn't needed for the crash here.

AI use: Claude Code (Claude Opus 5.5) ran the test and wrote this comment.

Keeps xcl-dev#1900's ordering: the sample count is read in its own block and the
clamped loads start a new block, so no textureLoad follows getDimensions in
one basic block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@lewisnic94-max lewisnic94-max left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3, high confidence] A v8 cache from the previous PR head still returns its old MSAA bytecode.

I tested 215528eefe24c75cd336197e909393749fc15220 with XCL_DIRECT_DXIL=1. I seeded a dynamically indexed Texture2DMS shader on pre-#1900 commit 689f2db. In three independent upgrades, this head selected a new v8 entry. Its DXIL matched a fresh translation byte for byte. All three format branches placed the texture load in a separate block after the dimensions query.

There is one narrower case for PR testers. Earlier head b5cfa8c9944e2ff1650b0e708d4b7c4cefc21ec1 already wrote v8 entries. Across three upgrades from that head, the cached DXIL kept the old same-block order in all three branches. Fresh output had it in none. Please consider a new version for this revised emitter if caches from the earlier PR head are supported. A regression can seed that exact head and inspect the bytes returned by console_to_dxil_in(). Cache version

The targeted gpu::dxil::msaa_tests suite on this head reported 5 passed, 0 failed, 0 ignored and 0 skip notices. Windows 11 build 26200.9974, Ryzen 7 5800X, RTX 3080 driver 616.92, debug Rust 1.100.0 MSVC and DXC 1.9.2602.17. The upgrade test checked bytecode. AMD driver execution was outside this run.

Follow-up on main 8c4a46a. I applied this exact PR locally after #1898. In three upgrades per shader, v7 seeds returned fresh DXIL for both directed rounding and MSAA. With stale v8 seeds, the rounding shader still returned NaN and the MSAA shader kept the old instruction order. Adding #1947 at 1831ec4 to the same local build regenerated both shaders from v8 in all three trials per shader. Related source-hash change

Codex (GPT-6) assisted with the synthetic cache tests, disassembly checks and analysis.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
Pulls in xcl-dev#1836 (graphics and two-pass PSO disk cache + lazy MS/GS + shader build coalescing), xcl-dev#1930 (DXIL CSE across discard), xcl-dev#1900, xcl-dev#1005, xcl-dev#1053, xcl-dev#1864, xcl-dev#1866, xcl-dev#1869, xcl-dev#1876, and xcl-dev#1898 while keeping our RDNA4 MSAA clamp (xcl-dev#1908), wave64 graphics Direct DXIL guard (xcl-dev#1913), atomic writable-range tracking, static-sampler cache keys, and 4M-group indirect dispatch clamp.
@raylitebull

Copy link
Copy Markdown
Member

Status check: #1900 (20cf130) already landed the MSAA textureLoad-before-getDimensions ordering fix, #1950 took TRANSLATOR_VERSION = 8, and #1947 now hashes gpu/dxil sources automatically. There is also an open [P3] review note from @lewisnic94-max on cache key safety.

Please let us know whether this PR can be closed as superseded by #1900, or rebased (without the kernel.rs version bump) if there are still separate blocks you want hardened.

@JJAutoCompare

Copy link
Copy Markdown

Empirical test report — PR #1908 (215528eefe24c75cd336197e909393749fc15220)

  • PR head commit: 215528eefe24c75cd336197e909393749fc15220 (refs/pull/1908/head)
  • origin/main commit: 5796cc467d80e3dac5d7d231ec34f1b0bebce169
  • Merge check (git merge-tree --write-tree origin/main HEAD): clean (exit 0, tree d39b01dfdf46a7ee75a82572dd7e3f94d1dd545b)
  • Diff scope (origin/main...HEAD): crates/xcl/src/gpu/dxil/kernel.rs (+1/-1), crates/xcl/src/gpu/dxil/lower_image.rs (+15/-7)

Tested

  • Hardware & OS: Intel Arc A770 Graphics (16258 MiB VRAM, driver 32.0.101.9175, XCL_ADAPTER=A770, wave32 / 8–32 lanes), AMD Ryzen 7 3800X (6 cores / 12 logical processors), Windows 11 Enterprise Evaluation 10.0.26200 (build 26200)
  • Toolchain & profile: rustc 1.100.0 (0ef1bc386 2026-11-09), cargo 1.100.0 (3acc79c0c 2026-11-05), debug (dev/test) profile, DXC 1.9.2609.5 (01b62ad4) (dxcompiler.dll + dxil.dll)
  • Build: cargo test --workspace --no-run and cargo build --workspace both exited 0.
  • Targeted MSAA / Direct DXIL tests:
    • cargo test -p xcl --lib gpu::dxil::msaa_tests -- --test-threads=4 --show-output: 5 passed, 0 failed, 0 ignored, 0 skipped (all 5 ran on the Arc A770 / validator):
      • gpu::dxil::msaa_tests::direct_msaa_loads_precede_get_dimensions (ok)
      • gpu::dxil::msaa_tests::direct_msaa_store_is_rejected (ok)
      • gpu::dxil::msaa_tests::gpu_direct_msaa_image_loads (ok)
      • gpu::dxil::msaa_tests::msaa_texture_ops_run (ok)
      • gpu::dxil::msaa_tests::render_target_sample_ops_validate (ok)
  • Full workspace suite:
    • cargo test --workspace -- --test-threads=4 --show-output: stopped after xcl --lib (903 passed, 24 failed, 25 ignored, 22 SKIPPED lines)
    • cargo test --workspace --no-fail-fast -- --test-threads=4 --show-output: 951 passed, 25 failed, 45 ignored across all 20 workspace test targets (exit 101):
      • xcl (--lib): 903 passed, 24 failed, 25 ignored
      • tests/e2e.rs: 2 passed, 1 failed, 0 ignored
      • Remaining 18 test targets (src/main.rs, bcpack_parity, console_dlls_e2e, console_shaders, disasm_e2e, gpu_compute_e2e, gpu_pso_e2e, heap_probe, low_va, pls_quota, predication_e2e, rpf_e2e, shaders_e2e, sparse_reinit, texture_states, xg_oracle, xcl-testtitle, doc-tests): 46 passed, 0 failed, 20 ignored
    • Failures (25 total, all Arc A770 / host-specific, none in MSAA):
      • 20× CreateComputePipelineState: The parameter is incorrect. (0x80070057) on Arc A770 (no native FP64 / rejected shader ops): gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_{0,1,2,3}, gpu::dxil::ops_tests::{doubles_match_cpu,groupshared_barrier_and_atomics_run}, gpu::dxil::round_tests::{gpu_direct_f32_round_modes_dynamic_and_denormals,gpu_direct_f32_round_modes_static}, gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu, gpu::recomp::tests::{gpu_clamp_and_omod_per_instruction,gpu_f64_class_compare,gpu_f64_compares_with_nan,gpu_f64_literal_high_word,gpu_f64_math_random,gpu_f64_roots,gpu_f64_rounding_and_conversions,gpu_float_compares_random,gpu_frexp_f64_exp_and_mant,gpu_ldexp_f64,gpu_rndne_f64}
      • 4× Arc A770 shader/driver value differences: gpu::recomp::tests::gpu_nonfused_mad_and_mac_prevent_fma_contraction, gpu::recomp::tests::gpu_ps_image_sample_offset_implicit_lod_between_mips, gpu::recomp::tests::gpu_valu_16_and_64_bit, gpu::recomp::tests::gpu_wave64_ps_whole_wave_reductions
      • 1× tests/e2e.rs (test_title_runs_and_game_folder_is_untouched): D3D12.X: dynamic depth bias via RSSetDepthBiasX (#94) (top-right [0, 0, 255, 255], expected green)
  • SKIPPED GPU tests (25 SKIPPED lines across 15 distinct tests — reported ok by Cargo, not counted as coverage):
    • no wave64 (18 lines across 10 tests): gpu::recomp::lower::tests::{a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu,coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu,cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu,the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu}, gpu::recomp::lower_dxil::tests::{a_per_lane_2d_or_3d_group_runs_on_the_gpu,f16_programs_on_the_gpu (2),f32_programs_on_the_gpu (6),integer_programs_on_the_gpu (2)}, gpu::recomp::tests::{gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware}
    • wave32, per-lane form: refused (#1426 semantics, 3 sub-cases inside 2 tests above): gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu (V_MUL_F16, V_PK_MUL_F16: VOP3 modifiers), gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (V_CVT_F16_F32)
    • Host / adapter feature skips (5 tests):
      • shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable driver cache (Windows Developer Mode required, 0x887A002D)
      • placed_title_textures_share_vram_and_preserve_pixels: tiled tier < 2
      • test_title_draws_with_a_root_signature_under_the_debug_layer: no d3d12SDKLayers.dll
      • heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows
      • uploads_start_from_each_subresources_state: no D3D12 debug layer (0x887A002D)

Not tested

  • AMD GPUs (in particular RDNA4 out-of-range ld2dms fault behavior and amdxc64.dll basic-block compilation) and NVIDIA GPUs
  • Native wave64 hardware (all wave64-only GPU test cases skipped on Arc A770)
  • Retail title / scripts/smoke.ps1 regression run (no retail game package on this test host)
  • D3D12 debug-layer, Windows Developer Mode driver-cache, tiled tier 2, and heap-window test paths (skipped on this host)
  • Release build profile

AI use

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@lewisnic94-max

Copy link
Copy Markdown

@raylitebull, I’m withdrawing my P3 cache objection for a rebase onto current main. It reproduced on the standalone 215528e head because the earlier preview and revised emitter both used v8. After #1947 merged, all 12 populated-cache upgrades on b8428c5 returned DXIL byte-for-byte identical to fresh translation. We tested v7 and v8 seeds with both the rounding and MSAA shaders, three runs per combination.

On main cbc296a, applying only the MSAA emitter change altered the direct source fingerprint with TRANSLATOR_VERSION held at 9. I’d drop the kernel.rs bump on rebase.

#1900 addressed the reported RDNA4 instruction-ordering crash. The remaining hardening is a separate decision. Main zeroes the result after the load. #1908 also redirects an out-of-range sample index to 0 before loading, while keeping getDimensions and textureLoad in separate blocks.

OpenAI Codex (GPT-6) assisted with the cache tests, source comparison and this reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants