Direct DXIL: scratch address calculation ignores SVE and treats SADDR and ADDR as mutually exclusive #2400

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

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

Summary

In crates/xcl/src/gpu/dxil/lower_mem.rs (scratch, lines 2354-2359):

fn scratch(&mut self, d: &Decoded, op: &str) -> LResult<()> {
    let saddr = Self::fv(d, "SADDR");
    let base = if saddr != 0x7D && saddr != 0x7F { self.sreg(saddr) } else { self.vreg(Self::fv(d, "ADDR")) };
    let raw = Self::fv(d, "OFFSET") as u32;
    let off = (((raw << 20) as i32) >> 20) as u32;
    let a = self.addc(base, off);

In RDNA2 ENC_FLAT_SCRATCH, SVE (Scratch VGPR Enable) independently controls whether VADDR (ADDR) is included in the address, and SADDR != 0x7F independently controls whether SGPR[SADDR] is included. Treating them as mutually exclusive without checking SVE causes two bugs:

  1. When both SADDR != 0x7F and SVE == 1 (indexed scratch access with a base SGPR + per-lane VGPR offset), vreg(ADDR) is completely dropped.
  2. When SADDR == 0x7F and SVE == 0 (immediate-only scratch offset), vreg(ADDR) is erroneously used as the base instead of 0.

Suggested fix

let saddr = Self::fv(d, "SADDR");
let sve = Self::fv(d, "SVE") != 0;
let sbase = if saddr != 0x7D && saddr != 0x7F { Some(self.sreg(saddr)) } else { None };
let vbase = if sve { Some(self.vreg(Self::fv(d, "ADDR"))) } else { None };
let base = match (sbase, vbase) {
    (Some(s), Some(v)) => self.add(s, v),
    (Some(s), None) => s,
    (None, Some(v)) => v,
    (None, None) => self.c(0),
};

Not tested

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

AI use

  • Antigravity harness (Gemini 4 Neon) audited lower_mem.rs and drafted this report; the author reviewed it before posting.
**@⁠ahmetbagci8** on GitHub · 2026-11-25 17:48 UTC · [original](https://github.com/xcl-dev/xcl/issues/2400) ### Summary In `crates/xcl/src/gpu/dxil/lower_mem.rs` (`scratch`, lines 2354-2359): ```rust fn scratch(&mut self, d: &Decoded, op: &str) -> LResult<()> { let saddr = Self::fv(d, "SADDR"); let base = if saddr != 0x7D && saddr != 0x7F { self.sreg(saddr) } else { self.vreg(Self::fv(d, "ADDR")) }; let raw = Self::fv(d, "OFFSET") as u32; let off = (((raw << 20) as i32) >> 20) as u32; let a = self.addc(base, off); ``` In RDNA2 `ENC_FLAT_SCRATCH`, `SVE` (Scratch VGPR Enable) independently controls whether `VADDR` (`ADDR`) is included in the address, and `SADDR != 0x7F` independently controls whether `SGPR[SADDR]` is included. Treating them as mutually exclusive without checking `SVE` causes two bugs: 1. When both `SADDR != 0x7F` and `SVE == 1` (indexed scratch access with a base SGPR + per-lane VGPR offset), `vreg(ADDR)` is completely dropped. 2. When `SADDR == 0x7F` and `SVE == 0` (immediate-only scratch offset), `vreg(ADDR)` is erroneously used as the base instead of `0`. ### Suggested fix ```rust let saddr = Self::fv(d, "SADDR"); let sve = Self::fv(d, "SVE") != 0; let sbase = if saddr != 0x7D && saddr != 0x7F { Some(self.sreg(saddr)) } else { None }; let vbase = if sve { Some(self.vreg(Self::fv(d, "ADDR"))) } else { None }; let base = match (sbase, vbase) { (Some(s), Some(v)) => self.add(s, v), (Some(s), None) => s, (None, Some(v)) => v, (None, None) => self.c(0), }; ``` ### Not tested - Read from commit `082944135cd2b96288470a595861fa608eee08dc` without a new runtime test. ### AI use - Antigravity harness (Gemini 4 Neon) audited `lower_mem.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:51 +00:00
Author
Owner

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

Claiming this issue: fixing RDNA2 Direct DXIL scratch() address calculation to handle SVE and combined SADDR + ADDR, 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/2400#issuecomment-7174229401) Claiming this issue: fixing RDNA2 Direct DXIL scratch() address calculation to handle SVE and combined SADDR + ADDR, with regression tests. AI use: Claude Code (Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.