Test probe: compare direct and joined reads of a shader timestamp

(cherry picked from commit 4b2ea70f0940a4317dc934000d249dce0fce50f6)
This commit is contained in:
Dathinel authored and KoLolX3 committed 2026-11-23 21:35:20 -08:00
1 parent 35e8407c9c
commit 2b7748a8d4
1 file changed
+33 -4
+33 -4
View File
@@ -6565,8 +6565,8 @@ mod tests {
const S_ENDPGM: u32 = 0xBF81_0000;
/// Lowers a compute program of constants: whether it translates.
fn lowers(words: &[u32]) -> Result<(), crate::ShaderError> {
/// Whether a synthetic compute program translates with these input registers.
fn lowers(words: &[u32], rsrc2: u32) -> Result<(), crate::ShaderError> {
let code: Vec<u8> = words.iter().flat_map(|w| w.to_le_bytes()).collect();
let native = NativeProgram {
stage: HwStage::Cs,
@@ -6575,7 +6575,7 @@ mod tests {
layout: vec![],
used: vec![],
io: StageIo::Cs(ComputeIo {
rsrc2: 0,
rsrc2,
threads: [1, 1, 1],
}),
code,
@@ -6626,10 +6626,39 @@ mod tests {
S_ENDPGM,
];
for words in [add, sub] {
lowers(&words).unwrap();
lowers(&words, 0).unwrap();
}
}
#[test]
fn a_missing_value_stays_missing_through_two_live_joins() {
let mut words = [
0xF490_0180,
0, // s_memtime s[6:7]
0xBF06_8000, // s_cmp_eq_u32 s0, 0 (s0 = group id X)
0xBF85_0001, // skip the first overwrite
0xBE86_0380, // s_mov_b32 s6, 0
0xBF06_8101, // s_cmp_eq_u32 s1, 1 (s1 = group id Y)
0xBF85_0001, // skip the second overwrite
0xBE86_0381, // s_mov_b32 s6, 1
0xBF07_8006, // s_cmp_lg_u32 s6, 0
0xBF85_0001, // use the result to branch
0xBE83_0380,
S_ENDPGM,
];
let group_ids_xy = 3 << 7;
// Compare to a direct read so future timestamp support works in both cases.
let refusal = |code: &[u32]| match lowers(code, group_ids_xy) {
Ok(()) => None,
Err(crate::ShaderError::Unsupported { what, .. }) => Some(what),
Err(error) => panic!("{error}"),
};
let direct = [&words[..2], &words[8..]].concat();
assert_eq!(refusal(&words), refusal(&direct));
words[8] = 0xBF07_8000; // read the group id instead; the timestamp is dead
lowers(&words, group_ids_xy).expect("dead timestamp");
}
#[test]
fn buffer_formats_by_number() {
// The numbers the disassembler names 8_8_8_8_UNORM, 16_16_SNORM,