Direct DXIL: MSAA loads clamp out-of-range sample indices before loading #1898
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1908"
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 bmjask on 2026-11-24T22:59:52Z.
Follow-up to #1679.
What is in it
getDimensions) is read in its own block, and the clampedtextureLoads start a new block, so notextureLoadfollowsgetDimensionsin one basic block.direct_msaa_loads_precede_get_dimensionsstill passes. -TRANSLATOR_VERSION7 -> 8 so cached direct containers re-key. - Patch as suggested by @imnicho in the #1679 review. Thanks!Tested
cargo test -p xcl --lib msaa -- --include-ignored: 6 passed, incl.gpu_direct_msaa_image_loadson the GPU anddirect_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 --workspaceandcargo test --workspace -- --test-threads=4: 0 failed (xcl lib: 927 passed, 25 ignored)Regression run
scripts/smoke.ps1, 60 s, release builds, run back to back withXCL_PREPARE=0against the same unstaged hard-link/junction view of the title (the original game folder was not modified). Input schedule:XCL_PRESS_AT=2:B,4:B,6:B,8:BandXCL_PRESS_A_AT=10,15,20,25,30,40.main:
PR:
Not tested
AI use
Imported from ivall/xcl. Originally posted by Melow-code on 2026-11-24T23:10:10Z.
Review: COMMENTED
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.
Imported from ivall/xcl. Originally posted by HKEY-Funk-Machine on 2026-11-24T23:09:32Z.
@bmjask @imnicho retested as asked: on the RX 9070,
gpu_direct_msaa_image_loadsstill ends the process with0xc0000005on #1908 atb5cfa8c. It's the same as on758e341, 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 plainIMAGE_LOADwith 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_ENDPGMafter the one instruction, same T#s and VGPRs as the test):IMAGE_LOAD2D MSAA, DMASK 0xF (sample = fragment 0..3, count 4)0xc0000005IMAGE_MSAA_LOAD2D MSAA0xc0000005IMAGE_GET_RESINFO2D MSAAIMAGE_LOAD2D MSAA array, DMASK 0x1 (sample 0..1, count 2)0xc0000005IMAGE_MSAA_LOAD2D MSAA array0xc0000005IMAGE_GET_RESINFO2D MSAA arrayIMAGE_MSAA_LOADD160xc0000005In every crashing case, translation and
check()(validation) finish, and the access violation comes insiderunner::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'sTexture2DMS/Texture2DMSArrayload itself (dx.op.textureLoadwith 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 ofTexture2DMS.Loaddiffers from ours (the sample-index operand, or the offsets / unused coordinate). I haven't done that.Tested
b5cfa8c(onmain689f2db).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_loadsexits0xc0000005. Release, the test alone: same.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.
Imported from ivall/xcl. Originally posted by imnicho on 2026-11-24T23:09:53Z.
@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 whendx.op.getDimensionscomes beforedx.op.textureLoadon a dynamically indexed heapTexture2DMSin the same block, whatever the sample index.Two consequences for this PR:
mimg_msaa, and the two changes pull in opposite directions: the clamp needs the sample count before the load, which is exactly thegetDimensionsin front oftextureLoadthat #1900 moved away. A plain rebase that keeps the clamp would bring the access violation back on the RDNA4 cards (the newdirect_msaa_loads_precede_get_dimensionstest onmainshould catch that).mainafter #1900 on the RX 9070 XT). If you still want it, the count would have to come from a block before the one with the loads (#1900 lists "different blocks" as not crashing). Otherwise I would close this one; sorry for the detour.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.
Imported from ivall/xcl. Originally posted by HKEY-Funk-Machine on 2026-11-24T23:10:41Z.
Update: on
main20cf130(with #1900),msaa_testspasses on the RX 9070: 5 passed, 0 failed, includinggpu_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 (getDimensionsbeforetextureLoadin 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.
Imported from ivall/xcl. Originally posted by eizispark on 2026-11-24T23:10:32Z.
Hardware test report — commit
215528eRe-verified
215528eefe24c75cd336197e909393749fc15220(rebased ontomain20cf13022f764208384c610c2ae6a3f4eed201a2): pass — splittingdx.op.getDimensionsinto its own block beforebr(loads_block)avoids theamdxc64.dll0xc0000005crash on AMD RDNA4 while clamping out-of-range MSAA sample indices (gpu_direct_msaa_image_loadsanddirect_msaa_loads_precede_get_dimensionsboth pass).Tested
32.0.32015.16001), 32 GB RAM,rustc 1.100.0 (0ef1bc386 2026-11-09)(stable-x86_64-pc-windows-msvc), debug tests + release smokecargo 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, andhle::d3d12x::vram::tests::reserved_needs_tiled_format_and_tiled_msaa)cargo test --workspace --no-fail-fast -- --test-threads=4:974 passed, 2 failed, 45 ignored(8 skipped), matchingmain20cf130(0new failures; the 2 failures are the pre-existing#1679AMD fuzz seedsgpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1andfuzz_validate_and_gpu_3;8 skipped= 6lower_dxilf16/f32#1426-semantics sub-cases,pso_measurement_compiles_an_exact_synthetic_record0x887A002D, andheap_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):PR (
215528eefe24c75cd336197e909393749fc15220):Not tested
XCL_SHADER_BACKEND=dxil/XCL_DIRECT_DXIL=1, NVIDIA/Intel GPUs, Wine/vkd3d-proton, gameplay past the menusAI use
(Updated from earlier check on
b5cfa8c)Imported from ivall/xcl. Originally posted by lewisnic94-max on 2026-11-25T00:18:42Z.
Review: COMMENTED
[P3, high confidence] A v8 cache from the previous PR head still returns its old MSAA bytecode.
I tested
215528eefe24c75cd336197e909393749fc15220withXCL_DIRECT_DXIL=1. I seeded a dynamically indexedTexture2DMSshader on pre-#1900 commit689f2db. 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
b5cfa8c9944e2ff1650b0e708d4b7c4cefc21ec1already 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 byconsole_to_dxil_in(). Cache versionThe targeted
gpu::dxil::msaa_testssuite 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 at1831ec4to the same local build regenerated both shaders from v8 in all three trials per shader. Related source-hash changeCodex (GPT-6) assisted with the synthetic cache tests, disassembly checks and analysis.
Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T01:08:10Z.
Status check:
#1900(20cf130) already landed the MSAAtextureLoad-before-getDimensionsordering fix,#1950tookTRANSLATOR_VERSION = 8, and#1947now hashesgpu/dxilsources 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 thekernel.rsversion bump) if there are still separate blocks you want hardened.Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-25T01:22:26Z.
Empirical test report — PR #1908 (
215528eefe24c75cd336197e909393749fc15220)215528eefe24c75cd336197e909393749fc15220(refs/pull/1908/head)origin/maincommit:5796cc467d80e3dac5d7d231ec34f1b0bebce169git merge-tree --write-tree origin/main HEAD): clean (exit0, treed39b01dfdf46a7ee75a82572dd7e3f94d1dd545b)origin/main...HEAD):crates/xcl/src/gpu/dxil/kernel.rs(+1/-1),crates/xcl/src/gpu/dxil/lower_image.rs(+15/-7)Tested
16258 MiBVRAM, driver32.0.101.9175,XCL_ADAPTER=A770, wave32 / 8–32 lanes), AMD Ryzen 7 3800X (6 cores / 12 logical processors), Windows 11 Enterprise Evaluation10.0.26200(build26200)rustc 1.100.0 (0ef1bc386 2026-11-09),cargo 1.100.0 (3acc79c0c 2026-11-05), debug (dev/test) profile, DXC1.9.2609.5 (01b62ad4)(dxcompiler.dll+dxil.dll)cargo test --workspace --no-runandcargo build --workspaceboth exited0.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)cargo test --workspace -- --test-threads=4 --show-output: stopped afterxcl --lib(903 passed, 24 failed, 25 ignored, 22SKIPPEDlines)cargo test --workspace --no-fail-fast -- --test-threads=4 --show-output: 951 passed, 25 failed, 45 ignored across all 20 workspace test targets (exit101):xcl(--lib): 903 passed, 24 failed, 25 ignoredtests/e2e.rs: 2 passed, 1 failed, 0 ignoredsrc/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 ignoredCreateComputePipelineState: 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}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_reductionstests/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)SKIPPEDGPU tests (25SKIPPEDlines across 15 distinct tests — reportedokby 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(#1426semantics, 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)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 < 2test_title_draws_with_a_root_signature_under_the_debug_layer:no d3d12SDKLayers.dllheap_window_out_of_memory_falls_back_to_the_switch_form:no heap windowsuploads_start_from_each_subresources_state:no D3D12 debug layer (0x887A002D)Not tested
ld2dmsfault behavior andamdxc64.dllbasic-block compilation) and NVIDIA GPUsscripts/smoke.ps1regression run (no retail game package on this test host)AI use
T3 Code / Antigravity (gemini-4-neon)checked out PR #1908, built the workspace, ran the targeted and full-workspace test suites on the Intel Arc A770 host above, parsed the logs, and posted this test report.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T02:16:00Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
Imported from ivall/xcl. Originally posted by lewisnic94-max on 2026-11-25T02:27:19Z.
@raylitebull, I’m withdrawing my P3 cache objection for a rebase onto current main. It reproduced on the standalone
215528ehead because the earlier preview and revised emitter both used v8. After #1947 merged, all 12 populated-cache upgrades onb8428c5returned 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 withTRANSLATOR_VERSIONheld at 9. I’d drop thekernel.rsbump 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
getDimensionsandtextureLoadin separate blocks.OpenAI Codex (GPT-6) assisted with the cache tests, source comparison and this reply.