Recompiler: collapse 1-dword bindless waterfall loops #3643
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3643"
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 Kalmarv on 2026-12-02T02:58:28Z.
What is in it
Extends the direct-DXIL waterfall pass (
crates/xcl/src/gpu/dxil/waterfall.rs) to collapse 1-dword bindless descriptor-index waterfall loops into straight-line per-lane code alongside the existing 4-dwordS#sampler waterfall collapse, unifying both on per-laneV_READFIRSTLANE_B32lowering.V_READFIRSTLANE_B32/V_CMP(X)_EQ_U32/S_AND_SAVEEXEC(orS_ANDN2_WREXEC) /S_CBRANCH_EXECNZwaterfall loops. Because direct DXIL already represents SGPRs as per-lane SSA values and lowers dynamicSRSRC/SSAMPaccesses throughNonUniformResourceIndexheap handles, those loops add unnecessary ballots, quad reads, control-flow branches, and DXIL size.waterfall::collapsehandling both 4-dwordS#sampler waterfalls and 1-dword bindless descriptor-index waterfalls (wave32B32and wave64B64, bothWREXECandSAVEEXEC/XORforms, including nested outer/inner pairs viatry_merge_into_outer_header, clearingpc = u64::MAXon emptied merged blocks so PC-based lookups skip them).V_READFIRSTLANE_B32instructions in place asEXEC-masked per-lane copies (lower_valu.rs,sel(act, a, 0)) for both 4-dwordS#and 1-dword waterfalls so inactive lanes (EXEC=0) get0instead of uninitialized VGPR keys. All fourS#words (s[sb..sb+3]) remain valid per lane (including formimg_gather4_lod), removingLw::waterfall_ssampandmimg_s3inlower_image.rs.Entry::Kernelinkernel.rssostore_registerslane-0 register dumps ats_endpgmkeep exact HLSL parity.leadersinkernel.rssorecomp::constant_samplerskeeps branch-following even when a collapsed loop strips leading noops or merges an inner block.V_READFIRSTLANE_B32PCs from split-wave64mask_exchangeEXECdemand,may_meet, andlane_readtracking, taints SGPRs derived from collapsedV_READFIRSTLANE_B32s inmask_exchange::known_stepandidioms::uniform_reads_with_rflso post-waterfall VGPR reads are never misclassified as wave-uniform orHow::OwnFirst, and addswaterfall_rfl_per_lanetocompact.rsblock deduplication keys.ENC_SMEMloads (GLC=1orDLC=1), RMW/loop-carried scalar dependencies (S_ADDK_I32,S_MULK_I32,S_CMOV*,S_BITSET*),ENC_VOP2OPR_VCCreads/writes (V_CNDMASK_B32,V_ADD/SUB*_CO_CI_U32), upward-exposedSCCormask_reg/iter_regreads, invalidENC_VOP3compare destinations (EXEC_LO,NULL,M0, or unaligned 64-bit pairs), VOPC VGPR-vs-VGPR compares inmatch_vcmp_eq_u64, live-out temporaries, or intra-block reads ofsave_reg/rem_reginpre[pos+1..].+2242/-294across 8 files (+130/-64across the 7 wiring files,+2112/-230inwaterfall.rs). Insidewaterfall.rs, 1291 lines are unit, DXIL validation, and RTX 5070 Ti GPU parity/regression tests, and 1067 total non-test lines cover the unified 4-dword + 1-dword matcher, liveness/soundness guards, and nested-merge rewriter. Keeping the matcher, soundness guards, wiring, and tests in one commit ensures the pass is never partially wired or missing its guards.Tested
rustc 1.99.0 (b940084d7 2026-09-28), DXC1.9.2609.5(debug + release).cargo build --release -p xcl: clean (39warnings — identical toorigin/main5eaadb54c, 0 new warnings).scripts/test.ps1(cargo build --workspace,cargo bench -p xcl --bench '*' -- --test,cargo test --workspace -- --test-threads=4, withXCL_DXC_DIRset to DXC1.9.2609.5): 2982 passed, 0 failed, 52 ignored across 43 test targets (24 SKIPPED GPU tests on this adapter: 22no wave64, 2no heap windows).gpu::dxil::waterfall::tests(11/11 passing, 0 skipped):collapses_sampler_waterfall_self_loop_and_preserves_s3_vgprrefuses_collapse_when_waterfall_sgpr_is_live_outcollapsed_waterfall_translates_and_validates_direct_dxilcollapses_nested_1dword_bindless_waterfall_pairrefuses_1dword_collapse_on_loop_carried_accumulator_or_live_out_sgpr(accumulator and live-out SGPR refusal)collapses_1dword_saveexec_xor_and_wave32_b32_forms(wave64SAVEEXEC/XOR+FallExec::Ends,Entry::Kernelskip for register-dump parity, jump-hop fallthrough exit, wave32B32WREXEC+GLOBAL_LOAD_DWORDunderENC_FLAT_GLBL, wave32B32SAVEEXEC/XOR)refuses_1dword_collapse_on_soundness_edge_cases(GLC/DLCSMEM,V_CNDMASK_B32/V_ADD_CO_CI_U32OPR_VCC, RMWS_ADDK_I32/S_CMOV_B32,iter_regread, upward-exposedSCCread, unaligned/EXEC_LOV_CMP_EQ_U32SDST, VOPC VGPR-vs-VGPRV_CMP_EQ_U64refusal, intra-blocksave_regread inpre[pos+1..], andpc == u64::MAXon emptied merged blocks when the outer loop refuses collapse)split_wave64_post_waterfall_readfirstlane_is_not_uniform_or_own_first(provesmask_exchange::known_stepandidioms::uniform_reads_with_rfldo not classify post-waterfallv_readfirstlane_b32reads of VGPRs loaded/moved from per-lane waterfall SGPRs asHow::OwnFirstoruniform_reads, and that split-wave64 DXIL emits a cross-half barrier)gpu_nested_1dword_bindless_waterfall_matches_uncollapsed(renders 8 distinct 2x1 textures × 2 CLAMP/WRAP samplers across an 8x8 RT on RTX 5070 Ti withx==0pixels masked toEXEC=0and garbage0x7FFF_FFE0keys; bit-for-bit identical to uncollapsed with 0quadReadLaneAtand 0waveReadLaneFirst)gpu_4dword_sampler_waterfall_gather4_lod_uses_all_four_words(renders a collapsed 4-dwordS#waterfall withIMAGE_GATHER4_Lwhere lanes share S# word 3 =0and differ only in S# word 0 CLAMP vs WRAP; bit-for-bit identical to uncollapsed with 0quadReadLaneAtand 0waveReadLaneFirst)gpu_static_sampler_retained_across_collapsed_waterfall_and_branch(2x1 texture atu=1.25, static CLAMP vs heap slot 0 WRAP across a collapsed waterfall + zero-offsets_branch; verified it fails with 0 static bindings when post-collapseleadersare rebuilt and passes with 1 static binding and red22.0across all 16 pixels with the fix).Regression run
Baseline (
main):PR head:
Not tested
XCL_HEAP_WINDOWS=1GPU tests (2 skipped under defaultscripts/test.ps1).AI use
origin/main(5eaadb54c), implemented all review fixes acrosswaterfall.rs,kernel.rs,lower.rs,lower_image.rs,lower_valu.rs,mask_exchange.rs,idioms.rs, andcompact.rs, added the unit and GPU regression tests, ran the build/test/smoke checks, and updated this description.Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T08:39:03Z.
Diff review (head
a28f48f69, read-only code review — not a#3041merge-check):Strong perf/memory win on bindless waterfall collapse, and the
compact.rs,mask_exchange.rs, andlower_valu.rswiring looks clean. Reading the full diff incrates/xcl/src/gpu/dxil/waterfall.rsturned up 5 soundness edge cases worth fixing before merge:Split-wave64
GLC=1/DLC=1SMEM loads corrupt upper-half lanes32..63(crates/xcl/src/gpu/dxil/waterfall.rs:442):is_pure_waterfall_body_instadmits allS_LOAD_DWORD*/S_BUFFER_LOAD_DWORD*without rejectingGLC=1orDLC=1. Incrates/xcl/src/gpu/dxil/lower_mem.rs:1295-1303,if self.split && coherentexchanges lane 0–31's loaded values into lanes 32–63 assuming the load is wave-uniform. Once collapsed,s_keyis per-lane, so coherent SMEM loads in split-wave64 compute/mesh silently overwrite lanes 32–63 with lanes 0–31's values. RejectingGLC == 1 || DLC == 1inENC_SMEMinsideis_pure_waterfall_body_instcloses this.ENC_VOP2OPR_VCCoperands (V_CNDMASK_B32,V_ADD_CO_CI_U32,V_SUB_CO_CI_U32,V_SUBREV_CO_CI_U32) are invisible toscalar_uses_defs(crates/xcl/src/gpu/dxil/waterfall.rs:128,:495):In
rdna2_spec.rs, theseENC_VOP2instructions encodeOPR_VCCwithfield: None, implicit: false.rdna2::sgpr_usesskipsfield: None(rdna2.rs:550) andscalar_uses_defsonly inspectso.implicit, so bothsusesandsdefscome back empty. That lets carry-in/out ops passsdefs.is_empty()(waterfall.rs:495) and hidesVCCreads/writes fromscalar_live_in(so Style 2 deletingV_CMP_EQ_U32 vcc, ...feeds staleVCCtoV_CNDMASK_B32/ carry-in ops and misses clobbering live-outVCC). Scanning all operands witho.field.is_none()(not justo.implicit) forVCC/SCC/EXECfixes both.Read-modify-write scalar ops (
S_ADDK_I32,S_MULK_I32,S_CMOVK_I32,S_CMOV_B32,S_CMOV_B64) bypass the loop-carried accumulator check (crates/xcl/src/gpu/dxil/waterfall.rs:128,:460):In
rdna2_spec.rs,SDSTon these instructions hasinput: false, output: true, sordna2::sgpr_usesrecordsSDSTonly insdefs, notsuses. Sinceis_pure_waterfall_body_installowsENC_SOPKandENC_SOP1(waterfall.rs:460), a loop-carried accumulator likeS_ADDK_I32 s8, 1does not appear inupward_used_scalarsand collapses into a single iteration. TreatingSDSTon these RMW ops as both read and written inscalar_uses_defs(or rejecting them inis_pure_waterfall_body_inst) prevents this.Style 2 omits
mask_reg,iter_reg, andSCC_REGfromis_forbidden_reg/s_keyoverlap checks (crates/xcl/src/gpu/dxil/waterfall.rs:267,:747,:781-820):is_forbidden_regchecksEXECandrem_reg(Style 1), but omits Style 2'siter_regandmask_reg(unliketry_collapse_4dword_sampler), allowing body ops to read/writeiter_regor readmask_regset by the deletedV_CMP_EQ_U32, ormask_reg/iter_regto overlaps_key.match_vcmp_eq_u32(waterfall.rs:267) does not rejectENC_VOP3SDST == EXEC_LO (126)/NULL (125)or unaligned 64-bit pairs.upward_used_scalarscontainsSCC_REG(e.g.S_CSELECT_B32/S_ADDC_U32/S_CMOV_*), even though deletingS_AND_SAVEEXEC/S_ANDN2_WREXECchangesSCCseen by the body from1back to the pre-loop value.try_merge_into_outer_headerdeletess_mov s[save/rem], execinprewithout checking intra-block reads inpre[pos+1..](crates/xcl/src/gpu/dxil/waterfall.rs:402,:900-930):find_tail_save_from_execchecks that nothing inpre[pos+1..]writesregorEXEC, andis_dead_after_prechecks onlypost_live[b](afterpre). If an instruction inpre[pos+1..]readssave_regorrem_reg, deleting thes_movleaves that read undefined. Checking thatpre[pos+1..]has no reads ofreg..reg+widthfixes this.Minor note:
is_pure_waterfall_body_inst(waterfall.rs:456) checksn.starts_with("GLOBAL_LOAD_")under"ENC_FLAT", whereasGLOBAL_LOAD_*uses"ENC_FLAT_GLBL"(conservative only — misses matches rather than miscompiling).AI use: Antigravity (Gemini 4 Neon) audited the full diff against
mainand drafted this review.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T08:45:37Z.
Review (head
a28f48f6, diff read, not a merge-check):kernel.rs ~330now rebuildsleadersfrom the blocks afterwaterfall::collapse, and onlyconstant_samplers(kernel.rs ~797) uses it. That analysis reads the original linearcfg.insts, where the removeds_cbranch_execnzis still there. A 4-dword collapse removes the loop head (the firstv_readfirstlane) from the block, and a nested merge emptiesb. Either way the branch target is no longer a leader,at.get(&t)?(recomp/mod.rs ~1863) returns None for the whole program, and it falls back to reading block by block. A static S# set before the loop and sampled in a later block then goes through the heap atword3 & 0x7FF, so the wrong sampler is used. On main the leaders come from before the collapse. Keeping those (dropping the secondlet leaders) avoids this.try_collapse_4dword_samplerstill removes the fourv_readfirstlaneand records onlyvb + 3(waterfall.rs ~605), and this PR leaveslower_image.rsunchanged. Somimg_gather4_lodstill reads S# words 0-2 from the SGPRs nothing writes anymore (lower_image.rs ~513), and gathers stay allowed in the body (~445). #3663 changes the value tovband readsv[vb+k]. If this PR lands after #3663 without switching tovb, every collapsed sampler readsv[vb+3+k], word 3 (the heap index) included. A simpler fix is to do what the 1-dword path already does: keep the fourv_readfirstlaneas per-lane copies, sos[sb..sb+3]are right per lane andssamp_vgpris no longer needed.v_cmp_eq_u32ands_and_saveexecare dropped. A body instruction that readsmask_reg(often VCC, e.g.v_cndmask_b32),iter_regor SCC passesis_pure_waterfall_body_inst, andupward_used_scalarsis compared only with the body's own definitions (waterfall.rs ~830). After the collapse that instruction reads the value from before the loop. Separately, a GLCs_loadis accepted (~442), but in split wave64smemgives the upper half the lower half's values through one slot per half (lower_mem.rs ~1297). That is wrong once the address depends on the per-lane key.FallExec::Ends/jump-hop exits, or refusal when a temporary is live out.refuses_1dword_collapse_on_loop_carried_accumulator_or_live_out_sgprtests only the accumulator.compact.rskey fix for the collapse already on main (#3663 has the same fix), the rewrite of the 4-dword matcher, the single-loop 1-dword collapse, and the nested merge that rewrites the CFG (try_merge_into_outer_header). The single-loop collapse works and can be tested without the merge.Fine: dynamic T#/S# heap handles are already created with
NonUniformResourceIndex(lower_image.rs), and SMEM addresses go through per-lane window selection, so a per-lane key gives a correct per-lane descriptor. The EXEC entry state is checked (preheader_inits_reg_from_exec). Cross-lane VALU, writes and LDS are rejected. Collapsedv_readfirstlaneis now part of the compact key, and mask_exchange no longer counts it as an EXEC reader.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-02T10:51:38Z.
merge-check
base:
1c8b551475head:
a28f48f698merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2912 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/3643#issuecomment-7339889467 and its findings stand. Most serious: rebuilding
leadersafter the collapse breaks branch following inconstant_samplers, so the wrong static sampler can be used.performance: 60 s smoke of a retail title, main
1c8b5514vs this merge (a28f48f6): 1652 -> 1685 frames shown (101 %; last presents per 2 s: 60 60 60), peak commit 18228 -> 16136 MB, 0 device removals, 0 crashes.verdict: not yet: rebuilding
leadersafter the collapse breaks branch following inconstant_samplers, so the wrong static sampler can be used (see the review)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 Gevroska on 2026-12-02T13:26:13Z.
I reproduced the static-sampler issue on an RTX 3080. I ran the same synthetic pixel shader on base
1c8b5514and PR heada28f48f6. It samples a two-texel texture atu = 1.25: the static clamp sampler returns red22, while heap slot zero uses wrap and returns11. I waited for the GPU fence and read back all 16 pixels.1c8b5514a28f48f622222211All 16 pixels agreed in each case. The head drops the static binding and samples the wrap texel. Both test processes passed because the fixture checks the pixel value expected from the binding it observes. For a regression test, I’d assert that this shader retains its static binding and returns
22.This covers the uniform, single-iteration case on driver
32.0.16.1692. I didn’t test divergent loops or retail game rendering. OpenAI Codex GPT-6 Sol (Daybreak) wrote and ran the GPU fixture, a separate GPT-6 Sol agent reviewed the source and logs, and GPT-6.2 Sol verified the saved results. GPT-6.2 Astra drafted this comment.I reviewed and approved this comment before posting.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T14:47:25Z.
Rebased onto
main(5eaadb54c) and updated to9c903a2e7, addressing all points from @Gevroska, @Foniass, and @Decodere:leadersregression (@Foniass, @Gevroska): Dropped the secondlet leadersafterwaterfall::collapseincrates/xcl/src/gpu/dxil/kernel.rssorecomp::constant_samplerskeeps pre-collapse CFG leaders and branch following. Addedgpu_static_sampler_retained_across_collapsed_waterfall_and_branch(2x1 texture atu = 1.25, static CLAMP vs heap slot 0 WRAP across a collapsed waterfall + zero-offsets_branch, asserting 1 static binding and red22.0across all 16 pixels) — verified it fails (0static bindings) with post-collapseleadersrestored and passes with the fix.S#stale words 0–2 /#3663conflict (@Foniass): Updatedtry_collapse_4dword_samplerto keep all fourV_READFIRSTLANE_B32instructions as per-lane copies (rfl_per_lane), matching the 1-dword path sos[sb..sb+3]stay valid per lane (including formimg_gather4_lod). RemovedLw::waterfall_ssampandmimg_s3(lower.rs,lower_image.rs,compact.rs).GLC == 1 || DLC == 1onENC_SMEMloads inis_pure_waterfall_body_instandtry_collapse_4dword_sampler.scalar_uses_defsto inspect allo.field.is_none()operands (not onlyo.implicit) forVCC/SCC/EXEC(fixingENC_VOP2V_CNDMASK_B32andV_ADD/SUB*_CO_CI_U32) plus inlineVCCZ/EXECZ/SCCcodes.SDSTops (S_ADDK_I32,S_MULK_I32,S_CMOVK_I32,S_CMOV_B32,S_CMOV_B64,S_BITSET*) as both read and written inscalar_uses_defs.mask_reg,iter_reg, andEXEC_HItois_forbidden_reg, refused upward-exposedSCC_REGreads, and validatedmatch_vcmp_eq_u32/match_vcmp_eq_u64/iter_reg/mask_regagainstM0/NULL/EXECand unaligned 64-bit pairs.pre[pos+1..]for intra-block reads ofsave_reg/rem_reg(has_read_in_tail) before deletings_movintry_merge_into_outer_header, and added"ENC_FLAT_GLBL"forGLOBAL_LOAD_*.#3655inmask_exchange.rs, excludingrfl_per_lanefromuses,may_meet, andlane_readas well as checkingwaterfall_rfl_per_lanefirst inlower_valu.rs.SAVEEXEC/XOR+FallExec::Ends, wave32B32forms +GLOBAL_LOAD_DWORD, live-out SGPR refusal, all 5 soundness edge cases, and the static-sampler GPU regression test. Updated the commit trailer (Assisted-by: Antigravity (Gemini 4 Neon)) and PR AI use consistently, and updated the size rationale and fresh 60 s smoke pair (5eaadb54cvs9c903a2e7) in the PR description.AI-written reply (Antigravity, Gemini 4 Neon).
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T18:00:23Z.
Code review location:
crates/xcl/src/gpu/dxil/lower_valu.rs; line 1057Critical: Not certain about this one: a collapsed
v_readfirstlane_b32is lowered as a per-lane copy for every lane, including lanes with EXEC=0, while scalar SMEM loads and descriptor-heap index math aren't EXEC-guarded. Inactive lanes now compute descriptors from their own, possibly uninitialized,v_keyinstead of the first active lane's valid key. In a pixel or compute wave with EXEC narrowed before the waterfall (killed, helper or never-launched lanes whosev_keyVGPR was never written), those lanes runs_load_dwordx8 s[t], s[base], s_keywith a garbage offset and build a NonUniformResourceIndex from a garbage descriptor. Before, the real readfirstlane gave every lane an active lane's in-range key. The result is an out-of-range heap index: undefined behaviour and possible device removal. Selecting the key from an active lane for inactive lanes (or keeping the readfirstlane for them) would avoid it.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T18:00:23Z.
Code review location:
crates/xcl/src/gpu/dxil/waterfall.rs; line 389Medium:
FallExec::Endsandscalar_live_in(Term::End => empty) assume no scalar register is observable at program end, but for Entry::Kernelstore_registers(kernel.rs:1104) dumps EXEC, VCC and every touched SGPR from lane 0 after the program. In a kernel-mode program whose waterfall falls straight through tos_endpgm, the uncollapsed dump shows EXEC=0 ands_key/remas of the last iteration, while the collapsed one shows EXEC = the entry mask,rem= the initial exec ands_key= lane 0's own key. Kernel-mode register dumps of such shaders then diverge from the HLSL path. Treating the dumped registers as live at End for kernels would keep them equal.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T18:00:23Z.
Review: COMMENTED
Review of
9c903a2e: 3 finding(s) (1 critical, 1 high, 1 medium), most severe first.crates/xcl/src/gpu/dxil/lower_valu.rs:1057: Not certain about this one: a collapsedv_readfirstlane_b32is lowered as a per-lane copy for every lane, including lanes with EXEC=0, while scalar SMEM loads and descriptor-heap index math aren't EXEC-guarded. (inline)crates/xcl/src/gpu/dxil/waterfall.rs:286: see below.crates/xcl/src/gpu/dxil/waterfall.rs:389:FallExec::Endsandscalar_live_in(Term::End => empty) assume no scalar register is observable at program end, but for Entry::Kernelstore_registers(kernel.rs:1104) dumps EXEC, VCC and every touched SGPR from lane 0 after the pr.... (inline)On lines outside the diff:
crates/xcl/src/gpu/dxil/waterfall.rs:286: Inmatch_vcmp_eq_u64(used for the 4-dword match), the swapped-operand test(s1 == s_base && s0 == 256 + v_base)also applies to VOPC, where VSRC1 is a raw VGPR index, so a VGPR-vs-VGPR compare is accepted as the S#-vs-VGPR waterfall compare. Afterv_readfirstlane s[8..11], v[85..88], a VOPCv_cmp_eq_u64 vcc, v[85:86], v[8:9](SRC0=256+85, VSRC1=8) matchessb=8, vb=85. That loop isn't a waterfall over s[8..11], yet it's collapsed to one pass and the iterations the compare controlled are dropped. Checking the encoding (VOPC's VSRC1 is a VGPR, not an SGPR) before accepting the swapped form would fix it.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-02T18:00:28Z.
@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-02T18:01:15Z.
merge-check
base:
5eaadb54c1head:
9c903a2e76merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2980 passed, 0 failed, 52 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: follow-up on
9c903a2e(reworked and rebased froma28f48f6, my last review's head). Still one commit, now +1783/-263. The 4-dword S# path now keeps its fourv_readfirstlaneas per-lane copies like the 1-dword path, soLw::waterfall_ssamp/mimg_s3are gone andlower_image.rsreadss[ssamp..ssamp+3](~506, ~701, ~1251, ~1436);kernel.rsno longer rebuildsleadersafter the collapse; the 1-dword matcher gained more refusals and tests; AI use names the model. Earlier findings: (1) static samplers losing branch following: fixed;leaderscomes from the CFG before the collapse again (kernel.rs~341), covered bygpu_static_sampler_retained_across_collapsed_waterfall_and_branch. (2) stale S# words 0-2 in the 4-dword path: fixed in the code (try_collapse_4dword_samplerkeepsactive[..4],waterfall.rs~752), but open #3663 fixes the same bug another way and a test merge of the two heads conflicts incompact.rs,lower.rs,lower_image.rsandwaterfall.rs; and no test checks the result (collapses_sampler_waterfall_self_loop_and_preserves_s3_vgpronly checks the returned PC set; nothing covers a gather or S# words 0-2 after a collapse). (3) loop-head values in the 1-dword body: fixed;mask_reg,iter_reg,rem_regand EXEC are refused (~857), an upward-exposed SCC read is refused (~906), GLC/DLC SMEM is refused (~497), with tests. (4) tests: partly fixed; SAVEEXEC/XOR, wave32 B32,FallExec::Ends, the live-out refusal and edge cases are covered, plus a GPU parity test of the nested pair (wave64 without split, NVIDIA only); the jump-hop exit infind_fallthrough_exec_restore(~362) and the 4-dword gather case are untested. (5) size: still open and grown: one commit with about 860 non-test lines bundling four parts that could be separate PRs (the 4-dword S# fix, i.e. the #3663 duplicate; the rewritten 4-dword matcher; the single-loop 1-dword collapse; and the nested-merge CFG rewrite intry_merge_into_outer_header, ~965-1063). New: when the outer loop can't be collapsed,try_merge_into_outer_headerstill deletes the inners_mov exec, s[save]and merges three blocks intopre(sound given its checks), but leaves empty, unreachable blocks that keep theirpcincfg.blocks, whichpclookups such asidioms::entry_atstill see; no test covers a merge without an outer collapse. The 1-dword collapse is on by default for every title (off withXCL_WATERFALL_COLLAPSE=0); split wave64 is checked only by DXIL validation, and AMD / wave64 hardware wasn't tested. Fine: a per-lanev_readfirstlaneis excluded from the mask-exchange EXEC demand,may_meetandlane_readand is part of the compact key; RMW SOPK / CMOV / BITSET count as reads; live-out temporaries andsave_regclobbers are refused; the XOR form can't change EXEC after the restore.performance: 60 s smoke of a retail title, main
5eaadb54vs this merge (9c903a2e): 1422 -> 1659 frames shown (116 %; last presents per 2 s: 61 60 60), peak commit 17184 -> 16369 MB, 0 device removals, 0 crashes.verdict: not yet: the 4-dword S# fix duplicates open #3663 (they conflict) and has no test that checks the result, bundled with the new 1-dword / nested collapse in one ~1780-line commit that could be split (see the review)
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 Kalmarv on 2026-12-02T18:24:40Z.
Updated to
6f6cbd380addressing all findings from @bmjask and @Foniass:EXEC=0) in collapsedv_readfirstlane_b32(@bmjask, Critical): Masked the per-lane copy withself.act()(lower_valu.rs:sel(act, a, 0)) so lanes withEXEC=0receive0instead of uninitialized VGPR keys, and tightenedsafe_tw0inlower_image.rsfromsel(valid, tw0, 0)tosel(run, tw0, 0)(run = act && valid) so inactive lanes in implicit-LOD pixel samples andget_lodalways index null SRV slot 0. Extendedgpu_nested_1dword_bindless_waterfall_matches_uncollapsedto maskx==0pixels toEXEC=0with garbage0x7FFF_FFE0keys and verify bit-for-bit parity with uncollapsed output.match_vcmp_eq_u64(@bmjask, High): RestrictedENC_VOPCinmatch_vcmp_eq_u64(waterfall.rs) to the non-swappedSRC0 == s_base && VSRC1 == v_baseform (sinceVSRC1is always a raw VGPR index), keeping the swapped form only forENC_VOP3. Added a regression test rejectingv_cmp_eq_u64 vcc, v[85:86], v[8:9](SRC0=256+85, VSRC1=8).Entry::Kernelregister-dump parity ats_endpgm(@bmjask, Medium): Skippedwaterfall::collapsewhenkernel(Entry::Kernel) inkernel.rssostore_registersdumps ofEXEC,VCC,SCC, and touched SGPRs remain exact with the HLSL path, and added a test checking thatEntry::Kernelstays uncollapsed whileEntry::Computecollapses.S#gather test, jump-hop exit test, emptied block PCs, and#3663(@Foniass):gpu_4dword_sampler_waterfall_gather4_lod_uses_all_four_words: a GPU parity test on a collapsed 4-dwordS#waterfall withIMAGE_GATHER4_L(mimg_gather4_lod) where lanes share S# word 3 =0and differ only in S# word 0 (CLAMP vs WRAP), asserting 0quadReadLaneAt/0waveReadLaneFirstand bit-for-bit parity with uncollapsed output.s_nop; s_branch->s_mov_b64 exec, s[32:33]) incollapses_1dword_saveexec_xor_and_wave32_b32_forms.cfg.blocks[b].pc = u64::MAXandcfg.blocks[fallthrough].pc = u64::MAXintry_merge_into_outer_headerso PC lookups (idioms::entry_at) skip emptied blocks, with a test covering a merged inner loop whose outer loop refuses collapse.#3663: this PR includes the unified per-lanerfl_per_lane4-dwordS#fix (so it supersedes#3663; if#3663lands first, I can rebase cleanly onto it).Re-verified on
6f6cbd380(RTX 5070 Ti, DXC 1.9.2609.5):cargo build --release -p xclclean (39 warnings, 0 new),scripts/test.ps12981 passed, 0 failed, 52 ignored (24 SKIPPED: 22no wave64, 2no heap windows), and fresh 60 s smoke (1392 -> 1697frames shown,60 61 63presents/2s,16644 -> 16007 MBpeak commit, 0 removals, 0 crashes).AI-written reply (Antigravity, Gemini 4 Neon).
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T18:39:35Z.
Review: COMMENTED
Review of
6f6cbd38: 3 finding(s) (2 high, 1 medium), most severe first.Re-review at
6f6cbd38. The three findings from the9c903a2ereview (inactive lanes using their ownv_keyafter the collapse, the VOPC swapped-operand match, kernel-mode register dumps at End) weren't flagged again at this head and look addressed. The findings below are new, and the first, second and fourth come from the changes made to address them.crates/xcl/src/gpu/dxil/mask_exchange.rs:526: see below.crates/xcl/src/gpu/dxil/lower_image.rs:1158:safe_tw0changed fromsel(valid, tw0, 0)tosel(run, tw0, 0)for every image op, not only collapsed waterfalls, so in the unguarded implicit-LOD paths (unorm_body/sample_body/get_lod) lanes outside EXEC now use heap slot .... (inline)crates/xcl/src/gpu/dxil/waterfall.rs:1007: see below.On lines outside the diff:
High
crates/xcl/src/gpu/dxil/mask_exchange.rs:526: After a collapse, SGPRs written in the waterfall body hold a different value in each lane, but the split-wave64known_stepstill treats a VALU or buffer load with no VGPR inputs, run under the launch EXEC, as giving one value in every lane (k.all). A laterv_readfirstlaneof that VGPR is then lowered asHow::OwnFirst, where each 32-lane half reads its own first lane. Take a wave64 split compute shader with full EXEC and a top-level 1-dword waterfalls_load_dwordx4 s[8:11], s[0:1], s_key; buffer_load_dword v5, off, s[8:11], 0, followed after the loop byv_readfirstlane_b32 s9, v5. Before the collapse, the V_CMPX narrowed EXEC, so v5 wasn't 'known'. Now v5 lands ink.all, and the upper half gets its own first lane's v5 instead of console lane 0's, so the result is wrong whenever the keys differ between the halves.rfl_per_laneis threaded through the exchange helpers but not throughknown_step.Medium
crates/xcl/src/gpu/dxil/waterfall.rs:1007:try_merge_into_outer_headerdeletes the fallthrough'ss_mov exec, s[save]and mergespre + b + fallthroughinto one block, butidioms::uniform_readsresets its uniform-VGPR set only per block and on EXEC writes. So VGPRs computed in the collapsed body from per-lane SGPRs now look uniform to a laterv_readfirstlanein the merged block. In a nested waterfall where the collapsed inner body doesv_mov_b32 v5, s_t0and the inner fallthrough later hasv_readfirstlane_b32 s9, v5, the read lands inuniform_reads. In split wave64,read_first_lane_uniformthen reads each half's own first lane, so the upper half gets its own per-key value instead of the wave's first lane's.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-02T18:39:35Z.
Code review location:
crates/xcl/src/gpu/dxil/lower_image.rs; line 1158High:
safe_tw0changed fromsel(valid, tw0, 0)tosel(run, tw0, 0)for every image op, not only collapsed waterfalls, so in the unguarded implicit-LOD paths (unorm_body/sample_body/get_lod) lanes outside EXEC now use heap slot 0 instead of the shader's own valid, wave-uniform T#. For a non-waterfall UNORMimage_sampleinside a divergent branch in a pixel shader, the inactive lanes of a quad take slot 0's dimensions, so their normalized coords are u/dims0 while active lanes use u/dimsA. The quad derivatives, and so the active pixels' mip/LOD, come out wrong. On the non-UNORM path, if slot 0 is a different resource type thankind(e.g. Texture3D vs Texture2D), those lanes access a mismatched descriptor, which is undefined behaviour and can hang some drivers. Limiting therunselect to collapsed waterfalls would keep the old behaviour elsewhere.Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T19:05:24Z.
Updated to
e56629641addressing all three findings from @bmjask's re-review of6f6cbd38:mask_exchange::known_stepuniformity tracking across collapsed waterfalls (High): Addednon_uniform_sgpr: u128toKnown(mask_exchange.rs), threadedrfl_per_lanethroughknown/known_step, tainted SGPRs written by collapsedv_readfirstlane_b32s and propagated taint through scalar ops/loads (including RMW scalarSDSTops), and gatedsame(VALU andBUFFER_LOAD_DWORD) plusHow::LaneBitscalar checks on!reads_non_uniform. Post-waterfallv_readfirstlane_b32reads of VGPRs loaded through per-lane descriptors are no longer misclassified asHow::OwnFirst.safe_tw0inlower_image.rs:1158(High): Revertedsafe_tw0back toself.sel(valid, tw0, z0)so non-waterfall implicit-LOD pixel samples andget_lodpreserve exact quad-derivative and descriptor behavior on inactive lanes (collapsed waterfalls remain guarded bysel(act, a, 0)onv_readfirstlane_b32inlower_valu.rsandself.guarded(run, ...)on non-implicit-LOD image ops).idioms::uniform_readsaftertry_merge_into_outer_header(Medium): Addedidioms::uniform_reads_with_rfl(cfg, rfl_per_lane)(idioms.rs), trackingnon_uniform_sgprs: u128through collapsedv_readfirstlane_b32s and scalar ops/loads so VGPRs derived from per-lane waterfall SGPRs in merged blocks are not marked uniform for laterv_readfirstlane_b32reads.split_wave64_post_waterfall_readfirstlane_is_not_uniform_or_own_firstinwaterfall.rscovering both thes_load_dwordx4+buffer_load_dword->v_readfirstlane_b32(known_step+ split-wave64 DXIL cross-half barrier) and nested merged-blockv_mov_b32 v5, s_t0->v_readfirstlane_b32(uniform_reads_with_rfl) cases.Re-verified on
e56629641(RTX 5070 Ti, DXC 1.9.2609.5):cargo build --release -p xclclean (39 warnings, 0 new),scripts/test.ps12982 passed, 0 failed, 52 ignored (24 SKIPPED: 22no wave64, 2no heap windows), and fresh 60 s smoke (1392 -> 1647frames shown,60 60 60presents/2s,16644 -> 16176 MBpeak commit, 0 removals, 0 crashes).AI-written reply (Antigravity, Gemini 4 Neon).
Imported from ivall/xcl. Originally posted by jsalzy on 2026-12-03T00:46:48Z.
merge-check claim
head:
e56629641cImported from ivall/xcl. Originally posted by jsalzy on 2026-12-03T00:59:02Z.
merge-check
base:
078358a058head:
e56629641cmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3014 passed, 0 failed, 52 ignored (44 test binaries); SKIPPED: 25 (22 no wave64 on this GPU; 2 no heap windows (opt-in XCL_HEAP_WINDOWS=1); 1 driver cache cannot be disabled without Windows Developer Mode); failing: none. All 8 tests the PR adds ran and passed, the 3 GPU ones included (none skipped). git diff --check clean; 39 compiler warnings, the same as main.
title run: not run
review: (1) Overlap with open #3663, which fixed this bug first: after #3500's collapsed 4-dword sampler waterfall, MIMG reads of S# words 0-2 (the emulated gather4 LOD path) got stale SGPRs. #3663 (opened 05:53Z, head
0324e7ce) reads those words from the lane's v[vb+k]. This PR (its fix came in at9c903a2e, 14:47Z) keeps the four v_readfirstlane as per-lane copies, so s[sb..sb+3] stay valid and Lw::waterfall_ssamp / mimg_s3 go away. Same bug, different approach, not the same change. Merged together they conflict in compact.rs, lower.rs, lower_image.rs and waterfall.rs, so only one of the two fixes should land. This PR's fix is now tested (gpu_4dword_sampler_waterfall_gather4_lod_uses_all_four_words). (2) Size: one commit with about 1,135 non-test lines (waterfall.rs +1,005 non-test, +1,107 tests). It bundles the S# fix of (1), the rewritten 4-dword matcher, the 1-dword collapse and the nested merge (try_merge_into_outer_header, waterfall.rs:970-1067); Foniass's earlier point still applies. (3) Missing tests: the jump-hop exit of find_fallthrough_exec_restore (waterfall.rs:363, up to 4 empty Jump hops) and a nested merge whose outer loop then doesn't collapse are not covered. No test program has an S_BRANCH, and the nested test collapses both loops. (4) Scope: the collapse is on by default for every non-kernel shader of every title (off with XCL_WATERFALL_COLLAPSE=0). The GPU parity tests ran here on NVIDIA only, and this PC has no wave64, so split wave64 is covered only by the translation and validation tests; no AMD run here (the PR is gpu:both). Main doesn't key translations on XCL_WATERFALL_COLLAPSE (open #3621 adds that), so turning the collapse off doesn't retranslate shaders already in the cache. (5) Open #3728 (same author) adds code that reads Lw::waterfall_ssamp, which this PR removes; the two conflict in lower_image.rs. Open #3621 also conflicts with this PR in waterfall.rs (the XCL_WATERFALL_COLLAPSE check). Checked and fine: the 1-dword matcher refuses loop-carried scalars, upward SCC reads, EXEC / mask / iter / rem registers in the body, GLC or DLC SMEM, anything outside a strict whitelist (no stores, LDS, atomics, lane ops or DPP), and any clobbered SGPR that is live into the fallthrough or overlaps the EXEC save. The EXEC restore must be the fallthrough's first non-noop instruction, so nothing sees the changed EXEC. The nested merge removes the inner restore only when the outer header saved that register from EXEC with no later write. Per-lane SGPRs never leave their block, so the per-block non-uniform taint in idioms.rs is enough, and mask_exchange carries it across blocks. Inactive lanes get 0 (lower_valu.rs ~1056). Entry::Kernel skips the collapse. The direct translator's cache key includes the hash of its sources, so translations from before this change aren't reused. Duplicates: I searched open and merged PRs for waterfall collapse, bindless waterfall, readfirstlane waterfall, waterfall.rs, waterfall_ssamp, try_merge_into_outer_header, rfl_per_lane, XCL_WATERFALL_COLLAPSE and S_CBRANCH_EXECNZ waterfall, and checked #1607's groups (none lists 3643 or 3663). Result: #3663 overlaps in part as in (1); #3728 and #3621 touch the same code but make different changes.performance: On by default (reasoned, not measured here): it removes the loops, ballots and branches of these waterfalls from translated shaders, so GPU work and DXIL size go down. Translation does one liveness pass over the CFG per collapsed loop, plus one per nested merge, so translation time grows with the number of waterfalls in a shader.
verdict: safe to merge as code: no blocking finding, the suite passes, and the PR's GPU tests pass on NVIDIA. Its S# word fix overlaps open #3663, which fixed the same bug first in another way, and the two conflict (review (1)): only one of them should land.
hardware / tool and model: RTX 4070 SUPER 12 GB (621.24 / 32.0.16.2124), Ryzen 7 7800X3D, 32 GB, Windows 11 Pro 25H2 26200.9974, Rust 1.100.0, debug / Claude app (Claude Opus 5.5): merge, build and suite run on this PC with git and cargo only; diff review by Claude Opus 5.5.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T14:07:24Z.
merge-check
base:
16c2fd082ahead:
e56629641cmerge: clean
build: ok
tests: 3020 passed, 0 failed, 56 ignored; 28 skipped, the same as on main
review: 3 medium, 1 nit (below)
performance: 60 s smoke run: 1683 → 1668 frames (99 % of main), peak commit 18505 → 17639 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 231 s there, 0 device removals, 0 crashes, 4.2 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: safe to merge: no blocking finding (the points below are medium or nits), the suite passes and the smoke run is clean
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
In short: Extends the direct-DXIL waterfall pass to collapse 1-dword bindless waterfall loops (single and nested, wave32 and wave64, WREXEC and SAVEEXEC/XOR forms). It also keeps the collapsed 4-dword S# readfirstlanes as per-lane copies masked by EXEC. The code findings from my last merge-check and from the later reviews are fixed and tested. What is left is the overlap with open #3663, a ~2500-line commit that could be split, and a default-on change run only on NVIDIA.
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.