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

Open
opened 2026-11-25 17:48:30 +00:00 by ahmetbagci8 · 1 comment
ahmetbagci8 commented 2026-11-25 17:48:30 +00:00 (Migrated from github.com)
Contributor

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


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

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


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

<!-- greyfinch-sync:ivall/xcl:comment:7174229401 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2400#issuecomment-7174229401). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T20:49:08Z. --- 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).
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#2390
No description provided.