Shaders: reads of uninitialized SGPRs read as zero, as VGPRs do

Compute programs read SGPRs the hardware does not initialize when two
branches make the paths look like they allow a read before a write, even
though the branch that skips the write does not reach the read. That stops
translation with 'a hardware SGPR input is not supported' and drops the
program's dispatches.

ComputeIo::initialized_sgprs() counts the user SGPRs, the enabled system
ones and the scratch wave offset. A read of a general SGPR (0..=105) at or
above that count holds whatever the previous wave left, so no program can
depend on its value: read it as zero, as unset VGPRs already are. Reserved
registers (VCC, trap temporaries, M0, EXEC) keep their current handling.
This commit is contained in:
local committed 2026-11-23 22:16:27 -05:00
1 parent 35e8407c9c
commit 0d594727c4
3 files changed
+47 -1

No files matched your search

+31
View File
@@ -319,6 +319,15 @@ impl ComputeIo {
(ids, take(10))
}
/// SGPRs the hardware initializes: the user SGPRs, the enabled system
/// ones, then the scratch wave offset when scratch is enabled (bit 0).
/// The ones above hold whatever the previous wave left.
pub fn initialized_sgprs(&self) -> u8 {
let (ids, info) = self.system_sgprs();
let end = ids.into_iter().chain([info]).flatten().map(|s| s + 1).max();
end.unwrap_or(0).max(self.user_sgprs()) + (self.rsrc2 & 1) as u8
}
/// Thread id components in v0, v1, v2 (1 to 3).
pub fn thread_id_vgprs(&self) -> u8 {
(self.rsrc2 >> 11 & 3) as u8 + 1
@@ -948,6 +957,28 @@ mod tests {
assert_eq!((cs.thread_id_vgprs(), cs.lds_bytes()), (3, 0));
}
#[test]
fn initialized_sgprs_covers_user_system_and_scratch() {
// 5 user SGPRs, group ids x and y (s5, s6), no scratch: s0..=s6.
let cs = ComputeIo {
rsrc2: 0x1098A,
threads: [16, 16, 1],
};
assert_eq!(cs.initialized_sgprs(), 7);
// All three group ids after 6 user SGPRs, plus the info SGPR: s0..=s9.
let cs = ComputeIo {
rsrc2: 0x78C,
threads: [8, 8, 1],
};
assert_eq!(cs.initialized_sgprs(), 10);
// The same with scratch enabled adds the wave offset: s0..=s10.
let cs = ComputeIo {
rsrc2: 0x78D,
threads: [8, 8, 1],
};
assert_eq!(cs.initialized_sgprs(), 11);
}
#[test]
fn reads_every_native_blob() {
let es = xbch(&fssm(&[(HwStage::Es, &VS_CODE)]));