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

Closed
opened 2026-11-25 17:59:23 +00:00 by ahmetbagci8 · 3 comments
ahmetbagci8 commented 2026-11-25 17:59:23 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by ahmetbagci8 on 2026-11-25T17:59:23Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:6610544766 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2407). Originally posted by [ahmetbagci8](https://github.com/ahmetbagci8) on 2026-11-25T17:59:23Z. --- ### 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.
oni-swr commented 2026-11-25 21:05:23 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by oni-swr on 2026-11-25T20:49:05Z.


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).

<!-- greyfinch-sync:ivall/xcl:comment:7174228528 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2407#issuecomment-7174228528). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T20:49:05Z. --- 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 commented 2026-11-25 22:06:37 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by oni-swr on 2026-11-25T21:10:20Z.


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).

<!-- greyfinch-sync:ivall/xcl:comment:7174707831 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2407#issuecomment-7174707831). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T21:10:20Z. --- 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).
ahmetbagci8 commented 2026-11-26 17:50:19 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by ahmetbagci8 on 2026-11-26T17:50:19Z.


Thanks @oni-swr for checking and pointing out dc0d25fe and wo_vm1_second_narrower_overwrites — closing as intentional behavior / false positive.

<!-- greyfinch-sync:ivall/xcl:comment:7199743836 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2407#issuecomment-7199743836). Originally posted by [ahmetbagci8](https://github.com/ahmetbagci8) on 2026-11-26T17:50:19Z. --- Thanks @oni-swr for checking and pointing out dc0d25fe and wo_vm1_second_narrower_overwrites — closing as intentional behavior / false positive.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl#2397
No description provided.