Direct DXIL: divergent VM=1 pixel shader exports overwrite live_vm_var to 0 for inactive lanes #2407

Open
opened 2026-11-26 05:29:58 +00:00 by github-bot · 2 comments
Owner

@⁠ahmetbagci8 on GitHub · 2026-11-25 17:59 UTC · original

Summary

In crates/xcl/src/gpu/dxil/lower_gfx.rs (lines 377-390):

if vm {
    self.gfx().ps_vm = true;
    let lv = self.gfx().live_vm_var;
    let a = self.act();
    let (one, z) = (self.c(1), self.c(0));
    let v = self.sel(a, one, z);
    self.wr(lv, v);
}
if done {
    self.gfx().ps_done = true;
    let lv = self.gfx().live_var;
    let one = self.c(1);
    self.set_out(lv, one);
}

Unlike if done (which uses self.set_out(lv, one) to preserve previously set 1s for inactive lanes), if vm unconditionally overwrites live_vm_var with self.sel(a, 1, 0).

In any pixel shader with structured divergent control flow containing two exp ..., vm=1 instructions (for example, an if/else where both branches export with VM=1, DONE=1 under complementary EXEC masks), the second exp executes with a == 0 for all lanes from the first branch and resets their live_vm_var to 0. At finish_gfx (lines 269-273), dead = (live_vm_var == 0) then discards all pixels from the first branch.

Suggested fix

Use self.set_out(lv, one) in if vm, matching if done:

if vm {
    self.gfx().ps_vm = true;
    let lv = self.gfx().live_vm_var;
    let one = self.c(1);
    self.set_out(lv, one);
}

Not tested

  • Read from commit 082944135cd2b96288470a595861fa608eee08dc without a new runtime test.

AI use

  • Antigravity harness (Gemini 4 Neon) audited lower_gfx.rs and drafted this report; the author reviewed it before posting.
**@⁠ahmetbagci8** on GitHub · 2026-11-25 17:59 UTC · [original](https://github.com/xcl-dev/xcl/issues/2407) ### Summary In `crates/xcl/src/gpu/dxil/lower_gfx.rs` (lines 377-390): ```rust if vm { self.gfx().ps_vm = true; let lv = self.gfx().live_vm_var; let a = self.act(); let (one, z) = (self.c(1), self.c(0)); let v = self.sel(a, one, z); self.wr(lv, v); } if done { self.gfx().ps_done = true; let lv = self.gfx().live_var; let one = self.c(1); self.set_out(lv, one); } ``` Unlike `if done` (which uses `self.set_out(lv, one)` to preserve previously set `1`s for inactive lanes), `if vm` unconditionally overwrites `live_vm_var` with `self.sel(a, 1, 0)`. In any pixel shader with structured divergent control flow containing two `exp ..., vm=1` instructions (for example, an `if/else` where both branches export with `VM=1, DONE=1` under complementary `EXEC` masks), the second `exp` executes with `a == 0` for all lanes from the first branch and resets their `live_vm_var` to `0`. At `finish_gfx` (lines 269-273), `dead = (live_vm_var == 0)` then discards all pixels from the first branch. ### Suggested fix Use `self.set_out(lv, one)` in `if vm`, matching `if done`: ```rust if vm { self.gfx().ps_vm = true; let lv = self.gfx().live_vm_var; let one = self.c(1); self.set_out(lv, one); } ``` ### Not tested - Read from commit `082944135cd2b96288470a595861fa608eee08dc` without a new runtime test. ### AI use - Antigravity harness (Gemini 4 Neon) audited `lower_gfx.rs` and drafted this report; the author reviewed it before posting.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:29:58 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 20:49 UTC · original

Claiming this issue: fixing divergent VM=1 pixel shader export live_vm_var accumulation in Direct DXIL lowering, with regression tests.
AI use: Claude Code (Claude Opus 5.5).

**@⁠oni-swr** on GitHub · 2026-11-25 20:49 UTC · [original](https://github.com/xcl-dev/xcl/issues/2407#issuecomment-7174228528) Claiming this issue: fixing divergent VM=1 pixel shader export live_vm_var accumulation in Direct DXIL lowering, with regression tests. AI use: Claude Code (Claude Opus 5.5).
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 21:10 UTC · original

Withdrawing my claim and not opening a PR — this looks like a false positive:

  • Commit dc0d25fe (#1488) intentionally makes each VM=1 pixel export overwrite the survival mask with that export's active EXEC mask (matching the HLSL backend's xcl_live = (act); and verified on Direct DXIL by gpu_ps_exp_vm_controls_pixel_survival case two_vm1_second_narrower_overwrites).
  • Branches in Direct DXIL lowering (crates/xcl/src/gpu/dxil/lower.rs:981-1013, including s_cbranch_execz) test the wave's EXEC mask, so in the reported if/else both exports execute with the same wave EXEC semantics as hardware (an empty branch is skipped by execz). Changing VM=1 to accumulate 1 would regress two_vm1_second_narrower_overwrites and diverge from HLSL.

AI use: Claude Code (Claude Opus 5.5).

**@⁠oni-swr** on GitHub · 2026-11-25 21:10 UTC · [original](https://github.com/xcl-dev/xcl/issues/2407#issuecomment-7174707831) Withdrawing my claim and not opening a PR — this looks like a false positive: - Commit `dc0d25fe` (#1488) intentionally makes each `VM=1` pixel export overwrite the survival mask with that export's active `EXEC` mask (matching the HLSL backend's `xcl_live = (act);` and verified on Direct DXIL by `gpu_ps_exp_vm_controls_pixel_survival` case `two_vm1_second_narrower_overwrites`). - Branches in Direct DXIL lowering (`crates/xcl/src/gpu/dxil/lower.rs:981-1013`, including `s_cbranch_execz`) test the wave's `EXEC` mask, so in the reported if/else both exports execute with the same wave `EXEC` semantics as hardware (an empty branch is skipped by `execz`). Changing `VM=1` to accumulate `1` would regress `two_vm1_second_narrower_overwrites` and diverge from HLSL. AI use: Claude Code (Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.