Recompiler: keep the raw-load shader flag guard in the DCE after block merging #3664
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3664"
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 Prime1997 on 2026-12-02T05:54:00Z.
Requested by Prime
#3503 made the optimizer's dead-code elimination keep one raw buffer load when every raw load in a shader is dead. The RawAndStructuredBuffers shader flag is set while the module is built, so a shader that loses all its raw loads no longer matches its flags. But
Module::optimizeruns a second DCE aftersimplify_cfgmerges blocks, and that one had no such guard: it dropped the very load the first DCE had kept. Both DCEs now go through oneModule::eliminate_dead, which applies the guard, so the load survives block merging too.Related: #3503 added the guard to the first DCE; this adds it to the second. #3646 (open) also changes
Module::optimizeinopt.rsfor speed; the two may conflict in text, not in behaviour.What is in it
crates/xcl/src/gpu/dxil/module/opt.rs: the two DCE loops inModule::optimizebecome oneModule::eliminate_dead, with the raw-load guard in both; a switch for the second one; a unit test that a dead raw load survives the DCE after block merging.crates/xcl/src/gpu/recomp/pso.rs,crates/xcl/src/shaders.rs: the new switch bypasses the translated shader caches and is part of the warm pipeline settings key, likeXCL_DXIL_NO_OPT.Tested
1c8b5514):cargo check -p xcl --lib --tests --target x86_64-pc-windows-gnupasses. The test suite was not run on this exact branch.Regression run
Not tested
scripts/smoke.ps1on this branch; AMD.a_dead_raw_buffer_load_survives_the_dce_after_block_mergingwas not run on this branch.Switches
XCL_DXIL_MERGE_DCE_RAW_GUARD(default on):=0leaves the guard out of the DCE after block merging, as before this change. While it is set (to any value), the shader caches are bypassed, as withXCL_DXIL_NO_OPT.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T09:13:32Z.
Review (head
cc6b6d1a, diff read, not a merge-check; checks red):PR checksreports that Regression run has noxcl-smokeblock made on headcc6b6d1a90and none made on a commit of main. The description also says the suite and the new test were not run on this branch, and the only test listed iscargo checkwithx86_64-pc-windows-gnu. CONTRIBUTING requires the whole suite on a GPU with counts.Build and test (Windows, no GPU)is red too, but it looks unrelated: the lib test process aborts (exit code 130088963) right afterhle::d3d12x::uma_driverlogs "coherent window could not be restored". The new test shows... okin that log. A rerun should tell.XCL_DXIL_MERGE_DCE_RAW_GUARD=0(opt.rs ~1937) restores the old behaviour, which drops the raw load the first DCE kept. That switch is the only reason for thepso.rs ~1183andshaders.rs ~36changes, and for the textual conflict with #3669 inshaders.rs. Any value disables the shader caches, including=1, which is the same as the default. CONTRIBUTING puts env-var switches in their own PR. Without the switch this is a ~90-line change toopt.rsalone.simplify_cfgtreats everyrawBufferLoadas removable and has no guard. It drops the load (and its handle chain) that #3503's guard kept, and the next iteration finds no raw load left to keep.flaggedclosure toSCALAR_HEAP_PAIR | SCALAR_HEAP_QUAD | RAW_HEAP_QUAD. Whichever PR lands second has to move that predicate intoeliminate_dead(opt.rs ~1517). If it doesn't, the outlined helpers lose the guard in one of the two DCEs.Fine: by reading,
eliminate_deadkeeps main's behaviour for both DCE passes: the same roots,keep_allstands in forskip("dce"), the second pass has the same!removableroots, andliveis now sized for each call. The new test fails on main formerge=true(the second DCE drops both the raw load and itsdx.op.unaryoperand) and passes with the fix. No cache version bump is needed:module/opt.rsis undersrc/gpu/dxil, whichXCL_DIRECT_DXIL_SOURCE_IDhashes (build.rs ~141).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-02T11:33:33Z.
Test report (not a merge-check:
PR descriptionred)base:
1c8b551475head:
cc6b6d1a90merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2910 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 by one reviewer at this same head; the review is at https://github.com/xcl-dev/xcl/pull/3664#issuecomment-7340565755 and its findings stand. Most serious: the fix is correct by reading; the description lacks the suite run and smoke blocks.
performance: 60 s smoke of a retail title, main
1c8b5514vs this merge (cc6b6d1a): 1652 -> 1693 frames shown (102 %; last presents per 2 s: 61 60 60), peak commit 18228 -> 18028 MB, 0 device removals, 0 crashes.assessment: merges, builds and passes the whole suite on current main, and the smoke run is clean; the review found no blocking problem, and the description still needs its suite counts and smoke blocks
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 Edgaras0404 on 2026-12-02T16:01:58Z.
test report (not a merge-check; requested AMD test of #3664)
base:
df0cfef638head:
cc6b6d1a90merge: clean
build: cargo build --workspace -> ok; cargo build --release -p xcl -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> the
-p xcl --libbinary aborted at exit 0x80004005 with notest result:line: 1383 ok, 4 failed, 25 ignored observed of 2,795 lib tests (the rest did not run); the 43 non-lib result lines: 147 passed, 2 failed, 20 ignored. SKIPPED 2 among the tests that ran, bothno heap windows(hle::d3d12x::bind::tests::two_pass_binds_set_the_shared_view_heap,heap_window_out_of_memory_falls_back_to_the_switch_form). Failing:gpu::dxil::compact_tests::gpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_form(compact_tests.rs:184,left (50, 0, 1, 5)vsright (50, 10045, 1, 5)),gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu,gpu::recomp::tests::gpu_f32_compares_with_nan,gpu::recomp::tests::gpu_float_compares_random(all three fail in the base lib run too), andgpu_two_pass_cache_e2e::two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs(merge full run: child atgpu_two_pass_cache_e2e.rs:472, parent at:584; base alone fails at:584,left: 1, right: 0). The base lib run has the same abort (exit 0x80004005; 1382 ok, 4 failed, 25 ignored) and the same four failures, so the PR adds no failure; its new testgpu::dxil::module::opt::tests::a_dead_raw_buffer_load_survives_the_dce_after_block_mergingpasses. WithXCL_DXIL_MERGE_DCE_RAW_GUARD=0that test fails formerge=true(left: 0, right: 1), so it covers the fix.review: most serious first: (1) the code fix is correct by reading: both DCEs now call
Module::eliminate_dead; the second gets the same raw-load guard,orderis refreshed aftersimplify_cfg(opt.rs:1455),repl2is sized for the whole instruction list, and the first call keeps theskip("dce")/keep-all behaviour. The new test passes with the guard on and fails with it off, so it is a real regression test. (2)XCL_DXIL_MERGE_DCE_RAW_GUARDis scope for its own PR:=0only restores the bug, while any value (including=1) bypasses the translated shader caches and changes the warm-pipeline settings key, and CONTRIBUTING asks for env switches separately; the fix itself is a ~90-lineopt.rschange. (3) overlap, not duplicate: #3654 changes the sameflaggedpredicate inopt.rs(the earlier review says it widens it to the scalar-heap pairs/quads), and #3646 also editsModule::optimize; whichever lands second needs the predicate moved intoeliminate_dead. #3503 is the merged predecessor that added the first guard. No duplicate found in open/merged PRs or #1607. (4) the description has no suite counts and noxcl-smokeblocks, soPR descriptionis red;Build and testis red; the linked review reports the new test logsokin that run, so it is not the new test.performance: 60 s retail smoke: base
df0cfef61619 frames / 16,223 MB peak, merge15614e381618 / 17,816 (99.9% frames, 109.8% peak; thresholds 80%/125%), 0 device removals and 0 crashes on both, exit 0x0 both; presents per 2 s last 3: base 60 60 61, merge 61 60 60.verdict: not yet: the
PR descriptioncheck is red (no suite counts orxcl-smokeblock) and the new switch is scope for its own PR; the code, tests and manual 60 s smoke are clean on AMD, so those are the only blockers.hardware / tool and model: AMD Radeon RX 6700 XT 12 GB (RDNA2), driver 32.0.21045.29003; AMD Ryzen 5 5600X; Windows 10 build 19045 / OpenCode, DeepSeek V4.1 Flash 1017
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T20:05:12Z.
Review: COMMENTED
Review of
cc6b6d1a: 1 finding(s) (1 medium), most severe first.crates/xcl/src/gpu/dxil/module/opt.rs:1392: see below.On lines outside the diff:
crates/xcl/src/gpu/dxil/module/opt.rs:1392: The raw-load guard only sees blocks that are still reachable wheneliminate_deadruns, but constant branch folding (and the unreachable-block sweep at line 1153) empties blocks withself.blocks[b].clear()before any DCE, so raw loads that existed only in a folded-away branch are dropped with no guard. Take a shader whose only raw-buffer access is arawBufferLoadinsideif (CONST_FALSE): the CondBr folds to Br, the block becomes unreachable and is cleared,eliminate_deadfinds no reachable rawBufferLoad, and the emitted DXIL still declares RawAndStructuredBuffers with no raw load left, the mismatch this PR is meant to prevent. Working out the flag from the final optimized code (on the writer side) instead of protecting loads in each DCE would cover every path.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 Foniass on 2026-12-03T14:50:20Z.
merge-check
base:
16c2fd082ahead:
cc6b6d1a90merge: clean
build: ok
tests: 3013 passed, 0 failed, 56 ignored; 28 skipped, the same as on main
review: 4 medium, 1 nit (below)
performance: 60 s smoke run: 1683 → 1659 frames (98 % of main), peak commit 18505 → 17233 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 226 s there, 0 device removals, 0 crashes, 3.4 presents/s; run with
XCL_SKIP_CS=95cc13288a27a96e(the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590)verdict: not yet:
PR descriptionis red; otherwise no blocking finding, the suite passes and the smoke run is cleanhardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
In short: Both DCE passes in Module::optimize now go through one eliminate_dead, so the raw-load guard from #3503 also runs after simplify_cfg merges blocks; a switch turns that off. The head has not changed since my earlier review: the fix is correct by reading, and the new test fails without the guard (an AMD tester confirmed it with the switch at 0). Nothing in the code blocks it; the switch belongs in another PR.
Medium
Nit
Checked and fine
How this was tested
16c2fd08, thencargo build --workspaceandcargo test --workspace --no-fail-fast -- --test-threads=4.scripts/smoke.ps1: 60 s of a retail title on main16c2fd08and on this merge; presents per 2 s at the end: 60 60 60.XCL_RUN_SECONDS=300and scripted A presses counted from the first frame (XCL_PRESS_BASE=frame, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.