This commit is contained in:
local committed 2026-11-25 15:33:42 -06:00
1 parent 35bd011453
commit 53abe45ad2
3 files changed
+222 -7

No files matched your search

+159 -5
View File
@@ -206,13 +206,15 @@ pub fn builder_bounds() -> bool {
/// is exact, so the switch is for telling a translator fault from a
/// clean-up fault, and for measuring what the clean-up is worth.
/// `VICTORY_SHADER_OPT`:
/// - unset: every pass.
/// - unset: every pass but the last one below (63).
/// - `0`: none (the module as the lowering made it).
/// - a number (decimal or `0x` hex): those passes; 1 dead code, 2 constants
/// and identities, 4 one instruction for one value, 8 what a branch taken
/// says about its condition, 16 one read for one place within a block,
/// 32 a first-lane read of two host waves without the round that asks
/// which half has a lane (where every lane has one).
/// 64 the dwords of one console load read by one call for every four
/// (not on unless asked: `127` is every pass with it).
///
/// Part of the translation: the shader cache keys on it (`victory-gpu`'s
/// does).
@@ -310,7 +312,7 @@ fn parse_shader_opt(value: Option<&str>) -> u32 {
Some(hex) => u32::from_str_radix(hex, 16).ok(),
None => v.parse().ok(),
});
parsed.map_or(bitcode::opt::ALL, |n| n & bitcode::opt::ALL)
parsed.map_or(bitcode::opt::DEFAULT, |n| n & bitcode::opt::ALL)
}
/// `VICTORY_SHADER_LOOP_LIMIT`'s value; the default when it is unset,
@@ -1080,13 +1082,15 @@ mod tests {
#[test]
fn the_clean_up_switch_parses_or_runs_every_pass() {
let all = super::bitcode::opt::ALL;
assert_eq!(parse_shader_opt(None), all);
let (all, usual) = (super::bitcode::opt::ALL, super::bitcode::opt::DEFAULT);
assert_eq!(usual, 63, "the passes of the builds before the wide loads");
assert_eq!(parse_shader_opt(None), usual);
assert_eq!(parse_shader_opt(Some("0")), 0);
assert_eq!(parse_shader_opt(Some(" 1 ")), 1);
assert_eq!(parse_shader_opt(Some("0x1")), 1);
assert_eq!(parse_shader_opt(Some("127")), all);
assert_eq!(parse_shader_opt(Some("0xffffffff")), all);
assert_eq!(parse_shader_opt(Some("on")), all);
assert_eq!(parse_shader_opt(Some("on")), usual);
}
#[test]
@@ -2081,6 +2085,156 @@ mod tests {
let _ = super::emit(&c, &native, &p, &st, &io, &res);
}
/// `s_buffer_load_dwordx4`, `x8` and `x16` from a raw SRV read the dwords
/// the console's range-checked load reads, a call a dword or
/// (`VICTORY_SHADER_OPT` with 64) a call for every four: also where a
/// call's four dwords lie across the view's end (the dwords out of it
/// are 0, the others are read). On the software adapter only: run the
/// test once plain and once with `VICTORY_SHADER_OPT=127`.
#[test]
#[cfg(windows)]
fn scalar_buffer_loads_read_the_same_dwords_one_call_or_four() {
// (first register, dwords) of the three loads, in order.
const LOADS: [(u32, u32); 3] = [(16, 8), (24, 4), (32, 16)];
let mut words: Vec<u32> = vec![
0xBE85_0380, // s_mov_b32 s5, 0
0xF408_0202,
0xFA00_0000, // s_load_dwordx4 s[8:11], s[4:5], 0x0 (the SRV)
0xF408_0302,
0xFA00_0020, // s_load_dwordx4 s[12:15], s[4:5], 0x20 (the UAV)
0xF42C_0404,
0x0000_0000, // s_buffer_load_dwordx8 s[16:23], s[8:11], s0
0xF428_0604,
0xFA00_0008, // s_buffer_load_dwordx4 s[24:27], s[8:11], 0x8
0xF430_0804,
0x0200_0004, // s_buffer_load_dwordx16 s[32:47], s[8:11], s1, 0x4
];
let mut out_dword = 0u32;
for (first, n) in LOADS {
for k in 0..n {
// v_mov_b32 v1, s<first + k>
words.push(0x7E00_0000 | 1 << 17 | 0x001 << 9 | (first + k));
// buffer_store_dword v1, s[12:15], offset 4 * out_dword
words.push(0x38 << 26 | 0x1C << 18 | (4 * out_dword));
words.push(0x80 << 24 | (12 >> 2) << 16 | 1 << 8);
out_dword += 1;
}
}
words.push(0xBF81_0000); // s_endpgm
let table = |kind, at| crate::UsedResource {
kind,
root: crate::RootType::Table,
table_offset_dwords: at,
lower_bound: 0,
stride: 4,
dwords: 4,
user_data: 4,
slot: 1,
};
let native = super::NativeProgram {
stage: super::HwStage::Cs,
wave64: false,
vgprs: 4,
layout: vec![
crate::RootParam {
root: crate::RootType::Constants,
table_offset_dwords: 0,
sgprs: 4,
base_register: 0,
user_data: 0,
slot: 0,
},
crate::RootParam {
root: crate::RootType::Table,
table_offset_dwords: 0,
sgprs: 1,
base_register: 0,
user_data: 4,
slot: 1,
},
],
used: vec![table(crate::ResourceType::Srv, 0), table(crate::ResourceType::Uav, 8)],
io: crate::native::StageIo::Cs(crate::native::ComputeIo {
rsrc2: 5 << 1,
threads: [1, 1, 1],
}),
code: words.iter().flat_map(|w| w.to_le_bytes()).collect(),
};
let p = crate::ir::build(&native.code, native.wave64, native.vgprs).unwrap();
let res = crate::resource::track(&p, &native.layout, native.stage, None).unwrap();
let io = crate::io::raise(&p, &native).unwrap();
let st = crate::structure::structure(&p).unwrap();
let l = super::lower::lower(&super::lower::Parts {
native: &native,
p: &p,
st: &st,
io: &io,
res: &res,
inputs: Vec::new(),
outputs: Vec::new(),
prims: Vec::new(),
mesh_stride: 0,
})
.unwrap();
// The calls that read the SRV: 28 a dword, 7 with four a call.
let wide = shader_opt() & super::bitcode::opt::WIDE != 0;
let mut dxil = l.dxil;
if let Ok(mut v) = super::validator::Validator::load(
super::validator::Validator::default_path().as_deref(),
) {
v.validate(&mut dxil).unwrap();
}
let _one = super::valu_tests::ONE_AT_A_TIME.lock().unwrap_or_else(|e| e.into_inner());
let Ok(host) = super::host::Host::new(true) else {
eprintln!("no software adapter; the dispatch is skipped");
return;
};
let cs = super::HostShader {
stage: super::HwStage::Cs,
dxil,
user_data: l.user_data,
samplers: Vec::new(),
static_samplers: Vec::new(),
root_cbvs: l.root_cbvs,
root_srvs: l.root_srvs,
root_uavs: l.root_uavs,
root_indexed_views: Vec::new(),
};
let (root, pso) = host.compute_pipeline(&cs).unwrap();
// Twelve dwords: the loads below run across the view's end.
let data: Vec<u32> = (0..12u32).map(|i| 0x1111_1111u32.wrapping_mul(i + 1) ^ 0x8000_0000).collect();
let dword = |byte: u64| -> u32 {
if byte.is_multiple_of(4) && byte + 4 <= 4 * data.len() as u64 { data[(byte / 4) as usize] } else { 0 }
};
for (s0, s1) in [(0u32, 0u32), (16, 0), (24, 4), (40, 28), (48, 44), (8, 12)] {
let out = host
.dispatch(
&root,
&pso,
&super::host::Dispatch {
roots: vec![(0, super::host::Root::Constants(vec![s0, s1, 0, 0, 0]))],
views: &[
super::host::View::Buffer {
data: &data,
stride: super::host::Stride::Raw,
},
super::host::View::RawUav(32),
],
samplers: &[],
groups: [1, 1, 1],
},
)
.unwrap();
let starts = [u64::from(s0), 8, u64::from(s1) + 4];
let mut want = Vec::new();
for (&(_, n), start) in LOADS.iter().zip(starts) {
want.extend((0..u64::from(n)).map(|k| dword(start + 4 * k)));
}
eprintln!("offsets {s0} and {s1}, four dwords a call: {wide}: {:x?}", &out[0][..28]);
assert_eq!(out[0][..28], want[..], "offsets {s0} and {s1}, four dwords a call: {wide}");
}
}
#[test]
fn valu_div_f32_sequence_executes_on_gpu() {
let words: &[u32] = &[