Recompiler: a wave64 compute program folds into one 32-lane wave #3562
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3562"
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 Royalflamejlh on 2026-12-01T06:34:32Z.
(Edited: head
2196dfd10, rebased ontomain5ad98adbc, after three rounds of review: av_cmpxno longer joins a run that reads EXEC as data; a negative inline mask gives -1 to the upper half; a folded loop's cap divides by the console group's threads; buffer accesses that count the lane (ADD_TID,global_*_addtid) count console lane t + 32 in their upper copies; SDWA scalar operands are not taken as spares; LWE counts towards N;s_subvector_loopis refused; a DPP16 upper copy takes the console's row mask bits 2..3; an SDWA compare into EXEC updates E; a panic in the rewrite falls back to the split form, and a compare into a constant is refused; a folded program with a returning atomic gets the compact plan a split one gets; the GPU test also compares with the split form on the same GPU. A test for each. Before: rebased ontomain38ad22da, after #3655; head8f236eca4.)On a GPU with 32-lane waves only, a wave64 compute program now runs folded where it can: each host lane carries two console lanes (t and t + 32), so the whole console wave is one host wave and nothing is exchanged between halves. The split form's exchange is what #3114 measures at 2.6x a program's GPU time, and its spin wait ended runs on Linux here in a GPU hang (NVIDIA Xid 109) at the title's world start.
The form is ported from VIctory-NVIDIA (
crates/victory-shader/src/fold.rsat5fabb46e, GPL-3.0-or-later, https://github.com/trustno1-coder/VIctory-NVIDIA), as a rewrite of the console code into a wave32 program before translation. The provenance note is in the file andTHIRD_PARTY.mdhas the entry.Folding is opt-in:
XCL_WAVE64_FOLD=1turns it on, and without it nothing changes. Its GPU time against the split form is not measured here; #3543, a port of the same idea, measured a median 1.27 times the split form's time on an RTX 4080 with a run-to-run spread as large as the difference.What is in it
crates/xcl/src/gpu/dxil/fold.rs(new, 1,195 lines): the rewrite. VGPR v of console lane t + 32 is VGPR v + N of host lane t; a run of vector instructions is written twice, under each half of EXEC; a mask is the two copies' 32-bit ballots;v_readlane,v_writelane,v_readfirstlaneandv_mbcntname the copy that holds the lane. Scalar code is unchanged, since XCL keeps the console's scalar branches.crates/xcl/src/gpu/dxil/fold_tests.rs(new, 871 lines): the tests, with a small RDNA2 interpreter that runs a console program in 64-lane waves and its folded code in 32-lane waves and compares.gpu/dxil/kernel.rs(translate_compute_rodata): the folded form is tried for a split wave64 compute program; any refusal logs one line and the split form runs. It is tried only withXCL_WAVE64_FOLD=1, which is part of the translated cache's identity.gpu/dxil/lower_mem.rs,lower_window.rs,lower.rs: in a folded program's upper copies of buffer accesses that count the lane (ADD_TID,global_*_addtid), the lane is console lane t + 32 (Lw::tid_lane, fromfold::Twins::upper_tid).ds_bpermute/ds_permute,ds_append/ds_consume, GDS, scratch,s_movrel*/v_movrel*, calls and indirect jumps,s_subvector_loop, EXEC or VCC as a memory operand, fewer than seven spare SGPRs, and a few rarer forms.gpu/dxil/kernel.rs,compact.rs: a folded program whose compact plan is refused only for its table's size is not folded, and a folded program is chosen for the compact form as its split form would be. On that other tree (compact table limit 12,288 words) two programs of about 122,000 instructions lost their compact form by folding and became 4.3 MB of DXIL each, which NVIDIA's compiler did not finish in ten minutes; withmain's 32,768 words both still fit, so onmainthis changes no program of that pack.fold.rs: a program folds only when its VGPRs and their twins fit 255 registers (2N <= 255); the rewrite uses no VGPR beyond the twins.docs/wave64-on-wave32.md: a section on the form.Why it is one pull request. 2,220 changed lines in six commits, over the ~800 the contributing guide asks a reason for. Of them, 1,198 are
fold.rsand 872 its tests; the rest (150 lines) are the wiring behindXCL_WAVE64_FOLD=1, the compact-limit check and its test, the warm setting, the docs and the provenance entry.fold.rsis one rewrite pass over the instruction set: every instruction it accepts is rewritten in the same loop, against the same register plan and the same EXEC handling, so a part of it (say, the lane primitives without the driver) would be code nothing calls and nothing can test on its own: the tests run whole console programs through the interpreter and the folded form.fold.rsnot yet called / turning it on / the census would give three PRs whose diffs are each under 150 lines and one of ~1,900 that is this one: the review offold.rswould be the same review.XCL_WAVE64_FOLD=1is set: with the switch off the translation and the caches are as onmain.The commits are kept apart so each part can be read on its own: the rewrite (
4779e9a96), its GPU tests and the pack count (09d2623ac), the docs (da0d2f01b), the compact-limit check (cc2d5fe79), the register limit (17e1504e4) and the opt-in switch (2196dfd10).Tested
2196dfd10:cargo test --workspace -- --test-threads=43022 passed, 0 failed, 53 ignored. The new and changed tests passed there, on the GPU too:gpu_folded_wave64_matches_the_console_wave(now also against the split form),gpu_folded_wave64_counts_the_console_lane_in_add_tid_accesses,gpu_folded_wave64_keeps_the_thread_limits, the DPP16, SDWA, LWE and refusal tests, anda_folded_program_with_a_returning_atomic_takes_the_compact_form.x86_64-pc-windows-gnu, release. Head913af192c(XCL_WAVE64_FOLDis also a warm pipeline library setting since; the fold andshaders::tests there, under Wine on the CPU: 122 passed, 0 failed, 1 ignored. Earlier head0c6bd4c0: the form made opt-in; the tests switch it on themselves).cargo test -p xcl --release --lib gpu::dxil -- --test-threads=2: 315 passed, 1 failed, 4 ignored. SKIPPED:dispatch_chain_native_wave64_builds_whole(no wave64). The failure isround_tests::directed_reference_basics, which fails the same way onmain.gpu_folded_wave64_matches_the_console_wave(seven programs: masks and lane reads; nested saveexec branches; LDS across a barrier; a loop with divergent exits; a carry chain with lane writes andv_cmpx; EXEC read as data and as a mask before av_cmpx; negative inline masks; in groups of 64, 128, 8x8, 8x8x4, 40 and 16x6 threads, against a small RDNA2 interpreter of the console wave) andgpu_folded_wave64_keeps_the_thread_limitspassed.the_folded_form_is_taken_for_a_split_program_and_has_no_exchange: the folded DXIL validates and has no atomic, compare-exchange or group-shared storage.XCL_GPU_PROFILE=1, which makes a queue run its draws and dispatches one after the other; on a later head of that tree the title lost its device at the world start without the switch (2 of 2 runs, with folding on and with it off) and ran 600 s with it (1 of 1), so the run says nothing about this change with the GPU's work overlapping. In a cold launch pass of that tree, of the 1,151 wave64 compute programs it translated, 732 folded, 351 ran as lone halves (another unmerged change) and 68 stayed split. Translated offline, folded DXIL was 1.11 times the split form's at the median and 1.73 times at the 95th percentile.Regression run
RTX 2070 SUPER 8 GB (driver 621.01), Ryzen 7 5700X3D, Windows 11 Pro 26200, release builds by
scripts/smoke.ps1, the same retail title for 60 s each.mainat078358a05, the newermain(this PR is on5ad98adbcand merges cleanly into078358a05):this PR's head:
Not tested
XCL_WAVE64_FOLD=1. The smoke runs below are without the switch, so they show only that nothing changes when it is off.SV_GroupIndexvalues, as the existing wave32 path does.v_div_fmas, MIMG/NSA and buffer instructions are ported but no test program uses them. The reference interpreter is this PR's own.AI use
6cec7afd) and the VGPR limit (bda4766f).Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:11:47Z.
Review (head
988b2987, diff read, not a merge-check; draft withPR descriptionred, so not built or run here):kernel.rs~219,fold.rs~54). The same idea from the same VIctory-NVIDIA source (throny's #3529 / #3530 / #3543, closed today) was measured in the world on an RTX 4080 at a median 1.27x the split form's time ("no measurable gain"). Please measure against the split form on the GPU, on Windows, before making it the default, or keep it opt-in.fold.rs~1112), while the closed stack refused at 2N + 16 > 255, the limit VIctory-NVIDIA hit at 2 x 129 VGPRs, so programs near 128 VGPRs probably spill on NVIDIA.gpu::dxilran, on Linux / Wine with windows-gnu). It conflicts with #3504, #3561 and #3563 inkernel.rs.Fine: the rewrites of
v_readfirstlane/v_readlane/v_writelane/v_mbcnt, run ordering (stores and EXEC writes end a run,upper_firstfor scalar hazards), thes_getpcremap to the console address, the NSA remap, and the provenance note plus THIRD_PARTY entry. It covers more than the closed stack (memory, LDS, barriers, DPP).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 Royalflamejlh on 2026-12-01T08:05:00Z.
Thanks for the read. On the points:
bda4766fb), with a test at the boundary. In the pack tested no program has 120 to 128 VGPRs; the ones at 129 were already refused.6cec7afd): a folded program whose compact plan is refused only for its table's size is not folded. On a tree with a 12,288-word table limit, two programs of about 122,000 instructions became 4.3 MB of DXIL each when folded and NVIDIA's compiler did not finish them in ten minutes. Withmain's 32,768 words both still fit.gpu::dxilon the new head, RTX 4060 Ti under Wine: 315 passed, 1 failed (directed_reference_basics, as onmain), 4 ignored.AI use: Claude Code. Claude Opus 5.5 checked the limit against the code and wrote the two changes; Claude Fable 5.2 ran the tests on the card and wrote this reply.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:18:37Z.
Re-review (head
bda4766f, diff read, not a merge-check:PR descriptionstill fails (no xcl-smoke blocks), so not built or run here). Follow-up to my review of988b2987.2N > 255(fold.rs~1112), and the commit argues the rewrite needs no extra VGPRs because its scratch registers are SGPRs (spare_sgprs), which matches the code. The description's "refuses: more than 128 VGPRs" is now stale (the limit is 127).6cec7afd): a folded program whose compact tables pass the limit now keeps the split compact form (kernel.rs~454-456,compact::wanted_plan/fits), with a test; it refuses folding even when the split form's tables don't fit either.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-01T10:17:02Z.
Triage (#1607) – head
0c6bd4cNo open PR makes the same change. #3543 (throny) was a port of the same fold and was closed by its author on 2026-11-30 because it measured no gain on an RTX 4080. #3561 (same author) is a different approach to the same exchange cost: a lane loop for small programs.
The provenance note and the THIRD_PARTY.md entry for VIctory-NVIDIA (GPL-3.0-or-later) are present. Since
0c6bd4c0folding is opt-in (XCL_WAVE64_FOLD=1). It has not been run on Windows or on any GPU other than the RTX 4060 Ti, and its GPU time against the split form is not measured, so it should stay opt-in until that is settled.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-01T14:19:17Z.
Folding is opt-in now (head
0c6bd4c0):XCL_WAVE64_FOLD=1turns it on, and without it no program changes form. The description says so, and why: no GPU-time measurement against the split form here, and #3543's figure.cargo test --lib gpu::dxilon that head, RTX 4060 Ti under Wine: 315 passed, 1 failed (directed_reference_basics, as onmain), 4 ignored; both GPU tests of the form passed.AI use: Claude Code with Claude Fable 5.2 made the change, ran the tests and wrote this.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-01T20:47:10Z.
XCL_WAVE64_FOLDis now a warm pipeline library setting as well (head913af192c): with it left out, a warm library built with folding on was reused with it off. Found while checking bmjask's point on #3563.AI use: Claude Code (Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T21:15:44Z.
Follow-up review (head
913af192, sincebda4766, diff read, not a merge-check; checks red):XCL_WAVE64_FOLD=1(fold.rs~49-56); the translated cache tag isxcl-wave64-fold-1(kernel.rs~110); the switch is a warm pipeline setting (shaders.rs~40) with a test; README anddocs/wave64-on-wave32.mdsay it is off and not measured.2 * n > HOST_REGISTERS(fold.rs~1112), and the description says "more than 127 VGPRs".kernel.rs~454 still refuses folding whenever the foldedwanted_plandoes not fit, even when the split form's tables would not fit either; it only loses a fold, and only with the switch on.gpu_folded_wave64_matches_the_console_wave(fold_tests.rs~504-522) takeswantfrom theruninterpreter, not from the split form on the same GPU.xcl-smokeblocks (the reasonPR descriptionis red), and #3504, #3561 and #3563 each still conflict with this branch ingpu/dxil/kernel.rs. The draft wording and AI use are fixed.New:
fold.rsalone is 1,158 lines. A natural split, stacked: (1) preparation with no behaviour change:compact::wanted_plan/fitsand thegroups/lastfields ofComputeStart; (2)fold.rswithfold_tests.rs, not yet called (the closed #3529 / #3530 / #3543 stack split the same port into context, lane primitives and driver); (3) turning it on:translate_foldedand its call intranslate_compute_rodatabehindXCL_WAVE64_FOLD=1, the compact-limit refusal, the warm setting, README and docs; (4) thewave64_fold_censuscount.Not reviewed line by line again because of the size; the 20 lines changed since the last review (the opt-in switch, warm setting, test, docs) are correct. The provenance note and
THIRD_PARTY.mdentry are in place.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 Royalflamejlh on 2026-12-01T21:52:58Z.
@Foniass thanks for the follow-up. I'd rather keep it as one pull request, and the description now says why, under Why it is one pull request:
fold.rsis one rewrite pass whose parts nothing could call or test alone (the tests run whole console programs through it), so the split would leave one ~1,900-line PR that is this one, beside three small ones; the closed #3529 / #3530 / #3543 stack split the same port and none of its parts could merge alone. The six commits are kept apart so each part reads on its own, and nothing changes withoutXCL_WAVE64_FOLD=1.The other open points stand as you list them: the smoke pair and a Windows run are owed (no Windows machine of ours answered today), the GPU tests compare with the interpreter rather than the split form on the same GPU, and the
compact_nest_tagconflict with #3561 / #3563.AI use: Claude Code (Claude Opus 5.5) drafted this reply and the description section.
Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T11:49:15Z.
merge-check
base:
1c8b551475head:
913af192c7merge: clean (d6993aa0d7f42f8bedf2c6ae93ede6cb7f790b08; 9 files, +2004/-12; git diff --check ok)
build: cargo build --workspace ok; cargo build --release -p xcl ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture -> 2918 passed, 1 failed, 52 ignored across 43 targets (28 SKIPPED lines matching clean base
1c8b551475: 22 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 2 no heap windows, 1 cannot disable the driver cache). The sole failure is the pre-existing Issue #3441 flake in tests/gpu_two_pass_cache_e2e.rs:584 (two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs,releasing the title PSOs releases their two-pass state: left: 1, right: 0), reproduced on clean base1c8b551475. All 10 new runnable tests passed on RTX 4060 with 0 skips (including both live GPU testsgpu_folded_wave64_matches_the_console_waveandgpu_folded_wave64_keeps_the_thread_limits, 7 unit tests ingpu::dxil::fold::tests, andshaders::warm_settings_keep_the_wave64_fold_switch_on_both_backends;wave64_fold_censusis marked#[ignore]).review: Full 9-file diff (+2004/-12) audited. The opt-in plumbing (
XCL_WAVE64_FOLD=1, off by default, keyed intokernel::compact_nest_tagandshaders::semantic_pipeline_setting),fold::init/compute_gate(leave = false), and GPL-3.0-or-later attribution inTHIRD_PARTY.mdandfold.rsare clean. However, code audit ofcrates/xcl/src/gpu/dxil/fold.rsfound three concrete silent miscompilation bugs wherefoldaccepts the program and emits wrong code instead of ordering correctly or failing closed:EXECwrites invalu_copy(fold.rs:405,fold.rs:434,fold.rs:455): all threet.exec = truepaths (SDWAv_cmpx, plainENC_VOPCv_cmpx, andENC_VOP3v_cmp*withdst == EXEC_LO) omitside.writes.push(mask_console(EXEC_LO, half)). Becauset.a.writesis empty: (a)joins(fold.rs:708-713) merges a preceding vector instruction readingEXEC_LO(e.g.v_mov_b32 v0, exec_lo) with a followingv_cmpx_*into one run, solower_copieswrites the post-v_cmpxEXEC_LOback intox.ebeforeupper_copiesrunsv_mov_b32 v0+N, e, giving console lanes 32..63 the overwrittenEXEC.loinstead of the pre-v_cmpxvalue; (b) single-instructionv_cmpx_* exec_lo, v0or VOP3v_cmp_* exec, exec_lo, v0fails to setupper_first = trueinTwin::ordered(clobberingx.ebeforeupper_copiesreads it); and (c) 64-bitv_cmpx_* exec, v[0:1]fails to be rejected byTwin::ordered.EXECwrite on SDWAv_cmpwithSD=1, SDST=EXEC_LO(fold.rs:407-412): whensd == EXEC_LO(126),mask(sd, half, x)rewritesSDSTto hostEXEC_LOfor both halves, butt.execis never set totrue, so neitherlower_copiesnorupper_copiescopies hostEXEC_LOback intox.e/x.e + 1and the write to consoleEXECis lost.spare_sgprs(fold.rs:993-1000) andscc_use(fold.rs:627-632):spare_sgprsrelies solely onrdna2::sgpr_uses, which skips SDWAVSRC0(S0=1),VSRC1(S1=1), andVOPC_VOP_SDWA_SDST_ENCSDST(SD=1) (rdna2.rs:554-559), allowing live SDWA-only SGPRs (such as aVOPCSDWA destination pair) to be allocated as sparex.e/jp/save/swap/t. Likewisescc_use(fold.rs:630) checksVSRC0 == 253(d.words[1] & 0xFF) but missesS1=1withVSRC1 == 253(d.words[0] >> 9 & 0xFF), allowing SCC-clobbering rewrites whileSCCis live into an SDWAVSRC1.performance: Two 60 s release smokes on title 29640639 vs clean base
1c8b551475(1462 frames, presents per 2 s last 3: 48 53 59, peak commit 16043 MB): default (switch unset) ran 1638 frames (+12.0%, steady 60 60 61, peak commit 16563 MB, +3.2%, 0 removals, 0 crashes); opt-inXCL_WAVE64_FOLD=1ran 1651 frames (+12.9% vs base, +0.8% vs default, steady 60 60 60, peak commit 14953 MB, -6.8% vs base, 0 removals, 0 crashes; 1 logged fallback[SHADER] wave64 fold: no spare scalar registers).Default (switch unset):
Opt-in (
XCL_WAVE64_FOLD=1):verdict: not yet: silent miscompilations in fold.rs (missing EXEC side.writes on v_cmpx/v_cmp-to-exec at lines 405/434/455, missing t.exec on SDWA v_cmp SDST=EXEC_LO at lines 407-412, and missed SDWA SGPR/SCC operands in spare_sgprs and scc_use)
hardware / tool and model: NVIDIA GeForce RTX 4060 8 GB (driver 621.40), Intel Core i5-11400F, 32 GB RAM, Windows 11 Build 26200, Rust 1.100.1 MSVC, DXC 1.9.2602.17 / Antigravity (Gemini 4 Neon)
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T13:48:45Z.
Follow-up review (head
8f236eca, since913af192, diff read, not a merge-check; checks red):git range-diffshows the own commit changed only wheremainmoved under it (theXCL_WAVE64_IDIOMSwarm setting and cache tag now sit next to this PR's own inshaders.rs/kernel.rs); this push is a rebase.New: none.
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 bmjask on 2026-12-02T14:53:50Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 712High: A v_cmpx (or a VOP3 v_cmp into EXEC) only sets
t.execand never adds EXEC_LO to its lower copy'swrites, sojoinslets it join a run whose earlier instructions read the console's EXEC_LO. Their upper copies read it throughx.e, whichlower_copieshas already overwritten with the post-cmpx EXEC. In the runv_mbcnt_lo_u32_b32 v0, exec_lo, 0; v_mbcnt_hi_u32_b32 v0, exec_hi, v0; v_cmpx_gt_u32 16, v0, the order is lower copies, thens_mov e, exec_lo(the new E.lo), then the upper copy of mbcnt_lo, which isv_bcnt(x.e)and counts the post-cmpx mask instead of the original. Lanes 32..63 get the wrong prefix count and the wrong lanes pass the v_cmpx. The same happens forv_mov_b32 v1, exec_loorv_cndmask ..., execfollowed by a v_cmpx in one run. Adding EXEC_LO to the cmpx'swriteswould keep it out of such runs.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:53:50Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 368High: In
mask9, negative inline integers (codes 193..=208) are kept as they are for the upper half, but a 64-bit mask from an inline -k sign-extends, so its high dword is always 0xFFFFFFFF (code 193), not -k.v_cndmask_b32_e64 v0, v1, v2, -2(mask 0xFFFF_FFFF_FFFF_FFFE) gives the upper copy selector 0xFFFFFFFE, so console lane 32 takes v1 instead of v2. The same goes forv_add_co_ci_u32_e64with a carry-in of -2..-16. The SAVEEXEC path (~923) maps these codes toint(-1)correctly, so mapping 193..=208 to 193 here would match it.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:53:50Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 1151Medium: The folded host group has half the console's threads (
total.div_ceil(64) * 32), andloop_passes(kernel.rs:558) divides the dispatch's loop budget by the host's numthreads, so each loop of a folded program gets about twice the split form's pass cap while each pass does two console lanes' work. For a 256-thread wave64 program with a runaway or very long loop, the split form caps it at share/256 passes and the folded form at share/128. The GPU-time bound IO_LOOP_BUDGET gives roughly doubles, which makes a TDR / device removal more likely on the hang-prone titles this form targets. Dividing by the console thread count would keep the cap the same.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:53:50Z.
Review: COMMENTED
Review of
8f236eca: 3 finding(s) (2 high, 1 medium), most severe first.crates/xcl/src/gpu/dxil/fold.rs:712: A v_cmpx (or a VOP3 v_cmp into EXEC) only setst.execand never adds EXEC_LO to its lower copy'swrites, sojoinslets it join a run whose earlier instructions read the console's EXEC_LO. (inline)crates/xcl/src/gpu/dxil/fold.rs:368: Inmask9, negative inline integers (codes 193..=208) are kept as they are for the upper half, but a 64-bit mask from an inline -k sign-extends, so its high dword is always 0xFFFFFFFF (code 193), not -k. (inline)crates/xcl/src/gpu/dxil/fold.rs:1151: The folded host group has half the console's threads (total.div_ceil(64) * 32), andloop_passes(kernel.rs:558) divides the dispatch's loop budget by the host's numthreads, so each loop of a folded program gets about twice the split .... (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.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:53:52Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T21:01:44Z.
Follow-up review of
ee2c186e, since8f236eca(code reading only, not a merge-check;PR descriptionred) · 1 high, 1 medium, 2 nitsIn short: Since
8f236ecathe first commit has three real fixes, each with a test:v_cmpxnow records its EXEC write, so an earlier instruction in the same run that reads EXEC no longer has its upper copy see the new value (fold.rs~512);kernel.rs~558).The code reads right. The size, the interpreter-only GPU tests and the compact-limit refusal are still open. The smoke blocks name
8f236eca, not this head (PR descriptionis red).High
fold.rs1,162,fold_tests.rs793), none generated. The new "Why it is one pull request" section argues against splitting off the preparation and the wiring, but not against splittingfold.rsitself, which the closed #3529 / #3530 / #3543 stack did with the same port. One possible stack:compact::wanted_plan/fits, thegroups/lastfields ofComputeStart, and thefoldparameter oftranslate_entry_with;v_readlane/v_writelane/v_readfirstlane/v_mbcntwith their test programs;translate_foldedbehindXCL_WAVE64_FOLD=1, the compact-limit refusal, the warm setting, README and docs;wave64_fold_censuscount.Medium
gpu_folded_wave64_matches_the_console_wave(fold_tests.rs~542-561) takeswantfrom this PR's interpreter, not from the split form's output on the same GPU. The interpreter and the rewrite can agree on the same misreading of an instruction.Nit
kernel.rs~492 refuses folding whenever the foldedwanted_plandoes not fit, even when the split form's tables do not fit either. It only loses a fold, and only with the switch on.ef027c50a) still says "XCL_WAVE64_FOLD=0 turns the form off" and "more than 128 VGPRs"; both are wrong at this head.programs()(~238) now has seven.XCL_WAVE64_FOLD=1was set for the PR's smoke run.Checked and fine
XCL_WAVE64_FOLD=1(fold.rs~47-56), part of the translated cache tag (kernel.rs~117) and of the warm settings, with a test.2 * n > HOST_REGISTERS(~1116).v_cmpxEXEC write inside.writes(~512-514) makesjoinsflush the run when an earlier upper copy reads EXEC. Covered byexec_read_then_cmpx.mask9maps inline -1..-16 to -1 for the upper dword, and the interpreter now reads an inline or literal SRC2 mask throughsrc64, soinline_maskscompares against the right value.loop_passesdivides by the console group's threads when folded, like the split form. Covered bya_folded_loop_has_the_passes_of_the_console_threads.8f236eca. No other open PR makes this change; #3561 is a different form for the same exchange cost.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T21:10:43Z.
Review: COMMENTED
Review of
ee2c186e: 5 finding(s) (2 high, 3 medium), most severe first.crates/xcl/src/gpu/dxil/fold.rs:593: MUBUF/MTBUF accesses without IDXEN are folded as-is, but the translator takes an ADD_TID_ENABLE buffer's index fromself.lane(lower_mem.rs:1347-1356, 2029-2038), which in the folded wave32 program is the host lane 0..31 for both copie.... (inline)crates/xcl/src/gpu/dxil/fold.rs:563: The ADDTID refusal is inside the"ENC_DS"match arm only, so GLOBAL_LOAD_DWORD_ADDTID and GLOBAL_STORE_DWORD_ADDTID (ENC_FLAT_GLBL) are folded, although their address comes from the implicit lane id (self.lane, lower_mem.rs:2153-2156.... (inline)crates/xcl/src/gpu/dxil/fold.rs:1000:spare_sgprsgets its 'used' set fromrdna2::sgpr_uses, which skips SRC0 for non-Plain variants (rdna2.rs:557) and never sees an SDWA S1 SGPR source or an SDWA VOPC SDST, so an SGPR the program uses only through SDWA can be chosen as .... (inline)crates/xcl/src/gpu/dxil/fold.rs:898: SOPK branches such as S_SUBVECTOR_LOOP_BEGIN/END (F_BRANCH, soflowreturns Flow::Branch) fall into the generic SOPK path and are copied verbatim. (inline)crates/xcl/src/gpu/dxil/fold.rs:1027:vgprs()adds the extra write dword for TFE but not for MIMG LWE, andmimg_vgpr_usescounts neither, so N can be one too small and the status dword lands on a twin register. (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.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T21:10:44Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 593High: MUBUF/MTBUF accesses without IDXEN are folded as-is, but the translator takes an ADD_TID_ENABLE buffer's index from
self.lane(lower_mem.rs:1347-1356, 2029-2038), which in the folded wave32 program is the host lane 0..31 for both copies, so console lanes 32..63 use lanes 0..31's slots. A wave64 program that spills or keeps a private array through a swizzled scratch V# (ADD_TID_ENABLE=1, IDXEN=0, the usual MUBUF scratch form) gets, from the upper copy ofbuffer_store_dwordfor console lane t+32, a write into lane t's slot, overwriting the lower half's private data, and both halves read back wrong values. The 'scratch' refusal covers only ENC_FLAT_SCRATCH. Refusing (or offsetting the lane by 32 in the upper copy) for ADD_TID buffers would fix it.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T21:10:44Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 563High: The ADDTID refusal is inside the
"ENC_DS"match arm only, so GLOBAL_LOAD_DWORD_ADDTID and GLOBAL_STORE_DWORD_ADDTID (ENC_FLAT_GLBL) are folded, although their address comes from the implicit lane id (self.lane, lower_mem.rs:2153-2156), which is the host lane 0..31 for both halves. Forglobal_store_dword_addtid v1, s[0:1]in a wave64 program, the upper copy for console lanes 32..63 stores at lane*4 for lanes 0..31: lanes 32..63's data overwrites lanes 0..31's, and lanes 32..63's addresses are never written. Moving the ADDTID check out of the DS arm would cover both.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T21:10:44Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 1000Medium:
spare_sgprsgets its 'used' set fromrdna2::sgpr_uses, which skips SRC0 for non-Plain variants (rdna2.rs:557) and never sees an SDWA S1 SGPR source or an SDWA VOPC SDST, so an SGPR the program uses only through SDWA can be chosen as E, a temp, the swap register or the far-jump pair. If the program uses s104/s105 only as an SDWA operand (e.g.v_cmp_eq_u32_sdwa s[104:105], v0, v1with SD=1),spare_sgprstreats them as free and makes them E, so the console's mask overwrites EXEC or the moves into E overwrite the program's value, and lanes run with the wrong EXEC or read corrupted data. Including SDWA operands in the used set would fix it.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T21:10:44Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 898Medium: SOPK branches such as S_SUBVECTOR_LOOP_BEGIN/END (F_BRANCH, so
flowreturns Flow::Branch) fall into the generic SOPK path and are copied verbatim. Their SIMM16 still holds the console offset, which is wrong in the longer folded code, and their implicit EXEC use isn't renamed to E. A program using them folds without a refusal, the host branch jumps into the middle of the expanded code, and the loop tests EXEC_LO instead of E. Refusing them, or relocating their offsets like the other branches, would fix it.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T21:10:44Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 1027Medium:
vgprs()adds the extra write dword for TFE but not for MIMG LWE, andmimg_vgpr_usescounts neither, so N can be one too small and the status dword lands on a twin register. An image load with LWE=1, TFE=0 that writes the program's highest VGPRs puts its status dword in v(N), the twin of v0, so the lower copy overwrites console lane t+32's v0 (its thread id or other data). Counting LWE like TFE would fix it.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T21:35:25Z.
Follow-up review of
f1988c2e, sinceee2c186e(code reading only, not a merge-check;PR descriptionred) · 1 high, 1 nitIn short: This push fixes four more cases in the fold and answers the interpreter-only point:
LWEis treated likeTFE;s_subvector_loopis refused.The GPU test now also compares each program with the split form on the same GPU. The fixes read right. The size is still open, and the smoke blocks name
8f236eca(PR descriptionis red).High
fold.rsandfold_tests.rsmost of them), none generated. The stack suggested earlier still applies:XCL_WAVE64_FOLD=1;Nit
kernel.rs~492 refuses folding whenever the foldedwanted_plandoes not fit, even when the split form's tables do not fit either.Checked and fine
gpu_folded_wave64_matches_the_console_wavenow also runstranslate_compute(the split form) and asserts the folded output equals it.emitrecords where each upper copy of a MUBUF / MTBUF access withoutIDXEN, or of an*ADDTIDinstruction, starts.upper_tidpasses those as byte offsets tolane_plus_32, andtid_laneadds 32 to the lane there (binary_searchon a list built in increasing order).gpu_folded_wave64_counts_the_console_lane_in_add_tid_accesseschecks 128 lanes throughglobal_store_dword_addtidand a V# with ADD_TID.spare_sgprsmarks SRC0 (S0, bit 23), SRC1 (S1, bit 31) and a VOPC SDST (SD, bit 15) as used.c < 127keepsc..c + 2inside the 128-entry array. Covered byan_sgpr_named_only_by_an_sdwa_operand_is_not_spare.LWEnow counts likeTFEfor the extra returned VGPR, ands_subvector_loopis refused, with a test.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:55:18Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 712Right for reads of EXEC as data.
fold_testsshowed it: with yourv_mbcnt_lo/hi+v_cmpx_gt_u32 16, v0run, console lane 32 counted 16 instead of 32. Fixed inf1988c2e8: a copy that writes EXEC now lists EXEC's dword in itswrites(end ofvalu_copy), sojoinsends the run before it.v_mov_b32 v6, exec_lobefore av_cmpxhad the same fault: its upper copy reads EXEC_LO through E.v_cndmask_b32 ..., execwas right before the fix: as a mask, its upper copy reads the upper dword from the hardware EXEC, and thev_cmpx's upper copy only changes that after it. The new test programexec_read_then_cmpxhas all three.Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:55:20Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 368Right.
mask9now gives the upper copy -1 (193) for any inline -1..-16, as the SAVEEXEC path does (f1988c2e8). Test programinline_masks(v_cndmask_b32with -2,v_add_co_ci_u32with -3): before the fix console lane 32 took 1 where the console takes 2.Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:55:22Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 1151Right. For a folded program
loop_passesnow divides by the console group's threads, not the host group's (translate_on_this_thread,f1988c2e8), so its cap is the split form's. Test:a_folded_loop_has_the_passes_of_the_console_threads(a group of 96: the folded form divided by 64 before the fix).Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:55:24Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 593Right. ADD_TID is a bit of the V#, known only when the program runs, so the fold cannot refuse on it. Fixed in
f1988c2e8:foldlists where the upper copies of buffer accesses without IDXEN and ofglobal_*_addtidstart (Twins::upper_tid), and the translation counts lane + 32 there (Lw::tid_lane,lower_mem.rs~2476, used by the MUBUF, MTBUF and addtid paths). Test:gpu_folded_wave64_counts_the_console_lane_in_add_tid_accesses(aglobal_store_dword_addtidand abuffer_store_dwordthrough an ADD_TID V#, one console wave of 64). It runs only on a GPU with wave32; its results will be in the description.Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:55:26Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 563Right; the same change as the buffer one above covers it, by counting the console lane instead of refusing: the upper copy of a
global_*_addtidis listed inTwins::upper_tid, andLw::tid_lanegives it lane + 32 (f1988c2e8). The GPU test stores withglobal_store_dword_addtidacross both halves.Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:55:28Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 1000Right.
spare_sgprsnow marks an SDWA instruction's scalar operands too (S0, S1 and a VOPC SDST with SD, each as a pair), inf1988c2e8. Test:an_sgpr_named_only_by_an_sdwa_operand_is_not_spare(v_cmp_eq_u32_sdwa s[104:105], v0, v1; before the fix s[104:105] became E).Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:55:31Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 898Right.
flownow refusess_subvector_loop_begin/end(fold.rs~628,f1988c2e8), so such a program keeps the split form. Test:what_the_rewrite_does_not_cover_is_refused_with_its_reason.Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:55:32Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 1027Right.
vgprsnow adds the status dword for LWE as for TFE (fold.rs~1050,f1988c2e8). Test:an_image_load_with_lwe_counts_its_status_dword(animage_loadinto v10 with LWE: N is 12; 11 before the fix).Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:55:39Z.
Thanks for both follow-ups (to 21:35). At
f1988c2e8(rebased onmain5ad98adbc), with bmjask's second round in it too:gpu_folded_wave64_matches_the_console_wavenow also runs each program's split form on the same GPU and requires the folded output to equal it, besides the interpreter's values.mainruns.XCL_WAVE64_FOLD, which it now says. The suite and smoke atf1988c2e8on the RTX 2070 SUPER PC are running; their counts go into the description.AI use: Claude Code (Claude Opus 5.5) wrote the fixes, the tests and the replies in this round.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T21:56:21Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 428High: For DPP16, the upper-half copy renames only src0 to its twin and keeps the console's ROW_MASK (bits 28..31) unchanged, but the translator derives the row from the host lane (lane >> 4, rows 0..1), so the upper copy applies the mask bits meant for console rows 0..1 instead of rows 2..3 (
row_mask >> 2). For a wave64v_mov_b32_dpp v1, v0 row_shr:1 row_mask:0xc(update only lanes 32..63), the lower copy is correctly off, but the upper copy reads bits 0..1 of 0xc, which are 0, so lanes 32..63 never get the update. With row_mask 0x3 it goes the other way, and the upper copy writes rows that should stay unchanged. Any mask where (rm & 3) != (rm >> 2) gives silently wrong results. Shifting the mask for the upper copy (and the bank mask if needed) would fix it.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T21:56:21Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 413High: An SDWA VOPC with an explicit SD destination of EXEC_LO doesn't set
t.exec, unlike the VOP3 v_cmp path (line 460), so the compare writes the host EXEC_LO but the result is never copied back into E. Forv_cmp_gt_u32_sdwa exec, v0, v1, both the A and B copies write the host EXEC_LO, nomov e, EXEC_LO/mov e+1, EXEC_LOfollows, and the next run reloads EXEC_LO from the stale E. The EXEC update is lost and lanes the console turned off keep running. Treating an SDWA SD of EXEC like the VOP3 case would fix it.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T21:56:21Z.
Review: COMMENTED
Review of
f1988c2e: 3 finding(s) (2 high, 1 medium), most severe first.Re-review at
f1988c2e. From theee2c186ereview, the SDWA spare-SGPR, S_SUBVECTOR_LOOP and MIMG LWE items weren't flagged again. ADD_TID addresses now usetid_lane(), but window selection still uses the host lane (third item). The first two items are new.crates/xcl/src/gpu/dxil/fold.rs:428: For DPP16, the upper-half copy renames only src0 to its twin and keeps the console's ROW_MASK (bits 28..31) unchanged, but the translator derives the row from the host lane (lane >> 4, rows 0..1), so the upper copy applies the mask bits .... (inline)crates/xcl/src/gpu/dxil/fold.rs:413: An SDWA VOPC with an explicit SD destination of EXEC_LO doesn't sett.exec, unlike the VOP3 v_cmp path (line 460), so the compare writes the host EXEC_LO but the result is never copied back into E. (inline)crates/xcl/src/gpu/dxil/lower_window.rs:293: see below.On lines outside the diff:
crates/xcl/src/gpu/dxil/lower_window.rs:293:addtid_windowstill picks the memory window of aglobal_*_addtidaccess fromself.lane, while the address computed right after it (lower_mem.rs:2156) now usestid_lane(), so a folded upper copy selects its window from lane t while it accesses lane t + 32. When the SADDR base sits within 128 bytes below a 4 GiB window boundary, the upper copy's address (base + 4*(t+32)) is in the next window butwindow_atwas given base + 4*t, so lanes 32..63 go through the wrong window (wrong data or an out-of-window guard). Usingtid_lane()here too would keep them consistent.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 Royalflamejlh on 2026-12-02T22:17:05Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 428Right. In
daf3c1be7the upper copy of a DPP16 instruction takes the console's row mask bits 2..3 as its bits 0..1 (valu_copy); the bank mask is per row, so it stays. Test:a_dpp16_row_mask_names_the_console_rows_in_each_copy(v_mov_b32_dpp v1, v0 row_shr:1 row_mask:0xc: the copies get 0xc and 0x3; 0xc twice before the fix).Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T22:17:07Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 413Right. An SDWA compare with SD = EXEC now sets
t.execas the VOP3 form does, so each copy's result goes back into E (daf3c1be7). Test:an_sdwa_compare_into_exec_keeps_the_console_exec(v_cmp_gt_u32_sdwa exec, v0, v1:s_mov_b32 E.hi, exec_loafter the upper copy; missing before the fix).Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T22:17:09Z.
On bmjask's third point at
f1988c2e(lower_window.rs~293, outside the diff): right,addtid_windownow picks the window fromtid_lane()too, so a folded upper copy's window and address agree (daf3c1be7). No test of its own: it needs a SADDR base within 128 bytes below a 4 GiB window boundary, which the test runner's single window does not give; the GPU testgpu_folded_wave64_counts_the_console_lane_in_add_tid_accessescovers the address. The two inline points are answered in their threads.AI use: Claude Code (Claude Opus 5.5) wrote the fixes, the tests and this reply.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T22:18:36Z.
Follow-up review of
daf3c1be, sincef1988c2e(code reading only, not a merge-check;PR descriptionred) · 1 high, 1 nitIn short: This push fixes three more cases in the fold:
lower_mem.rsnow usestid_lanetoo.Each has a test, and the code reads right. Commits 2, 3, 4 and 6 are unchanged. The size still blocks it.
High
XCL_WAVE64_FOLD=1, and the census.Nit
kernel.rs~492 refuses folding whenever the foldedwanted_plandoes not fit, even when the split form's tables do not fit either.Checked and fine
src0 == 0xFA): the upper copy keeps bank mask and controls, clears row-mask bits 30..31 (rows a 32-lane wave does not have) and moves them to 28..29.a_dpp16_row_mask_names_the_console_rows_in_each_copychecks0xCbecomes0xC/0x3. DPP8 and the other encodings are unchanged.SDset and SDSTEXEC_LOnow setst.exec, so the twin saves and restores EXEC like a VOP3 compare into EXEC.an_sdwa_compare_into_exec_keeps_the_console_execchecks the copies ofexec_loin the spare pair.tid_laneis nowpub(super)and used inlower_mem.rs, so a global ADD_TID access counts console lane t + 32 in the upper copy as well.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T22:26:36Z.
Thanks. The split and the compact-limit points stand as answered above: unchanged at
daf3c1be7. Both PRs still merge cleanly withmain078358a05and build there (cargo check --tests).Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T22:47:54Z.
Review: COMMENTED
Review of
daf3c1be: 2 finding(s) (2 medium), most severe first.Re-review at
daf3c1be. All three findings from thef1988c2ereview look addressed: the DPP16 row mask, the SDWA compare writing EXEC, and the ADDTID window now usingupper_tid. Two new items below, both behind XCL_WAVE64_FOLD=1.crates/xcl/src/gpu/dxil/fold.rs:165:Asm::putpanics on an encode error, andfold::foldruns on the caller's thread intranslate_compute_rodata. (inline)crates/xcl/src/gpu/dxil/kernel.rs:489: A folded program loses the compact form that branch-heavy split programs with a consumed atomic get, becauseautomatic_planis called withcompute && splitandsplitis false for the folded translation (the new guard at line 492 al.... (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.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T22:47:55Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 165Medium:
Asm::putpanics on an encode error, andfold::foldruns on the caller's thread intranslate_compute_rodata. Onlytranslate_entry_withturns translator panics into Err, so a panic in the rewrite skips the logged fallback to the split form. For any instruction/encoding pairrdna2::encoderejects ("X has no encoding Y") while rewriting a game shader, or an out-of-range index in the rewrite, the panic unwinds throughpso::direct_computeinto the PSO build instead of loggingwave64 fold: ... the split form, so a shader the split form handles can take down the pipeline compile. Returning Result fromAsm::put, or runningfold()inside the translator thread's panic boundary, would keep the fallback.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T22:47:55Z.
Code review location:
crates/xcl/src/gpu/dxil/kernel.rs; line 489Medium: A folded program loses the compact form that branch-heavy split programs with a consumed atomic get, because
automatic_planis called withcompute && splitandsplitis false for the folded translation (the new guard at line 492 also passesfalse, so it doesn't catch this). Take a wave64 compute program with 250 or more blocks, under 10 000 instructions, and a GLC BUFFER_ATOMIC_ADD whose result is used. Split, it gets a compact plan throughatomic_candidate. Folded, the plan is None andsplit_computewon't cut it either (Op::AtomicRmw => return None), so it's emitted in full at twice the size, uncompacted: the huge-DXIL / driver-compile-hang case the compact path exists to avoid, with no fallback to the split form. Passing the original split-ness toautomatic_plan(or refusing to fold when the split form would have had a plan) would fix it.Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T23:02:21Z.
Code review location:
crates/xcl/src/gpu/dxil/fold.rs; line 165(Edited: at
2196dfd10the SDST-255 compare below is refused by name infold, and the panic test is replaced by that refusal inwhat_the_rewrite_does_not_cover_is_refused_with_its_reason.catch_unwindstays.)Valid. In
fbac76fdctranslate_folded(kernel.rs:238) runsfold::foldinsidecatch_unwind, so a panic in the rewrite becomes the error "the rewrite panicked" and the logged fallback to the split form runs.Asm::putkeeps its panic: the instruction names it encodes are XCL's own.I could not make
Asm::putfail from console code. Random instruction words did panic the rewrite elsewhere, though: a VOP3 compare whose SDST is 255 overflowsc + 1inmask_console(fold.rs:308) in a debug build. The new testa_panic_in_the_rewrite_is_an_error_the_split_form_takes_over_fromuses that case. It fails without the change and passes with it.Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T23:02:23Z.
Code review location:
crates/xcl/src/gpu/dxil/kernel.rs; line 489Valid. In
fbac76fdcthe folded translation picks its compact plan as a split one does:automatic_plan(&cfg, &lw, compute && (split || fold.is_some()))(kernel.rs:489). The size guard below it now callswanted_plan(.., true), so it measures the same plan.New test:
a_folded_program_with_a_returning_atomic_takes_the_compact_form(compact_tests.rs) folds a GLCBUFFER_ATOMIC_ADDfollowed by 100 and then 200 copies of the branchy block (about 300 blocks or more). Without the change, the 100 more copies cost 3,220 B of DXIL. With it they cost 252 B.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T23:03:53Z.
Follow-up review of
fbac76fd, sincedaf3c1be(code reading only, not a merge-check) · 1 high, 1 nitIn short: This push makes two changes. A folded program is now chosen for the compact form the way a split one is: a branch-heavy program with a returning
BUFFER_ATOMIC_ADDtakes it in both forms. And a panic in the rewrite, which runs on the caller's thread, is now an error, so the split form takes over. Both have tests. Commits 1, 2, 3 and 5 are unchanged. The size still blocks it.High
XCL_WAVE64_FOLD=1, and the census.Nit
a_panic_in_the_rewrite_is_an_error_the_split_form_takes_over_from(fold_tests.rs) folds a VOP3v_cmp_eq_u32withVDST255 and expects "the rewrite panicked". Catching the panic is a reasonable safety net, sincecatch_unwindworks with the workspace's unwinding profile. But this known input should be refused by name infold, and the test should expect that refusal. Otherwise the default panic hook still prints a backtrace for it, and a later bug that panics looks the same in the log.Checked and fine
automatic_plannow getscompute && (split || fold.is_some()), and the refusal check useswanted_plan(.., true), so a folded program is planned as a split one is.a_folded_program_with_a_returning_atomic_takes_the_compact_formchecks that 100 more copies cost under a quarter of the DXIL of 100, and returns early whencompact_modeis forced.translate_foldedwraps onlyfold::foldincatch_unwind, maps a panic to an error, and keepsfold's own refusals as they were (??). The closure borrows onlycodeandcs, so no shared state is left half-written.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T23:16:48Z.
Thanks. At
2196dfd10:valu_copy(fold.rs:465) with "a compare into a constant".what_the_rewrite_does_not_cover_is_refused_with_its_reasonexpects that refusal; it fails without the check. The panic test is gone.catch_unwindintranslate_foldedstays as the safety net. After the check, 20 million random instruction words throughfoldraised no panic.AI use: Claude Code (Claude Opus 5.5) made the change and wrote this reply.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T23:18:30Z.
Follow-up review of
2196dfd1, sincefbac76fd(code reading only, not a merge-check) · 1 highIn short: This push fixes the nit from my last review. A VOP3 compare whose destination is a constant code (above
EXEC_HI), which overflowed the mask arithmetic, is now refused by name ("a compare into a constant"). The panic test is replaced by an assertion in the refusal test. Thecatch_unwindsafety net stays. Commits 1-5 are unchanged, and the size still blocks it.High
XCL_WAVE64_FOLD=1, and the census.Checked and fine
valu_copy(fold.rs) before the mask arithmetic, andwhat_the_rewrite_does_not_cover_is_refused_with_its_reasonexpects that reason. Destinations up toEXEC_HI(VCC, TTMP, M0, NULL, EXEC) still go the way they did.translate_foldedstill maps any other panic infoldto an error, so the split form takes over.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.