Direct DXIL: Lw::top_vgpr() reads init.touched (empty outside Entry::Kernel and cleared in XCL_PER_LANE), truncating v_movrel* and v_swaprel_b32 #1890

Open
opened 2026-11-26 05:08:37 +00:00 by github-bot · 1 comment
Owner

@⁠microwave805 on GitHub · 2026-11-24 22:37 UTC · original

Static audit on main @ 689f2db found that direct DXIL's v_movrel* and v_swaprel_b32 lowering computes its VGPR index bound from self.init.touched, which is only pre-populated for Entry::Kernel — and is explicitly emptied before every instruction in XCL_PER_LANE=1.

Where

  • crates/xcl/src/gpu/dxil/lower_wide.rs:264-354 (Lw::top_vgpr, Lw::movrel, Lw::swaprel)
  • crates/xcl/src/gpu/dxil/kernel.rs:208-220 (for d in cfg.insts.iter().filter(|_| kernel))
  • crates/xcl/src/gpu/recomp/lower_dxil.rs:267-272 (std::mem::take(&mut self.lw.init.touched) in DxilIr::foreign)

Root cause

  1. Lw::top_vgpr() returns the maximum VGPR present in self.init.touched (lower_wide.rs:264-266), and movrel() / swaprel() clamp their select/write loops to top = self.top_vgpr().max(vdst).max(base).
  2. In kernel.rs:208, lw.init.touched is only pre-populated when entry == Entry::Kernel. For all real shader stages (Entry::Compute, Entry::Vertex, Entry::Pixel, Entry::Mesh, Entry::Geometry), lw.init.touched starts empty and only accumulates VGPRs already lowered earlier in RPO order:
    • A v_movreld_b32 v0, s0 writing v0 + m0 before v0 + m0 has been referenced in an earlier block sees top == 0 (or a lower VGPR index) and silently drops the write.
    • A v_movrels_b32 v0, v4 or v_swaprel_b32 reading v4 + m0 where higher VGPRs are defined in a loop back-edge or initialized as stage inputs only referenced later silently reads 0 instead of the VGPR.
  3. In XCL_PER_LANE=1, DxilIr::foreign() (lower_dxil.rs:267) swaps out self.lw.init.touched with an empty BTreeSet before calling self.lw.inst_guarded(d, ...), so top_vgpr() is always 0 (even in Entry::Kernel), silently dropping every m0 > 0 write and returning 0 on every m0 > 0 read. Additionally, Lower::bridge() (lower.rs:1624) only passes rdna2::vgpr_uses(d) (the base VGPR) into inputs/outputs, so v_movrel*/v_swaprel_b32 cannot safely bridge in XCL_PER_LANE unless refused or given the full VGPR range.

Trigger

Any Compute/VS/PS/MS/GS shader translated through Direct DXIL (XCL_DIRECT_DXIL=1 / all) that executes v_movreld_b32 v0, v1 with m0 = 2 before v2 is directly named (e.g. dynamically indexing a VGPR array before reading v2 out), or any v_movrel*/v_swaprel_b32 with m0 > 0 under XCL_PER_LANE=1.

Fix direction

  • Store the program-wide max VGPR (scanned across all insts in Lw::new, matching recomp/emit.rs) in a dedicated Lw::max_vgpr: u64 field instead of deriving it from self.init.touched.
  • Refuse v_movrel* / v_swaprel_b32 in recomp/lower.rs::bridge() (or pass/collect the full [base..=max_vgpr] VGPR range).

AI use

  • Antigravity (Gemini 4 Neon): static code audit on main @ 689f2db and issue drafting.
