Repository navigation
Conversation
|
Diff review (head Strong perf/memory win on bindless waterfall collapse, and the
Minor note: AI use: Antigravity (Gemini 4 Neon) audited the full diff against |
|
Review (head a28f48f, diff read, not a merge-check):
Fine: dynamic T#/S# heap handles are already created with AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
|
merge-check AI-written and posted by Foniass without a human check of each point. |
|
I reproduced the static-sampler issue on an RTX 3080. I ran the same synthetic pixel shader on base
All 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 This covers the uniform, single-iteration case on driver I reviewed and approved this comment before posting. |
a28f48f to
9c903a2
Compare
|
Rebased onto
AI-written reply (Antigravity, Gemini 4 Neon). |
bmjask
left a comment
There was a problem hiding this comment.
Review of 9c903a2e: 3 finding(s) (1 critical, 1 high, 1 medium), most severe first.
- Critical
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) - High
crates/xcl/src/gpu/dxil/waterfall.rs:286: see below. - Medium
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:
- High
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.
| } | ||
| "v_readfirstlane_b32" => { | ||
| // Collapsed waterfall: SGPRs are already per-lane SSA values. | ||
| if self.waterfall_rfl_per_lane.contains(&self.pc) { |
There was a problem hiding this comment.
Critical: Not certain about this one: a collapsed v_readfirstlane_b32 is 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_key instead 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 whose v_key VGPR was never written), those lanes run s_load_dwordx8 s[t], s[base], s_key with 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.
| } | ||
| match blk.term { | ||
| Term::Jump(next) if next != cur => cur = next, | ||
| Term::End => return Some(FallExec::Ends), |
There was a problem hiding this comment.
Medium: FallExec::Ends and scalar_live_in (Term::End => empty) assume no scalar register is observable at program end, but for Entry::Kernel store_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 to s_endpgm, the uncollapsed dump shows EXEC=0 and s_key/rem as of the last iteration, while the collapsed one shows EXEC = the entry mask, rem = the initial exec and s_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.
|
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any. |
|
merge-check AI-written and posted by Foniass without a human check of each point. |
9c903a2 to
6f6cbd3
Compare
|
Updated to
Re-verified on AI-written reply (Antigravity, Gemini 4 Neon). |
bmjask
left a comment
There was a problem hiding this comment.
Review of 6f6cbd38: 3 finding(s) (2 high, 1 medium), most severe first.
Re-review at 6f6cbd38. The three findings from the 9c903a2e review (inactive lanes using their own v_key after 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.
- High
crates/xcl/src/gpu/dxil/mask_exchange.rs:526: see below. - High
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) - Medium
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.
| let run = self.land(act, valid); | ||
| let z0 = self.c(0); | ||
| let safe_tw0 = self.sel(valid, tw0, z0); | ||
| let safe_tw0 = self.sel(run, tw0, z0); |
There was a problem hiding this comment.
High: safe_tw0 changed from sel(valid, tw0, 0) to sel(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 UNORM image_sample inside 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 than kind (e.g. Texture3D vs Texture2D), those lanes access a mismatched descriptor, which is undefined behaviour and can hang some drivers. Limiting the run select to collapsed waterfalls would keep the old behaviour elsewhere.
Extend the direct-DXIL waterfall pass to collapse 1-dword bindless descriptor-index waterfall loops (single loops and nested outer/inner pairs, wave32 and wave64, both WREXEC and SAVEEXEC/XOR forms) into straight-line per-lane code alongside the existing 4-dword S# sampler waterfall collapse. Both 4-dword S# and 1-dword bindless waterfalls keep their V_READFIRSTLANE_B32 instructions lowered as EXEC-masked per-lane copies (inactive lanes receive 0 instead of uninitialized VGPR keys), are excluded from split-wave64 mask_exchange EXEC/meet/lane-read tracking, taint SGPRs derived from collapsed V_READFIRSTLANE_B32s in mask_exchange::known_step and idioms::uniform_reads so post-waterfall VGPR reads are not misclassified as wave-uniform, and participate in compact block deduplication keys while preserving pre-collapse CFG leaders for constant_samplers branch following. Entry::Kernel skips collapse so lane-0 register dumps at s_endpgm remain exact. Refuse collapse on side effects, coherent (GLC/DLC) SMEM loads, RMW/loop-carried scalar dependencies, upward-exposed SCC/VCC/mask/iter reads, invalid or VOPC VGPR-vs-VGPR compare encodings, or live-out temporaries, and clear PCs on emptied merged blocks. Assisted-by: Antigravity (Gemini 4 Neon)
|
Updated to
Re-verified on AI-written reply (Antigravity, Gemini 4 Neon). |
6f6cbd3 to
e566296
Compare
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.