Recompiler: read the whole per-lane S# in collapsed sampler waterfalls #3663
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3663"
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:53:55Z.
Requested by Prime
#3500 collapses a sampler (S#) waterfall loop into one pass where each lane reads its own sampler from v[vb..vb+3]. It removes the four
v_readfirstlanewrites to s[sb..sb+3] and points the MIMG at v[vb+3] for S# word 3 only. The emulated explicit-LOD gather (image_gather4_l*,mimg_gather4_lod) also reads S# words 0-2 (address modes, FORCE_UNORMALIZED, LOD bias, min/max LOD, mip filter), and it still took them from s[sb..sb+2]. After the collapse nothing writes those SGPRs, so each lane got stale or unrelated values. This change makes every S# word read of a MIMG in a collapsed waterfall come from the lane's own v[vb+k].Related: #3643 also changes
waterfall::collapseand thecompact.rsblock key for collapsed waterfalls; whichever lands second needs a rebase, and its 4-dword collapse should then record the S# base. #3621 keys translations onXCL_WATERFALL_COLLAPSE; the newXCL_WATERFALL_LANE_SWORDSwould need the same tag. #3298 adds an explicit-LOD comparison sample that reads S# words 0-2; if both land, those reads should go throughmimg_swordtoo.What is in it
crates/xcl/src/gpu/dxil/waterfall.rs:collapsenow maps each MIMG to the S# base v[vb] instead of v[vb+3]. WithXCL_WATERFALL_LANE_SWORDS=0, a loop whose body has animage_gather4*is not collapsed. Two tests: the gather4 loop collapses only with per-lane S# words, and a collapsedimage_gather4_ltranslates the same whichever (dead) SGPRs the waterfall used.crates/xcl/src/gpu/dxil/lower_image.rs:mimg_sword(pc, ssamp, k)reads S# word k from v[vb+k] for a collapsed waterfall and from s[ssamp+k] otherwise.mimg_s3andmimg_gather4_loduse it.crates/xcl/src/gpu/dxil/compact.rs: the block key includes the S# base, since the MIMG's words do not name it. Two collapsed waterfalls over different VGPRs could otherwise share one lowering.crates/xcl/src/gpu/dxil/lower.rs: doc comment onwaterfall_ssamp.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.Switches
XCL_WATERFALL_LANE_SWORDS, default on.=0leaves sampler waterfalls whose body has animage_gather4*uncollapsed (the loop runs as on the console).XCL_WATERFALL_COLLAPSE=0still collapses none. LikeXCL_WATERFALL_COLLAPSEon main, it is not part of the translation cache key, so clear the cache when changing it.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T08:45:55Z.
Review (head
0324e7ce, diff read, not a merge-check; checks red):Build and test (Windows, no GPU)on this head: 2762 passed, 1 failed, 31 ignored. The failure iswaterfall::tests::collapsed_gather4_l_reads_no_stale_s_sharp_sgprsatcrates/xcl/src/gpu/dxil/waterfall.rs ~573. The waterfall is collapsed in the dumped DXIL (one pass, no loop), but the test usestranslate_compute, and the compute prologue emits its ownwaveReadLaneFirstfor the wave slot (%14in the CI dump). The "should be collapsed" assert can never pass on a compute entry. Check for the collapse some other way (the waterfall'swaveActiveBallot/back edge, orkernel::translateas the existing test does). The description says onlycargo checkran, which is consistent with this.assert_eq!(da, db)comparison (S# at s[8..11] vs s[12..15], same v[40..43]) is the part that would fail on main: by reading, main'smimg_gather4_lodloads user SGPRs s8..s10 vs s12..s14. It sits after the broken assert, so as written the test fails the same way with and without the fix.gather4_waterfall_collapses_only_with_lane_s_wordsonly checks the new map convention (vb instead of vb+3) and the new switch, not what the lowering reads.xcl-smokeblock for head0324e7ceand none for a commit of main. This is a runtime change (crates/xcl/src/gpu/dxil).waterfall::collapseastry_collapse_4dword_samplerand keepsmimg_pcs.push((d.pc, vb + 3)), so this bug stays there. It also adds the samecompact.rskey line (waterfall_ssamp ... v + 1). If #3643 lands first, this PR becomes about 3 lines on top of it: the map value becomesvb,mimg_sword, and dropping the duplicate key line. If this one lands first, #3643 has to changevb + 3tovband its test'sSome(&88)when it rebases. Either way, only one of the two should carry the compact key.XCL_WATERFALL_LANE_SWORDSis an extra switch that is not in the cache key. Its=0setting only gives back the loop for gathers. CONTRIBUTING asks for env switches in their own PR, and toggling it reuses cached translations, which the description itself says. Consider dropping it from this fix.Fine: by reading, the fix is right. Main maps a collapsed MIMG to v[vb+3] for word 3 only, while
mimg_gather4_lod(lower_image.rs ~521) took words 0-2 (address modes, FORCE_UNORMALIZED, LOD bias, min/max LOD, mip filter) from s[sb..sb+2]. Nothing writes those after the collapse.collapsealready enforces contiguous v[vb+k] -> s[sb+k] with sb % 4 == 0, so v[vb..vb+3] is the lane's whole S# in order.mimg_gather4_lodis the only lowering that reads words 0-2. Adding vb to thecompact.rsblock key also closes a sharing hole that already exists on main for word 3.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-02T09:38:40Z.
Test report (not a merge-check:
PR descriptionred)base:
1c8b551475head:
0324e7ced7merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2910 passed, 1 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: gpu::dxil::waterfall::tests::collapsed_gather4_l_reads_no_stale_s_sharp_sgprs
review: read by one reviewer at this same head; the review is at https://github.com/xcl-dev/xcl/pull/3663#issuecomment-7339896237 and its findings stand. Most serious: its own new test fails, so the real check in it never runs.
performance: 60 s smoke of a retail title, main
1c8b5514vs this merge (0324e7ce): 1652 -> 1685 frames shown (101 %; last presents per 2 s: 60 60 60), peak commit 18228 -> 17102 MB, 0 device removals, 0 crashes.assessment: its own new test fails here too:
gpu::dxil::waterfall::tests::collapsed_gather4_l_reads_no_stale_s_sharp_sgprspanics atwaterfall.rs~573, "the waterfall should be collapsed" (the emitted DXIL keeps the loop), the same failure as in CI, so the stale-S# check the test is meant to make never runs. The rest of 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
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Edgaras0404 on 2026-12-02T12:51:16Z.
test report (not a merge-check; requested AMD test of #3663)
base:
df0cfef638head:
0324e7ced7merge: 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, 5 failed, 25 ignored observed of 2,796 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); the lib aborted before later modules. Failing: (1)gpu::dxil::waterfall::tests::collapsed_gather4_l_reads_no_stale_s_sharp_sgprs(new in the PR;waterfall.rs:573, compute prologue%14 = waveReadLaneFirst; base has no such test); (2)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); fails on base too, alone and in the base lib run); (3)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); (4)gpu_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), so the PR adds only the waterfall failure among the tests that ran; the compact-form and f32 failures are wave64 paths the NVIDIA report skips (20no wave64); the two-pass cache failure and the abort reproduce on base here.review: most serious first: (1) the PR's own new test can never pass: it asserts no
waveReadLaneFirstin atranslate_computeresult, but the compute prologue emits%14 = waveReadLaneFirst; the dumped DXIL has no waterfall loop (no backedge orphi; the remaining branches and the twowaveActiveBallots are the invalid-sampler guard), so the assert trips on the prologue, not on a loop. Reproduced atwaterfall.rs:573, beforeassert_eq!(da, db), so the check that covers the fix never runs (usekernel::translatelike the existing test, or test the waterfall's own map/ballot instead of the whole compute dump). (2)XCL_WATERFALL_LANE_SWORDSis an extra env switch outside the translation cache key (the description says to clear the cache); its=0form only affects gathers, and CONTRIBUTING asks for switches in their own PR. (3) overlap, not duplicate: #3643 rewriteswaterfall::collapseand adds the samecompact.rskey line, so whichever lands second needs a rebase and only one should carry the key; #3298 adds explicit-LOD comparison samples that read S# 0-2, and if both land those reads should also go throughmimg_sword(as the description says). (4) no test covers thecompact.rskey addition (two collapsed waterfalls over different VGPRs, same S#/SSAMP, must not share a lowering). (5) by reading the fix is right:mimg_gather4_lodis the only lowering that reads S# words 0-2, every such read now goes throughmimg_sword,collapseprovesv[vb..vb+3]contiguous and not overwritten, andcompact::planruns afterwaterfall::collapseso it seesvb;reads_sword_0_2counting everyIMAGE_GATHER4*is a conservative superset. The description also has no suite counts and noxcl-smokeblocks, which is whyPR descriptionis red. Searched open and merged PRs and #1607: no duplicate; the nearest are #3643 and #3298 (overlap, above).performance: 60 s retail smoke, base
df0cfef61621 frames / 17,375 MB peak, mergea3407f721621 frames / 17,983 MB peak (100% frames, 103.5% peak; thresholds 80%/125%), 0 device removals and 0 crashes on both, exit 0x0 both; presents per 2 s last 3: base 60 59 60, merge 60 60 61. The title needed Enter to leave the menu. This does not measure the changed path (no visible symptom was pinned to it and the title may not reach a collapsed gather4_l); by reading, non-gather waterfalls do the same work with a different VGPR word, gather waterfalls collapse instead of looping, and thecompact.rskey is compile-time only, so no frame-time or memory cost is expected.verdict: not yet: its own new test fails on this AMD machine (and
Build and test/PR descriptionare red), so theda == dbassertion that covers the fix never runs; the other failures reproduce on base and the smoke is clean.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
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.