**@⁠microwave805** on GitHub · 2026-11-24 22:37 UTC · [original](https://github.com/xcl-dev/xcl/issues/1890) Static audit on `main @ 689f2db` found that direct DXIL's `v_movrel*` and `v_swaprel_b32` lowering computes its VGPR index bound from `self.init.touched`, which is only pre-populated for `Entry::Kernel` — and is explicitly emptied before every instruction in `XCL_PER_LANE=1`. ### Where - `crates/xcl/src/gpu/dxil/lower_wide.rs:264-354` (`Lw::top_vgpr`, `Lw::movrel`, `Lw::swaprel`) - `crates/xcl/src/gpu/dxil/kernel.rs:208-220` (`for d in cfg.insts.iter().filter(|_| kernel)`) - `crates/xcl/src/gpu/recomp/lower_dxil.rs:267-272` (`std::mem::take(&mut self.lw.init.touched)` in `DxilIr::foreign`) ### Root cause 1. `Lw::top_vgpr()` returns the maximum VGPR present in `self.init.touched` (`lower_wide.rs:264-266`), and `movrel()` / `swaprel()` clamp their select/write loops to `top = self.top_vgpr().max(vdst).max(base)`. 2. In `kernel.rs:208`, `lw.init.touched` is only pre-populated when `entry == Entry::Kernel`. For all real shader stages (`Entry::Compute`, `Entry::Vertex`, `Entry::Pixel`, `Entry::Mesh`, `Entry::Geometry`), `lw.init.touched` starts empty and only accumulates VGPRs already lowered earlier in RPO order: - A `v_movreld_b32 v0, s0` writing `v0 + m0` before `v0 + m0` has been referenced in an earlier block sees `top == 0` (or a lower VGPR index) and silently drops the write. - A `v_movrels_b32 v0, v4` or `v_swaprel_b32` reading `v4 + m0` where higher VGPRs are defined in a loop back-edge or initialized as stage inputs only referenced later silently reads `0` instead of the VGPR. 3. In `XCL_PER_LANE=1`, `DxilIr::foreign()` (`lower_dxil.rs:267`) swaps out `self.lw.init.touched` with an empty `BTreeSet` before calling `self.lw.inst_guarded(d, ...)`, so `top_vgpr()` is **always 0** (even in `Entry::Kernel`), silently dropping every `m0 > 0` write and returning `0` on every `m0 > 0` read. Additionally, `Lower::bridge()` (`lower.rs:1624`) only passes `rdna2::vgpr_uses(d)` (the base VGPR) into `inputs`/`outputs`, so `v_movrel*`/`v_swaprel_b32` cannot safely bridge in `XCL_PER_LANE` unless refused or given the full VGPR range. ### Trigger Any Compute/VS/PS/MS/GS shader translated through Direct DXIL (`XCL_DIRECT_DXIL=1` / `all`) that executes `v_movreld_b32 v0, v1` with `m0 = 2` before `v2` is directly named (e.g. dynamically indexing a VGPR array before reading `v2` out), or any `v_movrel*`/`v_swaprel_b32` with `m0 > 0` under `XCL_PER_LANE=1`. ### Fix direction - Store the program-wide max VGPR (scanned across all `insts` in `Lw::new`, matching `recomp/emit.rs`) in a dedicated `Lw::max_vgpr: u64` field instead of deriving it from `self.init.touched`. - Refuse `v_movrel*` / `v_swaprel_b32` in `recomp/lower.rs::bridge()` (or pass/collect the full `[base..=max_vgpr]` VGPR range). ### AI use - Antigravity (Gemini 4 Neon): static code audit on `main @ 689f2db` and issue drafting.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:08:37 +00:00
Author
Owner

@⁠WebIdentity1 on GitHub · 2026-11-24 23:41 UTC · original

I am investigating this with public synthetic compute-entry fixtures on native Windows/RTX 3090. I will check the program-wide VGPR bound separately from the per-lane bridge contract, and coordinate any fix here; the existing #1823 kernel tests do not exercise the same entry setup. I will leave the distinct swaprel destination-semantics change in #803 to its author.

AI use: Codex with GPT-6 Astra is doing the investigation and tests.

**@⁠WebIdentity1** on GitHub · 2026-11-24 23:41 UTC · [original](https://github.com/xcl-dev/xcl/issues/1890#issuecomment-7147690002) I am investigating this with public synthetic compute-entry fixtures on native Windows/RTX 3090. I will check the program-wide VGPR bound separately from the per-lane bridge contract, and coordinate any fix here; the existing #1823 kernel tests do not exercise the same entry setup. I will leave the distinct swaprel destination-semantics change in #803 to its author. AI use: Codex with GPT-6 Astra is doing the investigation and tests.
This discussion has been locked. Commenting is limited to contributors.
No description provided.